From a010a8be77b26479631ab5791ba27783ce51ebaf Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 22 Sep 2015 17:44:40 +0200 Subject: [PATCH] Clean-up sources. --- src/game/Sound/SoundSystem.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index e2da67a..b592c2e 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -49,12 +49,28 @@ void dd::Systems::SoundSystem::Initialize() dd::Events::PlayBGM e2; e2.path = "Sounds/BGM/water-flowing.wav"; e2.SupportBGM = true; - e2.volume = 0.1; + e2.volume = 0.3; EventBroker->Publish(e2); } void dd::Systems::SoundSystem::Update(double dt) { + //LOG_INFO("Sources : %i", m_SourcesToBuffers.size()); + + std::vector deleteList; + for (auto item : m_SourcesToBuffers) { + ALint sourceState; + alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState); + if (sourceState == AL_STOPPED) { + deleteList.push_back(item.first); + } + } + + for (int i = 0; i < deleteList.size(); i++) { + alDeleteSources(1, &deleteList[i]); + //alDeleteBuffers(1, &m_SourcesToBuffers[deleteList[i]]); + m_SourcesToBuffers.erase(deleteList[i]); + } }