diff --git a/rpcs3/Input/mouse_gyro_handler.cpp b/rpcs3/Input/mouse_gyro_handler.cpp index 6f1c7cd637..e1b241f9cd 100644 --- a/rpcs3/Input/mouse_gyro_handler.cpp +++ b/rpcs3/Input/mouse_gyro_handler.cpp @@ -1,3 +1,4 @@ +#include "stdafx.h" #include "mouse_gyro_handler.h" #include @@ -7,53 +8,57 @@ #include +LOG_CHANNEL(gui_log, "GUI"); + void mouse_gyro_handler::clear() { - active = false; - reset = false; - gyro_x = DEFAULT_MOTION_X; - gyro_y = DEFAULT_MOTION_Y; - gyro_z = DEFAULT_MOTION_Z; + m_active = false; + m_reset = false; + m_gyro_x = DEFAULT_MOTION_X; + m_gyro_y = DEFAULT_MOTION_Y; + m_gyro_z = DEFAULT_MOTION_Z; } bool mouse_gyro_handler::toggle_enabled() { - enabled = !enabled; + m_enabled = !m_enabled; clear(); - return enabled; + return m_enabled; } void mouse_gyro_handler::set_gyro_active() { - active = true; + gui_log.notice("Mouse-based gyro activated"); + m_active = true; } void mouse_gyro_handler::set_gyro_reset() { - active = false; - reset = true; + gui_log.notice("Mouse-based gyro deactivated"); + m_active = false; + m_reset = true; } void mouse_gyro_handler::set_gyro_xz(s32 off_x, s32 off_y) { - if (!active) + if (!m_active) return; - gyro_x = static_cast(std::clamp(off_x, 0, DEFAULT_MOTION_X * 2 - 1)); - gyro_z = static_cast(std::clamp(off_y, 0, DEFAULT_MOTION_Z * 2 - 1)); + m_gyro_x = static_cast(std::clamp(off_x, 0, DEFAULT_MOTION_X * 2 - 1)); + m_gyro_z = static_cast(std::clamp(off_y, 0, DEFAULT_MOTION_Z * 2 - 1)); } void mouse_gyro_handler::set_gyro_y(s32 steps) { - if (!active) + if (!m_active) return; - gyro_y = static_cast(std::clamp(gyro_y + steps, 0, DEFAULT_MOTION_Y * 2 - 1)); + m_gyro_y = static_cast(std::clamp(m_gyro_y + steps, 0, DEFAULT_MOTION_Y * 2 - 1)); } void mouse_gyro_handler::handle_event(QEvent* ev, const QWindow& win) { - if (!enabled) + if (!m_enabled) return; // Mouse-based motion input. @@ -119,15 +124,12 @@ void mouse_gyro_handler::handle_event(QEvent* ev, const QWindow& win) void mouse_gyro_handler::apply_gyro(const std::shared_ptr& pad) { - if (!enabled) - return; - - if (!pad || !pad->is_connected()) + if (!m_enabled || !pad || !pad->is_connected()) return; // Inject mouse-based motion sensor values into pad sensors for gyro emulation. // The Qt frontend maps cursor offset and wheel input to absolute motion values while RMB is held. - if (reset) + if (m_reset) { // RMB released → reset motion pad->m_sensors[0].m_value = DEFAULT_MOTION_X; @@ -139,8 +141,8 @@ void mouse_gyro_handler::apply_gyro(const std::shared_ptr& pad) { // RMB held → accumulate motion // Axes have been chosen as tested in Sly 4 minigames. Top-down view motion uses X/Z axes. - pad->m_sensors[0].m_value = gyro_x; // Mouse X → Motion X - pad->m_sensors[1].m_value = gyro_y; // Mouse Wheel → Motion Y - pad->m_sensors[2].m_value = gyro_z; // Mouse Y → Motion Z + pad->m_sensors[0].m_value = m_gyro_x; // Mouse X → Motion X + pad->m_sensors[1].m_value = m_gyro_y; // Mouse Wheel → Motion Y + pad->m_sensors[2].m_value = m_gyro_z; // Mouse Y → Motion Z } } diff --git a/rpcs3/Input/mouse_gyro_handler.h b/rpcs3/Input/mouse_gyro_handler.h index 97a745d919..9c53f574e4 100644 --- a/rpcs3/Input/mouse_gyro_handler.h +++ b/rpcs3/Input/mouse_gyro_handler.h @@ -10,24 +10,23 @@ class QWindow; // Mouse-based motion sensor emulation state. class mouse_gyro_handler { -private: - atomic_t enabled = false; // Whether mouse-based gyro emulation mode has been enabled by using the associated hotkey - - atomic_t active = false; // Whether right mouse button is currently held (gyro active) - atomic_t reset = false; // One-shot reset request on right mouse button release - atomic_t gyro_x = DEFAULT_MOTION_X; // Accumulated from mouse X position relative to center - atomic_t gyro_y = DEFAULT_MOTION_Y; // Accumulated from mouse wheel delta - atomic_t gyro_z = DEFAULT_MOTION_Z; // Accumulated from mouse Y position relative to center - - void set_gyro_active(); - void set_gyro_reset(); - void set_gyro_xz(s32 off_x, s32 off_y); - void set_gyro_y(s32 steps); - public: void clear(); bool toggle_enabled(); void handle_event(QEvent* ev, const QWindow& win); void apply_gyro(const std::shared_ptr& pad); + +private: + atomic_t m_enabled = false; // Whether mouse-based gyro emulation mode has been enabled by using the associated hotkey + atomic_t m_active = false; // Whether right mouse button is currently held (gyro active) + atomic_t m_reset = false; // One-shot reset request on right mouse button release + atomic_t m_gyro_x = DEFAULT_MOTION_X; // Accumulated from mouse X position relative to center + atomic_t m_gyro_y = DEFAULT_MOTION_Y; // Accumulated from mouse wheel delta + atomic_t m_gyro_z = DEFAULT_MOTION_Z; // Accumulated from mouse Y position relative to center + + void set_gyro_active(); + void set_gyro_reset(); + void set_gyro_xz(s32 off_x, s32 off_y); + void set_gyro_y(s32 steps); };