From 3a5c0a27620e3bf443cbd0dab49746aaf9b3711d Mon Sep 17 00:00:00 2001 From: stiffly Date: Mon, 8 Feb 2016 14:01:32 +0100 Subject: [PATCH] SoundSystem does not longer inherit from SoundManager. SoundManager is a individual class that listens to events. The SoundManager only listens to the local player. --- include/Engine/Sound/Sound.h | 3 + include/Engine/Sound/SoundManager.h | 65 +++-------- include/Game/Game.h | 2 +- include/Game/Systems/SoundSystem.h | 40 ++++++- src/Engine/Sound/SoundManager.cpp | 165 ++++++---------------------- src/Game/Game.cpp | 5 + src/Game/Systems/SoundSystem.cpp | 119 +++++++++++++++++++- 7 files changed, 211 insertions(+), 188 deletions(-) diff --git a/include/Engine/Sound/Sound.h b/include/Engine/Sound/Sound.h index 6b2aac04..cccbdf07 100644 --- a/include/Engine/Sound/Sound.h +++ b/include/Engine/Sound/Sound.h @@ -1,6 +1,9 @@ #ifndef Sound_h__ #define Sound_h__ +#include +#include + #include "Core/ResourceManager.h" class Sound : public Resource diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index 9ba4d2ad..3923a17b 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -15,6 +15,7 @@ #include "Core/EventBroker.h" #include "Core/Transform.h" // Absolute transform #include "Sound/Sound.h" +#include "../Engine/Sound/EPlayQueueOnEntity.h" #include "Sound/EPlaySoundOnEntity.h" #include "Sound/EPlaySoundOnPosition.h" #include "Sound/EPlayBackgroundMusic.h" @@ -23,19 +24,9 @@ #include "Sound/EStopSound.h" #include "Sound/ESetBGMGain.h" #include "Sound/ESetSFXGain.h" -#include "Core/EShoot.h" -#include "Core/EPlayerSpawned.h" -#include "Input/EInputCommand.h" -#include "Core/ECaptured.h" -#include "Core/EPlayerDamage.h" -#include "Core/EPlayerDeath.h" -#include "Core/EPlayerHealthPickup.h" -#include "Core/EComponentAttached.h" -#include "Collision/ETrigger.h" #include "Core/EPause.h" -#include "Game/Events/EDoubleJump.h" -#include "Game/Events/EDashAbility.h" - +#include "Core/EComponentAttached.h" +#include "../Core/EPlayerSpawned.h" typedef std::pair> QueuedBuffers; @@ -61,20 +52,6 @@ public: // Update emitters / listener void Update(double dt); -protected: - // Specific logic - void playSound(Source* source); - // Need to be the same format (sample rate etc) - void playQueue(QueuedBuffers qb); - void stopSound(Source* source); - void playerJumps(); - void playerStep(double dt); - EntityID createChildEmitter(EntityWrapper localPlayer); - - // Logic - World* m_World = nullptr; - EventBroker* m_EventBroker = nullptr; - private: // Help functions for working with OpenaAL void setListenerPos(glm::vec3 pos) { alListener3f(AL_POSITION, pos.x, pos.y, pos.z); }; @@ -92,25 +69,30 @@ private: void deleteInactiveEmitters(); void stopEmitters(); void updateListener(double dt); - Source* createSource(std::string filePath); ALenum getSourceState(ALuint source); void setGain(Source* source, float gain); void setSoundProperties(Source* source, ComponentWrapper* soundComponent); + // Specific logic + void playSound(Source* source); + // Need to be the same format (sample rate etc) + void playQueue(QueuedBuffers qb); + void stopSound(Source* source); + Source* createSource(std::string filePath); std::unordered_map m_Sources; + // Logic + World* m_World = nullptr; + EventBroker* m_EventBroker = nullptr; // OpenAL system variables ALCdevice* m_ALCdevice = nullptr; ALCcontext* m_ALCcontext = nullptr; - - float m_BGMVolumeChannel = 1.0f; float m_SFXVolumeChannel = 1.0f; bool m_EditorEnabled = false; EntityWrapper m_LocalPlayer = EntityWrapper(); - std::default_random_engine generator; // Events EventRelay m_EPlaySoundOnEntity; @@ -129,31 +111,16 @@ private: bool OnSetBGMGain(const Events::SetBGMGain &e); EventRelay m_ESetSFXGain; bool OnSetSFXGain(const Events::SetSFXGain &e); - EventRelay m_EShoot; - bool OnShoot(const Events::Shoot &e); - EventRelay m_EPlayerSpawned; - bool OnPlayerSpawned(const Events::PlayerSpawned &e); - EventRelay m_ECaptured; - bool OnCaptured(const Events::Captured &e); - EventRelay m_EPlayerDamage; - bool OnPlayerDamage(const Events::PlayerDamage &e); - EventRelay m_EPlayerDeath; - bool OnPlayerDeath(const Events::PlayerDeath &e); - EventRelay m_EPlayerHealthPickup; - bool OnPlayerHealthPickup(const Events::PlayerHealthPickup &e); EventRelay m_EComponentAttached; bool OnComponentAttached(const Events::ComponentAttached &e); - EventRelay m_ETriggerTouch; - bool OnTriggerTouch(const Events::TriggerTouch &e); EventRelay m_EPause; bool OnPause(const Events::Pause &e); EventRelay m_EResume; bool OnResume(const Events::Resume &e); - EventRelay m_EDoubleJump; - bool OnDoubleJump(const Events::DoubleJump &e); - EventRelay m_EDashAbility; - bool OnDashAbility(const Events::DashAbility &e); - + EventRelay m_EPlayerSpawned; + bool OnPlayerSpawned(const Events::PlayerSpawned &e); + EventRelay m_EPlayQueueOnEntity; + bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e); }; diff --git a/include/Game/Game.h b/include/Game/Game.h index b6a2c0d3..6177a818 100644 --- a/include/Game/Game.h +++ b/include/Game/Game.h @@ -30,7 +30,7 @@ #include "Network/Client.h" // Sound -//#include "Sound/SoundManager.h" +#include "Sound/SoundManager.h" #include "Systems/SoundSystem.h" class Game diff --git a/include/Game/Systems/SoundSystem.h b/include/Game/Systems/SoundSystem.h index 77ebcfa1..b14d7486 100644 --- a/include/Game/Systems/SoundSystem.h +++ b/include/Game/Systems/SoundSystem.h @@ -1,13 +1,29 @@ #ifndef Systems_SoundSystem_h__ #define Systems_SoundSystem_h__ +#include + #include "../Engine/Core/System.h" -#include "../Engine/Sound/SoundManager.h" +#include "../Engine/Core/ResourceManager.h" +#include "../Engine/Sound/Sound.h" +#include "../Engine/Sound/EPlayQueueOnEntity.h" #include "../Engine/Core/EPlayerSpawned.h" #include "../Engine/Input/EInputCommand.h" +#include "../Engine/Core/EShoot.h" +#include "../Engine/Core/EPlayerSpawned.h" +#include "../Engine/Input/EInputCommand.h" +#include "../Engine/Core/ECaptured.h" +#include "../Engine/Core/EPlayerDamage.h" +#include "../Engine/Core/EPlayerDeath.h" +#include "../Engine/Core/EPlayerHealthPickup.h" +#include "../Engine/Collision/ETrigger.h" +#include "../Engine/Sound/EPlaySoundOnEntity.h" +#include "../Engine/Sound/EPlayBackgroundMusic.h" +#include "../Game/Events/EDoubleJump.h" +#include "../Game/Events/EDashAbility.h" -class SoundSystem : public PureSystem, ImpureSystem, SoundManager +class SoundSystem : public PureSystem, ImpureSystem { public: SoundSystem(World* world, EventBroker* eventbroker); @@ -23,6 +39,8 @@ private: // Logic for playing a sound when a player jumps void playerJumps(); + // Helper function + EntityID createChildEmitter(EntityWrapper parent); // Walking logic // Keeps track of how far the player has walked within this "key press session". @@ -34,10 +52,28 @@ private: // Determine what sound file to play. bool m_LeftFoot = false; + std::default_random_engine generator; + EventRelay m_EPlayerSpawned; bool OnPlayerSpawned(const Events::PlayerSpawned &e); EventRelay m_InputCommand; bool OnInputCommand(const Events::InputCommand &e); + EventRelay m_EDoubleJump; + bool OnDoubleJump(const Events::DoubleJump &e); + EventRelay m_EDashAbility; + bool OnDashAbility(const Events::DashAbility &e); + EventRelay m_ETriggerTouch; + bool OnTriggerTouch(const Events::TriggerTouch &e); + EventRelay m_EShoot; + bool OnShoot(const Events::Shoot &e); + EventRelay m_ECaptured; + bool OnCaptured(const Events::Captured &e); + EventRelay m_EPlayerDamage; + bool OnPlayerDamage(const Events::PlayerDamage &e); + EventRelay m_EPlayerDeath; + bool OnPlayerDeath(const Events::PlayerDeath &e); + EventRelay m_EPlayerHealthPickup; + bool OnPlayerHealthPickup(const Events::PlayerHealthPickup &e); }; #endif diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 7046ecc1..d75e9afc 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -20,16 +20,11 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker, bool editorMo EVENT_SUBSCRIBE_MEMBER(m_EContinueSound, &SoundManager::OnContinueSound); EVENT_SUBSCRIBE_MEMBER(m_ESetBGMGain, &SoundManager::OnSetBGMGain); EVENT_SUBSCRIBE_MEMBER(m_ESetSFXGain, &SoundManager::OnSetSFXGain); - EVENT_SUBSCRIBE_MEMBER(m_EShoot, &SoundManager::OnShoot); - EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned); - EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundManager::OnPlayerDamage); - EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundManager::OnCaptured); - EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundManager::OnTriggerTouch); EVENT_SUBSCRIBE_MEMBER(m_EPause, &SoundManager::OnPause); EVENT_SUBSCRIBE_MEMBER(m_EResume, &SoundManager::OnResume); EVENT_SUBSCRIBE_MEMBER(m_EComponentAttached, &SoundManager::OnComponentAttached); - EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundManager::OnDoubleJump); - EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundManager::OnDashAbility); + EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned); + EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity); } SoundManager::~SoundManager() @@ -135,18 +130,21 @@ void SoundManager::updateListener(double dt) { // Should only be one listener. auto listenerComponents = m_World->GetComponents("Listener"); - if (listenerComponents == nullptr) { + if (listenerComponents == nullptr || !m_LocalPlayer.Valid()) { return; } for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) { - EntityID listener = (*it).EntityID; - glm::vec3 previousPos; - alGetListener3f(AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z); // Get previous pos - glm::vec3 nextPos = Transform::AbsolutePosition(m_World, listener); // Get next (current) pos - glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; // Calculate velocity - setListenerPos(nextPos); - setListenerVel(velocity); - setListenerOri(glm::eulerAngles(Transform::AbsoluteOrientation(m_World, listener))); + EntityWrapper listener(m_World, (*it).EntityID); + if (listener.IsChildOf(m_LocalPlayer) || listener == m_LocalPlayer) { + glm::vec3 previousPos; + alGetListener3f(AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z); // Get previous pos + glm::vec3 nextPos = Transform::AbsolutePosition(listener); // Get next (current) pos + glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; // Calculate velocity + setListenerPos(nextPos); + setListenerVel(velocity); + setListenerOri(glm::eulerAngles(Transform::AbsoluteOrientation(listener))); + break; + } } } @@ -181,21 +179,6 @@ void SoundManager::stopSound(Source* source) alSourceStop(source->ALsource); } - - -void SoundManager::playerStep(double dt) -{ - -} - -EntityID SoundManager::createChildEmitter(EntityWrapper localPlayer) -{ - EntityID child = m_World->CreateEntity(localPlayer.ID); - m_World->AttachComponent(child, "Transform"); - m_World->AttachComponent(child, "SoundEmitter"); - return child; -} - bool SoundManager::OnPlaySoundOnEntity(const Events::PlaySoundOnEntity & e) { Source* source = createSource(e.FilePath); @@ -272,87 +255,6 @@ bool SoundManager::OnSetSFXGain(const Events::SetSFXGain & e) return true; } -bool SoundManager::OnShoot(const Events::Shoot & e) -{ - Source* source = createSource("Audio/laser/laser1.wav"); - //auto emitterID = m_World->CreateEntity(e.Player.ID); - //m_World->AttachComponent(emitterID, "Transform"); - //auto emitter = m_World->AttachComponent(emitterID, "SoundEmitter"); - source->Type = SoundType::SFX; - m_Sources[createChildEmitter(m_LocalPlayer)] = source; - playSound(source); - return true; -} - -bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned & e) -{ - if (e.PlayerID == -1) { // Local player - m_World->AttachComponent(e.Player.ID, "Listener"); - m_LocalPlayer.ID = e.Player.ID; - } - return true; -} - - -bool SoundManager::OnCaptured(const Events::Captured & e) -{ - int homeTeam = (int)m_World->GetComponent(e.CapturePointID, "Team")["Team"]; - int team = (int)m_World->GetComponent(m_LocalPlayer.ID, "Team")["Team"]; - Events::PlaySoundOnEntity ev; - if (team == homeTeam) { - ev.FilePath = "Audio/announcer/objective_achieved.wav"; - } else { - ev.FilePath = "Audio/announcer/objective_failed.wav"; // have not been tested - } - ev.EmitterID = createChildEmitter(m_LocalPlayer); - m_EventBroker->Publish(ev); - return false; -} - -bool SoundManager::OnPlayerDamage(const Events::PlayerDamage & e) -{ - // Should check for only local players here... - - std::uniform_int_distribution dist(1, 12); - int rand = dist(generator); - Source* source = createSource("Audio/hurt/hurt" + std::to_string(rand) + ".wav"); - source->Type = SoundType::SFX; - m_Sources[createChildEmitter(m_LocalPlayer)] = source; - - // Breathe - std::vector buffers; - buffers.push_back(source->SoundResource->Buffer()); - int ammountOfbreaths = (static_cast(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit - for (int i = 0; i < ammountOfbreaths; i++) { - buffers.push_back(ResourceManager::Load("Audio/exhausted/breath.wav")->Buffer()); - } - playQueue(QueuedBuffers(std::make_pair(source->ALsource, buffers))); - - return false; -} - -bool SoundManager::OnPlayerDeath(const Events::PlayerDeath & e) -{ - if (e.PlayerID == m_LocalPlayer.ID) { - Events::PlaySoundOnEntity ev; - ev.EmitterID = createChildEmitter(m_LocalPlayer); - ev.FilePath = "Audio/die/die2.wav"; // should random between a bunch - m_EventBroker->Publish(ev); - } - return false; -} - -bool SoundManager::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e) -{ - if (e.PlayerHealedID == m_LocalPlayer.ID) { - Events::PlaySoundOnEntity ev; - ev.EmitterID = createChildEmitter(m_LocalPlayer); - ev.FilePath = "Audio/pickup/pickup2.wav"; - m_EventBroker->Publish(ev); - } - return false; -} - bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e) { if (e.Component.Info.Name == "SoundEmitter") { @@ -363,16 +265,6 @@ bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e) return false; } -bool SoundManager::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; -} - bool SoundManager::OnPause(const Events::Pause & e) { for (auto it = m_Sources.begin(); it != m_Sources.end(); it++) { @@ -389,22 +281,29 @@ bool SoundManager::OnResume(const Events::Resume &e) return false; } -bool SoundManager::OnDoubleJump(const Events::DoubleJump & e) + +bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e) { - Events::PlaySoundOnEntity ev; - ev.EmitterID = createChildEmitter(m_LocalPlayer); - ev.FilePath = "Audio/jump/jump2.wav"; - m_EventBroker->Publish(ev); + if (e.PlayerID == -1) { // Local player + m_LocalPlayer = e.Player; + return true; + } return false; } -bool SoundManager::OnDashAbility(const Events::DashAbility &e) + +bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e) { - Events::PlaySoundOnEntity ev; - ev.EmitterID = createChildEmitter(m_LocalPlayer); - ev.FilePath = "Audio/jump/dash1.wav"; - m_EventBroker->Publish(ev); - return false; + Source* source = createSource(*e.FilePaths.begin()); + std::vector buffers; + buffers.push_back(source->SoundResource->Buffer()); + source->Type = SoundType::BGM; + std::vector::const_iterator it; + for (it = e.FilePaths.begin() + 1; it != e.FilePaths.end(); it++) { + buffers.push_back(ResourceManager::Load(*it)->Buffer()); + } + playQueue(QueuedBuffers(source->ALsource, buffers)); + return true; } ALenum SoundManager::getSourceState(ALuint source) diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 541aa001..d18aaf8d 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -71,6 +71,8 @@ Game::Game(int argc, char* argv[]) fp.MergeEntities(m_World); } + // Create the sound manager + m_SoundManager = new SoundManager(m_World, m_EventBroker, true); // Create Octrees m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4); @@ -123,6 +125,7 @@ Game::~Game() delete m_OctreeFrustrumCulling; delete m_OctreeCollision; delete m_OctreeTrigger; + delete m_SoundManager; delete m_World; delete m_FrameStack; delete m_InputProxy; @@ -150,6 +153,8 @@ void Game::Tick() m_InputProxy->Process(); m_EventBroker->Swap(); + m_SoundManager->Update(dt); + // Update network if (m_IsClientOrServer) { m_ClientOrServer->Update(); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 06e028f2..3f9b75d0 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -4,12 +4,18 @@ SoundSystem::SoundSystem(World* world, EventBroker* eventbroker) : System(world, eventbroker) , PureSystem("SoundEmitter") , ImpureSystem() - , SoundManager(world, eventbroker, true) { m_World = world; m_EventBroker = eventbroker; EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &SoundSystem::OnInputCommand); + EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump); + EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundSystem::OnDashAbility); + EVENT_SUBSCRIBE_MEMBER(m_EShoot, &SoundSystem::OnShoot); + EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned); + EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage); + EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured); + EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch); } void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt) @@ -20,8 +26,6 @@ void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComp void SoundSystem::Update(double dt) { playerStep(dt); - // Update listener and emitters. - SoundManager::Update(dt); } void SoundSystem::playerStep(double dt) @@ -83,6 +87,12 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e) m_DistanceMoved = 0.f; } } + if (e.Command == "TakeDamage" && e.Value > 0) { + Events::PlayerDamage ev; + ev.Player = m_LocalPlayer; + ev.Damage = 1.0; + m_EventBroker->Publish(ev); + } return false; } @@ -97,3 +107,106 @@ void SoundSystem::playerJumps() m_EventBroker->Publish(e); } } + +bool SoundSystem::OnShoot(const Events::Shoot & e) +{ + Events::PlaySoundOnEntity ev; + ev.EmitterID = createChildEmitter(m_LocalPlayer); + ev.FilePath = "Audio/laser/laser1.wav"; + m_EventBroker->Publish(ev); + return true; +} + +bool SoundSystem::OnCaptured(const Events::Captured & e) +{ + int homeTeam = (int)m_World->GetComponent(e.CapturePointID, "Team")["Team"]; + int team = (int)m_World->GetComponent(m_LocalPlayer.ID, "Team")["Team"]; + Events::PlaySoundOnEntity ev; + if (team == homeTeam) { + ev.FilePath = "Audio/announcer/objective_achieved.wav"; + } else { + ev.FilePath = "Audio/announcer/objective_failed.wav"; // have not been tested + } + ev.EmitterID = createChildEmitter(m_LocalPlayer); + m_EventBroker->Publish(ev); + return false; +} + +// Testing purposes atm... +bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) +{ + // Should check for only local players here... + std::uniform_int_distribution dist(1, 12); + int rand = dist(generator); + std::vector paths; + paths.push_back("Audio/hurt/hurt" + std::to_string(rand) + ".wav"); + + // Breathe + int ammountOfbreaths = (static_cast(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit + for (int i = 0; i < ammountOfbreaths; i++) { + paths.push_back("Audio/exhausted/breath.wav"); + } + Events::PlayQueueOnEntity ev; + ev.Emitter = m_LocalPlayer; + ev.FilePaths = paths; + m_EventBroker->Publish(ev); + return false; +} + +bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) +{ + if (e.PlayerID == m_LocalPlayer.ID) { + Events::PlaySoundOnEntity ev; + ev.EmitterID = createChildEmitter(m_LocalPlayer); + ev.FilePath = "Audio/die/die2.wav"; // should random between a bunch + m_EventBroker->Publish(ev); + } + return false; +} + +bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e) +{ + if (e.PlayerHealedID == m_LocalPlayer.ID) { + Events::PlaySoundOnEntity ev; + ev.EmitterID = createChildEmitter(m_LocalPlayer); + ev.FilePath = "Audio/pickup/pickup2.wav"; + m_EventBroker->Publish(ev); + } + 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; +} + +bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e) +{ + Events::PlaySoundOnEntity ev; + ev.EmitterID = createChildEmitter(m_LocalPlayer); + ev.FilePath = "Audio/jump/jump2.wav"; + m_EventBroker->Publish(ev); + return false; +} + +bool SoundSystem::OnDashAbility(const Events::DashAbility &e) +{ + Events::PlaySoundOnEntity ev; + ev.EmitterID = createChildEmitter(m_LocalPlayer); + ev.FilePath = "Audio/jump/dash1.wav"; + m_EventBroker->Publish(ev); + return false; +} + +EntityID SoundSystem::createChildEmitter(EntityWrapper localPlayer) +{ + EntityID child = m_World->CreateEntity(localPlayer.ID); + m_World->AttachComponent(child, "Transform"); + m_World->AttachComponent(child, "SoundEmitter"); + return child; +} \ No newline at end of file