Deki 1.3.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 <DekiEngine.h>

Public Member Functions

const DekiEngineHostGetHost () const
void Shutdown ()
 Shutdown the game engine and free resources.
void Update (uint32_t deltaTime)
 Update game logic and animations (called every frame).
void ProcessLifecycle ()
 Process lifecycle methods on the active scene Handles Awake, Start, Update and detects scene changes during lifecycle.
void Render ()
 Render the current scene to internal buffer.
void PresentFrame ()
 Present the render system's framebuffer through the display.
void RequestFullRefresh ()
 Make the next present cover the whole screen (the display's own RequestFullRefresh included).
size_t RegisterUpdate (const UpdateCallback &callback)
 Register an update callback to be called each frame.
void UnregisterUpdate (size_t id)
 Remove a callback registered with RegisterUpdate.
void RunUpdateCallbacks (uint32_t deltaTime)
 Run the registered update callbacks once.
void SetRootScene (Scene *scene, bool takeOwnership=true)
 Set the current root scene.
SceneGetRootScene () const
 Get the current root scene.
SceneCreateScene ()
 Create a new empty scene.
IDekiRenderSystemGetRenderer () const
 Get the renderer instance.
SceneSystemGetSceneSystem () const
 Get the scene system instance.
LifecycleManagerGetLifecycleManager () const
 Get the lifecycle manager instance.
IDekiRenderSystemGetRenderSystem () const
 Get the render system instance.
void SetRenderSystem (IDekiRenderSystem *rs)
 Set the render system (called by rendering package during registration).
IDekiInputSystemGetInputSystem () const
 Get the input system instance.
void SetInputSystem (IDekiInputSystem *is)
 Set the input system (called by input package during registration).
IDekiDisplayGetDisplay () const
 Get the active display.
void SetDisplay (IDekiDisplay *display, const std::string &name="")
 Register the active display (called by SDL3Display, LovyanGFXDisplay, EditorDisplay, etc.
const std::string & GetDisplayName () const
 Display name set by the registering package (e.g.
bool IsDisplayInitialized () const
 True iff a display has been registered AND its IsInitialized() is true.
bool IsInitialized () const
 Check if the game engine is initialized.
void SetGameUpdateCallback (const GameUpdateCallback &callback)
 Set the game update callback for game logic updates.
void SetTargetFPS (uint32_t fps)
 Set the target FPS for the main loop.
void RunMainLoop ()
 Run the main game loop This handles timing, platform updates, rendering, and callbacks.
void StopMainLoop ()
 Stop the main game loop.
bool IsRunning () const
 Check if the main loop is running.
void MarkDirty ()
 Mark the engine as dirty (needs redraw).
bool IsDirty () const
 Check if engine needs redraw.
const uint8_t * GetFrameBuffer () const
int32_t GetScreenWidth () const
int32_t GetScreenHeight () const
DekiColorFormat GetFrameBufferFormat () const
DekiEngineSettingsGetSettings ()
 Get engine settings.
const DekiEngineSettingsGetSettings () const

Static Public Member Functions

static DekiEngineGetInstance ()
 Get the singleton instance of DekiEngine.
static bool Initialize ()
 Initialize the engine from the active project settings.
static bool Initialize (const DekiEngineHost &host)
 Initialize the engine for an explicit host configuration.
static bool IsRuntimeMode ()
 Check if the engine is in runtime mode (play mode or device).
static void SetRuntimeMode (bool runtime)
 Set runtime mode (called by editor play mode init/shutdown).

Detailed Description

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

Holds the active scene graph via SceneSystem, drives the DekiBehaviour lifecycle (PreRender, Start, Update) through LifecycleManager, and dispatches to whichever render, input and display providers a package has installed — all four are optional, so a headless or editor-hosted engine is the same class with null providers.

Member Function Documentation

◆ GetInstance()

DekiEngine & DekiEngine::GetInstance ( )
static

Get the singleton instance of DekiEngine.

Returns
Reference to the DekiEngine instance

◆ Initialize() [1/2]

bool DekiEngine::Initialize ( )
static

Initialize the engine from the active project settings.

Returns
true if initialization successful, false otherwise

Picks the host configuration for this build: DekiEngineHost::Editor() in editor builds, DekiEngineHost::Device() otherwise.

◆ Initialize() [2/2]

bool DekiEngine::Initialize ( const DekiEngineHost & host)
static

Initialize the engine for an explicit host configuration.

◆ GetHost()

const DekiEngineHost & DekiEngine::GetHost ( ) const
inline

◆ Shutdown()

void DekiEngine::Shutdown ( )

Shutdown the game engine and free resources.

◆ Update()

void DekiEngine::Update ( uint32_t deltaTime)

Update game logic and animations (called every frame).

Parameters
deltaTimeTime since last update in milliseconds

◆ ProcessLifecycle()

void DekiEngine::ProcessLifecycle ( )

Process lifecycle methods on the active scene Handles Awake, Start, Update and detects scene changes during lifecycle.

◆ Render()

void DekiEngine::Render ( )

Render the current scene to internal buffer.

◆ PresentFrame()

void DekiEngine::PresentFrame ( )

Present the render system's framebuffer through the display.

Only the rectangles the render system reports as changed are pushed when the display can present partial frames (IDekiRenderSystem:: GetPresentRects + IDekiDisplay::PresentRegions); otherwise the whole frame. Every present in the engine goes through here.

◆ RequestFullRefresh()

void DekiEngine::RequestFullRefresh ( )

Make the next present cover the whole screen (the display's own RequestFullRefresh included).

◆ RegisterUpdate()

size_t DekiEngine::RegisterUpdate ( const UpdateCallback & callback)

Register an update callback to be called each frame.

Parameters
callbackFunction to call during update
Returns
ID of the registered callback (can be used to unregister)

◆ UnregisterUpdate()

void DekiEngine::UnregisterUpdate ( size_t id)

Remove a callback registered with RegisterUpdate.

Parameters
idThe value RegisterUpdate returned

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 DekiEngine::RunUpdateCallbacks ( uint32_t deltaTime)

Run the registered update callbacks once.

Parameters
deltaTimeMilliseconds 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 exactly as they do on a device.

◆ SetRootScene()

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

Set the current root scene.

Parameters
scenePointer to the scene to set as root
takeOwnershipIf true, engine will delete the scene when replaced or on shutdown

◆ GetRootScene()

Scene * DekiEngine::GetRootScene ( ) const

Get the current root scene.

Returns
Pointer to the current root scene, or nullptr if none set

◆ CreateScene()

Scene * DekiEngine::CreateScene ( )

Create a new empty scene.

Returns
Pointer to the created scene

◆ GetRenderer()

IDekiRenderSystem & DekiEngine::GetRenderer ( ) const
inline

Get the renderer instance.

Returns
The installed render system, or nullptr when headless

◆ GetSceneSystem()

SceneSystem & DekiEngine::GetSceneSystem ( ) const
inline

Get the scene system instance.

Returns
Reference to the SceneSystem instance

◆ GetLifecycleManager()

LifecycleManager * DekiEngine::GetLifecycleManager ( ) const
inline

Get the lifecycle manager instance.

Returns
Pointer to the LifecycleManager instance

◆ GetRenderSystem()

IDekiRenderSystem * DekiEngine::GetRenderSystem ( ) const
inline

Get the render system instance.

Returns
Pointer to the DekiRenderSystem instance (nullptr if no rendering package)

◆ SetRenderSystem()

void DekiEngine::SetRenderSystem ( IDekiRenderSystem * rs)
inline

Set the render system (called by rendering package during registration).

Parameters
rsPointer to the render system (package owns lifetime)

◆ GetInputSystem()

IDekiInputSystem * DekiEngine::GetInputSystem ( ) const
inline

Get the input system instance.

Returns
Pointer to the IDekiInputSystem instance (nullptr if no input package)

◆ SetInputSystem()

void DekiEngine::SetInputSystem ( IDekiInputSystem * is)
inline

Set the input system (called by input package during registration).

Parameters
isPointer to the input system (package owns lifetime)

◆ GetDisplay()

IDekiDisplay * DekiEngine::GetDisplay ( ) const
inline

Get the active display.

Set at runtime by a display integration package via SetDisplay(). nullptr if no display package is loaded.

◆ SetDisplay()

void DekiEngine::SetDisplay ( IDekiDisplay * display,
const std::string & name = "" )

Register the active display (called by SDL3Display, LovyanGFXDisplay, EditorDisplay, etc.

at package load).

The package owns the display instance's lifetime. Engine-core only stores the pointer + a name (for diagnostics) and re-runs the render system's Setup() so it can pick up a display-owned DMA buffer if available.

◆ GetDisplayName()

const std::string & DekiEngine::GetDisplayName ( ) const
inline

Display name set by the registering package (e.g.

"SDL3").

◆ IsDisplayInitialized()

bool DekiEngine::IsDisplayInitialized ( ) const
inline

True iff a display has been registered AND its IsInitialized() is true.

◆ IsInitialized()

bool DekiEngine::IsInitialized ( ) const
inline

Check if the game engine is initialized.

Returns
true if initialized, false otherwise

◆ IsRuntimeMode()

bool DekiEngine::IsRuntimeMode ( )
static

Check if the engine is in runtime mode (play mode or device).

In runtime mode, components follow the device code path: no editor GUID sync, no font preview, no on-demand baking. On device (!DEKI_EDITOR), always returns true. In editor, returns true only during play mode.

◆ SetRuntimeMode()

void DekiEngine::SetRuntimeMode ( bool runtime)
static

Set runtime mode (called by editor play mode init/shutdown).

◆ SetGameUpdateCallback()

void DekiEngine::SetGameUpdateCallback ( const GameUpdateCallback & callback)

Set the game update callback for game logic updates.

Parameters
callbackFunction to call for game logic updates

◆ SetTargetFPS()

void DekiEngine::SetTargetFPS ( uint32_t fps)

Set the target FPS for the main loop.

Parameters
fpsTarget frames per second (default: 30)

◆ RunMainLoop()

void DekiEngine::RunMainLoop ( )

Run the main game loop This handles timing, platform updates, rendering, and callbacks.

◆ StopMainLoop()

void DekiEngine::StopMainLoop ( )

Stop the main game loop.

◆ IsRunning()

bool DekiEngine::IsRunning ( ) const
inline

Check if the main loop is running.

Returns
true if running, false otherwise

◆ MarkDirty()

void DekiEngine::MarkDirty ( )
inline

Mark the engine as dirty (needs redraw).

◆ IsDirty()

bool DekiEngine::IsDirty ( ) const
inline

Check if engine needs redraw.

Returns
true if dirty, false otherwise

◆ GetFrameBuffer()

const uint8_t * DekiEngine::GetFrameBuffer ( ) const

◆ GetScreenWidth()

int32_t DekiEngine::GetScreenWidth ( ) const

◆ GetScreenHeight()

int32_t DekiEngine::GetScreenHeight ( ) const

◆ GetFrameBufferFormat()

DekiColorFormat DekiEngine::GetFrameBufferFormat ( ) const

◆ GetSettings() [1/2]

DekiEngineSettings & DekiEngine::GetSettings ( )
inline

Get engine settings.

Returns
Reference to the engine settings

◆ GetSettings() [2/2]

const DekiEngineSettings & DekiEngine::GetSettings ( ) const
inline

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