When using a PlaySoundOnEntity Event, you no longer have to provide the child of an entity as parameter.

This commit is contained in:
stiffly
2016-02-10 11:04:18 +01:00
parent 2c64ffc3d1
commit 94ff12cf66
5 changed files with 15 additions and 26 deletions
-3
View File
@@ -36,11 +36,8 @@ private:
World* m_World = nullptr;
EventBroker* m_EventBroker = nullptr;
std::string m_Announcer = "";
// Logic for playing a sound when a player jumps
void playerJumps();
// Helper function
EntityID createChildEmitter(EntityWrapper parent);
std::default_random_engine generator;
+5 -2
View File
@@ -192,7 +192,10 @@ bool SoundManager::OnPlaySoundOnEntity(const Events::PlaySoundOnEntity & e)
{
Source* source = createSource(e.FilePath);
source->Type = SoundType::SFX;
m_Sources[e.EmitterID] = source;
EntityID child = m_World->CreateEntity(e.EmitterID);
m_World->AttachComponent(child, "Transform");
m_World->AttachComponent(child, "SoundEmitter");
m_Sources[child] = source;
playSound(source);
return false;
}
@@ -243,7 +246,7 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
}
auto emitterChild = m_World->CreateEntity((*it).EntityID);
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
(bool&)emitter["Loop"] = false;
(bool&)emitter["Loop"] = true;
(std::string&)emitter["FilePath"] = e.FilePath;
m_World->AttachComponent(emitterChild, "Transform");
Source* source = createSource(e.FilePath);
+1 -4
View File
@@ -197,10 +197,7 @@ void PlayerMovementSystem::playerStep(double dt)
// Player moved a step's distance
// Create footstep sound
Events::PlaySoundOnEntity e;
EntityID child = m_World->CreateEntity(m_LocalPlayer.ID);
m_World->AttachComponent(child, "Transform");
m_World->AttachComponent(child, "SoundEmitter");
e.EmitterID = child;
e.EmitterID = m_LocalPlayer.ID;
e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav";
m_LeftFoot = !m_LeftFoot;
m_EventBroker->Publish(e);
+8 -16
View File
@@ -31,7 +31,7 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
m_World->AttachComponent(e.Player.ID, "Listener");
m_LocalPlayer = e.Player;
Events::PlaySoundOnEntity go;
go.EmitterID = createChildEmitter(m_LocalPlayer);
go.EmitterID = m_LocalPlayer.ID;
go.FilePath = "Audio/announcer/" + m_Announcer + "/go.wav";
m_EventBroker->Publish(go);
// TEMP: starts bgm
@@ -67,7 +67,7 @@ void SoundSystem::playerJumps()
glm::vec3 vel = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["Velocity"];
if (vel.y == 0) {
Events::PlaySoundOnEntity e;
e.EmitterID = createChildEmitter(m_LocalPlayer);
e.EmitterID = m_LocalPlayer.ID;
e.FilePath = "Audio/jump/jump1.wav";
m_EventBroker->Publish(e);
}
@@ -76,7 +76,7 @@ void SoundSystem::playerJumps()
bool SoundSystem::OnShoot(const Events::Shoot & e)
{
Events::PlaySoundOnEntity ev;
ev.EmitterID = createChildEmitter(m_LocalPlayer);
ev.EmitterID = m_LocalPlayer.ID;
ev.FilePath = "Audio/laser/laser1.wav";
m_EventBroker->Publish(ev);
return true;
@@ -92,7 +92,7 @@ bool SoundSystem::OnCaptured(const Events::Captured & e)
} else {
ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_failed.wav"; // have not been tested
}
ev.EmitterID = createChildEmitter(m_LocalPlayer);
ev.EmitterID = m_LocalPlayer.ID;
m_EventBroker->Publish(ev);
return false;
}
@@ -122,7 +122,7 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
{
//if (e.PlayerID == m_LocalPlayer.ID) {
Events::PlaySoundOnEntity ev;
ev.EmitterID = createChildEmitter(m_LocalPlayer);
ev.EmitterID = m_LocalPlayer.ID;
ev.FilePath = "Audio/die/die2.wav";
m_EventBroker->Publish(ev);
//}
@@ -133,7 +133,7 @@ bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e)
{
//if (e.PlayerHealedID == m_LocalPlayer.ID) {
Events::PlaySoundOnEntity ev;
ev.EmitterID = createChildEmitter(m_LocalPlayer);
ev.EmitterID = m_LocalPlayer.ID;
ev.FilePath = "Audio/pickup/pickup2.wav";
m_EventBroker->Publish(ev);
//}
@@ -153,7 +153,7 @@ bool SoundSystem::OnTriggerTouch(const Events::TriggerTouch & e)
bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e)
{
Events::PlaySoundOnEntity ev;
ev.EmitterID = createChildEmitter(m_LocalPlayer);
ev.EmitterID = m_LocalPlayer.ID;
ev.FilePath = "Audio/jump/jump2.wav";
m_EventBroker->Publish(ev);
return false;
@@ -162,16 +162,8 @@ bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e)
bool SoundSystem::OnDashAbility(const Events::DashAbility &e)
{
Events::PlaySoundOnEntity ev;
ev.EmitterID = createChildEmitter(m_LocalPlayer);
ev.EmitterID = m_LocalPlayer.ID;
ev.FilePath = "Audio/jump/dash1.wav";
m_EventBroker->Publish(ev);
return false;
}
EntityID SoundSystem::createChildEmitter(EntityWrapper localPlayer)
{
EntityID child = m_World->CreateEntity(localPlayer.ID);
m_World->AttachComponent(child, "Transform");
m_World->AttachComponent(child, "SoundEmitter");
return child;
}