Skip to main content

UiActionCommandManager.ixx File

Manager for processing UI action commands. More...

Included Headers

#include <unordered_map> #include <functional> #include <cassert> #include <helios/helios_config.h> #include <helios.engine.runtime.world.GameWorld> #include <helios.engine.ecs.GameObject> #include <helios.engine.common> #include <helios.engine.runtime.world.UpdateContext> #include <helios.engine.modules.ui.widgets.types.ActionId> #include <helios.engine.modules.ui.widgets.types> #include <helios.engine.modules.ui.widgets.commands>

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemodules

Domain-specific components and systems. More...

namespaceui

User interface components and systems for game entities. More...

Classes Index

classUiActionCommandManager

Manages and processes UI action commands with policy-based dispatch. More...

Description

Manager for processing UI action commands.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file UiActionCommandManager.ixx
3 * @brief Manager for processing UI action commands.
4 */
5module;
6
7#include <unordered_map>
8#include <functional>
9#include <cassert>
10#include <helios/helios_config.h>
11
12export module helios.engine.modules.ui.UiActionCommandManager;
13
14import helios.engine.modules.ui.widgets.commands;
15import helios.engine.modules.ui.widgets.types;
16import helios.engine.modules.ui.widgets.types.ActionId;
17
18
19import helios.engine.ecs.GameObject;
20
21import helios.engine.runtime.world.UpdateContext;
22
23import helios.engine.runtime.world.GameWorld;
24
25import helios.engine.common;
26
30
31export namespace helios::engine::modules::ui {
32
33 /**
34 * @brief Manages and processes UI action commands with policy-based dispatch.
35 *
36 * Collects UiActionCommand instances and dispatches them to registered
37 * action callbacks based on ActionId. Supports policy registration for
38 * handling different action types.
39 *
40 * @see UiActionCommand
41 * @see CommandHandlerRegistry
42 */
44
45 using ActionCallback = std::function<void(
47
48 /**
49 * @brief Queue of pending UI action commands.
50 */
51 std::vector<UiActionCommand> commands_;
52
53 /**
54 * @brief Map from ActionId to their handling callbacks.
55 */
56 std::unordered_map<ActionId, ActionCallback> policies_;
57
58 public:
60
61 /**
62 * @brief Constructs the manager with default capacity.
63 */
65 commands_.reserve(UI_ACTION_COMMAND_HANDLER_DEFAULT_CAPACITY);
66 };
67
68 /**
69 * @brief Processes all pending commands by invoking their registered policies.
70 *
71 * @param gameWorld The game world.
72 * @param update_context The current update context.
73 */
74 void flush(
76 ) noexcept {
77
78 for (auto cmd : commands_) {
79 if (policies_.contains(cmd.actionId())) {
80 policies_[cmd.actionId()](
81 update_context, cmd
82 );
83 }
84 }
85
86 commands_.clear();
87 }
88
89 /**
90 * @brief Submits a UI action command for processing.
91 *
92 * @param uiActionCommand The command to submit.
93 *
94 * @return Always returns true.
95 */
96 bool submit(UiActionCommand uiActionCommand) noexcept {
97
98 commands_.push_back(std::move(uiActionCommand));
99
100 return true;
101 };
102
103 /**
104 * @brief Registers a callback for a specific action ID.
105 *
106 * @param actionId The action ID to register.
107 * @param callback The callback to invoke when the action is triggered.
108 *
109 * @return Reference to this manager for method chaining.
110 */
112 const ActionId actionId,
113 ActionCallback callback
114 ) {
115 assert(policies_.find(actionId) == policies_.end() && "Action already registered");
116
117 policies_[actionId] = std::move(callback);
118 return *this;
119 }
120
121 /**
122 * @brief Initializes the manager and registers it with the game world.
123 *
124 * @param gameWorld The game world to register with.
125 */
128 }
129
130 };
131
132}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.