Skip to main content

GameLoop Class

Central orchestrator for the game update cycle. More...

Declaration

class helios::engine::runtime::gameloop::GameLoop { ... }

Base class

classPassCommitListener

Interface for receiving notifications when a pass reaches its commit point. More...

Public Constructors Index

GameLoop (GameWorld &gameWorld)

Constructs a GameLoop bound to a GameWorld. More...

Public Member Functions Index

helios::engine::runtime::gameloop::Phase &phase (const helios::engine::runtime::gameloop::PhaseType phaseType) noexcept

Returns a reference to the specified phase. More...

voidinit (GameWorld &gameWorld)

Initializes the GameLoop and all registered phases and passes. More...

GameWorld &gameWorld () noexcept
voidupdate (GameWorld &gameWorld, float deltaTime, const helios::engine::input::InputSnapshot &inputSnapshot) noexcept

Executes one full frame update across all phases. More...

boolisRunning (GameWorld &gameWorld) const noexcept

Protected Member Functions Index

voidonPassCommit (const CommitPoint commitPoint, GameWorld &gameWorld, UpdateContext &updateContext) noexcept

Commits pass-level state based on the specified CommitPoint flags. More...

voidphaseCommit (GameWorld &gameWorld, UpdateContext &updateContext)

Commits phase-level events and flushes commands and managers. More...

Protected Member Attributes Index

GameWorld &gameWorld_
helios::engine::runtime::gameloop::PhaseprePhase_

The pre-update phase, executed before main gameplay logic. More...

helios::engine::runtime::gameloop::PhasemainPhase_

The main update phase for core gameplay systems. More...

helios::engine::runtime::gameloop::PhasepostPhase_

The post-update phase for cleanup and synchronization. More...

helios::engine::runtime::messaging::event::GameLoopEventBusphaseEventBus_ {}

Event bus for phase-level event propagation. More...

helios::engine::runtime::messaging::event::GameLoopEventBuspassEventBus_ {}

Event bus for pass-level event propagation. More...

helios::engine::runtime::messaging::event::GameLoopEventBusframeEventBus_ {}

Event bus for frame-level event propagation. More...

floattotalTime_ = 0.0f

Accumulated total time since the first frame, in seconds. More...

Private Member Attributes Index

boolinitialized_ = false

Flag indicating whether init() has been called. More...

Protected Static Attributes Index

static const helios::engine::util::log::Logger &logger_ = ...

The logger used with this GameLoop instance. More...

Description

Central orchestrator for the game update cycle.

The GameLoop manages the execution of game systems across three distinct phases: Pre, Main, and Post. Each phase can contain multiple passes, and each pass can have a configurable commit point for fine-grained synchronization control.

Definition at line 88 of file GameLoop.ixx.

Public Constructors

GameLoop()

helios::engine::runtime::gameloop::GameLoop::GameLoop (GameWorld & gameWorld)
inline

Constructs a GameLoop bound to a GameWorld.

Initializes all phases with the same GameWorld reference so passes can resolve world-owned resources (for example command buffers) during system registration.

Parameters
gameWorld

The GameWorld associated with this GameLoop.

Definition at line 264 of file GameLoop.ixx.

Public Member Functions

gameWorld()

GameWorld & helios::engine::runtime::gameloop::GameLoop::gameWorld ()
inline noexcept

Definition at line 327 of file GameLoop.ixx.

328 return gameWorld_;
329 }

Reference gameWorld_.

Referenced by init, isRunning, onPassCommit, phaseCommit and update.

init()

void helios::engine::runtime::gameloop::GameLoop::init (GameWorld & gameWorld)
inline

Initializes the GameLoop and all registered phases and passes.

Iterates through all phases (Pre, Main, Post) and calls their init() methods, which in turn initialize all registered passes and systems. Systems receive a reference to the GameWorld for component queries and entity access.

Must be called exactly once before the first update() call.

Parameters
gameWorld

Reference to the game world to initialize with.

Precondition

Must not have been called before (asserts on multiple calls).

See Also

Phase::init()

See Also

Pass::init()

See Also

System::init()

Definition at line 311 of file GameLoop.ixx.

312
313 assert(!initialized_ && "init() already called");
314
315 prePhase_.init(gameWorld);
317
320
323
324 initialized_ = true;
325 }

References helios::engine::runtime::gameloop::Phase::addPassCommitListener, gameWorld, mainPhase_, postPhase_, prePhase_ and helios::engine::runtime::registerComponents.

isRunning()

bool helios::engine::runtime::gameloop::GameLoop::isRunning (GameWorld & gameWorld)
inline noexcept

phase()

