Loading...
Searching...
No Matches
ml::ApplicationWith< TManifest > Class Template Reference

Entry point for Malena applications with a manifest. More...

#include <Malena/Engine/App/Application.h>

Inheritance diagram for ml::ApplicationWith< TManifest >:
[legend]

Public Types

using Resources = ml::ManifestResources<TManifest>
 Unified resource accessor — Resources::get(Images::Icon).

Public Member Functions

void addComponent (Core &component)
 Register a Core object with the application's component manager.
 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.
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.
template<typename EnumType>
static auto get (EnumType key) -> std::enable_if_t< !is_asset_enum< TManifest, EnumType >::value, decltype(ConfigManager< TManifest >::get(key))>
 Retrieve a config value by enum key → ConfigManager.
template<typename EnumType>
static auto get (EnumType key) -> std::enable_if_t< is_asset_enum< TManifest, EnumType >::value, const_ref_t< decltype(AssetsManager< TManifest >::get(key))> >
 Retrieve an asset by enum key → AssetsManager.
static bool isBusy ()
 Return true if the manager is currently iterating.
static void processPending ()
 Flush all pending operations immediately.
template<typename EnumType>
static std::enable_if_t< is_sounds_enum< TManifest, EnumType >::value > unload (EnumType key)
template<typename EnumType>
static std::enable_if_t< is_fonts_enum< TManifest, EnumType >::value > unload (EnumType key)
template<typename EnumType>
static std::enable_if_t< is_images_enum< TManifest, EnumType >::value > unload (EnumType key)

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.

Detailed Description

template<typename TManifest>
class ml::ApplicationWith< TManifest >

Entry point for Malena applications with a manifest.

Extends Application with manifest support — injects Resources::get() and all manifest enum aliases into scope automatically. Use when your application has global resources (icon, main font, app-wide config).

class MyManifest : public ml::Manifest
{
public:
static constexpr const char* name = "My App";
static constexpr const char* version = "1.0.0";
enum class Images { Icon };
enum class Fonts { Main };
enum class Text { WindowTitle };
enum class Ints { TargetFPS };
private:
inline static const auto _ = [](){
set(Images::Icon, "assets/icon.png");
set(Fonts::Main, "assets/main.ttf");
set(Text::WindowTitle, std::string("My App"));
set(Ints::TargetFPS, 60);
return 0;
}();
};
class MyApp : public ml::ApplicationWith<MyManifest>
{
public:
MyApp() : ml::ApplicationWith<MyManifest>(
1280, 720, 32,
Resources::get(Text::WindowTitle)) {}
void onInit() override
{
auto& icon = Resources::get(Images::Icon);
auto& font = Resources::get(Fonts::Main);
int fps = Resources::get(Ints::TargetFPS);
}
void onReady() override { }
};
ml::ManifestResources< TManifest > Resources
Unified resource accessor — Resources::get(Images::Icon).
virtual void onInit()
Called once after construction, before the first frame.
Definition Lifecycle.h:82
virtual void onReady()
Called once after onInit(), when all components are registered.
Definition Lifecycle.h:90
Base class for all Malena manifests.
Definition Manifest.h:51
static void set(EnumType key, const char *filepath)
Register an asset file path.
static auto get(EnumType key) -> std::enable_if_t< is_asset_enum< TManifest, EnumType >::value, const_ref_t< decltype(AssetsManager< TManifest >::get(key))> >
Retrieve an asset by enum key → AssetsManager.
Template Parameters
ManifestA Manifest subclass declaring app-wide resources and configuration.
See also
Application, ApplicationBase, Resources

Definition at line 179 of file Application.h.

Member Typedef Documentation

◆ Resources

template<typename TManifest>
using ml::ApplicationWith< TManifest >::Resources = ml::ManifestResources<TManifest>

Unified resource accessor — Resources::get(Images::Icon).

Definition at line 184 of file Application.h.

Member Function Documentation

◆ addComponent()

void ml::ApplicationBase::addComponent ( Core & component)
inherited

Register a Core object with the application's component manager.

◆ ApplicationBase() [1/2]

