Fixed bug where it crashed on respawn. Also bug where i subscribed to an event twice.

This commit is contained in:
stiffly
2016-02-08 16:13:09 +01:00
parent 14c5410524
commit 6f163bf3a3
2 changed files with 22 additions and 7 deletions
+16
View File
@@ -101,9 +101,17 @@ void SoundManager::updateEmitters(double dt)
if (!m_World->ValidEntity(it->first)) {
return;
}
if (!m_World->HasComponent(it->first, "SoundEmitter"))
return;
glm::vec3 previousPos;
alGetSource3f(it->second->ALsource, AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z);
// Get next pos
if (!m_World->HasComponent(it->first, "Transform"))
return;
if (!m_World->ValidEntity(m_World->GetParent(it->first))) {
return;
}
glm::vec3 nextPos = Transform::AbsolutePosition(m_World, it->first);
// Calculate velocity
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt;
@@ -135,6 +143,10 @@ void SoundManager::updateListener(double dt)
}
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
EntityWrapper listener(m_World, (*it).EntityID);
if (!listener.Valid())
{
break;
}
if (listener.IsChildOf(m_LocalPlayer) || listener == m_LocalPlayer) {
glm::vec3 previousPos;
alGetListener3f(AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z); // Get previous pos
@@ -228,7 +240,11 @@ bool SoundManager::OnContinueSound(const Events::ContinueSound & e)
bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
{
auto listenerComponents = m_World->GetComponents("Listener");
LOG_INFO("SIZZE: %i", listenerComponents->size());
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
if((*it).EntityID != m_LocalPlayer.ID) {
break;
}
auto emitterChild = m_World->CreateEntity((*it).EntityID);
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
(bool&)emitter["Loop"] = false;
+6 -7
View File
@@ -3,7 +3,7 @@
SoundSystem::SoundSystem(World* world, EventBroker* eventbroker)
: System(world, eventbroker)
, PureSystem("SoundEmitter")
, ImpureSystem()
//, ImpureSystem()
{
m_World = world;
m_EventBroker = eventbroker;
@@ -12,7 +12,6 @@ SoundSystem::SoundSystem(World* world, EventBroker* eventbroker)
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump);
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundSystem::OnDashAbility);
EVENT_SUBSCRIBE_MEMBER(m_EShoot, &SoundSystem::OnShoot);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage);
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch);
@@ -31,10 +30,10 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
if (e.PlayerID == -1) { // Local player
m_World->AttachComponent(e.Player.ID, "Listener");
m_LocalPlayer = e.Player;
Events::PlaySoundOnEntity event;
event.EmitterID = createChildEmitter(m_LocalPlayer);
event.FilePath = "Audio/announcer/go.wav";
m_EventBroker->Publish(event);
Events::PlaySoundOnEntity go;
go.EmitterID = createChildEmitter(m_LocalPlayer);
go.FilePath = "Audio/announcer/go.wav";
m_EventBroker->Publish(go);
// TEMP: starts bgm
{
Events::PlayBackgroundMusic ev;
@@ -131,7 +130,7 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
//if (e.PlayerID == m_LocalPlayer.ID) {
Events::PlaySoundOnEntity ev;
ev.EmitterID = createChildEmitter(m_LocalPlayer);
ev.FilePath = "Audio/die/die2.wav"; // should random between a bunch
ev.FilePath = "Audio/die/die2.wav";
m_EventBroker->Publish(ev);
//}
return false;