R-Type 0.1
Loading...
Searching...
No Matches
rtk::GameEngine Class Reference

Owns the ECS world and runs the main loop of a game. More...

#include <GameEngine.hpp>

Public Types

using Clock = std::chrono::steady_clock
 Monotonic clock used to measure frame times.
 

Public Member Functions

ecs::Registry & registry ()
 Returns the entity and component registry.
 
ecs::Scheduler & scheduler ()
 Returns the system scheduler.
 
busEvent & eventBus ()
 Returns the event bus shared by the systems.
 
void stop ()
 Asks the main loop to exit after the current frame.
 
void setFPS (uint32_t fps)
 Sets the frame rate cap.
 
template<Game TGame>
int run (TGame &game)
 Loads the game and runs frames until it stops.
 

Detailed Description

Owns the ECS world and runs the main loop of a game.

Member Function Documentation

◆ registry()

ecs::Registry & rtk::GameEngine::registry ( )
inline

Returns the entity and component registry.

Returns
The registry.

◆ scheduler()

ecs::Scheduler & rtk::GameEngine::scheduler ( )
inline

Returns the system scheduler.

Returns
The scheduler.

◆ eventBus()

busEvent & rtk::GameEngine::eventBus ( )
inline

Returns the event bus shared by the systems.

Returns
The event bus.

◆ setFPS()

void rtk::GameEngine::setFPS ( uint32_t fps)
inline

Sets the frame rate cap.

Parameters
fpsFrames per second, 0 for no cap.

◆ run()

template<Game TGame>
int rtk::GameEngine::run ( TGame & game)
inline

Loads the game and runs frames until it stops.

Each frame calls onUpdate on the game, runs every system with the elapsed time clamped to 0.25 s, flushes the registry and then sleeps to respect the frame rate cap.

Template Parameters
TGameType satisfying the rtk::Game concept.
Parameters
gameGame to run.
Returns
0 when the loop ends normally.