Engine → ECS → command_buffer.h
command_buffer¶
| Type | Class |
| Namespace | conjure::ecs |
| Include File Path | engine/include/conjure/ecs/command_buffer.h |
| Source File Path | engine/src/ecs/command_buffer.cpp |
| API ↗ | Command buffers and observers |
Syntax¶
Constructors¶
| Access | Signature | Description |
|---|---|---|
| public | explicit command_buffer(
world &target); | |
| public | command_buffer(
command_buffer &&other) noexcept; |
Important
Copy constructor and assignment has been deleted.
Destructors¶
| Access | Signature | Description |
|---|---|---|
| public | ~command_buffer(); | Discards pending commands with a WARN (payloads are destroyed) and returns unused ids. The ids of a pending instantiation are released with a bumped generation, as in clear(). |
Variables¶
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mArena | core::memory::arena | — | |
| private | mCount | u32 | 0 | |
| private | mFirst | record * | nullptr | |
| private | m | std:: | {} | |
| private | mLast | record * | nullptr | |
| private | mRegistry | const component_ | nullptr | |
| private | mReserved | std:: | {} | |
| private | m | u32 | 0 | |
| private | mWorld | world * | nullptr | |
| public | RESERVE_ | static constexpr u32 | 64 | Ids reserved per refill. |
Functions¶
Public¶
add¶
add¶template <typename ComponentType> void add(
entity target,
ComponentType value = {});Records adding a component with an initial value (moved in). On an entity that already has it the value is applied like set(). An unregistered type asserts and records nothing.
add_raw¶
add_raw¶void add_raw(
entity target,
component_id id,
std::span<const std::byte> payload = {});Untyped add: the payload bytes are copy-constructed into the record (ops.copy or memcpy). An empty payload records no value: an entity that gains the component at flush gets its default value; one that holds it at flush (a remove_raw earlier in the same buffer included) keeps its current value, and no observer fires for it. Pass the default bytes to reset a held component.
append¶
append¶void append(
command_buffer &&other);Moves every command of other behind this buffer's commands, in order. other keeps its reserved ids and is empty afterwards.
clear¶
clear¶void clear() noexcept;Drops every command, destroying payloads that were not applied. The ids reserved by an instantiation that was never applied (cleared, or skipped by a failed flush) are released with a bumped generation, so the root instantiate() handed out stays dead and never aliases a later entity. That writes the world's record table, so clear a buffer holding an instantiation on the world's owner thread: off it, clear() asserts and leaves those ids reserved for good (the root still never aliases). Unused reserved ids are kept, and so is room for the records: a recording that outgrew the arena's 16 KiB block makes the buffer keep one block spanning the blocks that recording used (its bytes rounded up to whole 16 KiB blocks, like a vector's capacity: at most one block more than it needed), so repeating a recording of the same size allocates nothing after the next one. The room is kept for the buffer's lifetime unless shrink_to_fit() returns it.
create_entity¶
create_entity¶[[nodiscard]] entity create_entity();Reserves a real entity id that becomes alive at flush. The id may be used in later commands of any buffer of the same world and handed to scripts at once. Returns NULL_ENTITY (and logs) when the id space is exhausted.
destroy_entity¶
destroy_entity¶void destroy_entity(
entity target);Records the destruction of an entity. Wins over every other command on it in this buffer.
instantiate¶
instantiate¶[[nodiscard]] core::result<entity> instantiate(
std::shared_ptr<const entity_archive> archive);Records instantiating one copy of an archive at flush; ids are reserved now and the root is returned now. ARCHIVE_CORRUPT when the archive does not validate, ENTITY_LIMIT_REACHED when no ids are left.
remove¶
remove¶template <typename ComponentType> void remove(
entity target);Records removing a component. Cancels a pending add of the same component in this buffer. An unregistered type asserts and records nothing.
reserved_count¶
reserved_count¶[[nodiscard]] u32 reserved_count() const noexcept;Ids reserved and not yet handed out by create_entity().
set¶
set¶template <typename ComponentType> void set(
entity target,
ComponentType value);Records replacing the value of a component the entity has at flush (a missing component is skipped and counted). An unregistered type asserts and records nothing.
set_raw¶
set_raw¶void set_raw(
entity target,
component_id id,
std::span<const std::byte> payload);Untyped set.
shrink_to_fit¶
shrink_to_fit¶void shrink_to_fit() noexcept;Returns the room an earlier recording left behind to the heap: the arena's blocks and the capacity of the instantiation list. Only an empty buffer has room to give back; with commands pending the call changes nothing. Reserved ids are kept either way. The next recording acquires a fresh block, so call it when the buffer goes idle for good (a removed system, a cleared world), not between frames.
Private¶
destroy_payloads¶
destroy_payloads¶void destroy_payloads() noexcept;payload_size¶
payload_size¶template <typename ComponentType> [[nodiscard]] static constexpr u32 payload_size() noexcept;push_instantiate¶
push_instantiate¶[[nodiscard]] core::result<std::span<const entity>> push_instantiate(
std::shared_ptr<const entity_archive> archive,
u32 copies);push_plain_record¶
push_plain_record¶record *push_plain_record(
opcode op,
entity target,
component_id id);push_record¶
push_record¶[[nodiscard]] void *push_record(
opcode op,
entity target,
component_id id,
u32 payloadSize,
u32 alignment);recycle_arena¶
recycle_arena¶void recycle_arena() noexcept;refill_reserved¶
refill_reserved¶[[nodiscard]] bool refill_reserved();return_reserved¶
return_reserved¶void return_reserved() noexcept;Operator Overloads¶
Public¶
operator=¶
operator=¶command_buffer &operator=(
command_buffer &&other) noexcept;