aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/EventManager.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-20 18:48:18 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-20 18:48:18 +0100
commit9f882131f09410113d757d96e5aa0322aa5584bd (patch)
tree9ee5d3b3b8e83f3281797ec4c9c4be47dd603848 /src/crepe/api/EventManager.cpp
parent9a46acde813e00e574e70439795dedcdc9a8192a (diff)
git remake
Diffstat (limited to 'src/crepe/api/EventManager.cpp')
-rw-r--r--src/crepe/api/EventManager.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/src/crepe/api/EventManager.cpp b/src/crepe/api/EventManager.cpp
index 4f88e97..dbdb0c3 100644
--- a/src/crepe/api/EventManager.cpp
+++ b/src/crepe/api/EventManager.cpp
@@ -8,37 +8,39 @@ EventManager & EventManager::get_instance() {
}
void EventManager::dispatch_events() {
- for (auto event_it = this->events_queue.begin(); event_it != this->events_queue.end();) {
- std::unique_ptr<Event>& event = (*event_it).event;
- int channel = (*event_it).channel;
- std::type_index event_type = (*event_it).type;
-
- bool event_handled = false;
- auto handlers_it = this->subscribers.find(event_type);
- if (handlers_it != this->subscribers.end()) {
- std::vector<CallbackEntry>& handlers = handlers_it->second;
-
- std::sort(handlers.begin(), handlers.end(), [](const CallbackEntry& a, const CallbackEntry& b) {
- return a.priority > b.priority;
- });
-
- for (auto handler_it = handlers.begin(); handler_it != handlers.end(); ++handler_it) {
- // If callback is executed and returns true, remove the event from the queue
- if ((*handler_it).callback->exec(*event)) {
- event_it = this->events_queue.erase(event_it);
- event_handled = true;
- break;
- }
- }
- }
-
- if (!event_handled) {
- ++event_it;
- }
- }
+ for (auto event_it = this->events_queue.begin(); event_it != this->events_queue.end();) {
+ std::unique_ptr<Event> & event = (*event_it).event;
+ int channel = (*event_it).channel;
+ std::type_index event_type = (*event_it).type;
+
+ bool event_handled = false;
+ auto handlers_it = this->subscribers.find(event_type);
+ if (handlers_it != this->subscribers.end()) {
+ std::vector<CallbackEntry> & handlers = handlers_it->second;
+
+ std::sort(handlers.begin(), handlers.end(),
+ [](const CallbackEntry & a, const CallbackEntry & b) {
+ return a.priority > b.priority;
+ });
+
+ for (auto handler_it = handlers.begin(); handler_it != handlers.end();
+ ++handler_it) {
+ // If callback is executed and returns true, remove the event from the queue
+ if ((*handler_it).callback->exec(*event)) {
+ event_it = this->events_queue.erase(event_it);
+ event_handled = true;
+ break;
+ }
+ }
+ }
+
+ if (!event_handled) {
+ ++event_it;
+ }
+ }
}
-void EventManager::clear(){
+void EventManager::clear() {
this->subscribers.clear();
this->events_queue.clear();
}