diff --git a/SDK/include/NDK/BaseSystem.hpp b/SDK/include/NDK/BaseSystem.hpp index 9204f0fe0..1c9a0aa86 100644 --- a/SDK/include/NDK/BaseSystem.hpp +++ b/SDK/include/NDK/BaseSystem.hpp @@ -51,6 +51,10 @@ namespace Ndk template void Requires(); void RequiresComponent(ComponentIndex index); + template void RequiresAny(); + template void RequiresAny(); + void RequiresAnyComponent(ComponentIndex index); + private: void AddEntity(Entity* entity); @@ -68,6 +72,7 @@ namespace Ndk NzBitset m_entityBits; NzBitset<> m_excludedComponents; mutable NzBitset<> m_filterResult; + NzBitset<> m_requiredAnyComponents; NzBitset<> m_requiredComponents; SystemIndex m_systemIndex; World* m_world; diff --git a/SDK/include/NDK/BaseSystem.inl b/SDK/include/NDK/BaseSystem.inl index 6c4ac16cd..3f1d453c6 100644 --- a/SDK/include/NDK/BaseSystem.inl +++ b/SDK/include/NDK/BaseSystem.inl @@ -87,11 +87,31 @@ namespace Ndk m_requiredComponents.UnboundedSet(index); } + template + void BaseSystem::RequiresAny() + { + static_assert(std::is_base_of(), "ComponentType is not a component"); + + RequiresAnyComponent(GetComponentIndex()); + } + + template + void BaseSystem::RequiresAny() + { + RequiresAny(); + RequiresAny(); + } + + inline void BaseSystem::RequiresAnyComponent(ComponentIndex index) + { + m_requiredAnyComponents.UnboundedSet(index); + } + inline void BaseSystem::AddEntity(Entity* entity) { NazaraAssert(entity, "Invalid entity"); - m_entities.push_back(entity->CreateHandle()); + m_entities.emplace_back(entity); m_entityBits.UnboundedSet(entity->GetId(), true); entity->RegisterSystem(m_systemIndex); diff --git a/SDK/src/NDK/BaseSystem.cpp b/SDK/src/NDK/BaseSystem.cpp index 6c60f435c..a8e951d4e 100644 --- a/SDK/src/NDK/BaseSystem.cpp +++ b/SDK/src/NDK/BaseSystem.cpp @@ -27,6 +27,13 @@ namespace Ndk if (m_filterResult.TestAny()) return false; // Au moins un component exclu est présent + // Si nous avons une liste de composants nécessaires + if (m_requiredAnyComponents.TestAny()) + { + if (!m_requiredAnyComponents.Intersects(components)) + return false; + } + return true; }