DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches

Engine singleton: owns the scene system, lifecycle and frame loop. More...

#include <deki/Engine.h>

Classes

struct  FrameTimings
 How long the parts of a frame took, in milliseconds of the engine's clock: update (input, lifecycle, update callbacks), render and present. More...

Public Member Functions

const EngineHost & GetHost () const
void Shutdown ()
 Shuts the engine down and frees its resources.
void Update (uint32_t deltaTime)
 Runs one frame. deltaTime is milliseconds since the last call.
void ProcessLifecycle ()
 Runs Awake, Start and Update on the active scene, and handles a scene change made during them.
void Render ()
 Renders the current scene into the render system's framebuffer.
void PresentFrame ()
 Sends the render system's framebuffer to the display.
void RequestFullRefresh ()
 Makes the next present cover the whole screen, including the display's own RequestFullRefresh.
size_t RegisterUpdate (const UpdateCallback &callback)
 Calls callback every frame. Returns an id for UnregisterUpdate.
void UnregisterUpdate (size_t id)
 Removes the callback that RegisterUpdate returned id for.
void RunUpdateCallbacks (uint32_t deltaTime)
 Runs the registered update callbacks once.
void SetRootScene (Scene *scene, bool takeOwnership=true)
 Makes scene the root scene.
Scene * GetRootScene () const
 The root scene, or nullptr when none is set.
Scene * CreateScene ()
 Creates an empty scene.
IRenderSystem & GetRenderer () const
 The installed render system.
SceneSystem & GetSceneSystem () const
LifecycleManager * GetLifecycleManager () const
IRenderSystem * GetRenderSystem () const
 The render system, or nullptr when no rendering package is loaded.
void SetRenderSystem (IRenderSystem *rs)
 Called by a rendering package when it registers. The package owns rs.
IInputSystem * GetInputSystem () const
 The input system, or nullptr when no input package is loaded.
void SetInputSystem (IInputSystem *is)
 Called by an input package when it registers. The package owns is.
IDisplay * GetDisplay () const
 The active display, set by a display package through SetDisplay(), or nullptr when none is loaded.
void SetDisplay (IDisplay *display, const std::string &name="")
 Registers the active display; SDL3Display, LovyanGFXDisplay, EditorDisplay and the like call it when their package loads.
const std::string & GetDisplayName () const
 Display name set by the registering package, such as "SDL3".
bool IsDisplayInitialized () const
 True when a display is registered and its IsInitialized() is true.
bool IsInitialized () const
void SetGameUpdateCallback (const GameUpdateCallback &callback)
 Sets the callback that runs game logic each frame.
void SetTargetFPS (uint32_t fps)
 Frame rate the main loop aims for. The default is 30.
void RunMainLoop ()
 Runs the main loop (timing, platform updates, rendering, callbacks) until StopMainLoop().
void StopMainLoop ()
bool IsRunning () const
void MarkDirty ()
 Asks for a redraw.
bool IsDirty () const
 True when a redraw is needed.
FrameTimings GetLastFrameTimings () const
 How long the parts of the last frame took: see FrameTimings.
const uint8_t * GetFrameBuffer () const
int32_t GetScreenWidth () const
int32_t GetScreenHeight () const
ColorFormat GetFrameBufferFormat () const
EngineSettings & GetSettings ()
const EngineSettings & GetSettings () const

Static Public Member Functions

static Engine & GetInstance ()
static bool Initialize ()
 Starts the engine from the active project settings, with EngineHost::Editor() in editor builds and EngineHost::Device() otherwise.
static bool Initialize (const EngineHost &host)
 Starts the engine with the given host configuration.
static bool IsRuntimeMode ()
 True on a device, and in the editor during play mode.
static void SetRuntimeMode (bool runtime)
 Called by the editor's play mode when it starts and stops.

Detailed Description

Engine singleton: owns the scene system, lifecycle and frame loop.

Holds the active scene graph through SceneSystem, drives the component lifecycle (Awake, Start, Update) through LifecycleManager, and calls whichever render, input and display providers packages have installed. The providers are optional, so a headless or editor-hosted engine is the same class with null providers.

Member Function Documentation

◆ GetInstance()

Engine & Deki::Engine::GetInstance ( )
static

◆ Initialize() [1/2]

bool Deki::Engine::Initialize ( )
static

Starts the engine from the active project settings, with EngineHost::Editor() in editor builds and EngineHost::Device() otherwise.

Returns false on failure.

◆ Initialize() [2/2]

bool Deki::Engine::Initialize ( const EngineHost & host)
static

Starts the engine with the given host configuration.

◆ GetHost()

const EngineHost & Deki::Engine::GetHost ( ) const
inline

◆ Shutdown()

void Deki::Engine::Shutdown ( )

Shuts the engine down and frees its resources.

◆ Update()

void Deki::Engine::Update ( uint32_t deltaTime)

Runs one frame. deltaTime is milliseconds since the last call.

◆ ProcessLifecycle()

void Deki::Engine::ProcessLifecycle ( )

Runs Awake, Start and Update on the active scene, and handles a scene change made during them.

◆ Render()

void Deki::Engine::Render ( )

Renders the current scene into the render system's framebuffer.

◆ PresentFrame()

void Deki::Engine::PresentFrame ( )

Sends the render system's framebuffer to the display.

When the display can present partial frames, only the changed rectangles are sent (IRenderSystem::GetPresentRects + IDisplay::PresentRegions); otherwise the whole frame. Every present in the engine goes through here.

