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