From 774d7eab64108a8537c0d0db02744f8a11fa4618 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Dec 2020 10:25:10 -0500 Subject: [PATCH 1/5] mouse_input: Remove unused includes --- src/input_common/mouse/mouse_input.cpp | 3 --- src/input_common/mouse/mouse_input.h | 7 +++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index d0ee64ad75..055924087b 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp @@ -2,9 +2,6 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include "common/logging/log.h" -#include "common/math_util.h" -#include "common/param_package.h" #include "input_common/mouse/mouse_input.h" namespace MouseInput { diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 761663334b..6fc95a49e8 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h @@ -4,15 +4,14 @@ #pragma once -#include -#include +#include #include #include -#include + #include "common/common_types.h" #include "common/threadsafe_queue.h" +#include "common/vector_math.h" #include "core/frontend/input.h" -#include "input_common/main.h" #include "input_common/motion_input.h" namespace MouseInput { From 5842a767a99c07317ff6ef7771e129306c347a4c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Dec 2020 10:26:50 -0500 Subject: [PATCH 2/5] mouse_input: Resolve a -Wdocumentation warning --- src/input_common/mouse/mouse_input.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 6fc95a49e8..65e64bee76 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h @@ -49,7 +49,7 @@ public: * Signals that a button is pressed. * @param x the x-coordinate of the cursor * @param y the y-coordinate of the cursor - * @param button the button pressed + * @param button_ the button pressed */ void PressButton(int x, int y, int button_); From 395997178ba3f918671bc665fc7d8392f2e87ccd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Dec 2020 10:30:49 -0500 Subject: [PATCH 3/5] mouse_input: Remove two casts and amend some formatting Removes the use of two static casts and improves the readability of some vectors slightly. --- src/input_common/mouse/mouse_input.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index 055924087b..b23a7f1cc4 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp @@ -21,8 +21,11 @@ void Mouse::UpdateThread() { constexpr int update_time = 10; while (update_thread_running) { for (MouseInfo& info : mouse_info) { - Common::Vec3f angular_direction = {-info.tilt_direction.y, 0.0f, - -info.tilt_direction.x}; + const Common::Vec3f angular_direction{ + -info.tilt_direction.y, + 0.0f, + -info.tilt_direction.x, + }; info.motion.SetGyroscope(angular_direction * info.tilt_speed); info.motion.UpdateRotation(update_time * 1000); @@ -46,14 +49,14 @@ void Mouse::UpdateYuzuSettings() { } void Mouse::PressButton(int x, int y, int button_) { - if (button_ >= static_cast(mouse_info.size())) { + const auto button_index = static_cast(button_); + if (button_index >= mouse_info.size()) { return; } - int button = 1 << button_; - const auto button_index = static_cast(button_); + const auto button = 1U << button_index; buttons |= static_cast(button); - last_button = static_cast(button_); + last_button = static_cast(button_index); mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); @@ -63,8 +66,8 @@ void Mouse::PressButton(int x, int y, int button_) { void Mouse::MouseMove(int x, int y) { for (MouseInfo& info : mouse_info) { if (info.data.pressed) { - auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; - auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; + const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; + const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; info.last_mouse_position = Common::MakeVec(x, y); info.data.axis = {mouse_move.x, -mouse_move.y}; @@ -79,12 +82,12 @@ void Mouse::MouseMove(int x, int y) { } void Mouse::ReleaseButton(int button_) { - if (button_ >= static_cast(mouse_info.size())) { + const auto button_index = static_cast(button_); + if (button_index >= mouse_info.size()) { return; } - int button = 1 << button_; - const auto button_index = static_cast(button_); + const auto button = 1U << button_index; buttons &= static_cast(0xFF - button); mouse_info[button_index].tilt_speed = 0; From 16aadcc35430261216aee55732c1580139117ee4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Dec 2020 10:32:57 -0500 Subject: [PATCH 4/5] mouse_input: Invert conditional in UpdateYuzuSettings() Allows the struct to be constructed in place. --- src/input_common/mouse/mouse_input.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index b23a7f1cc4..10786a5413 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp @@ -41,11 +41,13 @@ void Mouse::UpdateThread() { } void Mouse::UpdateYuzuSettings() { - MouseStatus pad_status{}; - if (buttons != 0) { - pad_status.button = last_button; - mouse_queue.Push(pad_status); + if (buttons == 0) { + return; } + + mouse_queue.Push(MouseStatus{ + .button = last_button, + }); } void Mouse::PressButton(int x, int y, int button_) { From 424bffcd3f46b0ef30e73518b02045a443b5f1a1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Dec 2020 10:34:20 -0500 Subject: [PATCH 5/5] mouse_poller: Remove unused includes --- src/input_common/mouse/mouse_poller.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp index 6213f3dbdb..7445ad3ade 100644 --- a/src/input_common/mouse/mouse_poller.cpp +++ b/src/input_common/mouse/mouse_poller.cpp @@ -2,11 +2,9 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include -#include #include #include -#include "common/assert.h" + #include "common/threadsafe_queue.h" #include "input_common/mouse/mouse_input.h" #include "input_common/mouse/mouse_poller.h"