SDK/Entity: Add constant component getter
Former-commit-id: 602e3d136124f7a49270d95f191eeda0f78179d4 [formerly 1666ac8477467e91e8763109cb91e6cb2074d223] [formerly 3c27a318695a98bb97bbcceb2879f8b9b6da90bf [formerly 3f2b769579af5c103102a9a3d1f0c6a6c7bbbf32]] Former-commit-id: 791755b458c83193eb1849ed3eabf9b41da564bf [formerly 8fc83ec409b57a67999bb0f7a4e25a87d96024a2] Former-commit-id: 58a87205503d734ce877800da06daa1fee838bfa
This commit is contained in:
parent
4e2f33a8af
commit
17512b2b8e
|
|
@ -40,6 +40,8 @@ namespace Ndk
|
|||
|
||||
inline BaseComponent& GetComponent(ComponentIndex index);
|
||||
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 EntityId GetId() const;
|
||||
inline const Nz::Bitset<>& GetSystemBits() const;
|
||||
|
|
|
|||
|
|
@ -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 <NDK/Entity.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
|
|
@ -50,6 +51,27 @@ namespace Ndk
|
|||
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
|
||||
{
|
||||
return m_componentBits;
|
||||
|
|
|
|||
Loading…
Reference in New Issue