From a101f7c71ffd5177bd9c20e9b8490c1b27381c3c Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 27 Jul 2023 15:09:15 +0200 Subject: [PATCH] Core/EnttWorld: Add RemoveSystem method --- include/Nazara/Core/EnttSystemGraph.hpp | 2 ++ include/Nazara/Core/EnttSystemGraph.inl | 12 ++++++++++++ include/Nazara/Core/EnttWorld.hpp | 2 ++ include/Nazara/Core/EnttWorld.inl | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/include/Nazara/Core/EnttSystemGraph.hpp b/include/Nazara/Core/EnttSystemGraph.hpp index ac1251278..30697afda 100644 --- a/include/Nazara/Core/EnttSystemGraph.hpp +++ b/include/Nazara/Core/EnttSystemGraph.hpp @@ -30,6 +30,8 @@ namespace Nz template T& GetSystem() const; + template void RemoveSystem(); + void Update(); void Update(Time elapsedTime); diff --git a/include/Nazara/Core/EnttSystemGraph.inl b/include/Nazara/Core/EnttSystemGraph.inl index 2e4c69c36..12bde195d 100644 --- a/include/Nazara/Core/EnttSystemGraph.inl +++ b/include/Nazara/Core/EnttSystemGraph.inl @@ -71,6 +71,18 @@ namespace Nz auto& node = static_cast&>(*m_nodes[it->second]); return node.system; } + + template + void EnttSystemGraph::RemoveSystem() + { + auto it = m_systemToNodes.find(entt::type_hash()); + if (it == m_systemToNodes.end()) + return; + + m_nodes.erase(m_nodes.begin() + it->second); + m_systemToNodes.erase(it); + m_systemOrderUpdated = false; + } } #include diff --git a/include/Nazara/Core/EnttWorld.hpp b/include/Nazara/Core/EnttWorld.hpp index 5433cbb7e..29afd0404 100644 --- a/include/Nazara/Core/EnttWorld.hpp +++ b/include/Nazara/Core/EnttWorld.hpp @@ -30,6 +30,8 @@ namespace Nz const entt::registry& GetRegistry() const; template T& GetSystem() const; + template void RemoveSystem(); + void Update(Time elapsedTime) override; operator entt::registry&(); diff --git a/include/Nazara/Core/EnttWorld.inl b/include/Nazara/Core/EnttWorld.inl index 31ceae198..d076bb214 100644 --- a/include/Nazara/Core/EnttWorld.inl +++ b/include/Nazara/Core/EnttWorld.inl @@ -38,6 +38,12 @@ namespace Nz return m_systemGraph.GetSystem(); } + template + void EnttWorld::RemoveSystem() + { + return m_systemGraph.RemoveSystem(); + } + inline EnttWorld::operator entt::registry&() { return m_registry;