From a64d227cab6889e127f97d2022776176ce228d2f Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 3 Feb 2016 10:17:53 +0100 Subject: [PATCH] Assured the volume channels were working. Playing around with drumloop --- assets | 2 +- include/Engine/Sound/SoundSystem.h | 13 ++++++--- src/Engine/Sound/SoundSystem.cpp | 42 +++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/assets b/assets index 5bf03ccd..cde9a430 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 5bf03ccd54bed358d525840635573f931adf584e +Subproject commit cde9a43029fe674a01ede2b74a1987cd57f1074a diff --git a/include/Engine/Sound/SoundSystem.h b/include/Engine/Sound/SoundSystem.h index e161af77..9e636c95 100644 --- a/include/Engine/Sound/SoundSystem.h +++ b/include/Engine/Sound/SoundSystem.h @@ -9,6 +9,8 @@ #include "OpenAL/al.h" #include "OpenAL/alc.h" +#include "imgui/imgui.h" + #include "Core/World.h" #include "Core/EventBroker.h" #include "Core/Transform.h" // Absolute transform @@ -29,6 +31,7 @@ #include "Core/EPlayerDeath.h" #include "Core/EPlayerHealthPickup.h" #include "Core/EComponentAttached.h" +#include "Collision/ETrigger.h" enum class SoundType { SFX, @@ -90,8 +93,11 @@ private: World* m_World = nullptr; EventBroker* m_EventBroker = nullptr; std::unordered_map m_Sources; - float m_BGMVolumeChannel = 1.f; - float m_SFXVolumeChannel = 1.f; + + + + float m_BGMVolumeChannel = 1.0f; + float m_SFXVolumeChannel = 1.0f; bool m_EditorEnabled = false; const double m_PlayerFootstepInterval = 1.0; double m_TimeSinceLastFootstep = 0; @@ -117,7 +123,6 @@ private: bool OnSetBGMGain(const Events::SetBGMGain &e); // Not tested EventRelay m_ESetSFXGain; bool OnSetSFXGain(const Events::SetSFXGain &e); // Not tested - EventRelay m_EShoot; bool OnShoot(const Events::Shoot &e); EventRelay m_EPlayerSpawned; @@ -134,6 +139,8 @@ private: bool OnPlayerHealthPickup(const Events::PlayerHealthPickup &e); EventRelay m_EComponentAttached; bool OnComponentAttached(const Events::ComponentAttached &e); + EventRelay m_ETriggerTouch; + bool OnTriggerTouch(const Events::TriggerTouch &e); diff --git a/src/Engine/Sound/SoundSystem.cpp b/src/Engine/Sound/SoundSystem.cpp index e5684ac3..08e5c0a8 100644 --- a/src/Engine/Sound/SoundSystem.cpp +++ b/src/Engine/Sound/SoundSystem.cpp @@ -25,6 +25,7 @@ SoundSystem::SoundSystem(World* world, EventBroker* eventBroker, bool editorMode EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage); EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SoundSystem::OnInputCommand); EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured); + EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch); } SoundSystem::~SoundSystem() @@ -60,6 +61,10 @@ void SoundSystem::Update(double dt) deleteInactiveEmitters(); // can be optimized with "EEntityDeleted" updateEmitters(dt); updateListener(dt); + + // Editor debug info + ImGui::SliderFloat("BGM", &m_BGMVolumeChannel, 0.0f, 1.0f, "%.3f", 1.0f); + ImGui::SliderFloat("SFX", &m_SFXVolumeChannel, 0.0f, 1.0f, "%.3f", 1.0f); } void SoundSystem::deleteInactiveEmitters() @@ -287,11 +292,12 @@ bool SoundSystem::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e) for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) { auto emitterChild = m_World->CreateEntity((*it).EntityID); auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter"); - (bool&)emitter["Loop"] = true; + (bool&)emitter["Loop"] = false; (std::string&)emitter["FilePath"] = e.FilePath; m_World->AttachComponent(emitterChild, "Transform"); Source* source = createSource(e.FilePath); source->Type = SoundType::BGM; + setSoundProperties(source, &emitter); m_Sources[emitterChild] = source; playSound(source); } @@ -334,6 +340,12 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned & e) event.EmitterID = child; event.FilePath = "Audio/announcer/go.wav"; m_EventBroker->Publish(event); + // TEMP: starts bgm + { + Events::PlayBackgroundMusic ev; + ev.FilePath = "Audio/bgm/ambient.wav"; + m_EventBroker->Publish(ev); + } } return true; } @@ -384,15 +396,15 @@ bool SoundSystem::OnCaptured(const Events::Captured & e) bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) { //if (e.Player.ID == m_LocalPlayer) { - Events::PlaySoundOnEntity ev; - EntityID child = m_World->CreateEntity(m_LocalPlayer); - m_World->AttachComponent(child, "Transform"); - m_World->AttachComponent(child, "SoundEmitter"); - ev.EmitterID = child; - std::uniform_int_distribution dist(1, 12); - int rand = dist(generator); - ev.FilePath = "Audio/hurt/hurt" + std::to_string(rand) + ".wav"; - m_EventBroker->Publish(ev); + Events::PlaySoundOnEntity ev; + EntityID child = m_World->CreateEntity(m_LocalPlayer); + m_World->AttachComponent(child, "Transform"); + m_World->AttachComponent(child, "SoundEmitter"); + ev.EmitterID = child; + std::uniform_int_distribution dist(1, 12); + int rand = dist(generator); + ev.FilePath = "Audio/hurt/hurt" + std::to_string(rand) + ".wav"; + m_EventBroker->Publish(ev); //} return false; } @@ -433,6 +445,16 @@ bool SoundSystem::OnComponentAttached(const Events::ComponentAttached & e) return false; } +bool SoundSystem::OnTriggerTouch(const Events::TriggerTouch & e) +{ + if (m_World->HasComponent(e.Trigger.ID, "CapturePoint")) { + Events::PlayBackgroundMusic ev; + ev.FilePath = "Audio/bgm/drumstest.wav"; + m_EventBroker->Publish(ev); + } + return false; +} + void SoundSystem::setListenerOri(glm::vec3 ori) { // Calculate forward and up vector.