Refactor libretro_dummy mechanics

This commit is contained in:
twinaphex 2015-06-20 23:42:30 +02:00
parent 9b267e9802
commit 6f1bc69fc7
13 changed files with 142 additions and 130 deletions

View File

@ -639,7 +639,7 @@ static bool event_init_content(void)
/* No content to be loaded for dummy core, /* No content to be loaded for dummy core,
* just successfully exit. */ * just successfully exit. */
if (global->libretro_dummy) if (global->core_type == CORE_TYPE_DUMMY)
return true; return true;
if (!global->libretro_no_content) if (!global->libretro_no_content)
@ -697,7 +697,7 @@ static bool event_init_core(void)
rarch_verify_api_version(); rarch_verify_api_version();
pretro_init(); pretro_init();
global->use_sram = !global->libretro_dummy && global->use_sram = (global->core_type == CORE_TYPE_PLAIN) &&
!global->libretro_no_content; !global->libretro_no_content;
if (!event_init_content()) if (!event_init_content())
@ -716,7 +716,8 @@ static bool event_save_auto_state(void)
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
if (!settings->savestate_auto_save || global->libretro_dummy || if (!settings->savestate_auto_save ||
(global->core_type == CORE_TYPE_DUMMY) ||
global->libretro_no_content) global->libretro_no_content)
return false; return false;

View File

@ -1667,12 +1667,12 @@ static void config_load_core_specific(void)
*global->core_specific_config_path = '\0'; *global->core_specific_config_path = '\0';
if (!*settings->libretro if (!*settings->libretro)
#ifdef HAVE_DYNAMIC
|| global->libretro_dummy
#endif
)
return; return;
#ifdef HAVE_DYNAMIC
if (global->core_type == CORE_TYPE_DUMMY)
return;
#endif
#ifdef HAVE_MENU #ifdef HAVE_MENU
if (*settings->menu_config_directory) if (*settings->menu_config_directory)

212
dynamic.c
View File

