//
// Asura_ReverbVolume.cpp
//
// Created by Richard Rice - 10/10/2007
// 
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"
#include "Sound/Asura_ReverbVolume.h"

#ifdef ASURA_USE_REVERBVOLUME_SYSTEM

// Asura Platform-independent
#include "ChunkSystem/Asura_Chunk_Stream.h"

// Tools
#ifdef ASURA_TOOLS
	#include "Sound/Tools_Sound_System.h"
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////
/*-------------------------------**
** Asura_ReverbVolume_Controller **
**-------------------------------*/

Asura_Zone* Asura_ReverbVolume_Controller::AllocateZone(const bool bCreateFromLoad /*= false*/)
{
	return new Asura_ReverbVolume(bCreateFromLoad);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------**
** Asura_ReverbVolume **
**--------------------*/

#define ASURA_REVERBVOLUME_CHUNK_VERSION 3

Asura_ReverbVolume::Asura_ReverbVolume(const bool bCreateFromLoad)
:Asura_Zone(bCreateFromLoad)
,m_uReverbType(0)
,m_fReverbAmount(1.0f)
{
}

Asura_ReverbVolume::~Asura_ReverbVolume()
{
}

void Asura_ReverbVolume::ReadFromChunkStream(class Asura_Chunk_Stream& xStream)
{
	int iVersion;
	xStream >> iVersion;
	Asura_Assertf(iVersion <= ASURA_REVERBVOLUME_CHUNK_VERSION,("Unknown chunk version %d for reverb volume",iVersion));

	Asura_Zone::ReadFromChunkStream(xStream);
	
	xStream >> m_uReverbType;

	if( iVersion >= 1 )
	{
		xStream >> m_fReverbAmount;
	}

	#ifdef ASURA_TOOLS
	#ifdef ASURA_USE_AUDIO_SYSTEM
		if( iVersion < 3 )
		{
			// Now clearing out the preset from old reverb volumes
			m_uReverbType = ASURA_HASH_ID_UNSET;
		}
	#endif // ASURA_USE_AUDIO_SYSTEM
	#endif // ASURA_TOOLS
}

#ifdef ASURA_TOOLS
void Asura_ReverbVolume::WriteToChunkStream(class Asura_Chunk_Stream& xStream)
{
	//write our version
	xStream << (int) ASURA_REVERBVOLUME_CHUNK_VERSION;

	//write parent class
	Asura_Zone::WriteToChunkStream(xStream);

	//write our data
	xStream << m_uReverbType;
	xStream << m_fReverbAmount;
}
#endif //ASURA_TOOLS

float Asura_ReverbVolume::GetPriority(int iVolumeIndex) const
{
	//Prefer smaller volumes , so negate the size
	return -GetVolumeSize(iVolumeIndex);
}


#endif // ASURA_USE_REVERBVOLUME_SYSTEM
