From 03d6594f9ad79428cc87ededa422e9d3ec6dac8c Mon Sep 17 00:00:00 2001 From: Stiffly Date: Thu, 29 May 2014 19:10:22 +0200 Subject: [PATCH] Loads BGM and SFX sounds differently depending on path to sound file. --- src/Sound.cpp | 17 ++++++++++++++++- src/Systems/SoundSystem.cpp | 27 ++++++++++++++------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Sound.cpp b/src/Sound.cpp index 820dcf2..40b6e85 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -4,7 +4,22 @@ Sound::Sound(std::string path, FMOD_SYSTEM* system) { - FMOD_System_CreateSound(system, path.c_str(), FMOD_3D, NULL, &m_Sound); + + std::string str = ""; + for(int i = 7; i < 10; i++) + { + str += path[i]; + } + + if(str == "BGM") + { + FMOD_System_CreateSound(system, path.c_str(), FMOD_2D, NULL, &m_Sound); + } + if (str == "SFX") + { + FMOD_System_CreateSound(system, path.c_str(), FMOD_3D, NULL, &m_Sound); + } + } Sound::~Sound() diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index ebfa8ab..87d0862 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -89,18 +89,17 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par 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; - } - - } +// 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}; @@ -151,6 +150,9 @@ bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event) PlaySound(&m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop); FMOD_System_Update(m_System); + + + FMOD_BOOL isPlaying = false; FMOD_Channel_IsPlaying(m_Channels[event.Emitter], &isPlaying); if(!isPlaying) @@ -163,7 +165,6 @@ bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event) bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event) { auto emitter = m_World->CreateEntity(); - std::cout<<"ASSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS: "<AddComponent(emitter); auto eComponent = m_World->AddComponent(emitter);