SoundEmitter: Only detach/attach buffer if necessary
This commit is contained in:
parent
b1ebc655f9
commit
18c74e0f24
|
@ -144,12 +144,18 @@ void SoundEmitter::play(const std::string &filename,
|
||||||
if (i == srcCount)
|
if (i == srcCount)
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
/* Push the used source to the back of the priority list */
|
|
||||||
size_t srcIndex = srcPrio[i];
|
size_t srcIndex = srcPrio[i];
|
||||||
|
|
||||||
|
/* Only detach/reattach if it's actually a different buffer */
|
||||||
|
bool switchBuffer = (atchBufs[srcIndex] != buffer);
|
||||||
|
|
||||||
|
/* Push the used source to the back of the priority list */
|
||||||
arrayPushBack(srcPrio, srcCount, i);
|
arrayPushBack(srcPrio, srcCount, i);
|
||||||
|
|
||||||
AL::Source::ID src = alSrcs[srcIndex];
|
AL::Source::ID src = alSrcs[srcIndex];
|
||||||
AL::Source::stop(src);
|
AL::Source::stop(src);
|
||||||
|
|
||||||
|
if (switchBuffer)
|
||||||
AL::Source::detachBuffer(src);
|
AL::Source::detachBuffer(src);
|
||||||
|
|
||||||
SoundBuffer *old = atchBufs[srcIndex];
|
SoundBuffer *old = atchBufs[srcIndex];
|
||||||
|
@ -159,6 +165,7 @@ void SoundEmitter::play(const std::string &filename,
|
||||||
|
|
||||||
atchBufs[srcIndex] = SoundBuffer::ref(buffer);
|
atchBufs[srcIndex] = SoundBuffer::ref(buffer);
|
||||||
|
|
||||||
|
if (switchBuffer)
|
||||||
AL::Source::attachBuffer(src, buffer->alBuffer);
|
AL::Source::attachBuffer(src, buffer->alBuffer);
|
||||||
|
|
||||||
AL::Source::setVolume(src, _volume);
|
AL::Source::setVolume(src, _volume);
|
||||||
|
|
Loading…
Reference in New Issue