Skip to main content

Session.ixx File

Session state container for game-wide state. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespaceruntime

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

namespaceworld

World state management, resource registry, and per-frame update context. More...

Classes Index

classSession

Holds session-level state for the current game instance. More...

Description

Session state container for game-wide state.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file Session.ixx
3 * @brief Session state container for game-wide state.
4 */
5module;
6
7#include <optional>
8#include <vector>
9#include <span>
10#include <cassert>
11
12export module helios.engine.runtime.world.Session;
13
14import helios.engine.mechanics.gamestate.types;
15import helios.engine.mechanics.match.types;
16
17import helios.engine.state.types;
18import helios.engine.state.components;
19import helios.engine.state.types.StateTransitionId;
20
21import helios.engine.common.types.ViewportId;
22
23import helios.engine.ecs.GameObject;
24import helios.engine.ecs.EntityHandle;
25
26import helios.engine.common.types.ViewportId;
27
28import helios.engine.modules.rendering.viewport.components.ActiveViewportIdsStateComponent;
29
32
33using namespace helios::engine::state::types;
35
37
38export namespace helios::engine::runtime::world {
39
40 /**
41 * @brief Holds session-level state for the current game instance.
42 *
43 * @details The Session wraps a GameObject that stores session-related
44 * components using the template-based state system. It provides type-safe
45 * accessors for any registered state type (e.g., GameState, MatchState).
46 *
47 * State types must be registered via trackState<T>() before use:
48 *
49 * ```cpp
50 * session.trackState<GameState>();
51 * session.trackState<MatchState>();
52 * ```
53 *
54 * ## Stored Components
55 *
56 * - `StateComponent<T>` - Registered via trackState<T>()
57 * - `ActiveViewportIdsStateComponent` - Active viewport list (auto-added)
58 *
59 * @see StateComponent
60 * @see StateManager
61 */
62 class Session {
63
64 /**
65 * @brief The underlying GameObject storing session components.
66 */
67 ecs::GameObject gameObject_;
68
69 /**
70 * @brief Handle to the player entity.
71 */
72 ecs::EntityHandle playerEntity_;
73
74 public:
75
76 /**
77 * @brief Constructs a session with the given GameObject.
78 *
79 * @details Automatically adds ActiveViewportIdsStateComponent.
80 * State types must be registered separately via trackState<T>().
81 *
82 * @param go The GameObject to use as the session entity.
83 */
84 explicit Session(const ecs::GameObject go) : gameObject_(go) {
85 gameObject_.add<ActiveViewportIdsStateComponent>();
86 }
87
88 /**
89 * @brief Sets the player entity handle.
90 *
91 * @param go The player's entity handle.
92 */
93 void setPlayerEntityHandle(const ecs::EntityHandle go) noexcept {
94 playerEntity_ = go;
95 }
96
97 /**
98 * @brief Returns the player entity handle.
99 *
100 * @return The player's entity handle.
101 */
102 [[nodiscard]] ecs::EntityHandle playerEntityHandle() const noexcept {
103 return playerEntity_;
104 }
105
106 /**
107 * @brief Resets the session state.
108 */
109 void reset() {
110
111 }
112
113 /**
114 * @brief Updates state from a transition context.
115 *
116 * @details Called by StateManager after a successful transition.
117 *
118 * @tparam StateType The state enum type.
119 *
120 * @param stateTransitionContext The completed transition context.
121 */
122 template<typename StateType>
123 void setStateFrom(const StateTransitionContext<StateType> stateTransitionContext) noexcept {
124
125 if (auto* msc = gameObject_.get<StateComponent<StateType>>()) {
126 msc->setStateFromTransitionContext(stateTransitionContext);
127 }
128 }
129
130 /**
131 * @brief Returns the current state for a given state type.
132 *
133 * @tparam StateType The state enum type.
134 *
135 * @return The current state, or StateType::Undefined if not found.
136 */
137 template<typename StateType>
138 [[nodiscard]] StateType state() const noexcept {
139 auto* sc = gameObject_.get<StateComponent<StateType>>();
140
141 return sc ? sc->state() : StateType::Undefined;
142 }
143
144 /**
145 * @brief Returns the source state of the last transition.
146 *
147 * @tparam StateType The state enum type.
148 *
149 * @return The state that was transitioned from, or StateType::Undefined if not found.
150 */
151 template<typename StateType>
152 [[nodiscard]] StateType stateFrom() const noexcept {
153 auto* sc = gameObject_.get<StateComponent<StateType>>();
154
155 return sc ? sc->from() : StateType::Undefined;
156 }
157
158 /**
159 * @brief Returns the last transition ID for a given state type.
160 *
161 * @tparam StateType The state enum type.
162 *
163 * @return The transition ID, or Undefined if not found.
164 */
165 template<typename StateType>
166 [[nodiscard]] StateTransitionIdType<StateType> stateTransitionId() const noexcept {
167 auto* ms = gameObject_.get<StateComponent<StateType>>();
168
170 }
171
172 /**
173 * @brief Lets this session track the specified StateType.
174 *
175 * @tparam StateType The state enum type.
176 */
177 template<typename StateType>
178 void trackState() {
179 gameObject_.getOrAdd<StateComponent<StateType>>();
180 }
181
182 /**
183 * @brief Replaces the active viewport IDs with the provided list.
184 *
185 * @param viewportIds The new list of active viewport IDs.
186 */
187 void setViewportIds(std::span<const helios::engine::common::types::ViewportId>& viewportIds) noexcept {
189 }
190
191 /**
192 * @brief Returns the currently active viewport IDs.
193 *
194 * @return Read-only span of viewport identifiers.
195 */
196 [[nodiscard]] std::span<const helios::engine::common::types::ViewportId> viewportIds() const noexcept {
197 return gameObject_.get<ActiveViewportIdsStateComponent>()->viewportIds();
198 }
199
200 /**
201 * @brief Clears all active viewport IDs.
202 */
203 void clearViewportIds() noexcept {
204 gameObject_.get<ActiveViewportIdsStateComponent>()->clear();
205 }
206 };
207
208
209}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.