diff --git a/include/Sound/EPlayBGM.h b/include/Sound/EPlayBGM.h deleted file mode 100644 index 7fdc059..0000000 --- a/include/Sound/EPlayBGM.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef EVENTS_EPLAYBGM_H__ -#define EVENTS_EPLAYBGM_H__ - -#include "Core/EventBroker.h" - -namespace dd -{ - -namespace Events -{ - -struct PlayBGM : public Event -{ - std::string path; - float volume = 1; - //TODO: Rethink this - bool SupportBGM; -}; - -} - -} - -#endif - diff --git a/include/Sound/EPlaySFX.h b/include/Sound/EPlaySFX.h index 2d038f7..8ab697a 100644 --- a/include/Sound/EPlaySFX.h +++ b/include/Sound/EPlaySFX.h @@ -30,6 +30,8 @@ namespace Events struct PlaySFX : Event { std::string path; + float volume = 1.f; + bool loop = false; }; } diff --git a/include/Sound/SoundSystem.h b/include/Sound/SoundSystem.h index 4468c9d..5a68300 100644 --- a/include/Sound/SoundSystem.h +++ b/include/Sound/SoundSystem.h @@ -8,7 +8,6 @@ #include "Core/World.h" #include "Sound.h" #include "Sound/EPlaySFX.h" -#include "Sound/EPlayBGM.h" #include "Physics/EContact.h" #include "Core/EventBroker.h" #include "Game/CBall.h" @@ -37,10 +36,8 @@ private: //Events dd::EventRelay m_EPlaySFX; dd::EventRelay m_EContact; - dd::EventRelay m_EPlayBGM; bool OnPlaySFX(const dd::Events::PlaySFX &event); bool OnContact(const dd::Events::Contact &event); - bool OnPlayBGM(const dd::Events::PlayBGM &event); ALuint CreateSource(); diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index b592c2e..db60ea9 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -38,19 +38,21 @@ void dd::Systems::SoundSystem::Initialize() //Subscribe to events EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact); EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySFX); - EVENT_SUBSCRIBE_MEMBER(m_EPlayBGM, &SoundSystem::OnPlayBGM); //Todo: Move this - dd::Events::PlayBGM e; - e.path = "Sounds/BGM/soft-guitar.wav"; - e.SupportBGM = false; - EventBroker->Publish(e); - - dd::Events::PlayBGM e2; - e2.path = "Sounds/BGM/water-flowing.wav"; - e2.SupportBGM = true; - e2.volume = 0.3; - EventBroker->Publish(e2); + { + dd::Events::PlaySFX e; + e.path = "Sounds/BGM/soft-guitar.wav"; + e.loop = true; + EventBroker->Publish(e); + } + { + dd::Events::PlaySFX e; + e.path = "Sounds/BGM/water-flowing.wav"; + e.volume = 0.3f; + e.loop = true; + EventBroker->Publish(e); + } } void dd::Systems::SoundSystem::Update(double dt) @@ -74,31 +76,28 @@ void dd::Systems::SoundSystem::Update(double dt) } -bool dd::Systems::SoundSystem::OnPlayBGM(const dd::Events::PlayBGM &event) -{ - Sound *sound = ResourceManager::Load(event.path); - ALuint buffer = sound->Buffer(); - ALuint source = CreateSource(); - - alSourcei(source, AL_BUFFER, buffer); - alSourcei(source, AL_LOOPING, AL_TRUE); - alSourcef(source, AL_GAIN, event.volume); - alSourcePlay(source); - - m_SourcesToBuffers[source] = buffer; -} - bool dd::Systems::SoundSystem::OnPlaySFX(const dd::Events::PlaySFX &event) { + //Loading and binding sound buffer to source Sound *sound = ResourceManager::Load(event.path); ALuint buffer = sound->Buffer(); ALuint source = CreateSource(); - - alSourcei(source, AL_BUFFER, buffer); - alSourcei(source, AL_LOOPING, AL_FALSE); - alSourcePlay(source); - m_SourcesToBuffers[source] = buffer; + alSourcei(source, AL_BUFFER, buffer); + + //Sound settings + alSourcef(source, AL_GAIN, event.volume); + if (event.loop) { + alSourcei(source, AL_LOOPING, AL_TRUE); + } + else if (!event.loop) + { + alSourcei(source, AL_LOOPING, AL_FALSE); + } + + + //Play + alSourcePlay(source); } bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)