From e299e1f03ed446cf1a2484908e4311fedb1960a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Mon, 9 Apr 2018 12:37:58 +0200 Subject: [PATCH] Sdk/World: Add ForEachSystem method --- ChangeLog.md | 1 + SDK/include/NDK/World.hpp | 3 +++ SDK/include/NDK/World.inl | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index b9182f536..fc9d90771 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -121,6 +121,7 @@ Nazara Development Kit: - Fixed EntityList copy/movement assignment operator which was not properly unregistering contained entities. - ListenerSystem now handles velocity in a generic way (no longer require a VelocityComponent and is compatible with physics) - World now has const getters for systems +- Add World::ForEachSystem method, allowing iteration on every active system on a specific world # 0.4: diff --git a/SDK/include/NDK/World.hpp b/SDK/include/NDK/World.hpp index 214f8e936..9b1d4c970 100644 --- a/SDK/include/NDK/World.hpp +++ b/SDK/include/NDK/World.hpp @@ -50,6 +50,9 @@ namespace Ndk inline void DisableProfiler(); inline void EnableProfiler(bool enable = true); + template void ForEachSystem(const F& iterationFunc); + template void ForEachSystem(const F& iterationFunc) const; + inline const EntityHandle& GetEntity(EntityId id); inline const EntityList& GetEntities() const; inline const ProfilerData& GetProfilerData() const; diff --git a/SDK/include/NDK/World.inl b/SDK/include/NDK/World.inl index fb8549ea6..efe8b0480 100644 --- a/SDK/include/NDK/World.inl +++ b/SDK/include/NDK/World.inl @@ -133,6 +133,40 @@ namespace Ndk } } + /*! + * \brief Executes a function on every present system + * + * Calls iterationFunc on every previously added system, in the same order as their indexes + * + * \param iterationFunc Function to be called + */ + template + void World::ForEachSystem(const F& iterationFunc) + { + for (const auto& systemPtr : m_systems) + { + if (systemPtr) + iterationFunc(*systemPtr); + } + } + + /*! + * \brief Executes a function on every present system + * + * Calls iterationFunc on every previously added system, in the same order as their indexes + * + * \param iterationFunc Function to be called + */ + template + void World::ForEachSystem(const F& iterationFunc) const + { + for (const auto& systemPtr : m_systems) + { + if (systemPtr) + iterationFunc(static_cast(*systemPtr)); //< Force const reference + } + } + /*! * \brief Gets an entity * \return A constant reference to a handle of the entity @@ -392,7 +426,7 @@ namespace Ndk m_orderedSystems = std::move(world.m_orderedSystems); m_orderedSystemsUpdated = world.m_orderedSystemsUpdated; m_profilerData = std::move(world.m_profilerData); - m_isProfilerEnabled = world.m_isProfilerEnabled; + m_isProfilerEnabled = m_isProfilerEnabled; m_entities = std::move(world.m_entities); for (EntityBlock& block : m_entities)