From c28dc9e4f2c5f7dfa1a4f6b7bcb7cca57cfe6b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 27 Sep 2023 11:34:31 +0200 Subject: [PATCH] Pass in accelerometer readings using NativeAccelerometer instead of NativeAxis --- Common/Input/InputState.h | 2 +- Common/Input/KeyCodes.h | 2 +- Common/System/NativeApp.h | 1 + Qt/QtMain.cpp | 13 +------------ UI/NativeApp.cpp | 18 ++++++------------ android/jni/app-android.cpp | 13 +------------ 6 files changed, 11 insertions(+), 38 deletions(-) diff --git a/Common/Input/InputState.h b/Common/Input/InputState.h index c01680a0ae..a94547443d 100644 --- a/Common/Input/InputState.h +++ b/Common/Input/InputState.h @@ -31,7 +31,7 @@ enum InputDeviceID { DEVICE_ID_XINPUT_1 = 21, DEVICE_ID_XINPUT_2 = 22, DEVICE_ID_XINPUT_3 = 23, - DEVICE_ID_ACCELEROMETER = 30, + DEVICE_ID_ACCELEROMETER = 30, // no longer used DEVICE_ID_XR_HMD = 39, DEVICE_ID_XR_CONTROLLER_LEFT = 40, DEVICE_ID_XR_CONTROLLER_RIGHT = 41, diff --git a/Common/Input/KeyCodes.h b/Common/Input/KeyCodes.h index dc2b9897ce..8614e5a2d2 100644 --- a/Common/Input/KeyCodes.h +++ b/Common/Input/KeyCodes.h @@ -305,7 +305,7 @@ enum InputAxis { JOYSTICK_AXIS_MOUSE_REL_X = 26, JOYSTICK_AXIS_MOUSE_REL_Y = 27, - // Mobile device accelerometer/gyro + // Mobile device accelerometer/gyro. NOTE: These are no longer passed around internally, only used for the plugin API. JOYSTICK_AXIS_ACCELEROMETER_X = 40, JOYSTICK_AXIS_ACCELEROMETER_Y = 41, JOYSTICK_AXIS_ACCELEROMETER_Z = 42, diff --git a/Common/System/NativeApp.h b/Common/System/NativeApp.h index 94a67c9eb9..4799fa6f11 100644 --- a/Common/System/NativeApp.h +++ b/Common/System/NativeApp.h @@ -55,6 +55,7 @@ bool NativeIsRestarting(); void NativeTouch(const TouchInput &touch); bool NativeKey(const KeyInput &key); void NativeAxis(const AxisInput *axis, size_t count); +void NativeAccelerometer(float tiltX, float tiltY, float tiltZ); // Called when it's process a frame, including rendering. If the device can keep up, this // will be called sixty times per second. Main thread. diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index ea99d78ff5..9991d78a18 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -731,18 +731,7 @@ void MainUI::updateAccelerometer() { // TODO: Toggle it depending on whether it is enabled QAccelerometerReading *reading = acc->reading(); if (reading) { - AxisInput axis[3]; - for (int i = 0; i < 3; i++) { - axis[i].deviceId = DEVICE_ID_ACCELEROMETER; - } - - axis[0].axisId = JOYSTICK_AXIS_ACCELEROMETER_X; - axis[0].value = reading->x(); - axis[1].axisId = JOYSTICK_AXIS_ACCELEROMETER_Y; - axis[1].value = reading->y(); - axis[2].axisId = JOYSTICK_AXIS_ACCELEROMETER_Z; - axis[2].value = reading->z(); - NativeAxis(axis, 3); + NativeAccelerometer(reading->x(), reading->y(), reading->z()); } #endif } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index cd622c0873..f4056c10b3 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1336,22 +1336,12 @@ static void ProcessOneAxisEvent(const AxisInput &axis) { } void NativeAxis(const AxisInput *axes, size_t count) { - // figure out what the current tilt orientation is by checking the axis event - // This is static, since we need to remember where we last were (in terms of orientation) - static float tiltX; - static float tiltY; - static float tiltZ; - for (size_t i = 0; i < count; i++) { ProcessOneAxisEvent(axes[i]); - switch (axes[i].axisId) { - case JOYSTICK_AXIS_ACCELEROMETER_X: tiltX = axes[i].value; break; - case JOYSTICK_AXIS_ACCELEROMETER_Y: tiltY = axes[i].value; break; - case JOYSTICK_AXIS_ACCELEROMETER_Z: tiltZ = axes[i].value; break; - default: break; - } } +} +void NativeAccelerometer(float tiltX, float tiltY, float tiltZ) { if (g_Config.iTiltInputType == TILT_NULL) { // if tilt events are disabled, don't do anything special. return; @@ -1377,6 +1367,10 @@ void NativeAxis(const AxisInput *axes, size_t count) { TiltEventProcessor::ProcessTilt(landscape, tiltBaseAngleY, tiltX, tiltY, tiltZ, g_Config.bInvertTiltX, g_Config.bInvertTiltY, xSensitivity, ySensitivity); + + HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_X] = tiltX; + HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_Y] = tiltY; + HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_Z] = tiltZ; } void System_PostUIMessage(const std::string &message, const std::string &value) { diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 8433de7442..79048d9595 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1240,18 +1240,7 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_mouseWheelEvent( extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_accelerometer(JNIEnv *, jclass, float x, float y, float z) { if (!renderer_inited) return; - - AxisInput axis[3]; - for (int i = 0; i < 3; i++) { - axis[i].deviceId = DEVICE_ID_ACCELEROMETER; - } - axis[0].axisId = JOYSTICK_AXIS_ACCELEROMETER_X; - axis[0].value = x; - axis[1].axisId = JOYSTICK_AXIS_ACCELEROMETER_Y; - axis[1].value = y; - axis[2].axisId = JOYSTICK_AXIS_ACCELEROMETER_Z; - axis[2].value = z; - NativeAxis(axis, 3); + NativeAccelerometer(x, y, z); } extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessageFromJava(JNIEnv *env, jclass, jstring message, jstring param) {