Centralized event bus for the Malena trait-based event system.
More...
#include <Malena/Engine/Events/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 | hasReceiver (EventReceiver *receiver) |
| | True if receiver is still registered under any event key.
|
| 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, Core *core=nullptr) |
| | 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 45 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 142 of file EventManager.h.
◆ hasReceiver()
True if receiver is still registered under any event key.
A destroyed component is removed from all lists by forceUnsubscribeAll (from ~Core). Callers holding a raw EventReceiver* (e.g. the click dispatcher's static _focused) use this to detect that it was freed and avoid dereferencing a dangling pointer.
◆ 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, |
|
|
Core * | core = nullptr ) |
|
inlinestatic |
Register a component for an enum-keyed event.
- Template Parameters
-
- Parameters
-
| eventEnum | The enum value identifying the event. |
| component | The trait EventReceiver* subobject. |
| core | Owning Core, when the caller already knows it. Supplying it avoids recovering the Core by dynamic_cast from a trait subobject, which is undefined behaviour while the object is still under construction and aborts on MSVC. Defaults to nullptr, in which case the stamped _selfCore is preferred and RTTI is a last resort. |
Definition at line 76 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 96 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: