From 8bc5e618b196b2ac7bba106b088c9432874189e6 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 14 Aug 2016 17:56:01 +0200 Subject: [PATCH] SDK/System: Add possibility to disable systems without destroying them Former-commit-id: d72fc2252c8c55e0ef93aa28592fdf734e187d64 [formerly 84c57abb22494dbc67a02db65dc39e282fab0ec3] [formerly 4b302cfc908f0ddfa45facdf707199a1a41a98d1 [formerly a971f3d0eb400aabe9695613ca63672b0dbaeec2]] Former-commit-id: 3e03a4cd321c860dd3e264302839c5eb05bd2a85 [formerly 7db586c2246267f71fd54f4feb2c0b911e8c6387] Former-commit-id: aa53d5f6f7ca2428d9a76b6e4e1b6785ce4b1c1f --- SDK/include/NDK/BaseSystem.hpp | 5 +++++ SDK/include/NDK/BaseSystem.inl | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/SDK/include/NDK/BaseSystem.hpp b/SDK/include/NDK/BaseSystem.hpp index 8e828149d..969f2b773 100644 --- a/SDK/include/NDK/BaseSystem.hpp +++ b/SDK/include/NDK/BaseSystem.hpp @@ -27,6 +27,8 @@ namespace Ndk BaseSystem(BaseSystem&&) noexcept = default; virtual ~BaseSystem(); + inline void Enable(bool enable = true); + virtual BaseSystem* Clone() const = 0; bool Filters(const Entity* entity) const; @@ -36,6 +38,8 @@ namespace Ndk inline float GetUpdateRate() const; inline World& GetWorld() const; + inline bool IsEnabled() const; + inline bool HasEntity(const Entity* entity) const; inline void SetUpdateRate(float updatePerSecond); @@ -86,6 +90,7 @@ namespace Ndk Nz::Bitset<> m_requiredComponents; SystemIndex m_systemIndex; World* m_world; + bool m_updateEnabled; float m_updateCounter; float m_updateRate; diff --git a/SDK/include/NDK/BaseSystem.inl b/SDK/include/NDK/BaseSystem.inl index 0c2811ac0..490b32e76 100644 --- a/SDK/include/NDK/BaseSystem.inl +++ b/SDK/include/NDK/BaseSystem.inl @@ -2,12 +2,14 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp +#include #include #include namespace Ndk { inline BaseSystem::BaseSystem(SystemIndex systemId) : + m_updateEnabled(true), m_systemIndex(systemId) { SetUpdateRate(30); @@ -17,11 +19,17 @@ namespace Ndk m_excludedComponents(system.m_excludedComponents), m_requiredComponents(system.m_requiredComponents), m_systemIndex(system.m_systemIndex), + m_updateEnabled(system.m_updateEnabled), m_updateCounter(0.f), m_updateRate(system.m_updateRate) { } + inline void BaseSystem::Enable(bool enable) + { + m_updateEnabled = enable; + } + inline const std::vector& BaseSystem::GetEntities() const { return m_entities; @@ -42,6 +50,11 @@ namespace Ndk return *m_world; } + inline bool BaseSystem::IsEnabled() const + { + return m_updateEnabled; + } + inline bool BaseSystem::HasEntity(const Entity* entity) const { if (!entity) @@ -58,6 +71,9 @@ namespace Ndk inline void BaseSystem::Update(float elapsedTime) { + if (!IsEnabled()) + return; + if (m_updateRate > 0.f) { m_updateCounter += elapsedTime;