From 71a614e1f87141c4d062a2a466377322fc3d9ff0 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 18 Nov 2024 15:40:11 +0100 Subject: make format --- src/crepe/api/EventHandler.hpp | 3 +-- src/crepe/api/EventManager.cpp | 15 +++++++-------- src/crepe/api/EventManager.h | 9 +++------ src/crepe/api/EventManager.hpp | 22 ++++++++++----------- src/crepe/api/IKeyListener.cpp | 20 ++++++++------------ src/crepe/api/IKeyListener.h | 2 +- src/crepe/api/IMouseListener.cpp | 41 +++++++++++++++------------------------- src/crepe/api/IMouseListener.h | 1 - 8 files changed, 45 insertions(+), 68 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/api/EventHandler.hpp b/src/crepe/api/EventHandler.hpp index 564d3d7..9c47da2 100644 --- a/src/crepe/api/EventHandler.hpp +++ b/src/crepe/api/EventHandler.hpp @@ -7,8 +7,7 @@ namespace crepe { // Implementation of EventHandlerWrapper constructor template -EventHandlerWrapper::EventHandlerWrapper( - const EventHandler & handler) +EventHandlerWrapper::EventHandlerWrapper(const EventHandler & handler) : m_handler(handler), m_handler_type(m_handler.target_type().name()) {} diff --git a/src/crepe/api/EventManager.cpp b/src/crepe/api/EventManager.cpp index 7f47938..b465e89 100644 --- a/src/crepe/api/EventManager.cpp +++ b/src/crepe/api/EventManager.cpp @@ -8,12 +8,11 @@ EventManager & EventManager::get_instance() { } void EventManager::dispatch_events() { - using HandlersMap = std::unordered_map< - int, std::vector>>; + using HandlersMap + = std::unordered_map>>; using HandlersVec = std::vector>; - for (auto event_it = this->events_queue.begin(); - event_it != this->events_queue.end();) { + for (auto event_it = this->events_queue.begin(); event_it != this->events_queue.end();) { std::unique_ptr & event = std::get<0>(*event_it); int channel = std::get<1>(*event_it); std::type_index event_type = std::get<2>(*event_it); @@ -27,8 +26,8 @@ void EventManager::dispatch_events() { auto handlers = handlers_map.find(channel); if (handlers != handlers_map.end()) { HandlersVec & callbacks = handlers->second; - for (auto handler_it = callbacks.begin(); - handler_it != callbacks.end(); ++handler_it) { + for (auto 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; @@ -42,8 +41,8 @@ void EventManager::dispatch_events() { auto handlers_it = this->subscribers.find(event_type); if (handlers_it != this->subscribers.end()) { HandlersVec & handlers = handlers_it->second; - for (auto handler_it = handlers.begin(); - handler_it != handlers.end(); ++handler_it) { + for (auto handler_it = handlers.begin(); handler_it != handlers.end(); + ++handler_it) { // remove event from queue since and continue when callback returns true if ((*handler_it)->exec(*event)) { event_it = this->events_queue.erase(event_it); diff --git a/src/crepe/api/EventManager.h b/src/crepe/api/EventManager.h index 783db62..c7c4744 100644 --- a/src/crepe/api/EventManager.h +++ b/src/crepe/api/EventManager.h @@ -94,17 +94,14 @@ private: EventManager() = default; //! The queue of events to be processed. - std::vector, int, std::type_index>> - events_queue; + std::vector, int, std::type_index>> events_queue; //! Registered event handlers. - std::unordered_map>> + std::unordered_map>> subscribers; //! Event handlers indexed by event ID. std::unordered_map< std::type_index, - std::unordered_map>>> + std::unordered_map>>> subscribers_by_event_id; }; diff --git a/src/crepe/api/EventManager.hpp b/src/crepe/api/EventManager.hpp index d901492..b20b88f 100644 --- a/src/crepe/api/EventManager.hpp +++ b/src/crepe/api/EventManager.hpp @@ -4,8 +4,8 @@ namespace crepe { template void EventManager::subscribe(EventHandler && callback, int channel) { - using HandlersMap = std::unordered_map< - int, std::vector>>; + using HandlersMap + = std::unordered_map>>; using HandlersVec = std::vector>; std::type_index event_type = typeid(EventType); @@ -30,18 +30,17 @@ template void EventManager::queue_event(EventType && event, int channel) { std::type_index event_type = std::type_index(typeid(EventType)); - auto event_ptr - = std::make_unique(std::forward(event)); + auto event_ptr = std::make_unique(std::forward(event)); - std::tuple, int, std::type_index> tuple( - std::move(event_ptr), channel, event_type); + std::tuple, int, std::type_index> tuple(std::move(event_ptr), + channel, event_type); this->events_queue.push_back(std::move(tuple)); } template void EventManager::trigger_event(const EventType & event, int channel) { - using HandlersMap = std::unordered_map< - int, std::vector>>; + using HandlersMap + = std::unordered_map>>; using HandlersVec = std::vector>; std::type_index event_type = std::type_index(typeid(EventType)); @@ -71,10 +70,9 @@ void EventManager::trigger_event(const EventType & event, int channel) { } template -void EventManager::unsubscribe(const EventHandler & callback, - int channel) { - using HandlersMap = std::unordered_map< - int, std::vector>>; +void EventManager::unsubscribe(const EventHandler & callback, int channel) { + using HandlersMap + = std::unordered_map>>; using HandlersVec = std::vector>; std::type_index event_type(typeid(EventType)); diff --git a/src/crepe/api/IKeyListener.cpp b/src/crepe/api/IKeyListener.cpp index cd255df..f5426be 100644 --- a/src/crepe/api/IKeyListener.cpp +++ b/src/crepe/api/IKeyListener.cpp @@ -23,25 +23,21 @@ IKeyListener::~IKeyListener() { this->unsubscribe_events(); } // Subscribe to key events void IKeyListener::subscribe_events() { - key_pressed_handler = [this](const KeyPressEvent & event) { - return this->on_key_pressed(event); - }; - key_released_handler = [this](const KeyReleaseEvent & event) { - return this->on_key_released(event); - }; + key_pressed_handler + = [this](const KeyPressEvent & event) { return this->on_key_pressed(event); }; + key_released_handler + = [this](const KeyReleaseEvent & event) { return this->on_key_released(event); }; event_manager.subscribe(std::move(this->key_pressed_handler), this->channel); - event_manager.subscribe( - std::move(this->key_released_handler), this->channel); + event_manager.subscribe(std::move(this->key_released_handler), + this->channel); } // Unsubscribe from key events void IKeyListener::unsubscribe_events() { - event_manager.unsubscribe(this->key_pressed_handler, - this->channel); - event_manager.unsubscribe(this->key_released_handler, - this->channel); + event_manager.unsubscribe(this->key_pressed_handler, this->channel); + event_manager.unsubscribe(this->key_released_handler, this->channel); } // Activate key listening diff --git a/src/crepe/api/IKeyListener.h b/src/crepe/api/IKeyListener.h index 3e0e2cb..d492387 100644 --- a/src/crepe/api/IKeyListener.h +++ b/src/crepe/api/IKeyListener.h @@ -22,7 +22,7 @@ public: IKeyListener(const IKeyListener &) = delete; IKeyListener & operator=(const IKeyListener &) = delete; IKeyListener(IKeyListener &&) = delete; - + /** * \brief Pure virtual function to handle key press events. * \param event The key press event to handle. diff --git a/src/crepe/api/IMouseListener.cpp b/src/crepe/api/IMouseListener.cpp index bfa49f8..5ee2814 100644 --- a/src/crepe/api/IMouseListener.cpp +++ b/src/crepe/api/IMouseListener.cpp @@ -16,40 +16,29 @@ IMouseListener::~IMouseListener() { this->unsubscribe_events(); } void IMouseListener::subscribe_events() { // Define handler lambdas and subscribe them - mouse_click_handler = [this](const MouseClickEvent & event) { - return this->on_mouse_clicked(event); - }; - mouse_press_handler = [this](const MousePressEvent & event) { - return this->on_mouse_pressed(event); - }; - mouse_release_handler = [this](const MouseReleaseEvent & event) { - return this->on_mouse_released(event); - }; - mouse_move_handler = [this](const MouseMoveEvent & event) { - return this->on_mouse_moved(event); - }; + mouse_click_handler + = [this](const MouseClickEvent & event) { return this->on_mouse_clicked(event); }; + mouse_press_handler + = [this](const MousePressEvent & event) { return this->on_mouse_pressed(event); }; + mouse_release_handler + = [this](const MouseReleaseEvent & event) { return this->on_mouse_released(event); }; + mouse_move_handler + = [this](const MouseMoveEvent & event) { return this->on_mouse_moved(event); }; // Subscribe event handlers (no need for std::move) - event_manager.subscribe(std::move(mouse_click_handler), - this->channel); - event_manager.subscribe(std::move(mouse_press_handler), - this->channel); + event_manager.subscribe(std::move(mouse_click_handler), this->channel); + event_manager.subscribe(std::move(mouse_press_handler), this->channel); event_manager.subscribe(std::move(mouse_release_handler), this->channel); - event_manager.subscribe(std::move(mouse_move_handler), - this->channel); + event_manager.subscribe(std::move(mouse_move_handler), this->channel); } void IMouseListener::unsubscribe_events() { // Unsubscribe event handlers - event_manager.unsubscribe(mouse_click_handler, - this->channel); - event_manager.unsubscribe(mouse_press_handler, - this->channel); - event_manager.unsubscribe(mouse_release_handler, - this->channel); - event_manager.unsubscribe(mouse_move_handler, - this->channel); + event_manager.unsubscribe(mouse_click_handler, this->channel); + event_manager.unsubscribe(mouse_press_handler, this->channel); + event_manager.unsubscribe(mouse_release_handler, this->channel); + event_manager.unsubscribe(mouse_move_handler, this->channel); } void IMouseListener::activate_mouse() { diff --git a/src/crepe/api/IMouseListener.h b/src/crepe/api/IMouseListener.h index 2ec156f..c315c35 100644 --- a/src/crepe/api/IMouseListener.h +++ b/src/crepe/api/IMouseListener.h @@ -12,7 +12,6 @@ namespace crepe { */ class IMouseListener { public: - IMouseListener(); /** * \brief Constructs an IMouseListener with a specified channel. -- cgit v1.2.3