FlushPosMapQueue optimization
This commit is contained in:
@@ -608,7 +608,9 @@ void RageSound::StopPlaying()
|
|||||||
/* We may still have positions queued up in RageSoundManager. We need to make sure
|
/* We may still have positions queued up in RageSoundManager. We need to make sure
|
||||||
* that we don't accept those; otherwise, if we start playing again quickly, they'll
|
* that we don't accept those; otherwise, if we start playing again quickly, they'll
|
||||||
* confuse GetPositionSeconds(). Do this by changing our ID. */
|
* confuse GetPositionSeconds(). Do this by changing our ID. */
|
||||||
|
SOUNDMAN->UnregisterSound( this );
|
||||||
ID = SOUNDMAN->GetUniqueID();
|
ID = SOUNDMAN->GetUniqueID();
|
||||||
|
SOUNDMAN->RegisterSound( this );
|
||||||
|
|
||||||
// LOG->Trace("StopPlaying %p finished (%s)", this, this->GetLoadedFilePath().c_str());
|
// LOG->Trace("StopPlaying %p finished (%s)", this, this->GetLoadedFilePath().c_str());
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ void RageSoundManager::Update(float delta)
|
|||||||
FlushPosMapQueue();
|
FlushPosMapQueue();
|
||||||
|
|
||||||
/* Scan the owned_sounds list for sounds that are no longer playing, and delete them. */
|
/* Scan the owned_sounds list for sounds that are no longer playing, and delete them. */
|
||||||
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
|
g_SoundManMutex.Lock(); /* lock for access to owned_sounds */
|
||||||
set<RageSound *> ToDelete;
|
set<RageSound *> ToDelete;
|
||||||
for( set<RageSound *>::iterator it = owned_sounds.begin(); it != owned_sounds.end(); ++it )
|
for( set<RageSound *>::iterator it = owned_sounds.begin(); it != owned_sounds.end(); ++it )
|
||||||
{
|
{
|
||||||
@@ -110,7 +110,7 @@ void RageSoundManager::Update(float delta)
|
|||||||
|
|
||||||
for( set<RageSound *>::iterator it = ToDelete.begin(); it != ToDelete.end(); ++it )
|
for( set<RageSound *>::iterator it = ToDelete.begin(); it != ToDelete.end(); ++it )
|
||||||
owned_sounds.erase( *it );
|
owned_sounds.erase( *it );
|
||||||
g_SoundManMutex.Unlock(); /* finished with owned_sounds and all_sounds */
|
g_SoundManMutex.Unlock(); /* finished with owned_sounds */
|
||||||
|
|
||||||
/* Be sure to release g_SoundManMutex before deleting sounds. */
|
/* Be sure to release g_SoundManMutex before deleting sounds. */
|
||||||
for( set<RageSound *>::iterator it = ToDelete.begin(); it != ToDelete.end(); ++it )
|
for( set<RageSound *>::iterator it = ToDelete.begin(); it != ToDelete.end(); ++it )
|
||||||
@@ -124,14 +124,14 @@ void RageSoundManager::Update(float delta)
|
|||||||
void RageSoundManager::RegisterSound( RageSound *p )
|
void RageSoundManager::RegisterSound( RageSound *p )
|
||||||
{
|
{
|
||||||
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
|
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
|
||||||
all_sounds.insert( p );
|
all_sounds[p->GetID()] = p;
|
||||||
g_SoundManMutex.Unlock(); /* finished with all_sounds */
|
g_SoundManMutex.Unlock(); /* finished with all_sounds */
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundManager::UnregisterSound( RageSound *p )
|
void RageSoundManager::UnregisterSound( RageSound *p )
|
||||||
{
|
{
|
||||||
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
|
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
|
||||||
all_sounds.erase( p );
|
all_sounds.erase( p->GetID() );
|
||||||
g_SoundManMutex.Unlock(); /* finished with all_sounds */
|
g_SoundManMutex.Unlock(); /* finished with all_sounds */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,11 +160,11 @@ RageSound *RageSoundManager::GetSoundByID( int ID )
|
|||||||
LockMut( g_SoundManMutex );
|
LockMut( g_SoundManMutex );
|
||||||
|
|
||||||
/* Find the sound with p.ID. */
|
/* Find the sound with p.ID. */
|
||||||
set<RageSound *>::iterator it;
|
map<int,RageSound *>::iterator it;
|
||||||
for( it = all_sounds.begin(); it != all_sounds.end(); ++it )
|
it = all_sounds.find( ID );
|
||||||
if( (*it)->GetID() == ID )
|
if( it == all_sounds.end() )
|
||||||
return *it;
|
return NULL;
|
||||||
return NULL;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is only called by RageSoundManager::Update. */
|
/* This is only called by RageSoundManager::Update. */
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ class RageSoundManager
|
|||||||
* when they're finished playing): */
|
* when they're finished playing): */
|
||||||
set<RageSound *> owned_sounds;
|
set<RageSound *> owned_sounds;
|
||||||
|
|
||||||
/* A list of all sounds that currently exist. */
|
/* A list of all sounds that currently exist, by ID. */
|
||||||
set<RageSound *> all_sounds;
|
map<int,RageSound *> all_sounds;
|
||||||
|
|
||||||
RageSoundDriver *driver;
|
RageSoundDriver *driver;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user