Skip to main content

Phase.ixx File

Represents a phase within the game loop containing multiple passes. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine
namespaceruntime
namespacegameloop

Classes Index

classPhase

Represents a phase in the game loop containing multiple passes. More...

Description

Represents a phase within the game loop containing multiple passes.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <memory>
8#include <vector>
9
10export module helios.engine.runtime.gameloop:Phase;
11
12import :PassCommitListener;
13import :Pass;
14import :TypedPass;
15import :CommitPoint;
16
17import helios.engine.runtime.world.UpdateContext;
18import helios.engine.runtime.world.GameWorld;
19
20import helios.engine.runtime.world.Session;
21
22
23import helios.engine.runtime.enginestate.types;
24
27
29 class GameLoop;
30
31
40 enum class PhaseType {
44 Pre,
45
49 Main,
50
54 Post
55 };
56
74 class Phase {
75
77
89 std::vector<PassCommitListener*> passCommitListeners_;
90
91
92
98 void init(GameWorld& gameWorld){
99 for (auto& pass : passEntries_) {
100 // every pass contains systems that are updated here
101 pass->init(gameWorld);
102 }
103 };
104
123 void update(GameWorld& gameWorld, UpdateContext& updateContext){
124
125 for (auto& pass : passEntries_) {
126
127 if (pass->shouldRun(updateContext)) {
128 pass->update(updateContext);
129 notifyPassCommitListeners(pass->commitPoint(), gameWorld, updateContext);
130 }
131
132 }
133 };
134
152 bool notifyPassCommitListeners(CommitPoint commitPoint, GameWorld& gameWorld, UpdateContext& updateContext) {
153
154 for (const auto& passCommitListener : passCommitListeners_) {
155 passCommitListener->onPassCommit(commitPoint, gameWorld, updateContext);
156 }
157 return true;
158 }
159
163 std::vector<std::unique_ptr<Pass>> passEntries_;
164
169
171
172 public:
173
180 explicit Phase(helios::engine::runtime::gameloop::GameLoop& gameloop, GameWorld& gameWorld) : gameloop_(gameloop), gameWorld_(gameWorld) {
181
182 }
183
184
204
205 for (int i = 0; i < passCommitListeners_.size(); i++) {
206 if (passCommitListeners_[i] == passCommitListener) {
207 return false;
208 }
209 }
210
211 passCommitListeners_.emplace_back(passCommitListener);
212
213 return true;
214 }
215
233 template<typename StateType>
234 Pass& addPass(const StateType t) {
235 auto entry = std::make_unique<TypedPass<StateType>>(*this, t, gameWorld_);
236 auto* raw = entry.get();
237 passEntries_.emplace_back(std::move(entry));
238
239 return *raw;
240 }
241
248 return gameloop_;
249 }
250
251
252 };
253
254}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.