Fixed bug where it crashed on respawn. Also bug where i subscribed to an event twice.
This commit is contained in:
@@ -101,9 +101,17 @@ void SoundManager::updateEmitters(double dt)
|
|||||||
if (!m_World->ValidEntity(it->first)) {
|
if (!m_World->ValidEntity(it->first)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!m_World->HasComponent(it->first, "SoundEmitter"))
|
||||||
|
return;
|
||||||
|
|
||||||
glm::vec3 previousPos;
|
glm::vec3 previousPos;
|
||||||
alGetSource3f(it->second->ALsource, AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z);
|
alGetSource3f(it->second->ALsource, AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z);
|
||||||
// Get next pos
|
// 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);
|
glm::vec3 nextPos = Transform::AbsolutePosition(m_World, it->first);
|
||||||
// Calculate velocity
|
// Calculate velocity
|
||||||
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt;
|
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++) {
|
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
|
||||||
EntityWrapper listener(m_World, (*it).EntityID);
|
EntityWrapper listener(m_World, (*it).EntityID);
|
||||||
|
if (!listener.Valid())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (listener.IsChildOf(m_LocalPlayer) || listener == m_LocalPlayer) {
|
if (listener.IsChildOf(m_LocalPlayer) || listener == m_LocalPlayer) {
|
||||||
glm::vec3 previousPos;
|
glm::vec3 previousPos;
|
||||||
alGetListener3f(AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z); // Get previous pos
|
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)
|
bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
|
||||||
{
|
{
|
||||||
auto listenerComponents = m_World->GetComponents("Listener");
|
auto listenerComponents = m_World->GetComponents("Listener");
|
||||||
|
LOG_INFO("SIZZE: %i", listenerComponents->size());
|
||||||
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
|
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
|
||||||
|
if((*it).EntityID != m_LocalPlayer.ID) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
auto emitterChild = m_World->CreateEntity((*it).EntityID);
|
auto emitterChild = m_World->CreateEntity((*it).EntityID);
|
||||||
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
|
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
|
||||||
(bool&)emitter["Loop"] = false;
|
(bool&)emitter["Loop"] = false;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
SoundSystem::SoundSystem(World* world, EventBroker* eventbroker)
|
SoundSystem::SoundSystem(World* world, EventBroker* eventbroker)
|
||||||
: System(world, eventbroker)
|
: System(world, eventbroker)
|
||||||
, PureSystem("SoundEmitter")
|
, PureSystem("SoundEmitter")
|
||||||
, ImpureSystem()
|
//, ImpureSystem()
|
||||||
{
|
{
|
||||||
m_World = world;
|
m_World = world;
|
||||||
m_EventBroker = eventbroker;
|
m_EventBroker = eventbroker;
|
||||||
@@ -12,7 +12,6 @@ SoundSystem::SoundSystem(World* world, EventBroker* eventbroker)
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump);
|
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundSystem::OnDashAbility);
|
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundSystem::OnDashAbility);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EShoot, &SoundSystem::OnShoot);
|
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_EPlayerDamage, &SoundSystem::OnPlayerDamage);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
|
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch);
|
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch);
|
||||||
@@ -31,10 +30,10 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
|
|||||||
if (e.PlayerID == -1) { // Local player
|
if (e.PlayerID == -1) { // Local player
|
||||||
m_World->AttachComponent(e.Player.ID, "Listener");
|
m_World->AttachComponent(e.Player.ID, "Listener");
|
||||||
m_LocalPlayer = e.Player;
|
m_LocalPlayer = e.Player;
|
||||||
Events::PlaySoundOnEntity event;
|
Events::PlaySoundOnEntity go;
|
||||||
event.EmitterID = createChildEmitter(m_LocalPlayer);
|
go.EmitterID = createChildEmitter(m_LocalPlayer);
|
||||||
event.FilePath = "Audio/announcer/go.wav";
|
go.FilePath = "Audio/announcer/go.wav";
|
||||||
m_EventBroker->Publish(event);
|
m_EventBroker->Publish(go);
|
||||||
// TEMP: starts bgm
|
// TEMP: starts bgm
|
||||||
{
|
{
|
||||||
Events::PlayBackgroundMusic ev;
|
Events::PlayBackgroundMusic ev;
|
||||||
@@ -131,7 +130,7 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
|
|||||||
//if (e.PlayerID == m_LocalPlayer.ID) {
|
//if (e.PlayerID == m_LocalPlayer.ID) {
|
||||||
Events::PlaySoundOnEntity ev;
|
Events::PlaySoundOnEntity ev;
|
||||||
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
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);
|
m_EventBroker->Publish(ev);
|
||||||
//}
|
//}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user