diff --git a/SDK/include/NDK/Entity.hpp b/SDK/include/NDK/Entity.hpp index 33661eb50..5aeeb8226 100644 --- a/SDK/include/NDK/Entity.hpp +++ b/SDK/include/NDK/Entity.hpp @@ -40,6 +40,8 @@ namespace Ndk inline BaseComponent& GetComponent(ComponentIndex index); template ComponentType& GetComponent(); + inline const BaseComponent& GetComponent(ComponentIndex index) const; + template const ComponentType& GetComponent() const; inline const Nz::Bitset<>& GetComponentBits() const; inline EntityId GetId() const; inline const Nz::Bitset<>& GetSystemBits() const; diff --git a/SDK/include/NDK/Entity.inl b/SDK/include/NDK/Entity.inl index c7937b786..a03130b0d 100644 --- a/SDK/include/NDK/Entity.inl +++ b/SDK/include/NDK/Entity.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp +#include #include #include #include @@ -50,6 +51,27 @@ namespace Ndk return static_cast(GetComponent(index)); } + inline const BaseComponent& Entity::GetComponent(ComponentIndex index) const + { + ///DOC: Le component doit être présent + NazaraAssert(HasComponent(index), "This component is not part of the entity"); + + BaseComponent* component = m_components[index].get(); + NazaraAssert(component, "Invalid component pointer"); + + return *component; + } + + template + const ComponentType& Entity::GetComponent() const + { + ///DOC: Le component doit être présent + static_assert(std::is_base_of::value, "ComponentType is not a component"); + + ComponentIndex index = GetComponentIndex(); + return static_cast(GetComponent(index)); + } + inline const Nz::Bitset<>& Entity::GetComponentBits() const { return m_componentBits;