aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/EventManager.cpp
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-06 10:44:42 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-06 10:44:42 +0100
commitd5f63024ebed7df2fff8e016bd1c7c26f8fdfa27 (patch)
treeb26e35cb0482d04a33cc96d97ba21c21d0012229 /src/crepe/api/EventManager.cpp
parent9cde6875186b335c75eafa6402f0957cd4252c76 (diff)
parent1f4e961d7f9d6887c807cac1a362f2d178b0860b (diff)
Merge branch 'master' into decoupling
Diffstat (limited to 'src/crepe/api/EventManager.cpp')
-rw-r--r--src/crepe/api/EventManager.cpp46
1 files changed, 0 insertions, 46 deletions
diff --git a/src/crepe/api/EventManager.cpp b/src/crepe/api/EventManager.cpp
deleted file mode 100644
index 20f0dd3..0000000
--- a/src/crepe/api/EventManager.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "EventManager.h"
-
-using namespace crepe;
-using namespace std;
-
-EventManager & EventManager::get_instance() {
- static EventManager instance;
- return instance;
-}
-
-void EventManager::dispatch_events() {
- for (auto & event : this->events_queue) {
- this->handle_event(event.type, event.channel, *event.event.get());
- }
- this->events_queue.clear();
-}
-
-void EventManager::handle_event(type_index type, event_channel_t channel, const Event & data) {
- auto handlers_it = this->subscribers.find(type);
- if (handlers_it == this->subscribers.end()) return;
-
- vector<CallbackEntry> & handlers = handlers_it->second;
- for (auto & handler : handlers) {
- bool check_channel = handler.channel != CHANNEL_ALL || channel != CHANNEL_ALL;
- if (check_channel && handler.channel != channel) continue;
-
- bool handled = handler.callback->exec(data);
- if (handled) return;
- }
-}
-
-void EventManager::clear() {
- this->subscribers.clear();
- this->events_queue.clear();
-}
-
-void EventManager::unsubscribe(subscription_t id) {
- for (auto & [event_type, handlers] : this->subscribers) {
- for (auto it = handlers.begin(); it != handlers.end(); it++) {
- // find listener with subscription id
- if ((*it).id != id) continue;
- it = handlers.erase(it);
- return;
- }
- }
-}