DEKI/ENGINE docs
manual api reference
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
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

Scene * CreateScene ()
 Creates an empty scene.
IDisplay * GetDisplay () const
 The active display, set by a display package through SetDisplay(), or nullptr when none is loaded.
const std::string & GetDisplayName () const
 Display name set by the registering package, such as "SDL3".
const uint8_t * GetFrameBuffer () const
ColorFormat GetFrameBufferFormat () const
const EngineHost & GetHost () const
IInputSystem * GetInputSystem () const
 The input system, or nullptr when no input package is loaded.
FrameTimings GetLastFrameTimings () const
 How long the parts of the last frame took: see FrameTimings.
LifecycleManager * GetLifecycleManager () const
IRenderSystem & GetRenderer () const
 The installed render system.
IRenderSystem * GetRenderSystem () const
 The render system, or nullptr when no rendering package is loaded.
Scene * GetRootScene () const
 The root scene, or nullptr when none is set.
SceneSystem & GetSceneSystem () const
float GetScreenDiagonalInches () const
 The screen's diagonal in inches, 0 when unknown.
int32_t GetScreenHeight () const
float GetScreenHeightMeters () const
float GetScreenPixelsPerInch () const
 Pixels per inch of the screen at its current size, 0 when its diagonal or size is unknown.
int32_t GetScreenWidth () const
float GetScreenWidthMeters () const
 The screen's size on the glass in meters, 0 when unknown.
EngineSettings & GetSettings ()
const EngineSettings & GetSettings () const
bool IsDirty () const
 True when a redraw is needed.
bool IsDisplayInitialized () const
 True when a display is registered and its IsInitialized() is true.
bool IsInitialized () const
bool IsRunning () const
void MarkDirty ()
 Asks for a redraw.
void OpenRequestedScene ()
 Carries out an OpenScene request, if there is one.
void OpenScene (const AssetRefBase &scene)
 Opens the scene scene refers to (an AssetRef<Scene>) once this frame's updates are done: the scene being left is freed first, then the new one is loaded and started before it is drawn.
void OpenScene (const std::string &guid)
 Opens the scene asset guid, as OpenScene above.
void PresentFrame ()
 Sends the render system's framebuffer to the display.
void ProcessLifecycle ()
 Runs Awake, Start and Update on the active scene, and handles a scene change made during them.
size_t RegisterUpdate (const UpdateCallback &callback)
 Calls callback every frame. Returns an id for UnregisterUpdate.
size_t ReleaseUnusedAssets ()
 Frees the cached assets nothing uses any more: those no AssetRef field of a component on a live object (the root scene and the persistent objects) names.
void Render ()
 Renders the current scene into the render system's framebuffer.
void RequestFullRefresh ()
 Makes the next present cover the whole screen, including the display's own RequestFullRefresh.
void RunMainLoop ()
 Runs the main loop (timing, platform updates, rendering, callbacks) until StopMainLoop().
void RunUpdateCallbacks (uint32_t deltaTime)
 Runs the registered update callbacks once.
void SetDisplay (IDisplay *display, const std::string &name="")
 Registers the active display; SDL3Display, LovyanGFXDisplay, EditorDisplay and the like call it when their package loads.
void SetGameUpdateCallback (const GameUpdateCallback &callback)
 Sets the callback that runs game logic each frame.
void SetInputSystem (IInputSystem *is)
 Called by an input package when it registers. The package owns is.
void SetRenderSystem (IRenderSystem *rs)
 Called by a rendering package when it registers. The package owns rs.
void SetRootScene (Scene *scene, bool takeOwnership=true)
 Makes scene the root scene.
void SetScreenDiagonalInches (float inches)
void SetTargetFPS (uint32_t fps)
 Frame rate the main loop aims for. The default is 30.
void Shutdown ()
 Shuts the engine down and frees its resources.
bool StepMainLoop ()
 One frame of RunMainLoop: false once the loop should end.
void StopMainLoop ()
void UnregisterUpdate (size_t id)
 Removes the callback that RegisterUpdate returned id for.
void Update (float deltaMs)
 Runs one frame. deltaMs is milliseconds since the last call.

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

◆ CreateScene()

Scene * Deki::Engine::CreateScene ( )

Creates an empty scene.

◆ GetDisplay()

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

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

◆ GetDisplayName()

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

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

◆ GetFrameBuffer()

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

◆ GetFrameBufferFormat()

ColorFormat Deki::Engine::GetFrameBufferFormat ( ) const

◆ GetHost()

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

◆ GetInputSystem()

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

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

