Broadcaster acts as ImagoEngine's event system. It lets systems communicate without knowing about eachother.
More...
#include <Imago/Engine/Broadcaster.hpp>
|
| template<typename T> |
| using | SystemFn = void (*)(SceneContext&, const T&) |
| | Function pointer to a system that recieves SceneContext and an EventType and returns nothing.
|
|
| | Broadcaster (SceneContext &ctx) |
| | Construct a new Broadcaster object with the current SceneContext.
|
|
| Broadcaster (const Broadcaster &)=delete |
|
Broadcaster & | operator= (const Broadcaster &)=delete |
|
| Broadcaster (Broadcaster &&)=delete |
|
Broadcaster & | operator= (Broadcaster &&)=delete |
| template<typename T> |
| void | emit (const T &event) |
| | Call every system subscribed to EventType T in subcription order.
|
| template<typename T> |
| void | subscribe (SystemFn< T > system) |
| | Adds the system function pointer to the list for EventType T. Called during scene initialization.
|
| template<typename T> |
| void | unsubscribe (SystemFn< T > system) |
| | Removes the system function pointer from the list for EventType T.
|
|
void | clear () |
| | Drops every subscription for every event type.
|
Broadcaster acts as ImagoEngine's event system. It lets systems communicate without knowing about eachother.
Subscribed systems subscribe to an event and the Broadcaster stores them as type-erased std::function<void(SceneContext&, const void*)> and their addresses in a Subscriber wrapper. When emit is called for that even the Broadcaster iterates through all the subscribers corresponding to that event and invokes them.
◆ SystemFn
Function pointer to a system that recieves SceneContext and an EventType and returns nothing.
- Template Parameters
-
◆ Broadcaster()
| Imago::Engine::Broadcaster::Broadcaster |
( |
SceneContext & | ctx | ) |
|
|
explicit |
◆ emit()
template<typename T>
| void Imago::Engine::Broadcaster::emit |
( |
const T & | event | ) |
|
Call every system subscribed to EventType T in subcription order.
emit<T>() simply does nothing if there are no systems subscribed to a particular event. It also increments _broadcast depth for every emit currently happening.
- Template Parameters
-
| The | Event Type data to broadcast |
- Parameters
-
◆ subscribe()
template<typename T>
| void Imago::Engine::Broadcaster::subscribe |
( |
SystemFn< T > | system | ) |
|
Adds the system function pointer to the list for EventType T. Called during scene initialization.
- Template Parameters
-
- Parameters
-
| system | The function pointer to the system that is subscribing. |
◆ unsubscribe()
template<typename T>
| void Imago::Engine::Broadcaster::unsubscribe |
( |
SystemFn< T > | system | ) |
|
Removes the system function pointer from the list for EventType T.
This preserves the order of the remaining subscribers. It finds the specific system to unsubscribe from by comparing the ErasedFn address to the one's of those in the event list.
- Template Parameters
-
| The | Event to unsubscribe from. |
- Parameters
-
| system | The function pointer to the system that is unsubscribing. |
The documentation for this class was generated from the following files:
- engine/include/Imago/Engine/Broadcaster.hpp
- engine/src/Engine/Broadcaster.cpp