diff --git a/src/Components/SoundEmitter.h b/src/Components/SoundEmitter.h index 6bd80d8..adc7739 100755 --- a/src/Components/SoundEmitter.h +++ b/src/Components/SoundEmitter.h @@ -10,6 +10,11 @@ namespace Components struct SoundEmitter : Component { + enum SoundType + { + BGM_SOUND, + SFX_SOUND + }; SoundEmitter() : Gain(1.f), MaxDistance(1.f), MinDistance(1.f), Pitch(1.f), Loop(false) {} float Gain; float MaxDistance; @@ -17,6 +22,7 @@ struct SoundEmitter : Component float Pitch; bool Loop; std::string Path; + SoundType type; virtual SoundEmitter* Clone() const override { return new SoundEmitter(*this); } }; diff --git a/src/Events/PlayBGM.h b/src/Events/PlayBGM.h new file mode 100644 index 0000000..58eacf5 --- /dev/null +++ b/src/Events/PlayBGM.h @@ -0,0 +1,18 @@ +#ifndef Event_PlayBGM_h__ +#define Event_PlayBGM_h__ + +#include "EventBroker.h" +#include "Entity.h" + +namespace Events +{ + + struct PlayBGM : Event + { + std::string Resource; + bool Loop; + }; + +} + +#endif // Event_PlayBGM_h__ diff --git a/src/Events/PlaySound.h b/src/Events/PlaySFX.h similarity index 53% rename from src/Events/PlaySound.h rename to src/Events/PlaySFX.h index f84db01..e96f8cf 100644 --- a/src/Events/PlaySound.h +++ b/src/Events/PlaySFX.h @@ -1,5 +1,5 @@ -#ifndef Event_PlaySound_h__ -#define Event_PlaySound_h__ +#ifndef Event_PlaySFX_h__ +#define Event_PlaySFX_h__ #include "EventBroker.h" #include "Entity.h" @@ -7,7 +7,7 @@ namespace Events { -struct PlaySound : Event +struct PlaySFX : Event { EntityID Emitter; std::string Resource; @@ -16,4 +16,4 @@ struct PlaySound : Event } -#endif // Event_PlaySound_h__ +#endif // Event_PlaySFX_h__ diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 0a774e8..85be0a4 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -1092,7 +1092,7 @@ void GameWorld::Initialize() auto se1 = CreateEntity(); std::cout<(se1); - transform->Position = glm::vec3(20,2,-15); + transform->Position = glm::vec3(20,2,-100); transform->Scale = glm::vec3(3); auto emitterComponent = AddComponent(se1); emitterComponent->Path = "Sounds/WUB.mp3"; diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 1a88e95..6de554b 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -44,9 +44,8 @@ void InputManager::Update(double dt) if(m_CurrentKeyState[GLFW_KEY_Z]) //TEMP { - Events::PlaySound e; + Events::PlayBGM e; e.Resource = "Sounds/BGM/WUB.mp3"; - e.Emitter = 66; e.Loop = true; EventBroker->Publish(e); } diff --git a/src/InputManager.h b/src/InputManager.h index 3326070..61227ee 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -12,7 +12,8 @@ #include "Events/LockMouse.h" #include "Events/GamepadAxis.h" #include "Events/GamepadButton.h" -#include "Events/PlaySound.h" //Temp +#include "Events/PLaySFX.h" //Temp +#include "Events/PLayBGM.h" //Temp class InputManager { diff --git a/src/Sound.cpp b/src/Sound.cpp index ddd5311..820dcf2 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -9,5 +9,5 @@ Sound::Sound(std::string path, FMOD_SYSTEM* system) Sound::~Sound() { - + FMOD_Sound_Release(m_Sound); } \ No newline at end of file diff --git a/src/Systems/DebugSystem.cpp b/src/Systems/DebugSystem.cpp index f076664..b8d6d28 100644 --- a/src/Systems/DebugSystem.cpp +++ b/src/Systems/DebugSystem.cpp @@ -19,10 +19,10 @@ bool Systems::DebugSystem::OnKeyDown(const Events::KeyDown &event) { if (event.KeyCode == GLFW_KEY_ENTER) { - Events::PlaySound e; + Events::PlaySFX e; e.Emitter = 0; e.Resource = "Sounds/korvring.wav"; - EventBroker->Publish(e); + EventBroker->Publish(e); return true; } diff --git a/src/Systems/DebugSystem.h b/src/Systems/DebugSystem.h index bbf7cd5..b5ed722 100644 --- a/src/Systems/DebugSystem.h +++ b/src/Systems/DebugSystem.h @@ -4,7 +4,7 @@ #include "System.h" #include "Components/Transform.h" #include "Events/KeyDown.h" -#include "Events/PlaySound.h" +#include "Events/PlaySFX.h" namespace Systems { diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index b022366..8c0ea2a 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -5,7 +5,8 @@ void Systems::SoundSystem::Initialize() { EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated); - EVENT_SUBSCRIBE_MEMBER(m_EPlaySound, &SoundSystem::PlayASound); + EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::PlaySFX); + EVENT_SUBSCRIBE_MEMBER(m_EPlayBGM, &SoundSystem::PlayBGM); m_TransformSystem = m_World->GetSystem(); FMOD_System_Create(&m_System); @@ -18,7 +19,7 @@ void Systems::SoundSystem::Initialize() { LOG_INFO("FMOD initialized successfully"); } - FMOD_System_Set3DSettings(m_System, 10.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale + FMOD_System_Set3DSettings(m_System, 1.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale } @@ -85,7 +86,20 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par FMOD_CHANNEL* channel = m_Channels[entity]; FMOD_SOUND* sound = m_Sounds[entity]; auto eTransform = m_World->GetComponent(entity); - + + + if(emitter->type == emitter->BGM_SOUND) + { + + EntityID listener = m_Listeners[0]; // "Pretty" ugly hack... Sets the transform Component for emitter to be same as first listener + auto lTransform = m_World->GetComponent(listener); + if(lTransform) + { + eTransform->Position = m_TransformSystem->AbsolutePosition(listener); + eTransform->Velocity = lTransform->Velocity; + } + + } glm::vec3 tPos = m_TransformSystem->AbsolutePosition(entity); FMOD_VECTOR ePos = {tPos.x, tPos.y, tPos.z}; @@ -116,16 +130,15 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev float maxDist = emitter->MaxDistance; float minDist = emitter->MinDistance; float pitch = emitter->Pitch; - LoadSound(sound, path, maxDist, minDist); + //LoadSound(sound, path, maxDist, minDist); m_Channels.insert(std::make_pair(emitter->Entity, channel)); m_Sounds.insert(std::make_pair(emitter->Entity, sound)); } return true; } -bool Systems::SoundSystem::PlayASound(const Events::PlaySound &event) +bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event) { - auto emitter = m_World->GetComponent(event.Emitter); if(!emitter) { @@ -134,7 +147,6 @@ bool Systems::SoundSystem::PlayASound(const Events::PlaySound &event) } Sound* sound = m_World->GetResourceManager()->Load("Sound", event.Resource); m_Sounds[event.Emitter] = *sound; - //LoadSound(m_Sounds[event.Emitter], event.Resource, 1000.f, 1.f); PlaySound(&m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop); FMOD_System_Update(m_System); @@ -148,6 +160,21 @@ bool Systems::SoundSystem::PlayASound(const Events::PlaySound &event) return true; } +bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event) +{ + auto emitter = m_World->CreateEntity(); + auto eTransform = m_World->AddComponent(emitter); + + auto eComponent = m_World->AddComponent(emitter); + eComponent->type = eComponent->BGM_SOUND; + + Sound* sound = m_World->GetResourceManager()->Load("Sound", event.Resource); + m_Sounds[emitter] = *sound; + + FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_Channels[emitter]); + return true; +} + void Systems::SoundSystem::LoadSound(FMOD_SOUND* &sound, std::string filePath, float maxDist, float minDist) { FMOD_RESULT result = FMOD_System_CreateSound(m_System, filePath.c_str(), FMOD_3D | FMOD_HARDWARE , 0, &sound); diff --git a/src/Systems/SoundSystem.h b/src/Systems/SoundSystem.h index e1a5406..77e385c 100755 --- a/src/Systems/SoundSystem.h +++ b/src/Systems/SoundSystem.h @@ -10,7 +10,8 @@ #include "Components/SoundEmitter.h" #include "Components/Listener.h" #include "Events/ComponentCreated.h" -#include "Events/PlaySound.h" +#include "Events/PlaySFX.h" +#include "Events/PlayBGM.h" #include "Sound.h" namespace Systems @@ -33,8 +34,10 @@ private: // Events EventRelay m_EComponentCreated; bool OnComponentCreated(const Events::ComponentCreated &event); - EventRelay m_EPlaySound; - bool PlayASound(const Events::PlaySound &event); + EventRelay m_EPlaySFX; + bool PlaySFX(const Events::PlaySFX &event); + EventRelay m_EPlayBGM; + bool PlayBGM(const Events::PlayBGM &event); void LoadSound(FMOD_SOUND*&, std::string, float, float); void PlaySound(FMOD_CHANNEL**, FMOD_SOUND*, float volume, bool loop); diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index a801ad3..8123839 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -174,7 +174,8 @@ - + + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index fca9767..6836160 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -49,7 +49,6 @@ Input\Systems - Particle System\Systems @@ -66,6 +65,9 @@ Gameplay\Vehicles\Helicopter\Systems + + Audio + @@ -304,9 +306,6 @@ Util - - Audio\Events - Input\Events @@ -406,6 +405,12 @@ Base\Events + + Audio\Events + + + Audio\Events +