From 5f76ad1dde34fc0cf7b8ea63befa8917da94fe5c Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 20 Nov 2024 16:35:58 +0100 Subject: save before big refactor --- src/crepe/api/EventManager.hpp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'src/crepe/api/EventManager.hpp') diff --git a/src/crepe/api/EventManager.hpp b/src/crepe/api/EventManager.hpp index 9090a3f..3a40336 100644 --- a/src/crepe/api/EventManager.hpp +++ b/src/crepe/api/EventManager.hpp @@ -4,26 +4,17 @@ namespace crepe { template void EventManager::subscribe(const EventHandler & callback, int channel, int priority) { - using HandlersMap - = std::unordered_map>>; - using HandlersVec = std::vector>; + using HandlersVec = std::vector; std::type_index event_type = typeid(EventType); std::unique_ptr> handler = std::make_unique>(callback); - - if (channel) { - HandlersMap & handlers_map = this->subscribers_by_event_id[event_type]; - auto handlers = handlers_map.find(channel); - if (handlers != handlers_map.end()) { - handlers->second.emplace_back(std::move(handler)); - } else { - handlers_map[channel].emplace_back(std::move(handler)); - } - } else { - HandlersVec & handlers = this->subscribers[event_type]; - handlers.emplace_back(std::move(handler)); - } + HandlersVec & handlers = this->subscribers[event_type]; + handlers.emplace_back(CallbackEntry{ + .callback = std::move(handler), + .channel = channel, + .priority = priority, + }); } template @@ -33,12 +24,12 @@ void EventManager::queue_event(const EventType & event, int channel,int priority auto event_ptr = std::make_unique(event); - this->events_queue.push_back( QueueEntry{ .event = std::move(event_ptr), .channel = channel, - .type = event_type + .type = event_type, + .priority = priority } ); } @@ -51,7 +42,7 @@ void EventManager::trigger_event(const EventType & event, int channel) { std::type_index event_type = typeid(EventType); - if (channel > 0) { + if (channel == CHANNEL_ALL) { HandlersMap & handlers_map = this->subscribers_by_event_id[event_type]; auto handlers_it = handlers_map.find(channel); -- cgit v1.2.3