From 67dffafe5abc5094ecb76e78a754e06c7931754b Mon Sep 17 00:00:00 2001 From: stiffly Date: Fri, 26 Feb 2016 16:44:08 +0100 Subject: [PATCH] Drumloop will now play when a team is about to win --- assets | 2 +- include/Engine/Sound/SoundManager.h | 3 ++ src/Engine/Sound/SoundManager.cpp | 48 ++++++++++++++++++++++++----- src/Game/Systems/SoundSystem.cpp | 24 +++++++-------- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/assets b/assets index 00329bcf..cea183a0 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 00329bcf3ed427a14e5a1450f72ba9ff49ef64e9 +Subproject commit cea183a06a5dfbcb5ea9c0a3e76175c2e4b07bb2 diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index 9a4d68f2..fe5b4189 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -89,7 +89,10 @@ private: Source* createSource(std::string filePath); std::unordered_map m_Sources; void mainMenuLoop(); + void matchBGMLoop(); Source* m_CurrentBGM; + Source* m_CurrentBGMCombo; + bool m_TempPleaseDeleteMeASAP = false; // Logic World* m_World = nullptr; diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 7b6fef79..940572c4 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -66,7 +66,9 @@ void SoundManager::Update(double dt) deleteInactiveEmitters(); updateEmitters(dt); updateListener(dt); - if(false) + if (m_TempPleaseDeleteMeASAP) + matchBGMLoop(); + if (false) mainMenuLoop(); } @@ -187,6 +189,30 @@ void SoundManager::mainMenuLoop() } } +void SoundManager::matchBGMLoop() +{ + if (m_CurrentBGMCombo == nullptr) + return; + auto cCapturePoints = m_World->GetComponents("CapturePoint"); + for (auto it = cCapturePoints->begin(); it != cCapturePoints->end(); it++) { + float timeCaptured = (float)(double)(*it)["CaptureTimer"]; + float maxTimer = (float)(double)(*it)["CapturePointMaxTimer"]; + int capturePointIndex = (int)(*it)["CapturePointNumber"]; + + if (capturePointIndex == 0) { // Home for red team + if (timeCaptured < 0 && glm::abs(timeCaptured) < maxTimer) { + float gain = glm::abs(timeCaptured) / maxTimer; + setGain(m_CurrentBGMCombo, gain); + } + } else if (capturePointIndex == 4) { // Home for blue team + if (timeCaptured > 0 && timeCaptured < maxTimer) { + float gain = timeCaptured / maxTimer; + setGain(m_CurrentBGMCombo, gain); + } + } + } +} + void SoundManager::playSound(Source* source) { alSourcei(source->ALsource, AL_BUFFER, source->SoundResource->Buffer()); @@ -260,7 +286,7 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e) auto listenerComponents = m_World->GetComponents("Listener"); for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) { if ((*it).EntityID != m_LocalPlayer.ID) { - break; + continue;; } auto emitterChild = m_World->CreateEntity((*it).EntityID); auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter"); @@ -348,6 +374,15 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e) { if (e.PlayerID == -1) { // Local player m_LocalPlayer = e.Player; + if (m_TempPleaseDeleteMeASAP) { + return true; + } + m_CurrentBGMCombo = createSource("Audio/bgm/nearWin.wav"); + m_CurrentBGMCombo->Type = SoundType::BGM; + alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1); + setGain(m_CurrentBGMCombo, 0); + playSound(m_CurrentBGMCombo); + m_TempPleaseDeleteMeASAP = true; return true; } return false; @@ -368,7 +403,6 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e) return true; } - bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) { if (m_CurrentBGM == nullptr) { @@ -396,10 +430,10 @@ void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundCom { float gain; switch (source->Type) { - case SoundType::SFX: gain = m_SFXVolumeChannel; break; - case SoundType::BGM: gain = m_BGMVolumeChannel; break; - case SoundType::Announcer: gain = m_AnnouncerVolumeChannel; break; - default: gain = 1.f; break; + case SoundType::SFX: gain = m_SFXVolumeChannel; break; + case SoundType::BGM: gain = m_BGMVolumeChannel; break; + case SoundType::Announcer: gain = m_AnnouncerVolumeChannel; break; + default: gain = 1.f; break; } alSourcef(source->ALsource, AL_GAIN, (float)(double)(*soundComponent)["Gain"] * gain); alSourcef(source->ALsource, AL_PITCH, (float)(double)(*soundComponent)["Pitch"]); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 8135eb56..20336548 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -139,18 +139,18 @@ bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e) bool SoundSystem::OnTriggerTouch(const Events::TriggerTouch & e) { - // Temp for play test. - if (m_DrumsIsPlaying) { - return false; - } - if (m_World->HasComponent(e.Trigger.ID, "CapturePoint")) { - Events::PlaySoundOnEntity ev; // should be BGM - ev.EmitterID = LocalPlayer.ID; - ev.FilePath = "Audio/bgm/drumstest.wav"; - m_EventBroker->Publish(ev); - // Temp for play test. - m_DrumsIsPlaying = true; - } + //// Temp for play test. + //if (m_DrumsIsPlaying) { + // return false; + //} + //if (m_World->HasComponent(e.Trigger.ID, "CapturePoint")) { + // Events::PlaySoundOnEntity ev; // should be BGM + // ev.EmitterID = LocalPlayer.ID; + // ev.FilePath = "Audio/bgm/drumstest.wav"; + // m_EventBroker->Publish(ev); + // // Temp for play test. + // m_DrumsIsPlaying = true; + //} return false; }