KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::EventDispatcher Class Reference

Class for dispatching events. More...

#include <Event.h>

Public Member Functions

 EventDispatcher (Event &event)
 A constructor.
 
template<typename T>
bool Dispatch (EventFn< T > func)
 Routine for dispatching Events.
 

Detailed Description

Class for dispatching events.

Constructor & Destructor Documentation

◆ EventDispatcher()

Karma::EventDispatcher::EventDispatcher ( Event & event)
inline

A constructor.

Parameters
eventReference to an Event
Since
Karma 1.0.0

Member Function Documentation

◆ Dispatch()

template<typename T>
bool Karma::EventDispatcher::Dispatch ( EventFn< T > func)
inline

Routine for dispatching Events.

For a demonstration see the line

dispatcher.Dispatch<MouseButtonPressedEvent>(KR_BIND_EVENT_FN(KarmaGuiLayer::OnMouseButtonPressedEvent));
#define KR_BIND_EVENT_FN(fn)
Macro for std::bind routine. See https://en.cppreference.com/w/cpp/utility/functional/bind.
Definition Core.h:112
Event triggered when the mouse button is pressed.
Definition MouseEvent.h:136

where KR_BIND_EVENT_FN is defined like so

#define KR_BIND_EVENT_FN(fn) std::bind(&fn, this, std::placeholders::_1)

Hence, we see that the dispatch function, usually called in OnEvent(), allows the execution of the bounded function (EventFn) with the supplied Event.

A way to read dispatcher call is like so

"I am present in so class with such routine (fn), hence I am dispatching supplied Event with a bounded function (KR_BIND_EVENT_FN(fn)) to be executed"

Note
GLFW calls the Application::OnEvent which further calls the OnEvent function in the subsequent layers and, depending on m_Handled, the depth of the call chain (measured in the sense of for-loop, upon the ordered layers) is determined.
See also
Application::OnEvent(Event& e)
Since
Karma 1.0.0

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