Skip to main content

Session.ixx File

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

Included Headers

#include <optional> #include <vector> #include <span> #include <cassert> #include <helios.engine.rendering.viewport.components.ActiveViewportHandlesStateComponent> #include <helios.engine.rendering.viewport.types.ViewportHandle> #include <helios.ecs.types.EntityHandle> #include <helios.engine.runtime.world.GameObject> #include <helios.engine.runtime.enginestate.EngineStateBindings> #include <helios.engine.state.types.StateTransitionId> #include <helios.engine.state.components> #include <helios.engine.state.types.StateTransitionContext> #include <helios.ecs.components>

Namespaces Index

namespacehelios
namespaceengine
namespaceruntime
namespaceworld

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
5module;
6
7#include <optional>
8#include <vector>
9#include <span>
10#include <cassert>
11
12export module helios.engine.runtime.world.Session;
13
14
15import helios.ecs.components;
16
17import helios.engine.state.types.StateTransitionContext;
18import helios.engine.state.components;
19import helios.engine.state.types.StateTransitionId;
20import helios.engine.runtime.enginestate.EngineStateBindings;
21
22import helios.engine.runtime.world.GameObject;
23import helios.ecs.types.EntityHandle;
24
25import helios.engine.rendering.viewport.types.ViewportHandle;
26
27import helios.engine.rendering.viewport.components.ActiveViewportHandlesStateComponent;
28
30
32
33using namespace helios::engine::state::types;
36using namespace helios::ecs::components;
37export namespace helios::engine::runtime::world {
38
61 class Session {
62
63 using Handle_type = GameObject::Handle_type;
64
68 GameObject gameObject_;
69
73 Handle_type playerEntity_;
74
75 public:
76
85 explicit Session(const GameObject go) : gameObject_(go) {
87 gameObject_.add<Uninitialized<Handle_type>>();
88 }
89
91 return !gameObject_.has<Uninitialized<Handle_type>>();
92 }
93
95 return gameObject_.remove<Uninitialized<Handle_type>>();
96 }
97
99 return gameObject_.has<Destroyed<Handle_type>>();
100 }
101
103 gameObject_.add<Destroyed<Handle_type>>();
104 }
105
111 void setPlayerEntityHandle(const Handle_type go) noexcept {
112 playerEntity_ = go;
113 }
114
121 return playerEntity_;
122 }
123
127 void reset() {
128
129 }
130
140 template<typename StateType>
142
143 if (auto* msc = gameObject_.get<StateComponent<StateType>>()) {
144 msc->setStateFromTransitionContext(stateTransitionContext);
145 }
146 }
147
155 template<typename StateType>
156 [[nodiscard]] StateType state() const noexcept {
157 auto* sc = gameObject_.get<StateComponent<StateType>>();
158
159 return sc ? sc->state() : StateType::Undefined;
160 }
161
169 template<typename StateType>
171 auto* sc = gameObject_.get<StateComponent<StateType>>();
172
173 return sc ? sc->from() : StateType::Undefined;
174 }
175
183 template<typename StateType>
185 auto* ms = gameObject_.get<StateComponent<StateType>>();
186
188 }
189
195 template<typename StateType>
196 void trackState() {
197 gameObject_.getOrAdd<StateComponent<StateType>>();
198 }
199
205 void setViewportHandles(std::span<const ViewportHandle>& viewportHandles) noexcept {
207 }
208
214 [[nodiscard]] std::span<const ViewportHandle> viewportHandles() const noexcept {
216 }
217
225 [[nodiscard]] bool isActiveViewport(const ViewportHandle viewportHandle) const noexcept {
226 return gameObject_.get<ActiveViewportHandlesStateComponent<Handle_type>>()->has(viewportHandle);
227 }
228
233 gameObject_.get<ActiveViewportHandlesStateComponent<Handle_type>>()->clear();
234 }
235 };
236
237
238}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.