Browse Source

1. add 3s request
2. add config bind

ZengGengSen 1 year ago
parent
commit
b6a0472b1e

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

@@ -348,6 +348,7 @@ void android_environment_cb_native(unsigned cmd, void *data) {
             );
 
             (*env)->SetObjectArrayElement(env, array, i, bean);
+            (*env)->DeleteLocalRef(env, bean);
             (*env)->DeleteLocalRef(env, description);
          }
 
@@ -427,6 +428,76 @@ void android_environment_cb_native(unsigned cmd, void *data) {
             (*env)->DeleteLocalRef(env, jgeometry);
        }
            break;
+       /*
+       case RETRO_ENVIRONMENT_SET_AUTO_INPUT_BINDS:
+       case RETRO_ENVIRONMENT_SET_INPUT_BINDS: {
+            retro_keybind_set *binds = (retro_keybind_set *) data;
+            int j;
+
+            jobject bind = NULL;
+            jobject bind_set = NULL;
+            jobjectArray bind_array = NULL;
+            jobjectArray bind_set_array = NULL;
+            jstring joy_axis_label = NULL;
+            jstring joy_key_label = NULL;
+
+            bind_set_array = (*env)->NewObjectArray(
+                env, MAX_USERS,
+                app->beans.input_bind_set.clazz,
+                NULL
+            );
+            for (i = 0; i < MAX_USERS; ++i) {
+                bind_array = (*env)->NewObjectArray(
+                        env, RARCH_FIRST_CUSTOM_BIND,
+                        app->beans.input_bind.clazz,
+                        NULL
+                );
+
+                for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; ++j) {
+                    joy_axis_label = (*env)->NewStringUTF(env, binds[i][j].joyaxis_label);
+                    joy_key_label = (*env)->NewStringUTF(env, binds[i][j].joykey_label);
+                    bind = (*env)->NewObject(
+                            env,
+                            app->beans.input_bind.clazz,
+                            app->beans.input_bind.constructor,
+                            joy_axis_label,
+                            binds[i][j].joyaxis,
+                            binds[i][j].def_joyaxis,
+                            binds[i][j].orig_joyaxis,
+                            joy_key_label,
+                            binds[i][j].joykey,
+                            binds[i][j].def_joykey
+                    );
+
+                    (*env)->SetObjectArrayElement(env, bind_array, j, bind);
+
+                    (*env)->DeleteLocalRef(env, bind);
+                    (*env)->DeleteLocalRef(env, joy_key_label);
+                    (*env)->DeleteLocalRef(env, joy_axis_label);
+                }
+
+                bind_set = (*env)->NewObject(
+                        env,
+                        app->beans.input_bind_set.clazz,
+                        app->beans.input_bind_set.constructor,
+                        bind_array
+                );
+                (*env)->SetObjectArrayElement(env, bind_set_array, i, bind_set);
+
+                (*env)->DeleteLocalRef(env, bind_array);
+                (*env)->DeleteLocalRef(env, bind_set);
+            }
+
+            CALL_VOID_METHOD_PARAM(
+                  env, app->activity->clazz,
+                  app->environmentCallback,
+                  cmd, bind_set_array
+            );
+
+           (*env)->DeleteLocalRef(env, bind_set_array);
+       }
+           break;
+       */
    }
 }
 
@@ -725,6 +796,10 @@ Java_com_retroarch_browser_retroactivity_RetroActivityCommon_registerBeans(
    GET_CONSTRUCTOR(system_av_info.game_geometry, "(IIIIF)V");
    CREATE_CLASS(system_av_info.system_timing, "com/xugame/bean/SystemAVInfo$SystemTiming");
    GET_CONSTRUCTOR(system_av_info.system_timing, "(DD)V");
+//   CREATE_CLASS(input_bind, "com/xugame/bean/InputBind");
+//   GET_CONSTRUCTOR(input_bind, "(Ljava/lang/String;IIILjava/lang/String;II)V");
+//   CREATE_CLASS(input_bind_set, "com/xugame/bean/InputBindSet");
+//   GET_CONSTRUCTOR(input_bind_set, "([Lcom/xugame/bean/InputBind;)V");
 #undef CREATE_CLASS
 }
 
