diff --git a/src/core/system.cpp b/src/core/system.cpp index 7c67fe52b..91b02325d 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -930,7 +930,7 @@ void System::PauseSystem(bool paused) else { Host::OnSystemResumed(); - g_host_display->SetVSync(ShouldUseVSync()); + UpdateDisplaySync(); ResetPerformanceCounters(); ResetThrottler(); } @@ -1249,6 +1249,7 @@ bool System::Initialize(bool force_software_renderer) s_frame_number = 1; s_internal_frame_number = 1; + s_target_speed = g_settings.emulation_speed; s_throttle_frequency = 60.0f; s_frame_period = 0; s_next_frame_time = 0; @@ -2064,30 +2065,7 @@ void System::ResetThrottler() void System::Throttle() { - // Allow variance of up to 40ms either way. -#ifndef __ANDROID__ - static constexpr double MAX_VARIANCE_TIME_NS = 40 * 1000000; -#else - static constexpr double MAX_VARIANCE_TIME_NS = 50 * 1000000; -#endif - - // Use unsigned for defined overflow/wrap-around. - const Common::Timer::Value time = Common::Timer::GetCurrentValue(); - const double sleep_time = (s_next_frame_time >= time) ? - Common::Timer::ConvertValueToNanoseconds(s_next_frame_time - time) : - -Common::Timer::ConvertValueToNanoseconds(time - s_next_frame_time); - if (sleep_time < -MAX_VARIANCE_TIME_NS) - { - // Don't display the slow messages in debug, it'll always be slow... -#ifndef _DEBUG - Log_VerbosePrintf("System too slow, lost %.2f ms", (-sleep_time - MAX_VARIANCE_TIME_NS) / 1000000.0); -#endif - ResetThrottler(); - } - else - { - Common::Timer::SleepUntil(s_next_frame_time, true); - } + Common::Timer::SleepUntil(s_next_frame_time, true); } void System::RunFrames() @@ -2210,12 +2188,7 @@ void System::UpdateSpeedLimiterState() } } - const bool video_sync_enabled = ShouldUseVSync(); - const float max_display_fps = (!IsRunning() || m_throttler_enabled) ? 0.0f : g_settings.display_max_fps; - Log_InfoPrintf("Target speed: %f%%", target_speed * 100.0f); - Log_InfoPrintf("Using vsync: %s", video_sync_enabled ? "YES" : "NO"); - Log_InfoPrintf("Max display fps: %f (%s)", max_display_fps, - m_display_all_frames ? "displaying all frames" : "skipping displaying frames when needed"); + Log_VerbosePrintf("Target speed: %f%%", s_target_speed * 100.0f); if (IsValid()) { @@ -2235,23 +2208,36 @@ void System::UpdateSpeedLimiterState() ResetThrottler(); } - g_host_display->SetDisplayMaxFPS(max_display_fps); - g_host_display->SetVSync(video_sync_enabled); + // Defer vsync update until we unpause, in case of fullscreen UI. + if (IsRunning()) + UpdateDisplaySync(); if (g_settings.increase_timer_resolution) SetTimerResolutionIncreased(m_throttler_enabled); // When syncing to host and using vsync, we don't need to sleep. - if (syncing_to_host && video_sync_enabled && m_display_all_frames) + if (syncing_to_host && ShouldUseVSync() && m_display_all_frames) { Log_InfoPrintf("Using host vsync for throttling."); m_throttler_enabled = false; } } +void System::UpdateDisplaySync() +{ + const bool video_sync_enabled = ShouldUseVSync(); + const float max_display_fps = m_throttler_enabled ? 0.0f : g_settings.display_max_fps; + Log_VerbosePrintf("Using vsync: %s", video_sync_enabled ? "YES" : "NO"); + Log_VerbosePrintf("Max display fps: %f (%s)", max_display_fps, + m_display_all_frames ? "displaying all frames" : "skipping displaying frames when needed"); + + g_host_display->SetDisplayMaxFPS(max_display_fps); + g_host_display->SetVSync(video_sync_enabled); +} + bool System::ShouldUseVSync() { - return (!IsRunning() || (m_throttler_enabled && g_settings.video_sync_enabled && !IsRunningAtNonStandardSpeed())); + return g_settings.video_sync_enabled && !IsRunningAtNonStandardSpeed(); } bool System::IsFastForwardEnabled() diff --git a/src/core/system.h b/src/core/system.h index b32cc8ff5..0b4f522ab 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -230,6 +230,9 @@ void Throttle(); void UpdatePerformanceCounters(); void ResetPerformanceCounters(); +/// Resets vsync/max present fps state. +void UpdateDisplaySync(); + // Access controllers for simulating input. Controller* GetController(u32 slot); void UpdateControllers();