Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::ecs::detail::CommandBuffer< AccessContext > Class Template Referencefinal

Buffer for deferred execution of some operations on entities. More...

#include <command_buffer.h>

Public Member Functions

 CommandBuffer (World &world)
 
 CommandBuffer (CommandBuffer &&)=delete
 
 CommandBuffer (const CommandBuffer &)=delete
 
CommandBufferoperator= (CommandBuffer &&)=delete
 
CommandBufferoperator= (const CommandBuffer &)=delete
 
GAIA_NODISCARD Entity add (EntityKind kind=EntityKind::EK_Gen)
 Requests a new entity to be created.
 
GAIA_NODISCARD Entity copy (Entity entityFrom)
 Requests a new entity to be created by cloning an already existing entity.
 
template<typename T >
void add (Entity entity)
 Requests a component T to be added to entity.
 
void add (Entity entity, Entity other)
 Requests an entity other to be added to entity entity.
 
template<typename T >
void add (Entity entity, T &&value)
 Requests a component T to be added to entity. Also sets its value.
 
template<typename T >
void set (Entity entity, T &&value)
 Requests component data to be set to given values for a given entity.
 
void del (Entity entity)
 Requests an existing entity to be removed.
 
template<typename T >
void del (Entity entity)
 Requests removal of component T from entity.
 
void del (Entity entity, Entity object)
 Requests removal of entity object from entity entity.
 
void commit ()
 Commits all queued changes.
 

Detailed Description

template<typename AccessContext>
class gaia::ecs::detail::CommandBuffer< AccessContext >

Buffer for deferred execution of some operations on entities.

Adding and removing components and entities inside World::each or can result in changes of archetypes or chunk structure. This would lead to an undefined behavior. Therefore, such operations have to be executed after the loop is done.

Member Function Documentation

◆ add() [1/4]

template<typename AccessContext >
template<typename T >
void gaia::ecs::detail::CommandBuffer< AccessContext >::add ( Entity  entity)
inline

Requests a component T to be added to entity.

Template Parameters
TComponent type
Parameters
entityDestination entity

◆ add() [2/4]

template<typename AccessContext >
void gaia::ecs::detail::CommandBuffer< AccessContext >::add ( Entity  entity,
Entity  other 
)
inline

Requests an entity other to be added to entity entity.

Parameters
entityDestination entity
otherEntity to add to entity

◆ add() [3/4]

template<typename AccessContext >
template<typename T >
void gaia::ecs::detail::CommandBuffer< AccessContext >::add ( Entity  entity,
T &&  value 
)
inline

Requests a component T to be added to entity. Also sets its value.

Template Parameters
TComponent type
Parameters
entityDestination entity
valueComponent value
Warning
Component T should be registered in the world before calling this function. If used in concurrent environment, race conditions may occur otherwise.

◆ add() [4/4]

template<typename AccessContext >
GAIA_NODISCARD Entity gaia::ecs::detail::CommandBuffer< AccessContext >::add ( EntityKind  kind = EntityKind::EK_Gen)
inline

Requests a new entity to be created.

Parameters
kindEntity kind. Generic entity by default.
Returns
Entity that will be created. The id is not usable right away. It will be filled with proper data after commit().

◆ copy()

template<typename AccessContext >
GAIA_NODISCARD Entity gaia::ecs::detail::CommandBuffer< AccessContext >::copy ( Entity  entityFrom)
inline

Requests a new entity to be created by cloning an already existing entity.

Returns
Entity that will be created. The id is not usable right away. It will be filled with proper data after commit()

◆ del() [1/3]

template<typename AccessContext >
void gaia::ecs::detail::CommandBuffer< AccessContext >::del ( Entity  entity)
inline

Requests an existing entity to be removed.

Parameters
entityEntity to remove

◆ del() [2/3]

template<typename AccessContext >
template<typename T >
void gaia::ecs::detail::CommandBuffer< AccessContext >::del ( Entity  entity)
inline

Requests removal of component T from entity.

Template Parameters
TComponent type
Parameters
entitySource entity
Warning
Component T must be registered in the world before calling this function. Calling del without a previous add of the component doesn't make sense.

◆ del() [3/3]

template<typename AccessContext >
void gaia::ecs::detail::CommandBuffer< AccessContext >::del ( Entity  entity,
Entity  object 
)
inline

Requests removal of entity object from entity entity.

Parameters
entitySource entity
objectEntity to remove

◆ set()

template<typename AccessContext >
template<typename T >
void gaia::ecs::detail::CommandBuffer< AccessContext >::set ( Entity  entity,
T &&  value 
)
inline

Requests component data to be set to given values for a given entity.

Template Parameters
TComponent type
Parameters
entityDestination entity
valueComponent value
Warning
Component T must be registered in the world before calling this function. Calling set without a previous add of the component doesn't make sense.

The documentation for this class was generated from the following file: