Skip to main content

TypedPass.ixx File

State-filtered pass implementation for game loop phases. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespacemodules

Domain-specific components and systems. More...

namespaceruntime

Runtime infrastructure for game execution and lifecycle orchestration. More...

namespacegameloop

Central game loop orchestration module. More...

Classes Index

classTypedPass<StateType>

State-filtered pass that only executes in specific states. More...

Description

State-filtered pass implementation for game loop phases.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file TypedPass.ixx
3 * @brief State-filtered pass implementation for game loop phases.
4 */
5module;
6
7#include <type_traits>
8#include <utility>
9
10export module helios.engine.runtime.gameloop.TypedPass;
11
12import helios.engine.runtime.gameloop.CommitPoint;
13
14import helios.engine.runtime.gameloop.Pass;
15
16import helios.engine.runtime.world.SystemRegistry;
17
18import helios.engine.runtime.world.UpdateContext;
19import helios.engine.runtime.world.Session;
20
21import helios.engine.mechanics.gamestate.types;
22
23export namespace helios::engine::modules {
24 class GameWorld;
25}
26
28
29 class Phase;
30
31 /**
32 * @brief State-filtered pass that only executes in specific states.
33 *
34 * @details TypedPass extends the base Pass class with state-based filtering.
35 * The pass only executes when the current state (queried from Session)
36 * matches the configured state mask using bitwise AND.
37 *
38 * ## State Filtering
39 *
40 * The state mask is a bitfield where each bit represents a state value.
41 * A pass runs if any bit in the mask matches the current state:
42 *
43 * ```cpp
44 * // Run only in Running state
45 * phase.addPass<GameState>(GameState::Running)
46 * .addSystem<MovementSystem>();
47 *
48 * // Run in multiple states (bitwise OR)
49 * phase.addPass<GameState>(GameState::Running | GameState::Paused)
50 * .addSystem<InputSystem>();
51 * ```
52 *
53 * @tparam StateType The state enum type (e.g., GameState, MatchState).
54 *
55 * @see Pass
56 * @see Phase::addPass()
57 * @see Session::state()
58 */
59 template<typename StateType>
60 class TypedPass : public Pass {
61
63
64 /**
65 * @brief Reference to the owning Phase.
66 */
67 Phase& owner_;
68
69 /**
70 * @brief Bitmask of states in which this pass should execute.
71 */
72 StateType mask_;
73
74 /**
75 * @brief Updates all systems registered in this pass.
76 *
77 * @param updateContext The current update context.
78 */
79 void update(helios::engine::runtime::world::UpdateContext& updateContext) override {
80 for (auto& sys : systemRegistry_.items()) {
81 sys->update(updateContext);
82 }
83 }
84
85
86 /**
87 * @brief Initializes all systems registered in this pass.
88 *
89 * @param gameWorld Reference to the game world.
90 */
91 void init(helios::engine::runtime::world::GameWorld& gameWorld) override {
92 for (auto& sys : systemRegistry_.items()) {
93 sys->init(gameWorld);
94 }
95 }
96
97
98 /**
99 * @brief The CommitPoint configured for this Pass.
100 */
101 CommitPoint commitPoint_ = CommitPoint::None;
102
103
104
105 public:
106
107 /**
108 * @brief Constructs a Pass with a reference to its owning Phase.
109 *
110 * @param owner Reference to the parent Phase.
111 */
112 explicit TypedPass(Phase& owner, const StateType mask) : owner_(owner), mask_(mask) {}
113
114
115 /**
116 * @brief Marks this pass with a commit point and returns the owning Phase.
117 *
118 * @details When a commit point is set, the specified synchronization actions are
119 * performed after this pass completes. The default is `CommitPoint::PassEvents`
120 * which only synchronizes pass-level events.
121 *
122 * Available CommitPoint flags:
123 * - `PassEvents` - Events pushed via `UpdateContext::pushPass()` become readable.
124 * - `FlushCommands` - Pending commands from the CommandBuffer are executed.
125 * - `FlushManagers` - Managers process their queued requests.
126 * - `Structural` - Combines all three flags.
127 *
128 * Flags can be combined using bitwise OR:
129 * ```cpp
130 * pass.addCommitPoint(CommitPoint::PassEvents | CommitPoint::FlushCommands);
131 * ```
132 *
133 * @param commitPoint The flags specifying which actions to perform (default: PassEvents).
134 *
135 * @return Reference to the owning Phase for continued configuration.
136 *
137 * @see CommitPoint
138 * @see UpdateContext::pushPass()
139 * @see UpdateContext::readPass()
140 * @see GameLoop::passCommit()
141 */
143 commitPoint_ = commitPoint;
144 return owner_;
145 }
146
147
148 /**
149 * @brief Returns the configured commit point for this pass.
150 *
151 * @details The commit point determines what synchronization actions are performed
152 * after this pass completes. If no commit point was added, returns CommitPoint::None.
153 *
154 * @return The commit point flags for this pass.
155 *
156 * @see CommitPoint
157 * @see addCommitPoint()
158 */
159 [[nodiscard]] CommitPoint commitPoint() const noexcept override {
160 return commitPoint_;
161 }
162
163 /**
164 * @brief Checks if this pass should execute based on current state.
165 *
166 * @details Queries the current state from the Session and compares it
167 * against the configured mask using bitwise AND. The pass runs if
168 * any bit in the mask matches the current state.
169 *
170 * @param updateContext The current update context.
171 *
172 * @return True if the pass should execute.
173 */
174 [[nodiscard]] bool shouldRun(helios::engine::runtime::world::UpdateContext& updateContext) const noexcept override {
175 auto state = updateContext.session().state<StateType>();
176 return hasFlag(mask_, state);
177 }
178
179 /**
180 * @brief Checks if a value has any bit set in the mask.
181 *
182 * @param mask The bitmask to check against.
183 * @param value The value to test.
184 *
185 * @return True if any bit in mask matches value.
186 */
187 bool hasFlag(StateType mask, StateType value) const noexcept {
188 using U = std::underlying_type_t<StateType>;
189 return (static_cast<U>(mask) & static_cast<U>(value)) != 0;
190 }
191
192
193 };
194
195}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.