SDK/Entity: Add constant component getter
Former-commit-id: 1c7aa68fbf0c8e0bdfa8152632b2e9cdaa0f748e [formerly 676e34f3738632aa727470213928ad2c91368d9b] [formerly c3f162cad3a9c65da2bcaf037d7b55ea70ee5b53 [formerly 674d9d5ecaa0d561d002e470af4c0cf7dcf7e501]] Former-commit-id: bf5a07802efe57d0f6547a2c4b5ab8344e4515e9 [formerly 843780a0eaba37b46e59f9d81e56c3854a86ebde] Former-commit-id: 6849fc8cfe8d689f67d452d13fe317ea65ba2fec
This commit is contained in:
parent
e3989b8656
commit
6ab812b576
|
|
@ -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