◆ RequestFullRefresh()

void Deki::Engine::RequestFullRefresh ( )

Makes the next present cover the whole screen, including the display's own RequestFullRefresh.

◆ RegisterUpdate()

size_t Deki::Engine::RegisterUpdate ( const UpdateCallback & callback)

Calls callback every frame. Returns an id for UnregisterUpdate.

◆ UnregisterUpdate()

void Deki::Engine::UnregisterUpdate ( size_t id)

Removes the callback that RegisterUpdate returned id for.

A package DLL that registers a callback must unregister it before it unloads, or the engine calls into unmapped code on the next frame.

◆ RunUpdateCallbacks()

void Deki::Engine::RunUpdateCallbacks ( uint32_t deltaTime)

Runs the registered update callbacks once.

deltaTime is milliseconds since the previous call. Update() does this itself; hosts that drive the lifecycle by hand (the editor's play mode) call it so package systems (tweens, ...) tick there as they do on a device.

◆ SetRootScene()

void Deki::Engine::SetRootScene ( Scene * scene,
bool takeOwnership = true )

Makes scene the root scene.

With takeOwnership, the engine deletes it when it is replaced or on shutdown.

◆ GetRootScene()

Scene * Deki::Engine::GetRootScene ( ) const

The root scene, or nullptr when none is set.

◆ CreateScene()

Scene * Deki::Engine::CreateScene ( )

Creates an empty scene.

◆ GetRenderer()

IRenderSystem & Deki::Engine::GetRenderer ( ) const
inline

The installed render system.

Call it only when one is installed (see GetRenderSystem).

◆ GetSceneSystem()

SceneSystem & Deki::Engine::GetSceneSystem ( ) const
inline

◆ GetLifecycleManager()

LifecycleManager * Deki::Engine::GetLifecycleManager ( ) const
inline

◆ GetRenderSystem()

IRenderSystem * Deki::Engine::GetRenderSystem ( ) const
inline

The render system, or nullptr when no rendering package is loaded.

◆ SetRenderSystem()

void Deki::Engine::SetRenderSystem ( IRenderSystem * rs)
inline

Called by a rendering package when it registers. The package owns rs.

◆ GetInputSystem()

IInputSystem * Deki::Engine::GetInputSystem ( ) const
inline

The input system, or nullptr when no input package is loaded.

◆ SetInputSystem()

void Deki::Engine::SetInputSystem ( IInputSystem * is)
inline

Called by an input package when it registers. The package owns is.

◆ GetDisplay()

IDisplay * Deki::Engine::GetDisplay ( ) const
inline

The active display, set by a display package through SetDisplay(), or nullptr when none is loaded.

◆ SetDisplay()

void Deki::Engine::SetDisplay ( IDisplay * display,
const std::string & name = "" )

Registers the active display; SDL3Display, LovyanGFXDisplay, EditorDisplay and the like call it when their package loads.

The package owns the display. The engine keeps the pointer and a name for diagnostics, and sizes the framebuffer to the display, so every target renders at its own native resolution.

◆ GetDisplayName()

const std::string & Deki::Engine::GetDisplayName ( ) const
inline

Display name set by the registering package, such as "SDL3".

◆ IsDisplayInitialized()

bool Deki::Engine::IsDisplayInitialized ( ) const
inline

True when a display is registered and its IsInitialized() is true.

◆ IsInitialized()

bool Deki::Engine::IsInitialized ( ) const
inline

◆ IsRuntimeMode()

bool Deki::Engine::IsRuntimeMode ( )
static

True on a device, and in the editor during play mode.

In runtime mode components follow the device code path: no editor GUID sync, no font preview, no on-demand baking.

◆ SetRuntimeMode()

void Deki::Engine::SetRuntimeMode ( bool runtime)
static

Called by the editor's play mode when it starts and stops.

◆ SetGameUpdateCallback()

void Deki::Engine::SetGameUpdateCallback ( const GameUpdateCallback & callback)

Sets the callback that runs game logic each frame.

◆ SetTargetFPS()

void Deki::Engine::SetTargetFPS ( uint32_t fps)

Frame rate the main loop aims for. The default is 30.

◆ RunMainLoop()

void Deki::Engine::RunMainLoop ( )

Runs the main loop (timing, platform updates, rendering, callbacks) until StopMainLoop().

◆ StopMainLoop()

void Deki::Engine::StopMainLoop ( )

◆ IsRunning()

bool Deki::Engine::IsRunning ( ) const
inline

◆ MarkDirty()

void Deki::Engine::MarkDirty ( )
inline

Asks for a redraw.

◆ IsDirty()

bool Deki::Engine::IsDirty ( ) const
inline

True when a redraw is needed.

◆ GetLastFrameTimings()

FrameTimings Deki::Engine::GetLastFrameTimings ( ) const
inline

How long the parts of the last frame took: see FrameTimings.

◆ GetFrameBuffer()

const uint8_t * Deki::Engine::GetFrameBuffer ( ) const

◆ GetScreenWidth()

int32_t Deki::Engine::GetScreenWidth ( ) const

◆ GetScreenHeight()

int32_t Deki::Engine::GetScreenHeight ( ) const

◆ GetFrameBufferFormat()

ColorFormat Deki::Engine::GetFrameBufferFormat ( ) const

◆ GetSettings() [1/2]

EngineSettings & Deki::Engine::GetSettings ( )
inline

◆ GetSettings() [2/2]

const EngineSettings & Deki::Engine::GetSettings ( ) const
inline

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