Skip to content

Commit

Permalink
Refactor libretro_dummy mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Jun 20, 2015
1 parent 9b267e9 commit 6f1bc69
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 125 deletions.
7 changes: 4 additions & 3 deletions command_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ static bool event_init_content(void)

/* No content to be loaded for dummy core,
* just successfully exit. */
if (global->libretro_dummy)
if (global->core_type == CORE_TYPE_DUMMY)
return true;

if (!global->libretro_no_content)
Expand Down Expand Up @@ -697,7 +697,7 @@ static bool event_init_core(void)
rarch_verify_api_version();
pretro_init();

global->use_sram = !global->libretro_dummy &&
global->use_sram = (global->core_type == CORE_TYPE_PLAIN) &&
!global->libretro_no_content;

if (!event_init_content())
Expand All @@ -716,7 +716,8 @@ static bool event_save_auto_state(void)
settings_t *settings = config_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)
return false;

Expand Down
8 changes: 4 additions & 4 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1667,12 +1667,12 @@ static void config_load_core_specific(void)

*global->core_specific_config_path = '\0';

if (!*settings->libretro
if (!*settings->libretro)
return;
#ifdef HAVE_DYNAMIC
|| global->libretro_dummy
#endif
)
if (global->core_type == CORE_TYPE_DUMMY)
return;
#endif

