From 9001de7842ea073a47f1cd68102684e2ff16abcb Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sun, 10 Mar 2019 23:35:14 +0100 Subject: [PATCH] android: only handle analog axis if axis value has changed tentative fix for xbox 360 dpad --- .../reicast/src/main/jni/src/Android.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/shell/android-studio/reicast/src/main/jni/src/Android.cpp b/shell/android-studio/reicast/src/main/jni/src/Android.cpp index 7df9543a8..31cf64ff5 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -437,6 +437,13 @@ JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_emu_JNIdc_rendframeNative(J JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendinitNative(JNIEnv * env, jobject obj, jobject surface, jint width, jint height) { + if (g_window != NULL) + { + egl_makecurrent(); + rend_term_renderer(); + ANativeWindow_release(g_window); + g_window = NULL; + } if (surface != NULL) { g_window = ANativeWindow_fromSurface(env, surface); @@ -444,13 +451,6 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendinitNative(JNIEnv screen_width = width; screen_height = height; } - else - { - egl_makecurrent(); - rend_term_renderer(); - ANativeWindow_release(g_window); - g_window = NULL; - } } JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendinitJava(JNIEnv * env, jobject obj, jint width, jint height) @@ -640,11 +640,19 @@ JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_j return false; } + +static std::map, jint> previous_axis_values; + JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickAxisEvent(JNIEnv *env, jobject obj, jint id, jint key, jint value) { std::shared_ptr device = AndroidGamepadDevice::GetAndroidGamepad(id); - if (device != NULL) + // Only handle Left Stick on an Xbox 360 controller if there was actual + // motion on the stick, otherwise event can be handled as a DPAD event + if (device != NULL && previous_axis_values[std::make_pair(id, key)] != value) + { + previous_axis_values[std::make_pair(id, key)] = value; return device->gamepad_axis_input(key, value); + } else return false; }