mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 15:40:44 +00:00
(Android) Don't split up JNI functions into their own file -
assumed this is Android-specific for now (Android) Some input improvements - don't call AKeyEvent_getKeyCode unless type is of AINPUT_EVENT_TYPE_KEY
This commit is contained in:
parent
c5bda29ce3
commit
bb1e2a4677
@ -40,8 +40,27 @@ struct droid
|
||||
float disp_refresh_rate;
|
||||
};
|
||||
|
||||
struct jni_params
|
||||
{
|
||||
JavaVM *java_vm;
|
||||
jobject class_obj;
|
||||
char class_name[128];
|
||||
char method_name[128];
|
||||
char method_signature[128];
|
||||
char obj_method_name[128];
|
||||
char obj_method_signature[128];
|
||||
};
|
||||
|
||||
struct jni_out_params_char
|
||||
{
|
||||
char *out;
|
||||
size_t out_sizeof;
|
||||
char in[128];
|
||||
};
|
||||
|
||||
extern struct droid g_android;
|
||||
|
||||
extern int android_get_sdk_version(void);
|
||||
int android_get_sdk_version(void);
|
||||
void jni_get_char_argv(struct jni_params *params, struct jni_out_params_char *out_params);
|
||||
|
||||
#endif
|
||||
|
@ -286,40 +286,38 @@ static void android_input_poll(void *data)
|
||||
if(id == LOOPER_ID_INPUT)
|
||||
{
|
||||
AInputEvent* event = NULL;
|
||||
AInputQueue_getEvent(android_app->inputQueue, &event);
|
||||
int32_t handled = 1;
|
||||
|
||||
if (AInputQueue_getEvent(android_app->inputQueue, &event) >= 0)
|
||||
int id = AInputEvent_getDeviceId(event);
|
||||
int type = AInputEvent_getType(event);
|
||||
int i = state_device_ids[id];
|
||||
|
||||
if(i == -1)
|
||||
i = state_device_ids[id] = pads_connected++;
|
||||
|
||||
if(type == AINPUT_EVENT_TYPE_MOTION)
|
||||
{
|
||||
float x = AMotionEvent_getX(event, 0);
|
||||
float y = AMotionEvent_getY(event, 0);
|
||||
#ifdef RARCH_INPUT_DEBUG
|
||||
RARCH_LOG("AINPUT_EVENT_TYPE_MOTION, pad: %d, x: %f, y: %f.\n", i, x, y);
|
||||
#endif
|
||||
state[i] &= ~((1 << RETRO_DEVICE_ID_JOYPAD_LEFT) | (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) |
|
||||
(1 << RETRO_DEVICE_ID_JOYPAD_UP) | (1 << RETRO_DEVICE_ID_JOYPAD_DOWN));
|
||||
state[i] |= PRESSED_LEFT(x, y) ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
||||
state[i] |= PRESSED_RIGHT(x, y) ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
||||
state[i] |= PRESSED_UP(x, y) ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
||||
state[i] |= PRESSED_DOWN(x, y) ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int keycode = AKeyEvent_getKeyCode(event);
|
||||
int32_t handled = 1;
|
||||
uint64_t input_state = keycode_lut[keycode];
|
||||
|
||||
|
||||
int id = AInputEvent_getDeviceId(event);
|
||||
int type = AInputEvent_getType(event);
|
||||
int i = state_device_ids[id];
|
||||
|
||||
if(i == -1)
|
||||
i = state_device_ids[id] = pads_connected++;
|
||||
|
||||
#ifdef RARCH_INPUT_DEBUG
|
||||
RARCH_LOG("Keycode RetroPad %d : %d.\n", i, keycode);
|
||||
#endif
|
||||
|
||||
if(type == AINPUT_EVENT_TYPE_MOTION)
|
||||
{
|
||||
float x = AMotionEvent_getX(event, 0);
|
||||
float y = AMotionEvent_getY(event, 0);
|
||||
#ifdef RARCH_INPUT_DEBUG
|
||||
RARCH_LOG("AINPUT_EVENT_TYPE_MOTION, pad: %d, x: %f, y: %f.\n", i, x, y);
|
||||
#endif
|
||||
state[i] &= ~((1 << RETRO_DEVICE_ID_JOYPAD_LEFT) | (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) |
|
||||
(1 << RETRO_DEVICE_ID_JOYPAD_UP) | (1 << RETRO_DEVICE_ID_JOYPAD_DOWN));
|
||||
state[i] |= PRESSED_LEFT(x, y) ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
||||
state[i] |= PRESSED_RIGHT(x, y) ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
||||
state[i] |= PRESSED_UP(x, y) ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
||||
state[i] |= PRESSED_DOWN(x, y) ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
||||
}
|
||||
else if(input_state < (1 << RARCH_FIRST_META_KEY))
|
||||
if(input_state < (1 << RARCH_FIRST_META_KEY))
|
||||
{
|
||||
int action = AKeyEvent_getAction(event);
|
||||
|
||||
@ -333,9 +331,9 @@ static void android_input_poll(void *data)
|
||||
g_android.input_state = input_state;
|
||||
handled = 0;
|
||||
}
|
||||
|
||||
AInputQueue_finishEvent(android_app->inputQueue, event, handled);
|
||||
}
|
||||
|
||||
AInputQueue_finishEvent(android_app->inputQueue, event, handled);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,43 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include "jni_utils.h"
|
||||
|
||||
void jni_get_char_argv(struct jni_params *params, struct jni_out_params_char *out_params)
|
||||
{
|
||||
JNIEnv *env;
|
||||
JavaVM *vm = params->java_vm;
|
||||
|
||||
(*vm)->AttachCurrentThread(vm, &env, 0);
|
||||
|
||||
jclass acl = (*env)->GetObjectClass(env, params->class_obj); //class pointer
|
||||
jmethodID giid = (*env)->GetMethodID(env, acl, params->method_name, params->method_signature);
|
||||
jobject obj = (*env)->CallObjectMethod(env, params->class_obj, giid); //Got our object
|
||||
|
||||
jclass class_obj = (*env)->GetObjectClass(env, obj); //class pointer of object
|
||||
jmethodID gseid = (*env)->GetMethodID(env, class_obj, params->obj_method_name, params->obj_method_signature);
|
||||
|
||||
jstring jsParam1 = (*env)->CallObjectMethod(env, obj, gseid, (*env)->NewStringUTF(env, out_params->in));
|
||||
const char *test_argv = (*env)->GetStringUTFChars(env, jsParam1, 0);
|
||||
|
||||
strncpy(out_params->out, test_argv, out_params->out_sizeof);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jsParam1, test_argv);
|
||||
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _RARCH_JNI_UTILS_H
|
||||
#define _RARCH_JNI_UTILS_H
|
||||
|
||||
#include <jni.h>
|
||||
#include "android_glue.h"
|
||||
|
||||
struct jni_params
|
||||
{
|
||||
JavaVM *java_vm;
|
||||
jobject class_obj;
|
||||
char class_name[128];
|
||||
char method_name[128];
|
||||
char method_signature[128];
|
||||
char obj_method_name[128];
|
||||
char obj_method_signature[128];
|
||||
};
|
||||
|
||||
struct jni_out_params_char
|
||||
{
|
||||
char *out;
|
||||
size_t out_sizeof;
|
||||
char in[128];
|
||||
};
|
||||
|
||||
void jni_get_char_argv(struct jni_params *params, struct jni_out_params_char *out_params);
|
||||
|
||||
#endif
|
@ -20,7 +20,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include "jni_utils.h"
|
||||
#include <jni.h>
|
||||
#include "android_general.h"
|
||||
#include "../../../general.h"
|
||||
#include "../../../performance.h"
|
||||
@ -73,6 +73,30 @@ int android_get_sdk_version(void)
|
||||
return AConfiguration_getSdkVersion(g_android.app->config);
|
||||
}
|
||||
|
||||
void jni_get_char_argv(struct jni_params *params, struct jni_out_params_char *out_params)
|
||||
{
|
||||
JNIEnv *env;
|
||||
JavaVM *vm = params->java_vm;
|
||||
|
||||
(*vm)->AttachCurrentThread(vm, &env, 0);
|
||||
|
||||
jclass acl = (*env)->GetObjectClass(env, params->class_obj); //class pointer
|
||||
jmethodID giid = (*env)->GetMethodID(env, acl, params->method_name, params->method_signature);
|
||||
jobject obj = (*env)->CallObjectMethod(env, params->class_obj, giid); //Got our object
|
||||
|
||||
jclass class_obj = (*env)->GetObjectClass(env, obj); //class pointer of object
|
||||
jmethodID gseid = (*env)->GetMethodID(env, class_obj, params->obj_method_name, params->obj_method_signature);
|
||||
|
||||
jstring jsParam1 = (*env)->CallObjectMethod(env, obj, gseid, (*env)->NewStringUTF(env, out_params->in));
|
||||
const char *test_argv = (*env)->GetStringUTFChars(env, jsParam1, 0);
|
||||
|
||||
strncpy(out_params->out, test_argv, out_params->out_sizeof);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jsParam1, test_argv);
|
||||
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the next main command.
|
||||
*/
|
||||
|
@ -28,14 +28,6 @@ LOGGERS
|
||||
#include "../logger/logger.c"
|
||||
#endif
|
||||
|
||||
/*============================================================
|
||||
JNI UTILS
|
||||
============================================================ */
|
||||
|
||||
#ifdef ANDROID
|
||||
#include "../../android/native/jni/jni_utils.c"
|
||||
#endif
|
||||
|
||||
/*============================================================
|
||||
CONSOLE EXTENSIONS
|
||||
============================================================ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user