#ifdef HAVE_MENU
if (*settings->menu_config_directory)
Expand Down
204 changes: 103 additions & 101 deletions dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,103 +280,126 @@ libretro_find_controller_description(

/**
* 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.
**/
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();

switch (type)
{
SYM_DUMMY(retro_init);
SYM_DUMMY(retro_deinit);
case CORE_TYPE_PLAIN:
{
#ifdef HAVE_DYNAMIC
function_t sym = dylib_proc(NULL, "retro_init");

SYM_DUMMY(retro_api_version);
SYM_DUMMY(retro_get_system_info);
SYM_DUMMY(retro_get_system_av_info);
if (sym)
{
/* 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()");
}

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);
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()");
}

SYM_DUMMY(retro_set_controller_port_device);
/* Need to use absolute path for this setting. It can be
* saved to content history, and a relative path would
* break in that scenario. */
path_resolve_realpath(settings->libretro,
sizeof(settings->libretro));

SYM_DUMMY(retro_reset);
SYM_DUMMY(retro_run);
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
}

SYM_DUMMY(retro_serialize_size);
SYM_DUMMY(retro_serialize);
SYM_DUMMY(retro_unserialize);
SYM(retro_init);
SYM(retro_deinit);

SYM_DUMMY(retro_cheat_reset);
SYM_DUMMY(retro_cheat_set);
SYM(retro_api_version);
SYM(retro_get_system_info);
SYM(retro_get_system_av_info);

SYM_DUMMY(retro_load_game);
SYM_DUMMY(retro_load_game_special);
SYM(retro_set_environment);
SYM(retro_set_video_refresh);
SYM(retro_set_audio_sample);
SYM(retro_set_audio_sample_batch);
SYM(retro_set_input_poll);
SYM(retro_set_input_state);

SYM_DUMMY(retro_unload_game);
SYM_DUMMY(retro_get_region);
SYM_DUMMY(retro_get_memory_data);
SYM_DUMMY(retro_get_memory_size);
}
else
{
#ifdef HAVE_DYNAMIC
settings_t *settings = config_get_ptr();

/* Need to use absolute path for this setting. It can be
* 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
SYM(retro_set_controller_port_device);

SYM(retro_reset);
SYM(retro_run);

SYM(retro_serialize_size);
SYM(retro_serialize);
SYM(retro_unserialize);

SYM(retro_init);
SYM(retro_deinit);
SYM(retro_cheat_reset);
SYM(retro_cheat_set);

SYM(retro_api_version);
SYM(retro_get_system_info);
SYM(retro_get_system_av_info);
SYM(retro_load_game);
SYM(retro_load_game_special);

SYM(retro_unload_game);
SYM(retro_get_region);
SYM(retro_get_memory_data);
SYM(retro_get_memory_size);
break;
case CORE_TYPE_DUMMY:
SYM_DUMMY(retro_init);
SYM_DUMMY(retro_deinit);

SYM(retro_set_environment);
SYM(retro_set_video_refresh);
SYM(retro_set_audio_sample);
SYM(retro_set_audio_sample_batch);
SYM(retro_set_input_poll);
SYM(retro_set_input_state);
SYM_DUMMY(retro_api_version);
SYM_DUMMY(retro_get_system_info);
SYM_DUMMY(retro_get_system_av_info);

SYM(retro_set_controller_port_device);
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(retro_reset);
SYM(retro_run);
SYM_DUMMY(retro_set_controller_port_device);

SYM(retro_serialize_size);
SYM(retro_serialize);
SYM(retro_unserialize);
SYM_DUMMY(retro_reset);
SYM_DUMMY(retro_run);

SYM(retro_cheat_reset);
SYM(retro_cheat_set);
SYM_DUMMY(retro_serialize_size);
SYM_DUMMY(retro_serialize);
SYM_DUMMY(retro_unserialize);

SYM(retro_load_game);
SYM(retro_load_game_special);
SYM_DUMMY(retro_cheat_reset);
SYM_DUMMY(retro_cheat_set);

SYM(retro_unload_game);
SYM(retro_get_region);
SYM(retro_get_memory_data);
SYM(retro_get_memory_size);
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;
}
}

Expand Down Expand Up @@ -420,42 +443,21 @@ void libretro_get_current_core_pathname(char *name, size_t size)

/**
* 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
* 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.
* Every OS that this program supports should pass this. */
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)
{
/* 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);
load_symbols(type);

//move this to init_core, will need to be tested
//pretro_set_environment(rarch_environment_cb);
Expand Down
12 changes: 10 additions & 2 deletions dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@

#include <dynamic/dylib.h>

enum rarch_core_type
{
CORE_TYPE_PLAIN = 0,
CORE_TYPE_DUMMY,
};

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -168,12 +174,14 @@ extern size_t (*pretro_get_memory_size)(unsigned);

/**
* 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
* setups environment callback functions.
**/
void init_libretro_sym(bool dummy);
void init_libretro_sym(enum rarch_core_type type);

/**
* uninit_libretro_sym:
Expand Down
2 changes: 1 addition & 1 deletion frontend/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static void history_playlist_push(content_playlist_t *playlist,
char tmp[PATH_MAX_LENGTH] = {0};
global_t *global = global_get_ptr();

if (!playlist || global->libretro_dummy || !info)
if (!playlist || (global->core_type == CORE_TYPE_DUMMY) || !info)
return;

/* Path can be relative here.
Expand Down
2 changes: 1 addition & 1 deletion menu/drivers/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static INLINE void gl_menu_frame_background(
menu_display_set_viewport();

if ((settings->menu.pause_libretro
|| !global->main_is_init || global->libretro_dummy)
|| !global->main_is_init || (global->core_type == CORE_TYPE_DUMMY))
&& !force_transparency
&& texture)
coords.color = color;
Expand Down
2 changes: 1 addition & 1 deletion menu/menu_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void menu_display_fb(void)

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;
driver->block_libretro_input = true;
Expand Down
4 changes: 2 additions & 2 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_CORE_CHEAT_OPTIONS),
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_hash_to_str(MENU_LABEL_VALUE_DISK_OPTIONS),
menu_hash_to_str(MENU_LABEL_DISK_OPTIONS),
Expand All @@ -1461,7 +1461,7 @@ static int menu_displaylist_parse_horizontal_content_actions(menu_displaylist_in
if (!menu)
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))
{
menu_list_push(info->list,
Expand Down
2 changes: 1 addition & 1 deletion menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -3642,7 +3642,7 @@ static bool setting_append_list_main_menu_options(
parent_group);
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(
menu_hash_to_str(MENU_LABEL_SAVE_STATE),
Expand Down
2 changes: 1 addition & 1 deletion record/record_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ bool recording_init(void)
if (!global->record.enable)
return false;

if (global->libretro_dummy)
if (global->core_type == CORE_TYPE_DUMMY)
{
RARCH_WARN(RETRO_LOG_INIT_RECORDING_SKIPPED);
return false;
Expand Down
Loading

0 comments on commit 6f1bc69

Please sign in to comment.