Documentation for module 'NDK'
Former-commit-id: 63e1cac538c577a1f1aafa71fa7eef69a6d4daab [formerly b2d8769fd02a0e7d9c476d4ad7be1988a1fd6789] [formerly 636b5cb79bcb8da44d9aa45ba1023565bcf29f0d [formerly a2361ec2b8679d4d4ba096e543b5d4b91825dd62]] Former-commit-id: d402d35477f9db0135c553d55c401939426bf62d [formerly 607336ea0f42731e4604f3a8c2df06f3aecfc401] Former-commit-id: 69e23cd6c06723486de5e4641ce810012dac66da
This commit is contained in:
@@ -11,16 +11,29 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Adds a component to the entity
|
||||
* \return A reference to the newly added component
|
||||
*
|
||||
* \param args Arguments to create in place the component to add to the entity
|
||||
*/
|
||||
|
||||
template<typename ComponentType, typename... Args>
|
||||
ComponentType& Entity::AddComponent(Args&&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
|
||||
|
||||
// Allocation et affectation du component
|
||||
// Affectation and return of the component
|
||||
std::unique_ptr<ComponentType> ptr(new ComponentType(std::forward<Args>(args)...));
|
||||
return static_cast<ComponentType&>(AddComponent(std::move(ptr)));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enables the entity
|
||||
*
|
||||
* \param enable Should the entity be enabled
|
||||
*/
|
||||
|
||||
inline void Entity::Enable(bool enable)
|
||||
{
|
||||
if (m_enabled != enable)
|
||||
@@ -30,9 +43,17 @@ namespace Ndk
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a component in the entity by index
|
||||
* \return A reference to the component
|
||||
*
|
||||
* \param index Index of the component
|
||||
*
|
||||
* \remark Produces a NazaraAssert if component is not available in this entity or is invalid
|
||||
*/
|
||||
|
||||
inline BaseComponent& Entity::GetComponent(ComponentIndex index)
|
||||
{
|
||||
///DOC: Le component doit être présent
|
||||
NazaraAssert(HasComponent(index), "This component is not part of the entity");
|
||||
|
||||
BaseComponent* component = m_components[index].get();
|
||||
@@ -41,19 +62,33 @@ namespace Ndk
|
||||
return *component;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a component in the entity by type
|
||||
* \return A reference to the component
|
||||
*
|
||||
* \remark Produces a NazaraAssert if component is not available in this entity
|
||||
*/
|
||||
|
||||
template<typename ComponentType>
|
||||
ComponentType& Entity::GetComponent()
|
||||
{
|
||||
///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));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a component in the entity by index
|
||||
* \return A constant reference to the component
|
||||
*
|
||||
* \param index Index of the component
|
||||
*
|
||||
* \remark Produces a NazaraAssert if component is not available in this entity or is invalid
|
||||
*/
|
||||
|
||||
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();
|
||||
@@ -62,41 +97,79 @@ namespace Ndk
|
||||
return *component;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a component in the entity by type
|
||||
* \return A constant reference to the component
|
||||
*
|
||||
* \remark Produces a NazaraAssert if component is not available in this entity
|
||||
*/
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the bits representing the components in the entiy
|
||||
* \return A constant reference to the set of component's bits
|
||||
*/
|
||||
|
||||
inline const Nz::Bitset<>& Entity::GetComponentBits() const
|
||||
{
|
||||
return m_componentBits;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the identifier of the entity
|
||||
* \return Identifier of the entity
|
||||
*/
|
||||
|
||||
inline EntityId Entity::GetId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the bits representing the systems in the entiy
|
||||
* \return A constant reference to the set of system's bits
|
||||
*/
|
||||
|
||||
inline const Nz::Bitset<>& Entity::GetSystemBits() const
|
||||
{
|
||||
return m_systemBits;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the world in which the entity is
|
||||
* \return Pointer to the world
|
||||
*/
|
||||
|
||||
inline World* Entity::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not a component is present in the entity by index
|
||||
* \return true If it is the case
|
||||
*
|
||||
* \param index Index of the component
|
||||
*/
|
||||
|
||||
inline bool Entity::HasComponent(ComponentIndex index) const
|
||||
{
|
||||
return m_componentBits.UnboundedTest(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not a component is present in the entity by type
|
||||
* \return true If it is the case
|
||||
*/
|
||||
|
||||
template<typename ComponentType>
|
||||
bool Entity::HasComponent() const
|
||||
{
|
||||
@@ -106,16 +179,54 @@ namespace Ndk
|
||||
return HasComponent(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not the entity is enabled
|
||||
* \return true If it is the case
|
||||
*/
|
||||
|
||||
inline bool Entity::IsEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not the entity is valid
|
||||
* \return true If it is the case
|
||||
*/
|
||||
|
||||
inline bool Entity::IsValid() const
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Removes every components
|
||||
*/
|
||||
|
||||
inline void Entity::RemoveAllComponents()
|
||||
{
|
||||
m_removedComponentBits = m_componentBits;
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Removes a component in the entity by index
|
||||
*
|
||||
* \param index Index of the component
|
||||
*/
|
||||
|
||||
inline void Entity::RemoveComponent(ComponentIndex index)
|
||||
{
|
||||
m_removedComponentBits.UnboundedSet(index);
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Removes a component in the entity by type
|
||||
*/
|
||||
|
||||
template<typename ComponentType>
|
||||
void Entity::RemoveComponent()
|
||||
{
|
||||
@@ -125,19 +236,10 @@ namespace Ndk
|
||||
RemoveComponent(index);
|
||||
}
|
||||
|
||||
inline void Entity::RemoveAllComponents()
|
||||
{
|
||||
m_removedComponentBits = m_componentBits;
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
inline void Entity::RemoveComponent(ComponentIndex index)
|
||||
{
|
||||
m_removedComponentBits.UnboundedSet(index);
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
/*!
|
||||
* \brief Gives a string representation
|
||||
* \return A string representation of the object: "Entity(GetId())"
|
||||
*/
|
||||
|
||||
inline Nz::String Entity::ToString() const
|
||||
{
|
||||
@@ -145,16 +247,35 @@ namespace Ndk
|
||||
return ss << "Entity(" << GetId() << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the bits representing the removed components in the entiy
|
||||
* \return A constant reference to the set of remove component's bits
|
||||
*/
|
||||
|
||||
inline Nz::Bitset<>& Entity::GetRemovedComponentBits()
|
||||
{
|
||||
return m_removedComponentBits;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers a system for the entity
|
||||
*
|
||||
* \param index Index of the system
|
||||
*/
|
||||
|
||||
inline void Entity::RegisterSystem(SystemIndex index)
|
||||
{
|
||||
m_systemBits.UnboundedSet(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the world of the entity
|
||||
*
|
||||
* \param world World in which the entity will be
|
||||
*
|
||||
* \remark Produces a NazaraAssert if world is invalid
|
||||
*/
|
||||
|
||||
inline void Entity::SetWorld(World* world) noexcept
|
||||
{
|
||||
NazaraAssert(world, "An entity must be attached to a world at any time");
|
||||
@@ -162,6 +283,12 @@ namespace Ndk
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unregisters a system for the entity
|
||||
*
|
||||
* \param index Index of the system
|
||||
*/
|
||||
|
||||
inline void Entity::UnregisterSystem(SystemIndex index)
|
||||
{
|
||||
m_systemBits.UnboundedReset(index);
|
||||
@@ -173,10 +300,16 @@ namespace std
|
||||
template<>
|
||||
struct hash<Ndk::EntityHandle>
|
||||
{
|
||||
/*!
|
||||
* \brief Specialisation of std to hash
|
||||
* \return Result of the hash
|
||||
*
|
||||
* \param handle Entity to hash
|
||||
*/
|
||||
size_t operator()(const Ndk::EntityHandle& handle) const
|
||||
{
|
||||
// Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée
|
||||
// pour cette raison, nous devons hasher l'ID de l'entité (qui reste constante)
|
||||
// Hash the pointer will work until the entity is updated and moved
|
||||
// so, we have to hash the ID of the entity (which is constant)
|
||||
Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits<Ndk::EntityId>::max();
|
||||
|
||||
return hash<Ndk::EntityId>()(id);
|
||||
|
||||
Reference in New Issue
Block a user