diff --git a/assets b/assets index 1e7adc74..00329bcf 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 1e7adc749e02144615a20a82c847d3c8df46ee3d +Subproject commit 00329bcf3ed427a14e5a1450f72ba9ff49ef64e9 diff --git a/include/Engine/Sound/EChangeBGM.h b/include/Engine/Sound/EChangeBGM.h new file mode 100644 index 00000000..e60c58fc --- /dev/null +++ b/include/Engine/Sound/EChangeBGM.h @@ -0,0 +1,16 @@ +#ifndef Events_ChangeBGM_h__ +#define Events_ChangeBGM_h__ + +#include +#include "../Engine/Core/EventBroker.h" + +namespace Events +{ + +struct ChangeBGM : Event +{ + std::string FilePath = ""; +}; + +} +#endif // Events_ChangeBGM_h__ diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index ec034510..cad197a5 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -24,10 +24,12 @@ #include "../Engine/Sound/EStopSound.h" #include "../Engine/Sound/ESetBGMGain.h" #include "../Engine/Sound/ESetSFXGain.h" +#include "../Engine/Sound/EChangeBGM.h" #include "../Engine/Core/EPause.h" #include "../Engine/Core/EComponentAttached.h" #include "../Core/EPlayerSpawned.h" + typedef std::pair> QueuedBuffers; enum class SoundType { @@ -125,6 +127,8 @@ private: bool OnPlayerSpawned(const Events::PlayerSpawned &e); EventRelay m_EPlayQueueOnEntity; bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e); + EventRelay m_EChangeBGM; + bool OnChangeBGM(const Events::ChangeBGM &e); }; diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 872017fe..31861ad0 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -13,6 +13,9 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker) alDistanceModel(AL_LINEAR_DISTANCE); alDopplerFactor(1); + //m_CurrentBGM = createSource("Audio/lalala.wav"); + //playSound(m_CurrentBGM); + EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnEntity, &SoundManager::OnPlaySoundOnEntity); EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnPosition, &SoundManager::OnPlaySoundOnPosition); EVENT_SUBSCRIBE_MEMBER(m_EPlayBackgroundMusic, &SoundManager::OnPlayBackgroundMusic); @@ -59,7 +62,8 @@ void SoundManager::Update(double dt) deleteInactiveEmitters(); updateEmitters(dt); updateListener(dt); - mainMenuLoop(); + if(false) + mainMenuLoop(); } void SoundManager::deleteInactiveEmitters() @@ -171,8 +175,10 @@ Source* SoundManager::createSource(std::string filePath) void SoundManager::mainMenuLoop() { float time = getTimeOffsetSeconds(m_CurrentBGM); + //LOG_INFO("%f/%f", time, m_CurrentBGM->Duration); + // TODO: config? if (m_CurrentBGM->Duration - time <= 5) { // 5 is hard coded value that Petter recommended - m_CurrentBGM = createSource("Audio/crosscounter.wav"); + m_CurrentBGM = createSource("Audio/lalala.wav"); playSound(m_CurrentBGM); } } @@ -329,6 +335,18 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e) return true; } + +bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) +{ + if (m_CurrentBGM == nullptr) { + return false; + } + stopSound(m_CurrentBGM); + m_CurrentBGM = createSource(e.FilePath); + playSound(m_CurrentBGM); + return true; +} + ALenum SoundManager::getSourceState(ALuint source) { ALenum state; diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 7101311d..aed70584 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -114,11 +114,6 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) 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 = LocalPlayer; ev.FilePaths = paths;