Added Destructor. (improved StopSound and PlayBGM events)

This commit is contained in:
Stiffly
2014-06-04 15:21:05 +02:00
parent f9426745f7
commit 2ef5d49f7e
7 changed files with 64 additions and 29 deletions
+1 -1
Submodule assets updated: e09ebf5a29...cfda101f67
+7
View File
@@ -8,6 +8,13 @@ void GameWorld::Initialize()
ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj"); ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj");
ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj"); ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj");
//Background Music
{
Events::PlayBGM e;
e.Resource = "Sounds/BGM/RideoftheValkyries.mp3";
EventBroker->Publish(e);
}
// Interface // Interface
BindKey(GLFW_KEY_A, "interface_horizontal", -1.f); BindKey(GLFW_KEY_A, "interface_horizontal", -1.f);
BindKey(GLFW_KEY_D, "interface_horizontal", 1.f); BindKey(GLFW_KEY_D, "interface_horizontal", 1.f);
+22
View File
@@ -86,6 +86,28 @@ void InputManager::Update(double dt)
} }
if(m_CurrentKeyState[GLFW_KEY_P])
{
Events::StopSound e;
e.Emitter = 1;
EventBroker->Publish(e);
}
if(m_CurrentKeyState[GLFW_KEY_L])
{
Events::PlayBGM e;
e.Resource = "Sounds/BGM/WilliamTellOverture.mp3";
e.Loop = true;
EventBroker->Publish(e);
}
if(m_CurrentKeyState[GLFW_KEY_O])
{
Events::PlayBGM e;
e.Resource = "Sounds/BGM/DiesIrae.mp3";
e.Loop = true;
EventBroker->Publish(e);
}
// // Lock mouse while holding LMB // // Lock mouse while holding LMB
// if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) // if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
// { // {
+3
View File
@@ -13,6 +13,9 @@
#include "Events/GamepadAxis.h" #include "Events/GamepadAxis.h"
#include "Events/GamepadButton.h" #include "Events/GamepadButton.h"
#include "Events/StopSound.h"
#include "Events/PlayBGM.h"
class InputManager class InputManager
{ {
public: public:
+27 -17
View File
@@ -2,13 +2,18 @@
#include "SoundSystem.h" #include "SoundSystem.h"
#include "World.h" #include "World.h"
Systems::SoundSystem::~SoundSystem()
{
FMOD_System_Release(m_System);
}
void Systems::SoundSystem::Initialize() void Systems::SoundSystem::Initialize()
{ {
EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated); EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated);
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::PlaySFX); EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::PlaySFX);
EVENT_SUBSCRIBE_MEMBER(m_EPlayBGM, &SoundSystem::PlayBGM); EVENT_SUBSCRIBE_MEMBER(m_EPlayBGM, &SoundSystem::PlayBGM);
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::StopSound); EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::StopSound);
m_isPlaying = false;
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>(); m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
FMOD_System_Create(&m_System); FMOD_System_Create(&m_System);
FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_ENABLE_PROFILE, 0); FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_ENABLE_PROFILE, 0);
@@ -44,9 +49,8 @@ void Systems::SoundSystem::Update(double dt)
std::map<EntityID, FMOD_CHANNEL*>::iterator it; std::map<EntityID, FMOD_CHANNEL*>::iterator it;
for(it = m_DeleteChannels.begin(); it != m_DeleteChannels.end();) for(it = m_DeleteChannels.begin(); it != m_DeleteChannels.end();)
{ {
FMOD_BOOL isPlaying = false; FMOD_Channel_IsPlaying(it->second, &m_isPlaying);
FMOD_Channel_IsPlaying(it->second, &isPlaying); if(m_isPlaying)
if(isPlaying)
{ {
it++; it++;
} }
@@ -58,13 +62,12 @@ void Systems::SoundSystem::Update(double dt)
} }
} }
//LOG_INFO("Antal emitters i listan: %i", m_Channels.size()); LOG_INFO("Antal emitters i listan: %i", m_Channels.size());
for(it = m_Channels.begin(); it != m_Channels.end();) for(it = m_Channels.begin(); it != m_Channels.end();)
{ {
FMOD_BOOL isPlaying = false; FMOD_Channel_IsPlaying(it->second, &m_isPlaying);
FMOD_Channel_IsPlaying(it->second, &isPlaying); if(!m_isPlaying)
if(!isPlaying)
{ {
it = m_Channels.erase(it); it = m_Channels.erase(it);
} }
@@ -163,21 +166,28 @@ bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event)
bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event) bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event)
{ {
auto emitter = m_World->CreateEntity();
auto eTransform = m_World->AddComponent<Components::Transform>(emitter);
auto eComponent = m_World->AddComponent<Components::SoundEmitter>(emitter);
m_Channels[emitter] = m_BGMChannel;
eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D;
Sound* sound = ResourceManager->Load<Sound>("Sound2D", event.Resource);
//m_Sounds[emitter] = *sound;
FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_Channels[emitter]); FMOD_Channel_Stop(m_BGMChannel);
Sound* sound = ResourceManager->Load<Sound>("Sound2D", event.Resource);
FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_BGMChannel);
FMOD_Channel_SetMode(m_BGMChannel, FMOD_LOOP_NORMAL);
FMOD_Sound_SetLoopCount(*sound, -1);
return true; return true;
} }
bool Systems::SoundSystem::StopSound(const Events::StopSound &event) bool Systems::SoundSystem::StopSound(const Events::StopSound &event)
{ {
FMOD_Channel_Stop(m_Channels[event.Emitter]); auto eComp = m_World->GetComponent<Components::SoundEmitter>(event.Emitter);
if(eComp)
{
FMOD_Channel_Stop(m_Channels[event.Emitter]);
}
else
{
FMOD_Channel_Stop(m_BGMChannel);
}
return true; return true;
} }
+2 -3
View File
@@ -24,13 +24,12 @@ public:
SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) : System(world, eventBroker, resourceManager)
{ } { }
~SoundSystem();
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override; void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override;
void Initialize() override; void Initialize() override;
void Update(double dt) override; void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
//void OnComponentRemoved(std::string type, Component* component);
void OnComponentRemoved(EntityID entity, std::string type, Component* component) override; void OnComponentRemoved(EntityID entity, std::string type, Component* component) override;
FMOD_SYSTEM* GetFMODSystem() const { return m_System; } FMOD_SYSTEM* GetFMODSystem() const { return m_System; }
private: private:
@@ -48,11 +47,11 @@ private:
void PlaySound(FMOD_CHANNEL**, FMOD_SOUND*, float volume, bool loop); void PlaySound(FMOD_CHANNEL**, FMOD_SOUND*, float volume, bool loop);
FMOD_SYSTEM* m_System; FMOD_SYSTEM* m_System;
FMOD_BOOL m_isPlaying;
FMOD_CHANNEL* m_BGMChannel; FMOD_CHANNEL* m_BGMChannel;
std::vector<EntityID> m_Listeners; std::vector<EntityID> m_Listeners;
std::map<EntityID, FMOD_CHANNEL*> m_Channels; std::map<EntityID, FMOD_CHANNEL*> m_Channels;
std::map<EntityID, FMOD_CHANNEL*> m_DeleteChannels; std::map<EntityID, FMOD_CHANNEL*> m_DeleteChannels;
//std::map<EntityID, FMOD_SOUND*> m_Sounds;
std::map<EntityID, FMOD_SOUND*> m_DeleteSounds; std::map<EntityID, FMOD_SOUND*> m_DeleteSounds;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem; std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
@@ -78,15 +78,13 @@
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp"> <ClCompile Include="..\..\src\Systems\FollowSystem.cpp">
<Filter>Game\Systems</Filter> <Filter>Game\Systems</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Gameplay\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\GarageSystem.cpp"> <ClCompile Include="..\..\src\Systems\GarageSystem.cpp">
<Filter>Game\Systems</Filter> <Filter>Game\Systems</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\Sound.cpp"> <ClCompile Include="..\..\src\Sound.cpp">
<Filter>Audio</Filter> <Filter>Audio</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="Util"> <Filter Include="Util">
@@ -526,9 +524,6 @@
<ClInclude Include="..\..\src\Components\BlendMap.h"> <ClInclude Include="..\..\src\Components\BlendMap.h">
<Filter>Rendering\Components</Filter> <Filter>Rendering\Components</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Gameplay\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\LeaveTrigger.h"> <ClInclude Include="..\..\src\Events\LeaveTrigger.h">
<Filter>Physics\Events</Filter> <Filter>Physics\Events</Filter>
</ClInclude> </ClInclude>
@@ -565,9 +560,6 @@
<ClInclude Include="..\..\src\GUI\VehicleSelection.h"> <ClInclude Include="..\..\src\GUI\VehicleSelection.h">
<Filter>GUI</Filter> <Filter>GUI</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h">
<Filter>Gameplay\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SpawnVehicle.h"> <ClInclude Include="..\..\src\Events\SpawnVehicle.h">
<Filter>Game\Events</Filter> <Filter>Game\Events</Filter>
</ClInclude> </ClInclude>
@@ -577,6 +569,8 @@
<ClInclude Include="..\..\src\Components\SpawnPoint.h"> <ClInclude Include="..\..\src\Components\SpawnPoint.h">
<Filter>Game\Components</Filter> <Filter>Game\Components</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl"> <None Include="..\..\src\Shaders\Fragment2.glsl">