Animation system now listens to pause events

This commit is contained in:
2015-10-15 18:39:47 +02:00
parent a9eb3197de
commit f335955396
2 changed files with 23 additions and 0 deletions
+8
View File
@@ -4,6 +4,7 @@
#include "Core/System.h" #include "Core/System.h"
#include "Core/World.h" #include "Core/World.h"
#include "Rendering/CAnimation.h" #include "Rendering/CAnimation.h"
#include "Game/EPause.h"
namespace dd namespace dd
{ {
@@ -17,7 +18,14 @@ public:
: System(world, eventBroker) { } : System(world, eventBroker) { }
void RegisterComponents(ComponentFactory* cf) override; void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
void Update(double dt) override; void Update(double dt) override;
private:
bool m_Paused = false;
EventRelay<AnimationSystem, Events::Pause> m_EPause;
bool OnPause(const Events::Pause& e);
}; };
} }
+15
View File
@@ -6,8 +6,17 @@ void dd::Systems::AnimationSystem::RegisterComponents(ComponentFactory* cf)
cf->Register<Components::Animation>(); cf->Register<Components::Animation>();
} }
void dd::Systems::AnimationSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EPause, &AnimationSystem::OnPause);
}
void dd::Systems::AnimationSystem::Update(double dt) void dd::Systems::AnimationSystem::Update(double dt)
{ {
if (m_Paused) {
return;
}
auto animations = m_World->GetComponentsOfType<Components::Animation>(); auto animations = m_World->GetComponentsOfType<Components::Animation>();
if (animations == nullptr) { if (animations == nullptr) {
return; return;
@@ -18,3 +27,9 @@ void dd::Systems::AnimationSystem::Update(double dt)
animation->Time += animation->Speed * dt; animation->Time += animation->Speed * dt;
} }
} }
bool dd::Systems::AnimationSystem::OnPause(const Events::Pause& e)
{
m_Paused = !m_Paused;
return true;
}