The EPlaySoundOnEntity event now has support to set the gain on the sound. It now also uses EntityWrapper instead of EntityID.

This commit is contained in:
stiffly
2016-03-03 20:24:48 +01:00
parent 20c6caa408
commit 3613d66d32
5 changed files with 21 additions and 14 deletions
+2 -1
View File
@@ -12,7 +12,8 @@ namespace Events
// Sound behavior is thereby specified in the SoundEmitter component. // Sound behavior is thereby specified in the SoundEmitter component.
struct PlaySoundOnEntity : public Event struct PlaySoundOnEntity : public Event
{ {
EntityID EmitterID = 0; EntityWrapper Emitter = EntityWrapper::Invalid;
float Gain = 1.f;
std::string FilePath = ""; std::string FilePath = "";
}; };
+4 -2
View File
@@ -222,10 +222,12 @@ bool SoundManager::OnPlaySoundOnEntity(const Events::PlaySoundOnEntity & e)
{ {
Source* source = createSource(e.FilePath); Source* source = createSource(e.FilePath);
source->Type = SoundType::SFX; source->Type = SoundType::SFX;
EntityID child = m_World->CreateEntity(e.EmitterID); EntityID child = m_World->CreateEntity(e.Emitter.ID);
m_World->AttachComponent(child, "Transform"); m_World->AttachComponent(child, "Transform");
m_World->AttachComponent(child, "SoundEmitter"); auto cEmitter = m_World->AttachComponent(child, "SoundEmitter");
(double&)(float)cEmitter["Gain"] = e.Gain;
m_Sources[child] = source; m_Sources[child] = source;
setGain(source, cEmitter["Gain"]);
playSound(source); playSound(source);
return false; return false;
} }
+1 -1
View File
@@ -287,7 +287,7 @@ void PlayerMovementSystem::playerStep(double dt)
// Player moved a step's distance // Player moved a step's distance
// Create footstep sound // Create footstep sound
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = m_LocalPlayer.ID; e.Emitter = m_LocalPlayer;
e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav"; e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav";
m_LeftFoot = !m_LeftFoot; m_LeftFoot = !m_LeftFoot;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
+9 -8
View File
@@ -60,7 +60,7 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e)
auto model = m_World->AttachComponent(entity.ID, "Model"); auto model = m_World->AttachComponent(entity.ID, "Model");
(std::string&)model["Resource"] = "Models/Core/UnitCube.mesh"; (std::string&)model["Resource"] = "Models/Core/UnitCube.mesh";
Events::PlaySoundOnEntity ev; Events::PlaySoundOnEntity ev;
ev.EmitterID = entity.ID; ev.Emitter = entity;
ev.FilePath = "Audio/crosscounter.wav"; ev.FilePath = "Audio/crosscounter.wav";
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
} }
@@ -77,7 +77,7 @@ void SoundSystem::playerJumps()
bool grounded = (bool)m_World->GetComponent(LocalPlayer.ID, "Physics")["IsOnGround"]; bool grounded = (bool)m_World->GetComponent(LocalPlayer.ID, "Physics")["IsOnGround"];
if (grounded) { if (grounded) {
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = LocalPlayer.ID; e.Emitter = LocalPlayer;
e.FilePath = "Audio/Jump/Jump1.wav"; e.FilePath = "Audio/Jump/Jump1.wav";
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
@@ -106,7 +106,7 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
if (!IsClient) { // Only play for clients if (!IsClient) { // Only play for clients
return false; return false;
} }
if (LocalPlayer.ID = e.Victim.ID) { // You're local player was the one who took dmg if(!e.Victim.Valid()) {
return false; return false;
} }
std::uniform_int_distribution<int> dist(1, 12); std::uniform_int_distribution<int> dist(1, 12);
@@ -115,7 +115,7 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
paths.push_back("Audio/Hurt/Hurt" + std::to_string(rand) + ".wav"); paths.push_back("Audio/Hurt/Hurt" + std::to_string(rand) + ".wav");
Events::PlayQueueOnEntity ev; Events::PlayQueueOnEntity ev;
ev.Emitter = LocalPlayer; ev.Emitter = e.Victim;
ev.FilePaths = paths; ev.FilePaths = paths;
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
return false; return false;
@@ -123,7 +123,7 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
{ {
if (e.Player.ID != LocalPlayer.ID) { if (!e.Player.Valid()) {
return false; return false;
} }
if (!IsClient) { if (!IsClient) {
@@ -132,7 +132,8 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
// The local player is dead. The local player might be invalid? // The local player is dead. The local player might be invalid?
// Play the sound from the listener. // Play the sound from the listener.
// TODO: We might want to hear other players die. // TODO: We might want to hear other players die.
Events::PlayBackgroundMusic ev; Events::PlaySoundOnEntity ev;
ev.Emitter = e.Player;
ev.FilePath = "Audio/Die/Die2.wav"; ev.FilePath = "Audio/Die/Die2.wav";
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
return false; return false;
@@ -141,7 +142,7 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e) bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e)
{ {
Events::PlaySoundOnEntity ev; Events::PlaySoundOnEntity ev;
ev.EmitterID = LocalPlayer.ID; ev.Emitter = LocalPlayer;
ev.FilePath = "Audio/Pickup/Pickup2.wav"; ev.FilePath = "Audio/Pickup/Pickup2.wav";
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
return false; return false;
@@ -156,7 +157,7 @@ bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e)
return false; return false;
} }
Events::PlaySoundOnEntity ev; Events::PlaySoundOnEntity ev;
ev.EmitterID = e.entityID; ev.Emitter = EntityWrapper(m_World, e.entityID);
ev.FilePath = "Audio/Jump/Jump2.wav"; ev.FilePath = "Audio/Jump/Jump2.wav";
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
return false; return false;
@@ -87,9 +87,12 @@ void DefenderWeaponBehaviour::fireShell(WeaponInfo& wi)
if (weaponModelEntity.Valid()) { if (weaponModelEntity.Valid()) {
EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle"); EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle");
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = weaponModelEntity.ID; e.Emitter = weaponModelEntity;
e.FilePath = "Audio/weapon/Shotgun/ShotgunFire.wav"; e.FilePath = "Audio/weapon/Shotgun/ShotgunFire.wav";
m_EventBroker->Publish(e); e.Gain = 1.f;
if (IsClient) {
m_EventBroker->Publish(e);
}
for (auto& angles : pelletAngles) { for (auto& angles : pelletAngles) {
glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1); glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1);
float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction); float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction);