Berserk
Classes | Public Types | Public Member Functions | Friends | List of all members
EventDispatcher Class Referencefinal

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
 

Detailed Description

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.

Member Typedef Documentation

◆ Handle

Handle to identify subscribed listener function entry

◆ ListenerFunc

using EventDispatcher::ListenerFunc = std::function<bool(const Event &)>

Function type to subscribe listener

Member Function Documentation

◆ Dispatch()

void EventDispatcher::Dispatch ( const Ref< Event > &  event)

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.

Note
Must be called from game thread
Parameters
eventEvent to dispatch; must be not null

◆ Pause()

void EventDispatcher::Pause ( EventDispatcher::Handle  handle)

Pause listening for events of specified listener by handle.

Note
Must be called from game thread
Parameters
handleHandle of subscribed listener

◆ Resume()

void EventDispatcher::Resume ( EventDispatcher::Handle  handle)

Resume listening for events of specified listener by handle.

Note
Must be called from game thread
Parameters
handleHandle of subscribed listener

◆ Subscribe()

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.

Note
Must be called from game thread
Parameters
eventTypeType of the event to listen to
funcFunction of the listener to call on event
pausedPass true if paused; not accept events until paused is set to false
Returns
Handle of subscribed listener

◆ Unsubscribe()

void EventDispatcher::Unsubscribe ( EventDispatcher::Handle  handle)

Unsubscribe listener associated with specified handle.

Note
Must be called from game thread
Parameters
handleHandle of subscribed listener

Friends And Related Function Documentation

◆ Engine

friend class Engine
friend

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