From fe49a0fe40536a8157c15e9456ce85f9ff1c32ff Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Sep 2014 15:32:32 +0200 Subject: [PATCH 1/8] Some control flow changes --- frontend/frontend.c | 26 ++++++++++++-------------- retroarch.c | 3 --- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/frontend/frontend.c b/frontend/frontend.c index 99e8a9e2c9..4c7de987fc 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -209,23 +209,21 @@ int main_entry_iterate_menu(signature(), args_type() args) if (g_extern.system.shutdown) return main_entry_iterate_shutdown(signature_expand(), args); - if (menu_iterate()) + if (!menu_iterate()) { - if (driver.frontend_ctx && driver.frontend_ctx->process_events) - driver.frontend_ctx->process_events(args); - return 0; + rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); + driver_set_nonblock_state(driver.nonblock_state); + + rarch_main_command(RARCH_CMD_AUDIO_START); + rarch_main_set_state(RARCH_ACTION_STATE_FLUSH_INPUT); + + if (input_key_pressed_func(RARCH_QUIT_KEY) || + !driver.video->alive(driver.video_data)) + return 1; } - rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); - driver_set_nonblock_state(driver.nonblock_state); - - rarch_main_command(RARCH_CMD_AUDIO_START); - rarch_main_set_state(RARCH_ACTION_STATE_FLUSH_INPUT); - - if (input_key_pressed_func(RARCH_QUIT_KEY) || - !driver.video->alive(driver.video_data)) - return 1; - + if (driver.frontend_ctx && driver.frontend_ctx->process_events) + driver.frontend_ctx->process_events(args); return 0; } #endif diff --git a/retroarch.c b/retroarch.c index a67af7d7f8..777e6125ae 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3285,9 +3285,6 @@ static inline void limit_frame_time(void) void rarch_main_set_state(unsigned cmd) { - - frontend_loop = NULL; - switch (cmd) { case RARCH_ACTION_STATE_MENU_PREINIT: From a3269ff9eddde9bab10b5218aef2b9f9a7864a62 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Sep 2014 15:37:47 +0200 Subject: [PATCH 2/8] Add RARCH_ACTION_STATE_MENU_RUNNING_FINISHED to RARCH_CMD_RESUME --- retroarch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/retroarch.c b/retroarch.c index 777e6125ae..ee6dc10f94 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3545,6 +3545,9 @@ void rarch_main_command(unsigned cmd) rarch_main_set_state(RARCH_ACTION_STATE_FORCE_QUIT); break; case RARCH_CMD_RESUME: +#ifdef HAVE_MENU + rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); +#endif rarch_main_set_state(RARCH_ACTION_STATE_RUNNING); break; case RARCH_CMD_RESTART_RETROARCH: From cb1eea1ec243abc87f7727201781eaf22aa03183 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 14 Sep 2014 16:08:28 +0200 Subject: [PATCH 3/8] Add logging to main_entry_decide --- frontend/frontend.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontend/frontend.c b/frontend/frontend.c index 4c7de987fc..1888248fcb 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -85,16 +85,31 @@ int main_entry_decide(signature(), args_type() args) frontend_loop = NULL; if (g_extern.lifecycle_state & (1ULL << MODE_CLEAR_INPUT)) + { + RARCH_LOG("Frontend loop state changed : MODE_CLEAR_INPUT.\n"); frontend_loop = main_entry_iterate_clear_input; + } else if (g_extern.lifecycle_state & (1ULL << MODE_LOAD_GAME)) + { + RARCH_LOG("Frontend loop state changed : MODE_LOAD_GAME.\n"); frontend_loop = main_entry_iterate_load_content; + } else if (g_extern.lifecycle_state & (1ULL << MODE_GAME)) + { + RARCH_LOG("Frontend loop state changed : MODE_GAME.\n"); frontend_loop = main_entry_iterate_content; + } #ifdef HAVE_MENU else if (g_extern.lifecycle_state & (1ULL << MODE_MENU_PREINIT)) + { + RARCH_LOG("Frontend loop state changed : MODE_MENU_PREINIT.\n"); frontend_loop = main_entry_iterate_menu_preinit; + } else if (g_extern.lifecycle_state & (1ULL << MODE_MENU)) + { + RARCH_LOG("Frontend loop state changed : MODE_MENU.\n"); frontend_loop = main_entry_iterate_menu; + } #endif return 0; From 2284395c4dcbe1f380e2386da01f17f5971114ce Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Sep 2014 16:29:09 +0200 Subject: [PATCH 4/8] Get rid of frontend_loop --- frontend/frontend.c | 51 +++++++++---------------- frontend/frontend_context.h | 3 -- frontend/platform/platform_apple.c | 2 +- frontend/platform/platform_emscripten.c | 2 +- retroarch.c | 2 - 5 files changed, 19 insertions(+), 41 deletions(-) diff --git a/frontend/frontend.c b/frontend/frontend.c index 1888248fcb..512d4891fd 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -63,8 +63,6 @@ #define MAX_ARGS 32 -int (*frontend_loop)(signature(), args_type() args); - static retro_keyboard_event_t key_event; static int main_entry_iterate_shutdown(signature(), args_type() args) @@ -82,37 +80,24 @@ static int main_entry_iterate_shutdown(signature(), args_type() args) int main_entry_decide(signature(), args_type() args) { - frontend_loop = NULL; - - if (g_extern.lifecycle_state & (1ULL << MODE_CLEAR_INPUT)) - { - RARCH_LOG("Frontend loop state changed : MODE_CLEAR_INPUT.\n"); - frontend_loop = main_entry_iterate_clear_input; - } - else if (g_extern.lifecycle_state & (1ULL << MODE_LOAD_GAME)) - { - RARCH_LOG("Frontend loop state changed : MODE_LOAD_GAME.\n"); - frontend_loop = main_entry_iterate_load_content; - } - else if (g_extern.lifecycle_state & (1ULL << MODE_GAME)) - { - RARCH_LOG("Frontend loop state changed : MODE_GAME.\n"); - frontend_loop = main_entry_iterate_content; - } #ifdef HAVE_MENU - else if (g_extern.lifecycle_state & (1ULL << MODE_MENU_PREINIT)) - { - RARCH_LOG("Frontend loop state changed : MODE_MENU_PREINIT.\n"); - frontend_loop = main_entry_iterate_menu_preinit; - } - else if (g_extern.lifecycle_state & (1ULL << MODE_MENU)) - { - RARCH_LOG("Frontend loop state changed : MODE_MENU.\n"); - frontend_loop = main_entry_iterate_menu; - } -#endif + if (g_extern.system.shutdown) + return main_entry_iterate_shutdown(signature_expand(), args); + if (g_extern.lifecycle_state & (1ULL << MODE_CLEAR_INPUT)) + return main_entry_iterate_clear_input(signature_expand(), args); + if (g_extern.lifecycle_state & (1ULL << MODE_LOAD_GAME)) + return main_entry_iterate_load_content(signature_expand(), args); + if (g_extern.lifecycle_state & (1ULL << MODE_GAME)) + return main_entry_iterate_content(signature_expand(), args); + if (g_extern.lifecycle_state & (1ULL << MODE_MENU_PREINIT)) + return main_entry_iterate_menu_preinit(signature_expand(), args); + if (g_extern.lifecycle_state & (1ULL << MODE_MENU)) + return main_entry_iterate_menu(signature_expand(), args); - return 0; + return 1; +#else + return main_entry_iterate_content_nomenu(signature_expand(), args); +#endif } int main_entry_iterate_content(signature(), args_type() args) @@ -408,12 +393,10 @@ returntype main_entry(signature()) if (ret) #endif rarch_playlist_push(g_extern.history, g_extern.fullpath); -#else - frontend_loop = main_entry_iterate_content_nomenu; #endif #if defined(HAVE_MAIN_LOOP) - while (frontend_loop && !frontend_loop(signature_expand(), args)); + while (!main_entry_decide(signature_expand(), args)); main_exit(args); #endif diff --git a/frontend/frontend_context.h b/frontend/frontend_context.h index 6ba113cda4..e51466dad9 100644 --- a/frontend/frontend_context.h +++ b/frontend/frontend_context.h @@ -86,9 +86,6 @@ int main_entry_iterate_menu_preinit(signature(), args_type() args); int main_entry_iterate_menu(signature(), args_type() args); #endif -extern int (*frontend_loop)(signature(), args_type() args); - - #ifdef __cplusplus } #endif diff --git a/frontend/platform/platform_apple.c b/frontend/platform/platform_apple.c index b646fde300..9ff7f520d2 100644 --- a/frontend/platform/platform_apple.c +++ b/frontend/platform/platform_apple.c @@ -31,7 +31,7 @@ static void do_iteration(void) if (!(g_extern.main_is_init && !g_extern.is_paused)) return; - if (!frontend_loop || (frontend_loop && frontend_loop(0, NULL, NULL))) + if (main_entry_decide(0, NULL, NULL)) { main_exit(NULL); return; diff --git a/frontend/platform/platform_emscripten.c b/frontend/platform/platform_emscripten.c index e7364a32b2..138906e552 100644 --- a/frontend/platform/platform_emscripten.c +++ b/frontend/platform/platform_emscripten.c @@ -27,7 +27,7 @@ static void emscripten_mainloop(void) { - if (frontend_loop || (frontend_loop && frontend_loop(0, NULL, NULL))) + if (main_entry_decide(0, NULL, NULL)) { main_exit(NULL); exit(0); diff --git a/retroarch.c b/retroarch.c index ee6dc10f94..5217ff7c0c 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3332,8 +3332,6 @@ void rarch_main_set_state(unsigned cmd) default: break; } - - frontend_loop = main_entry_decide; } void rarch_main_command(unsigned cmd) From aae73438deae458f705b1e8fcbb4164e3934cd1b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Sep 2014 16:36:15 +0200 Subject: [PATCH 5/8] Simplify frontend.c entry functions --- frontend/frontend.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/frontend/frontend.c b/frontend/frontend.c index 512d4891fd..73b7c764ba 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -102,9 +102,6 @@ int main_entry_decide(signature(), args_type() args) int main_entry_iterate_content(signature(), args_type() args) { - if (g_extern.system.shutdown) - return main_entry_iterate_shutdown(signature_expand(), args); - if (!rarch_main_iterate()) { rarch_main_set_state(RARCH_ACTION_STATE_RUNNING_FINISHED); @@ -131,9 +128,6 @@ int main_entry_iterate_clear_input(signature(), args_type() args) { (void)args; - if (g_extern.system.shutdown) - return main_entry_iterate_shutdown(signature_expand(), args); - rarch_input_poll(); #ifdef HAVE_MENU if (menu_input()) @@ -149,9 +143,6 @@ int main_entry_iterate_clear_input(signature(), args_type() args) int main_entry_iterate_load_content(signature(), args_type() args) { - if (g_extern.system.shutdown) - return main_entry_iterate_shutdown(signature_expand(), args); - #ifdef HAVE_MENU if (!load_menu_content()) { @@ -172,9 +163,6 @@ int main_entry_iterate_menu_preinit(signature(), args_type() args) { int i; - if (g_extern.system.shutdown) - return main_entry_iterate_shutdown(signature_expand(), args); - /* Menu should always run with vsync on. */ rarch_main_command(RARCH_CMD_VIDEO_SET_BLOCKING_STATE); @@ -206,24 +194,23 @@ int main_entry_iterate_menu_preinit(signature(), args_type() args) int main_entry_iterate_menu(signature(), args_type() args) { - if (g_extern.system.shutdown) - return main_entry_iterate_shutdown(signature_expand(), args); - - if (!menu_iterate()) + if (menu_iterate()) { - rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); - driver_set_nonblock_state(driver.nonblock_state); - - rarch_main_command(RARCH_CMD_AUDIO_START); - rarch_main_set_state(RARCH_ACTION_STATE_FLUSH_INPUT); - - if (input_key_pressed_func(RARCH_QUIT_KEY) || - !driver.video->alive(driver.video_data)) - return 1; + if (driver.frontend_ctx && driver.frontend_ctx->process_events) + driver.frontend_ctx->process_events(args); + return 0; } - if (driver.frontend_ctx && driver.frontend_ctx->process_events) - driver.frontend_ctx->process_events(args); + rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); + driver_set_nonblock_state(driver.nonblock_state); + + rarch_main_command(RARCH_CMD_AUDIO_START); + rarch_main_set_state(RARCH_ACTION_STATE_FLUSH_INPUT); + + if (input_key_pressed_func(RARCH_QUIT_KEY) || + !driver.video->alive(driver.video_data)) + return 1; + return 0; } #endif From eff9bf17a8e5ce669eff0e8eff88303c271a3e6d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Sep 2014 18:07:00 +0200 Subject: [PATCH 6/8] Reimplement menu toggle in menu - now remembers last menu (Disp) Menu display drivers shouldn't influence control flow of menu, so take this out and move menu toggle control flow to menu_backend driver instead --- frontend/menu/backend/menu_common_backend.c | 7 +++++++ frontend/menu/disp/glui.c | 8 -------- frontend/menu/disp/lakka.c | 4 ---- frontend/menu/disp/rgui.c | 10 ---------- frontend/menu/disp/rmenu.c | 11 +---------- frontend/menu/disp/rmenu_xui.cpp | 7 +------ frontend/menu/menu_common.c | 7 ++++--- frontend/menu/menu_common.h | 1 + 8 files changed, 14 insertions(+), 41 deletions(-) diff --git a/frontend/menu/backend/menu_common_backend.c b/frontend/menu/backend/menu_common_backend.c index 6ebe187f87..4b3891969b 100644 --- a/frontend/menu/backend/menu_common_backend.c +++ b/frontend/menu/backend/menu_common_backend.c @@ -1409,6 +1409,13 @@ static int menu_common_iterate(unsigned action) if (driver.video_data && driver.menu_ctx && driver.menu_ctx->set_texture) driver.menu_ctx->set_texture(driver.menu); + if (action == MENU_ACTION_TOGGLE && + g_extern.main_is_init && !g_extern.libretro_dummy) + { + rarch_main_command(RARCH_CMD_RESUME); + return -1; + } + if (!strcmp(menu_label, "help")) return menu_start_screen_iterate(action); else if (!strcmp(menu_label, "info_screen")) diff --git a/frontend/menu/disp/glui.c b/frontend/menu/disp/glui.c index 972c410875..95d746f781 100644 --- a/frontend/menu/disp/glui.c +++ b/frontend/menu/disp/glui.c @@ -316,14 +316,6 @@ static int glui_input_postprocess(uint64_t old_state) { (void)old_state; - if ((driver.menu->trigger_state & (1ULL << RARCH_MENU_TOGGLE)) && - g_extern.main_is_init && - !g_extern.libretro_dummy) - { - rarch_main_command(RARCH_CMD_RESUME); - return -1; - } - return 0; } diff --git a/frontend/menu/disp/lakka.c b/frontend/menu/disp/lakka.c index 15480870ee..d2adfb59f5 100644 --- a/frontend/menu/disp/lakka.c +++ b/frontend/menu/disp/lakka.c @@ -1069,11 +1069,7 @@ static int lakka_input_postprocess(uint64_t old_state) & (1ULL << RARCH_MENU_TOGGLE)) && g_extern.main_is_init && !g_extern.libretro_dummy) - { global_alpha = 0; - rarch_main_command(RARCH_CMD_RESUME); - return -1; - } if (! global_alpha) add_tween(LAKKA_DELAY, 1.0, &global_alpha, &inOutQuad, NULL); diff --git a/frontend/menu/disp/rgui.c b/frontend/menu/disp/rgui.c index 1dbe16dcce..12fe12ee10 100644 --- a/frontend/menu/disp/rgui.c +++ b/frontend/menu/disp/rgui.c @@ -454,16 +454,6 @@ static void rgui_free(void *data) static int rgui_input_postprocess(uint64_t old_state) { - (void)old_state; - - if ((driver.menu->trigger_state & (1ULL << RARCH_MENU_TOGGLE)) && - g_extern.main_is_init && - !g_extern.libretro_dummy) - { - rarch_main_command(RARCH_CMD_RESUME); - return -1; - } - return 0; } diff --git a/frontend/menu/disp/rmenu.c b/frontend/menu/disp/rmenu.c index 12cd0d142e..2dfbab944c 100644 --- a/frontend/menu/disp/rmenu.c +++ b/frontend/menu/disp/rmenu.c @@ -328,16 +328,7 @@ static void rmenu_free(void *data) static int rmenu_input_postprocess(uint64_t old_state) { - menu_handle_t *menu = (menu_handle_t*)driver.menu; - - if ((menu->trigger_state & (1ULL << RARCH_MENU_TOGGLE)) && - g_extern.main_is_init && - !g_extern.libretro_dummy) - { - rarch_main_command(RARCH_CMD_RESUME); - return -1; - } - + (void)old_state; return 0; } diff --git a/frontend/menu/disp/rmenu_xui.cpp b/frontend/menu/disp/rmenu_xui.cpp index cf3d91643d..6cfee7772e 100644 --- a/frontend/menu/disp/rmenu_xui.cpp +++ b/frontend/menu/disp/rmenu_xui.cpp @@ -343,12 +343,7 @@ static void rmenu_xui_frame(void) static int rmenu_xui_input_postprocess(uint64_t old_state) { - if ((driver.menu->trigger_state & (1ULL << RARCH_MENU_TOGGLE)) && - g_extern.main_is_init) - { - rarch_main_command(RARCH_CMD_RESUME); - return -1; - } + (void)old_state; return 0; } diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index 29f840de70..c1addf3ee8 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -295,6 +295,8 @@ static unsigned input_frame(uint64_t trigger_state) return MENU_ACTION_START; if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT)) return MENU_ACTION_SELECT; + if (trigger_state & (1ULL << RARCH_MENU_TOGGLE)) + return MENU_ACTION_TOGGLE; return MENU_ACTION_NOOP; } @@ -304,7 +306,6 @@ bool menu_iterate(void) static bool initial_held = true; static bool first_held = false; uint64_t input_state = 0; - int32_t input_entry_ret = 0; int32_t ret = 0; if (!driver.menu) @@ -371,7 +372,7 @@ bool menu_iterate(void) if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->iterate) - input_entry_ret = driver.menu_ctx->backend->iterate(action); + driver.menu_ctx->backend->iterate(action); draw_frame(true); throttle_frame(); @@ -383,7 +384,7 @@ bool menu_iterate(void) if (ret < 0) menu_flush_stack_type(driver.menu->menu_stack, MENU_SETTINGS); - if (ret || input_entry_ret) + if (ret) return false; return true; diff --git a/frontend/menu/menu_common.h b/frontend/menu/menu_common.h index 3566342136..1a234bb962 100644 --- a/frontend/menu/menu_common.h +++ b/frontend/menu/menu_common.h @@ -94,6 +94,7 @@ typedef enum MENU_ACTION_MESSAGE, MENU_ACTION_SCROLL_DOWN, MENU_ACTION_SCROLL_UP, + MENU_ACTION_TOGGLE, MENU_ACTION_NOOP } menu_action_t; From 8caf16a538caa9ccc6a657e0b754dd6581cf3b9b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Sep 2014 19:30:44 +0200 Subject: [PATCH 7/8] (WGL) Build fix --- gfx/context/wgl_ctx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gfx/context/wgl_ctx.c b/gfx/context/wgl_ctx.c index e78d312c5b..f5788a46bd 100644 --- a/gfx/context/wgl_ctx.c +++ b/gfx/context/wgl_ctx.c @@ -563,8 +563,8 @@ static void gfx_ctx_input_driver(void *data, const input_driver_t **input, void { (void)data; dinput_wgl = input_dinput.init(); - *input = dinput ? &input_dinput : NULL; - *input_data = dinput; + *input = dinput_wgl ? &input_dinput : NULL; + *input_data = dinput_wgl; } static bool gfx_ctx_has_focus(void *data) From 3158a837f036ca531a1f7ed9df0138667bb21063 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Sep 2014 19:53:44 +0200 Subject: [PATCH 8/8] Define HAVE_COMMAND for Makefile.win --- Makefile.win | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.win b/Makefile.win index 4deb7bb2f9..fb10946d18 100644 --- a/Makefile.win +++ b/Makefile.win @@ -10,6 +10,7 @@ HAVE_DYLIB = 1 HAVE_D3D9 = 1 HAVE_NETPLAY = 1 HAVE_STDIN_CMD = 1 +HAVE_COMMAND = 1 HAVE_THREADS = 1 HAVE_RGUI = 1 HAVE_GLUI = 1