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>
auto delayedQueue () noexcept -> std::vector< CommandType > &

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

template <typename... CommandTypes>
boolshouldDelayCommand (const TimerState state) const noexcept

Determines whether a delayed command should be deferred. More...

template <typename... CommandTypes>
boolshouldDiscardCommand (const TimerState state) const noexcept

Determines whether a delayed command should be discarded. More...

template <typename... CommandTypes>
boolisDelayedCommandReady (const TimerState state) const noexcept

Determines whether a delayed command is ready for dispatch. 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...

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

Scratch queues for timer-gated commands surviving a flush cycle. 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 91 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 292 of file TypedCommandBuffer.ixx.

292 void add(Args&&... args) {
293 auto& queue = std::get<std::vector<T>>(commandQueues_);
294 queue.emplace_back(std::forward<Args>(args)...);
295 }

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 300 of file TypedCommandBuffer.ixx.

300 void clear() noexcept {
301 std::apply([](auto&... queue) { (queue.clear(), ...); }, commandQueues_);
302 }

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 313 of file TypedCommandBuffer.ixx.

313 void flush(GameWorld& gameWorld, UpdateContext& updateContext) noexcept {
314 (flushCommandQueue<CommandTypes>(gameWorld, updateContext), ...);
315 }

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 115 of file TypedCommandBuffer.ixx.

115 std::vector<CommandType>& commandQueue() noexcept {
116 return std::get<std::vector<CommandType>>(commandQueues_);
117 }

delayedQueue()

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

Returns the delayed scratch queue for a specific command type.

Template Parameters
CommandType

The command type.

Returns

Reference to the delayed scratch queue.

Definition at line 127 of file TypedCommandBuffer.ixx.

127 std::vector<CommandType>& delayedQueue() noexcept {
128 return std::get<std::vector<CommandType>>(delayedQueues_);
129 }

flushCommandQueue()

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

Flushes a single command queue.

Processing follows two branches depending on whether a handler is registered for `CommandType`:

**Handler registered** (`CommandHandlerRegistry::has<CommandType>()`):

  • Each command is forwarded via `commandHandlerRegistry.submit<CommandType>(cmd)`.

**No handler registered** (fallback):

  • The command must satisfy `ExecutableCommand`; otherwise an assertion fires at runtime.
  • Each command is dispatched via `cmd.execute(updateContext)`.

In both branches, if `CommandType` satisfies `DelayedCommandLike`, an additional timer check is performed per command:

1. The associated `GameTimer` is looked up via the command's `gameTimerId()`. 2. If the timer is still running (`shouldDelayCommand` returns true), the command is moved into the scratch queue and survives the current flush cycle. 3. If the timer has finished (`isDelayedCommandReady` returns true), the command is dispatched normally. 4. If the timer state is `Undefined` (e.g. timer was removed), the command is silently dropped.

After all commands have been processed the primary queue is cleared, the scratch queue contents are swapped back in as the new primary queue, and the scratch queue is cleared.

Template Parameters
CommandType

The command type to flush.

Parameters
gameWorld

The game world providing the CommandHandlerRegistry and TimerManager.

updateContext

The current frame's update context.

Definition at line 207 of file TypedCommandBuffer.ixx.

207 void flushCommandQueue(GameWorld& gameWorld, UpdateContext& updateContext) noexcept {
208
209 auto& timerManager = gameWorld.manager<TimerManager>();
210
211 auto& queue = commandQueue<CommandType>();
212 auto& delayed = delayedQueue<CommandType>();
213 delayed.clear();
214
215 if (queue.empty()) {
216 return;
217 }
218
219 auto& commandHandlerRegistry = gameWorld.commandHandlerRegistry();
220
221 if (commandHandlerRegistry.has<CommandType>()) {
222
223 for (auto& cmd : queue) {
224 if constexpr (DelayedCommandLike<CommandType>) {
225 auto* gameTimer = timerManager.gameTimer(cmd.gameTimerId());
226 if (!gameTimer) {
227 assert(gameTimer && "Unexpected null game timer");
228 commandHandlerRegistry.submit<CommandType>(cmd);
229 continue;
230 }
231
232 if (shouldDelayCommand(gameTimer->state())) {
233 delayed.push_back(std::move(cmd));
234 } else if (isDelayedCommandReady(gameTimer->state())) {
235 commandHandlerRegistry.submit<CommandType>(cmd);
236 } else if (shouldDiscardCommand(gameTimer->state())) {
237 // cancelled? Discard! intentionally noop
238 }
239 } else {
240 commandHandlerRegistry.submit<CommandType>(cmd);
241 }
242 }
243
244
245 } else {
246 if constexpr (ExecutableCommand<CommandType>) {
247
248 for (auto& cmd : queue) {
249 if constexpr (DelayedCommandLike<CommandType>) {
250 auto* gameTimer = timerManager.gameTimer(cmd.gameTimerId());
251 if (!gameTimer) {
252 assert(gameTimer && "Unexpected null game timer");
253 cmd.execute(updateContext);
254 continue;
255 }
256
257 if (shouldDelayCommand(gameTimer->state())) {
258 delayed.push_back(std::move(cmd));
259 } else if (isDelayedCommandReady(gameTimer->state())) {
260 cmd.execute(updateContext);
261 } else if (shouldDiscardCommand(gameTimer->state())) {
262 // cancelled? Discard! intentionally noop
263 }
264 } else {
265 cmd.execute(updateContext);
266 }
267
268 }
269
270 } else {
271 assert(false && "Command type is not executable");
272 }
273
274 }
275
276 queue.clear();
277 queue.swap(delayed);
278 delayed.clear();
279 }

isDelayedCommandReady()

template <typename... CommandTypes>
bool helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::isDelayedCommandReady (const TimerState state)
inline nodiscard noexcept

Determines whether a delayed command is ready for dispatch.

Parameters
state

The current timer state.

Returns

True if the associated timer has finished.

Definition at line 165 of file TypedCommandBuffer.ixx.

165 [[nodiscard]] bool isDelayedCommandReady(const TimerState state) const noexcept {
167 }

shouldDelayCommand()

template <typename... CommandTypes>
bool helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::shouldDelayCommand (const TimerState state)
inline nodiscard noexcept

Determines whether a delayed command should be deferred.

Returns true when the timer is still running - i.e. its state is neither Finished nor Undefined.

Parameters
state

The current timer state.

Returns

True if the command must remain in the scratch queue.

Definition at line 141 of file TypedCommandBuffer.ixx.

141 [[nodiscard]] bool shouldDelayCommand(const TimerState state) const noexcept {
142 return state == TimerState::Running;
143 }

shouldDiscardCommand()

template <typename... CommandTypes>
bool helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::shouldDiscardCommand (const TimerState state)
inline nodiscard noexcept

Determines whether a delayed command should be discarded.

Returns true when the timer is not in state Running or Finished..

Parameters
state

The current timer state.

Returns

True if the command should be discarded.

Definition at line 154 of file TypedCommandBuffer.ixx.

154 [[nodiscard]] bool shouldDiscardCommand(const TimerState state) const noexcept {
156 }

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 96 of file TypedCommandBuffer.ixx.

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

delayedQueues_

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

Scratch queues for timer-gated commands surviving a flush cycle.

Commands satisfying DelayedCommandLike whose timer has not yet finished are moved here during flush and swapped back into the primary queues afterwards.

Definition at line 105 of file TypedCommandBuffer.ixx.

105 std::tuple<std::vector<CommandTypes>...> delayedQueues_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.