TypedCommandBuffer Class Template
Compile-time typed command buffer with per-type queues and handler routing. More...
Declaration
Public Member Functions Index
template <typename T, typename... Args> | |
| void | add (Args &&... args) |
|
Enqueues a command of the specified type. More... | |
template <typename... CommandTypes> | |
| void | clear () noexcept |
|
Discards all queued commands without executing them. More... | |
template <typename... CommandTypes> | |
| void | flush (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> | |
| bool | shouldDelayCommand (const TimerState state) const noexcept |
|
Determines whether a delayed command should be deferred. More... | |
template <typename... CommandTypes> | |
| bool | shouldDiscardCommand (const TimerState state) const noexcept |
|
Determines whether a delayed command should be discarded. More... | |
template <typename... CommandTypes> | |
| bool | isDelayedCommandReady (const TimerState state) const noexcept |
|
Determines whether a delayed command is ready for dispatch. More... | |
template <typename CommandType> | |
| void | flushCommandQueue (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
- See Also
- See Also
- See Also
ExecutableCommand
Definition at line 91 of file TypedCommandBuffer.ixx.
Public Member Functions
add()
| 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.
clear()
| inline noexcept |
Discards all queued commands without executing them.
Definition at line 300 of file TypedCommandBuffer.ixx.
flush()
| 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.
Private Member Functions
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.
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.
flushCommandQueue()
| 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.
isDelayedCommandReady()
| 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.
shouldDelayCommand()
| 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.
shouldDiscardCommand()
| 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.
Private Member Attributes
commandQueues_
|
Per-type command queues stored as a tuple of vectors.
Definition at line 96 of file TypedCommandBuffer.ixx.
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.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.