Some cleanups to runloop - should not affect anything functionality-wise

This commit is contained in:
twinaphex 2019-01-12 17:58:35 +01:00
parent 700829b5d7
commit d95b4b70e7

View File

@ -207,7 +207,6 @@ bool discord_is_inited = false;
#endif
static bool rarch_is_inited = false;
static bool rarch_error_on_init = false;
static bool rarch_block_config_read = false;
static bool rarch_force_fullscreen = false;
static bool rarch_is_switching_display_mode = false;
static bool has_set_verbosity = false;
@ -230,13 +229,11 @@ static bool rarch_use_sram = false;
static bool rarch_ups_pref = false;
static bool rarch_bps_pref = false;
static bool rarch_ips_pref = false;
static bool rarch_patch_blocked = false;
static bool rarch_first_start = true;
static bool runloop_force_nonblock = false;
static bool runloop_paused = false;
static bool runloop_idle = false;
static bool runloop_exec = false;
static bool runloop_slowmotion = false;
bool runloop_fastmotion = false;
static bool runloop_shutdown_initiated = false;
@ -247,7 +244,6 @@ static bool runloop_remaps_core_active = false;
static bool runloop_remaps_game_active = false;
static bool runloop_remaps_content_dir_active = false;
static bool runloop_game_options_active = false;
static bool runloop_missing_bios = false;
static bool runloop_autosave = false;
#ifdef HAVE_DYNAMIC
static bool core_set_on_cmdline = false;
@ -351,14 +347,14 @@ static void global_free(void)
command_event(CMD_EVENT_RECORD_DEINIT, NULL);
command_event(CMD_EVENT_LOG_FILE_DEINIT, NULL);
rarch_block_config_read = false;
rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL);
rarch_is_sram_load_disabled = false;
rarch_is_sram_save_disabled = false;
rarch_use_sram = false;
rarch_bps_pref = false;
rarch_ips_pref = false;
rarch_ups_pref = false;
rarch_patch_blocked = false;
rarch_ctl(RARCH_CTL_UNSET_BPS_PREF, NULL);
rarch_ctl(RARCH_CTL_UNSET_IPS_PREF, NULL);
rarch_ctl(RARCH_CTL_UNSET_UPS_PREF, NULL);
rarch_ctl(RARCH_CTL_UNSET_PATCH_BLOCKED, NULL);
runloop_overrides_active = false;
runloop_remaps_core_active = false;
runloop_remaps_game_active = false;
@ -725,9 +721,9 @@ static void retroarch_parse_input_and_config(int argc, char *argv[])
retroarch_override_setting_free_state();
has_set_username = false;
rarch_ups_pref = false;
rarch_ips_pref = false;
rarch_bps_pref = false;
rarch_ctl(RARCH_CTL_UNSET_UPS_PREF, NULL);
rarch_ctl(RARCH_CTL_UNSET_IPS_PREF, NULL);
rarch_ctl(RARCH_CTL_UNSET_BPS_PREF, NULL);
*global->name.ups = '\0';
*global->name.bps = '\0';
*global->name.ips = '\0';
@ -1546,6 +1542,10 @@ error:
bool rarch_ctl(enum rarch_ctl_state state, void *data)
{
static bool rarch_block_config_read = false;
static bool rarch_patch_blocked = false;
static bool runloop_missing_bios = false; /* TODO/FIXME - not used right now? */
switch(state)
{
case RARCH_CTL_IS_PATCH_BLOCKED:
@ -1587,7 +1587,7 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
has_set_username = false;
rarch_is_inited = false;
rarch_error_on_init = false;
rarch_block_config_read = false;
rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL);
retroarch_msg_queue_deinit();
driver_uninit(DRIVERS_CMD_ALL);
@ -1609,7 +1609,7 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
global_free();
break;
case RARCH_CTL_MAIN_DEINIT:
if (!rarch_is_inited)
if (!rarch_ctl(RARCH_CTL_IS_INITED, NULL))
return false;
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
command_event(CMD_EVENT_COMMAND_DEINIT, NULL);
@ -1640,7 +1640,7 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
#endif
break;
case RARCH_CTL_INIT:
if (rarch_is_inited)
if (rarch_ctl(RARCH_CTL_IS_INITED, NULL))
driver_uninit(DRIVERS_CMD_ALL);
#ifdef HAVE_THREAD_STORAGE
@ -2591,12 +2591,15 @@ static bool input_driver_toggle_button_combo(
static enum runloop_state runloop_check_state(
settings_t *settings,
bool input_nonblock_state,
bool runloop_is_paused,
float fastforward_ratio,
unsigned *sleep_ms)
{
input_bits_t current_input;
#ifdef HAVE_MENU
static input_bits_t last_input = {{0}};
#endif
static bool runloop_exec = false;
static bool old_fs_toggle_pressed= false;
static bool old_focus = true;
bool is_focused = false;
@ -2604,18 +2607,20 @@ static enum runloop_state runloop_check_state(
uint64_t frame_count = 0;
bool focused = true;
bool pause_nonactive = settings->bools.pause_nonactive;
bool rarch_is_initialized = rarch_ctl(RARCH_CTL_IS_INITED, NULL);
bool fs_toggle_triggered = false;
#ifdef HAVE_MENU
bool menu_driver_binding_state = menu_driver_is_binding_state();
bool menu_is_alive = menu_driver_is_alive();
unsigned menu_toggle_gamepad_combo = settings->uints.input_menu_toggle_gamepad_combo;
#ifdef HAVE_EASTEREGG
static uint64_t seq = 0;
#endif
#endif
#ifdef HAVE_LIBNX
// Should be called once per frame
if(!appletMainLoop())
/* Should be called once per frame */
if (!appletMainLoop())
return RUNLOOP_STATE_QUIT;
#endif
@ -2631,9 +2636,9 @@ static enum runloop_state runloop_check_state(
#ifdef HAVE_MENU
last_input = current_input;
if (
((settings->uints.input_menu_toggle_gamepad_combo != INPUT_TOGGLE_NONE) &&
((menu_toggle_gamepad_combo != INPUT_TOGGLE_NONE) &&
input_driver_toggle_button_combo(
settings->uints.input_menu_toggle_gamepad_combo, &last_input)))
menu_toggle_gamepad_combo, &last_input)))
BIT256_SET(current_input, RARCH_MENU_TOGGLE);
#endif
@ -2643,7 +2648,7 @@ static enum runloop_state runloop_check_state(
if (bits_any_set(current_input.data, ARRAY_SIZE(current_input.data)))
{
BIT256_CLEAR_ALL(current_input);
if (runloop_paused)
if (runloop_is_paused)
BIT256_SET(current_input, RARCH_PAUSE_TOGGLE);
input_driver_flushing_input = true;
}
@ -2686,7 +2691,7 @@ static enum runloop_state runloop_check_state(
if (fs_toggle_triggered)
{
bool fullscreen_toggled = !runloop_paused
bool fullscreen_toggled = !runloop_is_paused
#ifdef HAVE_MENU
|| menu_is_alive;
#else
@ -2803,120 +2808,121 @@ static enum runloop_state runloop_check_state(
#ifdef HAVE_MENU
if (menu_is_alive)
{
enum menu_action action;
static input_bits_t old_input = {{0}};
static enum menu_action old_action = MENU_ACTION_CANCEL;
static enum menu_action
old_action = MENU_ACTION_CANCEL;
bool focused = false;
input_bits_t trigger_input = current_input;
global_t *global = global_get_ptr();
menu_ctx_iterate_t iter;
retro_ctx.poll_cb();
bits_clear_bits(trigger_input.data, old_input.data,
ARRAY_SIZE(trigger_input.data));
action = (enum menu_action)menu_event(&current_input, &trigger_input);
focused = pause_nonactive ? is_focused : true;
focused = focused && !ui_companion_is_on_foreground();
iter.action = action;
if (global)
{
enum menu_action action;
bool focused = false;
input_bits_t trigger_input = current_input;
global_t *global = global_get_ptr();
bits_clear_bits(trigger_input.data, old_input.data,
ARRAY_SIZE(trigger_input.data));
action = (enum menu_action)menu_event(&current_input, &trigger_input);
focused = pause_nonactive ? is_focused : true;
focused = focused && !ui_companion_is_on_foreground();
iter.action = action;
if ( global )
if (action == old_action)
{
if ( action == old_action )
retro_time_t press_time = cpu_features_get_time_usec();
if (action == MENU_ACTION_NOOP)
global->menu.noop_press_time = press_time - global->menu.noop_start_time;
else
global->menu.action_press_time = press_time - global->menu.action_start_time;
}
else
{
if (action == MENU_ACTION_NOOP)
{
if ( action == MENU_ACTION_NOOP )
global->menu.noop_press_time = cpu_features_get_time_usec() - global->menu.noop_start_time ;
global->menu.noop_start_time = cpu_features_get_time_usec();
global->menu.noop_press_time = 0;
if (global->menu.prev_action == old_action)
global->menu.action_start_time = global->menu.prev_start_time;
else
global->menu.action_press_time = cpu_features_get_time_usec() - global->menu.action_start_time ;
global->menu.action_start_time = cpu_features_get_time_usec();
}
else
{
if ( action == MENU_ACTION_NOOP )
if (global->menu.prev_action == action &&
global->menu.noop_press_time < 200000) /* 250ms */
{
global->menu.noop_start_time = cpu_features_get_time_usec() ;
global->menu.noop_press_time = 0 ;
if ( global->menu.prev_action == old_action )
global->menu.action_start_time = global->menu.prev_start_time;
else
global->menu.action_start_time = cpu_features_get_time_usec();
global->menu.action_start_time = global->menu.prev_start_time;
global->menu.action_press_time = cpu_features_get_time_usec() - global->menu.action_start_time;
}
else
{
if ( global->menu.prev_action == action &&
global->menu.noop_press_time < 200000) /* 250ms */
{
global->menu.action_start_time = global->menu.prev_start_time ;
global->menu.action_press_time = cpu_features_get_time_usec() - global->menu.action_start_time;
}
else
{
global->menu.prev_start_time = cpu_features_get_time_usec() ;
global->menu.prev_action = action;
global->menu.action_press_time = 0;
}
global->menu.prev_start_time = cpu_features_get_time_usec();
global->menu.prev_action = action;
global->menu.action_press_time = 0;
}
}
}
}
if (!menu_driver_iterate(&iter))
rarch_menu_running_finished();
if (!menu_driver_iterate(&iter))
rarch_menu_running_finished();
if (focused || !runloop_idle)
{
bool libretro_running = menu_display_libretro_running(
rarch_is_inited,
(current_core_type == CORE_TYPE_DUMMY));
if (focused || !runloop_idle)
{
bool libretro_running = menu_display_libretro_running(
rarch_is_initialized,
(current_core_type == CORE_TYPE_DUMMY));
menu_driver_render(runloop_idle, rarch_is_inited,
(current_core_type == CORE_TYPE_DUMMY)
)
;
if (settings->bools.audio_enable_menu &&
!libretro_running)
audio_driver_menu_sample();
menu_driver_render(runloop_idle, rarch_is_initialized,
(current_core_type == CORE_TYPE_DUMMY)
)
;
if (settings->bools.audio_enable_menu &&
!libretro_running)
audio_driver_menu_sample();
#ifdef HAVE_EASTEREGG
{
bool library_name_is_empty = string_is_empty(runloop_system.info.library_name);
if (library_name_is_empty && trigger_input.data[0])
{
if (string_is_empty(runloop_system.info.library_name) && trigger_input.data[0])
seq |= trigger_input.data[0] & 0xF0;
if (seq == 1157460427127406720ULL)
{
seq |= trigger_input.data[0] & 0xF0;
content_ctx_info_t content_info;
content_info.argc = 0;
content_info.argv = NULL;
content_info.args = NULL;
content_info.environ_get = NULL;
if (seq == 1157460427127406720ULL)
{
content_ctx_info_t content_info;
content_info.argc = 0;
content_info.argv = NULL;
content_info.args = NULL;
content_info.environ_get = NULL;
task_push_start_builtin_core(
&content_info,
CORE_TYPE_GONG, NULL, NULL);
}
seq <<= 8;
task_push_start_builtin_core(
&content_info,
CORE_TYPE_GONG, NULL, NULL);
}
else if (!string_is_empty(runloop_system.info.library_name))
seq = 0;
seq <<= 8;
}
#endif
else if (!library_name_is_empty)
seq = 0;
}
old_input = current_input;
old_action = action;
if (!focused)
return RUNLOOP_STATE_POLLED_AND_SLEEP;
if (action == MENU_ACTION_QUIT && !menu_driver_binding_state)
return RUNLOOP_STATE_QUIT;
#endif
}
old_input = current_input;
old_action = action;
if (!focused)
return RUNLOOP_STATE_POLLED_AND_SLEEP;
if (action == MENU_ACTION_QUIT && !menu_driver_binding_state)
return RUNLOOP_STATE_QUIT;
if (runloop_idle)
return RUNLOOP_STATE_POLLED_AND_SLEEP;
}
@ -2949,9 +2955,7 @@ static enum runloop_state runloop_check_state(
current_input, RARCH_UI_COMPANION_TOGGLE);
if (pressed && !old_pressed)
{
command_event(CMD_EVENT_UI_COMPANION_TOGGLE, (void*)(intptr_t)0);
}
old_pressed = pressed;
}
@ -2969,7 +2973,8 @@ static enum runloop_state runloop_check_state(
{
if (menu_driver_is_alive())
{
if (rarch_is_inited && (current_core_type != CORE_TYPE_DUMMY))
if (rarch_is_initialized &&
(current_core_type != CORE_TYPE_DUMMY))
{
rarch_menu_running_finished();
menu_event_kb_set(false, RETROK_F1);
@ -2982,7 +2987,8 @@ static enum runloop_state runloop_check_state(
{
if (menu_driver_is_alive())
{
if (rarch_is_inited && (current_core_type != CORE_TYPE_DUMMY))
if (rarch_is_initialized &&
(current_core_type != CORE_TYPE_DUMMY))
rarch_menu_running_finished();
}
else
@ -2999,7 +3005,7 @@ static enum runloop_state runloop_check_state(
if (menu_driver_is_alive())
{
if (!settings->bools.menu_throttle_framerate && !settings->floats.fastforward_ratio)
if (!settings->bools.menu_throttle_framerate && !fastforward_ratio)
return RUNLOOP_STATE_MENU_ITERATE;
return RUNLOOP_STATE_END;
@ -3135,7 +3141,7 @@ static enum runloop_state runloop_check_state(
* unpause the libretro core. */
/* FRAMEADVANCE will set us into pause mode. */
pause_pressed |= !runloop_paused && trig_frameadvance;
pause_pressed |= !runloop_is_paused && trig_frameadvance;
if (focused && pause_pressed && !old_pause_pressed)
command_event(CMD_EVENT_PAUSE_TOGGLE, NULL);
@ -3148,7 +3154,7 @@ static enum runloop_state runloop_check_state(
old_pause_pressed = pause_pressed;
old_frameadvance = frameadvance_pressed;
if (runloop_paused)
if (runloop_is_paused)
{
check_is_oneshot = trig_frameadvance ||
BIT256_GET(current_input, RARCH_REWIND);
@ -3186,7 +3192,7 @@ static enum runloop_state runloop_check_state(
if (input_nonblock_state)
{
input_driver_unset_nonblock_state();
runloop_fastmotion = false;
runloop_fastmotion = false;
fastforward_after_frames = 1;
}
else
@ -3206,7 +3212,7 @@ static enum runloop_state runloop_check_state(
else
{
input_driver_unset_nonblock_state();
runloop_fastmotion = false;
runloop_fastmotion = false;
fastforward_after_frames = 1;
}
driver_set_nonblock_state();
@ -3235,7 +3241,8 @@ static enum runloop_state runloop_check_state(
* for this frame. */
if (should_slot_increase && !old_should_slot_increase)
{
int new_state_slot = settings->ints.state_slot + 1;
int cur_state_slot = settings->ints.state_slot;
int new_state_slot = cur_state_slot + 1;
configuration_set_int(settings, settings->ints.state_slot, new_state_slot);
@ -3243,9 +3250,10 @@ static enum runloop_state runloop_check_state(
}
else if (should_slot_decrease && !old_should_slot_decrease)
{
int new_state_slot = settings->ints.state_slot - 1;
int cur_state_slot = settings->ints.state_slot;
int new_state_slot = cur_state_slot - 1;
if (settings->ints.state_slot > 0)
if (cur_state_slot > 0)
configuration_set_int(settings, settings->ints.state_slot, new_state_slot);
should_set = true;
@ -3307,7 +3315,7 @@ static enum runloop_state runloop_check_state(
s[0] = '\0';
if (state_manager_check_rewind(BIT256_GET(current_input, RARCH_REWIND),
settings->uints.rewind_granularity, runloop_paused, s, sizeof(s), &t))
settings->uints.rewind_granularity, runloop_is_paused, s, sizeof(s), &t))
runloop_msg_queue_push(s, 0, t, true);
}
@ -3324,12 +3332,12 @@ static enum runloop_state runloop_check_state(
current_input, RARCH_SLOWMOTION_HOLD_KEY);
if (new_slowmotion_button_state && !old_slowmotion_button_state)
{
if (runloop_slowmotion)
runloop_slowmotion = false;
else
runloop_slowmotion = true;
}
{
if (runloop_slowmotion)
runloop_slowmotion = false;
else
runloop_slowmotion = true;
}
else if (old_slowmotion_hold_button_state != new_slowmotion_hold_button_state)
{
if (new_slowmotion_hold_button_state)
@ -3533,8 +3541,12 @@ void runloop_unset(enum runloop_action action)
int runloop_iterate(unsigned *sleep_ms)
{
unsigned i;
bool runloop_is_paused = runloop_paused;
bool input_nonblock_state = input_driver_is_nonblock_state();
settings_t *settings = config_get_ptr();
float fastforward_ratio = settings->floats.fastforward_ratio;
unsigned video_frame_delay = settings->uints.video_frame_delay;
bool vrr_runloop_enable = settings->bools.vrr_runloop_enable;
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
#ifdef HAVE_DISCORD
@ -3546,23 +3558,25 @@ int runloop_iterate(unsigned *sleep_ms)
{
/* Updates frame timing if frame timing callback is in use by the core.
* Limits frame time if fast forward ratio throttle is enabled. */
retro_time_t current = cpu_features_get_time_usec();
retro_time_t delta = current - runloop_frame_time_last;
bool is_locked_fps = (runloop_paused ||
input_nonblock_state) |
!!recording_data;
if (!runloop_frame_time_last || is_locked_fps)
delta = runloop_frame_time.reference;
if (!is_locked_fps && runloop_slowmotion)
delta /= settings->floats.slowmotion_ratio;
runloop_frame_time_last = current;
retro_usec_t runloop_last_frame_time = runloop_frame_time_last;
retro_time_t current = cpu_features_get_time_usec();
bool is_locked_fps = (runloop_is_paused || input_nonblock_state)
| !!recording_data;
retro_time_t delta = (!runloop_last_frame_time || is_locked_fps) ?
runloop_frame_time.reference
: (current - runloop_last_frame_time);
if (is_locked_fps)
runloop_frame_time_last = 0;
else
{
float slowmotion_ratio = settings->floats.slowmotion_ratio;
runloop_frame_time_last = current;
if (runloop_slowmotion)
delta /= slowmotion_ratio;
}
runloop_frame_time.callback(delta);
}
@ -3571,6 +3585,8 @@ int runloop_iterate(unsigned *sleep_ms)
runloop_check_state(
settings,
input_nonblock_state,
runloop_is_paused,
fastforward_ratio,
sleep_ms))
{
case RUNLOOP_STATE_QUIT:
@ -3617,26 +3633,31 @@ int runloop_iterate(unsigned *sleep_ms)
input_push_analog_dpad(auto_binds, dpad_mode);
}
if ((settings->uints.video_frame_delay > 0) && !input_nonblock_state)
retro_sleep(settings->uints.video_frame_delay);
if ((video_frame_delay > 0) && !input_nonblock_state)
retro_sleep(video_frame_delay);
#ifdef HAVE_RUNAHEAD
/* Run Ahead Feature replaces the call to core_run in this loop */
if (settings->bools.run_ahead_enabled && settings->uints.run_ahead_frames > 0
{
unsigned run_ahead_num_frames = settings->uints.run_ahead_frames;
/* Run Ahead Feature replaces the call to core_run in this loop */
if (settings->bools.run_ahead_enabled && run_ahead_num_frames > 0
#ifdef HAVE_NETWORKING
&& !netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)
&& !netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)
#endif
)
run_ahead(settings->uints.run_ahead_frames, settings->bools.run_ahead_secondary_instance);
else
)
run_ahead(run_ahead_num_frames, settings->bools.run_ahead_secondary_instance);
else
core_run();
}
#else
core_run();
#endif
core_run();
#ifdef HAVE_CHEEVOS
if (runloop_check_cheevos())
cheevos_test();
#endif
cheat_manager_apply_retro_cheats() ;
cheat_manager_apply_retro_cheats();
#ifdef HAVE_DISCORD
if (discord_is_inited)
@ -3667,12 +3688,12 @@ int runloop_iterate(unsigned *sleep_ms)
autosave_unlock();
/* Condition for max speed x0.0 when vrr_runloop is off to skip that part */
if (settings->floats.fastforward_ratio || settings->bools.vrr_runloop_enable)
if (fastforward_ratio || vrr_runloop_enable)
end:
{
retro_time_t to_sleep_ms;
if (settings->bools.vrr_runloop_enable)
if (vrr_runloop_enable)
{
struct retro_system_av_info *av_info =
video_viewport_get_system_av_info();
@ -3693,12 +3714,12 @@ int runloop_iterate(unsigned *sleep_ms)
}
/* Fast Forward for max speed x0.0 */
if (!settings->floats.fastforward_ratio && runloop_fastmotion)
if (!fastforward_ratio && runloop_fastmotion)
return 0;
frame_limit_minimum_time =
(retro_time_t)roundf(1000000.0f / (av_info->timing.fps *
(runloop_fastmotion ? settings->floats.fastforward_ratio : 1.0f)));
(runloop_fastmotion ? fastforward_ratio : 1.0f)));
}
to_sleep_ms = (
@ -3707,7 +3728,7 @@ int runloop_iterate(unsigned *sleep_ms)
if (to_sleep_ms > 0)
{
*sleep_ms = (unsigned)to_sleep_ms;
*sleep_ms = (unsigned)to_sleep_ms;
/* Combat jitter a bit. */
frame_limit_last_time += frame_limit_minimum_time;
return 1;