mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
(Android) Split off input code into its own driver
This commit is contained in:
parent
6d3c12b9bd
commit
a675c4348f
@ -38,6 +38,7 @@ LOCAL_SRC_FILES = $(RARCH_PATH)/retroarch.c \
|
||||
$(RARCH_PATH)/gfx/fonts/null_fonts.c \
|
||||
$(RARCH_PATH)/gfx/state_tracker.c \
|
||||
$(RARCH_PATH)/input/null.c \
|
||||
input_android.c \
|
||||
$(RARCH_PATH)/screenshot.c \
|
||||
$(RARCH_PATH)/conf/config_file.c \
|
||||
$(RARCH_PATH)/autosave.c \
|
||||
|
80
android/native/jni/input_android.c
Normal file
80
android/native/jni/input_android.c
Normal file
@ -0,0 +1,80 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
*
|
||||
* 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 "android-general.h"
|
||||
#include "../../../general.h"
|
||||
#include "../../../driver.h"
|
||||
|
||||
/**
|
||||
* Process the next input event.
|
||||
*/
|
||||
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
||||
{
|
||||
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
|
||||
{
|
||||
g_android.animating = 1;
|
||||
g_android.state.x = AMotionEvent_getX(event, 0);
|
||||
g_android.state.y = AMotionEvent_getY(event, 0);
|
||||
//RARCH_LOG("AINPUT_EVENT_TYPE_MOTION - x: %d, y: %d.\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *android_input_init(void)
|
||||
{
|
||||
g_android.app->onInputEvent = engine_handle_input;
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
static void android_input_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
}
|
||||
|
||||
static int16_t android_input_state(void *data, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id)
|
||||
{
|
||||
(void)data;
|
||||
(void)retro_keybinds;
|
||||
(void)port;
|
||||
(void)device;
|
||||
(void)index;
|
||||
(void)id;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool android_input_key_pressed(void *data, int key)
|
||||
{
|
||||
(void)data;
|
||||
(void)key;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void android_input_free(void *data)
|
||||
{
|
||||
(void)data;
|
||||
}
|
||||
|
||||
const input_driver_t input_android = {
|
||||
android_input_init,
|
||||
android_input_poll,
|
||||
android_input_state,
|
||||
android_input_key_pressed,
|
||||
android_input_free,
|
||||
"android_input",
|
||||
};
|
||||
|
@ -18,45 +18,15 @@
|
||||
#include <jni.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <EGL/egl.h> /* Requires NDK r5 or newer */
|
||||
#include <GLES/gl.h>
|
||||
|
||||
#include "android-general.h"
|
||||
#include "../../../general.h"
|
||||
|
||||
//forward declarations
|
||||
void gfx_ctx_swap_buffers(void);
|
||||
void gfx_ctx_clear(void);
|
||||
void gfx_ctx_destroy(void);
|
||||
bool gfx_ctx_init(void);
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad( JavaVM *vm, void *pvt)
|
||||
{
|
||||
RARCH_LOG("JNI_OnLoad.\n" );
|
||||
|
||||
return JNI_VERSION_1_2;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_OnUnLoad( JavaVM *vm, void *pvt)
|
||||
{
|
||||
RARCH_LOG("JNI_OnUnLoad.\n" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the next input event.
|
||||
*/
|
||||
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
||||
{
|
||||
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
|
||||
{
|
||||
g_android.animating = 1;
|
||||
g_android.state.x = AMotionEvent_getX(event, 0);
|
||||
g_android.state.y = AMotionEvent_getY(event, 0);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
JNIEXPORT void JNICALL JNI_OnUnLoad( JavaVM *vm, void *pvt) { }
|
||||
|
||||
/**
|
||||
* Process the next main command.
|
||||
@ -84,17 +54,15 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd)
|
||||
break;
|
||||
case APP_CMD_GAINED_FOCUS:
|
||||
// When our app gains focus, we start monitoring the accelerometer.
|
||||
/*
|
||||
if (g_android.accelerometerSensor != NULL)
|
||||
{
|
||||
*/
|
||||
ASensorEventQueue_enableSensor(g_android.sensorEventQueue,
|
||||
g_android.accelerometerSensor);
|
||||
|
||||
// We'd like to get 60 events per second (in us).
|
||||
ASensorEventQueue_setEventRate(g_android.sensorEventQueue,
|
||||
g_android.accelerometerSensor, (1000L/60)*1000);
|
||||
//}
|
||||
}
|
||||
break;
|
||||
case APP_CMD_LOST_FOCUS:
|
||||
// When our app loses focus, we stop monitoring the accelerometer.
|
||||
@ -169,7 +137,6 @@ void android_main(struct android_app* state)
|
||||
snprintf(libretro_path, sizeof(libretro_path), "/data/data/com.retroarch/lib/libretro.so");
|
||||
|
||||
g_android.app->onAppCmd = engine_handle_cmd;
|
||||
g_android.app->onInputEvent = engine_handle_input;
|
||||
|
||||
// Prepare to monitor accelerometer
|
||||
g_android.sensorManager = ASensorManager_getInstance();
|
||||
|
@ -58,6 +58,7 @@ enum
|
||||
AUDIO_XDK360,
|
||||
AUDIO_NULL,
|
||||
|
||||
INPUT_ANDROID,
|
||||
INPUT_SDL,
|
||||
INPUT_X,
|
||||
INPUT_DINPUT,
|
||||
@ -131,6 +132,8 @@ enum
|
||||
#define INPUT_DEFAULT_DRIVER INPUT_XENON360
|
||||
#elif defined(_XBOX360) || defined(_XBOX) || defined(HAVE_XINPUT2) || defined(HAVE_XINPUT_XBOX1)
|
||||
#define INPUT_DEFAULT_DRIVER INPUT_XINPUT
|
||||
#elif defined(ANDROID)
|
||||
#define INPUT_DEFAULT_DRIVER INPUT_ANDROID
|
||||
#elif defined(_WIN32)
|
||||
#define INPUT_DEFAULT_DRIVER INPUT_DINPUT
|
||||
#elif defined(HAVE_SDL)
|
||||
|
3
driver.c
3
driver.c
@ -132,6 +132,9 @@ static const input_driver_t *input_drivers[] = {
|
||||
#ifdef GEKKO
|
||||
&input_gx,
|
||||
#endif
|
||||
#ifdef ANDROID
|
||||
&input_android,
|
||||
#endif
|
||||
#if defined(__linux__) && !defined(ANDROID)
|
||||
&input_linuxraw,
|
||||
#endif
|
||||
|
1
driver.h
1
driver.h
@ -280,6 +280,7 @@ extern const video_driver_t video_sdl;
|
||||
extern const video_driver_t video_vg;
|
||||
extern const video_driver_t video_ext;
|
||||
extern const video_driver_t video_null;
|
||||
extern const input_driver_t input_android;
|
||||
extern const input_driver_t input_sdl;
|
||||
extern const input_driver_t input_dinput;
|
||||
extern const input_driver_t input_x;
|
||||
|
@ -105,6 +105,8 @@ const char *config_get_default_input(void)
|
||||
{
|
||||
switch (INPUT_DEFAULT_DRIVER)
|
||||
{
|
||||
case INPUT_ANDROID:
|
||||
return "android_input";
|
||||
case INPUT_PS3:
|
||||
return "ps3";
|
||||
case INPUT_SDL:
|
||||
|
Loading…
Reference in New Issue
Block a user