helios::engine::runtime::gameloop::Phase & helios::engine::runtime::gameloop::GameLoop::phase (const helios::engine::runtime::gameloop::PhaseType phaseType)
inline noexcept

Returns a reference to the specified phase.

Parameters
phaseType

The type of phase to retrieve (Pre, Main, or Post).

Returns

Reference to the requested Phase.

Definition at line 274 of file GameLoop.ixx.

275
276 switch (phaseType) {
278 return prePhase_;
279 break;
281 return mainPhase_;
282 break;
284 return postPhase_;
285 break;
286 }
287
288 std::unreachable();
289
290 }

References helios::engine::runtime::gameloop::Main, mainPhase_, helios::engine::runtime::gameloop::Post, postPhase_, helios::engine::runtime::gameloop::Pre, prePhase_ and helios::engine::runtime::registerComponents.

update()

void helios::engine::runtime::gameloop::GameLoop::update (GameWorld & gameWorld, float deltaTime, const helios::engine::input::InputSnapshot & inputSnapshot)
inline noexcept

Executes one full frame update across all phases.

Iterates through Pre, Main, and Post phases, updating all registered systems and committing events and commands after each phase. The frame lifecycle:

  1. Pre Phase: Input processing, command generation, preparation
  2. Main Phase: Core gameplay logic, physics, collision detection
  3. Post Phase: Cleanup, synchronization, rendering preparation

After each phase, phaseCommit() is called to:

  • Swap phase event buffers (events become readable in next phase)
  • Clear pass event buffers
  • Flush command buffer
  • Flush managers

After the Post phase, the frame event bus is swapped, making frame-level events readable in the next frame.

Parameters
gameWorld

Reference to the game world.

deltaTime

Time elapsed since the last frame in seconds.

inputSnapshot

Snapshot of the current input state.

viewportSnapshots

Snapshots of viewports registered with an id.

Precondition

init() must have been called before the first update.

See Also

Phase

See Also

phaseCommit()

See Also

UpdateContext

Definition at line 361 of file GameLoop.ixx.

361 void update(
363 float deltaTime,
364 const helios::engine::input::InputSnapshot& inputSnapshot
365 ) noexcept {
366
367 assert(initialized_ && "GameLoop not initialized");
368
369 totalTime_ += deltaTime;
370
374 deltaTime,
379 inputSnapshot,
382 );
383
384 auto& session = gameWorld.session();
385
386 // gameloop phases
389
392
396 }

References helios::engine::runtime::world::GameWorld::engineWorld, frameEventBus_, gameWorld, helios::engine::runtime::world::GameWorld::level, mainPhase_, passEventBus_, phaseCommit, phaseEventBus_, postPhase_, prePhase_, helios::engine::runtime::registerComponents, helios::engine::runtime::world::GameWorld::runtimeEnvironment, helios::engine::runtime::world::GameWorld::session, helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::swapBuffers and totalTime_.

Protected Member Functions

onPassCommit()

void helios::engine::runtime::gameloop::GameLoop::onPassCommit (const CommitPoint commitPoint, GameWorld & gameWorld, UpdateContext & updateContext)
inline noexcept protected virtual

Commits pass-level state based on the specified CommitPoint flags.

Called after each pass that has a commit point configured. The CommitPoint flags determine which synchronization actions are performed:

  • PassEvents: Swaps pass event bus buffers, making events pushed via UpdateContext::pushPass() readable in subsequent passes.
  • FlushCommands: Executes pending commands from the CommandBuffer.
  • FlushManagers: Processes manager requests (e.g., spawning from pools).

The order is: FlushCommands → FlushManagers → PassEvents. Commands must be flushed before managers to ensure spawn requests are generated before being processed.

Parameters
commitPoint

The flags specifying which actions to perform.

gameWorld

The game world where the commit occured.

updateContext

The current update context.

See Also

CommitPoint

See Also

Pass::addCommitPoint()

See Also

UpdateContext::pushPass()

See Also

UpdateContext::readPass()

Definition at line 198 of file GameLoop.ixx.

199 const CommitPoint commitPoint,
201 UpdateContext& updateContext) noexcept {
202
203 // commands must be executed before Managers
206 }
207
210 }
211
212 // managers might create pass events
213 if ((commitPoint & CommitPoint::PassEvents) == CommitPoint::PassEvents) {
215 }
216
217 }

References helios::engine::runtime::world::GameWorld::flushCommandBuffers, helios::engine::runtime::gameloop::FlushCommands, helios::engine::runtime::gameloop::FlushManagers, helios::engine::runtime::world::GameWorld::flushManagers, gameWorld, passEventBus_, helios::engine::runtime::gameloop::PassEvents, helios::engine::runtime::registerComponents and helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::swapBuffers.

phaseCommit()

