From 167f78951ebc332991aba73647133c475bbd4281 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 10 Mar 2016 00:08:58 +0100 Subject: [PATCH] Made RespawnSystem not spawn while world is paused --- include/Engine/Core/RespawnSystem.h | 6 ++++++ src/Engine/Core/RespawnSystem.cpp | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/Engine/Core/RespawnSystem.h b/include/Engine/Core/RespawnSystem.h index bd604b79..eda73633 100644 --- a/include/Engine/Core/RespawnSystem.h +++ b/include/Engine/Core/RespawnSystem.h @@ -4,6 +4,7 @@ #include "System.h" #include "SpawnerSystem.h" #include "EEntityDeleted.h" +#include "EPause.h" class RespawnSystem : public PureSystem { @@ -14,9 +15,14 @@ public: private: std::unordered_map m_LastRespawnedEntity; + bool m_Paused = false; EventRelay m_EEntityDeleted; bool OnEntityDeleted(const Events::EntityDeleted& e); + EventRelay m_EPause; + bool OnPause(const Events::Pause& e); + EventRelay m_EResume; + bool OnResume(const Events::Resume& e); }; #endif \ No newline at end of file diff --git a/src/Engine/Core/RespawnSystem.cpp b/src/Engine/Core/RespawnSystem.cpp index 17a48c91..3def6ef1 100644 --- a/src/Engine/Core/RespawnSystem.cpp +++ b/src/Engine/Core/RespawnSystem.cpp @@ -5,10 +5,16 @@ RespawnSystem::RespawnSystem(SystemParams params) , PureSystem("Respawn") { EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &RespawnSystem::OnEntityDeleted); + EVENT_SUBSCRIBE_MEMBER(m_EPause, &RespawnSystem::OnPause); + EVENT_SUBSCRIBE_MEMBER(m_EResume, &RespawnSystem::OnResume); } void RespawnSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cRespawn, double dt) { + if (m_Paused) { + return; + } + if (!entity.HasComponent("Spawner")) { return; } @@ -30,3 +36,19 @@ bool RespawnSystem::OnEntityDeleted(const Events::EntityDeleted& e) return true; } +bool RespawnSystem::OnPause(const Events::Pause& e) +{ + if (e.World == m_World) { + m_Paused = true; + } + return true; +} + +bool RespawnSystem::OnResume(const Events::Resume& e) +{ + if (e.World == m_World) { + m_Paused = false; + } + return true; +} +