Documentation for module 'NDK'
Former-commit-id: a6c2075cfbfd0eccf2b77def71c0d42684bed590 [formerly 36ece2bc6a148bde6cacf45084821d20edcd115e] [formerly 4a6988792ec026e65be6850c46dfe8ddda92a885 [formerly fd3f4f975de5c427f3adc98b220446fd255be396]] Former-commit-id: c87fdc9483202842267c60eff3d619f0df2963bf [formerly ee35202f1b2df7ca20da5b6d8b13147f2b92c933] Former-commit-id: dad5de1b00bb4413f7aa191ca06b7d43b659f32a
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