Sdk/World: Inline GetEntity and KillEntity
This commit is contained in:
parent
c06db7d9c5
commit
0708531f6c
|
|
@ -47,7 +47,7 @@ namespace Ndk
|
|||
void Clear() noexcept;
|
||||
const EntityHandle& CloneEntity(EntityId id);
|
||||
|
||||
const EntityHandle& GetEntity(EntityId id);
|
||||
inline const EntityHandle& GetEntity(EntityId id);
|
||||
inline const EntityList& GetEntities() const;
|
||||
inline BaseSystem& GetSystem(SystemIndex index);
|
||||
template<typename SystemType> SystemType& GetSystem();
|
||||
|
|
@ -55,7 +55,7 @@ namespace Ndk
|
|||
inline bool HasSystem(SystemIndex index) const;
|
||||
template<typename SystemType> bool HasSystem() const;
|
||||
|
||||
void KillEntity(Entity* entity);
|
||||
inline void KillEntity(Entity* entity);
|
||||
inline void KillEntities(const EntityVector& list);
|
||||
|
||||
inline bool IsEntityValid(const Entity* entity) const;
|
||||
|
|
|
|||
|
|
@ -164,18 +164,53 @@ namespace Ndk
|
|||
return HasSystem(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Marks an entity for deletion
|
||||
*
|
||||
* \param Pointer to the entity
|
||||
*
|
||||
* \remark If the entity pointer is invalid, nothing is done
|
||||
* \remark For safety, entities are not killed until the next world update
|
||||
*/
|
||||
inline void World::KillEntity(Entity* entity)
|
||||
{
|
||||
if (IsEntityValid(entity))
|
||||
m_killedEntities.UnboundedSet(entity->GetId(), true);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Kills a set of entities
|
||||
*
|
||||
* This function has the same effect as calling KillEntity for every entity contained in the vector
|
||||
*
|
||||
* \param list Set of entities to kill
|
||||
*/
|
||||
|
||||
inline void World::KillEntities(const EntityVector& list)
|
||||
{
|
||||
for (const EntityHandle& entity : list)
|
||||
KillEntity(entity);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets an entity
|
||||
* \return A constant reference to a handle of the entity
|
||||
*
|
||||
* \param id Identifier of the entity
|
||||
*
|
||||
* \remark Handle referenced by this function can move in memory when updating the world, do not keep a reference to a handle from a world update to another
|
||||
* \remark If an invalid identifier is provided, an error got triggered and an invalid handle is returned
|
||||
*/
|
||||
inline const EntityHandle& World::GetEntity(EntityId id)
|
||||
{
|
||||
if (IsEntityIdValid(id))
|
||||
return m_entityBlocks[id]->handle;
|
||||
else
|
||||
{
|
||||
NazaraError("Invalid ID");
|
||||
return EntityHandle::InvalidHandle;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not an entity is valid
|
||||
* \return true If it is the case
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ namespace Ndk
|
|||
return EntityHandle::InvalidHandle;
|
||||
}
|
||||
|
||||
EntityHandle clone = CreateEntity();
|
||||
const EntityHandle& clone = CreateEntity();
|
||||
|
||||
const Nz::Bitset<>& componentBits = original->GetComponentBits();
|
||||
for (std::size_t i = componentBits.FindFirst(); i != componentBits.npos; i = componentBits.FindNext(i))
|
||||
|
|
@ -153,40 +153,6 @@ namespace Ndk
|
|||
return GetEntity(clone->GetId());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Kills an entity
|
||||
*
|
||||
* \param Pointer to the entity
|
||||
*
|
||||
* \remark No change is done if entity is invalid
|
||||
*/
|
||||
|
||||
void World::KillEntity(Entity* entity)
|
||||
{
|
||||
if (IsEntityValid(entity))
|
||||
m_killedEntities.UnboundedSet(entity->GetId(), true);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets an entity
|
||||
* \return A constant reference to the modified entity
|
||||
*
|
||||
* \param id Identifier of the entity
|
||||
*
|
||||
* \remark Produces a NazaraError if entity identifier is not valid
|
||||
*/
|
||||
|
||||
const EntityHandle& World::GetEntity(EntityId id)
|
||||
{
|
||||
if (IsEntityIdValid(id))
|
||||
return m_entities[id].handle;
|
||||
else
|
||||
{
|
||||
NazaraError("Invalid ID");
|
||||
return EntityHandle::InvalidHandle;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Updates the world
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue