reuse preloaded sounds

This commit is contained in:
Glenn Maynard
2005-07-18 19:09:31 +00:00
parent 2493236cea
commit 9ef48d4a48
+20 -2
View File
@@ -173,8 +173,14 @@ bool RageSound::Load( CString sSoundFilePath, bool bPrecache )
{ {
LOG->Trace( "RageSound::LoadSound( '%s', %d )", sSoundFilePath.c_str(), bPrecache ); LOG->Trace( "RageSound::LoadSound( '%s', %d )", sSoundFilePath.c_str(), bPrecache );
/* If this sound is already preloaded and held by SOUNDMAN, just make a
* copy of that. Since RageSoundReader_Preload is reference counted, this
* is cheap. */
SoundReader *pSound = SOUNDMAN->GetLoadedSound( sSoundFilePath );
if( pSound == NULL )
{
CString error; CString error;
SoundReader *pSound = SoundReader_FileReader::OpenFile( sSoundFilePath, error ); pSound = SoundReader_FileReader::OpenFile( sSoundFilePath, error );
if( pSound == NULL ) if( pSound == NULL )
{ {
LOG->Warn( "RageSound::Load: error opening sound \"%s\": %s", LOG->Warn( "RageSound::Load: error opening sound \"%s\": %s",
@@ -182,13 +188,25 @@ bool RageSound::Load( CString sSoundFilePath, bool bPrecache )
pSound = new RageSoundReader_Silence; pSound = new RageSoundReader_Silence;
} }
}
else
{
/* The sound we were given from SOUNDMAN is already preloaded. */
bPrecache = false;
}
LoadSoundReader( pSound ); LoadSoundReader( pSound );
/* Try to precache. Do this after calling LoadSoundReader() to put the /* Try to precache. Do this after calling LoadSoundReader() to put the
* sound in this->m_pSource, so we preload after resampling. */ * sound in this->m_pSource, so we preload after resampling. */
if( bPrecache ) if( bPrecache )
RageSoundReader_Preload::PreloadSound( m_pSource ); {
if( RageSoundReader_Preload::PreloadSound(m_pSource) )
{
/* We've preloaded the sound. Pass it to SOUNDMAN, for reuse. */
SOUNDMAN->AddLoadedSound( sSoundFilePath, (RageSoundReader_Preload *) m_pSource );
}
}
m_sFilePath = sSoundFilePath; m_sFilePath = sSoundFilePath;