Added Destructor. (improved StopSound and PlayBGM events)
This commit is contained in:
+1
-1
Submodule assets updated: e09ebf5a29...cfda101f67
@@ -8,6 +8,13 @@ void GameWorld::Initialize()
|
||||
ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj");
|
||||
ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj");
|
||||
|
||||
//Background Music
|
||||
{
|
||||
Events::PlayBGM e;
|
||||
e.Resource = "Sounds/BGM/RideoftheValkyries.mp3";
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
// Interface
|
||||
BindKey(GLFW_KEY_A, "interface_horizontal", -1.f);
|
||||
BindKey(GLFW_KEY_D, "interface_horizontal", 1.f);
|
||||
|
||||
@@ -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
|
||||
// if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
// {
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include "Events/GamepadAxis.h"
|
||||
#include "Events/GamepadButton.h"
|
||||
|
||||
#include "Events/StopSound.h"
|
||||
#include "Events/PlayBGM.h"
|
||||
|
||||
class InputManager
|
||||
{
|
||||
public:
|
||||
|
||||
+27
-17
@@ -2,13 +2,18 @@
|
||||
#include "SoundSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
Systems::SoundSystem::~SoundSystem()
|
||||
{
|
||||
FMOD_System_Release(m_System);
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::PlaySFX);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayBGM, &SoundSystem::PlayBGM);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::StopSound);
|
||||
|
||||
m_isPlaying = false;
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
FMOD_System_Create(&m_System);
|
||||
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;
|
||||
for(it = m_DeleteChannels.begin(); it != m_DeleteChannels.end();)
|
||||
{
|
||||
FMOD_BOOL isPlaying = false;
|
||||
FMOD_Channel_IsPlaying(it->second, &isPlaying);
|
||||
if(isPlaying)
|
||||
FMOD_Channel_IsPlaying(it->second, &m_isPlaying);
|
||||
if(m_isPlaying)
|
||||
{
|
||||
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();)
|
||||
{
|
||||
FMOD_BOOL isPlaying = false;
|
||||
FMOD_Channel_IsPlaying(it->second, &isPlaying);
|
||||
if(!isPlaying)
|
||||
FMOD_Channel_IsPlaying(it->second, &m_isPlaying);
|
||||
if(!m_isPlaying)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,12 @@ public:
|
||||
SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
~SoundSystem();
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override;
|
||||
void Initialize() override;
|
||||
void Update(double dt) 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;
|
||||
FMOD_SYSTEM* GetFMODSystem() const { return m_System; }
|
||||
private:
|
||||
@@ -48,11 +47,11 @@ private:
|
||||
void PlaySound(FMOD_CHANNEL**, FMOD_SOUND*, float volume, bool loop);
|
||||
|
||||
FMOD_SYSTEM* m_System;
|
||||
FMOD_BOOL m_isPlaying;
|
||||
FMOD_CHANNEL* m_BGMChannel;
|
||||
std::vector<EntityID> m_Listeners;
|
||||
std::map<EntityID, FMOD_CHANNEL*> m_Channels;
|
||||
std::map<EntityID, FMOD_CHANNEL*> m_DeleteChannels;
|
||||
//std::map<EntityID, FMOD_SOUND*> m_Sounds;
|
||||
std::map<EntityID, FMOD_SOUND*> m_DeleteSounds;
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
|
||||
|
||||
@@ -78,15 +78,13 @@
|
||||
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp">
|
||||
<Filter>Game\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
|
||||
<Filter>Gameplay\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\GarageSystem.cpp">
|
||||
<Filter>Game\Systems</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Sound.cpp">
|
||||
<Filter>Audio</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Systems\WallSystem.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Util">
|
||||
@@ -526,9 +524,6 @@
|
||||
<ClInclude Include="..\..\src\Components\BlendMap.h">
|
||||
<Filter>Rendering\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Systems\WallSystem.h">
|
||||
<Filter>Gameplay\Systems</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Events\LeaveTrigger.h">
|
||||
<Filter>Physics\Events</Filter>
|
||||
</ClInclude>
|
||||
@@ -565,9 +560,6 @@
|
||||
<ClInclude Include="..\..\src\GUI\VehicleSelection.h">
|
||||
<Filter>GUI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Events\OnDead.h">
|
||||
<Filter>Gameplay\Events</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Events\SpawnVehicle.h">
|
||||
<Filter>Game\Events</Filter>
|
||||
</ClInclude>
|
||||
@@ -577,6 +569,8 @@
|
||||
<ClInclude Include="..\..\src\Components\SpawnPoint.h">
|
||||
<Filter>Game\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Events\OnDead.h" />
|
||||
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
||||
|
||||
Reference in New Issue
Block a user