cubos::core::ecs::CommandBuffer class final

Stores commands to execute them later.

Constructors, destructors, conversion operators

CommandBuffer(World& world)
Constructs.

Public functions

void insertResource(memory::AnyValue value)
Inserts a resource into the world.
void eraseResource(const reflection::Type& type)
Removes a resource from the world.
auto create() -> Entity
Creates a new entity.
void destroy(Entity entity)
Destroys an entity.
auto spawn(const Blueprint& blueprint, bool withName = true) -> std::unordered_map<std::string, Entity>
Spawns a blueprint into the world.
void add(Entity entity, const reflection::Type& type, void* value)
Adds a component to an entity.
void remove(Entity entity, const reflection::Type& type)
Removes a component from an entity.
void relate(Entity from, Entity to, const reflection::Type& type, void* value)
Inserts a relation between the two given entities.
void unrelate(Entity from, Entity to, const reflection::Type& type)
Removes the relation, if there's any, between the two given entities.
void push(memory::Function<void(World&)> command)
Pushes a command.
void commit()
Commits the commands to the world.

Function documentation

cubos::core::ecs::CommandBuffer::CommandBuffer(World& world)

Constructs.

Parameters
world World to which the commands will be applied.

void cubos::core::ecs::CommandBuffer::insertResource(memory::AnyValue value)

Inserts a resource into the world.

Parameters
value Resource value.

void cubos::core::ecs::CommandBuffer::eraseResource(const reflection::Type& type)

Removes a resource from the world.

Parameters
type Resource type.

Entity cubos::core::ecs::CommandBuffer::create()

Creates a new entity.

Returns Entity identifier.

void cubos::core::ecs::CommandBuffer::destroy(Entity entity)

Destroys an entity.

Parameters
entity Entity identifier.

std::unordered_map<std::string, Entity> cubos::core::ecs::CommandBuffer::spawn(const Blueprint& blueprint, bool withName = true)

Spawns a blueprint into the world.

Parameters
blueprint Blueprint to spawn.
withName Whether to use the entity names from the blueprint.
Returns Map of entity names to their identifiers.

void cubos::core::ecs::CommandBuffer::add(Entity entity, const reflection::Type& type, void* value)

Adds a component to an entity.

Parameters
entity Entity identifier.
type Component type.
value Component value to be moved.

void cubos::core::ecs::CommandBuffer::remove(Entity entity, const reflection::Type& type)

Removes a component from an entity.

Parameters
entity Entity identifier.
type Component type.

void cubos::core::ecs::CommandBuffer::relate(Entity from, Entity to, const reflection::Type& type, void* value)

Inserts a relation between the two given entities.

Parameters
from From entity.
to To entity.
type Relation type.
value Relation value to move.

If the relation already exists, it is overwritten.

void cubos::core::ecs::CommandBuffer::unrelate(Entity from, Entity to, const reflection::Type& type)

Removes the relation, if there's any, between the two given entities.

Parameters
from From entity.
to To entity.
type Relation type.

void cubos::core::ecs::CommandBuffer::push(memory::Function<void(World&)> command)

Pushes a command.

Parameters
command Command function.