diff --git a/command_event.c b/command_event.c index 2fd26f7070..c317e07ddc 100644 --- a/command_event.c +++ b/command_event.c @@ -1705,6 +1705,9 @@ bool event_command(enum event_command cmd) case EVENT_CMD_VOLUME_DOWN: event_set_volume(-0.5f); break; + case EVENT_CMD_SET_FRAME_LIMIT: + rarch_main_set_frame_limit_last_time(); + break; case EVENT_CMD_NONE: default: return false; diff --git a/command_event.h b/command_event.h index 535746490b..54fc4c3c40 100644 --- a/command_event.h +++ b/command_event.h @@ -196,6 +196,7 @@ enum event_command EVENT_CMD_REMAPPING_DEINIT, EVENT_CMD_VOLUME_UP, EVENT_CMD_VOLUME_DOWN, + EVENT_CMD_SET_FRAME_LIMIT, EVENT_CMD_DATA_RUNLOOP_FREE }; diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 406473bd93..63c4264439 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -2956,6 +2956,7 @@ static bool setting_append_list_frame_throttling_options( parent_group, general_write_handler, general_read_handler); + menu_settings_list_current_add_cmd(list, list_info, EVENT_CMD_SET_FRAME_LIMIT); menu_settings_list_current_add_range(list, list_info, 1, 10, 0.1, true, true); CONFIG_FLOAT( diff --git a/retroarch.c b/retroarch.c index fc896569ed..248cda445e 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1157,7 +1157,7 @@ void rarch_init_system_av_info(void) video_viewport_get_system_av_info(); pretro_get_system_av_info(av_info); - rarch_main_set_frame_limit_last_time(); + event_command(EVENT_CMD_SET_FRAME_LIMIT); } /** diff --git a/runloop.c b/runloop.c index 8527712475..80279b4489 100644 --- a/runloop.c +++ b/runloop.c @@ -52,6 +52,7 @@ static bool main_is_slowmotion; static unsigned main_max_frames; static retro_time_t frame_limit_last_time; +static retro_time_t frame_limit_minimum_time; /** * check_pause: @@ -654,18 +655,11 @@ static void rarch_update_frame_time(driver_t *driver, float slowmotion_ratio, static int rarch_limit_frame_time(settings_t *settings) { - double effective_fps, mft_f; - retro_time_t current, target, to_sleep_ms, frame_limit_minimum_time; - struct retro_system_av_info *av_info; - float fastforward_ratio = settings->fastforward_ratio; + retro_time_t current, target, to_sleep_ms; if (!settings->fastforward_ratio_throttle_enable) return 0; - av_info = video_viewport_get_system_av_info(); - effective_fps = av_info->timing.fps * fastforward_ratio; - mft_f = 1000000.0f / effective_fps; - frame_limit_minimum_time = (retro_time_t) roundf(mft_f); current = rarch_get_time_usec(); target = frame_limit_last_time + frame_limit_minimum_time; to_sleep_ms = (target - current) / 1000; @@ -836,7 +830,12 @@ void rarch_main_state_free(void) void rarch_main_set_frame_limit_last_time(void) { - frame_limit_last_time = rarch_get_time_usec(); + settings_t *settings = config_get_ptr(); + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); + float fastforward_ratio = settings->fastforward_ratio; + + frame_limit_last_time = rarch_get_time_usec(); + frame_limit_minimum_time = (retro_time_t)roundf(1000000.0f / (av_info->timing.fps * fastforward_ratio)); } void rarch_main_global_free(void)