@@ -741,6 +816,8 @@ Java_com_retroarch_browser_retroactivity_RetroActivityCommon_unregisterBeans(
    (*env)->DeleteGlobalRef(env, android_app->beans.system_av_info.clazz);
    (*env)->DeleteGlobalRef(env, android_app->beans.system_av_info.game_geometry.clazz);
    (*env)->DeleteGlobalRef(env, android_app->beans.system_av_info.system_timing.clazz);
+//   (*env)->DeleteGlobalRef(env, android_app->beans.input_bind.clazz);
+//   (*env)->DeleteGlobalRef(env, android_app->beans.input_bind_set.clazz);
 }
 
 JNIEXPORT void JNICALL
@@ -843,6 +920,14 @@ JNIEXPORT void JNICALL Java_com_retroarch_browser_retroactivity_RetroActivityCom
 //   command_event(CMD_EVENT_VIDEO_APPLY_STATE_CHANGES, NULL);
 }
 
+JNIEXPORT void JNICALL Java_com_retroarch_browser_retroactivity_RetroActivityCommon_setJoystickBindValidNative
+        (JNIEnv *env, jobject thiz, jint port, jint id, jboolean valid) {
+    input_config_binds[port][id].valid = valid;
+}
+JNIEXPORT void JNICALL Java_com_retroarch_browser_retroactivity_RetroActivityCommon_setJoystickBindJoyKeyNative
+        (JNIEnv *env, jobject thiz, jint port, jint id, jint joy_key) {
+    input_config_binds[port][id].joykey = joy_key;
+}
 /*
  * Native activity interaction (called from main thread)
  **/
@@ -3296,3 +3381,4 @@ frontend_ctx_driver_t frontend_ctx_unix = {
 
 
 
+

+ 13 - 6
app/src/main/cpp/input/drivers_joypad/android_joypad.c

@@ -526,19 +526,26 @@ static int16_t android_joypad_state(
    return ret;
 }
 
-// todo: add 3 second detect delay
+/**
+ * 每 3s 检查一次是否有手柄插入
+ */
 static void android_joypad_poll(void) {
+   static retro_time_t timeout = 0;
    struct android_app *android_app = (struct android_app*)g_android;
    JNIEnv                     *env  = jni_thread_getenv();
+   retro_time_t now = cpu_features_get_time_usec();
 
    if (!env)
       return;
 
-   CALL_VOID_STATIC_METHOD(
-           env,
-           android_app->beans.joypad_manager.clazz,
-           android_app->beans.joypad_manager.pollInputDevices
-   );
+   if (!timeout || now >= timeout) {
+      timeout = now + 3000000;
+      CALL_VOID_STATIC_METHOD(
+              env,
+              android_app->beans.joypad_manager.clazz,
+              android_app->beans.joypad_manager.pollInputDevices
+      );
+   }
 }
 
 static bool android_joypad_query_pad(unsigned pad)

+ 9 - 12
app/src/main/cpp/input/input_driver.h

@@ -180,21 +180,12 @@ struct remote_message
    uint16_t state;
 };
 
-struct input_remote
-{
 #if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD)
+typedef struct input_remote
+{
    int net_fd[MAX_USERS];
-#endif
    bool state[RARCH_BIND_LIST_END];
-};
-
-
-typedef struct
-{
-   char display_name[256];
-} input_mouse_info_t;
-
-typedef struct input_remote input_remote_t;
+} input_remote_t;
 
 typedef struct input_remote_state
 {
@@ -203,6 +194,12 @@ typedef struct input_remote_state
    /* Left X, Left Y, Right X, Right Y */
    int16_t analog[4][MAX_USERS];
 } input_remote_state_t;
