CommandBuffer Class
Queue for deferred execution of game commands. More...
Declaration
Public Member Functions Index
template <typename T> | |
| CommandBuffer & | addDispatcher (std::unique_ptr< helios::engine::runtime::messaging::command::TypedTargetedCommandDispatcher< T > > d) |
|
Registers a dispatcher for a specific TargetedCommand type. More... | |
template <typename T> | |
| bool | hasDispatcher () const |
|
Checks if a dispatcher is registered for a specific TargetedCommand type. More... | |
template <typename T> | |
| CommandBuffer & | addDispatcher (std::unique_ptr< helios::engine::runtime::messaging::command::TypedWorldCommandDispatcher< T > > d) |
|
Registers a dispatcher for a specific WorldCommand type. More... | |
template <typename T> | |
| bool | hasDispatcher () const |
|
Checks if a dispatcher is registered for a specific WorldCommand type. More... | |
template <typename T, typename... Args> | |
| void | add (const helios::engine::ecs::EntityHandle &entityHandle, Args &&...args) |
|
Adds a command targeting a GameObject identified by Guid. More... | |
template <typename T, typename... Args> | |
| void | add (Args &&...args) |
|
Adds a world command to the buffer. More... | |
| CommandBuffer & | flush (helios::engine::runtime::world::GameWorld &gameWorld) |
|
Executes all buffered commands against the GameWorld and clears the buffer. More... | |
| CommandBuffer & | clear () |
|
Clears all buffered commands without executing them. More... | |
Private Member Attributes Index
| std::deque< TargetedCommandProxy > | targetedCommandBuffer_ |
|
Internal queue storing buffered commands. More... | |
| std::deque< WorldCommandProxy > | worldCommandBuffer_ |
|
Internal queue storing buffered world commands. More... | |
| std::unordered_map< std::type_index, std::unique_ptr< helios::engine::runtime::messaging::command::TargetedCommandDispatcher > > | targetedCommandDispatchers_ |
|
Registry of dispatchers for TargetedCommand types. More... | |
| std::unordered_map< std::type_index, std::unique_ptr< helios::engine::runtime::messaging::command::WorldCommandDispatcher > > | worldCommandDispatchers_ |
|
Registry of dispatchers for WorldCommand types. More... | |
Private Static Attributes Index
| static const helios::util::log::Logger & | logger_ = ... |
|
The logger used with this CommandBuffer instance. More... | |
Description
Queue for deferred execution of game commands.
The `CommandBuffer` provides a queue for game commands, decoupling their creation from their execution. Commands are buffered along with their target `GameObject` identifiers (`Guid`) and are executed in a single batch when `flush()` is called against a `GameWorld`.
Typical usage pattern: ```cpp helios::engine::runtime::messaging::command::CommandBuffer cmdBuffer; helios::engine::runtime::world::GameWorld world;
// Queue commands during input processing cmdBuffer.add(player.guid(), std::make_unique<MoveCommand>(direction, speed)); cmdBuffer.add(enemy.guid(), std::make_unique<AttackCommand>(target));
// Execute all commands at end of frame cmdBuffer.flush(world); // Executes and clears buffer ```
Commands targeting non-existent GameObjects are silently skipped during flush(). This behavior will be logged once the logging system is available.
Definition at line 61 of file CommandBuffer.ixx.
Public Member Functions
add()
| inline |
Adds a command targeting a GameObject identified by Guid.
- Parameters
-
guid The unique identifier of the target GameObject.
command The command to execute. Ownership is transferred to the buffer.
- Precondition
command must not be nullptr.
If command is nullptr, the call is silently ignored (will be logged in future).
This overload is useful when the GameObject instance is not directly available, such as in networked scenarios or when processing serialized commands.
Definition at line 218 of file CommandBuffer.ixx.
add()
| inline |
Adds a world command to the buffer.
- Template Parameters
-
T The concrete WorldCommand type to create.
Args Constructor argument types for T.
- Parameters
-
args Arguments forwarded to the T constructor.
WorldCommands operate on the entire GameWorld rather than a specific GameObject. They are executed before TargetedCommands during flush().
Definition at line 239 of file CommandBuffer.ixx.
addDispatcher()
| inline |
Registers a dispatcher for a specific TargetedCommand type.
When flush() processes a command of type T, it will route the command through this dispatcher instead of calling execute() directly.
- Template Parameters
-
T The concrete TargetedCommand type to dispatch.
- Parameters
-
d The dispatcher instance to register. Ownership is transferred.
- Precondition
No dispatcher for type T must already be registered.
- Returns
A reference to **this** CommandBuffer.
Definition at line 138 of file CommandBuffer.ixx.
Reference hasDispatcher.
addDispatcher()
| inline |
Registers a dispatcher for a specific WorldCommand type.
When flush() processes a command of type T, it will route the command through this dispatcher instead of calling execute() directly.
- Template Parameters
-
T The concrete WorldCommand type to dispatch.
- Parameters
-
d The dispatcher instance to register. Ownership is transferred.
- Precondition
No dispatcher for type T must already be registered.
- Returns
A reference to **this** CommandBuffer.
Definition at line 179 of file CommandBuffer.ixx.
Reference hasDispatcher.
clear()
| inline |
Clears all buffered commands without executing them.
- Returns
Reference to this CommandBuffer for method chaining.
This destroys all buffered commands. Use this to discard commands without executing them (e.g., when reverting to a previous game state).
Definition at line 314 of file CommandBuffer.ixx.
Reference clear.
flush()
| inline |
Executes all buffered commands against the GameWorld and clears the buffer.
- Parameters
-
gameWorld The world containing target GameObjects.
- Returns
Reference to this CommandBuffer for method chaining.
Execution proceeds in two phases: 1. **WorldCommands** are processed first. For each command, if a dispatcher is registered for its type, the command is routed via accept(). Otherwise, execute() is called directly. 2. **TargetedCommands** are processed second. Each command's target GameObject is resolved by Guid. If found and a dispatcher exists, the command is routed via accept(). Otherwise, execute() is called directly.
Commands targeting non-existent GameObjects (i.e., find() returns nullptr) are skipped and a warning is logged.
All commands are cleared after execution, regardless of success or failure.
Command execution should be noexcept. If execute() throws, the flush operation aborts and remaining commands are not executed.
Definition at line 269 of file CommandBuffer.ixx.
References clear and helios::engine::runtime::world::GameWorld::find.
hasDispatcher()
| inline nodiscard |
Checks if a dispatcher is registered for a specific TargetedCommand type.
- Template Parameters
-
T The concrete TargetedCommand type to check.
- Returns
true if a dispatcher is registered for type T, false otherwise.
Definition at line 157 of file CommandBuffer.ixx.
Referenced by addDispatcher and addDispatcher.
hasDispatcher()
| inline nodiscard |
Checks if a dispatcher is registered for a specific WorldCommand type.
- Template Parameters
-
T The concrete WorldCommand type to check.
- Returns
true if a dispatcher is registered for type T, false otherwise.
Definition at line 198 of file CommandBuffer.ixx.
Private Member Attributes
targetedCommandBuffer_
|
Internal queue storing buffered commands.
Uses std::deque for efficient push_back and iteration.
Definition at line 85 of file CommandBuffer.ixx.
targetedCommandDispatchers_
|
Registry of dispatchers for TargetedCommand types.
Maps command type indices to their corresponding dispatchers. When a command is flushed and a dispatcher is registered for its type, the command is routed through the dispatcher instead of executing directly.
Definition at line 109 of file CommandBuffer.ixx.
worldCommandBuffer_
|
Internal queue storing buffered world commands.
Uses std::deque for efficient push_back and iteration.
Definition at line 92 of file CommandBuffer.ixx.
worldCommandDispatchers_
|
Registry of dispatchers for WorldCommand types.
Maps command type indices to their corresponding dispatchers. When a command is flushed and a dispatcher is registered for its type, the command is routed through the dispatcher instead of executing directly.
Definition at line 118 of file CommandBuffer.ixx.
Private Static Attributes
logger_
| static |
The logger used with this CommandBuffer instance.
- Initialiser
Defaults to HELIOS_LOG_SCOPE.
Definition at line 99 of file CommandBuffer.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.