From 9e1dfbef295ee09c08bc2e44a0ad064537e7fcab Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 22 May 2014 03:12:56 +0200 Subject: [PATCH] Split up defer core functionality to menu_common and create callbacks for menu backend context-specific operations --- driver.h | 2 + frontend/menu/backend/menu_common_backend.c | 58 +++++++++------------ frontend/menu/backend/menu_lakka_backend.c | 2 + frontend/menu/menu_common.c | 37 +++++++++++++ frontend/menu/menu_common.h | 2 + 5 files changed, 69 insertions(+), 32 deletions(-) diff --git a/driver.h b/driver.h index cdf5757306..7492c3cb51 100644 --- a/driver.h +++ b/driver.h @@ -405,6 +405,8 @@ typedef struct menu_ctx_driver_backend int (*setting_toggle)(void *, unsigned, unsigned, unsigned); int (*setting_set)(void *, unsigned, unsigned); void (*setting_set_label)(char *, size_t, unsigned *, unsigned); + void (*defer_decision_automatic)(void *); + void (*defer_decision_manual)(void *); const char *ident; } menu_ctx_driver_backend_t; diff --git a/frontend/menu/backend/menu_common_backend.c b/frontend/menu/backend/menu_common_backend.c index bb58226e7b..ab9a421de2 100644 --- a/frontend/menu/backend/menu_common_backend.c +++ b/frontend/menu/backend/menu_common_backend.c @@ -1196,6 +1196,29 @@ static int menu_custom_bind_iterate_keyboard(void *data, unsigned action) return 0; } +static void menu_common_defer_decision_automatic(void *data) +{ + rgui_handle_t *rgui = (rgui_handle_t*)data; + + if (!rgui) + return; + + menu_flush_stack_type(rgui, RGUI_SETTINGS); + rgui->msg_force = true; +} + +static void menu_common_defer_decision_manual(void *data) +{ + rgui_handle_t *rgui = (rgui_handle_t*)data; + + if (!rgui) + return; + + file_list_push(rgui->menu_stack, g_settings.libretro_directory, RGUI_SETTINGS_DEFERRED_CORE, rgui->selection_ptr); + menu_clear_navigation(rgui); + rgui->need_refresh = true; +} + static int menu_common_iterate(void *data, unsigned action) { rgui_handle_t *rgui = (rgui_handle_t*)data; @@ -1520,38 +1543,7 @@ static int menu_common_iterate(void *data, unsigned action) else { if (rgui->defer_core) - { - fill_pathname_join(rgui->deferred_path, dir, path, sizeof(rgui->deferred_path)); - - const core_info_t *info = NULL; - size_t supported = 0; - if (rgui->core_info) - core_info_list_get_supported_cores(rgui->core_info, rgui->deferred_path, &info, &supported); - - if (supported == 1) // Can make a decision right now. - { - strlcpy(g_extern.fullpath, rgui->deferred_path, sizeof(g_extern.fullpath)); - strlcpy(g_settings.libretro, info->path, sizeof(g_settings.libretro)); - -#ifdef HAVE_DYNAMIC - menu_update_system_info(rgui, &rgui->load_no_rom); - g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); -#else - rarch_environment_cb(RETRO_ENVIRONMENT_SET_LIBRETRO_PATH, (void*)g_settings.libretro); - rarch_environment_cb(RETRO_ENVIRONMENT_EXEC, (void*)g_extern.fullpath); -#endif - - menu_flush_stack_type(rgui, RGUI_SETTINGS); - rgui->msg_force = true; - ret = -1; - } - else // Present a selection. - { - file_list_push(rgui->menu_stack, g_settings.libretro_directory, RGUI_SETTINGS_DEFERRED_CORE, rgui->selection_ptr); - menu_clear_navigation(rgui); - rgui->need_refresh = true; - } - } + ret = menu_defer_core(rgui, dir, path); else { fill_pathname_join(g_extern.fullpath, dir, path, sizeof(g_extern.fullpath)); @@ -4300,5 +4292,7 @@ const menu_ctx_driver_backend_t menu_ctx_backend_common = { menu_common_setting_toggle, menu_common_setting_set, menu_common_setting_set_label, + menu_common_defer_decision_automatic, + menu_common_defer_decision_manual, "menu_common", }; diff --git a/frontend/menu/backend/menu_lakka_backend.c b/frontend/menu/backend/menu_lakka_backend.c index 9b99e1f18d..e8d8a1549e 100644 --- a/frontend/menu/backend/menu_lakka_backend.c +++ b/frontend/menu/backend/menu_lakka_backend.c @@ -177,5 +177,7 @@ const menu_ctx_driver_backend_t menu_ctx_backend_lakka = { NULL, NULL, NULL, + NULL, + NULL, "menu_lakka", }; diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index 5ceb24f223..c4ce8991e8 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -66,6 +66,43 @@ void menu_update_system_info(void *data, bool *load_no_rom) #endif } +// When selection is presented back, returns 0. If it can make a decision right now, returns -1. +int menu_defer_core(void *data, const char *dir, const char *path) +{ + rgui_handle_t *rgui = (rgui_handle_t*)data; + const core_info_t *info = NULL; + size_t supported = 0; + + fill_pathname_join(rgui->deferred_path, dir, path, sizeof(rgui->deferred_path)); + + if (rgui->core_info) + core_info_list_get_supported_cores(rgui->core_info, rgui->deferred_path, &info, &supported); + + if (supported == 1) // Can make a decision right now. + { + strlcpy(g_extern.fullpath, rgui->deferred_path, sizeof(g_extern.fullpath)); + strlcpy(g_settings.libretro, info->path, sizeof(g_settings.libretro)); + +#ifdef HAVE_DYNAMIC + menu_update_system_info(rgui, &rgui->load_no_rom); + g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); +#else + rarch_environment_cb(RETRO_ENVIRONMENT_SET_LIBRETRO_PATH, (void*)g_settings.libretro); + rarch_environment_cb(RETRO_ENVIRONMENT_EXEC, (void*)g_extern.fullpath); +#endif + if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->defer_decision_automatic) + driver.menu_ctx->backend->defer_decision_automatic(rgui); + return -1; + } + else + { + if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->defer_decision_manual) + driver.menu_ctx->backend->defer_decision_manual(rgui); + } + + return 0; +} + void menu_rom_history_push(void *data, const char *path, const char *core_path, const char *core_name) diff --git a/frontend/menu/menu_common.h b/frontend/menu/menu_common.h index 3b6834a4b2..2c1667ef89 100644 --- a/frontend/menu/menu_common.h +++ b/frontend/menu/menu_common.h @@ -204,6 +204,8 @@ bool menu_replace_config(void *data, const char *path); bool menu_save_new_config(void); +int menu_defer_core(void *data, const char *dir, const char *path); + uint64_t menu_input(void *data); void menu_flush_stack_type(void *data, unsigned final_type);