diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-18 15:40:11 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-18 15:40:11 +0100 |
commit | 71a614e1f87141c4d062a2a466377322fc3d9ff0 (patch) | |
tree | 018f9007cfbe04d95716c5bde3ce3d5c73659fe1 /src/crepe/api | |
parent | b92da3c729c8fc7c002cb3acbb75c56cb63bd89e (diff) |
make format
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/EventHandler.hpp | 3 | ||||
-rw-r--r-- | src/crepe/api/EventManager.cpp | 15 | ||||
-rw-r--r-- | src/crepe/api/EventManager.h | 9 | ||||
-rw-r--r-- | src/crepe/api/EventManager.hpp | 22 | ||||
-rw-r--r-- | src/crepe/api/IKeyListener.cpp | 20 | ||||
-rw-r--r-- | src/crepe/api/IKeyListener.h | 2 | ||||
-rw-r--r-- | src/crepe/api/IMouseListener.cpp | 41 | ||||
-rw-r--r-- | src/crepe/api/IMouseListener.h | 1 |
8 files changed, 45 insertions, 68 deletions
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 <typename EventType> -EventHandlerWrapper<EventType>::EventHandlerWrapper( - const EventHandler<EventType> & handler) +EventHandlerWrapper<EventType>::EventHandlerWrapper(const EventHandler<EventType> & 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<std::unique_ptr<IEventHandlerWrapper>>>; + using HandlersMap + = std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; using HandlersVec = std::vector<std::unique_ptr<IEventHandlerWrapper>>; - 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> & 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<std::tuple<std::unique_ptr<Event>, int, std::type_index>> - events_queue; + std::vector<std::tuple<std::unique_ptr<Event>, int, std::type_index>> events_queue; //! Registered event handlers. - std::unordered_map<std::type_index, - std::vector<std::unique_ptr<IEventHandlerWrapper>>> + std::unordered_map<std::type_index, std::vector<std::unique_ptr<IEventHandlerWrapper>>> subscribers; //! Event handlers indexed by event ID. std::unordered_map< std::type_index, - std::unordered_map<int, - std::vector<std::unique_ptr<IEventHandlerWrapper>>>> + std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>> 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 <typename EventType> void EventManager::subscribe(EventHandler<EventType> && callback, int channel) { - using HandlersMap = std::unordered_map< - int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; + using HandlersMap + = std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; using HandlersVec = std::vector<std::unique_ptr<IEventHandlerWrapper>>; std::type_index event_type = typeid(EventType); @@ -30,18 +30,17 @@ template <typename EventType> void EventManager::queue_event(EventType && event, int channel) { std::type_index event_type = std::type_index(typeid(EventType)); - auto event_ptr - = std::make_unique<EventType>(std::forward<EventType>(event)); + auto event_ptr = std::make_unique<EventType>(std::forward<EventType>(event)); - std::tuple<std::unique_ptr<Event>, int, std::type_index> tuple( - std::move(event_ptr), channel, event_type); + std::tuple<std::unique_ptr<Event>, int, std::type_index> tuple(std::move(event_ptr), + channel, event_type); this->events_queue.push_back(std::move(tuple)); } template <typename EventType> void EventManager::trigger_event(const EventType & event, int channel) { - using HandlersMap = std::unordered_map< - int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; + using HandlersMap + = std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; using HandlersVec = std::vector<std::unique_ptr<IEventHandlerWrapper>>; std::type_index event_type = std::type_index(typeid(EventType)); @@ -71,10 +70,9 @@ void EventManager::trigger_event(const EventType & event, int channel) { } template <typename EventType> -void EventManager::unsubscribe(const EventHandler<EventType> & callback, - int channel) { - using HandlersMap = std::unordered_map< - int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; +void EventManager::unsubscribe(const EventHandler<EventType> & callback, int channel) { + using HandlersMap + = std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; using HandlersVec = std::vector<std::unique_ptr<IEventHandlerWrapper>>; 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<KeyPressEvent>(std::move(this->key_pressed_handler), this->channel); - event_manager.subscribe<KeyReleaseEvent>( - std::move(this->key_released_handler), this->channel); + event_manager.subscribe<KeyReleaseEvent>(std::move(this->key_released_handler), + this->channel); } // Unsubscribe from key events void IKeyListener::unsubscribe_events() { - event_manager.unsubscribe<KeyPressEvent>(this->key_pressed_handler, - this->channel); - event_manager.unsubscribe<KeyReleaseEvent>(this->key_released_handler, - this->channel); + event_manager.unsubscribe<KeyPressEvent>(this->key_pressed_handler, this->channel); + event_manager.unsubscribe<KeyReleaseEvent>(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<MouseClickEvent>(std::move(mouse_click_handler), - this->channel); - event_manager.subscribe<MousePressEvent>(std::move(mouse_press_handler), - this->channel); + event_manager.subscribe<MouseClickEvent>(std::move(mouse_click_handler), this->channel); + event_manager.subscribe<MousePressEvent>(std::move(mouse_press_handler), this->channel); event_manager.subscribe<MouseReleaseEvent>(std::move(mouse_release_handler), this->channel); - event_manager.subscribe<MouseMoveEvent>(std::move(mouse_move_handler), - this->channel); + event_manager.subscribe<MouseMoveEvent>(std::move(mouse_move_handler), this->channel); } void IMouseListener::unsubscribe_events() { // Unsubscribe event handlers - event_manager.unsubscribe<MouseClickEvent>(mouse_click_handler, - this->channel); - event_manager.unsubscribe<MousePressEvent>(mouse_press_handler, - this->channel); - event_manager.unsubscribe<MouseReleaseEvent>(mouse_release_handler, - this->channel); - event_manager.unsubscribe<MouseMoveEvent>(mouse_move_handler, - this->channel); + event_manager.unsubscribe<MouseClickEvent>(mouse_click_handler, this->channel); + event_manager.unsubscribe<MousePressEvent>(mouse_press_handler, this->channel); + event_manager.unsubscribe<MouseReleaseEvent>(mouse_release_handler, this->channel); + event_manager.unsubscribe<MouseMoveEvent>(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. |