+#endif
+
+typedef struct
+{
+   char display_name[256];
+} input_mouse_info_t;
 
 typedef struct input_list_element_t
 {

+ 5 - 0
app/src/main/cpp/tasks/task_autodetect.c

@@ -438,6 +438,11 @@ static void cb_input_autoconfigure_connect(
    if (autoconfig_handle->device_info.autoconfigured)
       input_config_set_autoconfig_binds(port,
             autoconfig_handle->autoconfig_file);
+
+   for (int i = 0; i < RARCH_FIRST_CUSTOM_BIND; ++i) {
+      RARCH_LOG("[Input]: valid %d", input_autoconf_binds[port][i].valid);
+      RARCH_LOG("[Input]: joykey %d", input_autoconf_binds[port][i].joykey);
+   }
 }
 
 static void input_autoconfigure_connect_handler(retro_task_t *task)

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

@@ -577,6 +577,9 @@ DebugUtil.i(TAG,"onTick"+millisUntilFinished);
 
   public native void gameDialogClosed();
 
+  public native void setJoystickBindValidNative(int port, int id, boolean valid);
+  public native void setJoystickBindJoyKeyNative(int port, int id, int joyKey);
+
   /////////////// Private methods ///////////////
   /**
    * Sanitizes a core name so that it can be used when dealing with

+ 0 - 1
app/src/main/java/com/xugame/app/AppSystem.java

@@ -1,7 +1,6 @@
 package com.xugame.app;
 
 import com.xugame.bean.InputCode;
-import com.xugame.bean.InputDescriptorBean;
 import com.xugame.bean.SystemAVInfo;
 
 public class AppSystem {

+ 0 - 4
app/src/main/java/com/xugame/app/EnvironmentCallback.java

@@ -1,12 +1,8 @@
 package com.xugame.app;
 
-import android.util.Log;
-
 import com.xugame.bean.InputDescriptorBean;
 import com.xugame.bean.SystemAVInfo;
 
-import java.util.Arrays;
-
 public interface EnvironmentCallback {
     void setInputDescriptors(InputDescriptorBean[] descriptors);
     void setSystemAVInfo(SystemAVInfo systemAVInfo);

+ 12 - 0
app/src/main/java/com/xugame/bean/InputCode.java

@@ -18,6 +18,18 @@ public class InputCode {
     public static final int JOYPAD_L3 = 14;      
     public static final int JOYPAD_R3 = 15;
 
+    public static final int JOYPAD_BASE_BIND_END = 16;
+
+    public static final int JOYPAD_NO_KEY = 0xFFFF;
+    public static final int JOYPAD_HAT_UP_SHIFT = 15;
+    public static final int JOYPAD_HAT_DOWN_SHIFT = 14;
+    public static final int JOYPAD_HAT_LEFT_SHIFT = 13;
+    public static final int JOYPAD_HAT_RIGHT_SHIFT = 12;
+    public static final int JOYPAD_HAT_UP_MASK = 1 << JOYPAD_HAT_UP_SHIFT;
+    public static final int JOYPAD_HAT_DOWN_MASK = 1 << JOYPAD_HAT_DOWN_SHIFT;
+    public static final int JOYPAD_HAT_LEFT_MASK = 1 << JOYPAD_HAT_LEFT_SHIFT;
+    public static final int JOYPAD_HAT_RIGHT_MASK = 1 << JOYPAD_HAT_RIGHT_SHIFT;
+
     public static final int ANALOG_LEFT_X_PLUS = 16;
     public static final int ANALOG_LEFT_X_MINUS = 17;
     public static final int ANALOG_LEFT_Y_PLUS = 18;

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

@@ -26,8 +26,10 @@ import com.xugame.gameconsole.util.DebugUtil;
 import com.xugame.gameconsole.util.Util;
 
 import java.io.File;
+import java.lang.reflect.Array;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.Arrays;
 
 //private void parserIntent() {
 //        Intent intent = getIntent();