#include "EventManager.h" // void EventManager::unsubscribe(std::type_index eventType, const std::string & handlerName, // int eventId) { // if (eventId) { // std::unordered_map< // std::type_index, std::unordered_map< // int, std::vector>>>::iterator subscriber_list = subscribers_by_event_id.find(eventType); // if (subscriber_list != subscribers_by_event_id.end()) { // std::unordered_map< // int, std::vector>> & // handlers_map // = subscriber_list->second; // std::unordered_map< // int, // std::vector>>::iterator // handlers // = handlers_map.find(eventId); // if (handlers != handlers_map.end()) { // std::vector> & callbacks // = handlers->second; // for (std::vector< // std::unique_ptr>::iterator it // = callbacks.begin(); // it != callbacks.end(); ++it) { // if (it->get()->get_type() == handlerName) { // it = callbacks.erase(it); // return; // } // } // } // } // } else { // std::unordered_map< // std::type_index, std::vector>>::iterator // handlers_it // = subscribers.find(eventType); // if (handlers_it != subscribers.end()) { // std::vector> & handlers // = handlers_it->second; // for (std::vector>::iterator it // = handlers.begin(); // it != handlers.end(); ++it) { // if (it->get()->get_type() == handlerName) { // it = handlers.erase(it); // return; // } // } // } // } // } void EventManager::queue_event(std::unique_ptr && event_, int eventId) { events_queue.emplace_back(std::move(event_), eventId); } void EventManager::dispatch_events() { for (std::vector, int>>::iterator event_it = events_queue.begin(); event_it != events_queue.end();) { bool handled = false; if (!handled) { trigger_event(*event_it->first.get(), event_it->second); event_it = events_queue.erase(event_it); } else { ++event_it; } } }