cubos::core::ecs::Commands class final

System argument used to write ECS commands and execute them at a later time.

Internally wraps a reference to a CommandBuffer object.

Constructors, destructors, conversion operators

Commands(CommandBuffer& buffer)
Constructs.
Commands(Commands&&) defaulted
Move constructor.
EntityBuilder(CommandBuffer& buffer, Entity entity)
Constructs.
BlueprintBuilder(CommandBuffer& buffer, std::unordered_map<std::string, Entity> nameToEntity)
Constructs.

Public functions

void insertResource(memory::AnyValue value)
Inserts a resource into the world.
template<typename T>
void insertResource(T value)
Inserts a resource into the world.
template<typename T, typename... TArgs>
void emplaceResource(TArgs && ... args)
Emplaces a resource into the world. Directly constructs the resource in place.
void eraseResource(const reflection::Type& type)
Removes a resource from the world.
template<typename T>
void eraseResource()
Removes a resource from the world.
auto create() -> EntityBuilder
Creates a new entity.
void destroy(Entity entity)
Destroys an entity.
auto spawn(const Blueprint& blueprint, bool withName = true) -> BlueprintBuilder
Spawns a blueprint into the world.
auto add(Entity entity, const reflection::Type& type, void* value) -> Commands&
Adds a component to an entity.
template<typename T>
auto add(Entity entity, T value) -> Commands&
Adds a component to an entity.
auto remove(Entity entity, const reflection::Type& type) -> Commands&
Removes a component from an entity.
template<typename T>
auto remove(Entity entity) -> Commands&
Removes a component from an entity.
auto relate(Entity from, Entity to, const reflection::Type& type, void* value) -> Commands&
Inserts a relation between the two given entities.
template<typename T>
auto relate(Entity from, Entity to, T value) -> Commands&
Inserts a relation between the two given entities.
auto unrelate(Entity from, Entity to, const reflection::Type& type) -> Commands&
Removes the relation, if there's any, between the two given entities.
template<typename T>
auto unrelate(Entity from, Entity to) -> Commands&
Removes the relation, if there's any, between the two given entities.
auto entity() const -> Entity
Gets the entity this builder is modifying.
auto named(std::string name) -> EntityBuilder&
Adds a Name component to the entity.
auto add(const reflection::Type& type, void* value) -> EntityBuilder&
Adds a component to the entity.
template<typename T>
auto add(T value) -> EntityBuilder&
Adds a component to the entity.
auto relatedFrom(Entity entity, const reflection::Type& type, void* value) -> EntityBuilder&
Adds an incoming relation from the given entity to this entity.
template<typename T>
auto relatedFrom(Entity entity, T value) -> EntityBuilder&
Adds an incoming relation from the given entity to this entity.
auto relatedTo(Entity entity, const reflection::Type& type, void* value) -> EntityBuilder&
Adds an outgoing relation from this entity to the given entity.
template<typename T>
auto relatedTo(Entity entity, T value) -> EntityBuilder&
Adds an outgoing relation from this entity to the given entity.
auto entity(const std::string& name) const -> Entity
Gets an entity of the spawned blueprint.
auto add(const std::string& name, const reflection::Type& type, void* value) -> BlueprintBuilder&
Adds a component to an entity of the blueprint.
template<typename T>
auto add(const std::string& name, T value) -> BlueprintBuilder&
Adds a component to an entity of the blueprint.

Function documentation

cubos::core::ecs::Commands::Commands(CommandBuffer& buffer)

Constructs.

Parameters
buffer Command buffer to write to.

cubos::core::ecs::Commands::EntityBuilder(CommandBuffer& buffer, Entity entity)

Constructs.

Parameters
buffer Command buffer.
entity Entity being modified.

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

Inserts a resource into the world.

Parameters
value Resource value.

template<typename T>
void cubos::core::ecs::Commands::insertResource(T value)

Inserts a resource into the world.

Template parameters
T Resource type.
Parameters
value Resource value.

template<typename T, typename... TArgs>
void cubos::core::ecs::Commands::emplaceResource(TArgs && ... args)

Emplaces a resource into the world. Directly constructs the resource in place.

Template parameters
T Resource type.
TArgs Argument types.
Parameters
args Arguments.

This is useful when the resource doesn't have a move constructor, for example, due to not implementing reflection.

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

Removes a resource from the world.

Parameters
type Resource type.

template<typename T>
void cubos::core::ecs::Commands::eraseResource()