template<typename TManifest>
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.

◆ ApplicationBase() [2/2]

template<typename TManifest>
ml::ApplicationBase::ApplicationBase ( unsigned int screenWidth,
unsigned int screenHeight,
unsigned int bitDepth,
const std::string & title )

Construct from pixel dimensions and bit depth.

◆ beginBusy()

void ml::DeferredOperationsManager< CoreManager< Core > >::beginBusy ( )
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.

◆ clear()

void ml::CoreManager< Core >::clear ( )
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.

◆ clearEvents()

void ml::ApplicationBase::clearEvents ( )
staticinherited

Clear all event subscriptions across the entire application.

◆ clearPending()

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).

◆ deferOrExecute()

void ml::DeferredOperationsManager< CoreManager< Core > >::deferOrExecute ( std::function< void()> operation)
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.

Parameters
operationThe callable to execute or defer.

◆ endBusy()

void ml::DeferredOperationsManager< CoreManager< Core > >::endBusy ( )
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.

◆ get() [1/2]

template<typename TManifest>
template<typename EnumType>
auto ml::ManifestResources< TManifest >::get ( EnumType key) -> std::enable_if_t< !is_asset_enum< TManifest, EnumType >::value, decltype(ConfigManager< TManifest >::get(key))>
inlinestaticinherited

Retrieve a config value by enum key → ConfigManager.

Return type is inferred from ConfigManager::get()Text gives const std::string&, Ints gives int, etc.

Definition at line 126 of file ManifestResources.h.

◆ get() [2/2]

template<typename TManifest>
template<typename EnumType>
auto ml::ManifestResources< TManifest >::get ( EnumType key) -> std::enable_if_t< is_asset_enum< TManifest, EnumType >::value, const_ref_t< decltype(AssetsManager< TManifest >::get(key))> >
inlinestaticinherited

Retrieve an asset by enum key → AssetsManager.

Return type is explicitly const T& — taking & gives const T* with no ambiguity, suitable for SFML functions that take const sf::Texture* etc.

Definition at line 111 of file ManifestResources.h.

◆ getComponents()

const std::vector< Core * > & ml::CoreManager< Core >::getComponents ( ) const
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.

Returns
Const reference to the internal component pointer vector.

◆ isBusy()

bool ml::DeferredOperationsManager< CoreManager< Core > >::isBusy ( )
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.

Returns
true when busyDepth > 0.

◆ onInit()

virtual void ml::Lifecycle::onInit ( )
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.

◆ onReady()

virtual void ml::Lifecycle::onReady ( )
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.

◆ onUpdate() [1/2]

void ml::Updatable::onUpdate ( std::function< void()> callback)
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.

Parameters
callbackFunction invoked with no arguments each frame.

◆ onUpdate() [2/2]

void ml::Updatable::onUpdate ( std::function< void(const std::optional< sf::Event > &)> callback)
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.

Parameters
callbackFunction invoked with the SFML event (always nullopt) each frame.

◆ onWindowFocusGained() [1/2]

void ml::Updatable::onWindowFocusGained ( std::function< void()> callback)
inherited

Register a no-argument callback invoked when the application window gains OS focus.

Parameters
callbackFunction invoked with no arguments when focus is gained.

◆ onWindowFocusGained() [2/2]

void ml::Updatable::onWindowFocusGained ( std::function< void(const std::optional< sf::Event > &)> callback)
inherited

Register a callback invoked when the application window gains OS focus, receiving the raw SFML event.

Parameters
callbackFunction invoked with the SFML event when focus is gained.

◆ onWindowFocusLost() [1/2]

void ml::Updatable::onWindowFocusLost ( std::function< void()> callback)
inherited

Register a no-argument callback invoked when the application window loses OS focus.

Parameters
callbackFunction invoked with no arguments when focus is lost.

◆ onWindowFocusLost() [2/2]

void ml::Updatable::onWindowFocusLost ( std::function< void(const std::optional< sf::Event > &)> callback)
inherited

Register a callback invoked when the application window loses OS focus, receiving the raw SFML event.

Parameters
callbackFunction invoked with the SFML event when focus is lost.

