From 6d1ac4fe18ba99ffa97364fe2caa3c19a8bb3aa2 Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 30 Mar 2015 04:18:44 +0200 Subject: [PATCH] Re-remade component and system ids Former-commit-id: 98b76695cca904c55c7333801c3cdf693da15086 --- SDK/include/NDK/Algorithm.hpp | 7 +++--- SDK/include/NDK/Algorithm.inl | 26 ++++++-------------- SDK/include/NDK/BaseComponent.hpp | 26 +++++++++++++++++--- SDK/include/NDK/BaseComponent.inl | 39 ++++++++++++++++++++++++++---- SDK/include/NDK/BaseSystem.hpp | 20 +++++++++------- SDK/include/NDK/BaseSystem.inl | 29 ++++++++++++---------- SDK/include/NDK/Component.inl | 3 +-- SDK/include/NDK/Entity.hpp | 19 ++++++++------- SDK/include/NDK/Entity.inl | 40 +++++++++++++++++++------------ SDK/include/NDK/Prerequesites.hpp | 5 ++-- SDK/include/NDK/System.inl | 2 +- SDK/include/NDK/World.hpp | 8 +++---- SDK/include/NDK/World.inl | 40 +++++++++++++++++-------------- SDK/src/NDK/BaseComponent.cpp | 3 +++ SDK/src/NDK/BaseSystem.cpp | 24 +++++++++---------- SDK/src/NDK/Entity.cpp | 27 +++++++++++++-------- SDK/src/NDK/World.cpp | 4 +--- 17 files changed, 196 insertions(+), 126 deletions(-) diff --git a/SDK/include/NDK/Algorithm.hpp b/SDK/include/NDK/Algorithm.hpp index 0e6758564..1a7dc52ab 100644 --- a/SDK/include/NDK/Algorithm.hpp +++ b/SDK/include/NDK/Algorithm.hpp @@ -11,10 +11,9 @@ namespace Ndk { - template ComponentId BuildComponentId(const char (&id)[N]); - template SystemId BuildSystemId(const char (&id)[N]); - template constexpr ComponentId GetComponentId(); - template constexpr SystemId GetSystemId(); + template ComponentId BuildComponentId(const char (&name)[N]); + template constexpr ComponentIndex GetComponentIndex(); + template constexpr SystemIndex GetSystemIndex(); } #include diff --git a/SDK/include/NDK/Algorithm.inl b/SDK/include/NDK/Algorithm.inl index 8d4710d34..f07825e8d 100644 --- a/SDK/include/NDK/Algorithm.inl +++ b/SDK/include/NDK/Algorithm.inl @@ -8,38 +8,26 @@ namespace Ndk { ///TODO: constexpr avec le C++14 template - ComponentId BuildComponentId(const char (&id)[N]) + ComponentId BuildComponentId(const char (&name)[N]) { - static_assert(N-1 <= sizeof(ComponentId), "ID too long for this size of component id"); + static_assert(N-1 <= sizeof(ComponentId), "Name too long for this size of component id"); ComponentId componentId = 0; for (int i = 0; i < N; ++i) - componentId |= static_cast(id[i]) << i*8; - - return componentId; - } - - template - SystemId BuildSystemId(const char (&id)[N]) - { - static_assert(N-1 <= sizeof(ComponentId), "ID too long for this size of component id"); - - ComponentId componentId = 0; - for (int i = 0; i < N; ++i) - componentId |= static_cast(id[i]) << i*8; + componentId |= static_cast(name[i]) << i*8; return componentId; } template - constexpr ComponentId GetComponentId() + constexpr ComponentIndex GetComponentIndex() { - return ComponentType::ComponentId; + return ComponentType::ComponentIndex; } template - constexpr SystemId GetSystemId() + constexpr SystemIndex GetSystemIndex() { - return SystemType::SystemId; + return SystemType::SystemIndex; } } diff --git a/SDK/include/NDK/BaseComponent.hpp b/SDK/include/NDK/BaseComponent.hpp index a77514d64..d9ae7410a 100644 --- a/SDK/include/NDK/BaseComponent.hpp +++ b/SDK/include/NDK/BaseComponent.hpp @@ -8,21 +8,41 @@ #define NDK_BASECOMPONENT_HPP #include +#include +#include +#include namespace Ndk { class NDK_API BaseComponent { public: - BaseComponent(ComponentId componentId); + using Factory = std::function; + + BaseComponent(ComponentIndex componentIndex); virtual ~BaseComponent(); virtual BaseComponent* Clone() const = 0; - ComponentId GetId() const; + ComponentIndex GetIndex() const; + + template + static ComponentIndex Register(const char (&name)[N]); + + static ComponentIndex Register(ComponentId id, Factory factoryFunc); protected: - ComponentId m_componentId; + ComponentIndex m_componentIndex; + + private: + struct ComponentEntry + { + ComponentId id; + Factory factory; + }; + + static std::vector s_entries; + static std::unordered_map s_idToIndex; }; } diff --git a/SDK/include/NDK/BaseComponent.inl b/SDK/include/NDK/BaseComponent.inl index f0262f042..8dde48ed6 100644 --- a/SDK/include/NDK/BaseComponent.inl +++ b/SDK/include/NDK/BaseComponent.inl @@ -2,15 +2,46 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp +#include +#include + namespace Ndk { - inline BaseComponent::BaseComponent(ComponentId componentId) : - m_componentId(componentId) + inline BaseComponent::BaseComponent(ComponentIndex index) : + m_componentIndex(index) { } - inline ComponentId BaseComponent::GetId() const + inline ComponentIndex BaseComponent::GetIndex() const { - return m_componentId; + return m_componentIndex; + } + + template + ComponentIndex BaseComponent::Register(const char (&name)[N]) + { + static_assert(std::is_default_constructible::value, "ComponentType should be default-constructible"); + + ComponentId id = BuildComponentId(name); + auto factory = []() -> BaseComponent* + { + return new ComponentType; + }; + + return Register(id, factory); + } + + inline ComponentIndex BaseComponent::Register(ComponentId id, Factory factoryFunc) + { + ComponentIndex index = s_entries.size(); + + s_entries.resize(index + 1); + ComponentEntry& entry = s_entries.back(); + entry.factory = factoryFunc; + entry.id = id; + + s_idToIndex[id] = index; + + return index; } } diff --git a/SDK/include/NDK/BaseSystem.hpp b/SDK/include/NDK/BaseSystem.hpp index 99478d558..b5d7441d1 100644 --- a/SDK/include/NDK/BaseSystem.hpp +++ b/SDK/include/NDK/BaseSystem.hpp @@ -10,7 +10,6 @@ #include #include #include -#include namespace Ndk { @@ -22,7 +21,7 @@ namespace Ndk friend World; public: - BaseSystem(SystemId systemId); + BaseSystem(SystemIndex systemId); virtual ~BaseSystem(); virtual BaseSystem* Clone() const = 0; @@ -30,19 +29,21 @@ namespace Ndk bool Filters(const Entity* entity) const; const std::vector& GetEntities() const; - SystemId GetId() const; + SystemIndex GetIndex() const; World& GetWorld() const; bool HasEntity(const Entity* entity) const; + static SystemIndex GetNextIndex(); + protected: template void Excludes(); template void Excludes(); - void ExcludesComponent(ComponentId componentId); + void ExcludesComponent(ComponentIndex index); template void Requires(); template void Requires(); - void RequiresComponent(ComponentId componentId); + void RequiresComponent(ComponentIndex index); private: void AddEntity(Entity* entity); @@ -56,10 +57,13 @@ namespace Ndk std::vector m_entities; NzBitset m_entityBits; - std::unordered_set m_excludedComponents; - std::unordered_set m_requiredComponents; - SystemId m_systemId; + NzBitset<> m_excludedComponents; + mutable NzBitset<> m_filterResult; + NzBitset<> m_requiredComponents; + SystemIndex m_systemIndex; World* m_world; + + static SystemIndex s_nextIndex; }; } diff --git a/SDK/include/NDK/BaseSystem.inl b/SDK/include/NDK/BaseSystem.inl index 91efa89fe..596591e1f 100644 --- a/SDK/include/NDK/BaseSystem.inl +++ b/SDK/include/NDK/BaseSystem.inl @@ -7,8 +7,8 @@ namespace Ndk { - inline BaseSystem::BaseSystem(SystemId systemId) : - m_systemId(systemId) + inline BaseSystem::BaseSystem(SystemIndex systemId) : + m_systemIndex(systemId) { } @@ -17,9 +17,9 @@ namespace Ndk return m_entities; } - inline SystemId BaseSystem::GetId() const + inline SystemIndex BaseSystem::GetIndex() const { - return m_systemId; + return m_systemIndex; } inline World& BaseSystem::GetWorld() const @@ -35,12 +35,17 @@ namespace Ndk return m_entityBits.UnboundedTest(entity->GetId()); } + inline SystemIndex BaseSystem::GetNextIndex() + { + return s_nextIndex++; + } + template void BaseSystem::Excludes() { static_assert(std::is_base_of(), "ComponentType is not a component"); - ExcludesComponent(GetComponentId()); + ExcludesComponent(GetComponentIndex()); } template @@ -50,9 +55,9 @@ namespace Ndk Excludes(); } - inline void BaseSystem::ExcludesComponent(ComponentId componentId) + inline void BaseSystem::ExcludesComponent(ComponentIndex index) { - m_excludedComponents.insert(componentId); + m_excludedComponents.UnboundedSet(index); } template @@ -60,7 +65,7 @@ namespace Ndk { static_assert(std::is_base_of(), "ComponentType is not a component"); - RequiresComponent(GetComponentId()); + RequiresComponent(GetComponentIndex()); } template @@ -70,9 +75,9 @@ namespace Ndk Requires(); } - inline void BaseSystem::RequiresComponent(ComponentId componentId) + inline void BaseSystem::RequiresComponent(ComponentIndex index) { - m_requiredComponents.insert(componentId); + m_requiredComponents.UnboundedSet(index); } inline void BaseSystem::AddEntity(Entity* entity) @@ -82,7 +87,7 @@ namespace Ndk m_entities.push_back(entity->CreateHandle()); m_entityBits.UnboundedSet(entity->GetId(), true); - entity->RegisterSystem(m_systemId); + entity->RegisterSystem(m_systemIndex); OnEntityAdded(entity); } @@ -99,7 +104,7 @@ namespace Ndk m_entities.pop_back(); // On le sort du vector m_entityBits.Reset(entity->GetId()); - entity->UnregisterSystem(m_systemId); + entity->UnregisterSystem(m_systemIndex); OnEntityRemoved(entity); // Et on appelle le callback } diff --git a/SDK/include/NDK/Component.inl b/SDK/include/NDK/Component.inl index 4a860dfd7..9aee60c35 100644 --- a/SDK/include/NDK/Component.inl +++ b/SDK/include/NDK/Component.inl @@ -2,14 +2,13 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp -#include #include namespace Ndk { template Component::Component() : - BaseComponent(GetComponentId()) + BaseComponent(GetComponentIndex()) { } diff --git a/SDK/include/NDK/Entity.hpp b/SDK/include/NDK/Entity.hpp index 413ee358e..e5561c617 100644 --- a/SDK/include/NDK/Entity.hpp +++ b/SDK/include/NDK/Entity.hpp @@ -11,8 +11,6 @@ #include #include #include -#include -#include namespace Ndk { @@ -35,12 +33,14 @@ namespace Ndk EntityHandle CreateHandle(); - BaseComponent& GetComponent(ComponentId componentId); + BaseComponent& GetComponent(ComponentIndex index); template ComponentType& GetComponent(); + const NzBitset<>& GetComponentBits() const; EntityId GetId() const; + const NzBitset<>& GetSystemBits() const; World* GetWorld() const; - bool HasComponent(ComponentId componentId) const; + bool HasComponent(ComponentIndex index) const; template bool HasComponent() const; void Kill(); @@ -48,7 +48,7 @@ namespace Ndk bool IsValid() const; void RemoveAllComponents(); - void RemoveComponent(ComponentId componentId); + void RemoveComponent(ComponentIndex index); template void RemoveComponent(); Entity& operator=(const Entity&) = delete; @@ -61,14 +61,15 @@ namespace Ndk void Destroy(); void RegisterHandle(EntityHandle* handle); - void RegisterSystem(SystemId systemId); + void RegisterSystem(SystemIndex index); void UnregisterHandle(EntityHandle* handle); - void UnregisterSystem(SystemId systemId); + void UnregisterSystem(SystemIndex index); + std::vector> m_components; std::vector m_handles; - std::unordered_map> m_components; - std::unordered_set m_systems; EntityId m_id; + NzBitset<> m_componentBits; + NzBitset<> m_systemBits; World* m_world; bool m_valid; }; diff --git a/SDK/include/NDK/Entity.inl b/SDK/include/NDK/Entity.inl index 33dbbce2c..72936bee9 100644 --- a/SDK/include/NDK/Entity.inl +++ b/SDK/include/NDK/Entity.inl @@ -25,12 +25,12 @@ namespace Ndk return static_cast(AddComponent(std::move(ptr))); } - inline BaseComponent& Entity::GetComponent(ComponentId componentId) + inline BaseComponent& Entity::GetComponent(ComponentIndex index) { ///DOC: Le component doit être présent - NazaraAssert(HasComponent(componentId), "This component is not part of the entity"); + NazaraAssert(HasComponent(index), "This component is not part of the entity"); - BaseComponent* component = m_components[componentId].get(); + BaseComponent* component = m_components[index].get(); NazaraAssert(component, "Invalid component pointer"); return *component; @@ -42,8 +42,13 @@ namespace Ndk ///DOC: Le component doit être présent static_assert(std::is_base_of(), "ComponentType is not a component"); - ComponentId componentId = GetComponentId(); - return static_cast(GetComponent(componentId)); + ComponentIndex index = GetComponentIndex(); + return static_cast(GetComponent(index)); + } + + inline const NzBitset<>& Entity::GetComponentBits() const + { + return m_componentBits; } inline EntityId Entity::GetId() const @@ -51,14 +56,19 @@ namespace Ndk return m_id; } + inline const NzBitset<>& Entity::GetSystemBits() const + { + return m_systemBits; + } + inline World* Entity::GetWorld() const { return m_world; } - inline bool Entity::HasComponent(ComponentId componentId) const + inline bool Entity::HasComponent(ComponentIndex index) const { - return m_components.count(componentId) > 0; + return m_componentBits.UnboundedTest(index); } template @@ -66,8 +76,8 @@ namespace Ndk { static_assert(std::is_base_of(), "ComponentType is not a component"); - ComponentId componentId = GetComponentId(); - return HasComponent(componentId); + ComponentIndex index = GetComponentIndex(); + return HasComponent(index); } template @@ -75,8 +85,8 @@ namespace Ndk { static_assert(std::is_base_of(), "ComponentType is not a component"); - ComponentId componentId = GetComponentId(); - RemoveComponent(componentId); + ComponentIndex index = GetComponentIndex(); + RemoveComponent(index); } inline void Entity::RegisterHandle(EntityHandle* handle) @@ -85,9 +95,9 @@ namespace Ndk m_handles.push_back(handle); } - inline void Entity::RegisterSystem(SystemId systemId) + inline void Entity::RegisterSystem(SystemIndex index) { - m_systems.insert(systemId); + m_systemBits.UnboundedSet(index); } inline void Entity::UnregisterHandle(EntityHandle* handle) @@ -100,8 +110,8 @@ namespace Ndk m_handles.pop_back(); } - inline void Entity::UnregisterSystem(SystemId systemId) + inline void Entity::UnregisterSystem(SystemIndex index) { - m_systems.erase(systemId); + m_systemBits.UnboundedReset(index); } } diff --git a/SDK/include/NDK/Prerequesites.hpp b/SDK/include/NDK/Prerequesites.hpp index 894671b2b..f49e1a76c 100644 --- a/SDK/include/NDK/Prerequesites.hpp +++ b/SDK/include/NDK/Prerequesites.hpp @@ -57,9 +57,10 @@ namespace Ndk { - using ComponentId = nzUInt32; + using ComponentId = nzUInt64; + using ComponentIndex = nzUInt32; using EntityId = nzUInt32; - using SystemId = nzUInt32; + using SystemIndex = nzUInt32; } #endif // NDK_PREREQUESITES_HPP diff --git a/SDK/include/NDK/System.inl b/SDK/include/NDK/System.inl index fa81072b1..3360505cd 100644 --- a/SDK/include/NDK/System.inl +++ b/SDK/include/NDK/System.inl @@ -9,7 +9,7 @@ namespace Ndk { template System::System() : - BaseSystem(GetSystemId()) + BaseSystem(GetSystemIndex()) { } diff --git a/SDK/include/NDK/World.hpp b/SDK/include/NDK/World.hpp index 51aef339d..63caae3bb 100644 --- a/SDK/include/NDK/World.hpp +++ b/SDK/include/NDK/World.hpp @@ -38,10 +38,10 @@ namespace Ndk void Clear(); const EntityHandle& GetEntity(EntityId id); - BaseSystem& GetSystem(SystemId systemId); + BaseSystem& GetSystem(SystemIndex index); template SystemType& GetSystem(); - bool HasSystem(SystemId systemId) const; + bool HasSystem(SystemIndex index) const; template bool HasSystem() const; void KillEntity(Entity* entity); @@ -51,7 +51,7 @@ namespace Ndk bool IsEntityIdValid(EntityId id) const; void RemoveAllSystems(); - void RemoveSystem(SystemId systemId); + void RemoveSystem(SystemIndex index); template void RemoveSystem(); void Update(); @@ -71,9 +71,9 @@ namespace Ndk unsigned int aliveIndex; }; + std::vector> m_systems; std::vector m_freeIdList; std::vector m_entities; - std::unordered_map> m_systems; EntityList m_aliveEntities; NzBitset m_dirtyEntities; NzBitset m_killedEntities; diff --git a/SDK/include/NDK/World.inl b/SDK/include/NDK/World.inl index eb3d819f1..cf1746bd7 100644 --- a/SDK/include/NDK/World.inl +++ b/SDK/include/NDK/World.inl @@ -11,15 +11,19 @@ namespace Ndk { NazaraAssert(system, "System must be valid"); - SystemId systemId = system->GetId(); + SystemIndex index = system->GetIndex(); + + // Nous nous assurons que le vecteur de component est suffisamment grand pour contenir le nouveau component + if (index >= m_systems.size()) + m_systems.resize(index + 1); // Affectation et retour du système - m_systems[systemId] = std::move(system); - m_systems[systemId]->SetWorld(*this); + m_systems[index] = std::move(system); + m_systems[index]->SetWorld(*this); MarkAllAsDirty(); // On force une mise à jour de toutes les entités - return *m_systems[systemId].get(); + return *m_systems[index].get(); } template @@ -43,12 +47,12 @@ namespace Ndk return list; } - inline BaseSystem& World::GetSystem(SystemId systemId) + inline BaseSystem& World::GetSystem(SystemIndex index) { ///DOC: Le système doit être présent - NazaraAssert(HasSystem(systemId), "This system is not part of the world"); + NazaraAssert(HasSystem(index), "This system is not part of the world"); - BaseSystem* system = m_systems[systemId].get(); + BaseSystem* system = m_systems[index].get(); NazaraAssert(system, "Invalid system pointer"); return *system; @@ -60,13 +64,13 @@ namespace Ndk ///DOC: Le système doit être présent static_assert(std::is_base_of(), "SystemType is not a system"); - SystemId systemId = GetSystemId(); - return static_cast(GetSystem(systemId)); + SystemIndex index = GetSystemIndex(); + return static_cast(GetSystem(index)); } - inline bool World::HasSystem(SystemId systemId) const + inline bool World::HasSystem(SystemIndex index) const { - return m_systems.count(systemId) > 0; + return index < m_systems.size() && m_systems[index]; } template @@ -74,8 +78,8 @@ namespace Ndk { static_assert(std::is_base_of(), "SystemType is not a component"); - SystemId systemId = GetSystemId(); - return HasSystem(systemId); + SystemIndex index = GetSystemIndex(); + return HasSystem(index); } inline void World::KillEntities(const EntityList& list) @@ -99,11 +103,11 @@ namespace Ndk m_systems.clear(); } - inline void World::RemoveSystem(SystemId systemId) + inline void World::RemoveSystem(SystemIndex index) { ///DOC: N'a aucun effet si le système n'est pas présent - if (HasSystem(systemId)) - m_systems[systemId].reset(); + if (HasSystem(index)) + m_systems[index].reset(); } template @@ -111,8 +115,8 @@ namespace Ndk { static_assert(std::is_base_of(), "SystemType is not a system"); - SystemId systemId = GetSystemId(); - RemoveSystem(systemId); + SystemIndex index = GetSystemIndex(); + RemoveSystem(index); } inline void World::MarkAllAsDirty() diff --git a/SDK/src/NDK/BaseComponent.cpp b/SDK/src/NDK/BaseComponent.cpp index f227f40a0..3c90cef21 100644 --- a/SDK/src/NDK/BaseComponent.cpp +++ b/SDK/src/NDK/BaseComponent.cpp @@ -7,4 +7,7 @@ namespace Ndk { BaseComponent::~BaseComponent() = default; + + std::vector BaseComponent::s_entries; + std::unordered_map BaseComponent::s_idToIndex; } diff --git a/SDK/src/NDK/BaseSystem.cpp b/SDK/src/NDK/BaseSystem.cpp index 58213a107..aadb63e4c 100644 --- a/SDK/src/NDK/BaseSystem.cpp +++ b/SDK/src/NDK/BaseSystem.cpp @@ -9,7 +9,7 @@ namespace Ndk BaseSystem::~BaseSystem() { for (const EntityHandle& entity : m_entities) - entity->UnregisterSystem(m_systemId); + entity->UnregisterSystem(m_systemIndex); } bool BaseSystem::Filters(const Entity* entity) const @@ -17,19 +17,17 @@ namespace Ndk if (!entity) return false; - for (ComponentId component : m_requiredComponents) - { - if (!entity->HasComponent(component)) - return false; // Au moins un component requis n'est pas présent - } + const NzBitset<>& components = entity->GetComponentBits(); - for (ComponentId component : m_excludedComponents) - { - if (entity->HasComponent(component)) - return false; // Au moins un component exclu est présent - } + m_filterResult.PerformsAND(m_requiredComponents, components); + if (m_filterResult != m_requiredComponents) + return false; // Au moins un component requis n'est pas présent - return true; + m_filterResult.PerformsAND(m_excludedComponents, components); + if (m_filterResult.TestAny()) + return false; // Au moins un component exclu est présent + + return true; } void BaseSystem::OnEntityAdded(Entity* entity) @@ -41,4 +39,6 @@ namespace Ndk { NazaraUnused(entity); } + + SystemIndex BaseSystem::s_nextIndex = 0; } diff --git a/SDK/src/NDK/Entity.cpp b/SDK/src/NDK/Entity.cpp index 51feed183..c911dbf65 100644 --- a/SDK/src/NDK/Entity.cpp +++ b/SDK/src/NDK/Entity.cpp @@ -27,15 +27,20 @@ namespace Ndk { NazaraAssert(component, "Component must be valid"); - ComponentId componentId = component->GetId(); + ComponentIndex index = component->GetIndex(); + + // Nous nous assurons que le vecteur de component est suffisamment grand pour contenir le nouveau component + if (index >= m_components.size()) + m_components.resize(index + 1); // Affectation et retour du component - m_components[componentId] = std::move(component); + m_components[index] = std::move(component); + m_componentBits.UnboundedSet(index); // On informe le monde que nous avons besoin d'une mise à jour m_world->MarkAsDirty(m_id); - return *m_components[componentId].get(); + return *m_components[index].get(); } EntityHandle Entity::CreateHandle() @@ -56,17 +61,19 @@ namespace Ndk void Entity::RemoveAllComponents() { m_components.clear(); + m_componentBits.Clear(); // On informe le monde que nous avons besoin d'une mise à jour m_world->MarkAsDirty(m_id); } - void Entity::RemoveComponent(ComponentId componentId) + void Entity::RemoveComponent(ComponentIndex index) { ///DOC: N'a aucun effet si le component n'est pas présent - if (HasComponent(componentId)) + if (HasComponent(index)) { - m_components[componentId].reset(); + m_components[index].reset(); + m_componentBits.Reset(index); // On informe le monde que nous avons besoin d'une mise à jour m_world->MarkAsDirty(m_id); @@ -83,15 +90,15 @@ namespace Ndk m_valid = false; // On informe chaque système - for (SystemId systemId : m_systems) + for (SystemIndex index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index)) { - if (m_world->HasSystem(systemId)) + if (m_world->HasSystem(index)) { - BaseSystem& system = m_world->GetSystem(systemId); + BaseSystem& system = m_world->GetSystem(index); system.RemoveEntity(this); } } - m_systems.clear(); + m_systemBits.Clear(); // On informe chaque handle de notre destruction pour éviter qu'il ne continue de pointer sur nous for (EntityHandle* handle : m_handles) diff --git a/SDK/src/NDK/World.cpp b/SDK/src/NDK/World.cpp index 76086d2a4..0a18c7f13 100644 --- a/SDK/src/NDK/World.cpp +++ b/SDK/src/NDK/World.cpp @@ -116,10 +116,8 @@ namespace Ndk // Aucun intérêt de traiter une entité n'existant plus if (entity.IsValid()) { - for (auto& systemPair : m_systems) + for (auto& system : m_systems) { - BaseSystem* system = systemPair.second.get(); - // L'entité est-elle enregistrée comme faisant partie du système ? bool partOfSystem = system->HasEntity(&entity); if (system->Filters(&entity))