◆ GetInstance()

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

◆ GetLastFrameTimings()

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

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

◆ GetLifecycleManager()

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

◆ GetRenderer()

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

The installed render system.

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

◆ GetRenderSystem()

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

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

◆ GetRootScene()

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

The root scene, or nullptr when none is set.

◆ GetSceneSystem()

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

◆ GetScreenDiagonalInches()

float Deki::Engine::GetScreenDiagonalInches ( ) const
inline

The screen's diagonal in inches, 0 when unknown.

A panel cannot report its size, so it comes from the board's platform file: a device build reads it from project_data.bin, and the editor sets it for the screen the Play view shows.

◆ GetScreenHeight()

int32_t Deki::Engine::GetScreenHeight ( ) const

◆ GetScreenHeightMeters()

float Deki::Engine::GetScreenHeightMeters ( ) const

◆ GetScreenPixelsPerInch()

float Deki::Engine::GetScreenPixelsPerInch ( ) const

Pixels per inch of the screen at its current size, 0 when its diagonal or size is unknown.

See ScreenPixelsPerInch.

◆ GetScreenWidth()

int32_t Deki::Engine::GetScreenWidth ( ) const

◆ GetScreenWidthMeters()

float Deki::Engine::GetScreenWidthMeters ( ) const

The screen's size on the glass in meters, 0 when unknown.

For laying out for a physically small screen: the 1.91" T-Display S3 AMOLED is 0.044 x 0.020 m, the 2.8" T-Deck 0.057 x 0.043 m.

◆ GetSettings() [1/2]

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

◆ GetSettings() [2/2]

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

◆ 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.

◆ IsDirty()

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

True when a redraw is needed.

◆ 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

◆ IsRunning()

bool Deki::Engine::IsRunning ( ) 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.

◆ MarkDirty()

void Deki::Engine::MarkDirty ( )
inline

Asks for a redraw.

◆ OpenRequestedScene()

void Deki::Engine::OpenRequestedScene ( )

Carries out an OpenScene request, if there is one.

Update() does this itself; hosts that drive the lifecycle by hand (the editor's play mode) call it after their updates.

◆ OpenScene() [1/2]

void Deki::Engine::OpenScene ( const AssetRefBase & scene)

Opens the scene scene refers to (an AssetRef<Scene>) once this frame's updates are done: the scene being left is freed first, then the new one is loaded and started before it is drawn.

The way for a game to change scenes: loading the next one itself and calling SetRootScene holds both in memory at once, more than a small board may have. A scene that does not exist is not opened, and the game stays where it is.

◆ OpenScene() [2/2]

void Deki::Engine::OpenScene ( const std::string & guid)

Opens the scene asset guid, as OpenScene above.

◆ 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.

◆ ProcessLifecycle()

void Deki::Engine::ProcessLifecycle ( )

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

◆ RegisterUpdate()

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

Calls callback every frame. Returns an id for UnregisterUpdate.

◆ ReleaseUnusedAssets()

size_t Deki::Engine::ReleaseUnusedAssets ( )

Frees the cached assets nothing uses any more: those no AssetRef field of a component on a live object (the root scene and the persistent objects) names.

An AssetRef held elsewhere loads its asset again when next asked, so keep assets in AssetRefs, not in raw pointers kept across frames. On a device OpenScene does this after every scene change; a game can call it after removing many objects. Returns how many assets were freed.

◆ Render()

void Deki::Engine::Render ( )

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

◆ RequestFullRefresh()

void Deki::Engine::RequestFullRefresh ( )

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

◆ RunMainLoop()

void Deki::Engine::RunMainLoop ( )

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

◆ 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.

◆ 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.

◆ SetGameUpdateCallback()

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

Sets the callback that runs game logic each frame.

◆ SetInputSystem()

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

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

◆ SetRenderSystem()

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

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

◆ 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.

◆ SetRuntimeMode()

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

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

◆ SetScreenDiagonalInches()

void Deki::Engine::SetScreenDiagonalInches ( float inches)

◆ SetTargetFPS()

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

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

◆ Shutdown()

void Deki::Engine::Shutdown ( )

Shuts the engine down and frees its resources.

◆ StepMainLoop()

bool Deki::Engine::StepMainLoop ( )

One frame of RunMainLoop: false once the loop should end.

A browser build calls it once per frame instead of looping.

◆ StopMainLoop()

void Deki::Engine::StopMainLoop ( )

◆ 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.

◆ Update()

void Deki::Engine::Update ( float deltaMs)

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


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