@ -280,103 +280,126 @@ libretro_find_controller_description(
/** /**
* load_symbols: * load_symbols:
* @dummy : Load dummy symbols if true * @type : Type of core to be loaded.
* If CORE_TYPE_DUMMY, will
* load dummy symbols.
* *
* Setup libretro callback symbols. * Setup libretro callback symbols.
**/ **/
static void load_symbols(bool is_dummy) static void load_symbols(enum rarch_core_type type)
{ {
if (is_dummy) settings_t *settings = config_get_ptr();
{
SYM_DUMMY(retro_init); switch (type)
SYM_DUMMY(retro_deinit);
SYM_DUMMY(retro_api_version);
SYM_DUMMY(retro_get_system_info);
SYM_DUMMY(retro_get_system_av_info);
SYM_DUMMY(retro_set_environment);
SYM_DUMMY(retro_set_video_refresh);
SYM_DUMMY(retro_set_audio_sample);
SYM_DUMMY(retro_set_audio_sample_batch);
SYM_DUMMY(retro_set_input_poll);
SYM_DUMMY(retro_set_input_state);
SYM_DUMMY(retro_set_controller_port_device);
SYM_DUMMY(retro_reset);
SYM_DUMMY(retro_run);
SYM_DUMMY(retro_serialize_size);
SYM_DUMMY(retro_serialize);
SYM_DUMMY(retro_unserialize);
SYM_DUMMY(retro_cheat_reset);
SYM_DUMMY(retro_cheat_set);
SYM_DUMMY(retro_load_game);
SYM_DUMMY(retro_load_game_special);
SYM_DUMMY(retro_unload_game);
SYM_DUMMY(retro_get_region);
SYM_DUMMY(retro_get_memory_data);
SYM_DUMMY(retro_get_memory_size);
}
else
{ {
case CORE_TYPE_PLAIN:
{
#ifdef HAVE_DYNAMIC #ifdef HAVE_DYNAMIC
settings_t *settings = config_get_ptr(); function_t sym = dylib_proc(NULL, "retro_init");
/* Need to use absolute path for this setting. It can be if (sym)
* saved to content history, and a relative path would {
* break in that scenario. */ /* Try to verify that -lretro was not linked in from other modules
path_resolve_realpath(settings->libretro, * since loading it dynamically and with -l will fail hard. */
sizeof(settings->libretro)); RARCH_ERR("Serious problem. RetroArch wants to load libretro dyamically, but it is already linked.\n");
RARCH_ERR("This could happen if other modules RetroArch depends on link against libretro directly.\n");
RARCH_ERR("Proceeding could cause a crash. Aborting ...\n");
rarch_fail(1, "init_libretro_sym()");
}
RARCH_LOG("Loading dynamic libretro from: \"%s\"\n", if (!*settings->libretro)
settings->libretro); {
lib_handle = dylib_load(settings->libretro); RARCH_ERR("RetroArch is built for dynamic libretro, but libretro_path is not set. Cannot continue.\n");
if (!lib_handle) rarch_fail(1, "init_libretro_sym()");
{ }
RARCH_ERR("Failed to open dynamic library: \"%s\"\n",
settings->libretro); /* Need to use absolute path for this setting. It can be
rarch_fail(1, "load_dynamic()"); * saved to content history, and a relative path would
} * break in that scenario. */
path_resolve_realpath(settings->libretro,
sizeof(settings->libretro));
RARCH_LOG("Loading dynamic libretro from: \"%s\"\n",
settings->libretro);
lib_handle = dylib_load(settings->libretro);
if (!lib_handle)
{
RARCH_ERR("Failed to open dynamic library: \"%s\"\n",
settings->libretro);
rarch_fail(1, "load_dynamic()");
}
#endif #endif
}
SYM(retro_init); SYM(retro_init);
SYM(retro_deinit); SYM(retro_deinit);
SYM(retro_api_version); SYM(retro_api_version);
SYM(retro_get_system_info); SYM(retro_get_system_info);
SYM(retro_get_system_av_info); SYM(retro_get_system_av_info);
SYM(retro_set_environment); SYM(retro_set_environment);
SYM(retro_set_video_refresh); SYM(retro_set_video_refresh);
SYM(retro_set_audio_sample); SYM(retro_set_audio_sample);
SYM(retro_set_audio_sample_batch); SYM(retro_set_audio_sample_batch);
SYM(retro_set_input_poll); SYM(retro_set_input_poll);
SYM(retro_set_input_state); SYM(retro_set_input_state);
SYM(retro_set_controller_port_device); SYM(retro_set_controller_port_device);
SYM(retro_reset); SYM(retro_reset);
SYM(retro_run); SYM(retro_run);
SYM(retro_serialize_size); SYM(retro_serialize_size);
SYM(retro_serialize); SYM(retro_serialize);
SYM(retro_unserialize); SYM(retro_unserialize);
SYM(retro_cheat_reset); SYM(retro_cheat_reset);
SYM(retro_cheat_set); SYM(retro_cheat_set);
SYM(retro_load_game); SYM(retro_load_game);
SYM(retro_load_game_special); SYM(retro_load_game_special);
SYM(retro_unload_game); SYM(retro_unload_game);
SYM(retro_get_region); SYM(retro_get_region);
SYM(retro_get_memory_data); SYM(retro_get_memory_data);
SYM(retro_get_memory_size); SYM(retro_get_memory_size);
break;
case CORE_TYPE_DUMMY:
SYM_DUMMY(retro_init);
SYM_DUMMY(retro_deinit);
SYM_DUMMY(retro_api_version);
SYM_DUMMY(retro_get_system_info);
SYM_DUMMY(retro_get_system_av_info);
SYM_DUMMY(retro_set_environment);
SYM_DUMMY(retro_set_video_refresh);
SYM_DUMMY(retro_set_audio_sample);
SYM_DUMMY(retro_set_audio_sample_batch);
SYM_DUMMY(retro_set_input_poll);
SYM_DUMMY(retro_set_input_state);
SYM_DUMMY(retro_set_controller_port_device);
SYM_DUMMY(retro_reset);
SYM_DUMMY(retro_run);
SYM_DUMMY(retro_serialize_size);
SYM_DUMMY(retro_serialize);
SYM_DUMMY(retro_unserialize);
SYM_DUMMY(retro_cheat_reset);
SYM_DUMMY(retro_cheat_set);
SYM_DUMMY(retro_load_game);
SYM_DUMMY(retro_load_game_special);
SYM_DUMMY(retro_unload_game);
SYM_DUMMY(retro_get_region);
SYM_DUMMY(retro_get_memory_data);
SYM_DUMMY(retro_get_memory_size);
break;
} }
} }
@ -420,42 +443,21 @@ void libretro_get_current_core_pathname(char *name, size_t size)
/** /**
* init_libretro_sym: * init_libretro_sym:
* @dummy : Load dummy symbols if true * @type : Type of core to be loaded.
* If CORE_TYPE_DUMMY, will
* load dummy symbols.
* *
* Initializes libretro symbols and * Initializes libretro symbols and
* setups environment callback functions. * setups environment callback functions.
**/ **/
void init_libretro_sym(bool dummy) void init_libretro_sym(enum rarch_core_type type)
{ {
/* Guarantee that we can do "dirty" casting. /* Guarantee that we can do "dirty" casting.
* Every OS that this program supports should pass this. */ * Every OS that this program supports should pass this. */
rarch_assert(sizeof(void*) == sizeof(void (*)(void))); rarch_assert(sizeof(void*) == sizeof(void (*)(void)));
if (!dummy)
{
#ifdef HAVE_DYNAMIC
settings_t *settings = config_get_ptr();
function_t sym = dylib_proc(NULL, "retro_init");
if (sym) load_symbols(type);
{
/* Try to verify that -lretro was not linked in from other modules
* since loading it dynamically and with -l will fail hard. */
RARCH_ERR("Serious problem. RetroArch wants to load libretro dyamically, but it is already linked.\n");
RARCH_ERR("This could happen if other modules RetroArch depends on link against libretro directly.\n");
RARCH_ERR("Proceeding could cause a crash. Aborting ...\n");
rarch_fail(1, "init_libretro_sym()");
}
if (!*settings->libretro)
{
RARCH_ERR("RetroArch is built for dynamic libretro, but libretro_path is not set. Cannot continue.\n");
rarch_fail(1, "init_libretro_sym()");
}
#endif
}
load_symbols(dummy);
//move this to init_core, will need to be tested //move this to init_core, will need to be tested
//pretro_set_environment(rarch_environment_cb); //pretro_set_environment(rarch_environment_cb);

View File

@ -26,6 +26,12 @@
#include <dynamic/dylib.h> #include <dynamic/dylib.h>
enum rarch_core_type
{
CORE_TYPE_PLAIN = 0,
CORE_TYPE_DUMMY,
};
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -168,12 +174,14 @@ extern size_t (*pretro_get_memory_size)(unsigned);
/** /**
* init_libretro_sym: * init_libretro_sym:
* @dummy : Load dummy symbols if true * @type : Type of core to be loaded.
* If CORE_TYPE_DUMMY, will
* load dummy symbols.
* *
* Initializes libretro symbols and * Initializes libretro symbols and
* setups environment callback functions. * setups environment callback functions.
**/ **/
void init_libretro_sym(bool dummy); void init_libretro_sym(enum rarch_core_type type);
/** /**
* uninit_libretro_sym: * uninit_libretro_sym:

View File

@ -172,7 +172,7 @@ static void history_playlist_push(content_playlist_t *playlist,
char tmp[PATH_MAX_LENGTH] = {0}; char tmp[PATH_MAX_LENGTH] = {0};
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
if (!playlist || global->libretro_dummy || !info) if (!playlist || (global->core_type == CORE_TYPE_DUMMY) || !info)
return; return;
/* Path can be relative here. /* Path can be relative here.

View File

@ -100,7 +100,7 @@ static INLINE void gl_menu_frame_background(
menu_display_set_viewport(); menu_display_set_viewport();
if ((settings->menu.pause_libretro if ((settings->menu.pause_libretro
|| !global->main_is_init || global->libretro_dummy) || !global->main_is_init || (global->core_type == CORE_TYPE_DUMMY))
&& !force_transparency && !force_transparency
&& texture) && texture)
coords.color = color; coords.color = color;

View File

@ -79,7 +79,7 @@ void menu_display_fb(void)
if (!settings->menu.pause_libretro) if (!settings->menu.pause_libretro)
{ {
if (global->main_is_init && !global->libretro_dummy) if (global->main_is_init && (global->core_type != CORE_TYPE_DUMMY))
{ {
bool block_libretro_input = driver->block_libretro_input; bool block_libretro_input = driver->block_libretro_input;
driver->block_libretro_input = true; driver->block_libretro_input = true;

View File

@ -1434,7 +1434,7 @@ static int menu_displaylist_parse_options(menu_displaylist_info_t *info)
menu_hash_to_str(MENU_LABEL_VALUE_CORE_CHEAT_OPTIONS), menu_hash_to_str(MENU_LABEL_VALUE_CORE_CHEAT_OPTIONS),
menu_hash_to_str(MENU_LABEL_CORE_CHEAT_OPTIONS), menu_hash_to_str(MENU_LABEL_CORE_CHEAT_OPTIONS),
MENU_SETTING_ACTION, 0, 0); MENU_SETTING_ACTION, 0, 0);
if (!global->libretro_dummy && global->system.disk_control.get_num_images) if ((global->core_type != CORE_TYPE_DUMMY) && global->system.disk_control.get_num_images)
menu_list_push(info->list, menu_list_push(info->list,
menu_hash_to_str(MENU_LABEL_VALUE_DISK_OPTIONS), menu_hash_to_str(MENU_LABEL_VALUE_DISK_OPTIONS),
menu_hash_to_str(MENU_LABEL_DISK_OPTIONS), menu_hash_to_str(MENU_LABEL_DISK_OPTIONS),
@ -1461,7 +1461,7 @@ static int menu_displaylist_parse_horizontal_content_actions(menu_displaylist_in
if (!menu) if (!menu)
return -1; return -1;
if (global->main_is_init && !global->libretro_dummy && if (global->main_is_init && (global->core_type != CORE_TYPE_DUMMY) &&
!strcmp(menu->deferred_path, global->fullpath)) !strcmp(menu->deferred_path, global->fullpath))
{ {
menu_list_push(info->list, menu_list_push(info->list,

View File

@ -3642,7 +3642,7 @@ static bool setting_append_list_main_menu_options(
parent_group); parent_group);
settings_data_list_current_add_flags(list, list_info, SD_FLAG_ADVANCED); settings_data_list_current_add_flags(list, list_info, SD_FLAG_ADVANCED);
} }
if (global->main_is_init && !global->libretro_dummy) if (global->main_is_init && (global->core_type != CORE_TYPE_DUMMY))
{ {
CONFIG_ACTION( CONFIG_ACTION(
menu_hash_to_str(MENU_LABEL_SAVE_STATE), menu_hash_to_str(MENU_LABEL_SAVE_STATE),

View File

@ -299,7 +299,7 @@ bool recording_init(void)
if (!global->record.enable) if (!global->record.enable)
return false; return false;
if (global->libretro_dummy) if (global->core_type == CORE_TYPE_DUMMY)
{ {
RARCH_WARN(RETRO_LOG_INIT_RECORDING_SKIPPED); RARCH_WARN(RETRO_LOG_INIT_RECORDING_SKIPPED);
return false; return false;

View File

@ -429,7 +429,7 @@ static void parse_input(int argc, char *argv[])
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
global->libretro_no_content = false; global->libretro_no_content = false;
global->libretro_dummy = false; global->core_type = CORE_TYPE_PLAIN;
global->has_set_save_path = false; global->has_set_save_path = false;
global->has_set_state_path = false; global->has_set_state_path = false;
global->has_set_libretro = false; global->has_set_libretro = false;
@ -458,7 +458,7 @@ static void parse_input(int argc, char *argv[])
if (argc < 2) if (argc < 2)
{ {
global->libretro_dummy = true; global->core_type = CORE_TYPE_DUMMY;
return; return;
} }
@ -713,7 +713,7 @@ static void parse_input(int argc, char *argv[])
switch (val) switch (val)
{ {
case RA_OPT_MENU: case RA_OPT_MENU:
global->libretro_dummy = true; global->core_type = CORE_TYPE_DUMMY;
break; break;
#ifdef HAVE_NETPLAY #ifdef HAVE_NETPLAY
@ -823,7 +823,7 @@ static void parse_input(int argc, char *argv[])
} }
} }
if (global->libretro_dummy) if (global->core_type == CORE_TYPE_DUMMY)
{ {
if (optind < argc) if (optind < argc)
{ {
@ -1184,7 +1184,7 @@ int rarch_main_init(int argc, char *argv[])
validate_cpu_features(); validate_cpu_features();
config_load(); config_load();
init_libretro_sym(global->libretro_dummy); init_libretro_sym(global->core_type);
init_system_info(); init_system_info();
init_drivers_pre(); init_drivers_pre();

View File

@ -425,7 +425,7 @@ static void do_state_check_menu_toggle(void)
if (menu_driver_alive()) if (menu_driver_alive())
{ {
if (global->main_is_init && !global->libretro_dummy) if (global->main_is_init && (global->core_type != CORE_TYPE_DUMMY))
rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED);
return; return;
} }
@ -462,7 +462,7 @@ static int do_pre_state_checks(event_cmd_state_t *cmd)
event_command(EVENT_CMD_GRAB_MOUSE_TOGGLE); event_command(EVENT_CMD_GRAB_MOUSE_TOGGLE);
#ifdef HAVE_MENU #ifdef HAVE_MENU
if (cmd->menu_pressed || (global->libretro_dummy)) if (cmd->menu_pressed || (global->core_type == CORE_TYPE_DUMMY))
do_state_check_menu_toggle(); do_state_check_menu_toggle();
#endif #endif

View File

@ -26,6 +26,7 @@
#include "autosave.h" #include "autosave.h"
#include "movie.h" #include "movie.h"
#include "cheats.h" #include "cheats.h"
#include "dynamic.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -319,7 +320,7 @@ typedef struct global
jmp_buf error_sjlj_context; jmp_buf error_sjlj_context;
bool libretro_no_content; bool libretro_no_content;
bool libretro_dummy; enum rarch_core_type core_type;
/* Config file associated with per-core configs. */ /* Config file associated with per-core configs. */
char core_specific_config_path[PATH_MAX_LENGTH]; char core_specific_config_path[PATH_MAX_LENGTH];