retroarch.c - some cleanups - retroarch_set_frame_limit - return

value - other cleanups
This commit is contained in:
twinaphex 2021-09-07 12:29:44 +02:00
parent 10782f9abc
commit 5b1872f6be
1 changed files with 61 additions and 73 deletions

View File

@ -8664,15 +8664,6 @@ static void retroarch_msg_queue_init(void)
#endif
}
#ifdef HAVE_THREADS
static void retroarch_autosave_deinit(struct rarch_state *p_rarch)
{
const bool rarch_use_sram = p_rarch->rarch_use_sram;
if (rarch_use_sram)
autosave_deinit();
}
#endif
/* COMMAND */
#ifdef HAVE_COMMAND
@ -10188,7 +10179,8 @@ static bool command_event_disk_control_append_image(
return false;
#ifdef HAVE_THREADS
retroarch_autosave_deinit(p_rarch);
if (p_rarch->rarch_use_sram)
autosave_deinit();
#endif
/* TODO/FIXME: Need to figure out what to do with subsystems case. */
@ -10338,9 +10330,9 @@ static void command_event_init_controllers(rarch_system_info_t *info,
}
#ifdef HAVE_CONFIGFILE
static void command_event_disable_overrides(struct rarch_state *p_rarch)
static void command_event_disable_overrides(void)
{
/* reload the original config */
/* Reload the original config */
config_unload_override();
runloop_state.overrides_active = false;
}
@ -10381,7 +10373,7 @@ static void command_event_deinit_core(
#ifdef HAVE_CONFIGFILE
if (runloop_state.overrides_active)
command_event_disable_overrides(p_rarch);
command_event_disable_overrides();
#endif
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
p_rarch->runtime_shader_preset[0] = '\0';
@ -10426,9 +10418,7 @@ static void command_event_init_cheats(
}
#endif
static void command_event_load_auto_state(
global_t *global,
struct rarch_state *p_rarch)
static void command_event_load_auto_state(global_t *global)
{
char savestate_name_auto[PATH_MAX_LENGTH];
bool ret = false;
@ -10461,8 +10451,7 @@ static void command_event_load_auto_state(
static void command_event_set_savestate_auto_index(
settings_t *settings,
const global_t *global,
struct rarch_state *p_rarch)
const global_t *global)
{
size_t i;
char state_dir[PATH_MAX_LENGTH];
@ -10653,7 +10642,7 @@ static bool event_init_content(
return false;
}
command_event_set_savestate_auto_index(settings, global, p_rarch);
command_event_set_savestate_auto_index(settings, global);
if (event_load_save_files(p_rarch->rarch_is_sram_load_disabled))
RARCH_LOG("[SRAM]: %s.\n",
@ -10670,7 +10659,7 @@ static bool event_init_content(
if (!cheevos_enable || !cheevos_hardcore_mode_enable)
#endif
if (global && settings->bools.savestate_auto_load)
command_event_load_auto_state(global, p_rarch);
command_event_load_auto_state(global);
#ifdef HAVE_BSV_MOVIE
bsv_movie_deinit(p_rarch);
@ -10802,14 +10791,13 @@ static void command_event_runtime_log_init(struct rarch_state *p_rarch)
sizeof(p_rarch->runtime_core_path));
}
static INLINE void retroarch_set_frame_limit(
struct rarch_state *p_rarch,
static INLINE float retroarch_set_frame_limit(
const struct retro_system_av_info *av_info,
float fastforward_ratio)
{
const struct retro_system_av_info* av_info = &p_rarch->video_driver_av_info;
p_rarch->frame_limit_minimum_time = (fastforward_ratio < 1.0f) ? 0.0f :
(retro_time_t)roundf(1000000.0f / (av_info->timing.fps * fastforward_ratio));
if (fastforward_ratio < 1.0f)
return 0.0f;
return (retro_time_t)roundf(1000000.0f / (av_info->timing.fps * fastforward_ratio));
}
static INLINE float retroarch_get_runloop_fastforward_ratio(
@ -10941,8 +10929,10 @@ static bool command_event_init_core(
if (!core_load(p_rarch, poll_type_behavior))
return false;
retroarch_set_frame_limit(p_rarch, fastforward_ratio);
p_rarch->frame_limit_last_time = cpu_features_get_time_usec();
p_rarch->frame_limit_minimum_time =
retroarch_set_frame_limit(&p_rarch->video_driver_av_info,
fastforward_ratio);
p_rarch->frame_limit_last_time = cpu_features_get_time_usec();
command_event_runtime_log_init(p_rarch);
return true;
@ -11021,7 +11011,6 @@ static bool command_event_save_config(
* Returns: true (1) on success, otherwise false (0).
**/
static bool command_event_save_core_config(
struct rarch_state *p_rarch,
const char *dir_menu_config,
const char *rarch_path_config)
{
@ -11129,7 +11118,6 @@ static bool command_event_save_core_config(
* autosave state.
**/
static void command_event_save_current_config(
struct rarch_state *p_rarch,
enum override_type type)
{
@ -11660,7 +11648,8 @@ static void retroarch_game_focus_free(struct rarch_state *p_rarch)
p_rarch->game_focus_state.core_requested = false;
}
static void retroarch_fastmotion_override_free(struct rarch_state *p_rarch,
static void retroarch_fastmotion_override_free(
struct rarch_state *p_rarch,
runloop_state_t *p_runloop)
{
settings_t *settings = p_rarch->configuration_settings;
@ -11682,7 +11671,8 @@ static void retroarch_fastmotion_override_free(struct rarch_state *p_rarch,
p_runloop->fastmotion_override.pending = false;
if (reset_frame_limit)
retroarch_set_frame_limit(p_rarch, fastforward_ratio);
p_rarch->frame_limit_minimum_time = retroarch_set_frame_limit(
&p_rarch->video_driver_av_info, fastforward_ratio);
}
static void retroarch_core_options_callback_free(runloop_state_t *p_runloop)
@ -12132,7 +12122,7 @@ bool command_event(enum event_command cmd, void *data)
#ifdef HAVE_CONFIGFILE
if (runloop_state.overrides_active)
{
command_event_disable_overrides(p_rarch);
command_event_disable_overrides();
if (!settings->bools.video_fullscreen)
{
@ -12277,7 +12267,8 @@ bool command_event(enum event_command cmd, void *data)
break;
case CMD_EVENT_AUTOSAVE_INIT:
#ifdef HAVE_THREADS
retroarch_autosave_deinit(p_rarch);
if (p_rarch->rarch_use_sram)
autosave_deinit();
{
#ifdef HAVE_NETWORKING
unsigned autosave_interval =
@ -12751,27 +12742,27 @@ bool command_event(enum event_command cmd, void *data)
config_save_file_salamander();
#endif
#ifdef HAVE_CONFIGFILE
command_event_save_current_config(p_rarch, OVERRIDE_NONE);
command_event_save_current_config(OVERRIDE_NONE);
#endif
break;
case CMD_EVENT_MENU_SAVE_CURRENT_CONFIG_OVERRIDE_CORE:
#ifdef HAVE_CONFIGFILE
command_event_save_current_config(p_rarch, OVERRIDE_CORE);
command_event_save_current_config(OVERRIDE_CORE);
#endif
break;
case CMD_EVENT_MENU_SAVE_CURRENT_CONFIG_OVERRIDE_CONTENT_DIR:
#ifdef HAVE_CONFIGFILE
command_event_save_current_config(p_rarch, OVERRIDE_CONTENT_DIR);
command_event_save_current_config(OVERRIDE_CONTENT_DIR);
#endif
break;
case CMD_EVENT_MENU_SAVE_CURRENT_CONFIG_OVERRIDE_GAME:
#ifdef HAVE_CONFIGFILE
command_event_save_current_config(p_rarch, OVERRIDE_GAME);
command_event_save_current_config(OVERRIDE_GAME);
#endif
break;
case CMD_EVENT_MENU_SAVE_CONFIG:
#ifdef HAVE_CONFIGFILE
if (!command_event_save_core_config(p_rarch,
if (!command_event_save_core_config(
settings->paths.directory_menu_config,
path_get(RARCH_PATH_CONFIG)))
return false;
@ -13396,8 +13387,9 @@ bool command_event(enum event_command cmd, void *data)
command_event_set_mixer_volume(settings, -0.5f);
break;
case CMD_EVENT_SET_FRAME_LIMIT:
retroarch_set_frame_limit(p_rarch,
retroarch_get_runloop_fastforward_ratio(
p_rarch->frame_limit_minimum_time =
retroarch_set_frame_limit(&p_rarch->video_driver_av_info,
retroarch_get_runloop_fastforward_ratio(
settings, &runloop_state));
break;
case CMD_EVENT_DISCORD_INIT:
@ -15054,7 +15046,7 @@ static bool rarch_environment_cb(unsigned cmd, void *data)
* - Unload any active input remaps */
#ifdef HAVE_CONFIGFILE
if (runloop_state.overrides_active)
command_event_disable_overrides(p_rarch);
command_event_disable_overrides();
#endif
if ( runloop_state.remaps_core_active
|| runloop_state.remaps_content_dir_active
@ -16939,7 +16931,7 @@ static bool write_file_with_random_name(char **temp_dll_path,
return okay;
}
static char *copy_core_to_temp_file(struct rarch_state *p_rarch,
static char *copy_core_to_temp_file(
const char *dir_libretro)
{
char retroarch_tmp_path[PATH_MAX_LENGTH];
@ -17047,7 +17039,7 @@ static bool secondary_core_create(struct rarch_state *p_rarch,
if (p_rarch->secondary_library_path)
free(p_rarch->secondary_library_path);
p_rarch->secondary_library_path = NULL;
p_rarch->secondary_library_path = copy_core_to_temp_file(p_rarch,
p_rarch->secondary_library_path = copy_core_to_temp_file(
settings->paths.directory_libretro);
if (!p_rarch->secondary_library_path)
@ -18483,26 +18475,14 @@ void bsv_movie_frame_rewind(void)
}
}
static bool bsv_movie_init_handle(
struct rarch_state *p_rarch,
const char *path,
enum rarch_movie_type type)
{
bsv_movie_t *state = bsv_movie_init_internal(path, type);
if (!state)
return false;
p_rarch->bsv_movie_state_handle = state;
return true;
}
static bool bsv_movie_init(struct rarch_state *p_rarch)
{
bsv_movie_t *state = NULL;
if (p_rarch->bsv_movie_state.movie_start_playback)
{
if (!bsv_movie_init_handle(p_rarch,
if (!(state = bsv_movie_init_internal(
p_rarch->bsv_movie_state.movie_start_path,
RARCH_MOVIE_PLAYBACK))
RARCH_MOVIE_PLAYBACK)))
{
RARCH_ERR("%s: \"%s\".\n",
msg_hash_to_str(MSG_FAILED_TO_LOAD_MOVIE_FILE),
@ -18510,6 +18490,7 @@ static bool bsv_movie_init(struct rarch_state *p_rarch)
return false;
}
p_rarch->bsv_movie_state_handle = state;
p_rarch->bsv_movie_state.movie_playback = true;
runloop_msg_queue_push(msg_hash_to_str(MSG_STARTING_MOVIE_PLAYBACK),
2, 180, false,
@ -18522,10 +18503,9 @@ static bool bsv_movie_init(struct rarch_state *p_rarch)
{
char msg[8192];
if (!bsv_movie_init_handle(
p_rarch,
if (!(state = bsv_movie_init_internal(
p_rarch->bsv_movie_state.movie_start_path,
RARCH_MOVIE_RECORD))
RARCH_MOVIE_RECORD)))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD),
@ -18536,6 +18516,7 @@ static bool bsv_movie_init(struct rarch_state *p_rarch)
return false;
}
p_rarch->bsv_movie_state_handle = state;
snprintf(msg, sizeof(msg),
"%s \"%s\".",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
@ -18563,6 +18544,7 @@ static bool runloop_check_movie_init(struct rarch_state *p_rarch,
settings_t *settings)
{
char msg[16384], path[8192];
bsv_movie_t *state = NULL;
int state_slot = settings->ints.state_slot;
msg[0] = path[0] = '\0';
@ -18581,11 +18563,9 @@ static bool runloop_check_movie_init(struct rarch_state *p_rarch,
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
path);
bsv_movie_init_handle(
p_rarch,
path, RARCH_MOVIE_RECORD);
state = bsv_movie_init_internal(path, RARCH_MOVIE_RECORD);
if (!p_rarch->bsv_movie_state_handle)
if (!state)
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD),
@ -18596,6 +18576,8 @@ static bool runloop_check_movie_init(struct rarch_state *p_rarch,
return false;
}
p_rarch->bsv_movie_state_handle = state;
runloop_msg_queue_push(msg, 2, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
@ -32428,7 +32410,7 @@ bool retroarch_main_init(int argc, char *argv[])
* - Unload any active input remaps */
#ifdef HAVE_CONFIGFILE
if (runloop_state.overrides_active)
command_event_disable_overrides(p_rarch);
command_event_disable_overrides();
#endif
if ( runloop_state.remaps_core_active
|| runloop_state.remaps_content_dir_active
@ -33203,7 +33185,8 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
input_mapper_reset(&p_rarch->input_driver_mapper);
#ifdef HAVE_THREADS
retroarch_autosave_deinit(p_rarch);
if (p_rarch->rarch_use_sram)
autosave_deinit();
#endif
command_event(CMD_EVENT_RECORD_DEINIT, NULL);
@ -33914,7 +33897,7 @@ bool retroarch_main_quit(void)
#ifdef HAVE_CONFIGFILE
if (runloop_state.overrides_active)
command_event_disable_overrides(p_rarch);
command_event_disable_overrides();
#endif
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
p_rarch->runtime_shader_preset[0] = '\0';
@ -34124,7 +34107,9 @@ static void runloop_apply_fastmotion_override(
fastforward_ratio_default;
if (fastforward_ratio_current != fastforward_ratio_last)
retroarch_set_frame_limit(p_rarch, fastforward_ratio_current);
p_rarch->frame_limit_minimum_time =
retroarch_set_frame_limit(&p_rarch->video_driver_av_info,
fastforward_ratio_current);
}
static enum runloop_state runloop_check_state(
@ -35711,11 +35696,14 @@ end:
}
if (runloop_state.fastmotion)
retroarch_set_frame_limit(p_rarch,
retroarch_get_runloop_fastforward_ratio(
p_rarch->frame_limit_minimum_time =
retroarch_set_frame_limit(&p_rarch->video_driver_av_info,
retroarch_get_runloop_fastforward_ratio(
settings, &runloop_state));
else
retroarch_set_frame_limit(p_rarch, 1.0f);
p_rarch->frame_limit_minimum_time =
retroarch_set_frame_limit(&p_rarch->video_driver_av_info,
1.0f);
}
/* if there's a fast forward limit, inject sleeps to keep from going too fast. */