Skip to main content

TypedCommandBuffer Class Template

Compile-time typed command buffer with per-type queues and handler routing. More...

Declaration

template <typename... CommandTypes> class helios::engine::runtime::messaging::command::TypedCommandBuffer<CommandTypes> { ... }

Public Member Functions Index

template <typename T, typename... Args>
voidadd (Args &&... args)

Enqueues a command of the specified type. More...

template <typename... CommandTypes>
voidclear () noexcept

Discards all queued commands without executing them. More...

template <typename... CommandTypes>
voidflush (GameWorld &gameWorld, UpdateContext &updateContext) noexcept

Flushes all command queues in template parameter order. More...

Private Member Functions Index

template <typename CommandType>
auto commandQueue () noexcept -> std::vector< CommandType > &

Returns the queue for a specific command type. More...

template <typename CommandType>
voidflushCommandQueue (GameWorld &gameWorld, UpdateContext &updateContext) noexcept

Flushes a single command queue. More...

Private Member Attributes Index

template <typename... CommandTypes>
std::tuple< std::vector< CommandTypes >... >commandQueues_

Per-type command queues stored as a tuple of vectors. More...

Description

Compile-time typed command buffer with per-type queues and handler routing.

TypedCommandBuffer stores commands in separate `std::vector` queues, one per command type, packed into a `std::tuple`. This provides:

  • **Zero-overhead dispatch:** Command types are known at compile time, eliminating virtual dispatch for queue access.
  • **Deterministic ordering:** Commands are flushed in the order of the template parameter list, ensuring reproducible execution.
  • **Handler-or-execute routing:** During flush, each command is either routed to a registered handler or executed directly via its `execute()` method (if it satisfies ExecutableCommand).

## Flush Routing

For each command type in the parameter pack: 1. If a handler for `Cmd` is registered → `handler.submit(cmd)` 2. Else if `Cmd` satisfies `ExecutableCommand` → `cmd.execute(ctx)` 3. Else → assertion failure (misconfiguration)

Template Parameters
CommandTypes

The command types this buffer manages.

See Also

CommandBuffer

See Also

CommandHandlerRegistry

See Also

EngineCommandBuffer

See Also

ExecutableCommand

Definition at line 69 of file TypedCommandBuffer.ixx.

Public Member Functions

add()

template <typename T, typename... Args>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::add (Args &&... args)
inline

Enqueues a command of the specified type.

Template Parameters
T

The command type. Must be one of the CommandTypes.

Args

Constructor argument types.

Parameters
args

Arguments forwarded to the command constructor.

Definition at line 139 of file TypedCommandBuffer.ixx.

139 void add(Args&&... args) {
140 auto& queue = std::get<std::vector<T>>(commandQueues_);
141 queue.emplace_back(std::forward<Args>(args)...);
142 }

clear()

template <typename... CommandTypes>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::clear ()
inline noexcept

Discards all queued commands without executing them.

Definition at line 147 of file TypedCommandBuffer.ixx.

147 void clear() noexcept {
148 std::apply([](auto&... queue) { (queue.clear(), ...); }, commandQueues_);
149 }

flush()

template <typename... CommandTypes>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::flush (GameWorld & gameWorld, UpdateContext & updateContext)
inline noexcept

Flushes all command queues in template parameter order.

Iterates through each command type using a fold expression, flushing queues in the order specified by the template parameters.

Parameters
gameWorld

The game world for which the queue should be flushed.

updateContext

The current frame's update context.

Definition at line 160 of file TypedCommandBuffer.ixx.

160 void flush(GameWorld& gameWorld, UpdateContext& updateContext) noexcept {
161 (flushCommandQueue<CommandTypes>(gameWorld, updateContext), ...);
162 }

Private Member Functions

commandQueue()

template <typename CommandType>
std::vector< CommandType > & helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::commandQueue ()
inline noexcept

Returns the queue for a specific command type.

Template Parameters
CommandType

The command type.

Returns

Reference to the command queue.

Definition at line 84 of file TypedCommandBuffer.ixx.

84 std::vector<CommandType>& commandQueue() noexcept {
85 return std::get<std::vector<CommandType>>(commandQueues_);
86 }

flushCommandQueue()

template <typename CommandType>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::flushCommandQueue (GameWorld & gameWorld, UpdateContext & updateContext)
inline noexcept

Flushes a single command queue.

Routes each command to its registered handler, or executes it directly if no handler is registered and the command satisfies ExecutableCommand.

Template Parameters
CommandType

The command type to flush.

Parameters
gameWorld

The game world for which the queue should be flushed.

updateContext

The current frame's update context.

Definition at line 101 of file TypedCommandBuffer.ixx.

101 void flushCommandQueue(GameWorld& gameWorld, UpdateContext& updateContext) noexcept {
102
103 auto& queue = commandQueue<CommandType>();
104 if (queue.empty()) {
105 return;
106 }
107
108 auto& commandHandlerRegistry = gameWorld.commandHandlerRegistry();
109
110 if (commandHandlerRegistry.has<CommandType>()) {
111 for (auto& cmd : queue) {
112 commandHandlerRegistry.submit<CommandType>(cmd);
113 }
114 } else {
115 if constexpr (ExecutableCommand<CommandType>) {
116 for (auto& cmd : queue) {
117 cmd.execute(updateContext);
118 }
119 } else {
120 assert(false && "Command type is not executable");
121 }
122
123 }
124
125 queue.clear();
126 }

Private Member Attributes

commandQueues_

template <typename... CommandTypes>
std::tuple<std::vector<CommandTypes>...> helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::commandQueues_

Per-type command queues stored as a tuple of vectors.

Definition at line 74 of file TypedCommandBuffer.ixx.

74 std::tuple<std::vector<CommandTypes>...> commandQueues_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.