Centralized event bus for the Malena trait-based event system.
More...
#include <EventManager.h>
|
| static void | clear () |
| | Remove all subscriptions for all events.
|
| static void | clearPending () |
| | Discard all pending operations without executing them.
|
| template<typename EnumType> |
| static void | fire (EnumType eventEnum, Fireable *dispatcher, const std::optional< sf::Event > &event, SystemCallback resolve=nullptr, SystemCallback reject=nullptr) |
| | Fire an event to all matching subscribers.
|
| static bool | isBusy () |
| | Return true if the manager is currently iterating.
|
| static void | processPending () |
| | Flush all pending operations immediately.
|
| template<typename EnumType> |
| static void | subscribe (EnumType eventEnum, EventReceiver *component) |
| | Register a component for an enum-keyed event.
|
| template<typename EnumType> |
| static void | unsubscribe (EnumType eventEnum, Core *core) |
| | Remove a component's subscription to one event.
|
| static void | unsubscribeAll (Core *core) |
| | Remove all subscriptions for a component.
|
|
| 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 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.
|
Centralized event bus for the Malena trait-based event system.
Stores subscribers keyed by std::string — generated from any enum value via EnumKey::get(). Both ml::Event built-in values and user manifest event enums work identically.
All public methods take enum values directly — EnumKey::get() is called internally. Users and framework code never see raw string keys.
Inherits DeferredOperationsManager — any unsubscribe call during fire() is deferred until iteration ends, preventing iterator invalidation and use-after-free crashes.
- See also
- Fireable, EventReceiver, EnumKey, DeferredOperationsManager
Definition at line 40 of file EventManager.h.
◆ beginBusy()
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::EventManager::clear |
( |
| ) |
|
|
static |
Remove all subscriptions for all events.
Deferred if called during fire().
◆ 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()
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
-
| operation | The callable to execute or defer. |
◆ endBusy()
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.
◆ fire()
template<typename EnumType>
| void ml::EventManager::fire |
( |
EnumType | eventEnum, |
|
|
Fireable * | dispatcher, |
|
|
const std::optional< sf::Event > & | event, |
|
|
SystemCallback | resolve = nullptr, |
|
|
SystemCallback | reject = nullptr ) |
|
inlinestatic |
Fire an event to all matching subscribers.
- Template Parameters
-
- Parameters
-
| eventEnum | The enum value identifying the event. |
| dispatcher | The Fireable singleton owning filter logic. |
| event | SFML event forwarded to callbacks. |
| resolve | Called per-component after process() passes filter. |
| reject | Called per-component when filter fails. |
Definition at line 115 of file EventManager.h.
◆ isBusy()
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.
◆ 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.
◆ subscribe()
template<typename EnumType>
| void ml::EventManager::subscribe |
( |
EnumType | eventEnum, |
|
|
EventReceiver * | component ) |
|
inlinestatic |
Register a component for an enum-keyed event.
- Template Parameters
-
- Parameters
-
| eventEnum | The enum value identifying the event. |
| component | The trait EventReceiver* subobject. |
Definition at line 64 of file EventManager.h.
◆ unsubscribe()
template<typename EnumType>
| void ml::EventManager::unsubscribe |
( |
EnumType | eventEnum, |
|
|
Core * | core ) |
|
inlinestatic |
Remove a component's subscription to one event.
Deferred if called during fire().
- Template Parameters
-
- Parameters
-
| eventEnum | The event to unsubscribe from. |
| core | The component's Core* identity. |
Definition at line 79 of file EventManager.h.
◆ unsubscribeAll()
| void ml::EventManager::unsubscribeAll |
( |
Core * | core | ) |
|
|
static |
◆ AppManager
◆ Core
◆ Fireable
◆ Unsubscribable
| friend class Unsubscribable |
|
friend |
◆ busyDepth
|
|
inlinestaticprotectedinherited |
◆ pendingOperations
|
|
inlinestaticprotectedinherited |
The documentation for this class was generated from the following file: