Internal base class for all Malena applications. More...
#include <Malena/Engine/App/Application.h>
Public Member Functions | |
| ApplicationBase (const sf::VideoMode &videoMode, const std::string &title, sf::RenderWindow &window=WindowManager::getWindow()) | |
| Construct with an explicit video mode and window title. | |
| ApplicationBase (unsigned int screenWidth, unsigned int screenHeight, unsigned int bitDepth, const std::string &title) | |
| Construct from pixel dimensions and bit depth. | |
| ~ApplicationBase () | |
| void | addComponent (Core &component) |
Register a Core object with the application's component manager. | |
| void | clear () |
| Remove all registered objects. | |
| const std::vector< Core * > & | getComponents () const |
| Return a read-only view of all currently registered objects. | |
| virtual void | onInit () |
| Called once after construction, before the first frame. | |
| virtual void | onReady () |
Called once after onInit(), when all components are registered. | |
| void | onUpdate (std::function< void()> callback) |
| Register a no-argument callback invoked every frame. | |
| void | onUpdate (std::function< void(const std::optional< sf::Event > &)> callback) |
| Register a callback invoked every frame, receiving the SFML event. | |
| void | onWindowFocusGained (std::function< void()> callback) |
| Register a no-argument callback invoked when the application window gains OS focus. | |
| void | onWindowFocusGained (std::function< void(const std::optional< sf::Event > &)> callback) |
| Register a callback invoked when the application window gains OS focus, receiving the raw SFML event. | |
| void | onWindowFocusLost (std::function< void()> callback) |
| Register a no-argument callback invoked when the application window loses OS focus. | |
| void | onWindowFocusLost (std::function< void(const std::optional< sf::Event > &)> callback) |
| Register a callback invoked when the application window loses OS focus, receiving the raw SFML event. | |
| void | onWindowResized (std::function< void()> callback) |
| Register a no-argument callback invoked when the application window is resized. | |
| void | onWindowResized (std::function< void(const std::optional< sf::Event > &)> callback) |
| Register a callback invoked when the application window is resized, receiving the raw SFML event. | |
| virtual void | process (const std::string &key, const std::optional< sf::Event > &event) |
Invoke all callbacks registered for key. | |
| template<typename ENUM_TYPE> | |
| void | process (ENUM_TYPE eventName, const std::optional< sf::Event > &event) |
Invoke all callbacks registered for eventName. | |
| bool | removeComponent (Core &component) |
Unregister a T object by reference. | |
| void | reset () |
| Full application reset — clears events, messages, and components. | |
| void | run () |
| Enter the main loop and run until the window is closed. | |
Static Public Member Functions | |
| static void | clearEvents () |
| Clear all event subscriptions across the entire application. | |
| static void | clearPending () |
| Discard all pending operations without executing them. | |
| static bool | isBusy () |
Return true if the manager is currently iterating. | |
| static void | processPending () |
| Flush all pending operations immediately. | |
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. | |
Internal base class for all Malena applications.
Do not inherit directly. Use ml::Application or ml::ApplicationWith.
Definition at line 34 of file Application.h.
| ml::ApplicationBase::ApplicationBase | ( | const sf::VideoMode & | videoMode, |
| const std::string & | title, | ||
| sf::RenderWindow & | window = WindowManager::getWindow() ) |
Construct with an explicit video mode and window title.
| ml::ApplicationBase::ApplicationBase | ( | unsigned int | screenWidth, |
| unsigned int | screenHeight, | ||
| unsigned int | bitDepth, | ||
| const std::string & | title ) |
Construct from pixel dimensions and bit depth.
| ml::ApplicationBase::~ApplicationBase | ( | ) |
| void ml::ApplicationBase::addComponent | ( | Core & | component | ) |
Register a Core object with the application's component manager.
|
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 |
Clear all event subscriptions across the entire application.
|
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.
|
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.
|
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.
|
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.
|
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.
|
inherited |
Register a no-argument callback invoked every frame.
The callback fires once per frame before the draw pass. All active components receive this regardless of hover or focus state.
| callback | Function invoked with no arguments each frame. |
|
inherited |
Register a callback invoked every frame, receiving the SFML event.
For frame events the std::optional<sf::Event> is always std::nullopt — use the no-argument overload unless you specifically need the optional parameter in your callback signature.
| callback | Function invoked with the SFML event (always nullopt) each frame. |
|
inherited |
Register a no-argument callback invoked when the application window gains OS focus.
| callback | Function invoked with no arguments when focus is gained. |
|
inherited |
Register a callback invoked when the application window gains OS focus, receiving the raw SFML event.
| callback | Function invoked with the SFML event when focus is gained. |
|
inherited |
Register a no-argument callback invoked when the application window loses OS focus.
| callback | Function invoked with no arguments when focus is lost. |
|
inherited |
Register a callback invoked when the application window loses OS focus, receiving the raw SFML event.
| callback | Function invoked with the SFML event when focus is lost. |
|
inherited |
Register a no-argument callback invoked when the application window is resized.
| callback | Function invoked with no arguments on window resize. |
|
inherited |
Register a callback invoked when the application window is resized, receiving the raw SFML event.
| callback | Function invoked with the SFML event on window resize. |
|
virtualinherited |
Invoke all callbacks registered for key.
Called by framework dispatchers. key is the string produced by EnumKey::get(eventEnum).
| key | String key identifying the event. |
| event | SFML event forwarded to each callback. |
|
inherited |
Invoke all callbacks registered for eventName.
Template overload that accepts any enum value directly, converting to a string key via EnumKey::get() internally.
| ENUM_TYPE | Any enum type. |
| eventName | The enum value identifying the event. |
| event | SFML event forwarded to each callback. |
|
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::ApplicationBase::reset | ( | ) |
Full application reset — clears events, messages, and components.
Tears down all framework state in the correct order:
After reset(), call onInit() and onReady() to rebuild the scene.
|
inherited |
Enter the main loop and run until the window is closed.
Each iteration of the loop:
fireInputEvents().fireUpdateEvents() for the per-frame update tick.draw() on all registered components, and displays the frame.Returns when the SFML window is closed or window.close() is called.
|
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.