Central event dispatcher connecting isolated engine systems.
More...
#include <EventBus.hpp>
|
| | EventBus () |
| | Initializes the EventBus and resets the handler ID counter.
|
| |
| template<typename T > |
| void | Publish (T &&event) |
| | Adds an event to the corresponding type queue for future dispatch.
|
| |
| template<typename T > |
| HandlerId | Subscribe (std::function< void(const T &)> callback) |
| | Registers a new subscriber callback for a specific event type.
|
| |
| void | Unsubscribe (HandlerId id) |
| | Removes a handler from the event bus across all queues.
|
| |
| void | DispatchEvents () |
| | Initiates sequential dispatch of all accumulated events across all queues.
|
| |
|
| std::unordered_map< std::type_index, std::unique_ptr< IEventQueue > > | queues |
| | Map of event types to their queues.
|
| |
| HandlerId | nextId |
| | Counter for generating unique handler IDs.
|
| |
Central event dispatcher connecting isolated engine systems.
◆ EventBus()
Initializes the EventBus and resets the handler ID counter.
- Parameters
-
- Return values
-
◆ DispatchEvents()
| void EventBus::DispatchEvents |
( |
| ) |
|
|
inline |
Initiates sequential dispatch of all accumulated events across all queues.
- Parameters
-
- Return values
-
◆ Publish()
template<typename T >
| void EventBus::Publish |
( |
T && |
event | ) |
|
|
inline |
Adds an event to the corresponding type queue for future dispatch.
- Parameters
-
| event | : Universal reference to the event being sent |
- Return values
-
◆ Subscribe()
template<typename T >
| HandlerId EventBus::Subscribe |
( |
std::function< void(const T &)> |
callback | ) |
|
|
inline |
Registers a new subscriber callback for a specific event type.
- Parameters
-
| callback | : Function handling the constant reference to the event |
- Return values
-
| The | unique HandlerId required for unsubscription |
◆ Unsubscribe()
Removes a handler from the event bus across all queues.
- Note
- Iterates through all abstract queues. Safe and efficient enough since unsubscriptions are rare
- Parameters
-
| id | : The unique identifier of the handler returned by Subscribe |
- Return values
-
◆ nextId
Counter for generating unique handler IDs.
◆ queues
| std::unordered_map<std::type_index, std::unique_ptr<IEventQueue> > EventBus::queues |
|
private |
Map of event types to their queues.
The documentation for this class was generated from the following file:
- /home/runner/work/Cheese-Engine/Cheese-Engine/inc/EventBus.hpp