aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/EventManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api/EventManager.cpp')
-rw-r--r--src/crepe/api/EventManager.cpp36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/crepe/api/EventManager.cpp b/src/crepe/api/EventManager.cpp
index 3d8558b..872c6eb 100644
--- a/src/crepe/api/EventManager.cpp
+++ b/src/crepe/api/EventManager.cpp
@@ -1,24 +1,22 @@
#include "EventManager.h"
-
-
void EventManager::dispatch_events() {
- for (auto event_it = events_queue.begin(); event_it != events_queue.end();) {
- auto& event = std::get<0>(*event_it);
- int channel = std::get<1>(*event_it);
- std::type_index event_type = std::get<2>(*event_it);
+ for (std::vector<std::tuple<std::unique_ptr<Event>, int, std::type_index>>::iterator event_it = this->events_queue.begin(); event_it != this->events_queue.end();) {
+ std::unique_ptr<Event>& event = std::get<0>(*event_it);
+ int channel = std::get<1>(*event_it);
+ std::type_index event_type = std::get<2>(*event_it);
bool event_handled = false;
if (channel) {
- auto handlers_it = subscribers_by_event_id.find(event_type);
+ std::unordered_map<std::type_index, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>::iterator handlers_it = subscribers_by_event_id.find(event_type);
if (handlers_it != subscribers_by_event_id.end()) {
- auto& handlers_map = handlers_it->second;
- auto handlers = handlers_map.find(channel);
+ std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>& handlers_map = handlers_it->second;
+ std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator handlers = handlers_map.find(channel);
if (handlers != handlers_map.end()) {
- auto& callbacks = handlers->second;
- for (auto& handler : callbacks) {
- if (handler->exec(*event)) {
+ std::vector<std::unique_ptr<IEventHandlerWrapper>>& callbacks = handlers->second;
+ for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::iterator handler_it = callbacks.begin(); handler_it != callbacks.end(); ++handler_it) {
+ if ((*handler_it)->exec(*event)) {
event_it = events_queue.erase(event_it);
event_handled = true;
break;
@@ -28,12 +26,12 @@ void EventManager::dispatch_events() {
}
} else {
// Handle event for all channels
- auto handlers_it = subscribers.find(event_type);
- if (handlers_it != subscribers.end()) {
- auto& handlers = handlers_it->second;
- for (auto& handler : handlers) {
- if (handler->exec(*event)) {
- event_it = events_queue.erase(event_it);
+ std::unordered_map<std::type_index, std::vector<std::unique_ptr<IEventHandlerWrapper>>>::iterator handlers_it = this->subscribers.find(event_type);
+ if (handlers_it != this->subscribers.end()) {
+ std::vector<std::unique_ptr<IEventHandlerWrapper>>& handlers = handlers_it->second;
+ for (std::vector<std::unique_ptr<IEventHandlerWrapper>>::iterator handler_it = handlers.begin(); handler_it != handlers.end(); ++handler_it) {
+ if ((*handler_it)->exec(*event)) {
+ event_it = this->events_queue.erase(event_it);
event_handled = true;
break;
}
@@ -46,5 +44,3 @@ void EventManager::dispatch_events() {
}
}
}
-
-