Manages subscribing, dispatching, and creating events.
More...
#include <event.hpp>
|
| template<typename T> |
| using | Callback = std::function<void(World&, const T&)> |
| | Function signature for event callbacks.
|
|
| 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.
|
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.
◆ Callback
Function signature for event callbacks.
- Template Parameters
-
◆ 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
-
- Parameters
-
◆ 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
-
| T | The event type to subscribe to |
- Parameters
-
| callback | The function that handles the event |
The documentation for this class was generated from the following file: