From 0ba034f7e9f3915bb6485a7338d2f255b85bfa29 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 17 Mar 2015 12:34:03 +0100 Subject: [PATCH] (Entity) Added components bits Moved [Add/Remove]Component implementation to .cpp Former-commit-id: e61e8c57911c2e106e6c0959b692a006b8f58c40 --- SDK/include/NDK/Entity.hpp | 3 +++ SDK/include/NDK/Entity.inl | 36 +++++------------------------------- SDK/src/NDK/Entity.cpp | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/SDK/include/NDK/Entity.hpp b/SDK/include/NDK/Entity.hpp index 6159ddce8..28e539d93 100644 --- a/SDK/include/NDK/Entity.hpp +++ b/SDK/include/NDK/Entity.hpp @@ -7,6 +7,7 @@ #ifndef NDK_ENTITY_HPP #define NDK_ENTITY_HPP +#include #include #include #include @@ -35,6 +36,7 @@ namespace Ndk BaseComponent& GetComponent(nzUInt32 componentId); template ComponentType& GetComponent(); + const NzBitset<>& GetComponentBits() const; Id GetId() const; World* GetWorld() const; @@ -64,6 +66,7 @@ namespace Ndk std::vector> m_components; std::vector m_handles; Id m_id; + NzBitset<> m_componentBits; World* m_world; bool m_valid; }; diff --git a/SDK/include/NDK/Entity.inl b/SDK/include/NDK/Entity.inl index a9fea8fd4..3dbe0d65f 100644 --- a/SDK/include/NDK/Entity.inl +++ b/SDK/include/NDK/Entity.inl @@ -15,25 +15,6 @@ namespace Ndk { } - inline BaseComponent& Entity::AddComponent(std::unique_ptr&& component) - { - NazaraAssert(component, "Component must be valid"); - - nzUInt32 componentId = component->GetId(); - - // Nous supprimons l'ancien component, s'il existe - RemoveComponent(componentId); - - // Nous nous assurons que le vecteur de component est suffisamment grand pour contenir le nouveau component - if (m_components.size() <= componentId) - m_components.resize(componentId + 1); - - // Affectation et retour du component - m_components[componentId] = std::move(component); - - return *m_components[componentId].get(); - } - template ComponentType& Entity::AddComponent(Args&&... args) { @@ -65,6 +46,11 @@ namespace Ndk return static_cast(GetComponent(componentId)); } + inline const NzBitset<>& Entity::GetComponentBits() const + { + return m_componentBits; + } + inline Entity::Id Entity::GetId() const { return m_id; @@ -89,18 +75,6 @@ namespace Ndk return HasComponent(componentId); } - inline void Entity::RemoveAllComponents() - { - m_components.clear(); - } - - inline void Entity::RemoveComponent(nzUInt32 componentId) - { - ///DOC: N'a aucun effet si le component n'est pas présent - if (HasComponent(componentId)) - m_components[componentId].reset(); - } - template void Entity::RemoveComponent() { diff --git a/SDK/src/NDK/Entity.cpp b/SDK/src/NDK/Entity.cpp index b167d0597..c84ec83c7 100644 --- a/SDK/src/NDK/Entity.cpp +++ b/SDK/src/NDK/Entity.cpp @@ -23,6 +23,26 @@ namespace Ndk Destroy(); } + BaseComponent& Entity::AddComponent(std::unique_ptr&& component) + { + NazaraAssert(component, "Component must be valid"); + + nzUInt32 componentId = component->GetId(); + + // Nous supprimons l'ancien component, s'il existe + RemoveComponent(componentId); + + // Nous nous assurons que le vecteur de component est suffisamment grand pour contenir le nouveau component + if (m_components.size() <= componentId) + m_components.resize(componentId + 1); + + // Affectation et retour du component + m_components[componentId] = std::move(component); + m_componentBits.UnboundedSet(componentId); + + return *m_components[componentId].get(); + } + EntityHandle Entity::CreateHandle() { return EntityHandle(this); @@ -38,6 +58,22 @@ namespace Ndk return m_valid; } + void Entity::RemoveAllComponents() + { + m_components.clear(); + m_componentBits.Clear(); + } + + void Entity::RemoveComponent(nzUInt32 componentId) + { + ///DOC: N'a aucun effet si le component n'est pas présent + if (HasComponent(componentId)) + { + m_components[componentId].reset(); + m_componentBits.Reset(componentId); + } + } + void Entity::Create() { m_valid = true;