Removes a resource from the world.

Template parameters
T Resource type.

EntityBuilder cubos::core::ecs::Commands::create()

Creates a new entity.

Returns Builder which can be used to modify the created entity.

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

Destroys an entity.

Parameters
entity Entity identifier.

BlueprintBuilder cubos::core::ecs::Commands::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 Blueprint builder.

Commands& cubos::core::ecs::Commands::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.
Returns Commands.

template<typename T>
Commands& cubos::core::ecs::Commands::add(Entity entity, T value)

Adds a component to an entity.

Template parameters
T Component type.
Parameters
entity Entity identifier.
value Component value.
Returns Commands.

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

Removes a component from an entity.

Parameters
entity Entity identifier.
type Component type.
Returns Commands.

template<typename T>
Commands& cubos::core::ecs::Commands::remove(Entity entity)

Removes a component from an entity.

Template parameters
T Component type.
Parameters
entity Entity identifier.
Returns Commands.

Commands& cubos::core::ecs::Commands::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.
Returns Commands.

If the relation already exists, it is overwritten.

template<typename T>
Commands& cubos::core::ecs::Commands::relate(Entity from, Entity to, T value)

Inserts a relation between the two given entities.

Template parameters
T Relation type.
Parameters
from From entity.
to To entity.
value Relation value.
Returns Commands.

If the relation already exists, it is overwritten.

Commands& cubos::core::ecs::Commands::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.
Returns Commands.

template<typename T>
Commands& cubos::core::ecs::Commands::unrelate(Entity from, Entity to)

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

Template parameters
T Relation type.
Parameters
from From entity.
to To entity.
Returns Commands.

Entity cubos::core::ecs::Commands::entity() const

Gets the entity this builder is modifying.

Returns Entity identifier.

EntityBuilder& cubos::core::ecs::Commands::named(std::string name)

Adds a Name component to the entity.

Parameters
name Entity name.
Returns Reference to this builder, for chaining.

EntityBuilder& cubos::core::ecs::Commands::add(const reflection::Type& type, void* value)

Adds a component to the entity.

Parameters
type Component type.
value Component value.
Returns Reference to this builder, for chaining.

template<typename T>
EntityBuilder& cubos::core::ecs::Commands::add(T value)

Adds a component to the entity.

Template parameters
T Component type.
Parameters
value Component value.
Returns Reference to this builder, for chaining.

EntityBuilder& cubos::core::ecs::Commands::relatedFrom(Entity entity, const reflection::Type& type, void* value)

Adds an incoming relation from the given entity to this entity.

Parameters
entity Entity.
type Relation type.
value Relation value.
Returns Reference to this builder, for chaining.

template<typename T>
EntityBuilder& cubos::core::ecs::Commands::relatedFrom(Entity entity, T value)

Adds an incoming relation from the given entity to this entity.

Template parameters
T Relation type.
Parameters
entity Entity.
value Relation value.
Returns Reference to this builder, for chaining.

EntityBuilder& cubos::core::ecs::Commands::relatedTo(Entity entity, const reflection::Type& type, void* value)

Adds an outgoing relation from this entity to the given entity.

Parameters
entity Entity.
type Relation type.
value Relation value.
Returns Reference to this builder, for chaining.

template<typename T>
EntityBuilder& cubos::core::ecs::Commands::relatedTo(Entity entity, T value)

Adds an outgoing relation from this entity to the given entity.

Template parameters
T Relation type.
Parameters
entity Entity.
value Relation value.
Returns Reference to this builder, for chaining.

Entity cubos::core::ecs::Commands::entity(const std::string& name) const

Gets an entity of the spawned blueprint.

Parameters
name Entity name.
Returns Entity identifier.

Aborts if the name does not match any entity of the blueprint.

BlueprintBuilder& cubos::core::ecs::Commands::add(const std::string& name, const reflection::Type& type, void* value)

Adds a component to an entity of the blueprint.

Parameters
name Entity name.
type Component Type.
value Component value.
Returns Reference to this builder, for chaining.

Aborts if name does not match any entity of the blueprint.

template<typename T>
BlueprintBuilder& cubos::core::ecs::Commands::add(const std::string& name, T value)

Adds a component to an entity of the blueprint.

Template parameters
T Component type.
Parameters
name Entity name.
value Component value.
Returns Reference to this builder, for chaining.

Aborts if name does not match any entity of the blueprint.