From 20d46f63c87ed4db85f3f08578d08bd5057cffdd Mon Sep 17 00:00:00 2001 From: stiffly Date: Sun, 13 Mar 2016 00:16:55 +0100 Subject: [PATCH 1/3] The main menu music would not start again when you returned to the main menu. --- include/Engine/Sound/SoundManager.h | 3 +++ src/Engine/Sound/SoundManager.cpp | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index ff9f440a..87a762fc 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -30,6 +30,7 @@ #include "../Engine/Core/EPause.h" #include "../Engine/Core/EComponentAttached.h" #include "../Core/EPlayerSpawned.h" +#include "../Engine/Network/EPlayerDisconnected.h" typedef std::pair> QueuedBuffers; @@ -139,6 +140,8 @@ private: bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e); EventRelay m_EChangeBGM; bool OnChangeBGM(const Events::ChangeBGM &e); + EventRelay m_EplayerDisconnected; + bool OnPlayerDisconnected(const Events::PlayerDisconnected& e); }; diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 2495fdd6..520a9c1d 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -30,6 +30,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker) EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity); EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM); + EVENT_SUBSCRIBE_MEMBER(m_EplayerDisconnected, &SoundManager::OnPlayerDisconnected); Events::ChangeBGM e; e.FilePath = "Audio/bgm/MenuMusic.wav"; @@ -394,7 +395,9 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e) bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) { if (m_CurrentBGM != nullptr) { - stopSound(m_CurrentBGM); + if (getSourceState(m_CurrentBGM->ALsource) == AL_PLAYING) { + stopSound(m_CurrentBGM); + } } m_CurrentBGM = createSource(e.FilePath); m_CurrentBGM->Type = SoundType::BGM; @@ -403,6 +406,22 @@ bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) return true; } + +bool SoundManager::OnPlayerDisconnected(const Events::PlayerDisconnected& e) +{ + // A player returned to the main menu. Easiest solution when we don't have states in the game. Not "PC". + if (m_CurrentBGMCombo != nullptr) { + if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) { + stopSound(m_CurrentBGMCombo); + } + } + stopSound(m_CurrentBGMCombo); + Events::ChangeBGM changeBGM; + changeBGM.FilePath = "Audio/BGM/MenuMusic.wav"; + m_EventBroker->Publish(changeBGM); + return true; +} + ALenum SoundManager::getSourceState(ALuint source) { ALenum state; From aa2475dfd61751c92b1b9ea88a5b2ee36730e10e Mon Sep 17 00:00:00 2001 From: stiffly Date: Sun, 13 Mar 2016 15:36:56 +0100 Subject: [PATCH 2/3] Stops bgm when the game is reset. --- include/Engine/Sound/SoundManager.h | 3 +++ src/Engine/Sound/SoundManager.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index 9b0e9710..869a476b 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -31,6 +31,7 @@ #include "../Engine/Core/EComponentAttached.h" #include "../Core/EPlayerSpawned.h" #include "../Engine/Network/EPlayerDisconnected.h" +#include "../Game/Events/EReset.h" typedef std::pair> QueuedBuffers; @@ -142,6 +143,8 @@ private: bool OnChangeBGM(const Events::ChangeBGM &e); EventRelay m_EplayerDisconnected; bool OnPlayerDisconnected(const Events::PlayerDisconnected& e); + EventRelay m_EReset; + bool OnReset(const Events::Reset& e); }; diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 2c238d38..a5a6cc9b 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -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; From fe090504cfb16d428494e72ed8466fcf280102b4 Mon Sep 17 00:00:00 2001 From: stiffly Date: Sun, 13 Mar 2016 17:35:05 +0100 Subject: [PATCH 3/3] Now listens to SetCamera event and the background music should be working properly. --- include/Engine/Sound/SoundManager.h | 10 ++-- src/Engine/Sound/SoundManager.cpp | 78 +++++++++++------------------ src/Game/Systems/SoundSystem.cpp | 5 -- 3 files changed, 32 insertions(+), 61 deletions(-) diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index 869a476b..894ed5bf 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -30,8 +30,7 @@ #include "../Engine/Core/EPause.h" #include "../Engine/Core/EComponentAttached.h" #include "../Core/EPlayerSpawned.h" -#include "../Engine/Network/EPlayerDisconnected.h" -#include "../Game/Events/EReset.h" +#include "../Rendering/ESetCamera.h" typedef std::pair> QueuedBuffers; @@ -93,7 +92,6 @@ private: void matchBGMLoop(); Source* m_CurrentBGM = nullptr; Source* m_CurrentBGMCombo = nullptr; - bool m_DrumLoopHasBeenStarted = false; // Logic World* m_World = nullptr; @@ -141,10 +139,8 @@ private: bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e); EventRelay m_EChangeBGM; bool OnChangeBGM(const Events::ChangeBGM &e); - EventRelay m_EplayerDisconnected; - bool OnPlayerDisconnected(const Events::PlayerDisconnected& e); - EventRelay m_EReset; - bool OnReset(const Events::Reset& e); + EventRelay m_ESetCamera; + bool OnSetCamera(const Events::SetCamera& e); }; diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index a5a6cc9b..803aadf2 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -30,12 +30,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker) EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned); 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"; - m_EventBroker->Publish(e); + EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &SoundManager::OnSetCamera); } SoundManager::~SoundManager() @@ -69,8 +64,7 @@ void SoundManager::Update(double dt) deleteInactiveEmitters(); updateEmitters(dt); updateListener(dt); - if (m_DrumLoopHasBeenStarted) - matchBGMLoop(); + matchBGMLoop(); } void SoundManager::deleteInactiveEmitters() @@ -365,15 +359,6 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e) { if (e.PlayerID == -1) { // Local player m_LocalPlayer = e.Player; - if (m_DrumLoopHasBeenStarted) { - return true; - } - m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav"); - m_CurrentBGMCombo->Type = SoundType::BGM; - alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1); - setGain(m_CurrentBGMCombo, 0); - playSound(m_CurrentBGMCombo); - m_DrumLoopHasBeenStarted = true; return true; } return false; @@ -407,37 +392,32 @@ bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) return true; } - -bool SoundManager::OnPlayerDisconnected(const Events::PlayerDisconnected& e) +bool SoundManager::OnSetCamera(const Events::SetCamera& e) { - // A player returned to the main menu. Easiest solution when we don't have states in the game. Not "PC". - if (m_CurrentBGMCombo != nullptr) { - if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) { - stopSound(m_CurrentBGMCombo); + if (e.CameraEntity.Name() == "Overview_Camera_Start_Menu") { + if (m_CurrentBGMCombo != nullptr) { + if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) { + stopSound(m_CurrentBGMCombo); + } } - } - stopSound(m_CurrentBGMCombo); - Events::ChangeBGM changeBGM; - changeBGM.FilePath = "Audio/BGM/MenuMusic.wav"; - m_EventBroker->Publish(changeBGM); - 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); + Events::ChangeBGM changeBGM; + changeBGM.FilePath = "Audio/BGM/MenuMusic.wav"; + m_EventBroker->Publish(changeBGM); + } else if (e.CameraEntity.Name() == "PickTeamCamera") { + Events::ChangeBGM changeBGM; + changeBGM.FilePath = "Audio/BGM/Layer1.wav"; + m_EventBroker->Publish(changeBGM); + if (m_CurrentBGMCombo != nullptr) { + if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) { + stopSound(m_CurrentBGMCombo); + } } + m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav"); + m_CurrentBGMCombo->Type = SoundType::BGM; + alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1); + setGain(m_CurrentBGMCombo, 0); + playSound(m_CurrentBGMCombo); } - if (m_CurrentBGM != nullptr) { - if (getSourceState(m_CurrentBGM->ALsource) == AL_PLAYING) { - stopSound(m_CurrentBGM); - } - } - return true; } ALenum SoundManager::getSourceState(ALuint source) @@ -456,14 +436,14 @@ void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundCom { float gain; switch (source->Type) { - case SoundType::SFX: - gain = m_SFXVolumeChannel; + case SoundType::SFX: + gain = m_SFXVolumeChannel; break; - case SoundType::BGM: + case SoundType::BGM: gain = m_BGMVolumeChannel; break; - case SoundType::Announcer: - gain = m_AnnouncerVolumeChannel; + case SoundType::Announcer: + gain = m_AnnouncerVolumeChannel; break; default: gain = 1.f; diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 4ee7090b..999e1fc9 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -30,11 +30,6 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e) Events::PlayAnonuncerVoice go; go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav"; m_EventBroker->Publish(go); - { - Events::ChangeBGM ev; - ev.FilePath = "Audio/BGM/Layer1.wav"; - m_EventBroker->Publish(ev); - } } return true; }