From 8b77825fb84b1eb71b3939aaed766d347a689db5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 1 Mar 2015 11:19:54 +0100 Subject: [PATCH] (Entity) Changed template name from C to ComponentType Former-commit-id: 780c96238f5f976b9caa86ec982bec7b5fd9ee8a --- SDK/include/NDK/Entity.hpp | 10 +++---- SDK/include/NDK/Entity.inl | 53 +++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/SDK/include/NDK/Entity.hpp b/SDK/include/NDK/Entity.hpp index f5385e5d4..eedbc4082 100644 --- a/SDK/include/NDK/Entity.hpp +++ b/SDK/include/NDK/Entity.hpp @@ -29,23 +29,23 @@ namespace Ndk Entity(Entity&& entity); ~Entity(); - template Component& AddComponent(Args&&... args); + template ComponentType& AddComponent(Args&&... args); EntityHandle CreateHandle(); - template Component& GetComponent(); - template const Component& GetComponent() const; + template ComponentType& GetComponent(); + template const ComponentType& GetComponent() const; Id GetId() const; World* GetWorld() const; - template bool HasComponent() const; + template bool HasComponent() const; void Kill(); bool IsValid() const; void RemoveAllComponent(); - template void RemoveComponent(); + template void RemoveComponent(); Entity& operator=(const Entity&) = delete; Entity& operator=(Entity&&) = delete; diff --git a/SDK/include/NDK/Entity.inl b/SDK/include/NDK/Entity.inl index a77894d0c..7f8786bf2 100644 --- a/SDK/include/NDK/Entity.inl +++ b/SDK/include/NDK/Entity.inl @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace Ndk @@ -16,58 +17,58 @@ namespace Ndk { } - template - C& Entity::AddComponent(Args&&... args) + template + ComponentType& Entity::AddComponent(Args&&... args) { - static_assert(std::is_base_of(), "C is not a component"); + static_assert(std::is_base_of(), "ComponentType is not a component"); // Nous supprimons l'ancien component, s'il existe - RemoveComponent(); + RemoveComponent(); // Récupération de l'identification du component, qui va nous servir d'indice - nzUInt32 componentId = C::ComponentId; + nzUInt32 componentId = ComponentType::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); // Allocation et affectation du component - std::unique_ptr ptr(new C(std::forward(args)...)); - C* component = ptr.get(); + std::unique_ptr ptr(new ComponentType(std::forward(args)...)); + ComponentType* component = ptr.get(); m_components[componentId] = std::move(ptr); return *component; } - template - C& Entity::GetComponent() + template + ComponentType& Entity::GetComponent() { ///DOC: Lance une exception si le component n'est pas présent - static_assert(std::is_base_of(), "C is not a component"); + static_assert(std::is_base_of(), "ComponentType is not a component"); - if (!HasComponent()) + if (!HasComponent()) throw std::runtime_error("Tried to get a non-present component"); - BaseComponent* component = m_components[C::ComponentId].get(); + BaseComponent* component = m_components[ComponentType::ComponentId].get(); NazaraAssert(component, "Invalid component pointer"); - return *static_cast(component); + return *static_cast(component); } - template - const C& Entity::GetComponent() const + template + const ComponentType& Entity::GetComponent() const { ///DOC: Lance une exception si le component n'est pas présent - static_assert(std::is_base_of(), "C is not a component"); + static_assert(std::is_base_of(), "ComponentType is not a component"); - if (!HasComponent()) + if (!HasComponent()) throw std::runtime_error("Tried to get a non-present component"); - BaseComponent* component = m_components[C::ComponentId].get(); + BaseComponent* component = m_components[ComponentType::ComponentId].get(); NazaraAssert(component, "Invalid component pointer"); - return *static_cast(component); + return *static_cast(component); } inline Entity::Id Entity::GetId() const @@ -80,12 +81,12 @@ namespace Ndk return m_world; } - template + template bool Entity::HasComponent() const { - static_assert(std::is_base_of(), "C is not a component"); + static_assert(std::is_base_of(), "ComponentType is not a component"); - nzUInt32 componentId = C::ComponentId; + nzUInt32 componentId = ComponentType::ComponentId; return m_components.size() > componentId && m_components[componentId]; } @@ -94,13 +95,13 @@ namespace Ndk m_components.clear(); } - template + template void Entity::RemoveComponent() { - static_assert(std::is_base_of(), "C is not a component"); + static_assert(std::is_base_of(), "ComponentType is not a component"); - if (HasComponent()) - m_components[C::ComponentId].reset(); + if (HasComponent()) + m_components[ComponentType::ComponentId].reset(); } inline void Entity::RegisterHandle(EntityHandle* handle)