From 5ee62ba0fd18def765a9a805f2d4189e9b9b2a52 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sun, 24 Aug 2014 09:19:54 +0200 Subject: [PATCH] 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. --- src/soundemitter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/soundemitter.cpp b/src/soundemitter.cpp index 63be515..1cad920 100644 --- a/src/soundemitter.cpp +++ b/src/soundemitter.cpp @@ -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;