فهرست منبع

fix the gamepad auto_plugin problem

ZengGengSen 2 سال پیش
والد
کامیت
56a6bbf454

+ 14 - 0
app/src/main/cpp/frontend/drivers/platform_unix.c

@@ -597,6 +597,20 @@ Java_com_retroarch_browser_retroactivity_RetroActivityCommon_registerBeans(
    android_app->beans.joypad_manager.clazz =
            (*env)->NewGlobalRef(env, android_app->beans.joypad_manager.clazz);
 
+   GET_STATIC_METHOD_ID(
+           env,
+           android_app->beans.joypad_manager.initialize,
+           android_app->beans.joypad_manager.clazz,
+           "initialize", "()V"
+   );
+
+   GET_STATIC_METHOD_ID(
+           env,
+           android_app->beans.joypad_manager.uninitialize,
+           android_app->beans.joypad_manager.clazz,
+           "uninitialize", "()V"
+   );
+
    GET_STATIC_METHOD_ID(
            env,
            android_app->beans.joypad_manager.pollInputDevices,

+ 2 - 0
app/src/main/cpp/frontend/drivers/platform_unix.h

@@ -202,6 +202,8 @@ struct android_app
 
        struct {
            jclass clazz;
+           jmethodID initialize;
+           jmethodID uninitialize;
            jmethodID pollInputDevices;
        } joypad_manager;
    } beans;

+ 2 - 21
app/src/main/cpp/gfx/video_driver.c

@@ -1548,27 +1548,8 @@ void video_driver_free_internal(void)
    if (!(video_st->flags & VIDEO_FLAG_CACHE_CONTEXT))
       video_driver_free_hw_context();
 
-   if (!(input_st->current_data == video_st->data))
-   {
-      if (input_st->current_driver)
-         if (input_st->current_driver->free)
-            input_st->current_driver->free(input_st->current_data);
-      if (input_st->primary_joypad)
-      {
-         const input_device_driver_t *tmp   = input_st->primary_joypad;
-         input_st->primary_joypad    = NULL;
-         tmp->destroy();
-      }
-#ifdef HAVE_MFI
-      if (input_st->secondary_joypad)
-      {
-         const input_device_driver_t *tmp   = input_st->secondary_joypad;
-         input_st->secondary_joypad         = NULL;
-         tmp->destroy();
-      }
-#endif
-      input_st->flags &= ~INP_FLAG_KB_MAPPING_BLOCKED;
-      input_st->current_data                = NULL;
+   if (input_st->current_data != video_st->data) {
+      video_driver_free_input();
    }
 
    if (     video_st->data

+ 26 - 3
app/src/main/cpp/input/drivers_joypad/android_joypad.c

@@ -404,7 +404,21 @@ Java_com_xugame_app_JoypadManager_removeJoystickNative(
    android->pads_connected--;
 }
 
-static void *android_joypad_init(void *data) { return (void*)-1; }
+static void *android_joypad_init(void *data) {
+   struct android_app *android_app = (struct android_app*)g_android;
+   JNIEnv                     *env  = jni_thread_getenv();
+
+   if (!env)
+      return NULL;
+
+   CALL_VOID_STATIC_METHOD(
+           env,
+           android_app->beans.joypad_manager.clazz,
+           android_app->beans.joypad_manager.initialize
+   );
+
+   return (void*)-1;
+}
 
 static int32_t android_joypad_button_state(
       struct android_app *android_app,
@@ -536,6 +550,7 @@ static void android_joypad_destroy(void)
 {
    unsigned i, j;
    struct android_app *android_app = (struct android_app*)g_android;
+   JNIEnv                     *env = jni_thread_getenv();
 
    for (i = 0; i < DEFAULT_MAX_PADS; i++)
    {
@@ -545,13 +560,21 @@ static void android_joypad_destroy(void)
          android_app->analog_state[i][j] = 0;
    }
 
-   for (i = 0; i < MAX_USERS; i++)
-   {
+   for (i = 0; i < MAX_USERS; i++) {
       android_app->rumble_last_strength_strong[i] = 0;
       android_app->rumble_last_strength_weak  [i] = 0;
       android_app->rumble_last_strength       [i] = 0;
       android_app->id                         [i] = 0;
    }
+
+   if (!env)
+      return;
+
+   CALL_VOID_STATIC_METHOD(
+           env,
+           android_app->beans.joypad_manager.clazz,
+           android_app->beans.joypad_manager.uninitialize
+   );
 }
 
 static void android_input_set_rumble_internal(

+ 24 - 0
app/src/main/cpp/input/input_driver.c

@@ -3077,6 +3077,30 @@ bool video_driver_init_input(
    return true;
 }
 
+void video_driver_free_input()
+{
+   input_driver_state_t *input_st    = input_state_get_ptr();
+   if (input_st->primary_joypad)
+      if (input_st->primary_joypad->destroy)
+         input_st->primary_joypad->destroy();
+   input_st->primary_joypad    = NULL;
+
+   if (input_st->current_driver)
+      if (input_st->current_driver->free)
+         input_st->current_driver->free(input_st->current_data);
+   input_st->current_driver    = NULL;
+   input_st->current_data      = NULL;
+#ifdef HAVE_MFI
+   if (input_st->secondary_joypad)
+      {
+         const input_device_driver_t *tmp   = input_st->secondary_joypad;
+         input_st->secondary_joypad         = NULL;
+         tmp->destroy();
+      }
+#endif
+   input_st->flags &= ~INP_FLAG_KB_MAPPING_BLOCKED;
+}
+
 bool input_driver_grab_mouse(void)
 {
    if (!input_driver_st.current_driver || !input_driver_st.current_driver->grab_mouse)

+ 1 - 0
app/src/main/cpp/input/input_driver.h

@@ -553,6 +553,7 @@ bool video_driver_init_input(
       input_driver_t *tmp,
       settings_t *settings,
       bool verbosity_enabled);
+void video_driver_free_input();
 
 bool input_driver_grab_mouse(void);
 

+ 0 - 1
app/src/main/java/com/retroarch/browser/retroactivity/RetroActivityCommon.java

@@ -98,7 +98,6 @@ public abstract class RetroActivityCommon extends NativeActivity
   protected void onStart() {
     super.onStart();
 
-    JoypadManager.initialize();
     registerBeans();
   }
 

+ 30 - 3
app/src/main/java/com/xugame/app/JoypadManager.java

@@ -1,6 +1,5 @@
 package com.xugame.app;
 
-import android.util.Log;
 import android.view.InputDevice;
 import android.view.MotionEvent;
 
@@ -15,19 +14,29 @@ public class JoypadManager {
         }
     }
 
+    public static void uninitialize() {
+        mJoystickHandler.removeInputDevices();
+        mJoystickHandler = null;
+    }
+
     // Using for JNI
     public static void pollInputDevices() {
         mJoystickHandler.pollInputDevices();
     }
 
     // Check if a given device is considered a possible SDL joystick
-    public static boolean isDeviceSDLJoystick(int deviceId) {
+    public static boolean isDeviceJoystick(int deviceId) {
         InputDevice device = InputDevice.getDevice(deviceId);
         // We cannot use InputDevice.isVirtual before API 16, so let's accept
         // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
         if ((device == null) || (deviceId < 0)) {
             return false;
         }
+
+        if (device.isVirtual()) {
+            return false;
+        }
+
         int sources = device.getSources();
 
         /* This is called for every button press, so let's not spam the logs */
@@ -42,6 +51,13 @@ public class JoypadManager {
             Log.v(TAG, "Input device " + device.getName() + " is a gamepad.");
         }
         */
+        InputDevice.MotionRange range = device.getMotionRange(MotionEvent.AXIS_HAT_X);
+        if(range == null)
+            return false;
+
+        range = device.getMotionRange(MotionEvent.AXIS_HAT_Y);
+        if(range == null)
+            return false;
 
         return ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 ||
                 ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) ||
@@ -59,6 +75,9 @@ class JoypadHandler {
      */
     public void pollInputDevices() {
     }
+
+    public void removeInputDevices() {
+    }
 }
 
 class JoypadHandler_API extends JoypadHandler {
@@ -74,7 +93,7 @@ class JoypadHandler_API extends JoypadHandler {
 
         for (int deviceId : deviceIds) {
             if (!mJoypadIds.contains(deviceId)) {
-                if (JoypadManager.isDeviceSDLJoystick(deviceId)) {
+                if (JoypadManager.isDeviceJoystick(deviceId)) {
                     InputDevice joypadDevice = InputDevice.getDevice(deviceId);
                     mJoypadIds.add(deviceId);
                     JoypadManager.addJoystickNative(
@@ -108,4 +127,12 @@ class JoypadHandler_API extends JoypadHandler {
             }
         }
     }
+
+    @Override
+    public void removeInputDevices() {
+        for (int deviceId : mJoypadIds) {
+            JoypadManager.removeJoystickNative(deviceId);
+        }
+        mJoypadIds.clear();
+    }
 }

+ 1 - 0
app/src/main/java/com/xugame/gameconsole/emulator/RetroArchEmulatorActivity.java

@@ -353,6 +353,7 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         if (requestCode == 200) {
             if (resultCode == 201) {//继续游戏
+                gameDialogClosed();
                 if (data != null) {
                     int scanLine = data.getIntExtra("scanLine", 0);
                     int screen = data.getIntExtra("screen", 0);