//////////////////////////////////////////////////////////////////////////////
//
// Asura_Chunk_ResourceFile_PC_ReplaceableSounds.cpp
//
// Copyright (c) 2003 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

#include "Core/Asura.h"

#if !defined(ASURA_USE_AUDIO_SYSTEM)

#include "Asura_Chunk_ResourceFile_PC_ReplaceableSounds.h"

// independent includes
#include "FileAccess/Asura_FileAccess.h"
#include "ChunkSystem/Asura_Chunk_Macros.h" // non-tools builds weren't compiling with this

// pc includes
#include "Sound/Asura_PC_ReplaceableSounds.h"

// project-supplied include
#include "Sound/Asura_ProjectSoundIDs.h"


bool Asura_Chunk_ResourceFile_PC_ReplaceableSoundsInfo::Process(Asura_Handle iFileHandle)
{
    u_int uVersion;
    ASURA_CHUNK_FILEEXTRACT(iFileHandle, uVersion, u_int);
    Asura_Assert(uVersion <= ASURA_RESOURCEFILE_PC_REPLACEABLESOUNDSINFO_VERSION, "unknown PC sound version");

    u_int uNumEntries;
    ASURA_CHUNK_FILEEXTRACT(iFileHandle, uNumEntries, u_int);
    Asura_Assert(uNumEntries < ASURA_MAX_NUMBER_OF_LOADED_SOUNDS, "too many replaceable sounds");

	Asura_PC_ReplaceableSounds::Initialise(uNumEntries, Asura_FileAccess::GetFilename(iFileHandle));
	
    for (u_int u = 0; u < uNumEntries; ++u)
    {
        Entry xEntry;
        ASURA_CHUNK_FILEEXTRACT(iFileHandle, xEntry, Entry);

		#ifdef ASURA_ASSERT
		bool bOK = 
		#endif
		Asura_PC_ReplaceableSounds::AddReplaceableSoundInfo(xEntry.iSoundID, xEntry.uByteOffset, xEntry.uSize);
		// (MH - 22.04.2003) error if 1) the sound had an error when it was added 
		// to the resource file in the first place, or 2) if the sound has already 
		// been loaded. Both are traceable problems and can be fixed so I'm 
		// leaving this assert in.
		Asura_Assert(bOK, "failed to add replaceable sound info");
	}

	return true;
}

#endif	//!defined(ASURA_USE_AUDIO_SYSTEM)
