Acheron
Loading...
Searching...
No Matches
acheron::ecs::EventManager Class Reference

Manages subscribing, dispatching, and creating events. More...

#include <event.hpp>

Public Types

template<typename T>
using Callback = std::function<void(World&, const T&)>
 Function signature for event callbacks.

Public Member Functions

template<typename T>
void Subscribe (World &world, Callback< T > callback)
 Subscribe to an event type.
template<typename T>
void Emit (const T &event)
 Emit an event.
void Dispatch ()
 Dispatch all queued events.

Detailed Description

Manages subscribing, dispatching, and creating events.

Events are plain structs that can be emitted with Emit<T>(), and subscribed to with Subscribe<T>(). The bus stores events until Dispatch() is called, at which point all subscribers are notified.

Member Typedef Documentation

◆ Callback

template<typename T>
using acheron::ecs::EventManager::Callback = std::function<void(World&, const T&)>

Function signature for event callbacks.

Template Parameters
TThe event type

Member Function Documentation

◆ Dispatch()

void acheron::ecs::EventManager::Dispatch ( )
inline

Dispatch all queued events.

Invokes all callbacks subscribed to the emitted event types, then clears the queue

◆ Emit()

template<typename T>
void acheron::ecs::EventManager::Emit ( const T & event)
inline

Emit an event.

Queues an event of type T for dispatch at the end of the frame

Template Parameters
TThe event type
Parameters
eventThe event instance

◆ Subscribe()

template<typename T>
void acheron::ecs::EventManager::Subscribe ( World & world,
Callback< T > callback )
inline

Subscribe to an event type.

Registers a callback that is invoked whenever the event type is emitted

Template Parameters
TThe event type to subscribe to
Parameters
callbackThe function that handles the event

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