From a288c598413e3d9ab52999bd009484bd19b3fce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 16 Feb 2023 10:33:47 +0100 Subject: [PATCH] Simplify tilt, step 1 --- Core/TiltEventProcessor.cpp | 18 +++++++++++------- Core/TiltEventProcessor.h | 11 +---------- UI/NativeApp.cpp | 4 +--- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Core/TiltEventProcessor.cpp b/Core/TiltEventProcessor.cpp index 536c8b90d81c..6bf962c6c703 100644 --- a/Core/TiltEventProcessor.cpp +++ b/Core/TiltEventProcessor.cpp @@ -19,6 +19,13 @@ static u32 tiltButtonsDown = 0; float rawTiltAnalogX; float rawTiltAnalogY; +// Represents a generic Tilt event +struct Tilt { + Tilt() : x_(0), y_(0) {} + Tilt(const float x, const float y) : x_(x), y_(y) {} + float x_, y_; +}; + // These functions generate tilt events given the current Tilt amount, // and the deadzone radius. void GenerateAnalogStickEvent(const Tilt &tilt); @@ -51,7 +58,7 @@ inline Tilt DampenTilt(const Tilt &tilt, float deadzone, float xSensitivity, flo ); } -Tilt GenTilt(bool landscape, float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity) { +void ProcessTilt(bool landscape, float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity) { if (landscape) { std::swap(x, y); } else { @@ -78,18 +85,15 @@ Tilt GenTilt(bool landscape, float calibrationAngle, float x, float y, float z, } // finally, dampen the tilt according to our curve. - return DampenTilt(transformedTilt, deadzone, xSensitivity, ySensitivity); -} - -void TranslateTiltToInput(const Tilt &tilt) { - rawTiltAnalogX = tilt.x_; - rawTiltAnalogY = tilt.y_; + Tilt tilt = DampenTilt(transformedTilt, deadzone, xSensitivity, ySensitivity); switch (g_Config.iTiltInputType) { case TILT_NULL: break; case TILT_ANALOG: + rawTiltAnalogX = tilt.x_; + rawTiltAnalogY = tilt.y_; GenerateAnalogStickEvent(tilt); break; diff --git a/Core/TiltEventProcessor.h b/Core/TiltEventProcessor.h index fb7156b9a2bb..3eda969e17c4 100644 --- a/Core/TiltEventProcessor.h +++ b/Core/TiltEventProcessor.h @@ -2,18 +2,9 @@ namespace TiltEventProcessor { -// Represents a generic Tilt event -struct Tilt { - Tilt() : x_(0), y_(0) {} - Tilt(const float x, const float y) : x_(x), y_(y) {} - float x_, y_; -}; - // generates a tilt in the correct coordinate system based on // calibration. x, y, z is the current accelerometer reading (with no conversion). -Tilt GenTilt(bool landscape, const float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity); - -void TranslateTiltToInput(const Tilt &tilt); +void ProcessTilt(bool landscape, const float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity); void ResetTiltEvents(); // Lets you preview the amount of tilt in TiltAnalogSettingsScreen. diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index bd3a062f8272..50aa992c8b5f 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1404,11 +1404,9 @@ void NativeAxis(const AxisInput &axis) { // see [http://developer.android.com/guide/topics/sensors/sensors_overview.html] for details bool landscape = dp_yres < dp_xres; // now transform out current tilt to the calibrated coordinate system - Tilt trueTilt = GenTilt(landscape, tiltBaseAngleY, tiltX, tiltY, tiltZ, + ProcessTilt(landscape, tiltBaseAngleY, tiltX, tiltY, tiltZ, g_Config.bInvertTiltX, g_Config.bInvertTiltY, xSensitivity, ySensitivity); - - TranslateTiltToInput(trueTilt); } void NativeMessageReceived(const char *message, const char *value) {