//////////////////////////////////////////////////////////////////////////////
//
// Asura_Chunk_ResourceFile_PSP_StreamedSounds.cpp
//
// Copyright (c) 2003 Rebellion. All rights reserved.
//
// Description:
//
//     none
//
//////////////////////////////////////////////////////////////////////////////

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

#include "Core/Asura.h"

#include "ChunkSystem/Asura_Chunk_ResourceFile_PSP_StreamedSounds.h"

// engine independent headers
#include "ChunkSystem/Asura_Chunk_Macros.h"
#include "Sound/Asura_Sound.h"

// engine PSP headers
#include "Sound/Asura_PSP_Sound.h"

// C L A S S   I M P L E M E N T A T I O N S /////////////////////////////////

bool Asura_Chunk_ResourceFile_PSP_StreamedSounds::Process( Asura_Handle iFileHandle )
{
    int iVersion;
    ASURA_CHUNK_FILEEXTRACT( iFileHandle, iVersion, int );

    // Check version.
    if( iVersion > ASURA_PSP_STREAMEDSOUNDS_CHUNK_VERSION )
    {
        Asura_Assert( false, "Chunk data is newer than this build. You need new code." );
    }

    int iNumEntries;
    ASURA_CHUNK_FILEEXTRACT( iFileHandle, iNumEntries, int );
    Asura_Assert( iNumEntries < ASURA_MAX_NUMBER_OF_LOADED_SOUNDS, "Too many streamed sounds." );

	if (iNumEntries > 0)
	{
		Asura_PSP_Sound::InitStreamedSounds( Asura_FileAccess::GetFilename(iFileHandle) );

		bool bSoundIDsAreDynamic = (Flags & uASURA_PSP_STREAMEDSOUNDS_FLAG_SOUNDIDS_ARE_DYNAMIC) != 0;

		HdrEntry xHdrEntry;
		for( int i = 0; i < iNumEntries; ++i )
		{
			ASURA_CHUNK_FILEEXTRACT( iFileHandle, xHdrEntry, HdrEntry );

			Asura_PSP_Sound::AddStreamingSoundData(	bSoundIDsAreDynamic ? ASURA_SID_DYNAMIC : xHdrEntry.iSoundID,
													xHdrEntry.iOffset,
													xHdrEntry.iSize,
													bSoundIDsAreDynamic ? xHdrEntry.iSoundID : ASURA_HASH_ID_UNSET );
		}
	}

    // Return false so that the main chunk loading code will skip the rest
    // of the data for us. It has an optimisation for where the data's at the
    // end of the file, which should be the case for Streamed Sounds.
    return false;
}
