SoundEmitter: Optimize source allocation strategy a bit

If no source is free, instead of seizing the lowest priority one,
first try to find the lowest priority source with the same buffer
that is about to be played and use it. Otherwise, take lowest priority
one as before.
This commit is contained in:
Jonas Kulla 2014-08-24 09:19:54 +02:00
parent ce72e6d0ee
commit 5ee62ba0fd
1 changed files with 7 additions and 0 deletions

View File

@ -128,6 +128,13 @@ void SoundEmitter::play(const std::string &filename,
if (AL::Source::getState(alSrcs[srcPrio[i]]) != AL_PLAYING)
break;
/* If we didn't find any, try to find the lowest priority source
* with the same buffer to overtake */
if (i == SE_SOURCES)
for (size_t j = 0; j < SE_SOURCES; ++j)
if (atchBufs[srcPrio[j]] == buffer)
i = j;
/* If we didn't find any, overtake the one with lowest priority */
if (i == SE_SOURCES)
i = 0;