21 template <
typename Tevent>
22 using event_callback = std::function<bool(Tevent &)>;
23 using base_event_callback = std::function<bool(
event &)>;
24 using callback_list = std::vector<base_event_callback>;
27 static std::map<string_id, callback_list> EventHandlers;
37 template <
typename Tevent>
40 auto event_handlers = EventHandlers.find(Tevent::StaticType);
41 if (event_handlers == EventHandlers.end())
42 EventHandlers.emplace(Tevent::StaticType, std::vector { std::move(EventCallback) });
44 event_handlers->second.push_back(std::move(EventCallback));
54 template <
typename Tevent>
57 AddEventListner<Tevent>([callback = std::move(EventCallback)](
event &Event)
59 if (Event.
GetType() != Tevent::StaticType)
return false;
60 return callback(
static_cast<Tevent &
>(Event));
71 template <
typename Tevent>
74 std::map<string_id, callback_list>::iterator event_handlers = EventHandlers.find(Event.GetType());
75 if (event_handlers == EventHandlers.end())
return;
77 for (
const auto &callback : event_handlers->second)
79 Event.Handled |= callback(Event);
80 if (Event.Handled)
break;
static void AddEventListner(std::function< bool(Tevent &)> &&EventCallback)
static void AddEventListner(base_event_callback &&EventCallback)
static void Invoke(Tevent &Event)
virtual u32 GetType() const =0
String id generating by CRC32 algoritm implemetation module. Can be used both in compiletime anr runt...