(Menu) Move 'rgui' global variable to 'driver' struct

This commit is contained in:
twinaphex 2014-05-09 05:47:32 +02:00
parent c35c1fdb74
commit 0454ac623e
11 changed files with 157 additions and 81 deletions

View File

@ -466,6 +466,7 @@ typedef struct driver
void *video_data;
void *input_data;
#ifdef HAVE_MENU
void *menu;
const menu_ctx_driver_t *menu_ctx;
#endif

View File

@ -127,7 +127,7 @@ static retro_keyboard_event_t key_event;
static int main_entry_iterate_clear_input(args_type() args)
{
rarch_input_poll();
if (!menu_input())
if (!menu_input(driver.menu))
{
// Restore libretro keyboard callback.
g_extern.system.key_event = key_event;
@ -143,7 +143,7 @@ static int main_entry_iterate_shutdown(args_type() args)
#ifdef HAVE_MENU
// Load dummy core instead of exiting RetroArch completely.
if (g_settings.load_dummy_on_core_shutdown)
load_menu_game_prepare_dummy();
load_menu_game_prepare_dummy(driver.menu);
else
#endif
return 1;
@ -173,9 +173,9 @@ static int main_entry_iterate_content(args_type() args)
static int main_entry_iterate_load_content(args_type() args)
{
load_menu_game_prepare();
load_menu_game_prepare(driver.menu);
if (load_menu_game())
if (load_menu_game(driver.menu))
{
g_extern.lifecycle_state |= (1ULL << MODE_GAME);
if (driver.video_data && driver.video_poke && driver.video_poke->set_aspect_ratio)
@ -203,6 +203,7 @@ static int main_entry_iterate_load_content(args_type() args)
static int main_entry_iterate_menu_preinit(args_type() args)
{
int i;
rgui_handle_t *rgui = (rgui_handle_t*)driver.menu;
// Menu should always run with vsync on.
video_set_nonblock_state_func(false);
@ -222,6 +223,12 @@ static int main_entry_iterate_menu_preinit(args_type() args)
if (driver.audio_data)
audio_stop_func();
if (!rgui)
{
driver.menu = (rgui_handle_t*)menu_init();
rgui = (rgui_handle_t*)driver.menu;
}
rgui->need_refresh = true;
rgui->old_input_state |= 1ULL << RARCH_MENU_TOGGLE;
@ -233,7 +240,7 @@ static int main_entry_iterate_menu_preinit(args_type() args)
static int main_entry_iterate_menu(args_type() args)
{
if (menu_iterate())
if (menu_iterate(driver.menu))
{
if (frontend_ctx && frontend_ctx->process_events)
frontend_ctx->process_events(args);
@ -288,7 +295,7 @@ void main_exit(args_type() args)
#ifdef HAVE_MENU
g_extern.system.shutdown = false;
menu_free();
menu_free(driver.menu);
if (g_extern.config_save_on_exit && *g_extern.config_path)
{
@ -366,7 +373,7 @@ returntype main_entry(signature())
#if defined(HAVE_MENU)
if (menu_init_enable)
menu_init();
driver.menu = (rgui_handle_t*)menu_init();
if (frontend_ctx && frontend_ctx->process_args)
frontend_ctx->process_args(argc, argv, args);
@ -379,7 +386,7 @@ returntype main_entry(signature())
// If we started a ROM directly from command line,
// push it to ROM history.
if (!g_extern.libretro_dummy)
menu_rom_history_push_current();
menu_rom_history_push_current(driver.menu);
}
while (!main_entry_iterate(signature_expand(), args));

View File

@ -1340,7 +1340,7 @@ static int menu_common_iterate(void *data, unsigned action)
// FIXME: Add for consoles.
strlcpy(g_settings.libretro, path, sizeof(g_settings.libretro));
strlcpy(g_extern.fullpath, rgui->deferred_path, sizeof(g_extern.fullpath));
load_menu_game_new_core();
load_menu_game_new_core(rgui);
rgui->msg_force = true;
ret = -1;
menu_flush_stack_type(rgui, RGUI_SETTINGS);
@ -1384,7 +1384,7 @@ static int menu_common_iterate(void *data, unsigned action)
fill_pathname_join(config, dir, path, sizeof(config));
menu_flush_stack_type(rgui, RGUI_SETTINGS);
rgui->msg_force = true;
if (menu_replace_config(config))
if (menu_replace_config(rgui, config))
{
menu_clear_navigation(rgui);
ret = -1;
@ -1417,7 +1417,7 @@ static int menu_common_iterate(void *data, unsigned action)
}
else if (menu_type == RGUI_SETTINGS_OPEN_HISTORY)
{
load_menu_game_history(rgui->selection_ptr);
load_menu_game_history(rgui, rgui->selection_ptr);
menu_flush_stack_type(rgui, RGUI_SETTINGS);
ret = -1;
}
@ -1688,6 +1688,7 @@ static void menu_common_shader_manager_set_preset(void *data, unsigned type, con
if (path && shader)
{
rgui_handle_t *rgui = (rgui_handle_t*)driver.menu;
// Load stored CGP into RGUI menu on success.
// Used when a preset is directly loaded.
// No point in updating when the CGP was created from RGUI itself.
@ -2141,7 +2142,9 @@ static bool osk_callback_enter_audio_device_init(void *data)
static bool osk_callback_enter_filename(void *data)
{
if (!driver.osk)
rgui_handle_t *rgui = (rgui_handle_t*)driver.menu;
if (!driver.osk || !rgui)
return false;
if (g_extern.lifecycle_state & (1ULL << MODE_OSK_ENTRY_SUCCESS))
@ -3778,6 +3781,8 @@ static int menu_common_setting_set(void *data, unsigned setting, unsigned action
static void menu_common_setting_set_label(char *type_str, size_t type_str_size, unsigned *w, unsigned type)
{
rgui_handle_t *rgui = (rgui_handle_t*)driver.menu;
switch (type)
{
case RGUI_SETTINGS_VIDEO_ROTATION:

View File

@ -595,9 +595,11 @@ static void rgui_free(void *data)
static int rgui_input_postprocess(void *data, uint64_t old_state)
{
(void)data;
int ret = 0;
int ret;
rgui_handle_t *rgui;
rgui = (rgui_handle_t*)data;
ret = 0;
if ((rgui->trigger_state & (1ULL << RARCH_MENU_TOGGLE)) &&
g_extern.main_is_init &&

View File

@ -464,9 +464,10 @@ static void rmenu_free(void *data)
static int rmenu_input_postprocess(void *data, uint64_t old_state)
{
(void)data;
int ret;
rgui_handle_t *rgui = (rgui_handle_t*)data;
int ret = 0;
ret = 0;
if ((rgui->trigger_state & (1ULL << RARCH_MENU_TOGGLE)) &&
g_extern.main_is_init &&

View File

@ -33,8 +33,6 @@
#include "../../compat/posix_string.h"
rgui_handle_t *rgui;
void menu_update_system_info(void *data, bool *load_no_rom)
{
rgui_handle_t *rgui = (rgui_handle_t*)data;
@ -68,20 +66,22 @@ void menu_update_system_info(void *data, bool *load_no_rom)
#endif
}
void menu_rom_history_push(const char *path,
void menu_rom_history_push(void *data, const char *path,
const char *core_path,
const char *core_name)
{
rgui_handle_t *rgui = (rgui_handle_t*)data;
if (rgui->history)
rom_history_push(rgui->history, path, core_path, core_name);
}
void menu_rom_history_push_current(void)
void menu_rom_history_push_current(void *data)
{
// g_extern.fullpath can be relative here.
// Ensure we're pushing absolute path.
char tmp[PATH_MAX];
rgui_handle_t *rgui = (rgui_handle_t*)data;
strlcpy(tmp, g_extern.fullpath, sizeof(tmp));
@ -89,14 +89,16 @@ void menu_rom_history_push_current(void)
path_resolve_realpath(tmp, sizeof(tmp));
if (g_extern.system.no_game || *tmp)
menu_rom_history_push(*tmp ? tmp : NULL,
menu_rom_history_push(rgui, *tmp ? tmp : NULL,
g_settings.libretro,
g_extern.system.info.library_name);
}
void load_menu_game_prepare(void)
void load_menu_game_prepare(void *data)
{
if (*g_extern.fullpath || rgui->load_no_rom)
rgui_handle_t *rgui = (rgui_handle_t*)data;
if (*g_extern.fullpath || (rgui && rgui->load_no_rom))
{
if (*g_extern.fullpath)
{
@ -111,7 +113,7 @@ void load_menu_game_prepare(void)
#ifdef RARCH_CONSOLE
if (g_extern.system.no_game || *g_extern.fullpath)
#endif
menu_rom_history_push(*g_extern.fullpath ? g_extern.fullpath : NULL,
menu_rom_history_push(rgui, *g_extern.fullpath ? g_extern.fullpath : NULL,
g_settings.libretro,
rgui->info.library_name ? rgui->info.library_name : "");
}
@ -138,12 +140,18 @@ void load_menu_game_prepare(void)
MENU_TEXTURE_FULLSCREEN);
}
void load_menu_game_history(unsigned game_index)
void load_menu_game_history(void *data, unsigned game_index)
{
rgui_handle_t *rgui;
const char *path = NULL;
const char *core_path = NULL;
const char *core_name = NULL;
rgui = (rgui_handle_t*)data;
if (!rgui)
return;
rom_history_get_index(rgui->history,
game_index, &path, &core_path, &core_name);
@ -163,9 +171,11 @@ void load_menu_game_history(unsigned game_index)
#endif
}
static void menu_init_history(void)
static void menu_init_history(void *data)
{
if (rgui->history)
rgui_handle_t *rgui = (rgui_handle_t*)data;
if (rgui && rgui->history)
{
rom_history_free(rgui->history);
rgui->history = NULL;
@ -187,8 +197,13 @@ static void menu_init_history(void)
}
}
static void menu_update_libretro_info(void)
static void menu_update_libretro_info(void *data)
{
rgui_handle_t *rgui = (rgui_handle_t*)data;
if (!rgui)
return;
*rgui->libretro_dir = '\0';
#if defined(RARCH_CONSOLE)
@ -213,8 +228,13 @@ static void menu_update_libretro_info(void)
menu_update_system_info(rgui, NULL);
}
void load_menu_game_prepare_dummy(void)
void load_menu_game_prepare_dummy(void *data)
{
rgui_handle_t *rgui = (rgui_handle_t*)data;
if (!rgui)
return;
// Starts dummy core.
*g_extern.fullpath = '\0';
rgui->load_no_rom = false;
@ -224,13 +244,14 @@ void load_menu_game_prepare_dummy(void)
g_extern.system.shutdown = false;
}
bool load_menu_game(void)
bool load_menu_game(void *data)
{
struct rarch_main_wrap args = {0};
rgui_handle_t *rgui = (rgui_handle_t*)data;
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;
@ -238,33 +259,44 @@ bool load_menu_game(void)
args.rom_path = *g_extern.fullpath ? g_extern.fullpath : NULL;
args.libretro_path = *g_settings.libretro ? g_settings.libretro : NULL;
args.no_rom = rgui->load_no_rom;
rgui->load_no_rom = false;
if (rarch_main_init_wrap(&args) == 0)
if (rgui)
rgui->load_no_rom = false;
if (rarch_main_init_wrap(&args) != 0)
{
RARCH_LOG("rarch_main_init_wrap() succeeded.\n");
// Update menu state which depends on config.
menu_update_libretro_info();
menu_init_history();
if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->shader_manager_init)
driver.menu_ctx->backend->shader_manager_init(rgui);
return true;
}
else
{
char name[PATH_MAX];
char msg[PATH_MAX];
char name[PATH_MAX], msg[PATH_MAX];
fill_pathname_base(name, g_extern.fullpath, sizeof(name));
snprintf(msg, sizeof(msg), "Failed to load %s.\n", name);
msg_queue_push(g_extern.msg_queue, msg, 1, 90);
rgui->msg_force = true;
if (rgui)
rgui->msg_force = true;
RARCH_ERR("rarch_main_init_wrap() failed.\n");
return false;
}
RARCH_LOG("rarch_main_init_wrap() succeeded.\n");
if (rgui)
{
// Update menu state which depends on config.
menu_update_libretro_info(rgui);
menu_init_history(rgui);
if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->shader_manager_init)
driver.menu_ctx->backend->shader_manager_init(rgui);
}
return true;
}
void menu_init(void)
void *menu_init(void)
{
rgui_handle_t *rgui = (rgui_handle_t*)calloc(1, sizeof(rgui));
if (!rgui)
return NULL;
if (!menu_ctx_init_first(&driver.menu_ctx, (void**)&rgui))
{
RARCH_ERR("Could not initialize menu.\n");
@ -287,17 +319,24 @@ void menu_init(void)
rgui->frame_buf_show = true;
rgui->current_pad = 0;
menu_update_libretro_info();
menu_update_libretro_info(rgui);
if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->shader_manager_init)
driver.menu_ctx->backend->shader_manager_init(rgui);
menu_init_history();
menu_init_history(rgui);
rgui->last_time = rarch_get_time_usec();
return rgui;
}
void menu_free(void)
void menu_free(void *data)
{
rgui_handle_t *rgui = (rgui_handle_t*)data;
if (!rgui)
return;
if (driver.menu_ctx && driver.menu_ctx->free)
driver.menu_ctx->free(rgui);
@ -354,17 +393,23 @@ void menu_ticker_line(char *buf, size_t len, unsigned index, const char *str, bo
}
#ifdef HAVE_MENU
uint64_t menu_input(void)
uint64_t menu_input(void *data)
{
unsigned i;
uint64_t input_state = 0;
uint64_t input_state;
rgui_handle_t *rgui;
#ifdef RARCH_CONSOLE
static const struct retro_keybind *binds[] = { g_settings.input.menu_binds };
#else
static const struct retro_keybind *binds[] = { g_settings.input.binds[0] };
#endif
rgui = (rgui_handle_t*)data;
input_state = 0;
if (!rgui)
return 0;
input_push_analog_dpad((struct retro_keybind*)binds[0], g_settings.input.analog_dpad_mode[0]);
for (i = 0; i < MAX_PLAYERS; i++)
input_push_analog_dpad(g_settings.input.autoconf_binds[i], g_settings.input.analog_dpad_mode[i]);
@ -422,8 +467,13 @@ void menu_flush_stack_type(void *data, unsigned final_type)
}
}
void load_menu_game_new_core(void)
void load_menu_game_new_core(void *data)
{
rgui_handle_t *rgui = (rgui_handle_t*)data;
if (!rgui)
return;
#ifdef HAVE_DYNAMIC
menu_update_system_info(rgui, &rgui->load_no_rom);
g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME);
@ -433,17 +483,23 @@ void load_menu_game_new_core(void)
#endif
}
bool menu_iterate(void)
bool menu_iterate(void *data)
{
retro_time_t time, delta, target_msec, sleep_msec;
unsigned action;
static bool initial_held = true;
static bool first_held = false;
uint64_t input_state = 0;
uint64_t input_state;
int32_t input_entry_ret, ret;
rgui_handle_t *rgui;
input_state = 0;
input_entry_ret = 0;
ret = 0;
rgui = (rgui_handle_t*)data;
if (!rgui)
return false;
if (g_extern.lifecycle_state & (1ULL << MODE_MENU_PREINIT))
{
@ -465,7 +521,7 @@ bool menu_iterate(void)
return false;
}
input_state = menu_input();
input_state = menu_input(rgui);
if (rgui->do_held)
{
@ -566,9 +622,13 @@ bool menu_iterate(void)
// Likely to have lots of small bugs.
// Cleanly exit the main loop to ensure that all the tiny details get set properly.
// This should mitigate most of the smaller bugs.
bool menu_replace_config(const char *path)
bool menu_replace_config(void *data, const char *path)
{
if (strcmp(path, g_extern.config_path) == 0)
rgui_handle_t *rgui;
rgui = (rgui_handle_t*)data;
if (strcmp(path, g_extern.config_path) == 0 || !rgui)
return false;
if (g_extern.config_save_on_exit && *g_extern.config_path)
@ -851,6 +911,7 @@ void menu_build_scroll_indices(void *data, file_list_t *buf)
void menu_init_core_info(void *data)
{
rgui_handle_t *rgui = (rgui_handle_t*)data;
core_info_list_free(rgui->core_info);
rgui->core_info = NULL;
if (*rgui->libretro_dir)

View File

@ -182,30 +182,28 @@ typedef struct
bool bind_mode_keyboard;
} rgui_handle_t;
extern rgui_handle_t *rgui;
void menu_init(void);
bool menu_iterate(void);
void menu_free(void);
void *menu_init(void);
bool menu_iterate(void *data);
void menu_free(void *data);
void menu_ticker_line(char *buf, size_t len, unsigned tick, const char *str, bool selected);
void menu_init_core_info(void *data);
void load_menu_game_prepare(void);
void load_menu_game_prepare_dummy(void);
bool load_menu_game(void);
void load_menu_game_history(unsigned game_index);
extern void load_menu_game_new_core(void);
void menu_rom_history_push(const char *path, const char *core_path,
void load_menu_game_prepare(void *data);
void load_menu_game_prepare_dummy(void *data);
bool load_menu_game(void *data);
void load_menu_game_history(void *data, unsigned game_index);
extern void load_menu_game_new_core(void *data);
void menu_rom_history_push(void *data, const char *path, const char *core_path,
const char *core_name);
void menu_rom_history_push_current(void);
void menu_rom_history_push_current(void *data);
bool menu_replace_config(const char *path);
bool menu_replace_config(void *data, const char *path);
bool menu_save_new_config(void);
uint64_t menu_input(void);
uint64_t menu_input(void *data);
void menu_flush_stack_type(void *data, unsigned final_type);
void menu_update_system_info(void *data, bool *load_no_rom);

View File

@ -112,6 +112,7 @@ void preset_filename_callback(void *userdata, const char *str)
void menu_key_event(bool down, unsigned keycode, uint32_t character, uint16_t mod)
{
rgui_handle_t *rgui = (rgui_handle_t*)driver.menu;
(void)down;
(void)keycode;
(void)mod;

View File

@ -109,10 +109,10 @@ int apple_rarch_load_content(int argc, char* argv[])
if (rarch_main_init(argc, argv))
return 1;
menu_init();
menu_init(driver.menu);
if (!g_extern.libretro_dummy)
menu_rom_history_push_current();
menu_rom_history_push_current(driver.menu);
g_extern.lifecycle_state |= 1ULL << MODE_GAME;

View File

@ -45,13 +45,13 @@ int main(int argc, char *argv[])
if ((init_ret = rarch_main_init(argc, argv))) return init_ret;
#ifdef HAVE_MENU
menu_init();
menu_init(driver.menu);
g_extern.lifecycle_state |= 1ULL << MODE_GAME;
// If we started a ROM directly from command line,
// push it to ROM history.
if (!g_extern.libretro_dummy)
menu_rom_history_push_current();
menu_rom_history_push_current(driver.menu);
#endif
emscripten_set_main_loop(emscripten_mainloop, g_settings.video.vsync ? 0 : INT_MAX, 1);

View File

@ -498,7 +498,7 @@ const rarch_setting_t* setting_data_get_list(void)
CONFIG_PATH(g_settings.game_history_path, "game_history_path", "Content History Path", DEFAULT_ME_YO) WITH_FLAGS(SD_FLAG_ALLOW_EMPTY)
CONFIG_UINT(g_settings.game_history_size, "game_history_size", "Content History Size", game_history_size)
#ifdef HAVE_RGUI
#ifdef HAVE_MENU
CONFIG_PATH(g_settings.rgui_content_directory, "rgui_browser_directory", "Content Directory", DEFAULT_ME_YO) WITH_FLAGS(SD_FLAG_ALLOW_EMPTY | SD_FLAG_PATH_DIR)
CONFIG_PATH(g_settings.rgui_config_directory, "rgui_config_directory", "Config Directory", DEFAULT_ME_YO) WITH_FLAGS(SD_FLAG_ALLOW_EMPTY | SD_FLAG_PATH_DIR)
CONFIG_BOOL(g_settings.rgui_show_start_screen, "rgui_show_start_screen", "Show Start Screen", rgui_show_start_screen)