From 28c9f5191304587d00e8e46b6938d98f728daf8e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 3 Mar 2013 11:22:59 +0100 Subject: [PATCH] (Android) Rewrite new input code some more --- android/native/jni/input_android.c | 18 ++++++++++++++---- frontend/frontend_android.c | 16 +--------------- frontend/frontend_android.h | 4 ++-- retroarch.c | 18 ++---------------- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/android/native/jni/input_android.c b/android/native/jni/input_android.c index 4a0bdfc8d1..8482c4eb7b 100644 --- a/android/native/jni/input_android.c +++ b/android/native/jni/input_android.c @@ -46,9 +46,13 @@ static unsigned pointer_count; /** * Process the next main command. */ -void engine_handle_cmd (void *data, int32_t cmd) +void engine_handle_cmd(void) { - struct android_app *android_app = (struct android_app*)data; + struct android_app *android_app = (struct android_app*)g_android; + int8_t cmd; + + if (read(android_app->msgread, &cmd, sizeof(cmd)) != sizeof(cmd)) + cmd = -1; switch (cmd) { @@ -162,12 +166,18 @@ void engine_handle_cmd (void *data, int32_t cmd) g_extern.lifecycle_state |= (1ULL << RARCH_QUIT_KEY); break; } + + if (cmd == APP_CMD_INIT_WINDOW) + { + if (g_extern.lifecycle_state & (1ULL << RARCH_PAUSE_TOGGLE)) + init_drivers(); + } } -void engine_handle_input (void *data, int32_t cmd) +void engine_handle_input(void) { bool debug_enable = g_settings.input.debug_enable; - struct android_app *android_app = (struct android_app*)data; + struct android_app *android_app = (struct android_app*)g_android; uint64_t *lifecycle_state = &g_extern.lifecycle_state; *lifecycle_state &= ~((1ULL << RARCH_RESET) | (1ULL << RARCH_REWIND) | (1ULL << RARCH_FAST_FORWARD_KEY) | (1ULL << RARCH_FAST_FORWARD_HOLD_KEY) | (1ULL << RARCH_MUTE) | (1ULL << RARCH_SAVE_STATE_KEY) | (1ULL << RARCH_LOAD_STATE_KEY) | (1ULL << RARCH_STATE_SLOT_PLUS) | (1ULL << RARCH_STATE_SLOT_MINUS)); diff --git a/frontend/frontend_android.c b/frontend/frontend_android.c index 6064c8ca65..d1ccd520fa 100644 --- a/frontend/frontend_android.c +++ b/frontend/frontend_android.c @@ -61,24 +61,10 @@ static void print_cur_config (void *data) static bool android_run_events (void *data) { - struct android_app *android_app = (struct android_app*)data; int id = ALooper_pollOnce(-1, NULL, NULL, NULL); if (id == LOOPER_ID_MAIN) - { - int8_t cmd; - - if (read(android_app->msgread, &cmd, sizeof(cmd)) != sizeof(cmd)) - cmd = -1; - - engine_handle_cmd(android_app, cmd); - - if (cmd == APP_CMD_INIT_WINDOW) - { - if (g_extern.lifecycle_state & (1ULL << RARCH_PAUSE_TOGGLE)) - init_drivers(); - } - } + engine_handle_cmd(); // Check if we are exiting. if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY)) diff --git a/frontend/frontend_android.h b/frontend/frontend_android.h index 16e6f21f9f..6592f5b85d 100644 --- a/frontend/frontend_android.h +++ b/frontend/frontend_android.h @@ -154,8 +154,8 @@ enum { }; int8_t android_app_read_cmd (void *data); -extern void engine_app_read_cmd (void *data); -extern void engine_handle_cmd (void *data, int32_t cmd); +extern void engine_app_read_cmd(void); +extern void engine_handle_cmd(void); extern struct android_app *g_android; diff --git a/retroarch.c b/retroarch.c index e9d0c21bd1..e584afe3c5 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2793,28 +2793,14 @@ bool rarch_main_iterate(void) } #ifdef ANDROID - struct android_app *android_app = (struct android_app*)g_android; int ident; while ((ident = ALooper_pollAll( (input_key_pressed_func(RARCH_PAUSE_TOGGLE)) ? -1 : 0, NULL, NULL, NULL)) >= 0) { if (ident == LOOPER_ID_MAIN) - { - int8_t cmd; - - if (read(android_app->msgread, &cmd, sizeof(cmd)) != sizeof(cmd)) - cmd = -1; - - engine_handle_cmd(android_app, cmd); - - if (cmd == APP_CMD_INIT_WINDOW) - { - if (g_extern.lifecycle_state & (1ULL << RARCH_PAUSE_TOGGLE)) - init_drivers(); - } - } + engine_handle_cmd(); else if (!input_key_pressed_func(RARCH_PAUSE_TOGGLE)) - engine_handle_input(android_app, 0); + engine_handle_input(); else return true; }