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; }