Small cleanups

This commit is contained in:
libretroadmin 2023-08-12 18:59:29 +02:00
parent 904e9fbe1d
commit 5f79c13928

232
runloop.c
View File

@ -371,7 +371,7 @@ unsigned retro_get_perf_count_libretro(void)
void runloop_performance_counter_register(struct retro_perf_counter *perf) void runloop_performance_counter_register(struct retro_perf_counter *perf)
{ {
if ( perf->registered if ( perf->registered
|| runloop_state.perf_ptr_libretro >= MAX_COUNTERS) || runloop_state.perf_ptr_libretro >= MAX_COUNTERS)
return; return;
@ -487,15 +487,15 @@ static bool runloop_environ_cb_get_system_info(unsigned cmd, void *data)
subsys_rom_info[j].valid_extensions)) subsys_rom_info[j].valid_extensions))
free((char *) free((char *)
subsys_rom_info[j].valid_extensions); subsys_rom_info[j].valid_extensions);
subsys_rom_info[j].desc = subsys_rom_info[j].desc =
strdup(info[i].roms[j].desc); strdup(info[i].roms[j].desc);
subsys_rom_info[j].valid_extensions = subsys_rom_info[j].valid_extensions =
strdup(info[i].roms[j].valid_extensions); strdup(info[i].roms[j].valid_extensions);
subsys_rom_info[j].required = subsys_rom_info[j].required =
info[i].roms[j].required; info[i].roms[j].required;
subsys_rom_info[j].block_extract = subsys_rom_info[j].block_extract =
info[i].roms[j].block_extract; info[i].roms[j].block_extract;
subsys_rom_info[j].need_fullpath = subsys_rom_info[j].need_fullpath =
info[i].roms[j].need_fullpath; info[i].roms[j].need_fullpath;
} }
@ -557,7 +557,7 @@ void libretro_get_environment_info(
runloop_st->flags &= ~RUNLOOP_FLAG_IGNORE_ENVIRONMENT_CB; runloop_st->flags &= ~RUNLOOP_FLAG_IGNORE_ENVIRONMENT_CB;
} }
static dylib_t load_dynamic_core(const char *path, char *buf, static dylib_t load_dynamic_core(const char *path, char *buf,
size_t size) size_t size)
{ {
#if defined(ANDROID) #if defined(ANDROID)
@ -998,7 +998,7 @@ static bool mmap_preprocess_descriptors(
if ((desc->core.len & (desc->core.len - 1)) != 0) if ((desc->core.len & (desc->core.len - 1)) != 0)
return false; return false;
desc->core.select = top_addr desc->core.select = top_addr
& ~mmap_inflate(mmap_add_bits_down(desc->core.len - 1), & ~mmap_inflate(mmap_add_bits_down(desc->core.len - 1),
desc->core.disconnect); desc->core.disconnect);
} }
@ -1017,12 +1017,12 @@ static bool mmap_preprocess_descriptors(
/* Disconnect unselected bits that are too high to ever /* Disconnect unselected bits that are too high to ever
* index into the core's buffer. Higher addresses will * index into the core's buffer. Higher addresses will
* repeat / mirror the buffer as long as they match select */ * repeat / mirror the buffer as long as they match select */
while (mmap_highest_bit(top_addr while (mmap_highest_bit(top_addr
& ~desc->core.select & ~desc->core.select
& ~desc->core.disconnect) > & ~desc->core.disconnect) >
mmap_highest_bit(highest_reachable)) mmap_highest_bit(highest_reachable))
desc->core.disconnect |= mmap_highest_bit(top_addr desc->core.disconnect |= mmap_highest_bit(top_addr
& ~desc->core.select & ~desc->core.select
& ~desc->core.disconnect); & ~desc->core.disconnect);
} }
@ -1203,7 +1203,7 @@ static bool validate_folder_specific_options(
* yet exist, provides source path from which initial * yet exist, provides source path from which initial
* options should be extracted * options should be extracted
* *
* NOTE: caller must ensure * NOTE: caller must ensure
* path and src_path are NULL-terminated * path and src_path are NULL-terminated
* *
**/ **/
@ -1212,41 +1212,36 @@ static void runloop_init_core_options_path(
char *path, size_t len, char *path, size_t len,
char *src_path, size_t src_len) char *src_path, size_t src_len)
{ {
char *game_options_path = NULL; char *options_path = NULL;
char *folder_options_path = NULL;
runloop_state_t *runloop_st = &runloop_state; runloop_state_t *runloop_st = &runloop_state;
bool game_specific_options = settings->bools.game_specific_options; bool game_specific_options = settings->bools.game_specific_options;
/* Check whether game-specific options exist */ /* Check whether game-specific options exist */
if ( game_specific_options if ( game_specific_options
&& validate_game_specific_options(&game_options_path)) && validate_game_specific_options(&options_path))
{ {
/* Notify system that we have a valid core options /* Notify system that we have a valid core options
* override */ * override */
path_set(RARCH_PATH_CORE_OPTIONS, game_options_path); path_set(RARCH_PATH_CORE_OPTIONS, options_path);
runloop_st->flags &= ~RUNLOOP_FLAG_FOLDER_OPTIONS_ACTIVE; runloop_st->flags &= ~RUNLOOP_FLAG_FOLDER_OPTIONS_ACTIVE;
runloop_st->flags |= RUNLOOP_FLAG_GAME_OPTIONS_ACTIVE; runloop_st->flags |= RUNLOOP_FLAG_GAME_OPTIONS_ACTIVE;
/* Copy options path */ strlcpy(path, options_path, len);
strlcpy(path, game_options_path, len); free(options_path);
free(game_options_path);
} }
/* Check whether folder-specific options exist */ /* Check whether folder-specific options exist */
else if ( game_specific_options else if ( game_specific_options
&& validate_folder_specific_options( && validate_folder_specific_options(
&folder_options_path)) &options_path))
{ {
/* Notify system that we have a valid core options /* Notify system that we have a valid core options
* override */ * override */
path_set(RARCH_PATH_CORE_OPTIONS, folder_options_path); path_set(RARCH_PATH_CORE_OPTIONS, options_path);
runloop_st->flags &= ~RUNLOOP_FLAG_GAME_OPTIONS_ACTIVE; runloop_st->flags &= ~RUNLOOP_FLAG_GAME_OPTIONS_ACTIVE;
runloop_st->flags |= RUNLOOP_FLAG_FOLDER_OPTIONS_ACTIVE; runloop_st->flags |= RUNLOOP_FLAG_FOLDER_OPTIONS_ACTIVE;
/* Copy options path */ strlcpy(path, options_path, len);
strlcpy(path, folder_options_path, len); free(options_path);
free(folder_options_path);
} }
else else
{ {
@ -1277,7 +1272,7 @@ static void runloop_init_core_options_path(
/* If not using per-core options, or if a per-core options /* If not using per-core options, or if a per-core options
* file does not yet exist, must fetch 'global' options path */ * file does not yet exist, must fetch 'global' options path */
if ( !per_core_options if ( !per_core_options
|| !per_core_options_exist) || !per_core_options_exist)
{ {
const char *options_path = path_core_options; const char *options_path = path_core_options;
@ -1358,9 +1353,10 @@ static void runloop_core_msg_queue_push(
struct retro_system_av_info *av_info, struct retro_system_av_info *av_info,
const struct retro_message_ext *msg) const struct retro_message_ext *msg)
{ {
double fps;
unsigned duration_frames;
enum message_queue_category category; enum message_queue_category category;
/* Get duration in frames */
double fps = (av_info && (av_info->timing.fps > 0)) ? av_info->timing.fps : 60.0;
unsigned duration_frames = (unsigned)((fps * (float)msg->duration / 1000.0f) + 0.5f);
/* Assign category */ /* Assign category */
switch (msg->level) switch (msg->level)
@ -1378,10 +1374,6 @@ static void runloop_core_msg_queue_push(
break; break;
} }
/* Get duration in frames */
fps = (av_info && (av_info->timing.fps > 0)) ? av_info->timing.fps : 60.0;
duration_frames = (unsigned)((fps * (float)msg->duration / 1000.0f) + 0.5f);
/* Note: Do not flush the message queue here - a core /* Note: Do not flush the message queue here - a core
* may need to send multiple notifications simultaneously */ * may need to send multiple notifications simultaneously */
runloop_msg_queue_push(msg->msg, runloop_msg_queue_push(msg->msg,
@ -1862,7 +1854,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
/* Handle 'alternate' non-queued notifications */ /* Handle 'alternate' non-queued notifications */
case RETRO_MESSAGE_TYPE_NOTIFICATION_ALT: case RETRO_MESSAGE_TYPE_NOTIFICATION_ALT:
{ {
video_driver_state_t *video_st = video_driver_state_t *video_st =
video_state_get_ptr(); video_state_get_ptr();
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr(); dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
@ -1879,7 +1871,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
/* Handle 'progress' messages */ /* Handle 'progress' messages */
case RETRO_MESSAGE_TYPE_PROGRESS: case RETRO_MESSAGE_TYPE_PROGRESS:
{ {
video_driver_state_t *video_st = video_driver_state_t *video_st =
video_state_get_ptr(); video_state_get_ptr();
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr(); dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
@ -1898,7 +1890,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
case RETRO_MESSAGE_TYPE_NOTIFICATION: case RETRO_MESSAGE_TYPE_NOTIFICATION:
default: default:
{ {
video_driver_state_t *video_st = video_driver_state_t *video_st =
video_state_get_ptr(); video_state_get_ptr();
runloop_core_msg_queue_push( runloop_core_msg_queue_push(
&video_st->av_info, msg); &video_st->av_info, msg);
@ -1975,7 +1967,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
const char *dir_system = settings->paths.directory_system; const char *dir_system = settings->paths.directory_system;
bool systemfiles_in_content_dir = settings->bools.systemfiles_in_content_dir; bool systemfiles_in_content_dir = settings->bools.systemfiles_in_content_dir;
if ( string_is_empty(dir_system) if ( string_is_empty(dir_system)
|| systemfiles_in_content_dir) || systemfiles_in_content_dir)
{ {
const char *fullpath = path_get(RARCH_PATH_CONTENT); const char *fullpath = path_get(RARCH_PATH_CONTENT);
@ -2030,7 +2022,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
case RETRO_ENVIRONMENT_SET_PIXEL_FORMAT: case RETRO_ENVIRONMENT_SET_PIXEL_FORMAT:
{ {
video_driver_state_t *video_st = video_driver_state_t *video_st =
video_state_get_ptr(); video_state_get_ptr();
enum retro_pixel_format pix_fmt = enum retro_pixel_format pix_fmt =
*(const enum retro_pixel_format*)data; *(const enum retro_pixel_format*)data;
@ -2186,7 +2178,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
case RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK: case RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK:
{ {
input_driver_state_t input_driver_state_t
*input_st = input_state_get_ptr(); *input_st = input_state_get_ptr();
const struct retro_keyboard_callback *info = const struct retro_keyboard_callback *info =
(const struct retro_keyboard_callback*)data; (const struct retro_keyboard_callback*)data;
@ -2294,7 +2286,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
struct retro_hw_render_callback *cb = struct retro_hw_render_callback *cb =
(struct retro_hw_render_callback*)data; (struct retro_hw_render_callback*)data;
video_driver_state_t *video_st = video_driver_state_t *video_st =
video_state_get_ptr(); video_state_get_ptr();
struct retro_hw_render_callback *hwr = struct retro_hw_render_callback *hwr =
VIDEO_DRIVER_GET_HW_CONTEXT_INTERNAL(video_st); VIDEO_DRIVER_GET_HW_CONTEXT_INTERNAL(video_st);
@ -2382,11 +2374,11 @@ bool runloop_environment_cb(unsigned cmd, void *data)
case RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK: case RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK:
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
{ {
recording_state_t recording_state_t
*recording_st = recording_state_get_ptr(); *recording_st = recording_state_get_ptr();
audio_driver_state_t audio_driver_state_t
*audio_st = audio_state_get_ptr(); *audio_st = audio_state_get_ptr();
const struct const struct
retro_audio_callback *cb = (const struct retro_audio_callback*)data; retro_audio_callback *cb = (const struct retro_audio_callback*)data;
RARCH_LOG("[Environ]: SET_AUDIO_CALLBACK.\n"); RARCH_LOG("[Environ]: SET_AUDIO_CALLBACK.\n");
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
@ -2473,7 +2465,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
* without video driver initialisation) */ * without video driver initialisation) */
if (audio_latency_new != audio_latency_current) if (audio_latency_new != audio_latency_current)
{ {
recording_state_t recording_state_t
*recording_st = recording_state_get_ptr(); *recording_st = recording_state_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr(); video_driver_state_t *video_st = video_state_get_ptr();
bool video_fullscreen = settings->bools.video_fullscreen; bool video_fullscreen = settings->bools.video_fullscreen;
@ -2485,9 +2477,9 @@ bool runloop_environment_cb(unsigned cmd, void *data)
command_event(CMD_EVENT_REINIT, &reinit_flags); command_event(CMD_EVENT_REINIT, &reinit_flags);
video_driver_set_aspect_ratio(); video_driver_set_aspect_ratio();
/* Cannot continue recording with different /* Cannot continue recording with different
* parameters. * parameters.
* Take the easiest route out and just restart * Take the easiest route out and just restart
* the recording. */ * the recording. */
if (recording_st->data) if (recording_st->data)
@ -2524,7 +2516,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
case RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES: case RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES:
{ {
uint64_t *mask = (uint64_t*)data; uint64_t *mask = (uint64_t*)data;
input_driver_state_t input_driver_state_t
*input_st = input_state_get_ptr(); *input_st = input_state_get_ptr();
RARCH_LOG("[Environ]: GET_INPUT_DEVICE_CAPABILITIES.\n"); RARCH_LOG("[Environ]: GET_INPUT_DEVICE_CAPABILITIES.\n");
@ -2571,7 +2563,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
{ {
struct retro_location_callback *cb = struct retro_location_callback *cb =
(struct retro_location_callback*)data; (struct retro_location_callback*)data;
location_driver_state_t location_driver_state_t
*location_st = location_state_get_ptr(); *location_st = location_state_get_ptr();
RARCH_LOG("[Environ]: GET_LOCATION_INTERFACE.\n"); RARCH_LOG("[Environ]: GET_LOCATION_INTERFACE.\n");
@ -2657,7 +2649,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
/* First set new refresh rate and display rate, then after REINIT do /* First set new refresh rate and display rate, then after REINIT do
* another display rate change to make sure the change stays */ * another display rate change to make sure the change stays */
if ( video_switch_refresh_rate if ( video_switch_refresh_rate
&& video_display_server_set_refresh_rate(refresh_rate)) && video_display_server_set_refresh_rate(refresh_rate))
video_monitor_set_refresh_rate(refresh_rate); video_monitor_set_refresh_rate(refresh_rate);
@ -2665,8 +2657,8 @@ bool runloop_environment_cb(unsigned cmd, void *data)
* reinit, otherwise the input driver crashes and the menu gets * reinit, otherwise the input driver crashes and the menu gets
* corrupted. */ * corrupted. */
if (no_video_reinit) if (no_video_reinit)
reinit_flags = reinit_flags =
DRIVERS_CMD_ALL & DRIVERS_CMD_ALL &
~(DRIVER_VIDEO_MASK | DRIVER_INPUT_MASK | ~(DRIVER_VIDEO_MASK | DRIVER_INPUT_MASK |
DRIVER_MENU_MASK); DRIVER_MENU_MASK);
@ -2690,7 +2682,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
video_display_server_set_refresh_rate(refresh_rate); video_display_server_set_refresh_rate(refresh_rate);
/* Cannot continue recording with different parameters. /* Cannot continue recording with different parameters.
* Take the easiest route out and just restart * Take the easiest route out and just restart
* the recording. */ * the recording. */
if (recording_st->data) if (recording_st->data)
{ {
@ -2924,7 +2916,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
/* Can potentially be called every frame, /* Can potentially be called every frame,
* don't do anything unless required. */ * don't do anything unless required. */
if ( (geom->base_width != in_geom->base_width) if ( (geom->base_width != in_geom->base_width)
|| (geom->base_height != in_geom->base_height) || (geom->base_height != in_geom->base_height)
|| (geom->aspect_ratio != in_geom->aspect_ratio)) || (geom->aspect_ratio != in_geom->aspect_ratio))
{ {
geom->base_width = in_geom->base_width; geom->base_width = in_geom->base_width;
@ -2942,7 +2934,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
if (settings->bools.video_frame_delay_auto) if (settings->bools.video_frame_delay_auto)
video_st->frame_delay_pause = true; video_st->frame_delay_pause = true;
/* TODO: Figure out what to do, if anything, with /* TODO: Figure out what to do, if anything, with
recording. */ recording. */
} }
else else
@ -3206,12 +3198,12 @@ bool runloop_environment_cb(unsigned cmd, void *data)
bool menu_opened = false; bool menu_opened = false;
bool core_paused = runloop_st->flags & RUNLOOP_FLAG_PAUSED; bool core_paused = runloop_st->flags & RUNLOOP_FLAG_PAUSED;
bool no_audio = ((audio_st->flags & AUDIO_FLAG_SUSPENDED) bool no_audio = ((audio_st->flags & AUDIO_FLAG_SUSPENDED)
|| !(audio_st->flags & AUDIO_FLAG_ACTIVE)); || !(audio_st->flags & AUDIO_FLAG_ACTIVE));
float core_fps = (float)video_st->av_info.timing.fps; float core_fps = (float)video_st->av_info.timing.fps;
#ifdef HAVE_REWIND #ifdef HAVE_REWIND
if (runloop_st->rewind_st.flags if (runloop_st->rewind_st.flags
& STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED) & STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED)
{ {
throttle_state->mode = RETRO_THROTTLE_REWINDING; throttle_state->mode = RETRO_THROTTLE_REWINDING;
@ -3258,7 +3250,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
/* VSync overrides the mode if the rate is limited by the display. */ /* VSync overrides the mode if the rate is limited by the display. */
if ( menu_opened /* Menu currently always runs with vsync on. */ if ( menu_opened /* Menu currently always runs with vsync on. */
|| (settings->bools.video_vsync || (settings->bools.video_vsync
&& (!(runloop_st->flags & RUNLOOP_FLAG_FORCE_NONBLOCK)) && (!(runloop_st->flags & RUNLOOP_FLAG_FORCE_NONBLOCK))
&& !(input_state_get_ptr()->flags & INP_FLAG_NONBLOCKING))) && !(input_state_get_ptr()->flags & INP_FLAG_NONBLOCKING)))
{ {
@ -3280,7 +3272,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
&& throttle_state->mode != RETRO_THROTTLE_VSYNC) && throttle_state->mode != RETRO_THROTTLE_VSYNC)
{ {
/* Keep base if frame limiter matching the core is active. */ /* Keep base if frame limiter matching the core is active. */
retro_time_t core_limit = (core_fps retro_time_t core_limit = (core_fps
? (retro_time_t)(1000000.0f / core_fps) ? (retro_time_t)(1000000.0f / core_fps)
: (retro_time_t)0); : (retro_time_t)0);
retro_time_t frame_limit = runloop_st->frame_limit_minimum_time; retro_time_t frame_limit = runloop_st->frame_limit_minimum_time;
@ -3749,7 +3741,7 @@ static void runloop_audio_buffer_status_free(runloop_state_t *runloop_st)
static void runloop_fastmotion_override_free(runloop_state_t *runloop_st) static void runloop_fastmotion_override_free(runloop_state_t *runloop_st)
{ {
video_driver_state_t video_driver_state_t
*video_st = video_state_get_ptr(); *video_st = video_state_get_ptr();
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
float fastforward_ratio = settings->floats.fastforward_ratio; float fastforward_ratio = settings->floats.fastforward_ratio;
@ -3959,7 +3951,7 @@ static void runloop_apply_fastmotion_override(runloop_state_t *runloop_st, setti
* (required if RETRO_ENVIRONMENT_SET_FASTFORWARDING_OVERRIDE * (required if RETRO_ENVIRONMENT_SET_FASTFORWARDING_OVERRIDE
* is called during core de-initialisation) */ * is called during core de-initialisation) */
#if defined(HAVE_GFX_WIDGETS) #if defined(HAVE_GFX_WIDGETS)
if ( p_dispwidget->active if ( p_dispwidget->active
&& !(runloop_st->flags & RUNLOOP_FLAG_FASTMOTION)) && !(runloop_st->flags & RUNLOOP_FLAG_FASTMOTION))
video_st->flags &= ~VIDEO_FLAG_WIDGETS_FAST_FORWARD; video_st->flags &= ~VIDEO_FLAG_WIDGETS_FAST_FORWARD;
#endif #endif
@ -3979,7 +3971,7 @@ static void runloop_apply_fastmotion_override(runloop_state_t *runloop_st, setti
void runloop_event_deinit_core(void) void runloop_event_deinit_core(void)
{ {
video_driver_state_t video_driver_state_t
*video_st = video_state_get_ptr(); *video_st = video_state_get_ptr();
runloop_state_t *runloop_st = &runloop_state; runloop_state_t *runloop_st = &runloop_state;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
@ -4073,7 +4065,7 @@ static bool runloop_path_init_subsystem(runloop_state_t *runloop_st)
{ {
unsigned num_content = MIN(info->num_roms, unsigned num_content = MIN(info->num_roms,
subsystem_path_empty subsystem_path_empty
? 0 ? 0
: (unsigned)runloop_st->subsystem_fullpaths->size); : (unsigned)runloop_st->subsystem_fullpaths->size);
for (i = 0; i < num_content; i++) for (i = 0; i < num_content; i++)
@ -4117,7 +4109,7 @@ static bool runloop_path_init_subsystem(runloop_state_t *runloop_st)
} }
} }
/* Let other relevant paths be inferred /* Let other relevant paths be inferred
from the main SRAM location. */ from the main SRAM location. */
if (!retroarch_override_setting_is_set( if (!retroarch_override_setting_is_set(
RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL)) RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL))
@ -4155,7 +4147,7 @@ static void runloop_path_init_savefile_internal(runloop_state_t *runloop_st)
static void runloop_path_init_savefile(runloop_state_t *runloop_st) static void runloop_path_init_savefile(runloop_state_t *runloop_st)
{ {
bool should_sram_be_used = bool should_sram_be_used =
(runloop_st->flags & RUNLOOP_FLAG_USE_SRAM) (runloop_st->flags & RUNLOOP_FLAG_USE_SRAM)
&& !(runloop_st->flags & RUNLOOP_FLAG_IS_SRAM_SAVE_DISABLED); && !(runloop_st->flags & RUNLOOP_FLAG_IS_SRAM_SAVE_DISABLED);
@ -4229,7 +4221,7 @@ static bool event_init_content(
are true. are true.
*/ */
#ifdef HAVE_CHEEVOS #ifdef HAVE_CHEEVOS
if ( !cheevos_enable if ( !cheevos_enable
|| !cheevos_hardcore_mode_enable) || !cheevos_hardcore_mode_enable)
#endif #endif
{ {
@ -4239,7 +4231,7 @@ static bool event_init_content(
if (!(input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_START_PLAYBACK)) if (!(input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_START_PLAYBACK))
#endif #endif
{ {
if ( runloop_st->entry_state_slot if ( runloop_st->entry_state_slot
&& !command_event_load_entry_state(settings)) && !command_event_load_entry_state(settings))
{ {
/* loading the state failed, reset entry slot */ /* loading the state failed, reset entry slot */
@ -4331,7 +4323,7 @@ void runloop_set_frame_limit(
runloop_st->frame_limit_minimum_time = 0.0f; runloop_st->frame_limit_minimum_time = 0.0f;
else else
runloop_st->frame_limit_minimum_time = (retro_time_t) runloop_st->frame_limit_minimum_time = (retro_time_t)
roundf(1000000.0f / roundf(1000000.0f /
(av_info->timing.fps * fastforward_ratio)); (av_info->timing.fps * fastforward_ratio));
} }
@ -4339,7 +4331,7 @@ float runloop_get_fastforward_ratio(
settings_t *settings, settings_t *settings,
struct retro_fastforwarding_override *fastmotion_override) struct retro_fastforwarding_override *fastmotion_override)
{ {
if ( fastmotion_override->fastforward if ( fastmotion_override->fastforward
&& (fastmotion_override->ratio >= 0.0f)) && (fastmotion_override->ratio >= 0.0f))
return fastmotion_override->ratio; return fastmotion_override->ratio;
return settings->floats.fastforward_ratio; return settings->floats.fastforward_ratio;
@ -4378,7 +4370,7 @@ void runloop_set_video_swap_interval(
* set swap interval to 1 */ * set swap interval to 1 */
if ( (vrr_runloop_enable) if ( (vrr_runloop_enable)
|| (core_hz > timing_hz) || (core_hz > timing_hz)
|| (core_hz <= 0.0f) || (core_hz <= 0.0f)
|| (timing_hz <= 0.0f)) || (timing_hz <= 0.0f))
{ {
runloop_st->video_swap_interval_auto = 1; runloop_st->video_swap_interval_auto = 1;
@ -4425,7 +4417,7 @@ unsigned int retroarch_get_core_requested_rotation(void)
} }
/* /*
Returns final rotation including both user chosen video rotation Returns final rotation including both user chosen video rotation
and core requested rotation if allowed by video_allow_rotate and core requested rotation if allowed by video_allow_rotate
*/ */
unsigned int retroarch_get_rotation(void) unsigned int retroarch_get_rotation(void)
@ -4925,7 +4917,7 @@ bool core_options_remove_override(bool game_specific)
/* Sanity check 2 - can only remove an override /* Sanity check 2 - can only remove an override
* if the specified type is currently active */ * if the specified type is currently active */
if ( game_specific if ( game_specific
&& !(runloop_st->flags & RUNLOOP_FLAG_GAME_OPTIONS_ACTIVE) && !(runloop_st->flags & RUNLOOP_FLAG_GAME_OPTIONS_ACTIVE)
) )
goto error; goto error;
@ -5114,7 +5106,7 @@ void core_options_flush(void)
if (!string_is_empty(path_core_options)) if (!string_is_empty(path_core_options))
{ {
config_file_t *conf_tmp = NULL; config_file_t *conf_tmp = NULL;
bool path_valid = path_is_valid(path_core_options); bool path_valid = path_is_valid(path_core_options);
/* Attempt to load existing file */ /* Attempt to load existing file */
if (path_valid) if (path_valid)
@ -5419,7 +5411,7 @@ static enum runloop_state_enum runloop_check_state(
BIT256_CLEAR_ALL_PTR(&current_bits); BIT256_CLEAR_ALL_PTR(&current_bits);
input_st->flags &= ~(INP_FLAG_BLOCK_LIBRETRO_INPUT input_st->flags &= ~(INP_FLAG_BLOCK_LIBRETRO_INPUT
| INP_FLAG_BLOCK_HOTKEY); | INP_FLAG_BLOCK_HOTKEY);
if (input_st->flags & INP_FLAG_KB_MAPPING_BLOCKED) if (input_st->flags & INP_FLAG_KB_MAPPING_BLOCKED)
@ -5452,8 +5444,8 @@ static enum runloop_state_enum runloop_check_state(
if (input_active || (menu_st->input_driver_flushing_input > 0)) if (input_active || (menu_st->input_driver_flushing_input > 0))
{ {
BIT256_CLEAR_ALL(current_bits); BIT256_CLEAR_ALL(current_bits);
if ( runloop_paused if ( runloop_paused
&& !runloop_paused_hotkey && !runloop_paused_hotkey
&& settings->bools.menu_pause_libretro) && settings->bools.menu_pause_libretro)
BIT256_SET(current_bits, RARCH_PAUSE_TOGGLE); BIT256_SET(current_bits, RARCH_PAUSE_TOGGLE);
else if (runloop_paused_hotkey) else if (runloop_paused_hotkey)
@ -5497,7 +5489,7 @@ static enum runloop_state_enum runloop_check_state(
HOTKEY_CHECK(RARCH_GRAB_MOUSE_TOGGLE, CMD_EVENT_GRAB_MOUSE_TOGGLE, true, NULL); HOTKEY_CHECK(RARCH_GRAB_MOUSE_TOGGLE, CMD_EVENT_GRAB_MOUSE_TOGGLE, true, NULL);
/* Automatic mouse grab on focus */ /* Automatic mouse grab on focus */
if ( settings->bools.input_auto_mouse_grab if ( settings->bools.input_auto_mouse_grab
&& (is_focused) && (is_focused)
&& (is_focused != (((runloop_st->flags & RUNLOOP_FLAG_FOCUSED)) > 0)) && (is_focused != (((runloop_st->flags & RUNLOOP_FLAG_FOCUSED)) > 0))
&& !(input_st->flags & INP_FLAG_GRAB_MOUSE_STATE)) && !(input_st->flags & INP_FLAG_GRAB_MOUSE_STATE))
@ -5564,10 +5556,10 @@ static enum runloop_state_enum runloop_check_state(
#endif #endif
/* /*
* If the Aspect Ratio is FULL then update the aspect ratio to the * If the Aspect Ratio is FULL then update the aspect ratio to the
* current video driver aspect ratio (The full window) * current video driver aspect ratio (The full window)
* *
* TODO/FIXME * TODO/FIXME
* Should possibly be refactored to have last width & driver width & height * Should possibly be refactored to have last width & driver width & height
* only be done once when we are using an overlay OR using aspect ratio * only be done once when we are using an overlay OR using aspect ratio
* full * full
@ -5612,7 +5604,7 @@ static enum runloop_state_enum runloop_check_state(
quit_press_twice = settings->bools.quit_press_twice; quit_press_twice = settings->bools.quit_press_twice;
/* Check double press if enabled */ /* Check double press if enabled */
if ( trig_quit_key if ( trig_quit_key
&& quit_press_twice) && quit_press_twice)
{ {
static retro_time_t quit_key_time = 0; static retro_time_t quit_key_time = 0;
@ -5915,7 +5907,7 @@ static enum runloop_state_enum runloop_check_state(
runloop_st->flags & RUNLOOP_FLAG_IDLE); runloop_st->flags & RUNLOOP_FLAG_IDLE);
} }
if ( (menu_st->flags & MENU_ST_FLAG_ALIVE) if ( (menu_st->flags & MENU_ST_FLAG_ALIVE)
&& !(runloop_st->flags & RUNLOOP_FLAG_IDLE)) && !(runloop_st->flags & RUNLOOP_FLAG_IDLE))
if (display_menu_libretro(runloop_st, input_st, if (display_menu_libretro(runloop_st, input_st,
settings->floats.slowmotion_ratio, settings->floats.slowmotion_ratio,
@ -6330,7 +6322,7 @@ static enum runloop_state_enum runloop_check_state(
current_bits, RARCH_FAST_FORWARD_KEY); current_bits, RARCH_FAST_FORWARD_KEY);
bool new_hold_button_state = BIT256_GET( bool new_hold_button_state = BIT256_GET(
current_bits, RARCH_FAST_FORWARD_HOLD_KEY); current_bits, RARCH_FAST_FORWARD_HOLD_KEY);
bool check2 = new_button_state bool check2 = new_button_state
&& !old_button_state; && !old_button_state;
if (!check2) if (!check2)
@ -6468,7 +6460,7 @@ static enum runloop_state_enum runloop_check_state(
#ifdef HAVE_REWIND #ifdef HAVE_REWIND
struct state_manager_rewind_state struct state_manager_rewind_state
*rewind_st = &runloop_st->rewind_st; *rewind_st = &runloop_st->rewind_st;
if (rewind_st->flags if (rewind_st->flags
& STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED) & STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED)
runloop_msg_queue_push( runloop_msg_queue_push(
msg_hash_to_str(MSG_SLOW_MOTION_REWIND), 1, 1, false, NULL, msg_hash_to_str(MSG_SLOW_MOTION_REWIND), 1, 1, false, NULL,
@ -6569,12 +6561,12 @@ static enum runloop_state_enum runloop_check_state(
if (check2 && !check1 && replay_slot + addition < -1) if (check2 && !check1 && replay_slot + addition < -1)
{ {
replay_slot = 1000; replay_slot = 1000;
check1 = true; check1 = true;
} }
} }
/* Wrap-around to -1 (Auto) */ /* Wrap-around to -1 (Auto) */
else if (replay_slot + addition > 999) else if (replay_slot + addition > 999)
replay_slot = -2; replay_slot = -2;
if (check2) if (check2)
{ {
@ -6670,10 +6662,10 @@ static enum runloop_state_enum runloop_check_state(
*/ */
if (need_to_apply) if (need_to_apply)
{ {
timer.current = current_time; timer.current = current_time;
timer.timeout_us = timer.timeout_end - timer.current; timer.timeout_us = timer.timeout_end - timer.current;
if ( !timer.timer_end if ( !timer.timer_end
&& timer.timeout_us <= 0) && timer.timeout_us <= 0)
{ {
timer.timer_end = true; timer.timer_end = true;
@ -6692,7 +6684,7 @@ static enum runloop_state_enum runloop_check_state(
{ {
runloop_st->shader_delay_timer.timeout_us = settings->uints.video_shader_delay * 1000; runloop_st->shader_delay_timer.timeout_us = settings->uints.video_shader_delay * 1000;
runloop_st->shader_delay_timer.current = cpu_features_get_time_usec(); runloop_st->shader_delay_timer.current = cpu_features_get_time_usec();
runloop_st->shader_delay_timer.timeout_end = runloop_st->shader_delay_timer.current runloop_st->shader_delay_timer.timeout_end = runloop_st->shader_delay_timer.current
+ runloop_st->shader_delay_timer.timeout_us; + runloop_st->shader_delay_timer.timeout_us;
runloop_st->shader_delay_timer.timer_begin = true; runloop_st->shader_delay_timer.timer_begin = true;
runloop_st->shader_delay_timer.timer_end = false; runloop_st->shader_delay_timer.timer_end = false;
@ -6700,7 +6692,7 @@ static enum runloop_state_enum runloop_check_state(
else else
{ {
runloop_st->shader_delay_timer.current = current_time; runloop_st->shader_delay_timer.current = current_time;
runloop_st->shader_delay_timer.timeout_us = runloop_st->shader_delay_timer.timeout_end runloop_st->shader_delay_timer.timeout_us = runloop_st->shader_delay_timer.timeout_end
- runloop_st->shader_delay_timer.current; - runloop_st->shader_delay_timer.current;
if (runloop_st->shader_delay_timer.timeout_us <= 0) if (runloop_st->shader_delay_timer.timeout_us <= 0)
@ -6886,8 +6878,8 @@ int runloop_iterate(void)
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
#ifdef HAVE_MENU #ifdef HAVE_MENU
/* FIXME: This is an ugly way to tell Netplay this... */ /* FIXME: This is an ugly way to tell Netplay this... */
if (menu_pause_libretro && if ( menu_pause_libretro
netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) && netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)
) )
netplay_driver_ctl(RARCH_NETPLAY_CTL_PAUSE, NULL); netplay_driver_ctl(RARCH_NETPLAY_CTL_PAUSE, NULL);
#endif #endif
@ -6961,16 +6953,16 @@ int runloop_iterate(void)
if (dpad_mode[i] == ANALOG_DPAD_LSTICK) if (dpad_mode[i] == ANALOG_DPAD_LSTICK)
{ {
x_plus = RARCH_ANALOG_LEFT_X_PLUS; x_plus = RARCH_ANALOG_LEFT_X_PLUS;
y_plus = RARCH_ANALOG_LEFT_Y_PLUS; y_plus = RARCH_ANALOG_LEFT_Y_PLUS;
x_minus = RARCH_ANALOG_LEFT_X_MINUS; x_minus = RARCH_ANALOG_LEFT_X_MINUS;
y_minus = RARCH_ANALOG_LEFT_Y_MINUS; y_minus = RARCH_ANALOG_LEFT_Y_MINUS;
} }
for (k = RETRO_DEVICE_ID_JOYPAD_UP; k <= RETRO_DEVICE_ID_JOYPAD_RIGHT; k++) for (k = RETRO_DEVICE_ID_JOYPAD_UP; k <= RETRO_DEVICE_ID_JOYPAD_RIGHT; k++)
{ {
(auto_binds)[k].orig_joyaxis = (auto_binds)[k].joyaxis; (auto_binds)[k].orig_joyaxis = (auto_binds)[k].joyaxis;
(general_binds)[k].orig_joyaxis = (general_binds)[k].joyaxis; (general_binds)[k].orig_joyaxis = (general_binds)[k].joyaxis;
} }
if (!INHERIT_JOYAXIS(auto_binds)) if (!INHERIT_JOYAXIS(auto_binds))
@ -7010,9 +7002,9 @@ int runloop_iterate(void)
static bool skip_delay_prev = false; static bool skip_delay_prev = false;
bool frame_time_update = bool frame_time_update =
/* Skip some initial frames for stabilization */ /* Skip some initial frames for stabilization */
video_st->frame_count > frame_time_interval && video_st->frame_count > frame_time_interval
/* Only update when there are enough frames for averaging */ /* Only update when there are enough frames for averaging */
video_st->frame_count % frame_time_interval == 0; && video_st->frame_count % frame_time_interval == 0;
/* A few frames must be ignored after slow+fastmotion/pause /* A few frames must be ignored after slow+fastmotion/pause
* is disabled or geometry change is triggered */ * is disabled or geometry change is triggered */
@ -7045,17 +7037,17 @@ int runloop_iterate(void)
/* Reset new desired delay target */ /* Reset new desired delay target */
if (video_st->frame_delay_target != video_frame_delay) if (video_st->frame_delay_target != video_frame_delay)
{ {
frame_time_update = false; frame_time_update = false;
video_st->frame_delay_target = video_frame_delay_effective = video_frame_delay; video_st->frame_delay_target = video_frame_delay_effective = video_frame_delay;
RARCH_LOG("[Video]: Frame delay reset to %d ms.\n", video_frame_delay); RARCH_LOG("[Video]: Frame delay reset to %d ms.\n", video_frame_delay);
} }
/* Decide what should happen to effective delay */ /* Decide what should happen to effective delay */
if (video_frame_delay_effective > 0 && frame_time_update) if (video_frame_delay_effective > 0 && frame_time_update)
{ {
video_frame_delay_auto_t vfda = {0}; video_frame_delay_auto_t vfda = {0};
vfda.frame_time_interval = frame_time_interval; vfda.frame_time_interval = frame_time_interval;
vfda.refresh_rate = refresh_rate; vfda.refresh_rate = refresh_rate;
video_frame_delay_auto(video_st, &vfda); video_frame_delay_auto(video_st, &vfda);
if (vfda.delay_decrease > 0) if (vfda.delay_decrease > 0)
@ -7084,10 +7076,10 @@ int runloop_iterate(void)
bool run_ahead_secondary_instance = settings->bools.run_ahead_secondary_instance; bool run_ahead_secondary_instance = settings->bools.run_ahead_secondary_instance;
/* Run Ahead Feature replaces the call to core_run in this loop */ /* Run Ahead Feature replaces the call to core_run in this loop */
bool want_runahead = run_ahead_enabled bool want_runahead = run_ahead_enabled
&& (run_ahead_num_frames > 0) && (run_ahead_num_frames > 0)
&& (runloop_st->flags & RUNLOOP_FLAG_RUNAHEAD_AVAILABLE); && (runloop_st->flags & RUNLOOP_FLAG_RUNAHEAD_AVAILABLE);
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
want_runahead = want_runahead want_runahead = want_runahead
&& !netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL); && !netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL);
#endif #endif
@ -7204,9 +7196,9 @@ end:
/* if there's a fast forward limit, inject sleeps to keep from going too fast. */ /* if there's a fast forward limit, inject sleeps to keep from going too fast. */
if (runloop_st->frame_limit_minimum_time) if (runloop_st->frame_limit_minimum_time)
{ {
const retro_time_t end_frame_time = cpu_features_get_time_usec(); const retro_time_t end_frame_time = cpu_features_get_time_usec();
const retro_time_t to_sleep_ms = ( const retro_time_t to_sleep_ms = (
( runloop_st->frame_limit_last_time ( runloop_st->frame_limit_last_time
+ runloop_st->frame_limit_minimum_time) + runloop_st->frame_limit_minimum_time)
- end_frame_time) / 1000; - end_frame_time) / 1000;
@ -7215,7 +7207,7 @@ end:
unsigned sleep_ms = (unsigned)to_sleep_ms; unsigned sleep_ms = (unsigned)to_sleep_ms;
/* Combat jitter a bit. */ /* Combat jitter a bit. */
runloop_st->frame_limit_last_time += runloop_st->frame_limit_last_time +=
runloop_st->frame_limit_minimum_time; runloop_st->frame_limit_minimum_time;
if (sleep_ms > 0) if (sleep_ms > 0)
@ -7501,7 +7493,7 @@ bool core_set_cheat(retro_ctx_cheat_info_t *info)
run_ahead_frames = settings->uints.run_ahead_frames; run_ahead_frames = settings->uints.run_ahead_frames;
run_ahead_secondary_instance = settings->bools.run_ahead_secondary_instance; run_ahead_secondary_instance = settings->bools.run_ahead_secondary_instance;
want_runahead = run_ahead_enabled want_runahead = run_ahead_enabled
&& (run_ahead_frames > 0) && (run_ahead_frames > 0)
&& (runloop_st->flags & RUNLOOP_FLAG_RUNAHEAD_AVAILABLE); && (runloop_st->flags & RUNLOOP_FLAG_RUNAHEAD_AVAILABLE);
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (want_runahead) if (want_runahead)
@ -7540,8 +7532,8 @@ bool core_reset_cheat(void)
run_ahead_enabled = settings->bools.run_ahead_enabled; run_ahead_enabled = settings->bools.run_ahead_enabled;
run_ahead_frames = settings->uints.run_ahead_frames; run_ahead_frames = settings->uints.run_ahead_frames;
run_ahead_secondary_instance = settings->bools.run_ahead_secondary_instance; run_ahead_secondary_instance = settings->bools.run_ahead_secondary_instance;
want_runahead = run_ahead_enabled want_runahead = run_ahead_enabled
&& (run_ahead_frames > 0) && (run_ahead_frames > 0)
&& (runloop_st->flags & RUNLOOP_FLAG_RUNAHEAD_AVAILABLE); && (runloop_st->flags & RUNLOOP_FLAG_RUNAHEAD_AVAILABLE);
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (want_runahead) if (want_runahead)
@ -7782,7 +7774,7 @@ void core_run(void)
current_core->retro_run(); current_core->retro_run();
if ( late_polling if ( late_polling
&& (!(current_core->flags & RETRO_CORE_FLAG_INPUT_POLLED))) && (!(current_core->flags & RETRO_CORE_FLAG_INPUT_POLLED)))
input_driver_poll(); input_driver_poll();
@ -7874,7 +7866,7 @@ void runloop_path_set_names(void)
sizeof(runloop_st->name.replay) - len); sizeof(runloop_st->name.replay) - len);
} }
#endif #endif
#ifdef HAVE_CHEATS #ifdef HAVE_CHEATS
if (!string_is_empty(runloop_st->runtime_content_path_basename)) if (!string_is_empty(runloop_st->runtime_content_path_basename))
{ {
@ -7929,7 +7921,7 @@ void runloop_path_set_redirect(settings_t *settings,
#endif #endif
{ {
/* Per-core and/or per-content-directory saves */ /* Per-core and/or per-content-directory saves */
if (( sort_savefiles_enable if (( sort_savefiles_enable
|| sort_savefiles_by_content_enable) || sort_savefiles_by_content_enable)
&& !string_is_empty(old_savefile_dir)) && !string_is_empty(old_savefile_dir))
{ {
@ -8008,13 +8000,13 @@ void runloop_path_set_redirect(settings_t *settings,
if (string_is_empty(new_savefile_dir)) if (string_is_empty(new_savefile_dir))
RARCH_LOG("Cannot resolve save file path.\n"); RARCH_LOG("Cannot resolve save file path.\n");
else if (sort_savefiles_enable else if (sort_savefiles_enable
|| sort_savefiles_by_content_enable) || sort_savefiles_by_content_enable)
RARCH_LOG("Saving files in content directory is set. This overrides other save file directory settings.\n"); RARCH_LOG("Saving files in content directory is set. This overrides other save file directory settings.\n");
} }
/* Set savestate directory if empty based on content directory */ /* Set savestate directory if empty based on content directory */
if ( string_is_empty(new_savestate_dir) if ( string_is_empty(new_savestate_dir)
|| savestates_in_content_dir) || savestates_in_content_dir)
{ {
strlcpy(new_savestate_dir, strlcpy(new_savestate_dir,
@ -8024,7 +8016,7 @@ void runloop_path_set_redirect(settings_t *settings,
if (string_is_empty(new_savestate_dir)) if (string_is_empty(new_savestate_dir))
RARCH_LOG("Cannot resolve save state file path.\n"); RARCH_LOG("Cannot resolve save state file path.\n");
else if (sort_savestates_enable else if (sort_savestates_enable
|| sort_savestates_by_content_enable) || sort_savestates_by_content_enable)
RARCH_LOG("Saving save states in content directory is set. This overrides other save state file directory settings.\n"); RARCH_LOG("Saving save states in content directory is set. This overrides other save state file directory settings.\n");
} }