From 1bff5bb7558c32bc04cedccff0b5fb1fcc951bb1 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 21 Mar 2005 03:41:06 +0000 Subject: [PATCH] play copy of so that the Cancel sound continues playing after the transition and sample have been torn down --- stepmania/src/RandomSample.cpp | 27 ++++++++++++++++++++------- stepmania/src/RandomSample.h | 3 ++- stepmania/src/Transition.cpp | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/stepmania/src/RandomSample.cpp b/stepmania/src/RandomSample.cpp index 0774d7978a..05d121798b 100644 --- a/stepmania/src/RandomSample.cpp +++ b/stepmania/src/RandomSample.cpp @@ -3,7 +3,7 @@ #include "RageSound.h" #include "RageUtil.h" #include "RageLog.h" - +#include "RageSoundManager.h" RandomSample::RandomSample() @@ -78,14 +78,11 @@ bool RandomSample::LoadSound( CString sSoundFilePath ) return true; } -void RandomSample::PlayRandom() +int RandomSample::GetNextToPlay() { // play one of the samples if( m_pSamples.empty() ) - { -// LOG->Trace( "WARNING: Tried to play a RandomSample that has 0 sounds loaded." ); - return; - } + return -1; int iIndexToPlay = 0; for( int i=0; i<5; i++ ) @@ -95,8 +92,24 @@ void RandomSample::PlayRandom() break; } - m_pSamples[iIndexToPlay]->Play(); 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() diff --git a/stepmania/src/RandomSample.h b/stepmania/src/RandomSample.h index 0c8ca50d45..dc362ec62c 100644 --- a/stepmania/src/RandomSample.h +++ b/stepmania/src/RandomSample.h @@ -14,12 +14,13 @@ public: bool Load( CString sFilePath, int iMaxToLoad = 1000 /*load all*/ ); void UnloadAll(); void PlayRandom(); + void PlayCopyOfRandom(); void Stop(); private: bool LoadSoundDir( CString sDir, int iMaxToLoad ); bool LoadSound( CString sSoundFilePath ); - + int GetNextToPlay(); vector m_pSamples; int m_iIndexLastPlayed; diff --git a/stepmania/src/Transition.cpp b/stepmania/src/Transition.cpp index e820ea4f88..664f9bb113 100644 --- a/stepmania/src/Transition.cpp +++ b/stepmania/src/Transition.cpp @@ -53,7 +53,7 @@ void Transition::Update( float fDeltaTime ) /* Start the transition on the first update, not in the ctor, so * we don't play a sound while our parent is still loading. */ if( m_bFirstUpdate ) - m_sound.PlayRandom(); + m_sound.PlayCopyOfRandom(); // Check this before running Update, so we draw the last frame of the finished // transition before sending m_MessageToSendWhenDone.