Add support for fast forward frame limiting.
This commit is contained in:
parent
e8271031b6
commit
9e4cee5b30
|
@ -381,6 +381,9 @@ static const bool savestate_auto_load = true;
|
||||||
// Slowmotion ratio.
|
// Slowmotion ratio.
|
||||||
static const float slowmotion_ratio = 3.0;
|
static const float slowmotion_ratio = 3.0;
|
||||||
|
|
||||||
|
// Maximum fast forward ratio (Negative => no limit).
|
||||||
|
static const float fastforward_ratio = -1.0;
|
||||||
|
|
||||||
// Enable stdin/network command interface
|
// Enable stdin/network command interface
|
||||||
static const bool network_cmd_enable = false;
|
static const bool network_cmd_enable = false;
|
||||||
static const uint16_t network_cmd_port = 55355;
|
static const uint16_t network_cmd_port = 55355;
|
||||||
|
|
|
@ -264,6 +264,7 @@ struct settings
|
||||||
unsigned rewind_granularity;
|
unsigned rewind_granularity;
|
||||||
|
|
||||||
float slowmotion_ratio;
|
float slowmotion_ratio;
|
||||||
|
float fastforward_ratio;
|
||||||
|
|
||||||
bool pause_nonactive;
|
bool pause_nonactive;
|
||||||
unsigned autosave_interval;
|
unsigned autosave_interval;
|
||||||
|
@ -367,6 +368,12 @@ struct global
|
||||||
|
|
||||||
unsigned state_slot;
|
unsigned state_slot;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
rarch_time_t minimum_frame_time;
|
||||||
|
rarch_time_t last_frame_time;
|
||||||
|
} frame_limit;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
struct retro_system_info info;
|
struct retro_system_info info;
|
||||||
|
|
20
retroarch.c
20
retroarch.c
|
@ -2819,6 +2819,8 @@ void rarch_init_system_info(void)
|
||||||
static void init_system_av_info(void)
|
static void init_system_av_info(void)
|
||||||
{
|
{
|
||||||
pretro_get_system_av_info(&g_extern.system.av_info);
|
pretro_get_system_av_info(&g_extern.system.av_info);
|
||||||
|
g_extern.frame_limit.last_frame_time = rarch_get_time_usec();
|
||||||
|
g_extern.frame_limit.minimum_frame_time = (rarch_time_t)roundf(1000000.0f / (g_extern.system.av_info.timing.fps * g_settings.fastforward_ratio));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void verify_api_version(void)
|
static void verify_api_version(void)
|
||||||
|
@ -3021,6 +3023,23 @@ static inline void update_frame_time(void)
|
||||||
g_extern.system.frame_time.callback(delta);
|
g_extern.system.frame_time.callback(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void limit_frame_time(void)
|
||||||
|
{
|
||||||
|
if (g_settings.fastforward_ratio < 0.0f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rarch_time_t current = rarch_get_time_usec();
|
||||||
|
rarch_time_t target = g_extern.frame_limit.last_frame_time + g_extern.frame_limit.minimum_frame_time;
|
||||||
|
rarch_time_t to_sleep_ms = (target - current) / 1000;
|
||||||
|
if (to_sleep_ms > 0)
|
||||||
|
{
|
||||||
|
rarch_sleep(to_sleep_ms);
|
||||||
|
g_extern.frame_limit.last_frame_time += g_extern.frame_limit.minimum_frame_time; // Combat jitter a bit.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_extern.frame_limit.last_frame_time = rarch_get_time_usec();
|
||||||
|
}
|
||||||
|
|
||||||
bool rarch_main_iterate(void)
|
bool rarch_main_iterate(void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DYLIB
|
#ifdef HAVE_DYLIB
|
||||||
|
@ -3065,6 +3084,7 @@ bool rarch_main_iterate(void)
|
||||||
|
|
||||||
update_frame_time();
|
update_frame_time();
|
||||||
pretro_run();
|
pretro_run();
|
||||||
|
limit_frame_time();
|
||||||
|
|
||||||
#ifdef HAVE_BSV_MOVIE
|
#ifdef HAVE_BSV_MOVIE
|
||||||
if (g_extern.bsv.movie)
|
if (g_extern.bsv.movie)
|
||||||
|
|
|
@ -461,6 +461,12 @@
|
||||||
# Slowmotion ratio. When slowmotion, game will slow down by factor.
|
# Slowmotion ratio. When slowmotion, game will slow down by factor.
|
||||||
# slowmotion_ratio = 3.0
|
# slowmotion_ratio = 3.0
|
||||||
|
|
||||||
|
# The maximum rate at which games will be run when using fast forward. (E.g. 5.0 for 60 fps game => 300 fps cap).
|
||||||
|
# RetroArch will go to sleep to ensure that the maximum rate will not be exceeded.
|
||||||
|
# Do not rely on this cap to be perfectly accurate.
|
||||||
|
# A negative ratio equals no FPS cap.
|
||||||
|
# fastforward_ratio = -1.0
|
||||||
|
|
||||||
# Enable stdin/network command interface.
|
# Enable stdin/network command interface.
|
||||||
# network_cmd_enable = false
|
# network_cmd_enable = false
|
||||||
# network_cmd_port = 55355
|
# network_cmd_port = 55355
|
||||||
|
|
|
@ -209,6 +209,7 @@ void config_set_defaults(void)
|
||||||
g_settings.rewind_buffer_size = rewind_buffer_size;
|
g_settings.rewind_buffer_size = rewind_buffer_size;
|
||||||
g_settings.rewind_granularity = rewind_granularity;
|
g_settings.rewind_granularity = rewind_granularity;
|
||||||
g_settings.slowmotion_ratio = slowmotion_ratio;
|
g_settings.slowmotion_ratio = slowmotion_ratio;
|
||||||
|
g_settings.fastforward_ratio = fastforward_ratio;
|
||||||
g_settings.pause_nonactive = pause_nonactive;
|
g_settings.pause_nonactive = pause_nonactive;
|
||||||
g_settings.autosave_interval = autosave_interval;
|
g_settings.autosave_interval = autosave_interval;
|
||||||
|
|
||||||
|
@ -678,6 +679,8 @@ bool config_load_file(const char *path)
|
||||||
if (g_settings.slowmotion_ratio < 1.0f)
|
if (g_settings.slowmotion_ratio < 1.0f)
|
||||||
g_settings.slowmotion_ratio = 1.0f;
|
g_settings.slowmotion_ratio = 1.0f;
|
||||||
|
|
||||||
|
CONFIG_GET_FLOAT(fastforward_ratio, "fastforward_ratio");
|
||||||
|
|
||||||
CONFIG_GET_BOOL(pause_nonactive, "pause_nonactive");
|
CONFIG_GET_BOOL(pause_nonactive, "pause_nonactive");
|
||||||
CONFIG_GET_INT(autosave_interval, "autosave_interval");
|
CONFIG_GET_INT(autosave_interval, "autosave_interval");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue