Move all of the code to menu_common.c to avoid code duplication

across frontends
This commit is contained in:
twinaphex 2013-04-28 16:38:13 +02:00
parent ca5db6d5b7
commit 63ba647018
10 changed files with 139 additions and 306 deletions

View File

@ -35,66 +35,6 @@
#undef HAVE_MENU
#endif
#ifdef HAVE_MENU
// FIXME: This should probably be in menu_common ...
static void load_menu_game_prepare(void)
{
if (g_extern.lifecycle_mode_state & (1ULL << MODE_INFO_DRAW))
{
char tmp[PATH_MAX];
char str[PATH_MAX];
fill_pathname_base(tmp, g_extern.fullpath, sizeof(tmp));
snprintf(str, sizeof(str), "INFO - Loading %s ...", tmp);
msg_queue_push(g_extern.msg_queue, str, 1, 1);
}
if (rgui->history)
{
rom_history_push(rgui->history,
g_extern.fullpath,
g_settings.libretro,
rgui->info.library_name);
}
// Draw frame for loading message
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, rgui->frame_buf_show, MENU_TEXTURE_FULLSCREEN);
rarch_render_cached_frame();
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, false,
MENU_TEXTURE_FULLSCREEN);
}
static bool load_menu_game(void)
{
if (g_extern.main_is_init)
rarch_main_deinit();
struct rarch_main_wrap args = {0};
args.verbose = g_extern.verbose;
args.config_path = *g_extern.config_path ? g_extern.config_path : NULL;
args.sram_path = *g_extern.savefile_dir ? g_extern.savefile_dir : NULL;
args.state_path = *g_extern.savestate_dir ? g_extern.savestate_dir : NULL;
args.rom_path = g_extern.fullpath;
args.libretro_path = g_settings.libretro;
if (rarch_main_init_wrap(&args) == 0)
{
RARCH_LOG("rarch_main_init_wrap() succeeded.\n");
return true;
}
else
{
RARCH_ERR("rarch_main_init_wrap() failed.\n");
return false;
}
}
#endif
int main(int argc, char *argv[])
{
#ifdef HAVE_RARCH_MAIN_IMPLEMENTATION
@ -121,11 +61,18 @@ int main(int argc, char *argv[])
load_menu_game_prepare();
// If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ...
if (!load_menu_game())
if (load_menu_game())
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
else
{
#ifdef RARCH_CONSOLE
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
#else
return 1;
#endif
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME);
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
{

View File

@ -224,38 +224,21 @@ static void *android_app_entry(void *data)
break;
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME))
{
if (g_extern.lifecycle_mode_state & (1ULL << MODE_INFO_DRAW))
load_menu_game_prepare();
// If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ...
if (load_menu_game())
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
else
{
char tmp[PATH_MAX];
char str[PATH_MAX];
fill_pathname_base(tmp, g_extern.fullpath, sizeof(tmp));
snprintf(str, sizeof(str), "INFO - Loading %s...", tmp);
msg_queue_push(g_extern.msg_queue, str, 1, 1);
}
#if defined(HAVE_RGUI) || defined(HAVE_RMENU) || defined(HAVE_RMENU_XUI)
if (rgui->history)
{
rom_history_push(rgui->history,
g_extern.fullpath,
g_settings.libretro,
rgui->info.library_name);
}
// draw frame for loading message
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, rgui->frame_buf_show, MENU_TEXTURE_FULLSCREEN);
rarch_render_cached_frame();
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, false,
MENU_TEXTURE_FULLSCREEN);
#ifdef RARCH_CONSOLE
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
#else
return 1;
#endif
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME);
g_extern.lifecycle_mode_state |= (1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
{
@ -274,35 +257,6 @@ static void *android_app_entry(void *data)
audio_stop_func();
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT))
{
if (g_extern.main_is_init)
rarch_main_deinit();
struct rarch_main_wrap args = {0};
args.verbose = true;
args.config_path = g_extern.config_path;
args.sram_path = NULL;
args.state_path = NULL;
args.rom_path = g_extern.fullpath;
args.libretro_path = g_settings.libretro;
init_ret = rarch_main_init_wrap(&args);
if (init_ret == 0)
{
RARCH_LOG("rarch_main_init succeeded.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
}
else
{
RARCH_ERR("rarch_main_init failed.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT);
}
else if(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
{
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT);

View File

@ -42,7 +42,7 @@ int rarch_main(int argc, char *argv[])
g_extern.verbose = true;
menu_init();
g_extern.lifecycle_mode_state |= 1ULL << MODE_INIT;
g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME);
for (;;)
{
@ -50,72 +50,27 @@ int rarch_main(int argc, char *argv[])
break;
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME))
{
if (g_extern.lifecycle_mode_state & (1ULL << MODE_INFO_DRAW))
load_menu_game_prepare();
// If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ...
if (load_menu_game())
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
else
{
char tmp[PATH_MAX];
char str[PATH_MAX];
fill_pathname_base(tmp, g_extern.fullpath, sizeof(tmp));
snprintf(str, sizeof(str), "INFO - Loading %s...", tmp);
msg_queue_push(g_extern.msg_queue, str, 1, 1);
}
#if defined(HAVE_RGUI) || defined(HAVE_RMENU) || defined(HAVE_RMENU_XUI)
if (rgui->history)
{
rom_history_push(rgui->history,
g_extern.fullpath,
g_settings.libretro,
rgui->info.library_name);
}
// draw frame for loading message
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, rgui->frame_buf_show, MENU_TEXTURE_FULLSCREEN);
rarch_render_cached_frame();
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, false,
MENU_TEXTURE_FULLSCREEN);
#ifdef RARCH_CONSOLE
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
#else
return 1;
#endif
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME);
g_extern.lifecycle_mode_state |= (1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
{
while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate());
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT))
{
if (g_extern.main_is_init)
rarch_main_deinit();
struct rarch_main_wrap args = {0};
args.verbose = g_extern.verbose;
args.config_path = *g_extern.config_path ? g_extern.config_path : NULL;
args.sram_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_SRAM_DIR_ENABLE)) ? g_extern.console.main_wrap.default_sram_dir : NULL;
args.state_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_STATE_DIR_ENABLE)) ? g_extern.console.main_wrap.default_savestate_dir : NULL;
args.rom_path = g_extern.fullpath;
args.libretro_path = g_settings.libretro;
int init_ret = rarch_main_init_wrap(&args);
if (init_ret == 0)
{
RARCH_LOG("rarch_main_init() succeeded.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
}
else
{
RARCH_ERR("rarch_main_init() failed.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
{
g_extern.lifecycle_mode_state |= 1ULL << MODE_MENU_PREINIT;

View File

@ -132,11 +132,9 @@ int rarch_main(int argc, char *argv[])
menu_init();
if (system_process_args(argc, argv) == 0)
{
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU);
g_extern.lifecycle_mode_state |= (1ULL << MODE_INIT);
}
system_process_args(argc, argv);
g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME);
for (;;)
{
@ -144,38 +142,21 @@ int rarch_main(int argc, char *argv[])
break;
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME))
{
if (g_extern.lifecycle_mode_state & (1ULL << MODE_INFO_DRAW))
load_menu_game_prepare();
// If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ...
if (load_menu_game())
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
else
{
char tmp[PATH_MAX];
char str[PATH_MAX];
fill_pathname_base(tmp, g_extern.fullpath, sizeof(tmp));
snprintf(str, sizeof(str), "INFO - Loading %s...", tmp);
msg_queue_push(g_extern.msg_queue, str, 1, 1);
}
#if defined(HAVE_RGUI) || defined(HAVE_RMENU) || defined(HAVE_RMENU_XUI)
if (rgui->history)
{
rom_history_push(rgui->history,
g_extern.fullpath,
g_settings.libretro,
rgui->info.library_name);
}
// draw frame for loading message
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, rgui->frame_buf_show, MENU_TEXTURE_FULLSCREEN);
rarch_render_cached_frame();
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, false,
MENU_TEXTURE_FULLSCREEN);
#ifdef RARCH_CONSOLE
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
#else
return 1;
#endif
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME);
g_extern.lifecycle_mode_state |= (1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
{
@ -193,35 +174,6 @@ int rarch_main(int argc, char *argv[])
audio_stop_func();
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT))
{
if (g_extern.main_is_init)
rarch_main_deinit();
struct rarch_main_wrap args = {0};
args.verbose = g_extern.verbose;
args.config_path = *g_extern.config_path ? g_extern.config_path : NULL;
args.sram_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_SRAM_DIR_ENABLE)) ? g_extern.console.main_wrap.default_sram_dir : NULL;
args.state_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_STATE_DIR_ENABLE)) ? g_extern.console.main_wrap.default_savestate_dir : NULL;
args.rom_path = *g_extern.fullpath ? g_extern.fullpath : NULL;
args.libretro_path = g_settings.libretro;
int init_ret = rarch_main_init_wrap(&args);
if (init_ret == 0)
{
RARCH_LOG("rarch_main_init succeeded.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
}
else
{
RARCH_ERR("rarch_main_init failed.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
msg_queue_push(g_extern.msg_queue, "ERROR - An error occurred during ROM loading.", 1, 180);
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
{
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT);

View File

@ -92,6 +92,10 @@ void* rarch_main_ios(void* args)
#ifdef HAVE_RGUI
char* system_directory = ios_get_rarch_system_directory();
strlcpy(g_extern.savestate_dir, system_directory,
sizeof(g_extern.savestate_dir));
strlcpy(g_extern.savesfile_dir, system_directory,
sizeof(g_extern.savefile_dir));
menu_init();
g_extern.lifecycle_mode_state |= 1ULL << MODE_GAME;
@ -102,38 +106,21 @@ void* rarch_main_ios(void* args)
break;
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME))
{
if (g_extern.lifecycle_mode_state & (1ULL << MODE_INFO_DRAW))
load_menu_game_prepare();
// If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ...
if (load_menu_game())
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
else
{
char tmp[PATH_MAX];
char str[PATH_MAX];
fill_pathname_base(tmp, g_extern.fullpath, sizeof(tmp));
snprintf(str, sizeof(str), "INFO - Loading %s...", tmp);
msg_queue_push(g_extern.msg_queue, str, 1, 1);
}
#if defined(HAVE_RGUI) || defined(HAVE_RMENU) || defined(HAVE_RMENU_XUI)
if (rgui->history)
{
rom_history_push(rgui->history,
g_extern.fullpath,
g_settings.libretro,
rgui->info.library_name);
}
// draw frame for loading message
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, rgui->frame_buf_show, MENU_TEXTURE_FULLSCREEN);
rarch_render_cached_frame();
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, false,
MENU_TEXTURE_FULLSCREEN);
#ifdef RARCH_CONSOLE
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
#else
return 1;
#endif
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME);
g_extern.lifecycle_mode_state |= (1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
{
@ -142,35 +129,6 @@ void* rarch_main_ios(void* args)
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT))
{
if (g_extern.main_is_init)
rarch_main_deinit();
struct rarch_main_wrap args = {0};
args.verbose = g_extern.verbose;
args.config_path = *g_extern.config_path ? g_extern.config_path : NULL;
args.sram_path = system_directory;
args.state_path = system_directory;
args.rom_path = g_extern.fullpath;
args.libretro_path = g_settings.libretro;
int init_ret = rarch_main_init_wrap(&args);
if (init_ret == 0)
{
RARCH_LOG("rarch_main_init() succeeded.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
}
else
{
RARCH_ERR("rarch_main_init() failed.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
msg_queue_push(g_extern.msg_queue, "ERROR - An error occurred during ROM loading.", 1, 180);
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
{
g_extern.lifecycle_mode_state |= 1ULL << MODE_MENU_PREINIT;

View File

@ -32,6 +32,10 @@
rgui_handle_t *rgui;
#if defined(RARCH_CONSOLE) || defined(__BLACKBERRY_QNX__)
#define GLOBAL_INIT
#endif
#ifdef HAVE_SHADER_MANAGER
void shader_manager_init(rgui_handle_t *rgui)
{
@ -363,6 +367,77 @@ void rgui_list_get_last(const rgui_list_t *list,
#endif
#ifdef GLOBAL_INIT
static bool global_init_done = false;
#endif
void load_menu_game_prepare(void)
{
#ifdef GLOBAL_INIT
if (!global_init_done)
return;
#endif
if (g_extern.lifecycle_mode_state & (1ULL << MODE_INFO_DRAW))
{
char tmp[PATH_MAX];
char str[PATH_MAX];
fill_pathname_base(tmp, g_extern.fullpath, sizeof(tmp));
snprintf(str, sizeof(str), "INFO - Loading %s ...", tmp);
msg_queue_push(g_extern.msg_queue, str, 1, 1);
}
if (rgui->history)
{
rom_history_push(rgui->history,
g_extern.fullpath,
g_settings.libretro,
rgui->info.library_name);
}
// Draw frame for loading message
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, rgui->frame_buf_show, MENU_TEXTURE_FULLSCREEN);
rarch_render_cached_frame();
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_enable(driver.video_data, false,
MENU_TEXTURE_FULLSCREEN);
}
bool load_menu_game(void)
{
if (g_extern.main_is_init)
rarch_main_deinit();
struct rarch_main_wrap args = {0};
args.verbose = g_extern.verbose;
args.config_path = *g_extern.config_path ? g_extern.config_path : NULL;
args.sram_path = *g_extern.savefile_dir ? g_extern.savefile_dir : NULL;
args.state_path = *g_extern.savestate_dir ? g_extern.savestate_dir : NULL;
args.rom_path = g_extern.fullpath;
args.libretro_path = g_settings.libretro;
#ifdef GLOBAL_INIT
if (!global_init_done)
global_init_done = true;
#endif
if (rarch_main_init_wrap(&args) == 0)
{
RARCH_LOG("rarch_main_init_wrap() succeeded.\n");
return true;
}
else
{
RARCH_ERR("rarch_main_init_wrap() failed.\n");
return false;
}
}
void menu_init(void)
{
rgui = rgui_init();

View File

@ -268,6 +268,9 @@ void shader_manager_get_str(struct gfx_shader *shader,
char *type_str, size_t type_str_size, unsigned type);
#endif
void load_menu_game_prepare(void);
bool load_menu_game(void);
#ifdef __cplusplus
}
#endif

View File

@ -341,15 +341,10 @@ static int system_process_args(int argc, char *argv[])
if (argc > 2 && argv[1] != NULL && argv[2] != NULL)
{
g_extern.lifecycle_mode_state |= (1ULL << MODE_EXTLAUNCH_CHANNEL);
snprintf(g_extern.fullpath, sizeof(g_extern.fullpath),
"%s%s", argv[1], argv[2]);
g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME);
ret = 1;
}
else
g_extern.lifecycle_mode_state |= (1ULL << MODE_EXTLAUNCH_SALAMANDER);
return ret;
}

View File

@ -208,10 +208,7 @@ static void get_environment_settings(int argc, char *argv[])
else
#endif
#ifndef IS_SALAMANDER
{
g_extern.lifecycle_mode_state |= (1ULL << MODE_EXTLAUNCH_SALAMANDER);
RARCH_WARN("Started from Salamander, auto-game start disabled.\n");
}
#endif
memset(&size, 0x00, sizeof(CellGameContentSize));
@ -350,7 +347,6 @@ static int system_process_args(int argc, char *argv[])
{
RARCH_LOG("Started from multiMAN, will auto-start game.\n");
strlcpy(g_extern.fullpath, argv[1], sizeof(g_extern.fullpath));
g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME);
ret = 1;
}
#endif

View File

@ -112,8 +112,6 @@ enum menu_enums
MODE_MENU_INGAME_EXIT,
MODE_INFO_DRAW,
MODE_FPS_DRAW,
MODE_EXTLAUNCH_SALAMANDER,
MODE_EXTLAUNCH_CHANNEL,
MODE_EXTLAUNCH_MULTIMAN,
MODE_EXIT,
MODE_EXITSPAWN,