Add RageSoundManager::StopPlayingSoundsForThisThread. We

need to stop playing the sounds that a thread started before exiting
the thread, or it causes unpredictable behavior with DirectSound.
This commit is contained in:
Glenn Maynard
2004-04-07 03:47:12 +00:00
parent 960bc1eaac
commit 37de4a8898
4 changed files with 27 additions and 0 deletions
+5
View File
@@ -71,6 +71,7 @@ RageSound::RageSound()
position = 0;
stopped_position = 0;
playing = false;
playing_thread = 0;
databuf.reserve(internal_buffer_size);
/* Register ourself, so we have a unique ID and receive Update()s. */
@@ -103,6 +104,7 @@ RageSound::RageSound(const RageSound &cpy):
position = cpy.position;
stopped_position = cpy.stopped_position;
playing = false;
playing_thread = 0;
databuf.reserve(internal_buffer_size);
Sample = cpy.Sample->Copy();
@@ -579,6 +581,8 @@ void RageSound::StartPlaying()
/* Tell the sound manager to start mixing us. */
playing = true;
playing_thread = RageThread::GetCurrentThreadID();
SOUNDMAN->StartMixing(this);
SOUNDMAN->playing_sounds.insert( this );
}
@@ -598,6 +602,7 @@ void RageSound::StopPlaying()
SOUNDMAN->lock.Unlock();
playing = false;
playing_thread = 0;
pos_map.clear();
}
+4
View File
@@ -104,6 +104,7 @@ public:
bool SetPositionSeconds( float fSeconds );
CString GetLoadedFilePath() const { return m_sFilePath; }
bool IsPlaying() const { return playing; }
unsigned GetPlayingThread() const { return playing_thread; }
float GetPlaybackRate() const;
RageTimer GetStartTime() const;
@@ -158,6 +159,9 @@ private:
int stopped_position;
bool playing;
/* If playing, record the thread that called Play(). */
unsigned playing_thread;
/* Unique ID number for this instance of RageSound. */
int ID;
+14
View File
@@ -195,6 +195,20 @@ void RageSoundManager::StopPlayingAllCopiesOfSound(RageSound &snd)
}
}
void RageSoundManager::StopPlayingSoundsForThisThread()
{
/* Lock to make sure sounds don't become invalidated below before we get to them. */
LockMut(lock);
set<RageSound *> Sounds = GetPlayingSounds();
for( set<RageSound *>::iterator it = Sounds.begin(); it != Sounds.end(); ++it )
{
if( (*it)->GetPlayingThread() != RageThread::GetCurrentThreadID() )
continue;
(*it)->Stop();
}
}
void RageSoundManager::GetCopies(RageSound &snd, vector<RageSound *> &snds)
{
LockMut(lock);
+4
View File
@@ -56,6 +56,10 @@ public:
RageSound *PlaySound( RageSound &snd, const RageSoundParams *params );
void StopPlayingAllCopiesOfSound(RageSound &snd);
/* Stop all sounds that were started by this thread. This should be called
* before exiting a thread. */
void StopPlayingSoundsForThisThread();
/* A list of all sounds that currently exist. RageSound adds and removes
* itself to this. */
set<RageSound *> all_sounds;