CheeseEngine
A 2D Game Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
EventBus Class Reference

Central event dispatcher connecting isolated engine systems. More...

#include <EventBus.hpp>

Public Member Functions

 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.
 

Private Attributes

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.
 

Detailed Description

Central event dispatcher connecting isolated engine systems.

Constructor & Destructor Documentation

◆ EventBus()

EventBus::EventBus ( )
inline

Initializes the EventBus and resets the handler ID counter.

Parameters
None
Return values
None

Member Function Documentation

◆ DispatchEvents()

void EventBus::DispatchEvents ( )
inline

Initiates sequential dispatch of all accumulated events across all queues.

Parameters
None
Return values
None

◆ 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
None

◆ 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
Theunique HandlerId required for unsubscription

◆ Unsubscribe()

void EventBus::Unsubscribe ( HandlerId  id)
inline

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
None

Member Data Documentation

◆ nextId

HandlerId EventBus::nextId
private

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: