16#ifndef ENGINE_EVENTSYSTEM_H
17#define ENGINE_EVENTSYSTEM_H
19#include <open-cpp-utils/unique_id.h>
26#define MAX_EVENT_TYPES 256
28namespace ocu = open_cpp_utils;
30namespace OpenShaderDesigner
38 static uint8_t TypeOf() {
return static_cast<uint8_t
>(ocu::unique_id<uint8_t, T>()); }
44 virtual inline uint8_t
GetID()
const = 0;
53 virtual bool _HandleEvent(
const Event* event) = 0;
62 template<
typename EventType>
79 bool _HandleEvent(
const Event* event)
override;
108 inline static std::list<_ImplEventHandler*> HandlerMap[MAX_EVENT_TYPES];
109 inline static std::mutex Lock;
119 std::lock_guard guard(Lock);
120 const uint8_t index = T::ID;
128 std::lock_guard guard(Lock);
129 const uint8_t index = T::ID;
133 template<
typename EventType>
136 if(EventType::ID != event->
GetID())
return false;
137 return HandleEvent(
reinterpret_cast<const EventType*
>(event));
141#define BeginEvent(EVENT) struct EVENT : OpenShaderDesigner::Event \
143 static inline const uint8_t ID = Event::TypeOf<EVENT>(); \
144 inline uint8_t GetID() const override { return ID; }
Base EventHandler for abstraction.
Definition EventSystem.h:52
EventHandler interface for creating custom EventHandlers.
Definition EventSystem.h:64
virtual bool HandleEvent(const HandledType *event)=0
Virtual function for custom EventHandler implementations.
EventType HandledType
The type handled by the EventHandler.
Definition EventSystem.h:66
EventSystem for posting Events to be handled.
Definition EventSystem.h:86
static void UnregisterHandler(EventHandler< T > *)
Unregister an EventHandler with the EventSystem.
Definition EventSystem.h:116
static void PostEvent(const Event *)
Post an Event to be Handled.
Definition EventSystem.cpp:23
static void RegisterHandler(EventHandler< T > *)
Register an EventHandler with the EventSystem.
Definition EventSystem.h:125
Base Event class for sending events to the Engine.
Definition EventSystem.h:36
virtual uint8_t GetID() const =0
Get the Event's type ID.