State-driven scene router for Malena applications. More...
#include <SceneManager.h>
Static Public Member Functions | |
| template<typename App> | |
| static void | attach (App &app) |
Wire SceneManager into the application's state machine. | |
| static void | back () |
| Navigate to the previously visited state. | |
| static void | bind (StateEnum state, Core &scene) |
| Bind an existing scene instance to a state (eager). | |
| template<typename SceneType, typename... Args> | |
| static void | bindLazy (StateEnum state, Args &&... args) |
| Bind a lazily-constructed scene type to a state. | |
| static void | clear () |
| Clear all bindings and history. | |
| static StateEnum | current () |
| Return the currently active state. | |
| static bool | has (StateEnum state) |
Return true if a scene has been bound to state. | |
| static bool | isActive (StateEnum state) |
Return true if state is currently the active scene. | |
| static void | start (StateEnum state) |
| Activate the initial scene without recording a history entry. | |
State-driven scene router for Malena applications.
SceneManager<StateEnum> binds scenes (any Core-derived object or lazily-constructed type) to application state enum values. When the app calls setState(), SceneManager intercepts the transition via onStateEnter / onStateExit and performs the scene swap automatically — removing the outgoing scene from CoreManager and adding the incoming one.
setState() on the application is the only navigation primitive. SceneManager reacts to it; it does not replace it.back() is the one exception — it calls setState() with the previously visited state, keeping the state machine as the single source of truth.bind) are always in memory. Scenes bound lazily (bindLazy) are constructed on first visit and destroyed on back() or when another scene replaces them.Lazy scenes are heap-allocated on first visit and freed when they are navigated away from. This is useful for heavy scenes (lots of textures, many components) that should not occupy memory while inactive.
Every setState() call pushes the departing state onto a history stack. back() pops it and calls setState() with that value. The initial scene set via start() is NOT pushed — it acts as the history root.
| StateEnum | The enum class declared in your app manifest's State typedef. Must match the enum used by the app's own StateManager. |
Definition at line 108 of file SceneManager.h.
|
inlinestatic |
Wire SceneManager into the application's state machine.
Registers onStateEnter and onStateExit callbacks on app so that every future setState() call automatically triggers a scene swap. Also stores a reference to setState() so that back() can navigate without the caller holding an app reference.
Call this once in initialization(), before start().
| App | Any class that exposes:
|
| app | The application instance to attach to. |
Definition at line 223 of file SceneManager.h.
|
inlinestatic |
Navigate to the previously visited state.
Pops the history stack and calls setState() with the recovered state. Does nothing if history is empty (i.e., already at the root).
setState() on the application, which fires onStateExit and onStateEnter as normal. The scene swap happens automatically through those callbacks. Definition at line 283 of file SceneManager.h.
|
inlinestatic |
Bind an existing scene instance to a state (eager).
The scene is always in memory. SceneManager does not own it — lifetime management is the caller's responsibility (typically a member of Application).
| state | The application state that activates this scene. |
| scene | Reference to a Core-derived scene object. |
Definition at line 158 of file SceneManager.h.
|
inlinestatic |
Bind a lazily-constructed scene type to a state.
The scene is heap-allocated on first visit and destroyed when navigated away from. Constructor arguments are forwarded at construction time.
| SceneType | A Core-derived type to construct on demand. |
| Args | Constructor argument types (deduced). |
| state | The application state that activates this scene. |
| args | Arguments forwarded to SceneType's constructor. |
Definition at line 181 of file SceneManager.h.
|
inlinestatic |
Clear all bindings and history.
Call before rebuilding the scene set (e.g., after Application::reset()). Does NOT deactivate the current scene — call deactivate(current()) first if needed.
Definition at line 325 of file SceneManager.h.
|
inlinestatic |
Return the currently active state.
Definition at line 304 of file SceneManager.h.
|
inlinestatic |
Return true if a scene has been bound to state.
| state | State to check. |
Definition at line 316 of file SceneManager.h.
|
inlinestatic |
Return true if state is currently the active scene.
| state | State to check. |
Definition at line 310 of file SceneManager.h.
|
inlinestatic |
Activate the initial scene without recording a history entry.
Call after attach() and all bind() / bindLazy() calls. The initial scene is treated as the history root — back() cannot navigate past it.
| state | The state whose scene should be shown first. |
Definition at line 264 of file SceneManager.h.