Engine
Raylib based game framework
Loading...
Searching...
No Matches
Engine Class Reference

Core engine. More...

#include <Engine.hpp>

Inheritance diagram for Engine:
Collaboration diagram for Engine:

Public Member Functions

 Engine (const WindowInfo &windowInfo)
 Creates the engine and all its subsystems.
template<typename T, typename... Args>
void SetFirstScene (Args &&... args)
 Sets the initial scene and immediately transitions to it.
void Run (const u32 targetFps, const u32 updateFrequency, const u8 maxUpdatesPerFrame=5)
 Runs the engine loop.
double GetUpdateTime () const
 Returns how long the average update loop took in milliseconds.
double GetDrawTime () const
 Returns how long the average draw loop took in milliseconds.

Static Public Member Functions

static EngineGet ()
 Returns the active engine instance.

Public Attributes

Registryregistry = m_registry
 Entity-component registry.
Dispatcher & dispatcher = m_dispatcher
 Event dispatcher.
Rendererrenderer = m_renderer
 Sprite renderer.
ResourceManagerresourceManager = m_resourceManager
 Resource cache manager.
SceneManagersceneManager = m_sceneManager
 Scene lifecycle manager.
SystemManagersystemManager = m_systemManager
 System execution manager.
LuaManagerluaManager = m_luaManager
 Lua scripting manager.
AsyncNetwork & network = m_network
 Asynchronous networking (unavailable on Emscripten).
BS::thread_pool< BS::tp::none > threadPool
 Thread pool for background tasks (unavailable on Emscripten).

Detailed Description

Core engine.

Owns and coordinates all major subsystems.

Only a single Engine instance may exist at a time. Use Engine::Get() to access the instance, or prefer the convenience macros (REGISTRY, DISPATCHER, RENDERER, etc.) which call through to it.

Constructor & Destructor Documentation

◆ Engine()

Engine::Engine ( const WindowInfo & windowInfo)

Creates the engine and all its subsystems.

Opens a raylib window, initialises the audio device, registers default resource caches (Texture2D, Image, Sound, Music, Wave, raw text and binary files), and adds the built-in systems (AnimationSystem, InputSystem, AudioSystem, ParticleSystem).

Parameters
windowInfoInitial window configuration

Member Function Documentation

◆ Get()

Engine & Engine::Get ( )
static

Returns the active engine instance.

Asserts if no Engine has been constructed. Prefer the convenience macros (REGISTRY, RENDERER, etc.) over calling this directly.

Returns
Reference to the singleton Engine

◆ Run()

void Engine::Run ( const u32 targetFps,
const u32 updateFrequency,
const u8 maxUpdatesPerFrame = 5 )

Runs the engine loop.

This is blocking until the window is closed or a CloseGame event is dispatched.

Each frame the loop:

  1. Accumulates elapsed time and runs fixed-timestep Update passes (systems → Lua → scene)
  2. Calls the Renderer update (sprite sort)
  3. Draws to the virtual canvas (renderer → systems → scene)
  4. Scales the canvas to the real window and presents it
Parameters
targetFpsTarget frames per second
updateFrequencyFixed update steps per second (must be ≤ targetFps)
maxUpdatesPerFrameMaximum catch-up steps per frame before the accumulator is reset

◆ SetFirstScene()

template<typename T, typename... Args>
void Engine::SetFirstScene ( Args &&... args)
inline

Sets the initial scene and immediately transitions to it.

The scene is constructed with the given arguments, added to the SceneManager, and made active before Run is called.

Template Parameters
TScene type (must derive from Scene)
ArgsT constructor argument types
Parameters
argsScene constructor arguments

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