void helios::engine::runtime::gameloop::GameLoop::phaseCommit (GameWorld & gameWorld, UpdateContext & updateContext)
inline protected

Commits phase-level events and flushes commands and managers.

Called after each phase completes. This method:

  1. Clears pass event buffers for the new phase.
  2. Flushes the command buffer, executing deferred commands.
  3. Flushes managers, allowing to process any request generated by the commands.
  4. Swaps phase event bus buffers, making events readable in the next phase.
Parameters
gameWorld

Reference to the game world.

updateContext

The current update context.

See Also

UpdateContext::pushPhase()

See Also

UpdateContext::readPhase()

Definition at line 235 of file GameLoop.ixx.

238
240
241 // command buffers generate requests for managers, so this comes first
243
244 // managers process requests
246
247 // make sure flushed managers make their events available to the phase event bus
249 }

References helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::clearAll, helios::engine::runtime::world::GameWorld::flushCommandBuffers, helios::engine::runtime::world::GameWorld::flushManagers, gameWorld, passEventBus_, phaseEventBus_, helios::engine::runtime::registerComponents and helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::swapBuffers.

Referenced by update.

Protected Member Attributes

frameEventBus_

helios::engine::runtime::messaging::event::GameLoopEventBus helios::engine::runtime::gameloop::GameLoop::frameEventBus_ {}
protected

Event bus for frame-level event propagation.

Events pushed via UpdateContext::pushFrame() are buffered here and become readable in the next frame via UpdateContext::readFrame(). The buffer swap occurs at the end of the Post phase.

Frame-level events persist across all phases within a frame and are useful for cross-frame communication (e.g., collision events that should be processed in the next frame).

See Also

UpdateContext::pushFrame()

See Also

UpdateContext::readFrame()

Definition at line 165 of file GameLoop.ixx.

Referenced by update.

gameWorld_

GameWorld& helios::engine::runtime::gameloop::GameLoop::gameWorld_
protected

Definition at line 107 of file GameLoop.ixx.

Referenced by gameWorld.

mainPhase_

helios::engine::runtime::gameloop::Phase helios::engine::runtime::gameloop::GameLoop::mainPhase_
protected

The main update phase for core gameplay systems.

Definition at line 118 of file GameLoop.ixx.

Referenced by init, phase and update.

passEventBus_

helios::engine::runtime::messaging::event::GameLoopEventBus helios::engine::runtime::gameloop::GameLoop::passEventBus_ {}
protected

Event bus for pass-level event propagation.

Events pushed via UpdateContext::pushPass() are buffered here and become readable in subsequent passes via UpdateContext::readPass(). The buffer swap occurs when a pass has a commit point.

See Also

UpdateContext::pushPass()

See Also

UpdateContext::readPass()

See Also

Pass::addCommitPoint()

Definition at line 149 of file GameLoop.ixx.

Referenced by onPassCommit, phaseCommit and update.

phaseEventBus_

helios::engine::runtime::messaging::event::GameLoopEventBus helios::engine::runtime::gameloop::GameLoop::phaseEventBus_ {}
protected

Event bus for phase-level event propagation.

Events pushed via UpdateContext::pushPhase() are buffered here and become readable in the next phase via UpdateContext::readPhase(). The buffer swap occurs in phaseCommit().

See Also

UpdateContext::pushPhase()

See Also

UpdateContext::readPhase()

Definition at line 136 of file GameLoop.ixx.

Referenced by phaseCommit and update.

postPhase_

helios::engine::runtime::gameloop::Phase helios::engine::runtime::gameloop::GameLoop::postPhase_
protected

The post-update phase for cleanup and synchronization.

Definition at line 123 of file GameLoop.ixx.

Referenced by init, phase and update.

prePhase_

helios::engine::runtime::gameloop::Phase helios::engine::runtime::gameloop::GameLoop::prePhase_
protected

The pre-update phase, executed before main gameplay logic.

Definition at line 113 of file GameLoop.ixx.

Referenced by init, phase and update.

totalTime_

float helios::engine::runtime::gameloop::GameLoop::totalTime_ = 0.0f
protected

Accumulated total time since the first frame, in seconds.

Definition at line 170 of file GameLoop.ixx.

170 float totalTime_ = 0.0f;

Referenced by update.

Private Member Attributes

initialized_

bool helios::engine::runtime::gameloop::GameLoop::initialized_ = false

Flag indicating whether init() has been called.

Used to assert that init() is called exactly once before the first update() and to prevent multiple initializations.

Definition at line 97 of file GameLoop.ixx.

97 bool initialized_ = false;

Protected Static Attributes

logger_

const helios::engine::util::log::Logger& helios::engine::runtime::gameloop::GameLoop::logger_
protected static

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.