play copy of so that the Cancel sound continues playing after the transition and sample have been torn down

This commit is contained in:
Chris Danford
2005-03-21 03:41:06 +00:00
parent a23db65a1e
commit 1bff5bb755
3 changed files with 23 additions and 9 deletions
+20 -7
View File
@@ -3,7 +3,7 @@
#include "RageSound.h" #include "RageSound.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "RageLog.h" #include "RageLog.h"
#include "RageSoundManager.h"
RandomSample::RandomSample() RandomSample::RandomSample()
@@ -78,14 +78,11 @@ bool RandomSample::LoadSound( CString sSoundFilePath )
return true; return true;
} }
void RandomSample::PlayRandom() int RandomSample::GetNextToPlay()
{ {
// play one of the samples // play one of the samples
if( m_pSamples.empty() ) if( m_pSamples.empty() )
{ return -1;
// LOG->Trace( "WARNING: Tried to play a RandomSample that has 0 sounds loaded." );
return;
}
int iIndexToPlay = 0; int iIndexToPlay = 0;
for( int i=0; i<5; i++ ) for( int i=0; i<5; i++ )
@@ -95,8 +92,24 @@ void RandomSample::PlayRandom()
break; break;
} }
m_pSamples[iIndexToPlay]->Play();
m_iIndexLastPlayed = iIndexToPlay; m_iIndexLastPlayed = iIndexToPlay;
return iIndexToPlay;
}
void RandomSample::PlayRandom()
{
int iIndexToPlay = GetNextToPlay();
if( iIndexToPlay == -1 )
return;
m_pSamples[iIndexToPlay]->Play();
}
void RandomSample::PlayCopyOfRandom()
{
int iIndexToPlay = GetNextToPlay();
if( iIndexToPlay == -1 )
return;
SOUNDMAN->PlayCopyOfSound( *m_pSamples[iIndexToPlay] );
} }
void RandomSample::Stop() void RandomSample::Stop()
+2 -1
View File
@@ -14,12 +14,13 @@ public:
bool Load( CString sFilePath, int iMaxToLoad = 1000 /*load all*/ ); bool Load( CString sFilePath, int iMaxToLoad = 1000 /*load all*/ );
void UnloadAll(); void UnloadAll();
void PlayRandom(); void PlayRandom();
void PlayCopyOfRandom();
void Stop(); void Stop();
private: private:
bool LoadSoundDir( CString sDir, int iMaxToLoad ); bool LoadSoundDir( CString sDir, int iMaxToLoad );
bool LoadSound( CString sSoundFilePath ); bool LoadSound( CString sSoundFilePath );
int GetNextToPlay();
vector<RageSound*> m_pSamples; vector<RageSound*> m_pSamples;
int m_iIndexLastPlayed; int m_iIndexLastPlayed;
+1 -1
View File
@@ -53,7 +53,7 @@ void Transition::Update( float fDeltaTime )
/* Start the transition on the first update, not in the ctor, so /* Start the transition on the first update, not in the ctor, so
* we don't play a sound while our parent is still loading. */ * we don't play a sound while our parent is still loading. */
if( m_bFirstUpdate ) if( m_bFirstUpdate )
m_sound.PlayRandom(); m_sound.PlayCopyOfRandom();
// Check this before running Update, so we draw the last frame of the finished // Check this before running Update, so we draw the last frame of the finished
// transition before sending m_MessageToSendWhenDone. // transition before sending m_MessageToSendWhenDone.