19#ifndef ENGINE_EVENTSYSTEM_H
20#define ENGINE_EVENTSYSTEM_H
22#include <open-cpp-utils/unique_id.h>
29#define MAX_EVENT_TYPES 256
31namespace ocu = open_cpp_utils;
33namespace OpenShaderDesigner
42 static uint8_t TypeOf() {
return static_cast<uint8_t
>(ocu::unique_id<uint8_t, T>()); }
48 virtual inline uint8_t
GetID()
const = 0;
57 virtual bool _HandleEvent(
const Event* event) = 0;
66template<
typename EventType>
83 bool _HandleEvent(
const Event* event)
override;
112 inline static std::list<_ImplEventHandler*> HandlerMap_[MAX_EVENT_TYPES];
113 inline static std::mutex Lock_;
123 std::lock_guard guard(Lock_);
124 const uint8_t index = T::ID;
132 std::lock_guard guard(Lock_);
133 const uint8_t index = T::ID;
137template<
typename EventType>
140 if(EventType::ID != event->
GetID())
return false;
141 return HandleEvent(
reinterpret_cast<const EventType*
>(event));
146#define BeginEvent(EVENT) struct EVENT : OpenShaderDesigner::Event \
148 static inline const uint8_t ID = Event::TypeOf<EVENT>(); \
149 inline uint8_t GetID() const override { return ID; }
Base EventHandler for abstraction.
Definition EventSystem.h:56
EventHandler interface for creating custom EventHandlers.
Definition EventSystem.h:68
virtual bool HandleEvent(const HandledType *event)=0
Virtual function for custom EventHandler implementations.
EventType HandledType
The type handled by the EventHandler.
Definition EventSystem.h:70
EventSystem for posting Events to be handled.
Definition EventSystem.h:90
static void UnregisterHandler(EventHandler< T > *)
Unregister an EventHandler with the EventSystem.
Definition EventSystem.h:120
static void PostEvent(const Event *)
Post an Event to be Handled.
Definition EventSystem.cpp:26
static void RegisterHandler(EventHandler< T > *)
Register an EventHandler with the EventSystem.
Definition EventSystem.h:129
Base Event class for sending events to the Engine.
Definition EventSystem.h:40
virtual uint8_t GetID() const =0
Get the Event's type ID.