RageSound::DeleteSelfWhenFinishedPlaying(). Replaces RageSoundManager::DeleteSoundWhenFinished, without needing to poll every sound in the list every frame and without any extra locking.
This commit is contained in:
@@ -68,6 +68,7 @@ RageSound::RageSound():
|
|||||||
m_iStreamFrame = 0;
|
m_iStreamFrame = 0;
|
||||||
m_iStoppedSourceFrame = 0;
|
m_iStoppedSourceFrame = 0;
|
||||||
m_bPlaying = false;
|
m_bPlaying = false;
|
||||||
|
m_bDeleteWhenFinished = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSound::~RageSound()
|
RageSound::~RageSound()
|
||||||
@@ -90,10 +91,15 @@ RageSound &RageSound::operator=( const RageSound &cpy )
|
|||||||
{
|
{
|
||||||
LockMut(cpy.m_Mutex);
|
LockMut(cpy.m_Mutex);
|
||||||
|
|
||||||
|
/* If m_bDeleteWhenFinished, then nobody that has a reference to the sound should
|
||||||
|
* be making copies. */
|
||||||
|
ASSERT( !cpy.m_bDeleteWhenFinished );
|
||||||
|
|
||||||
m_Param = cpy.m_Param;
|
m_Param = cpy.m_Param;
|
||||||
m_iStreamFrame = cpy.m_iStreamFrame;
|
m_iStreamFrame = cpy.m_iStreamFrame;
|
||||||
m_iStoppedSourceFrame = cpy.m_iStoppedSourceFrame;
|
m_iStoppedSourceFrame = cpy.m_iStoppedSourceFrame;
|
||||||
m_bPlaying = false;
|
m_bPlaying = false;
|
||||||
|
m_bDeleteWhenFinished = false;
|
||||||
|
|
||||||
delete m_pSource;
|
delete m_pSource;
|
||||||
if( cpy.m_pSource )
|
if( cpy.m_pSource )
|
||||||
@@ -119,6 +125,24 @@ void RageSound::Unload()
|
|||||||
m_sFilePath = "";
|
m_sFilePath = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The sound will self-delete itself when it stops playing. If the sound is not
|
||||||
|
* playing, the sound will be deleted immediately. The caller loses ownership
|
||||||
|
* of the sound. */
|
||||||
|
void RageSound::DeleteSelfWhenFinishedPlaying()
|
||||||
|
{
|
||||||
|
m_Mutex.Lock();
|
||||||
|
|
||||||
|
if( !m_bPlaying )
|
||||||
|
{
|
||||||
|
m_Mutex.Unlock();
|
||||||
|
delete this;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_bDeleteWhenFinished = true;
|
||||||
|
m_Mutex.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
bool RageSound::IsLoaded() const
|
bool RageSound::IsLoaded() const
|
||||||
{
|
{
|
||||||
return m_pSource != NULL;
|
return m_pSource != NULL;
|
||||||
@@ -359,6 +383,14 @@ void RageSound::SoundIsFinishedPlaying()
|
|||||||
|
|
||||||
m_Mutex.Lock();
|
m_Mutex.Lock();
|
||||||
|
|
||||||
|
if( m_bDeleteWhenFinished )
|
||||||
|
{
|
||||||
|
m_bDeleteWhenFinished = false;
|
||||||
|
m_Mutex.Unlock();
|
||||||
|
delete this;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Lock the mutex after calling SOUNDMAN->GetPosition(). We must not make driver
|
/* Lock the mutex after calling SOUNDMAN->GetPosition(). We must not make driver
|
||||||
* calls with our mutex locked (driver mutex < sound mutex). */
|
* calls with our mutex locked (driver mutex < sound mutex). */
|
||||||
if( !m_HardwareToStreamMap.IsEmpty() && !m_StreamToSourceMap.IsEmpty() )
|
if( !m_HardwareToStreamMap.IsEmpty() && !m_StreamToSourceMap.IsEmpty() )
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ public:
|
|||||||
|
|
||||||
void Unload();
|
void Unload();
|
||||||
bool IsLoaded() const;
|
bool IsLoaded() const;
|
||||||
|
void DeleteSelfWhenFinishedPlaying();
|
||||||
|
|
||||||
void StartPlaying();
|
void StartPlaying();
|
||||||
void StopPlaying();
|
void StopPlaying();
|
||||||
@@ -173,6 +174,7 @@ private:
|
|||||||
* position when stopped, and when playing but pos_map hasn't yet been filled. */
|
* position when stopped, and when playing but pos_map hasn't yet been filled. */
|
||||||
int m_iStoppedSourceFrame;
|
int m_iStoppedSourceFrame;
|
||||||
bool m_bPlaying;
|
bool m_bPlaying;
|
||||||
|
bool m_bDeleteWhenFinished;
|
||||||
|
|
||||||
RString m_sError;
|
RString m_sError;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user