|
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
|
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. | |
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.
|
static |
|
static |
Starts the engine from the active project settings, with EngineHost::Editor() in editor builds and EngineHost::Device() otherwise.
Returns false on failure.
|
static |
Starts the engine with the given host configuration.
|
inline |
| void Deki::Engine::Shutdown | ( | ) |
Shuts the engine down and frees its resources.
| void Deki::Engine::Update | ( | uint32_t | deltaTime | ) |
Runs one frame. deltaTime is milliseconds since the last call.
| void Deki::Engine::ProcessLifecycle | ( | ) |
Runs Awake, Start and Update on the active scene, and handles a scene change made during them.
| void Deki::Engine::Render | ( | ) |
Renders the current scene into the render system's framebuffer.
| 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.
| void Deki::Engine::RequestFullRefresh | ( | ) |
Makes the next present cover the whole screen, including the display's own RequestFullRefresh.
| size_t Deki::Engine::RegisterUpdate | ( | const UpdateCallback & | callback | ) |
Calls callback every frame. Returns an id for 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.
| 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.
| 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.
| Scene * Deki::Engine::GetRootScene | ( | ) | const |
The root scene, or nullptr when none is set.
| Scene * Deki::Engine::CreateScene | ( | ) |
Creates an empty scene.
|
inline |
The installed render system.
Call it only when one is installed (see GetRenderSystem).
|
inline |
|
inline |
|
inline |
The render system, or nullptr when no rendering package is loaded.
|
inline |
Called by a rendering package when it registers. The package owns rs.
|
inline |
The input system, or nullptr when no input package is loaded.
|
inline |
Called by an input package when it registers. The package owns is.
|
inline |
The active display, set by a display package through SetDisplay(), or nullptr when none is loaded.
| 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.
|
inline |
Display name set by the registering package, such as "SDL3".
|
inline |
True when a display is registered and its IsInitialized() is true.
|
inline |
|
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.
|
static |
Called by the editor's play mode when it starts and stops.
| void Deki::Engine::SetGameUpdateCallback | ( | const GameUpdateCallback & | callback | ) |
Sets the callback that runs game logic each frame.
| void Deki::Engine::SetTargetFPS | ( | uint32_t | fps | ) |
Frame rate the main loop aims for. The default is 30.
| void Deki::Engine::RunMainLoop | ( | ) |
Runs the main loop (timing, platform updates, rendering, callbacks) until StopMainLoop().
| void Deki::Engine::StopMainLoop | ( | ) |
|
inline |
|
inline |
Asks for a redraw.
|
inline |
True when a redraw is needed.
|
inline |
How long the parts of the last frame took: see FrameTimings.
| const uint8_t * Deki::Engine::GetFrameBuffer | ( | ) | const |
| int32_t Deki::Engine::GetScreenWidth | ( | ) | const |
| int32_t Deki::Engine::GetScreenHeight | ( | ) | const |
| ColorFormat Deki::Engine::GetFrameBufferFormat | ( | ) | const |
|
inline |
|
inline |