◆ onWindowResized() [1/2]

void ml::Updatable::onWindowResized ( std::function< void()> callback)
inherited

Register a no-argument callback invoked when the application window is resized.

Parameters
callbackFunction invoked with no arguments on window resize.

◆ onWindowResized() [2/2]

void ml::Updatable::onWindowResized ( std::function< void(const std::optional< sf::Event > &)> callback)
inherited

Register a callback invoked when the application window is resized, receiving the raw SFML event.

Parameters
callbackFunction invoked with the SFML event on window resize.

◆ process() [1/2]

virtual void ml::EventReceiver::process ( const std::string & key,
const std::optional< sf::Event > & event )
virtualinherited

Invoke all callbacks registered for key.

Called by framework dispatchers. key is the string produced by EnumKey::get(eventEnum).

Parameters
keyString key identifying the event.
eventSFML event forwarded to each callback.

◆ process() [2/2]

template<typename ENUM_TYPE>
void ml::EventReceiver::process ( ENUM_TYPE eventName,
const std::optional< sf::Event > & event )
inherited

Invoke all callbacks registered for eventName.

Template overload that accepts any enum value directly, converting to a string key via EnumKey::get() internally.

Template Parameters
ENUM_TYPEAny enum type.
Parameters
eventNameThe enum value identifying the event.
eventSFML event forwarded to each callback.

◆ processPending()

Flush all pending operations immediately.

Normally called automatically by endBusy(). Provided as a public escape hatch for unusual teardown sequences.

Warning
Calling this while isBusy() is true can cause iterator invalidation in the currently running loop. Only call manually when you are certain it is safe.

◆ removeComponent()

bool ml::CoreManager< Core >::removeComponent ( Core & component)
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.

Parameters
componentThe object to remove.
Returns
true if the object was found and removed (or queued for removal); false if it was not registered.

◆ reset()

void ml::ApplicationBase::reset ( )
inherited

Full application reset — clears events, messages, and components.

Tears down all framework state in the correct order:

  1. All event subscriptions
  2. All message subscriptions
  3. All registered components

After reset(), call onInit() and onReady() to rebuild the scene.

Note
Does NOT close the window or restart the main loop.

◆ run()

void ml::AppManager::run ( )
inherited

Enter the main loop and run until the window is closed.

Each iteration of the loop:

  1. Polls all pending SFML events and passes each to fireInputEvents().
  2. Calls fireUpdateEvents() for the per-frame update tick.
  3. Clears the window, calls draw() on all registered components, and displays the frame.

Returns when the SFML window is closed or window.close() is called.

◆ unload() [1/3]

template<typename TManifest>
template<typename EnumType>
std::enable_if_t< is_sounds_enum< TManifest, EnumType >::value > ml::ManifestResources< TManifest >::unload ( EnumType key)
inlinestaticinherited

Definition at line 150 of file ManifestResources.h.

◆ unload() [2/3]

template<typename TManifest>
template<typename EnumType>
std::enable_if_t< is_fonts_enum< TManifest, EnumType >::value > ml::ManifestResources< TManifest >::unload ( EnumType key)
inlinestaticinherited

Definition at line 143 of file ManifestResources.h.

◆ unload() [3/3]

template<typename TManifest>
template<typename EnumType>
std::enable_if_t< is_images_enum< TManifest, EnumType >::value > ml::ManifestResources< TManifest >::unload ( EnumType key)
inlinestaticinherited

Definition at line 136 of file ManifestResources.h.

Member Data Documentation

◆ busyDepth

int ml::DeferredOperationsManager< CoreManager< Core > >::busyDepth
inlinestaticprotectedinherited

Iteration nesting depth. Operations are deferred while this is > 0.

Definition at line 70 of file DeferredOperationsManager.h.

◆ pendingOperations

std::vector<std::function<void()> > ml::DeferredOperationsManager< CoreManager< Core > >::pendingOperations
inlinestaticprotectedinherited

Queue of operations pending until the current iteration completes.

Definition at line 73 of file DeferredOperationsManager.h.


The documentation for this class was generated from the following file: