From f72dea3852d461452482b1eefe9f25cf75e0cc2d Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 24 Feb 2016 11:51:06 +0100 Subject: [PATCH 01/19] Added a system that will handle BGM. Created specific logic for sounds to loop like Petter wants. --- include/Engine/Sound/SoundManager.h | 37 +++++++++--------- include/Game/Systems/BackgroundMusicSystem.h | 21 ++++++++++ src/Engine/Sound/SoundManager.cpp | 40 +++++++++++++++++--- src/Game/Systems/BackgroundMusicSystem.cpp | 23 +++++++++++ 4 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 include/Game/Systems/BackgroundMusicSystem.h create mode 100644 src/Game/Systems/BackgroundMusicSystem.cpp diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index 5b027c62..ec034510 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -9,25 +9,23 @@ #include "OpenAL/al.h" #include "OpenAL/alc.h" -#include "imgui/imgui.h" - -#include "Core/World.h" -#include "Core/EventBroker.h" +#include "../Engine/Core/World.h" +#include "../Engine/Core/EventBroker.h" #include "../Engine/Core/ResourceManager.h" #include "../Engine/Core/ConfigFile.h" -#include "Core/Transform.h" // Absolute transform -#include "Sound/Sound.h" +#include "../Engine/Core/Transform.h" +#include "../Engine/Sound/Sound.h" #include "../Engine/Sound/EPlayQueueOnEntity.h" -#include "Sound/EPlaySoundOnEntity.h" -#include "Sound/EPlaySoundOnPosition.h" -#include "Sound/EPlayBackgroundMusic.h" -#include "Sound/EPauseSound.h" -#include "Sound/EContinueSound.h" -#include "Sound/EStopSound.h" -#include "Sound/ESetBGMGain.h" -#include "Sound/ESetSFXGain.h" -#include "Core/EPause.h" -#include "Core/EComponentAttached.h" +#include "../Engine/Sound/EPlaySoundOnEntity.h" +#include "../Engine/Sound/EPlaySoundOnPosition.h" +#include "../Engine/Sound/EPlayBackgroundMusic.h" +#include "../Engine/Sound/EPauseSound.h" +#include "../Engine/Sound/EContinueSound.h" +#include "../Engine/Sound/EStopSound.h" +#include "../Engine/Sound/ESetBGMGain.h" +#include "../Engine/Sound/ESetSFXGain.h" +#include "../Engine/Core/EPause.h" +#include "../Engine/Core/EComponentAttached.h" #include "../Core/EPlayerSpawned.h" typedef std::pair> QueuedBuffers; @@ -43,6 +41,7 @@ struct Source Sound* SoundResource = nullptr; ALuint ALsource; SoundType Type; + float Duration; }; class SoundManager @@ -74,14 +73,18 @@ private: ALenum getSourceState(ALuint source); void setGain(Source* source, float gain); void setSoundProperties(Source* source, ComponentWrapper* soundComponent); + float getDurationSeconds(Source* source); + float getTimeOffsetSeconds(Source* source); // Specific logic void playSound(Source* source); - // Need to be the same format (sample rate etc) + // Needs 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; + void mainMenuLoop(); + Source* m_CurrentBGM; // Logic World* m_World = nullptr; diff --git a/include/Game/Systems/BackgroundMusicSystem.h b/include/Game/Systems/BackgroundMusicSystem.h new file mode 100644 index 00000000..243b0f61 --- /dev/null +++ b/include/Game/Systems/BackgroundMusicSystem.h @@ -0,0 +1,21 @@ +#ifndef Systems_BackgroundMusicSystem_h__ +#define Systems_BackgroundMusicSystem_h__ + +#include "../Engine/Core/System.h" +#include "../Engine/Core/EventBroker.h" + +// Handles transitions between BGM's depending on the current state of the game. +class BackgroundMusicSystem : public PureSystem +{ +public: + BackgroundMusicSystem(SystemParams params); + ~BackgroundMusicSystem(); + void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cEmitter, double dt) override; + +private: + void mainMenuLoop(); + + const std::string menu = "Audio/crosscounter.wav"; +}; + +#endif // ifndef diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 8e103d5c..872017fe 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -56,13 +56,10 @@ void SoundManager::stopEmitters() void SoundManager::Update(double dt) { m_EventBroker->Process(); - deleteInactiveEmitters(); // can be optimized with "EEntityDeleted" + deleteInactiveEmitters(); 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); + mainMenuLoop(); } void SoundManager::deleteInactiveEmitters() @@ -166,9 +163,20 @@ Source* SoundManager::createSource(std::string filePath) Source* source = new Source(); source->ALsource = alSource; source->SoundResource = ResourceManager::Load(filePath); + source->Duration = getDurationSeconds(source); return source; } + +void SoundManager::mainMenuLoop() +{ + float time = getTimeOffsetSeconds(m_CurrentBGM); + if (m_CurrentBGM->Duration - time <= 5) { // 5 is hard coded value that Petter recommended + m_CurrentBGM = createSource("Audio/crosscounter.wav"); + playSound(m_CurrentBGM); + } +} + void SoundManager::playSound(Source* source) { alSourcei(source->ALsource, AL_BUFFER, source->SoundResource->Buffer()); @@ -338,12 +346,32 @@ void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundCom float gain = (source->Type == SoundType::SFX) ? m_SFXVolumeChannel : m_BGMVolumeChannel; alSourcef(source->ALsource, AL_GAIN, (float)(double)(*soundComponent)["Gain"] * gain); alSourcef(source->ALsource, AL_PITCH, (float)(double)(*soundComponent)["Pitch"]); - alSourcei(source->ALsource, AL_LOOPING, (int)(bool)(*soundComponent)["Loop"]); // YOLO + alSourcei(source->ALsource, AL_LOOPING, (int)(bool)(*soundComponent)["Loop"]); alSourcef(source->ALsource, AL_MAX_DISTANCE, (float)(double)(*soundComponent)["MaxDistance"]); alSourcef(source->ALsource, AL_ROLLOFF_FACTOR, (float)(double)(*soundComponent)["RollOffFactor"]); alSourcef(source->ALsource, AL_REFERENCE_DISTANCE, (float)(double)(*soundComponent)["ReferenceDistance"]); } +float SoundManager::getDurationSeconds(Source* source) +{ + ALuint buffer = source->SoundResource->Buffer(); + ALint sizeBytes, channels, bits, frequenzy; + alGetBufferi(buffer, AL_SIZE, &sizeBytes); + alGetBufferi(buffer, AL_CHANNELS, &channels); + alGetBufferi(buffer, AL_BITS, &bits); + alGetBufferi(buffer, AL_FREQUENCY, &frequenzy); + float sampleLength = (float)sizeBytes * 8 / (channels * bits); + return (sampleLength / frequenzy); +} + + +float SoundManager::getTimeOffsetSeconds(Source* source) +{ + float time; + alGetSourcef(source->ALsource, AL_SEC_OFFSET, &time); + return time; +} + void SoundManager::initOpenAL() { // Initialize OpenAL diff --git a/src/Game/Systems/BackgroundMusicSystem.cpp b/src/Game/Systems/BackgroundMusicSystem.cpp new file mode 100644 index 00000000..d37427b9 --- /dev/null +++ b/src/Game/Systems/BackgroundMusicSystem.cpp @@ -0,0 +1,23 @@ +#include "../Game/Systems/BackgroundMusicSystem.h" + +BackgroundMusicSystem::BackgroundMusicSystem(SystemParams params) + : System(params) + , PureSystem("SoundEmitter") +{ + +} + +BackgroundMusicSystem::~BackgroundMusicSystem() +{ + +} + +void BackgroundMusicSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cEmitter, double dt) +{ + +} + +void BackgroundMusicSystem::mainMenuLoop() +{ + +} From 9783f9c65072eed0be81690974327401f63f494f Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 24 Feb 2016 14:18:42 +0100 Subject: [PATCH 02/19] Added an event to change the background music. --- assets | 2 +- include/Engine/Sound/EChangeBGM.h | 16 ++++++++++++++++ include/Engine/Sound/SoundManager.h | 4 ++++ src/Engine/Sound/SoundManager.cpp | 22 ++++++++++++++++++++-- src/Game/Systems/SoundSystem.cpp | 5 ----- 5 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 include/Engine/Sound/EChangeBGM.h 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; From cf3d1b5b007918173702c6d352c062e96163f904 Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 24 Feb 2016 14:19:38 +0100 Subject: [PATCH 03/19] Changed the default reference distance for emitters. Should be heard all over the map --- resources/Schema/Components/SoundEmitter.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/Schema/Components/SoundEmitter.xml b/resources/Schema/Components/SoundEmitter.xml index e0a38d2f..def00cfc 100644 --- a/resources/Schema/Components/SoundEmitter.xml +++ b/resources/Schema/Components/SoundEmitter.xml @@ -4,7 +4,7 @@ 1.0 1.0 false - 20.0 + 220.0 1.0 1.0 \ No newline at end of file From 7dbb9e452b68a3776ed9a0116f68ab4ad473deee Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 24 Feb 2016 15:08:39 +0100 Subject: [PATCH 04/19] Added a announcer volume channel. --- include/Engine/Sound/EPlayAnnouncerVoice.h | 17 +++++++++ include/Engine/Sound/ESetAnnouncerGain.h | 16 +++++++++ include/Engine/Sound/SoundManager.h | 10 +++++- include/Game/Systems/SoundSystem.h | 1 + resources/DefaultConfig.ini | 1 + src/Engine/Sound/SoundManager.cpp | 41 +++++++++++++++++++++- src/Game/Systems/SoundSystem.cpp | 6 ++-- 7 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 include/Engine/Sound/EPlayAnnouncerVoice.h create mode 100644 include/Engine/Sound/ESetAnnouncerGain.h diff --git a/include/Engine/Sound/EPlayAnnouncerVoice.h b/include/Engine/Sound/EPlayAnnouncerVoice.h new file mode 100644 index 00000000..18d1a953 --- /dev/null +++ b/include/Engine/Sound/EPlayAnnouncerVoice.h @@ -0,0 +1,17 @@ +#ifndef Events_PlayAnnouncerVoice_h__ +#define Events_PlayAnnouncerVoice_h__ + +#include +#include "../Engine/Core/EventBroker.h" + +namespace Events +{ + +struct PlayAnonuncerVoice : public Event +{ + std::string FilePath = ""; +}; + +} + +#endif diff --git a/include/Engine/Sound/ESetAnnouncerGain.h b/include/Engine/Sound/ESetAnnouncerGain.h new file mode 100644 index 00000000..2149be80 --- /dev/null +++ b/include/Engine/Sound/ESetAnnouncerGain.h @@ -0,0 +1,16 @@ +#ifndef Events_SetAnnouncerGain_h__ +#define Events_SetAnnouncerGain_h__ + +#include "../Engine/Core/EventBroker.h" + +namespace Events +{ + +struct SetAnnouncerGain : public Event +{ + float Gain = 1; +}; + +} + +#endif // diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index cad197a5..9a4d68f2 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -19,11 +19,13 @@ #include "../Engine/Sound/EPlaySoundOnEntity.h" #include "../Engine/Sound/EPlaySoundOnPosition.h" #include "../Engine/Sound/EPlayBackgroundMusic.h" +#include "../Engine/Sound/EPlayAnnouncerVoice.h" #include "../Engine/Sound/EPauseSound.h" #include "../Engine/Sound/EContinueSound.h" #include "../Engine/Sound/EStopSound.h" #include "../Engine/Sound/ESetBGMGain.h" #include "../Engine/Sound/ESetSFXGain.h" +#include "../Engine/Sound/ESetAnnouncerGain.h" #include "../Engine/Sound/EChangeBGM.h" #include "../Engine/Core/EPause.h" #include "../Engine/Core/EComponentAttached.h" @@ -34,7 +36,8 @@ typedef std::pair> QueuedBuffers; enum class SoundType { SFX, - BGM + BGM, + Announcer }; struct Source @@ -98,6 +101,7 @@ private: float m_BGMVolumeChannel = 1.0f; float m_SFXVolumeChannel = 1.0f; + float m_AnnouncerVolumeChannel = 1.0f; EntityWrapper m_LocalPlayer = EntityWrapper(); // Events @@ -107,6 +111,8 @@ private: bool OnPlaySoundOnPosition(const Events::PlaySoundOnPosition &e); EventRelay m_EPlayBackgroundMusic; bool OnPlayBackgroundMusic(const Events::PlayBackgroundMusic &e); + EventRelay m_EPlayAnnouncerVoice; + bool OnPlayAnnouncerVoice(const Events::PlayAnonuncerVoice& e); EventRelay m_EPauseSound; bool OnPauseSound(const Events::PauseSound &e); EventRelay m_EStopSound; @@ -117,6 +123,8 @@ private: bool OnSetBGMGain(const Events::SetBGMGain &e); EventRelay m_ESetSFXGain; bool OnSetSFXGain(const Events::SetSFXGain &e); + EventRelay m_ESetAnnouncerGain; + bool OnSetAnnouncerGain(const Events::SetAnnouncerGain& e); EventRelay m_EComponentAttached; bool OnComponentAttached(const Events::ComponentAttached &e); EventRelay m_EPause; diff --git a/include/Game/Systems/SoundSystem.h b/include/Game/Systems/SoundSystem.h index 962eb085..37e78d32 100644 --- a/include/Game/Systems/SoundSystem.h +++ b/include/Game/Systems/SoundSystem.h @@ -20,6 +20,7 @@ #include "../Engine/Collision/ETrigger.h" #include "../Engine/Sound/EPlaySoundOnEntity.h" #include "../Engine/Sound/EPlayBackgroundMusic.h" +#include "../Engine/Sound/EPlayAnnouncerVoice.h" #include "../Game/Events/EDoubleJump.h" #include "../Game/Events/EDashAbility.h" diff --git a/resources/DefaultConfig.ini b/resources/DefaultConfig.ini index 60ee4823..c118070b 100644 --- a/resources/DefaultConfig.ini +++ b/resources/DefaultConfig.ini @@ -36,4 +36,5 @@ ResourceLoading=true [Sound] BGMVolume=1.0 SFXVolume=1.0 +AnnouncerVolume=1.0 Announcer=female \ No newline at end of file diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 31861ad0..7b6fef79 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -7,6 +7,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker) m_World = world; m_BGMVolumeChannel = config->Get("Sound.BGMVolume", 1.f); m_SFXVolumeChannel = config->Get("Sound.SFXVolume", 1.f); + m_AnnouncerVolumeChannel = config->Get("Sound.AnnouncerVolume", 1.f); initOpenAL(); alSpeedOfSound(340.29f); @@ -19,16 +20,19 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker) EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnEntity, &SoundManager::OnPlaySoundOnEntity); EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnPosition, &SoundManager::OnPlaySoundOnPosition); EVENT_SUBSCRIBE_MEMBER(m_EPlayBackgroundMusic, &SoundManager::OnPlayBackgroundMusic); + EVENT_SUBSCRIBE_MEMBER(m_EPlayAnnouncerVoice, &SoundManager::OnPlayAnnouncerVoice); EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundManager::OnStopSound); EVENT_SUBSCRIBE_MEMBER(m_EPauseSound, &SoundManager::OnPauseSound); 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_ESetAnnouncerGain, &SoundManager::OnSetAnnouncerGain); 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_EPlayerSpawned, &SoundManager::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity); + EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM); } SoundManager::~SoundManager() @@ -272,6 +276,28 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e) return true; } + +bool SoundManager::OnPlayAnnouncerVoice(const Events::PlayAnonuncerVoice& e) +{ + auto listenerComponents = m_World->GetComponents("Listener"); + for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) { + if ((*it).EntityID != m_LocalPlayer.ID) { + break; + } + auto emitterChild = m_World->CreateEntity((*it).EntityID); + auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter"); + (bool&)emitter["Loop"] = false; + (std::string&)emitter["FilePath"] = e.FilePath; + m_World->AttachComponent(emitterChild, "Transform"); + Source* source = createSource(e.FilePath); + source->Type = SoundType::Announcer; + setSoundProperties(source, &emitter); + m_Sources[emitterChild] = source; + playSound(source); + } + return true; +} + bool SoundManager::OnSetBGMGain(const Events::SetBGMGain & e) { m_BGMVolumeChannel = e.Gain; @@ -284,6 +310,13 @@ bool SoundManager::OnSetSFXGain(const Events::SetSFXGain & e) return true; } + +bool SoundManager::OnSetAnnouncerGain(const Events::SetAnnouncerGain& e) +{ + m_AnnouncerVolumeChannel = e.Gain; + return true; +} + bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e) { if (e.Component.Info.Name == "SoundEmitter") { @@ -361,7 +394,13 @@ void SoundManager::setGain(Source * source, float gain) void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundComponent) { - float gain = (source->Type == SoundType::SFX) ? m_SFXVolumeChannel : m_BGMVolumeChannel; + 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; + } alSourcef(source->ALsource, AL_GAIN, (float)(double)(*soundComponent)["Gain"] * gain); alSourcef(source->ALsource, AL_PITCH, (float)(double)(*soundComponent)["Pitch"]); alSourcei(source->ALsource, AL_LOOPING, (int)(bool)(*soundComponent)["Loop"]); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index aed70584..8135eb56 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -36,8 +36,7 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e) { if (e.PlayerID == -1) { // Local player m_World->AttachComponent(e.Player.ID, "Listener"); - Events::PlaySoundOnEntity go; - go.EmitterID = LocalPlayer.ID; + Events::PlayAnonuncerVoice go; go.FilePath = "Audio/announcer/" + m_Announcer + "/go.wav"; m_EventBroker->Publish(go); // TEMP: starts bgm @@ -92,13 +91,12 @@ bool SoundSystem::OnCaptured(const Events::Captured & e) { int homeTeam = (int)m_World->GetComponent(e.CapturePointID, "Team")["Team"]; int team = (int)m_World->GetComponent(LocalPlayer.ID, "Team")["Team"]; - Events::PlaySoundOnEntity ev; + Events::PlayAnonuncerVoice ev; if (team == homeTeam) { ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_achieved.wav"; } else { ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_failed.wav"; // have not been tested } - ev.EmitterID = LocalPlayer.ID; m_EventBroker->Publish(ev); // Temp for play test. m_DrumsIsPlaying = false; From 67dffafe5abc5094ecb76e78a754e06c7931754b Mon Sep 17 00:00:00 2001 From: stiffly Date: Fri, 26 Feb 2016 16:44:08 +0100 Subject: [PATCH 05/19] 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; } From 4fd578c764262a4392e34138a3df710722cc57f1 Mon Sep 17 00:00:00 2001 From: stiffly Date: Mon, 29 Feb 2016 16:26:09 +0100 Subject: [PATCH 06/19] Removed logic that's no longer needed. --- assets | 2 +- include/Engine/Sound/SoundManager.h | 1 - include/Game/Systems/SoundSystem.h | 5 ----- src/Engine/Sound/SoundManager.cpp | 16 +--------------- src/Game/Systems/SoundSystem.cpp | 20 +------------------- 5 files changed, 3 insertions(+), 41 deletions(-) diff --git a/assets b/assets index cea183a0..d72b3b4b 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit cea183a06a5dfbcb5ea9c0a3e76175c2e4b07bb2 +Subproject commit d72b3b4b47cb6a1de8d8ccc94ff9640b3d1e0d56 diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index fe5b4189..3452917c 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -88,7 +88,6 @@ private: void stopSound(Source* source); Source* createSource(std::string filePath); std::unordered_map m_Sources; - void mainMenuLoop(); void matchBGMLoop(); Source* m_CurrentBGM; Source* m_CurrentBGMCombo; diff --git a/include/Game/Systems/SoundSystem.h b/include/Game/Systems/SoundSystem.h index 37e78d32..3826b62a 100644 --- a/include/Game/Systems/SoundSystem.h +++ b/include/Game/Systems/SoundSystem.h @@ -35,11 +35,6 @@ private: std::string m_Announcer = ""; // Logic for playing a sound when a player jumps void playerJumps(); - - // Temporary solution for play test. - bool m_DrumsIsPlaying = false; - double m_DrumTimer = 0.0; - bool drumTimer(double dt); std::default_random_engine generator; diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 940572c4..272cb89e 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -68,8 +68,6 @@ void SoundManager::Update(double dt) updateListener(dt); if (m_TempPleaseDeleteMeASAP) matchBGMLoop(); - if (false) - mainMenuLoop(); } void SoundManager::deleteInactiveEmitters() @@ -177,18 +175,6 @@ Source* SoundManager::createSource(std::string filePath) return source; } - -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/lalala.wav"); - playSound(m_CurrentBGM); - } -} - void SoundManager::matchBGMLoop() { if (m_CurrentBGMCombo == nullptr) @@ -377,7 +363,7 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e) if (m_TempPleaseDeleteMeASAP) { return true; } - m_CurrentBGMCombo = createSource("Audio/bgm/nearWin.wav"); + m_CurrentBGMCombo = createSource("Audio/bgm/layer2.wav"); m_CurrentBGMCombo->Type = SoundType::BGM; alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1); setGain(m_CurrentBGMCombo, 0); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 20336548..9020895d 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -25,11 +25,6 @@ void SoundSystem::Update(double dt) if (!IsClient) { return; } - - // Temp for play test. - if (m_DrumsIsPlaying) { - m_DrumsIsPlaying = !drumTimer(dt); - } } bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e) @@ -42,7 +37,7 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e) // TEMP: starts bgm { Events::PlayBackgroundMusic ev; - ev.FilePath = "Audio/bgm/ambient.wav"; + ev.FilePath = "Audio/bgm/layer1.wav"; m_EventBroker->Publish(ev); } } @@ -76,17 +71,6 @@ void SoundSystem::playerJumps() } } -bool SoundSystem::drumTimer(double dt) -{ - m_DrumTimer += dt; - if (m_DrumTimer > 15) { - m_DrumTimer = 0.0; - return true; - } else { - return false; - } -} - bool SoundSystem::OnCaptured(const Events::Captured & e) { int homeTeam = (int)m_World->GetComponent(e.CapturePointID, "Team")["Team"]; @@ -98,8 +82,6 @@ bool SoundSystem::OnCaptured(const Events::Captured & e) ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_failed.wav"; // have not been tested } m_EventBroker->Publish(ev); - // Temp for play test. - m_DrumsIsPlaying = false; return false; } From d3ffb9768bceec9bad79ce54f6447373848e6a4f Mon Sep 17 00:00:00 2001 From: stiffly Date: Tue, 1 Mar 2016 14:47:57 +0100 Subject: [PATCH 07/19] Sets velocity to 0, does not make use of doppler effect atm --- include/Game/Systems/SoundSystem.h | 4 -- .../Systems/Weapon/DefenderWeaponBehaviour.h | 1 + src/Engine/Sound/SoundManager.cpp | 2 +- src/Game/Systems/SoundSystem.cpp | 65 ++++++++----------- .../Weapon/DefenderWeaponBehaviour.cpp | 4 ++ 5 files changed, 34 insertions(+), 42 deletions(-) diff --git a/include/Game/Systems/SoundSystem.h b/include/Game/Systems/SoundSystem.h index 3826b62a..003c6f66 100644 --- a/include/Game/Systems/SoundSystem.h +++ b/include/Game/Systems/SoundSystem.h @@ -44,10 +44,6 @@ private: 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_ECaptured; bool OnCaptured(const Events::Captured &e); EventRelay m_EPlayerDamage; diff --git a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h index 5ca13d3e..c4b814a1 100644 --- a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h @@ -2,6 +2,7 @@ #include "Collision/Collision.h" #include "Core/EPlayerDamage.h" #include "Rendering/ESetCamera.h" +#include "Sound/EPlaySoundOnEntity.h" class DefenderWeaponBehaviour : public WeaponBehaviour { diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 272cb89e..d271e260 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -122,7 +122,7 @@ void SoundManager::updateEmitters(double dt) // Calculate velocity glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; setSourcePos(it->second->ALsource, nextPos); - setSourceVel(it->second->ALsource, velocity); + setSourceVel(it->second->ALsource, glm::vec3(0)); auto emitter = m_World->GetComponent(it->first, "SoundEmitter"); setSoundProperties(it->second, &emitter); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index a79711ae..c446ee3c 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -6,16 +6,14 @@ SoundSystem::SoundSystem(SystemParams params) { ConfigFile* config = ResourceManager::Load("Config.ini"); m_Announcer = ResourceManager::Load("Config.ini")->Get("Sound.Announcer", "female"); - if (IsClient) { - 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_EPlayerDamage, &SoundSystem::OnPlayerDamage); - EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured); - EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch); - EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &SoundSystem::OnPlayerDeath); - } + + 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_EPlayerDamage, &SoundSystem::OnPlayerDamage); + EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured); + EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &SoundSystem::OnPlayerDeath); + } void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt) @@ -52,6 +50,19 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e) playerJumps(); return true; } + } + if (e.Command == "SoundTemp" && e.Value > 0) { + EntityWrapper entity(m_World, m_World->CreateEntity()); + auto transform = m_World->AttachComponent(entity.ID, "Transform"); + (glm::vec3&)transform["Position"] = glm::vec3(0, 10, 0); + (glm::vec3&)transform["Scale"] = glm::vec3(10, 10, 10); + auto emitter = m_World->AttachComponent(entity.ID, "SoundEmitter"); + auto model = m_World->AttachComponent(entity.ID, "Model"); + (std::string&)model["Resource"] = "Models/Core/UnitCube.mesh"; + Events::PlaySoundOnEntity ev; + ev.EmitterID = entity.ID; + ev.FilePath = "Audio/crosscounter.wav"; + m_EventBroker->Publish(ev); } return false; @@ -136,37 +147,17 @@ bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e) return false; } -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; - //} - return false; -} - bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e) { + if (!m_World->ValidEntity(e.entityID)) { + return false; + } + if (!IsClient) { + return false; + } Events::PlaySoundOnEntity ev; - ev.EmitterID = LocalPlayer.ID; + ev.EmitterID = e.entityID; ev.FilePath = "Audio/jump/jump2.wav"; m_EventBroker->Publish(ev); return false; -} - -bool SoundSystem::OnDashAbility(const Events::DashAbility &e) -{ - Events::PlaySoundOnEntity ev; - ev.EmitterID = LocalPlayer.ID; - ev.FilePath = "Audio/jump/dash1.wav"; - m_EventBroker->Publish(ev); - return false; } \ No newline at end of file diff --git a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp index 028bd10c..fbc6e37c 100644 --- a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp @@ -86,6 +86,10 @@ void DefenderWeaponBehaviour::fireShell(WeaponInfo& wi) } if (weaponModelEntity.Valid()) { EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle"); + Events::PlaySoundOnEntity e; + e.EmitterID = weaponModelEntity.ID; + e.FilePath = "Audio/laser/laser1.wav"; + m_EventBroker->Publish(e); for (auto& angles : pelletAngles) { glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1); float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction); From b7fac7103d4f0aaa8463ff43c0a3be0fa5e0e5ba Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 2 Mar 2016 11:26:06 +0100 Subject: [PATCH 08/19] More reasonable distance to hear sounds by other players. Modeified by rolloff factor. --- resources/Schema/Components/SoundEmitter.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/Schema/Components/SoundEmitter.xml b/resources/Schema/Components/SoundEmitter.xml index 23420219..f74183c2 100644 --- a/resources/Schema/Components/SoundEmitter.xml +++ b/resources/Schema/Components/SoundEmitter.xml @@ -5,6 +5,6 @@ 1.0 false 220.0 - 5.0 + 10 1.0 \ No newline at end of file From 3613d66d32bd66cd61b26c4d20ed2f48302624cf Mon Sep 17 00:00:00 2001 From: stiffly Date: Thu, 3 Mar 2016 20:24:48 +0100 Subject: [PATCH 09/19] The EPlaySoundOnEntity event now has support to set the gain on the sound. It now also uses EntityWrapper instead of EntityID. --- include/Engine/Sound/EPlaySoundOnEntity.h | 3 ++- src/Engine/Sound/SoundManager.cpp | 6 ++++-- src/Game/Systems/PlayerMovementSystem.cpp | 2 +- src/Game/Systems/SoundSystem.cpp | 17 +++++++++-------- .../Systems/Weapon/DefenderWeaponBehaviour.cpp | 7 +++++-- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/Engine/Sound/EPlaySoundOnEntity.h b/include/Engine/Sound/EPlaySoundOnEntity.h index 39dea432..12be68b9 100644 --- a/include/Engine/Sound/EPlaySoundOnEntity.h +++ b/include/Engine/Sound/EPlaySoundOnEntity.h @@ -12,7 +12,8 @@ namespace Events // Sound behavior is thereby specified in the SoundEmitter component. struct PlaySoundOnEntity : public Event { - EntityID EmitterID = 0; + EntityWrapper Emitter = EntityWrapper::Invalid; + float Gain = 1.f; std::string FilePath = ""; }; diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 57b710cf..ae1c79ce 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -222,10 +222,12 @@ bool SoundManager::OnPlaySoundOnEntity(const Events::PlaySoundOnEntity & e) { Source* source = createSource(e.FilePath); source->Type = SoundType::SFX; - EntityID child = m_World->CreateEntity(e.EmitterID); + EntityID child = m_World->CreateEntity(e.Emitter.ID); m_World->AttachComponent(child, "Transform"); - m_World->AttachComponent(child, "SoundEmitter"); + auto cEmitter = m_World->AttachComponent(child, "SoundEmitter"); + (double&)(float)cEmitter["Gain"] = e.Gain; m_Sources[child] = source; + setGain(source, cEmitter["Gain"]); playSound(source); return false; } diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 72008e05..2a973a51 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -287,7 +287,7 @@ void PlayerMovementSystem::playerStep(double dt) // Player moved a step's distance // Create footstep sound Events::PlaySoundOnEntity e; - e.EmitterID = m_LocalPlayer.ID; + e.Emitter = m_LocalPlayer; e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav"; m_LeftFoot = !m_LeftFoot; m_EventBroker->Publish(e); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 93ab4469..de221f36 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -60,7 +60,7 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e) auto model = m_World->AttachComponent(entity.ID, "Model"); (std::string&)model["Resource"] = "Models/Core/UnitCube.mesh"; Events::PlaySoundOnEntity ev; - ev.EmitterID = entity.ID; + ev.Emitter = entity; ev.FilePath = "Audio/crosscounter.wav"; m_EventBroker->Publish(ev); } @@ -77,7 +77,7 @@ void SoundSystem::playerJumps() bool grounded = (bool)m_World->GetComponent(LocalPlayer.ID, "Physics")["IsOnGround"]; if (grounded) { Events::PlaySoundOnEntity e; - e.EmitterID = LocalPlayer.ID; + e.Emitter = LocalPlayer; e.FilePath = "Audio/Jump/Jump1.wav"; m_EventBroker->Publish(e); } @@ -106,7 +106,7 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) if (!IsClient) { // Only play for clients return false; } - if (LocalPlayer.ID = e.Victim.ID) { // You're local player was the one who took dmg + if(!e.Victim.Valid()) { return false; } std::uniform_int_distribution dist(1, 12); @@ -115,7 +115,7 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) paths.push_back("Audio/Hurt/Hurt" + std::to_string(rand) + ".wav"); Events::PlayQueueOnEntity ev; - ev.Emitter = LocalPlayer; + ev.Emitter = e.Victim; ev.FilePaths = paths; m_EventBroker->Publish(ev); return false; @@ -123,7 +123,7 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) { - if (e.Player.ID != LocalPlayer.ID) { + if (!e.Player.Valid()) { return false; } if (!IsClient) { @@ -132,7 +132,8 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) // The local player is dead. The local player might be invalid? // Play the sound from the listener. // TODO: We might want to hear other players die. - Events::PlayBackgroundMusic ev; + Events::PlaySoundOnEntity ev; + ev.Emitter = e.Player; ev.FilePath = "Audio/Die/Die2.wav"; m_EventBroker->Publish(ev); return false; @@ -141,7 +142,7 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e) { Events::PlaySoundOnEntity ev; - ev.EmitterID = LocalPlayer.ID; + ev.Emitter = LocalPlayer; ev.FilePath = "Audio/Pickup/Pickup2.wav"; m_EventBroker->Publish(ev); return false; @@ -156,7 +157,7 @@ bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e) return false; } Events::PlaySoundOnEntity ev; - ev.EmitterID = e.entityID; + ev.Emitter = EntityWrapper(m_World, e.entityID); ev.FilePath = "Audio/Jump/Jump2.wav"; m_EventBroker->Publish(ev); return false; diff --git a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp index f148f6de..08678177 100644 --- a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp @@ -87,9 +87,12 @@ void DefenderWeaponBehaviour::fireShell(WeaponInfo& wi) if (weaponModelEntity.Valid()) { EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle"); Events::PlaySoundOnEntity e; - e.EmitterID = weaponModelEntity.ID; + e.Emitter = weaponModelEntity; e.FilePath = "Audio/weapon/Shotgun/ShotgunFire.wav"; - m_EventBroker->Publish(e); + e.Gain = 1.f; + if (IsClient) { + m_EventBroker->Publish(e); + } for (auto& angles : pelletAngles) { glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1); float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction); From 1227a795d791b30d5fcfca8dd720249633e97302 Mon Sep 17 00:00:00 2001 From: stiffly Date: Thu, 3 Mar 2016 21:23:53 +0100 Subject: [PATCH 10/19] WIP --- include/Game/Systems/PlayerMovementSystem.h | 2 +- src/Game/Systems/PlayerMovementSystem.cpp | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index bf7b4718..f84aed96 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -31,7 +31,7 @@ private: // To get a difference when calculating the walking state. glm::vec3 m_LastPosition = glm::vec3(); // The logic for making the sound play when player is moving - void playerStep(double dt); + void playerStep(double dt, EntityWrapper player); // Spawn a hexagon at origin of an Entity void spawnHexagon(EntityWrapper target); diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 31e5aacf..1d176146 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -242,10 +242,9 @@ void PlayerMovementSystem::updateMovementControllers(double dt) } } } - + playerStep(dt, player); controller->Reset(); } - playerStep(dt); } @@ -281,11 +280,8 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt) position += velocity * (float)dt; } -void PlayerMovementSystem::playerStep(double dt) +void PlayerMovementSystem::playerStep(double dt, EntityWrapper player) { - if (!m_LocalPlayer.Valid()) { - return; - } // Position of the local player, used see how far a player has moved. glm::vec3 pos = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Transform")["Position"]; // Used to see if a player is airborne. @@ -298,7 +294,7 @@ void PlayerMovementSystem::playerStep(double dt) // Create footstep sound Events::PlaySoundOnEntity e; e.Emitter = m_LocalPlayer; - e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav"; + e.FilePath = m_LeftFoot ? "Audio/Footstep/Footstep2.wav" : "Audio/Footstep/Footstep3.wav"; m_LeftFoot = !m_LeftFoot; m_EventBroker->Publish(e); m_DistanceMoved = 0.f; From a7c57da2c94268576f91b7084bea521d93213b14 Mon Sep 17 00:00:00 2001 From: stiffly Date: Fri, 4 Mar 2016 03:03:38 +0100 Subject: [PATCH 11/19] WIP --- src/Engine/Sound/SoundManager.cpp | 5 +---- src/Game/Systems/SoundSystem.cpp | 24 +++--------------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index ae1c79ce..f5403740 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -14,9 +14,6 @@ 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); @@ -122,7 +119,7 @@ void SoundManager::updateEmitters(double dt) // Calculate velocity glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; setSourcePos(it->second->ALsource, nextPos); - setSourceVel(it->second->ALsource, glm::vec3(0)); + //setSourceVel(it->second->ALsource, glm::vec3(0)); auto emitter = m_World->GetComponent(it->first, "SoundEmitter"); setSoundProperties(it->second, &emitter); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index de221f36..bc11d0e1 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -20,11 +20,7 @@ void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComp { } void SoundSystem::Update(double dt) -{ - if (!IsClient) { - return; - } -} +{ } bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e) { @@ -51,26 +47,12 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e) return true; } } - if (e.Command == "SoundTemp" && e.Value > 0) { - EntityWrapper entity(m_World, m_World->CreateEntity()); - auto transform = m_World->AttachComponent(entity.ID, "Transform"); - (glm::vec3&)transform["Position"] = glm::vec3(0, 10, 0); - (glm::vec3&)transform["Scale"] = glm::vec3(10, 10, 10); - auto emitter = m_World->AttachComponent(entity.ID, "SoundEmitter"); - auto model = m_World->AttachComponent(entity.ID, "Model"); - (std::string&)model["Resource"] = "Models/Core/UnitCube.mesh"; - Events::PlaySoundOnEntity ev; - ev.Emitter = entity; - ev.FilePath = "Audio/crosscounter.wav"; - m_EventBroker->Publish(ev); - } - return false; } void SoundSystem::playerJumps() { - if (!LocalPlayer.Valid()) { + if (!IsClient) { // Only play for clients return; } @@ -85,7 +67,7 @@ void SoundSystem::playerJumps() bool SoundSystem::OnCaptured(const Events::Captured & e) { - if (!LocalPlayer.Valid()) { + if (!IsClient) { // Only play for clients return false; } int homeTeam = (int)m_World->GetComponent(e.CapturePointTakenID, "Team")["Team"]; From 16124b7aa731ef254613db76860f20250ce073eb Mon Sep 17 00:00:00 2001 From: stiffly Date: Fri, 4 Mar 2016 03:31:51 +0100 Subject: [PATCH 12/19] Crash fix --- src/Game/Systems/PlayerMovementSystem.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 1d176146..759bd723 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -283,6 +283,9 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt) void PlayerMovementSystem::playerStep(double dt, EntityWrapper player) { // Position of the local player, used see how far a player has moved. + if(!IsClient) { + return; + } glm::vec3 pos = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Transform")["Position"]; // Used to see if a player is airborne. bool grounded = (bool)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["IsOnGround"]; From e0de91cce39ba994dc9e01f437b959c6d5c54ffd Mon Sep 17 00:00:00 2001 From: stiffly Date: Tue, 8 Mar 2016 16:55:35 +0100 Subject: [PATCH 13/19] WIP --- include/Game/Systems/SoundSystem.h | 6 ++++-- src/Game/Systems/SoundSystem.cpp | 34 +++++++++++++++++------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/Game/Systems/SoundSystem.h b/include/Game/Systems/SoundSystem.h index 003c6f66..fca242db 100644 --- a/include/Game/Systems/SoundSystem.h +++ b/include/Game/Systems/SoundSystem.h @@ -2,6 +2,7 @@ #define Systems_SoundSystem_h__ #include +#include #include "../Engine/Core/System.h" #include "../Engine/Core/ResourceManager.h" @@ -34,9 +35,10 @@ public: private: std::string m_Announcer = ""; // Logic for playing a sound when a player jumps - void playerJumps(); + void playerJumps(EntityWrapper player); - std::default_random_engine generator; + std::default_random_engine m_RandomGenerator; + std::uniform_int_distribution m_RandIntDistribution; EventRelay m_EPlayerSpawned; bool OnPlayerSpawned(const Events::PlayerSpawned &e); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index bc11d0e1..66d740c8 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -6,14 +6,15 @@ SoundSystem::SoundSystem(SystemParams params) { ConfigFile* config = ResourceManager::Load("Config.ini"); m_Announcer = ResourceManager::Load("Config.ini")->Get("Sound.Announcer", "female"); - + unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); + m_RandomGenerator = std::default_random_engine(seed); + m_RandIntDistribution = std::uniform_int_distribution(1, 12); 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_EPlayerDamage, &SoundSystem::OnPlayerDamage); EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &SoundSystem::OnPlayerDeath); - } void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt) @@ -42,24 +43,28 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e) bool SoundSystem::OnInputCommand(const Events::InputCommand & e) { if (e.Command == "Jump" && e.Value > 0) { - if (e.PlayerID == -1) { // local player - playerJumps(); - return true; + if (e.PlayerID == -1) { + playerJumps(LocalPlayer); + } else { + playerJumps(e.Player); } - } + return true; + } return false; } -void SoundSystem::playerJumps() +void SoundSystem::playerJumps(EntityWrapper player) { if (!IsClient) { // Only play for clients return; } - - bool grounded = (bool)m_World->GetComponent(LocalPlayer.ID, "Physics")["IsOnGround"]; + if(!player.HasComponent("Physics")) { + return; + } + bool grounded = (bool)player["Physics"]["IsOnGround"]; if (grounded) { Events::PlaySoundOnEntity e; - e.Emitter = LocalPlayer; + e.Emitter = player; e.FilePath = "Audio/Jump/Jump1.wav"; m_EventBroker->Publish(e); } @@ -76,7 +81,7 @@ bool SoundSystem::OnCaptured(const Events::Captured & e) if (team == homeTeam) { ev.FilePath = "Audio/Announcer/" + m_Announcer + "/ObjectiveAchieved.wav"; } else { - ev.FilePath = "Audio/Announcer/" + m_Announcer + "/ObjectiveFailed.wav"; + ev.FilePath = "Audio/Announcer/" + m_Announcer + "/ObjectiveFailed.wav"; } m_EventBroker->Publish(ev); return false; @@ -88,13 +93,12 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) if (!IsClient) { // Only play for clients return false; } - if(!e.Victim.Valid()) { + if (!e.Victim.Valid()) { return false; } - 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"); + paths.push_back("Audio/Hurt/Hurt" + std::to_string(m_RandIntDistribution(m_RandomGenerator)) + ".wav"); Events::PlayQueueOnEntity ev; ev.Emitter = e.Victim; From 66d0f9fa4744c78aafee05ac247a85b182cd9d40 Mon Sep 17 00:00:00 2001 From: stiffly Date: Fri, 11 Mar 2016 19:17:43 +0100 Subject: [PATCH 14/19] Added menu music --- assets | 2 +- include/Engine/Sound/SoundManager.h | 6 +++--- include/Game/Systems/SoundSystem.h | 2 +- src/Engine/Sound/SoundManager.cpp | 15 +++++++++------ src/Game/Systems/SoundSystem.cpp | 3 +-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/assets b/assets index 33455a9d..bc6e7df0 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 33455a9d10979b3041d7b8c026be4ac40b2ebad0 +Subproject commit bc6e7df04c09d8db2d889ef60cbc510060a469ed diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index 3452917c..ff9f440a 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -89,9 +89,9 @@ private: Source* createSource(std::string filePath); std::unordered_map m_Sources; void matchBGMLoop(); - Source* m_CurrentBGM; - Source* m_CurrentBGMCombo; - bool m_TempPleaseDeleteMeASAP = false; + Source* m_CurrentBGM = nullptr; + Source* m_CurrentBGMCombo = nullptr; + bool m_DrumLoopHasBeenStarted = false; // Logic World* m_World = nullptr; diff --git a/include/Game/Systems/SoundSystem.h b/include/Game/Systems/SoundSystem.h index fca242db..4852f01a 100644 --- a/include/Game/Systems/SoundSystem.h +++ b/include/Game/Systems/SoundSystem.h @@ -24,7 +24,7 @@ #include "../Engine/Sound/EPlayAnnouncerVoice.h" #include "../Game/Events/EDoubleJump.h" #include "../Game/Events/EDashAbility.h" - +#include "../Engine/Sound/EChangeBGM.h" class SoundSystem : public PureSystem, ImpureSystem { diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index f5403740..2cc5fafa 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -30,6 +30,10 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker) EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity); EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM); + + Events::ChangeBGM e; + e.FilePath = "Audio/bgm/MenuMusic.wav"; + m_EventBroker->Publish(e); } SoundManager::~SoundManager() @@ -63,7 +67,7 @@ void SoundManager::Update(double dt) deleteInactiveEmitters(); updateEmitters(dt); updateListener(dt); - if (m_TempPleaseDeleteMeASAP) + if (m_DrumLoopHasBeenStarted) matchBGMLoop(); } @@ -359,7 +363,7 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e) { if (e.PlayerID == -1) { // Local player m_LocalPlayer = e.Player; - if (m_TempPleaseDeleteMeASAP) { + if (m_DrumLoopHasBeenStarted) { return true; } m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav"); @@ -367,7 +371,7 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e) alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1); setGain(m_CurrentBGMCombo, 0); playSound(m_CurrentBGMCombo); - m_TempPleaseDeleteMeASAP = true; + m_DrumLoopHasBeenStarted = true; return true; } return false; @@ -390,10 +394,9 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e) bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) { - if (m_CurrentBGM == nullptr) { - return false; + if (m_CurrentBGM != nullptr) { + stopSound(m_CurrentBGM); } - stopSound(m_CurrentBGM); m_CurrentBGM = createSource(e.FilePath); playSound(m_CurrentBGM); return true; diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 66d740c8..095c9b85 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -30,9 +30,8 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e) Events::PlayAnonuncerVoice go; go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav"; m_EventBroker->Publish(go); - // TEMP: starts bgm { - Events::PlayBackgroundMusic ev; + Events::ChangeBGM ev; ev.FilePath = "Audio/BGM/Layer1.wav"; m_EventBroker->Publish(ev); } From 28d576bfc038850e16e3a713cb1e236b7887cdc8 Mon Sep 17 00:00:00 2001 From: stiffly Date: Fri, 11 Mar 2016 21:04:33 +0100 Subject: [PATCH 15/19] Now the bgm should loop again. --- src/Engine/Sound/SoundManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 2cc5fafa..bbab46cb 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -377,7 +377,6 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e) return false; } - bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e) { Source* source = createSource(*e.FilePaths.begin()); @@ -398,6 +397,8 @@ bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) stopSound(m_CurrentBGM); } m_CurrentBGM = createSource(e.FilePath); + m_CurrentBGM->Type = SoundType::BGM; + alSourcei(m_CurrentBGM->ALsource, AL_LOOPING, 1); playSound(m_CurrentBGM); return true; } From 9942747d41a6b3fe6775dba6d3d5335d97244502 Mon Sep 17 00:00:00 2001 From: stiffly Date: Sat, 12 Mar 2016 14:26:09 +0100 Subject: [PATCH 16/19] WIP pull request fixes --- include/Game/Systems/BackgroundMusicSystem.h | 21 ------------------ src/Engine/Network/Server.cpp | 2 +- src/Engine/Sound/SoundManager.cpp | 20 ++++++++++++----- src/Game/Systems/BackgroundMusicSystem.cpp | 23 -------------------- 4 files changed, 15 insertions(+), 51 deletions(-) delete mode 100644 include/Game/Systems/BackgroundMusicSystem.h delete mode 100644 src/Game/Systems/BackgroundMusicSystem.cpp diff --git a/include/Game/Systems/BackgroundMusicSystem.h b/include/Game/Systems/BackgroundMusicSystem.h deleted file mode 100644 index 243b0f61..00000000 --- a/include/Game/Systems/BackgroundMusicSystem.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef Systems_BackgroundMusicSystem_h__ -#define Systems_BackgroundMusicSystem_h__ - -#include "../Engine/Core/System.h" -#include "../Engine/Core/EventBroker.h" - -// Handles transitions between BGM's depending on the current state of the game. -class BackgroundMusicSystem : public PureSystem -{ -public: - BackgroundMusicSystem(SystemParams params); - ~BackgroundMusicSystem(); - void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cEmitter, double dt) override; - -private: - void mainMenuLoop(); - - const std::string menu = "Audio/crosscounter.wav"; -}; - -#endif // ifndef diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index 1f94a137..39b9260e 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -592,7 +592,7 @@ void Server::parseOnInputCommand(Packet& packet) e.Player = EntityWrapper(m_World, m_ConnectedPlayers.at(player).EntityID); e.Value = packet.ReadPrimitive(); m_EventBroker->Publish(e); - if (e.Command == "PrimaryFire" || e.Command == "Reload") { + if (e.Command == "PrimaryFire" || e.Command == "Reload" || e.Command == "Jump") { m_InputCommandsToBroadcast.push_back(e); } //LOG_INFO("Server::parseOnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID); diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index bbab46cb..83619ea9 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -297,7 +297,7 @@ bool SoundManager::OnPlayAnnouncerVoice(const Events::PlayAnonuncerVoice& 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"); @@ -394,7 +394,7 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e) bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) { if (m_CurrentBGM != nullptr) { - stopSound(m_CurrentBGM); + stopSound(m_CurrentBGM); } m_CurrentBGM = createSource(e.FilePath); m_CurrentBGM->Type = SoundType::BGM; @@ -419,10 +419,18 @@ 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/BackgroundMusicSystem.cpp b/src/Game/Systems/BackgroundMusicSystem.cpp deleted file mode 100644 index d37427b9..00000000 --- a/src/Game/Systems/BackgroundMusicSystem.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "../Game/Systems/BackgroundMusicSystem.h" - -BackgroundMusicSystem::BackgroundMusicSystem(SystemParams params) - : System(params) - , PureSystem("SoundEmitter") -{ - -} - -BackgroundMusicSystem::~BackgroundMusicSystem() -{ - -} - -void BackgroundMusicSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cEmitter, double dt) -{ - -} - -void BackgroundMusicSystem::mainMenuLoop() -{ - -} From 9bac141a6b12cb83fc23ba74aaa1f698194b4349 Mon Sep 17 00:00:00 2001 From: stiffly Date: Sat, 12 Mar 2016 15:07:10 +0100 Subject: [PATCH 17/19] WIP fixing pull request --- src/Engine/Network/Server.cpp | 2 +- src/Game/Game.cpp | 4 +++- src/Game/Systems/SoundSystem.cpp | 18 +++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index 39b9260e..1f94a137 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -592,7 +592,7 @@ void Server::parseOnInputCommand(Packet& packet) e.Player = EntityWrapper(m_World, m_ConnectedPlayers.at(player).EntityID); e.Value = packet.ReadPrimitive(); m_EventBroker->Publish(e); - if (e.Command == "PrimaryFire" || e.Command == "Reload" || e.Command == "Jump") { + if (e.Command == "PrimaryFire" || e.Command == "Reload") { m_InputCommandsToBroadcast.push_back(e); } //LOG_INFO("Server::parseOnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID); diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 7b80727e..372a8c84 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -223,7 +223,9 @@ void Game::Tick() m_EventBroker->Swap(); PerformanceTimer::StartTimerAndStopPrevious("SoundManager"); - m_SoundManager->Update(dt); + if (m_IsClient) { + m_SoundManager->Update(dt); + } // Update network PerformanceTimer::StartTimerAndStopPrevious("Network"); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 095c9b85..ef61b070 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -86,16 +86,20 @@ bool SoundSystem::OnCaptured(const Events::Captured & e) return false; } -// Testing purposes atm... bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) { if (!IsClient) { // Only play for clients return false; } - if (!e.Victim.Valid()) { + if (!e.Victim.Valid() || !e.Inflictor.Valid()) { + return false; + } + auto victimTeam = m_World->GetComponent(e.Victim.ID, "Team"); + auto inflictorTeam = m_World->GetComponent(e.Inflictor.ID, "Team"); + if ((int)victimTeam["Team"] == (int)inflictorTeam["Team"]) { + // Victim and inflictor are the same team, should not play "hurt" sound. return false; } - std::vector paths; paths.push_back("Audio/Hurt/Hurt" + std::to_string(m_RandIntDistribution(m_RandomGenerator)) + ".wav"); @@ -141,9 +145,9 @@ bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e) if (!IsClient) { return false; } - Events::PlaySoundOnEntity ev; - ev.Emitter = EntityWrapper(m_World, e.entityID); - ev.FilePath = "Audio/Jump/Jump2.wav"; - m_EventBroker->Publish(ev); + //Events::PlaySoundOnEntity ev; + //ev.Emitter = EntityWrapper(m_World, e.entityID); + //ev.FilePath = "Audio/Jump/Jump2.wav"; + //m_EventBroker->Publish(ev); return false; } \ No newline at end of file From cc10e5500b6ced786c9b4d2ceeb4976a7218564c Mon Sep 17 00:00:00 2001 From: stiffly Date: Sat, 12 Mar 2016 15:31:44 +0100 Subject: [PATCH 18/19] 2x jump now only plays for local player --- src/Engine/Sound/SoundManager.cpp | 2 +- src/Game/Systems/SoundSystem.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 83619ea9..2495fdd6 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -275,7 +275,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) { - continue;; + continue; } auto emitterChild = m_World->CreateEntity((*it).EntityID); auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter"); diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index ef61b070..f486c28c 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -145,9 +145,11 @@ bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e) if (!IsClient) { return false; } - //Events::PlaySoundOnEntity ev; - //ev.Emitter = EntityWrapper(m_World, e.entityID); - //ev.FilePath = "Audio/Jump/Jump2.wav"; - //m_EventBroker->Publish(ev); + if (e.entityID == LocalPlayer.ID) { + Events::PlaySoundOnEntity ev; + ev.Emitter = EntityWrapper(m_World, e.entityID); + ev.FilePath = "Audio/Jump/Jump2.wav"; + m_EventBroker->Publish(ev); + } return false; } \ No newline at end of file From 8e9ddc7b9de09bc9d0334237f705ded66768be24 Mon Sep 17 00:00:00 2001 From: stiffly Date: Sat, 12 Mar 2016 17:51:06 +0100 Subject: [PATCH 19/19] playerJump is only done for local player. --- src/Game/Systems/SoundSystem.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index f486c28c..4ee7090b 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -44,9 +44,7 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e) if (e.Command == "Jump" && e.Value > 0) { if (e.PlayerID == -1) { playerJumps(LocalPlayer); - } else { - playerJumps(e.Player); - } + } return true; } return false;