Stops bgm when the game is reset.

This commit is contained in:
stiffly
2016-03-13 15:36:56 +01:00
parent 5c343cb254
commit aa2475dfd6
2 changed files with 21 additions and 0 deletions
+18
View File
@@ -31,6 +31,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
EVENT_SUBSCRIBE_MEMBER(m_EplayerDisconnected, &SoundManager::OnPlayerDisconnected);
EVENT_SUBSCRIBE_MEMBER(m_EReset, &SoundManager::OnReset);
Events::ChangeBGM e;
e.FilePath = "Audio/bgm/MenuMusic.wav";
@@ -422,6 +423,23 @@ bool SoundManager::OnPlayerDisconnected(const Events::PlayerDisconnected& e)
return true;
}
bool SoundManager::OnReset(const Events::Reset& e)
{
// The game was reset, stop playing the background music (drums)
if (m_CurrentBGMCombo != nullptr) {
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGMCombo);
}
}
if (m_CurrentBGM != nullptr) {
if (getSourceState(m_CurrentBGM->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGM);
}
}
return true;
}
ALenum SoundManager::getSourceState(ALuint source)
{
ALenum state;