SDK/Entity: Add constant component getter
Former-commit-id: 743d7014974b3d1aa9ea58e52ed89f9aca511768 [formerly 7038ae6b04a57ddd716c43c43ddb1d9b7d43734e] [formerly 3836f98661a50646c3044a7551cb733bf121c249 [formerly a47cdf1a9da62c3ca2ff2da60d015f98bed6f7cd]] Former-commit-id: 84faa425e9d8b4e6e022c598e076f59cd74b5322 [formerly 5dc0e4aaa6e24ceb84f60cf68ff45dc69cf3f437] Former-commit-id: 888def1e5d87e4ac42616f23ad16497b52df99e5
This commit is contained in:
parent
6749bde3fc
commit
bc565e0989
|
|
@ -40,6 +40,8 @@ namespace Ndk
|
||||||
|
|
||||||
inline BaseComponent& GetComponent(ComponentIndex index);
|
inline BaseComponent& GetComponent(ComponentIndex index);
|
||||||
template<typename ComponentType> ComponentType& GetComponent();
|
template<typename ComponentType> ComponentType& GetComponent();
|
||||||
|
inline const BaseComponent& GetComponent(ComponentIndex index) const;
|
||||||
|
template<typename ComponentType> const ComponentType& GetComponent() const;
|
||||||
inline const Nz::Bitset<>& GetComponentBits() const;
|
inline const Nz::Bitset<>& GetComponentBits() const;
|
||||||
inline EntityId GetId() const;
|
inline EntityId GetId() const;
|
||||||
inline const Nz::Bitset<>& GetSystemBits() const;
|
inline const Nz::Bitset<>& GetSystemBits() const;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
// This file is part of the "Nazara Development Kit"
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Core/StringStream.hpp>
|
#include <Nazara/Core/StringStream.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
@ -50,6 +51,27 @@ namespace Ndk
|
||||||
return static_cast<ComponentType&>(GetComponent(index));
|
return static_cast<ComponentType&>(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<typename ComponentType>
|
||||||
|
const ComponentType& Entity::GetComponent() const
|
||||||
|
{
|
||||||
|
///DOC: Le component doit être présent
|
||||||
|
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
|
||||||
|
|
||||||
|
ComponentIndex index = GetComponentIndex<ComponentType>();
|
||||||
|
return static_cast<ComponentType&>(GetComponent(index));
|
||||||
|
}
|
||||||
|
|
||||||
inline const Nz::Bitset<>& Entity::GetComponentBits() const
|
inline const Nz::Bitset<>& Entity::GetComponentBits() const
|
||||||
{
|
{
|
||||||
return m_componentBits;
|
return m_componentBits;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue