R-Type  2
Doom but in better
Loading...
Searching...
No Matches
EventDispatcher Class Reference

A utility class for dispatching and handling game events. More...

#include <EventDispatcher.hpp>

Collaboration diagram for EventDispatcher:
Collaboration graph

Public Types

using Callback = std::function<void(const GameMessage&)>
 Defines the type for event callbacks.
 

Public Member Functions

void subscribe (Callback callback)
 Subscribes a listener to game events.
 
void notify (const GameMessage &event)
 Notifies the subscribed listener of an event.
 

Detailed Description

A utility class for dispatching and handling game events.

The EventDispatcher facilitates the subscription and notification of game events using a callback mechanism. It allows a single listener to subscribe to events, which are then forwarded through the provided callback.

Definition at line 12 of file EventDispatcher.hpp.

Member Typedef Documentation

◆ Callback

using EventDispatcher::Callback = std::function<void(const GameMessage&)>

Defines the type for event callbacks.

A callback is a function that takes a GameMessage as a parameter.

Definition at line 19 of file EventDispatcher.hpp.

Member Function Documentation

◆ notify()

void EventDispatcher::notify ( const GameMessage & event)
inline

Notifies the subscribed listener of an event.

If a listener is subscribed, this method forwards the given GameMessage to the listener's callback.

Parameters
eventThe event to be dispatched, represented as a GameMessage.

Definition at line 39 of file EventDispatcher.hpp.

◆ subscribe()

void EventDispatcher::subscribe ( Callback callback)
inline

Subscribes a listener to game events.

This method allows setting a callback function to handle incoming game events.

Parameters
callbackA function that processes GameMessage events.

Definition at line 28 of file EventDispatcher.hpp.


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