Drives the application main loop and coordinates all framework managers. More...
#include <Malena/Engine/App/AppManager.h>
Public Types | |
| enum | Architecture { MVC , EDA , ECS } |
| Architectural style hint passed at construction. More... | |
Public Member Functions | |
| AppManager (const sf::VideoMode &videoMode, const std::string &title, sf::RenderWindow &window=WindowManager::getWindow(), Architecture architecture=MVC, std::uint32_t windowStyle=sf::Style::Default) | |
Construct an AppManager and create the SFML window. | |
| virtual | ~AppManager ()=default |
| void | addComponent (Core &component) |
Register a T object with this manager. | |
| void | clear () |
| Remove all registered objects. | |
| Architecture | getArchitecture () const |
| Return the architectural mode set at construction. | |
| const std::vector< Core * > & | getComponents () const |
| Return a read-only view of all currently registered objects. | |
| bool | isPaused () const |
Return true if the application is currently paused. | |
| void | onClose (std::function< bool()> handler) |
| Register a callback invoked when the OS close button is pressed. | |
| virtual void | onInit () |
| Called once after construction, before the first frame. | |
| void | onPostRender (std::function< void()> hook) |
Register a callback invoked after all components are drawn and before display(). | |
| void | onPreRender (std::function< void()> hook) |
Register a callback invoked after clear() and before drawing components. | |
| virtual void | onReady () |
Called once after onInit(), when all components are registered. | |
| void | onResize (std::function< void(unsigned int, unsigned int)> handler) |
| Register a callback invoked whenever the window is resized. | |
| void | pause () |
| Suspend per-frame update events. | |
| bool | removeComponent (Core &component) |
Unregister a T object by reference. | |
| void | resume () |
Resume update events after a pause(). | |
| void | run () |
| Enter the main loop and run until the window is closed. | |
| void | setBackgroundColor (sf::Color color) |
| Set the colour used to clear the window at the start of each frame. | |
| void | setFramerateLimit (unsigned int limit) |
| Cap the frame rate. | |
| void | setIcon (const sf::Image &icon) |
Set the window icon from an sf::Image. | |
| void | setTitle (const std::string &title) |
| Change the window title at runtime. | |
| void | setVSync (bool enabled) |
| Enable or disable vertical synchronisation. | |
| void | setWindowPosition (int x, int y) |
| Move the window to a position on the desktop. | |
| void | setWindowStyle (std::uint32_t style) |
| Recreate the window with new decoration-style flags. | |
Static Public Member Functions | |
| static void | clearExclusiveOwner () |
| Lift any active exclusive-owner restriction. | |
| static void | clearPending () |
| Discard all pending operations without executing them. | |
| static Core * | exclusiveOwner () |
The current exclusive-interaction owner, or nullptr. | |
| static float | getDeltaTime () |
| Return the elapsed time of the previous frame in seconds. | |
| static bool | isBusy () |
Return true if the manager is currently iterating. | |
| static void | processPending () |
| Flush all pending operations immediately. | |
| static void | setExclusiveOwner (Core *owner) |
Restrict click and hover dispatch to owner and its descendants. Any component outside that subtree silently receives no events. Pass nullptr (or call clearExclusiveOwner) to lift the restriction. | |
Static Protected Member Functions | |
| static void | beginBusy () |
| Signal that iteration has begun. | |
| static void | deferOrExecute (std::function< void()> operation) |
Execute operation now if safe, otherwise queue it. | |
| static void | endBusy () |
| Signal that iteration has ended; flush pending operations. | |
Static Protected Attributes | |
| static int | busyDepth |
| Iteration nesting depth. Operations are deferred while this is > 0. | |
| static std::vector< std::function< void()> > | pendingOperations |
| Queue of operations pending until the current iteration completes. | |
Drives the application main loop and coordinates all framework managers.
AppManager owns the SFML render window and runs the core application lifecycle:
Lifecycle::onInit() then Lifecycle::onReady() before entering the loop.fireInputEvents().fireUpdateEvents() (skipped when paused).Most window properties can be set before run() or at any time during the loop via dedicated setters:
| Setter | Effect |
|---|---|
setBackgroundColor() | Colour passed to window.clear() each frame |
setFramerateLimit() | Cap the frame rate (0 = unlimited) |
setVSync() | Toggle vertical synchronisation |
setTitle() | Change the window title at runtime |
setIcon() | Set the window icon from an sf::Image |
setWindowPosition() | Move the window on the desktop |
setWindowStyle() | Recreate the window with new decoration flags |
| Setter | Called |
|---|---|
onPreRender() | After clear(), before drawing components |
onPostRender() | After drawing all components, before display() |
onClose() | When the OS close button is pressed; return false to cancel |
onResize() | When the window is resized |
pause() suspends fireUpdateEvents() while leaving the render loop running, so the window stays responsive and the last rendered frame remains visible. resume() restores normal operation.
AppManager::getDeltaTime() returns the elapsed time (in seconds) of the previous frame, updated at the start of each iteration. Components can call this from any onUpdate callback.
The Architecture enum lets the framework know which structural style the application uses.
| Value | Meaning |
|---|---|
MVC | Model-View-Controller — default for most UI applications |
EDA | Event-Driven Architecture — pure message/event flow |
ECS | Entity-Component-System — activates the ECS subsystem |
Most applications do not instantiate AppManager directly. Instead, inherit from ml::Application, which wraps AppManager into a single convenient base class.
For the common case, subclass ml::Application and override onInit() and onReady() directly:
Definition at line 107 of file AppManager.h.
Architectural style hint passed at construction.
Informs the framework which structural pattern the application follows. Defaults to MVC.
| Enumerator | |
|---|---|
| MVC | Model-View-Controller. |
| EDA | Event-Driven Architecture. |
| ECS | Entity-Component-System. |
Definition at line 116 of file AppManager.h.
| ml::AppManager::AppManager | ( | const sf::VideoMode & | videoMode, |
| const std::string & | title, | ||
| sf::RenderWindow & | window = WindowManager::getWindow(), | ||
| Architecture | architecture = MVC, | ||
| std::uint32_t | windowStyle = sf::Style::Default ) |
Construct an AppManager and create the SFML window.
onInit() and onReady() are called by run() before the main loop begins, not in the constructor. The window parameter defaults to WindowManager::getWindow() so the framework's centralized window is used unless an explicit one is provided.
| videoMode | SFML video mode (resolution + bit depth). |
| title | Window title string. |
| window | Render window to use. Defaults to the framework window. |
| architecture | Structural pattern hint. Defaults to MVC. |
| windowStyle | SFML window style flags (e.g. sf::Style::Default, sf::Style::None, sf::Style::Fullscreen). Defaults to sf::Style::Default. |
|
virtualdefault |
|
inherited |
Register a T object with this manager.
After registration, the object will receive update() and draw() calls each frame (for managers that drive those methods).
| component | The object to register. Must outlive its registration. |
|
staticprotectedinherited |
Signal that iteration has begun.
Increments the busy-depth counter. Multiple nested calls are safe — operations remain deferred until the outermost endBusy() is reached.
|
inherited |
Remove all registered objects.
If the collection is currently being iterated, the clear is deferred. After this call (or after the deferred clear executes), getComponents() returns an empty vector.
|
static |
Lift any active exclusive-owner restriction.
|
staticinherited |
Discard all pending operations without executing them.
Use during application shutdown or full reset when executing the queued operations would be unsafe (e.g., the objects they reference have already been destroyed).
|
staticprotectedinherited |
Execute operation now if safe, otherwise queue it.
If busyDepth > 0 the operation is appended to pendingOperations and will run when the current iteration completes. If the manager is idle the operation executes immediately.
| operation | The callable to execute or defer. |
|
staticprotectedinherited |
Signal that iteration has ended; flush pending operations.
Decrements the busy-depth counter. When the counter reaches zero, all operations in pendingOperations are executed in FIFO order and the queue is cleared.
|
inlinestatic |
The current exclusive-interaction owner, or nullptr.
Definition at line 330 of file AppManager.h.
|
inline |
Return the architectural mode set at construction.
Definition at line 317 of file AppManager.h.
|
nodiscardinherited |
Return a read-only view of all currently registered objects.
The returned reference is valid until the next structural modification (add or remove). Do not store the reference across frames.
|
inlinestatic |
Return the elapsed time of the previous frame in seconds.
Updated at the start of every main-loop iteration. Safe to call from any onUpdate callback.
Definition at line 257 of file AppManager.h.
|
staticinherited |
Return true if the manager is currently iterating.
Can be used by external code that needs to know whether a destructive operation will be deferred.
true when busyDepth > 0.
|
inline |
Return true if the application is currently paused.
Definition at line 274 of file AppManager.h.
| void ml::AppManager::onClose | ( | std::function< bool()> | handler | ) |
Register a callback invoked when the OS close button is pressed.
| handler | Callable with signature bool(). Return true to allow the window to close (default behaviour), or false to cancel the close (e.g. show a "save changes?" dialog). |
|
inlinevirtualinherited |
Called once after construction, before the first frame.
Override to perform initial setup — configure component properties, load resources, and register objects with the framework. At this point no other sibling components are guaranteed to be fully registered.
Definition at line 82 of file Lifecycle.h.
| void ml::AppManager::onPostRender | ( | std::function< void()> | hook | ) |
Register a callback invoked after all components are drawn and before display().
Use this for post-processing effects, HUD overlays, or any content that must appear on top of all components.
| hook | Callable with signature void(). |
| void ml::AppManager::onPreRender | ( | std::function< void()> | hook | ) |
Register a callback invoked after clear() and before drawing components.
Use this to draw background layers, debug overlays, or ImGui frames that should appear beneath the component layer.
| hook | Callable with signature void(). |
|
inlinevirtualinherited |
Called once after onInit(), when all components are registered.
Override to wire logic that depends on other components already existing — event callbacks, cross-component bindings, or derived initial state.
Definition at line 90 of file Lifecycle.h.
| void ml::AppManager::onResize | ( | std::function< void(unsigned int, unsigned int)> | handler | ) |
Register a callback invoked whenever the window is resized.
| handler | Callable with signature void(unsigned int width, unsigned int height). |
| void ml::AppManager::pause | ( | ) |
Suspend per-frame update events.
After pause(), fireUpdateEvents() is skipped each iteration. The render loop continues running so the window stays responsive and the last rendered frame remains visible.
|
staticinherited |
Flush all pending operations immediately.
Normally called automatically by endBusy(). Provided as a public escape hatch for unusual teardown sequences.
isBusy() is true can cause iterator invalidation in the currently running loop. Only call manually when you are certain it is safe.
|
inherited |
Unregister a T object by reference.
Safe to call from inside an event or update callback. If the collection is currently being iterated, the removal is deferred until iteration completes.
| component | The object to remove. |
true if the object was found and removed (or queued for removal); false if it was not registered. | void ml::AppManager::resume | ( | ) |
Resume update events after a pause().
| void ml::AppManager::run | ( | ) |
Enter the main loop and run until the window is closed.
Each iteration of the loop:
fireUpdateEvents() for the per-frame update tick (skipped when paused).onPreRender, draws all visible components, invokes onPostRender, and presents the frame.Returns when the SFML window is closed or window.close() is called.
| void ml::AppManager::setBackgroundColor | ( | sf::Color | color | ) |
Set the colour used to clear the window at the start of each frame.
| color | Any sf::Color value. Defaults to sf::Color::Black. |
|
static |
Restrict click and hover dispatch to owner and its descendants. Any component outside that subtree silently receives no events. Pass nullptr (or call clearExclusiveOwner) to lift the restriction.
| void ml::AppManager::setFramerateLimit | ( | unsigned int | limit | ) |
Cap the frame rate.
Calls sf::Window::setFramerateLimit. Pass 0 to remove the cap.
| limit | Maximum frames per second. |
| void ml::AppManager::setIcon | ( | const sf::Image & | icon | ) |
| void ml::AppManager::setTitle | ( | const std::string & | title | ) |
Change the window title at runtime.
| title | New UTF-8 window title string. |
| void ml::AppManager::setVSync | ( | bool | enabled | ) |
Enable or disable vertical synchronisation.
| enabled | true to enable VSync, false to disable. |
| void ml::AppManager::setWindowPosition | ( | int | x, |
| int | y ) |
Move the window to a position on the desktop.
| x | Horizontal position in desktop pixels. |
| y | Vertical position in desktop pixels. |
| void ml::AppManager::setWindowStyle | ( | std::uint32_t | style | ) |
Recreate the window with new decoration-style flags.
Equivalent to calling sf::Window::create again with the stored video-mode and title but a new style. Any previously configured framerate limit is re-applied automatically.
| style | Combination of sf::Style flags, e.g. sf::Style::Titlebar | sf::Style::Close. |
|
inlinestaticprotectedinherited |
Iteration nesting depth. Operations are deferred while this is > 0.
Definition at line 70 of file DeferredOperationsManager.h.
|
inlinestaticprotectedinherited |
Queue of operations pending until the current iteration completes.
Definition at line 73 of file DeferredOperationsManager.h.