|
Berserk
|
Event dispatcher is responsible for managing engine events. More...
#include <EventDispatcher.hpp>
Public Types | |
| using | ListenerFunc = std::function< bool(const Event &)> |
| using | Handle = size_t |
Public Member Functions | |
| BRK_API void | Dispatch (const Ref< Event > &event) |
| Dispatch new event to listeners. More... | |
| BRK_API Handle | Subscribe (const EventType &eventType, ListenerFunc func, bool paused=false) |
| Subscribe listener function to specified event type. More... | |
| BRK_API void | Unsubscribe (Handle handle) |
| Unsubscribe listener associated with specified handle. More... | |
| BRK_API void | Pause (Handle handle) |
| Pause listening for events of specified listener by handle. More... | |
| BRK_API void | Resume (Handle handle) |
| Resume listening for events of specified listener by handle. More... | |
Friends | |
| class | Engine |
Event dispatcher is responsible for managing engine events.
Use this class to:
Event dispatcher provides handlers for subscribed functions, so parameters and execution can be tweaked after subscription.
| using EventDispatcher::Handle = size_t |
Handle to identify subscribed listener function entry
| using EventDispatcher::ListenerFunc = std::function<bool(const Event &)> |
Function type to subscribe listener
Dispatch new event to listeners.
Dispatches provided event to subscribed listeners of this event type. Event type if defined from event overridden Event::GetEventType() function. Event is not dispatched immediately, instead it is queued to be dispatched later. It is safe to dispatch events inside listeners, while responding on incoming event.
| event | Event to dispatch; must be not null |
| void EventDispatcher::Pause | ( | EventDispatcher::Handle | handle | ) |
Pause listening for events of specified listener by handle.
| handle | Handle of subscribed listener |
| void EventDispatcher::Resume | ( | EventDispatcher::Handle | handle | ) |
Resume listening for events of specified listener by handle.
| handle | Handle of subscribed listener |
| EventDispatcher::Handle EventDispatcher::Subscribe | ( | const EventType & | eventType, |
| EventDispatcher::ListenerFunc | func, | ||
| bool | paused = false |
||
| ) |
Subscribe listener function to specified event type.
The listener function will be called for each new dispatched event of specified type eventType. If listener is set paused, then it won't receive events, until it is resumed. Listener is identified by returned handle. Use this handle further to tweak subscribed listener.
| eventType | Type of the event to listen to |
| func | Function of the listener to call on event |
| paused | Pass true if paused; not accept events until paused is set to false |
| void EventDispatcher::Unsubscribe | ( | EventDispatcher::Handle | handle | ) |
Unsubscribe listener associated with specified handle.
| handle | Handle of subscribed listener |
|
friend |