SDK/System: Add possibility to disable systems without destroying them
Former-commit-id: 7f5c006d80ba2e7f0babf67c908216b9ca190c70 [formerly 66eab17e82f0cbe6ff89506096573ffd33ccf241] [formerly fadc95f707e00f1cfc9542c7b5aca2e1643aaeec [formerly 8f0f812c57785cad50bd0977c3c592e42b79c5a7]] Former-commit-id: 07a07da0bc9436fa7035e8265c7a2f4aaec26ef2 [formerly e577306b868cdf3186f1c417c7396d237fb9a08b] Former-commit-id: 5bd70063f389a01d704f484350b48fe0674f4b7e
This commit is contained in:
parent
3933af597f
commit
d29813de02
|
|
@ -27,6 +27,8 @@ namespace Ndk
|
||||||
BaseSystem(BaseSystem&&) noexcept = default;
|
BaseSystem(BaseSystem&&) noexcept = default;
|
||||||
virtual ~BaseSystem();
|
virtual ~BaseSystem();
|
||||||
|
|
||||||
|
inline void Enable(bool enable = true);
|
||||||
|
|
||||||
virtual BaseSystem* Clone() const = 0;
|
virtual BaseSystem* Clone() const = 0;
|
||||||
|
|
||||||
bool Filters(const Entity* entity) const;
|
bool Filters(const Entity* entity) const;
|
||||||
|
|
@ -36,6 +38,8 @@ namespace Ndk
|
||||||
inline float GetUpdateRate() const;
|
inline float GetUpdateRate() const;
|
||||||
inline World& GetWorld() const;
|
inline World& GetWorld() const;
|
||||||
|
|
||||||
|
inline bool IsEnabled() const;
|
||||||
|
|
||||||
inline bool HasEntity(const Entity* entity) const;
|
inline bool HasEntity(const Entity* entity) const;
|
||||||
|
|
||||||
inline void SetUpdateRate(float updatePerSecond);
|
inline void SetUpdateRate(float updatePerSecond);
|
||||||
|
|
@ -86,6 +90,7 @@ namespace Ndk
|
||||||
Nz::Bitset<> m_requiredComponents;
|
Nz::Bitset<> m_requiredComponents;
|
||||||
SystemIndex m_systemIndex;
|
SystemIndex m_systemIndex;
|
||||||
World* m_world;
|
World* m_world;
|
||||||
|
bool m_updateEnabled;
|
||||||
float m_updateCounter;
|
float m_updateCounter;
|
||||||
float m_updateRate;
|
float m_updateRate;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,14 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
// This file is part of the "Nazara Development Kit"
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/BaseSystem.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
inline BaseSystem::BaseSystem(SystemIndex systemId) :
|
inline BaseSystem::BaseSystem(SystemIndex systemId) :
|
||||||
|
m_updateEnabled(true),
|
||||||
m_systemIndex(systemId)
|
m_systemIndex(systemId)
|
||||||
{
|
{
|
||||||
SetUpdateRate(30);
|
SetUpdateRate(30);
|
||||||
|
|
@ -17,11 +19,17 @@ namespace Ndk
|
||||||
m_excludedComponents(system.m_excludedComponents),
|
m_excludedComponents(system.m_excludedComponents),
|
||||||
m_requiredComponents(system.m_requiredComponents),
|
m_requiredComponents(system.m_requiredComponents),
|
||||||
m_systemIndex(system.m_systemIndex),
|
m_systemIndex(system.m_systemIndex),
|
||||||
|
m_updateEnabled(system.m_updateEnabled),
|
||||||
m_updateCounter(0.f),
|
m_updateCounter(0.f),
|
||||||
m_updateRate(system.m_updateRate)
|
m_updateRate(system.m_updateRate)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void BaseSystem::Enable(bool enable)
|
||||||
|
{
|
||||||
|
m_updateEnabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
inline const std::vector<EntityHandle>& BaseSystem::GetEntities() const
|
inline const std::vector<EntityHandle>& BaseSystem::GetEntities() const
|
||||||
{
|
{
|
||||||
return m_entities;
|
return m_entities;
|
||||||
|
|
@ -42,6 +50,11 @@ namespace Ndk
|
||||||
return *m_world;
|
return *m_world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool BaseSystem::IsEnabled() const
|
||||||
|
{
|
||||||
|
return m_updateEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool BaseSystem::HasEntity(const Entity* entity) const
|
inline bool BaseSystem::HasEntity(const Entity* entity) const
|
||||||
{
|
{
|
||||||
if (!entity)
|
if (!entity)
|
||||||
|
|
@ -58,6 +71,9 @@ namespace Ndk
|
||||||
|
|
||||||
inline void BaseSystem::Update(float elapsedTime)
|
inline void BaseSystem::Update(float elapsedTime)
|
||||||
{
|
{
|
||||||
|
if (!IsEnabled())
|
||||||
|
return;
|
||||||
|
|
||||||
if (m_updateRate > 0.f)
|
if (m_updateRate > 0.f)
|
||||||
{
|
{
|
||||||
m_updateCounter += elapsedTime;
|
m_updateCounter += elapsedTime;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue