From aafc02968240b47803ba1fb81a7e9d474356c4c2 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 29 Nov 2024 19:55:49 +1000 Subject: [PATCH] Misc: Un-namespace Timer --- src/common/file_system.cpp | 2 +- src/common/log.cpp | 5 +- src/common/timer.cpp | 4 - src/common/timer.h | 4 - src/core/achievements.cpp | 8 +- src/core/cdrom_async_reader.cpp | 6 +- src/core/fullscreen_ui.cpp | 5 +- src/core/game_database.cpp | 4 +- src/core/game_list.cpp | 2 +- src/core/gpu_backend.cpp | 8 +- src/core/gpu_dump.cpp | 2 +- src/core/gpu_hw.cpp | 18 +-- src/core/gpu_hw_texture_cache.cpp | 2 +- src/core/host_interface_progress_callback.h | 2 +- src/core/performance_counters.cpp | 20 +-- src/core/system.cpp | 128 ++++++++++---------- src/duckstation-qt/coverdownloaddialog.h | 2 +- src/duckstation-qt/gamelistrefreshthread.h | 2 +- src/duckstation-qt/qtprogresscallback.h | 2 +- src/duckstation-regtest/regtest_host.cpp | 6 +- src/util/audio_stream.cpp | 4 +- src/util/gpu_device.cpp | 10 +- src/util/http_downloader.cpp | 11 +- src/util/http_downloader_curl.cpp | 4 +- src/util/http_downloader_winhttp.cpp | 4 +- src/util/imgui_fullscreen.cpp | 29 ++--- src/util/imgui_manager.cpp | 31 +++-- src/util/input_manager.cpp | 16 +-- src/util/metal_device.mm | 4 +- src/util/postprocessing.cpp | 4 +- src/util/postprocessing.h | 4 +- src/util/postprocessing_shader_fx.h | 2 +- 32 files changed, 168 insertions(+), 187 deletions(-) diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index d195cbca4..364199b26 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -923,7 +923,7 @@ std::FILE* FileSystem::OpenExistingOrCreateCFile(const char* path, s32 retry_ms, // if there's a sharing violation, keep retrying if (file == INVALID_HANDLE_VALUE && GetLastError() == ERROR_SHARING_VIOLATION && retry_ms >= 0) { - Common::Timer timer; + Timer timer; while (retry_ms == 0 || timer.GetTimeMilliseconds() <= retry_ms) { Sleep(1); diff --git a/src/common/log.cpp b/src/common/log.cpp index 87bbfa54f..dc5e0acd3 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -81,7 +81,7 @@ struct State std::vector callbacks; std::mutex callbacks_mutex; - Common::Timer::Value start_timestamp = Common::Timer::GetCurrentValue(); + Timer::Value start_timestamp = Timer::GetCurrentValue(); FileSystem::ManagedCFilePtr file_handle; @@ -146,8 +146,7 @@ const std::array(Log::Channel::MaxCount)>& Log: float Log::GetCurrentMessageTime() { - return static_cast( - Common::Timer::ConvertValueToSeconds(Common::Timer::GetCurrentValue() - s_state.start_timestamp)); + return static_cast(Timer::ConvertValueToSeconds(Timer::GetCurrentValue() - s_state.start_timestamp)); } bool Log::AreTimestampsEnabled() diff --git a/src/common/timer.cpp b/src/common/timer.cpp index 6b74097d8..38939389f 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -15,8 +15,6 @@ #include #endif -namespace Common { - #ifdef _WIN32 static double s_counter_frequency; @@ -399,5 +397,3 @@ void Timer::NanoSleep(std::uint64_t ns) nanosleep(&ts, nullptr); #endif } - -} // namespace Common diff --git a/src/common/timer.h b/src/common/timer.h index 33db85db8..11958966b 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -4,8 +4,6 @@ #pragma once #include -namespace Common { - class Timer { public: @@ -47,5 +45,3 @@ public: private: Value m_tvStartValue; }; - -} // namespace Common \ No newline at end of file diff --git a/src/core/achievements.cpp b/src/core/achievements.cpp index 48d80212a..61e3dbe5d 100644 --- a/src/core/achievements.cpp +++ b/src/core/achievements.cpp @@ -103,7 +103,7 @@ struct LeaderboardTrackerIndicator { u32 tracker_id; std::string text; - Common::Timer show_hide_time; + Timer show_hide_time; bool active; }; @@ -111,7 +111,7 @@ struct AchievementChallengeIndicator { const rc_client_achievement_t* achievement; std::string badge_path; - Common::Timer show_hide_time; + Timer show_hide_time; bool active; }; @@ -119,7 +119,7 @@ struct AchievementProgressIndicator { const rc_client_achievement_t* achievement; std::string badge_path; - Common::Timer show_hide_time; + Timer show_hide_time; bool active; }; } // namespace @@ -219,7 +219,7 @@ static bool s_has_achievements = false; static bool s_has_leaderboards = false; static bool s_has_rich_presence = false; static std::string s_rich_presence_string; -static Common::Timer s_rich_presence_poll_time; +static Timer s_rich_presence_poll_time; static rc_client_async_handle_t* s_login_request; static rc_client_async_handle_t* s_load_game_request; diff --git a/src/core/cdrom_async_reader.cpp b/src/core/cdrom_async_reader.cpp index 7d2c21e17..3e31b4892 100644 --- a/src/core/cdrom_async_reader.cpp +++ b/src/core/cdrom_async_reader.cpp @@ -187,7 +187,7 @@ bool CDROMAsyncReader::WaitForReadToComplete() return m_buffers[m_buffer_front.load()].result; } - Common::Timer wait_timer; + Timer wait_timer; DEBUG_LOG("Sector read pending, waiting"); std::unique_lock lock(m_mutex); @@ -226,7 +226,7 @@ void CDROMAsyncReader::EmptyBuffers() bool CDROMAsyncReader::ReadSectorIntoBuffer(std::unique_lock& lock) { - Common::Timer timer; + Timer timer; const u32 slot = m_buffer_back.load(); m_buffer_back.store((slot + 1) % static_cast(m_buffers.size())); @@ -259,7 +259,7 @@ bool CDROMAsyncReader::ReadSectorIntoBuffer(std::unique_lock& lock) void CDROMAsyncReader::ReadSectorNonThreaded(CDImage::LBA lba) { - Common::Timer timer; + Timer timer; m_buffers.resize(1); m_seek_error.store(false); diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 6b3c97e2c..2bc52997f 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -422,7 +422,7 @@ static std::string s_input_binding_key; static std::string s_input_binding_display_name; static std::vector s_input_binding_new_bindings; static std::vector>> s_input_binding_value_ranges; -static Common::Timer s_input_binding_timer; +static Timer s_input_binding_timer; static bool s_controller_macro_expanded[NUM_CONTROLLER_AND_CARD_PORTS][InputManager::NUM_MACRO_BUTTONS_PER_CONTROLLER] = {}; @@ -4323,7 +4323,8 @@ void FullscreenUI::DrawGraphicsSettingsPage() DrawEnumSetting(bsi, FSUI_ICONSTR(ICON_FA_CROP_ALT, "Crop Mode"), FSUI_CSTR("Determines how much of the area typically not visible on a consumer TV set to crop/hide."), "Display", "CropMode", Settings::DEFAULT_DISPLAY_CROP_MODE, &Settings::ParseDisplayCropMode, - &Settings::GetDisplayCropModeName, &Settings::GetDisplayCropModeDisplayName, DisplayCropMode::MaxCount); + &Settings::GetDisplayCropModeName, &Settings::GetDisplayCropModeDisplayName, + DisplayCropMode::MaxCount); DrawEnumSetting( bsi, FSUI_ICONSTR(ICON_FA_EXPAND, "Scaling"), diff --git a/src/core/game_database.cpp b/src/core/game_database.cpp index 6d81b5da9..1b10aed67 100644 --- a/src/core/game_database.cpp +++ b/src/core/game_database.cpp @@ -163,7 +163,7 @@ void GameDatabase::EnsureLoaded() if (s_loaded) return; - Common::Timer timer; + Timer timer; s_loaded = true; @@ -1417,7 +1417,7 @@ void GameDatabase::EnsureTrackHashesMapLoaded() bool GameDatabase::LoadTrackHashes() { - Common::Timer load_timer; + Timer load_timer; Error error; std::optional gamedb_data(Host::ReadResourceFileToString(DISCDB_YAML_FILENAME, false, &error)); diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index bf7f93877..8894a7d9a 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -1690,7 +1690,7 @@ FileSystem::ManagedCFilePtr GameList::OpenMemoryCardTimestampCache(bool for_writ if (errno != EACCES) return nullptr; - Common::Timer timer; + Timer timer; while (timer.GetTimeMilliseconds() <= 100.0f) { fp = FileSystem::OpenManagedSharedCFile(filename.c_str(), mode, share_mode, nullptr); diff --git a/src/core/gpu_backend.cpp b/src/core/gpu_backend.cpp index a8b17818a..b24c3f6b0 100644 --- a/src/core/gpu_backend.cpp +++ b/src/core/gpu_backend.cpp @@ -217,7 +217,7 @@ void GPUBackend::Sync(bool allow_sleep) void GPUBackend::RunGPULoop() { static constexpr double SPIN_TIME_NS = 1 * 1000000; - Common::Timer::Value last_command_time = 0; + Timer::Value last_command_time = 0; for (;;) { @@ -225,8 +225,8 @@ void GPUBackend::RunGPULoop() u32 read_ptr = m_command_fifo_read_ptr.load(); if (read_ptr == write_ptr) { - const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); - if (Common::Timer::ConvertValueToNanoseconds(current_time - last_command_time) < SPIN_TIME_NS) + const Timer::Value current_time = Timer::GetCurrentValue(); + if (Timer::ConvertValueToNanoseconds(current_time - last_command_time) < SPIN_TIME_NS) continue; std::unique_lock lock(m_sync_mutex); @@ -273,7 +273,7 @@ void GPUBackend::RunGPULoop() } } - last_command_time = allow_sleep ? 0 : Common::Timer::GetCurrentValue(); + last_command_time = allow_sleep ? 0 : Timer::GetCurrentValue(); m_command_fifo_read_ptr.store(read_ptr); } } diff --git a/src/core/gpu_dump.cpp b/src/core/gpu_dump.cpp index 3d8a93cf7..216b232f5 100644 --- a/src/core/gpu_dump.cpp +++ b/src/core/gpu_dump.cpp @@ -320,7 +320,7 @@ std::unique_ptr GPUDump::Player::Open(std::string path, Error* { std::unique_ptr ret; - Common::Timer timer; + Timer timer; std::optional> data; if (StringUtil::EndsWithNoCase(path, ".psxgpu.zst") || StringUtil::EndsWithNoCase(path, ".psxgpu.xz")) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 8540f4328..7abdf31f4 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -152,8 +152,8 @@ class ShaderCompileProgressTracker { public: ShaderCompileProgressTracker(std::string title, u32 total) - : m_title(std::move(title)), m_min_time(Common::Timer::ConvertSecondsToValue(1.0)), - m_update_interval(Common::Timer::ConvertSecondsToValue(0.1)), m_start_time(Common::Timer::GetCurrentValue()), + : m_title(std::move(title)), m_min_time(Timer::ConvertSecondsToValue(1.0)), + m_update_interval(Timer::ConvertSecondsToValue(0.1)), m_start_time(Timer::GetCurrentValue()), m_last_update_time(0), m_progress(0), m_total(total) { } @@ -161,14 +161,14 @@ public: double GetElapsedMilliseconds() const { - return Common::Timer::ConvertValueToMilliseconds(Common::Timer::GetCurrentValue() - m_start_time); + return Timer::ConvertValueToMilliseconds(Timer::GetCurrentValue() - m_start_time); } void Increment(u32 progress = 1) { m_progress += progress; - const u64 tv = Common::Timer::GetCurrentValue(); + const u64 tv = Timer::GetCurrentValue(); if ((tv - m_start_time) >= m_min_time && (tv - m_last_update_time) >= m_update_interval) { Host::DisplayLoadingScreen(m_title.c_str(), 0, static_cast(m_total), static_cast(m_progress)); @@ -178,10 +178,10 @@ public: private: std::string m_title; - Common::Timer::Value m_min_time; - Common::Timer::Value m_update_interval; - Common::Timer::Value m_start_time; - Common::Timer::Value m_last_update_time; + Timer::Value m_min_time; + Timer::Value m_update_interval; + Timer::Value m_start_time; + Timer::Value m_last_update_time; u32 m_progress; u32 m_total; }; @@ -1612,7 +1612,7 @@ bool GPU_HW::CompilePipelines(Error* error) bool GPU_HW::CompileResolutionDependentPipelines(Error* error) { - Common::Timer timer; + Timer timer; m_vram_readback_pipeline.reset(); for (std::unique_ptr& p : m_vram_extract_pipeline) diff --git a/src/core/gpu_hw_texture_cache.cpp b/src/core/gpu_hw_texture_cache.cpp index 5c2484914..bf0bca50d 100644 --- a/src/core/gpu_hw_texture_cache.cpp +++ b/src/core/gpu_hw_texture_cache.cpp @@ -3100,7 +3100,7 @@ void GPUTextureCache::PreloadReplacementTextures() { static constexpr float UPDATE_INTERVAL = 1.0f; - Common::Timer last_update_time; + Timer last_update_time; u32 num_textures_loaded = 0; const size_t total_textures = s_state.vram_replacements.size() + s_state.vram_write_texture_replacements.size() + s_state.texture_page_texture_replacements.size(); diff --git a/src/core/host_interface_progress_callback.h b/src/core/host_interface_progress_callback.h index 3af69e7fd..b46ac13d3 100644 --- a/src/core/host_interface_progress_callback.h +++ b/src/core/host_interface_progress_callback.h @@ -28,7 +28,7 @@ public: private: void Redraw(bool force); - Common::Timer m_open_time; + Timer m_open_time; float m_open_delay = 1.0f; int m_last_progress_percent = -1; }; diff --git a/src/core/performance_counters.cpp b/src/core/performance_counters.cpp index 5a6ad2a20..14a93fc95 100644 --- a/src/core/performance_counters.cpp +++ b/src/core/performance_counters.cpp @@ -22,8 +22,8 @@ namespace { struct State { - Common::Timer::Value last_update_time; - Common::Timer::Value last_frame_time; + Timer::Value last_update_time; + Timer::Value last_frame_time; u32 last_frame_number; u32 last_internal_frame_number; @@ -142,7 +142,7 @@ void PerformanceCounters::Clear() void PerformanceCounters::Reset() { - const Common::Timer::Value now_ticks = Common::Timer::GetCurrentValue(); + const Timer::Value now_ticks = Timer::GetCurrentValue(); s_state.last_frame_time = now_ticks; s_state.last_update_time = now_ticks; @@ -162,10 +162,10 @@ void PerformanceCounters::Reset() void PerformanceCounters::Update(u32 frame_number, u32 internal_frame_number) { - const Common::Timer::Value now_ticks = Common::Timer::GetCurrentValue(); + const Timer::Value now_ticks = Timer::GetCurrentValue(); const float frame_time = static_cast( - Common::Timer::ConvertValueToMilliseconds(now_ticks - std::exchange(s_state.last_frame_time, now_ticks))); + Timer::ConvertValueToMilliseconds(now_ticks - std::exchange(s_state.last_frame_time, now_ticks))); s_state.minimum_frame_time_accumulator = (s_state.minimum_frame_time_accumulator == 0.0f) ? frame_time : std::min(s_state.minimum_frame_time_accumulator, frame_time); @@ -175,8 +175,8 @@ void PerformanceCounters::Update(u32 frame_number, u32 internal_frame_number) s_state.frame_time_history_pos = (s_state.frame_time_history_pos + 1) % NUM_FRAME_TIME_SAMPLES; // update fps counter - const Common::Timer::Value ticks_diff = now_ticks - s_state.last_update_time; - const float time = static_cast(Common::Timer::ConvertValueToSeconds(ticks_diff)); + const Timer::Value ticks_diff = now_ticks - s_state.last_update_time; + const float time = static_cast(Timer::ConvertValueToSeconds(ticks_diff)); if (time < PERFORMANCE_COUNTER_UPDATE_INTERVAL) return; @@ -190,7 +190,7 @@ void PerformanceCounters::Update(u32 frame_number, u32 internal_frame_number) // TODO: Make the math here less rubbish const double pct_divider = 100.0 * (1.0 / ((static_cast(ticks_diff) * static_cast(Threading::GetThreadTicksPerSecond())) / - Common::Timer::GetFrequency() / 1000000000.0)); + Timer::GetFrequency() / 1000000000.0)); const double time_divider = 1000.0 * (1.0 / static_cast(Threading::GetThreadTicksPerSecond())) * (1.0 / static_cast(frames_runf)); @@ -230,8 +230,8 @@ void PerformanceCounters::Update(u32 frame_number, u32 internal_frame_number) if (g_settings.display_show_gpu_stats) g_gpu->UpdateStatistics(frames_run); - VERBOSE_LOG("FPS: {:.2f} VPS: {:.2f} CPU: {:.2f} GPU: {:.2f} Avg: {:.2f}ms Min: {:.2f}ms Max: {:.2f}ms", - s_state.fps, s_state.vps, s_state.cpu_thread_usage, s_state.gpu_usage, s_state.average_frame_time, + VERBOSE_LOG("FPS: {:.2f} VPS: {:.2f} CPU: {:.2f} GPU: {:.2f} Avg: {:.2f}ms Min: {:.2f}ms Max: {:.2f}ms", s_state.fps, + s_state.vps, s_state.cpu_thread_usage, s_state.gpu_usage, s_state.average_frame_time, s_state.minimum_frame_time, s_state.maximum_frame_time); Host::OnPerformanceCountersUpdated(); diff --git a/src/core/system.cpp b/src/core/system.cpp index 4b425f1c8..df399ce76 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -181,8 +181,8 @@ static void UpdateThrottlePeriod(); static void ResetThrottler(); /// Throttles the system, i.e. sleeps until it's time to execute the next frame. -static void Throttle(Common::Timer::Value current_time); -static void AccumulatePreFrameSleepTime(Common::Timer::Value current_time); +static void Throttle(Timer::Value current_time); +static void AccumulatePreFrameSleepTime(Timer::Value current_time); static void UpdateDisplayVSync(); static bool UpdateGameSettingsLayer(); @@ -270,14 +270,14 @@ struct ALIGN_TO_CACHE_LINE StateVars float video_frame_rate = 0.0f; float target_speed = 0.0f; - Common::Timer::Value frame_period = 0; - Common::Timer::Value next_frame_time = 0; + Timer::Value frame_period = 0; + Timer::Value next_frame_time = 0; - Common::Timer::Value frame_start_time = 0; - Common::Timer::Value last_active_frame_time = 0; - Common::Timer::Value pre_frame_sleep_time = 0; - Common::Timer::Value max_active_frame_time = 0; - Common::Timer::Value last_pre_frame_sleep_update_time = 0; + Timer::Value frame_start_time = 0; + Timer::Value last_active_frame_time = 0; + Timer::Value pre_frame_sleep_time = 0; + Timer::Value max_active_frame_time = 0; + Timer::Value last_pre_frame_sleep_update_time = 0; std::unique_ptr media_capture; std::unique_ptr gpu_dump_player; @@ -468,7 +468,7 @@ void System::LogStartupInformation() bool System::ProcessStartup(Error* error) { - Common::Timer timer; + Timer timer; // Allocate JIT memory as soon as possible. if (!CPU::CodeCache::ProcessStartup(error)) @@ -1243,15 +1243,15 @@ bool System::RecreateGPU(GPURenderer renderer, bool force_recreate_device, bool void System::HandleHostGPUDeviceLost() { - static Common::Timer::Value s_last_gpu_reset_time = 0; + static Timer::Value s_last_gpu_reset_time = 0; static constexpr float MIN_TIME_BETWEEN_RESETS = 15.0f; // If we're constantly crashing on something in particular, we don't want to end up in an // endless reset loop.. that'd probably end up leaking memory and/or crashing us for other // reasons. So just abort in such case. - const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); + const Timer::Value current_time = Timer::GetCurrentValue(); if (s_last_gpu_reset_time != 0 && - Common::Timer::ConvertValueToSeconds(current_time - s_last_gpu_reset_time) < MIN_TIME_BETWEEN_RESETS) + Timer::ConvertValueToSeconds(current_time - s_last_gpu_reset_time) < MIN_TIME_BETWEEN_RESETS) { Panic("Host GPU lost too many times, device is probably completely wedged."); } @@ -2197,10 +2197,10 @@ void System::FrameDone() } } - Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); + Timer::Value current_time = Timer::GetCurrentValue(); // pre-frame sleep accounting (input lag reduction) - const Common::Timer::Value pre_frame_sleep_until = s_state.next_frame_time + s_state.pre_frame_sleep_time; + const Timer::Value pre_frame_sleep_until = s_state.next_frame_time + s_state.pre_frame_sleep_time; s_state.last_active_frame_time = current_time - s_state.frame_start_time; if (s_state.pre_frame_sleep) AccumulatePreFrameSleepTime(current_time); @@ -2255,15 +2255,15 @@ void System::FrameDone() } // pre-frame sleep (input lag reduction) - current_time = Common::Timer::GetCurrentValue(); + current_time = Timer::GetCurrentValue(); if (s_state.pre_frame_sleep) { // don't sleep if it's under 1ms, because we're just going to overshoot (or spin). if (pre_frame_sleep_until > current_time && - Common::Timer::ConvertValueToMilliseconds(pre_frame_sleep_until - current_time) >= 1) + Timer::ConvertValueToMilliseconds(pre_frame_sleep_until - current_time) >= 1) { - Common::Timer::SleepUntil(pre_frame_sleep_until, true); - current_time = Common::Timer::GetCurrentValue(); + Timer::SleepUntil(pre_frame_sleep_until, true); + current_time = Timer::GetCurrentValue(); } } @@ -2306,7 +2306,7 @@ void System::UpdateThrottlePeriod() const double target_speed = std::max(static_cast(s_state.target_speed), std::numeric_limits::epsilon()); s_state.frame_period = - Common::Timer::ConvertSecondsToValue(1.0 / (static_cast(s_state.video_frame_rate) * target_speed)); + Timer::ConvertSecondsToValue(1.0 / (static_cast(s_state.video_frame_rate) * target_speed)); } else { @@ -2318,18 +2318,18 @@ void System::UpdateThrottlePeriod() void System::ResetThrottler() { - s_state.next_frame_time = Common::Timer::GetCurrentValue() + s_state.frame_period; + s_state.next_frame_time = Timer::GetCurrentValue() + s_state.frame_period; s_state.pre_frame_sleep_time = 0; } -void System::Throttle(Common::Timer::Value current_time) +void System::Throttle(Timer::Value current_time) { // If we're running too slow, advance the next frame time based on the time we lost. Effectively skips // running those frames at the intended time, because otherwise if we pause in the debugger, we'll run // hundreds of frames when we resume. if (current_time > s_state.next_frame_time) { - const Common::Timer::Value diff = static_cast(current_time) - static_cast(s_state.next_frame_time); + const Timer::Value diff = static_cast(current_time) - static_cast(s_state.next_frame_time); s_state.next_frame_time += (diff / s_state.frame_period) * s_state.frame_period + s_state.frame_period; return; } @@ -2339,13 +2339,13 @@ void System::Throttle(Common::Timer::Value current_time) // That way in a query->response->query->response chain, we don't process only one message per frame. if (s_state.socket_multiplexer && s_state.socket_multiplexer->HasAnyClientSockets()) { - Common::Timer::Value poll_start_time = current_time; + Timer::Value poll_start_time = current_time; for (;;) { const u32 sleep_ms = - static_cast(Common::Timer::ConvertValueToMilliseconds(s_state.next_frame_time - poll_start_time)); + static_cast(Timer::ConvertValueToMilliseconds(s_state.next_frame_time - poll_start_time)); s_state.socket_multiplexer->PollEventsWithTimeout(sleep_ms); - poll_start_time = Common::Timer::GetCurrentValue(); + poll_start_time = Timer::GetCurrentValue(); if (poll_start_time >= s_state.next_frame_time || (!g_settings.display_optimal_frame_pacing && sleep_ms == 0)) break; } @@ -2355,25 +2355,25 @@ void System::Throttle(Common::Timer::Value current_time) // Use a spinwait if we undersleep for all platforms except android.. don't want to burn battery. // Linux also seems to do a much better job of waking up at the requested time. #if !defined(__linux__) - Common::Timer::SleepUntil(s_state.next_frame_time, g_settings.display_optimal_frame_pacing); + Timer::SleepUntil(s_state.next_frame_time, g_settings.display_optimal_frame_pacing); #else - Common::Timer::SleepUntil(s_state.next_frame_time, false); + Timer::SleepUntil(s_state.next_frame_time, false); #endif } #else // No spinwait on Android, see above. - Common::Timer::SleepUntil(s_state.next_frame_time, false); + Timer::SleepUntil(s_state.next_frame_time, false); #endif #if 0 - const Common::Timer::Value time_after_sleep = Common::Timer::GetCurrentValue(); + const Timer::Value time_after_sleep = Timer::GetCurrentValue(); DEV_LOG("Asked for {:.2f} ms, slept for {:.2f} ms, {:.2f} ms {}", - Common::Timer::ConvertValueToMilliseconds(s_next_frame_time - current_time), - Common::Timer::ConvertValueToMilliseconds(time_after_sleep - current_time), - Common::Timer::ConvertValueToMilliseconds((time_after_sleep < s_next_frame_time) ? - (s_next_frame_time - time_after_sleep) : - (time_after_sleep - s_next_frame_time)), - (time_after_sleep < s_next_frame_time) ? "early" : "late"); + Timer::ConvertValueToMilliseconds(s_state.next_frame_time - current_time), + Timer::ConvertValueToMilliseconds(time_after_sleep - current_time), + Timer::ConvertValueToMilliseconds((time_after_sleep < s_state.next_frame_time) ? + (s_state.next_frame_time - time_after_sleep) : + (time_after_sleep - s_state.next_frame_time)), + (time_after_sleep < s_state.next_frame_time) ? "early" : "late"); #endif s_state.next_frame_time += s_state.frame_period; @@ -2726,7 +2726,7 @@ bool System::LoadState(const char* path, Error* error, bool save_undo_state) return true; } - Common::Timer load_timer; + Timer load_timer; auto fp = FileSystem::OpenManagedCFile(path, "rb", error); if (!fp) @@ -3026,7 +3026,7 @@ bool System::SaveState(const char* path, Error* error, bool backup_existing_save return false; } - Common::Timer save_timer; + Timer save_timer; SaveStateBuffer buffer; if (!SaveStateToBuffer(&buffer, error, 256)) @@ -3301,38 +3301,37 @@ float System::GetAudioNominalRate() return (s_state.throttler_enabled || s_state.syncing_to_host_with_vsync) ? s_state.target_speed : 1.0f; } -void System::AccumulatePreFrameSleepTime(Common::Timer::Value current_time) +void System::AccumulatePreFrameSleepTime(Timer::Value current_time) { DebugAssert(s_state.pre_frame_sleep); s_state.max_active_frame_time = std::max(s_state.max_active_frame_time, s_state.last_active_frame_time); // in case one frame runs over, adjust to compensate - const Common::Timer::Value max_sleep_time_for_this_frame = + const Timer::Value max_sleep_time_for_this_frame = s_state.frame_period - std::min(s_state.last_active_frame_time, s_state.frame_period); if (max_sleep_time_for_this_frame < s_state.pre_frame_sleep_time) { - s_state.pre_frame_sleep_time = Common::AlignDown( - max_sleep_time_for_this_frame, static_cast(Common::Timer::ConvertMillisecondsToValue(1))); + s_state.pre_frame_sleep_time = + Common::AlignDown(max_sleep_time_for_this_frame, static_cast(Timer::ConvertMillisecondsToValue(1))); DEV_LOG("Adjust pre-frame time to {} ms due to overrun of {} ms", - Common::Timer::ConvertValueToMilliseconds(s_state.pre_frame_sleep_time), - Common::Timer::ConvertValueToMilliseconds(s_state.last_active_frame_time)); + Timer::ConvertValueToMilliseconds(s_state.pre_frame_sleep_time), + Timer::ConvertValueToMilliseconds(s_state.last_active_frame_time)); } - if (Common::Timer::ConvertValueToSeconds(current_time - s_state.last_pre_frame_sleep_update_time) >= + if (Timer::ConvertValueToSeconds(current_time - s_state.last_pre_frame_sleep_update_time) >= PRE_FRAME_SLEEP_UPDATE_INTERVAL) { s_state.last_pre_frame_sleep_update_time = current_time; - const Common::Timer::Value expected_frame_time = - s_state.max_active_frame_time + - Common::Timer::ConvertMillisecondsToValue(g_settings.display_pre_frame_sleep_buffer); + const Timer::Value expected_frame_time = + s_state.max_active_frame_time + Timer::ConvertMillisecondsToValue(g_settings.display_pre_frame_sleep_buffer); s_state.pre_frame_sleep_time = Common::AlignDown(s_state.frame_period - std::min(expected_frame_time, s_state.frame_period), - static_cast(Common::Timer::ConvertMillisecondsToValue(1))); + static_cast(Timer::ConvertMillisecondsToValue(1))); DEV_LOG("Set pre-frame time to {} ms (expected frame time of {} ms)", - Common::Timer::ConvertValueToMilliseconds(s_state.pre_frame_sleep_time), - Common::Timer::ConvertValueToMilliseconds(expected_frame_time)); + Timer::ConvertValueToMilliseconds(s_state.pre_frame_sleep_time), + Timer::ConvertValueToMilliseconds(expected_frame_time)); s_state.max_active_frame_time = 0; } @@ -3344,12 +3343,11 @@ void System::FormatLatencyStats(SmallStringBase& str) const u32 audio_latency = AudioStream::GetMSForBufferSize(audio_stream->GetSampleRate(), audio_stream->GetBufferedFramesRelaxed()); - const double active_frame_time = std::ceil(Common::Timer::ConvertValueToMilliseconds(s_state.last_active_frame_time)); - const double pre_frame_time = std::ceil(Common::Timer::ConvertValueToMilliseconds(s_state.pre_frame_sleep_time)); - const double input_latency = - std::ceil(Common::Timer::ConvertValueToMilliseconds(s_state.frame_period - s_state.pre_frame_sleep_time) - - Common::Timer::ConvertValueToMilliseconds(static_cast(s_state.runahead_frames) * - s_state.frame_period)); + const double active_frame_time = std::ceil(Timer::ConvertValueToMilliseconds(s_state.last_active_frame_time)); + const double pre_frame_time = std::ceil(Timer::ConvertValueToMilliseconds(s_state.pre_frame_sleep_time)); + const double input_latency = std::ceil( + Timer::ConvertValueToMilliseconds(s_state.frame_period - s_state.pre_frame_sleep_time) - + Timer::ConvertValueToMilliseconds(static_cast(s_state.runahead_frames) * s_state.frame_period)); str.format("AF: {:.0f}ms | PF: {:.0f}ms | IL: {:.0f}ms | AL: {}ms", active_frame_time, pre_frame_time, input_latency, audio_latency); @@ -4859,7 +4857,7 @@ bool System::SaveMemoryState(MemorySaveState* mss) bool System::SaveRewindState() { #ifdef PROFILE_MEMORY_SAVE_STATES - Common::Timer save_timer; + Timer save_timer; #endif // try to reuse the frontmost slot @@ -4897,7 +4895,7 @@ bool System::LoadRewindState(u32 skip_saves /*= 0*/, bool consume_state /*=true return false; #ifdef PROFILE_MEMORY_SAVE_STATES - Common::Timer load_timer; + Timer load_timer; #endif if (!LoadMemoryState(s_state.rewind_states.back())) @@ -4961,7 +4959,7 @@ void System::DoRewind() Host::PumpMessagesOnCPUThread(); IdlePollUpdate(); - Throttle(Common::Timer::GetCurrentValue()); + Throttle(Timer::GetCurrentValue()); } void System::SaveRunaheadState() @@ -4986,7 +4984,7 @@ void System::SaveRunaheadState() bool System::DoRunahead() { #ifdef PROFILE_MEMORY_SAVE_STATES - static Common::Timer replay_timer; + static Timer replay_timer; #endif if (s_state.runahead_replay_pending) @@ -5839,12 +5837,12 @@ bool System::ChangeGPUDump(std::string new_path) void System::UpdateSessionTime(const std::string& prev_serial) { - const u64 ctime = Common::Timer::GetCurrentValue(); + const Timer::Value ctime = Timer::GetCurrentValue(); if (!prev_serial.empty() && GameList::IsGameListLoaded()) { // round up to seconds const std::time_t etime = - static_cast(std::round(Common::Timer::ConvertValueToSeconds(ctime - s_state.session_start_time))); + static_cast(std::round(Timer::ConvertValueToSeconds(ctime - s_state.session_start_time))); const std::time_t wtime = std::time(nullptr); GameList::AddPlayedTimeForSerial(prev_serial, wtime, etime); } @@ -5854,8 +5852,8 @@ void System::UpdateSessionTime(const std::string& prev_serial) u64 System::GetSessionPlayedTime() { - const u64 ctime = Common::Timer::GetCurrentValue(); - return static_cast(std::round(Common::Timer::ConvertValueToSeconds(ctime - s_state.session_start_time))); + const Timer::Value ctime = Timer::GetCurrentValue(); + return static_cast(std::round(Timer::ConvertValueToSeconds(ctime - s_state.session_start_time))); } void System::QueueTaskOnThread(std::function task) diff --git a/src/duckstation-qt/coverdownloaddialog.h b/src/duckstation-qt/coverdownloaddialog.h index 2174287bd..ff1ebbe13 100644 --- a/src/duckstation-qt/coverdownloaddialog.h +++ b/src/duckstation-qt/coverdownloaddialog.h @@ -53,5 +53,5 @@ private: Ui::CoverDownloadDialog m_ui; std::unique_ptr m_thread; - Common::Timer m_last_refresh_time; + Timer m_last_refresh_time; }; diff --git a/src/duckstation-qt/gamelistrefreshthread.h b/src/duckstation-qt/gamelistrefreshthread.h index 5fb61a41f..9c148ad67 100644 --- a/src/duckstation-qt/gamelistrefreshthread.h +++ b/src/duckstation-qt/gamelistrefreshthread.h @@ -35,7 +35,7 @@ private: void fireUpdate(); GameListRefreshThread* m_parent; - Common::Timer m_start_time; + Timer m_start_time; QString m_status_text; int m_last_range = 1; int m_last_value = 0; diff --git a/src/duckstation-qt/qtprogresscallback.h b/src/duckstation-qt/qtprogresscallback.h index f7215881a..69058bc70 100644 --- a/src/duckstation-qt/qtprogresscallback.h +++ b/src/duckstation-qt/qtprogresscallback.h @@ -42,7 +42,7 @@ private: void checkForDelayedShow(); QProgressDialog m_dialog; - Common::Timer m_show_timer; + Timer m_show_timer; float m_show_delay; }; diff --git a/src/duckstation-regtest/regtest_host.cpp b/src/duckstation-regtest/regtest_host.cpp index 12a245e41..0a6731acd 100644 --- a/src/duckstation-regtest/regtest_host.cpp +++ b/src/duckstation-regtest/regtest_host.cpp @@ -788,12 +788,12 @@ int main(int argc, char* argv[]) s_frames_remaining = s_frames_to_run; { - const Common::Timer::Value start_time = Common::Timer::GetCurrentValue(); + const Timer::Value start_time = Timer::GetCurrentValue(); System::Execute(); - const Common::Timer::Value elapsed_time = Common::Timer::GetCurrentValue() - start_time; - const double elapsed_time_ms = Common::Timer::ConvertValueToMilliseconds(elapsed_time); + const Timer::Value elapsed_time = Timer::GetCurrentValue() - start_time; + const double elapsed_time_ms = Timer::ConvertValueToMilliseconds(elapsed_time); INFO_LOG("Total execution time: {:.2f}ms, average frame time {:.2f}ms, {:.2f} FPS", elapsed_time_ms, elapsed_time_ms / static_cast(s_frames_to_run), static_cast(s_frames_to_run) / elapsed_time_ms * 1000.0); diff --git a/src/util/audio_stream.cpp b/src/util/audio_stream.cpp index 31ce20236..bd4ebc51d 100644 --- a/src/util/audio_stream.cpp +++ b/src/util/audio_stream.cpp @@ -788,9 +788,9 @@ void AudioStream::UpdateStretchTempo() static int iterations = 0; static u64 last_log_time = 0; - const u64 now = Common::Timer::GetCurrentValue(); + const u64 now = Timer::GetCurrentValue(); - if (Common::Timer::ConvertValueToSeconds(now - last_log_time) > 1.0f) + if (Timer::ConvertValueToSeconds(now - last_log_time) > 1.0f) { VERBOSE_LOG("buffers: {:4d} ms ({:3.0f}%), tempo: {}, comp: {:2.3f}, iters: {}, reset:{}", (ibuffer_usage * 1000u) / m_sample_rate, 100.0f * buffer_usage / base_target_usage, tempo, diff --git a/src/util/gpu_device.cpp b/src/util/gpu_device.cpp index bd7acad9e..de710f6e3 100644 --- a/src/util/gpu_device.cpp +++ b/src/util/gpu_device.cpp @@ -242,8 +242,8 @@ bool GPUSwapChain::ShouldSkipPresentingFrame() const float throttle_rate = (m_window_info.surface_refresh_rate > 0.0f) ? m_window_info.surface_refresh_rate : 60.0f; const float throttle_period = 1.0f / throttle_rate; - const u64 now = Common::Timer::GetCurrentValue(); - const double diff = Common::Timer::ConvertValueToSeconds(now - m_last_frame_displayed_time); + const u64 now = Timer::GetCurrentValue(); + const double diff = Timer::ConvertValueToSeconds(now - m_last_frame_displayed_time); if (diff < throttle_period) return true; @@ -255,8 +255,8 @@ void GPUSwapChain::ThrottlePresentation() { const float throttle_rate = (m_window_info.surface_refresh_rate > 0.0f) ? m_window_info.surface_refresh_rate : 60.0f; - const u64 sleep_period = Common::Timer::ConvertNanosecondsToValue(1e+9f / static_cast(throttle_rate)); - const u64 current_ts = Common::Timer::GetCurrentValue(); + const u64 sleep_period = Timer::ConvertNanosecondsToValue(1e+9f / static_cast(throttle_rate)); + const u64 current_ts = Timer::GetCurrentValue(); // Allow it to fall behind/run ahead up to 2*period. Sleep isn't that precise, plus we need to // allow time for the actual rendering. @@ -266,7 +266,7 @@ void GPUSwapChain::ThrottlePresentation() else m_last_frame_displayed_time += sleep_period; - Common::Timer::SleepUntil(m_last_frame_displayed_time, false); + Timer::SleepUntil(m_last_frame_displayed_time, false); } GPUDevice::GPUDevice() diff --git a/src/util/http_downloader.cpp b/src/util/http_downloader.cpp index 11ef826b9..8a97eb8a2 100644 --- a/src/util/http_downloader.cpp +++ b/src/util/http_downloader.cpp @@ -43,7 +43,7 @@ void HTTPDownloader::CreateRequest(std::string url, Request::Callback callback, req->url = std::move(url); req->callback = std::move(callback); req->progress = progress; - req->start_time = Common::Timer::GetCurrentValue(); + req->start_time = Timer::GetCurrentValue(); std::unique_lock lock(m_pending_http_request_lock); if (LockedGetActiveRequestCount() < m_max_active_requests) @@ -65,7 +65,7 @@ void HTTPDownloader::CreatePostRequest(std::string url, std::string post_data, R req->post_data = std::move(post_data); req->callback = std::move(callback); req->progress = progress; - req->start_time = Common::Timer::GetCurrentValue(); + req->start_time = Timer::GetCurrentValue(); std::unique_lock lock(m_pending_http_request_lock); if (LockedGetActiveRequestCount() < m_max_active_requests) @@ -84,7 +84,7 @@ void HTTPDownloader::LockedPollRequests(std::unique_lock& lock) InternalPollRequests(); - const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); + const Timer::Value current_time = Timer::GetCurrentValue(); u32 active_requests = 0; u32 unstarted_requests = 0; @@ -99,8 +99,7 @@ void HTTPDownloader::LockedPollRequests(std::unique_lock& lock) } if ((req->state == Request::State::Started || req->state == Request::State::Receiving) && - current_time >= req->start_time && - Common::Timer::ConvertValueToSeconds(current_time - req->start_time) >= m_timeout) + current_time >= req->start_time && Timer::ConvertValueToSeconds(current_time - req->start_time) >= m_timeout) { // request timed out ERROR_LOG("Request for '{}' timed out", req->url); @@ -207,7 +206,7 @@ void HTTPDownloader::WaitForAllRequests() while (!m_pending_http_requests.empty()) { // Don't burn too much CPU. - Common::Timer::NanoSleep(1000000); + Timer::NanoSleep(1000000); LockedPollRequests(lock); } } diff --git a/src/util/http_downloader_curl.cpp b/src/util/http_downloader_curl.cpp index cece67103..4cf11a912 100644 --- a/src/util/http_downloader_curl.cpp +++ b/src/util/http_downloader_curl.cpp @@ -105,7 +105,7 @@ size_t HTTPDownloaderCurl::WriteCallback(char* ptr, size_t size, size_t nmemb, v const size_t transfer_size = size * nmemb; const size_t new_size = current_size + transfer_size; req->data.resize(new_size); - req->start_time = Common::Timer::GetCurrentValue(); + req->start_time = Timer::GetCurrentValue(); std::memcpy(&req->data[current_size], ptr, transfer_size); if (req->content_length == 0) @@ -211,7 +211,7 @@ bool HTTPDownloaderCurl::StartRequest(HTTPDownloader::Request* request) DEV_LOG("Started HTTP request for '{}'", req->url); req->state.store(Request::State::Started, std::memory_order_release); - req->start_time = Common::Timer::GetCurrentValue(); + req->start_time = Timer::GetCurrentValue(); const CURLMcode err = curl_multi_add_handle(m_multi_handle, req->handle); if (err != CURLM_OK) diff --git a/src/util/http_downloader_winhttp.cpp b/src/util/http_downloader_winhttp.cpp index e0b7fdc58..6c0c46bb6 100644 --- a/src/util/http_downloader_winhttp.cpp +++ b/src/util/http_downloader_winhttp.cpp @@ -237,7 +237,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR const u32 new_size = req->io_position + dwStatusInformationLength; Assert(new_size <= req->data.size()); req->data.resize(new_size); - req->start_time = Common::Timer::GetCurrentValue(); + req->start_time = Timer::GetCurrentValue(); if (!WinHttpQueryDataAvailable(hRequest, nullptr) && GetLastError() != ERROR_IO_PENDING) { @@ -345,7 +345,7 @@ bool HTTPDownloaderWinHttp::StartRequest(HTTPDownloader::Request* request) DEV_LOG("Started HTTP request for '{}'", req->url); req->state = Request::State::Started; - req->start_time = Common::Timer::GetCurrentValue(); + req->start_time = Timer::GetCurrentValue(); return true; } diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index 39b3705ef..90a24a127 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -175,8 +175,8 @@ struct Notification std::string title; std::string text; std::string badge_path; - Common::Timer::Value start_time; - Common::Timer::Value move_time; + Timer::Value start_time; + Timer::Value move_time; float duration; float target_y; float last_y; @@ -187,7 +187,7 @@ static std::vector s_notifications; static std::string s_toast_title; static std::string s_toast_message; -static Common::Timer::Value s_toast_start_time; +static Timer::Value s_toast_start_time; static float s_toast_duration; namespace { @@ -357,7 +357,8 @@ std::optional ImGuiFullscreen::LoadTextureImage(std::string_view path, u3 std::shared_ptr ImGuiFullscreen::UploadTexture(std::string_view path, const Image& image) { Error error; - std::unique_ptr texture = g_gpu_device->FetchAndUploadTextureImage(image, GPUTexture::Flags::None, &error); + std::unique_ptr texture = + g_gpu_device->FetchAndUploadTextureImage(image, GPUTexture::Flags::None, &error); if (!texture) { ERROR_LOG("Failed to upload texture '{}': {}", Path::GetFileTitle(path), error.GetDescription()); @@ -2937,7 +2938,7 @@ void ImGuiFullscreen::DrawBackgroundProgressDialogs(ImVec2& position, float spac void ImGuiFullscreen::AddNotification(std::string key, float duration, std::string title, std::string text, std::string image_path) { - const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); + const Timer::Value current_time = Timer::GetCurrentValue(); if (!key.empty()) { @@ -2951,10 +2952,8 @@ void ImGuiFullscreen::AddNotification(std::string key, float duration, std::stri it->badge_path = std::move(image_path); // Don't fade it in again - const float time_passed = - static_cast(Common::Timer::ConvertValueToSeconds(current_time - it->start_time)); - it->start_time = - current_time - Common::Timer::ConvertSecondsToValue(std::min(time_passed, NOTIFICATION_FADE_IN_TIME)); + const float time_passed = static_cast(Timer::ConvertValueToSeconds(current_time - it->start_time)); + it->start_time = current_time - Timer::ConvertSecondsToValue(std::min(time_passed, NOTIFICATION_FADE_IN_TIME)); return; } } @@ -2984,7 +2983,7 @@ void ImGuiFullscreen::DrawNotifications(ImVec2& position, float spacing) return; static constexpr float MOVE_DURATION = 0.5f; - const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); + const Timer::Value current_time = Timer::GetCurrentValue(); const float horizontal_padding = ImGuiFullscreen::LayoutScale(20.0f); const float vertical_padding = ImGuiFullscreen::LayoutScale(10.0f); @@ -3009,7 +3008,7 @@ void ImGuiFullscreen::DrawNotifications(ImVec2& position, float spacing) for (u32 index = 0; index < static_cast(s_notifications.size());) { Notification& notif = s_notifications[index]; - const float time_passed = static_cast(Common::Timer::ConvertValueToSeconds(current_time - notif.start_time)); + const float time_passed = static_cast(Timer::ConvertValueToSeconds(current_time - notif.start_time)); if (time_passed >= notif.duration) { s_notifications.erase(s_notifications.begin() + index); @@ -3047,8 +3046,7 @@ void ImGuiFullscreen::DrawNotifications(ImVec2& position, float spacing) } else if (actual_y != expected_y) { - const float time_since_move = - static_cast(Common::Timer::ConvertValueToSeconds(current_time - notif.move_time)); + const float time_since_move = static_cast(Timer::ConvertValueToSeconds(current_time - notif.move_time)); if (time_since_move >= MOVE_DURATION) { notif.move_time = current_time; @@ -3108,7 +3106,7 @@ void ImGuiFullscreen::ShowToast(std::string title, std::string message, float du { s_toast_title = std::move(title); s_toast_message = std::move(message); - s_toast_start_time = Common::Timer::GetCurrentValue(); + s_toast_start_time = Timer::GetCurrentValue(); s_toast_duration = duration; } @@ -3125,8 +3123,7 @@ void ImGuiFullscreen::DrawToast() if (s_toast_title.empty() && s_toast_message.empty()) return; - const float elapsed = - static_cast(Common::Timer::ConvertValueToSeconds(Common::Timer::GetCurrentValue() - s_toast_start_time)); + const float elapsed = static_cast(Timer::ConvertValueToSeconds(Timer::GetCurrentValue() - s_toast_start_time)); if (elapsed >= s_toast_duration) { ClearToast(); diff --git a/src/util/imgui_manager.cpp b/src/util/imgui_manager.cpp index 9a68bf6c2..3a7e32272 100644 --- a/src/util/imgui_manager.cpp +++ b/src/util/imgui_manager.cpp @@ -54,8 +54,8 @@ struct OSDMessage { std::string key; std::string text; - Common::Timer::Value start_time; - Common::Timer::Value move_time; + Timer::Value start_time; + Timer::Value move_time; float duration; float target_y; float last_y; @@ -82,8 +82,8 @@ static void SetClipboardTextImpl(void* userdata, const char* text); static void AddOSDMessage(std::string key, std::string message, float duration, bool is_warning); static void RemoveKeyedOSDMessage(std::string key, bool is_warning); static void ClearOSDMessages(bool clear_warnings); -static void AcquirePendingOSDMessages(Common::Timer::Value current_time); -static void DrawOSDMessages(Common::Timer::Value current_time); +static void AcquirePendingOSDMessages(Timer::Value current_time); +static void DrawOSDMessages(Timer::Value current_time); static void CreateSoftwareCursorTextures(); static void UpdateSoftwareCursorTexture(u32 index); static void DestroySoftwareCursorTextures(); @@ -114,7 +114,7 @@ static DynamicHeapArray s_emoji_font_data; static float s_window_width; static float s_window_height; -static Common::Timer s_last_render_time; +static Timer s_last_render_time; // cached copies of WantCaptureKeyboard/Mouse, used to know when to dispatch events static std::atomic_bool s_imgui_wants_keyboard{false}; @@ -781,7 +781,7 @@ void ImGuiManager::AddOSDMessage(std::string key, std::string message, float dur if (!s_show_osd_messages && !is_warning) return; - const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); + const Timer::Value current_time = Timer::GetCurrentValue(); OSDMessage msg; msg.key = std::move(key); @@ -847,7 +847,7 @@ void ImGuiManager::ClearOSDMessages(bool clear_warnings) } } -void ImGuiManager::AcquirePendingOSDMessages(Common::Timer::Value current_time) +void ImGuiManager::AcquirePendingOSDMessages(Timer::Value current_time) { std::atomic_thread_fence(std::memory_order_consume); if (s_osd_posted_messages.empty()) @@ -870,9 +870,8 @@ void ImGuiManager::AcquirePendingOSDMessages(Common::Timer::Value current_time) iter->duration = new_msg.duration; // Don't fade it in again - const float time_passed = - static_cast(Common::Timer::ConvertValueToSeconds(current_time - iter->start_time)); - iter->start_time = current_time - Common::Timer::ConvertSecondsToValue(std::min(time_passed, OSD_FADE_IN_TIME)); + const float time_passed = static_cast(Timer::ConvertValueToSeconds(current_time - iter->start_time)); + iter->start_time = current_time - Timer::ConvertSecondsToValue(std::min(time_passed, OSD_FADE_IN_TIME)); } else { @@ -887,7 +886,7 @@ void ImGuiManager::AcquirePendingOSDMessages(Common::Timer::Value current_time) } } -void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time) +void ImGuiManager::DrawOSDMessages(Timer::Value current_time) { static constexpr float MOVE_DURATION = 0.5f; @@ -905,7 +904,7 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time) while (iter != s_osd_active_messages.end()) { OSDMessage& msg = *iter; - const float time_passed = static_cast(Common::Timer::ConvertValueToSeconds(current_time - msg.start_time)); + const float time_passed = static_cast(Timer::ConvertValueToSeconds(current_time - msg.start_time)); if (time_passed >= msg.duration) { iter = s_osd_active_messages.erase(iter); @@ -934,8 +933,7 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time) else { // We got repositioned, probably due to another message above getting removed. - const float time_since_move = - static_cast(Common::Timer::ConvertValueToSeconds(current_time - msg.move_time)); + const float time_since_move = static_cast(Timer::ConvertValueToSeconds(current_time - msg.move_time)); const float frac = Easing::OutExpo(time_since_move / MOVE_DURATION); msg.last_y = std::floor(msg.last_y - ((msg.last_y - msg.target_y) * frac)); } @@ -946,8 +944,7 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time) } else if (actual_y != expected_y) { - const float time_since_move = - static_cast(Common::Timer::ConvertValueToSeconds(current_time - msg.move_time)); + const float time_since_move = static_cast(Timer::ConvertValueToSeconds(current_time - msg.move_time)); if (time_since_move >= MOVE_DURATION) { msg.move_time = current_time; @@ -981,7 +978,7 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time) void ImGuiManager::RenderOSDMessages() { - const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); + const Timer::Value current_time = Timer::GetCurrentValue(); AcquirePendingOSDMessages(current_time); DrawOSDMessages(current_time); } diff --git a/src/util/input_manager.cpp b/src/util/input_manager.cpp index e088a899a..8253e50ae 100644 --- a/src/util/input_manager.cpp +++ b/src/util/input_manager.cpp @@ -66,7 +66,7 @@ struct PadVibrationBinding struct Motor { InputBindingKey binding; - u64 last_update_time; + Timer::Value last_update_time; InputSource* source; float last_intensity; }; @@ -1607,14 +1607,14 @@ void InputManager::SetPadVibrationIntensity(u32 pad_index, float large_or_single const float report_intensity = std::max(large_or_single_motor_intensity, small_motor_intensity); if (large_motor.source) { - large_motor.last_update_time = Common::Timer::GetCurrentValue(); + large_motor.last_update_time = Timer::GetCurrentValue(); large_motor.source->UpdateMotorState(large_motor.binding, report_intensity); } } else if (large_motor.source == small_motor.source) { // both motors are bound to the same source, do an optimal update - large_motor.last_update_time = Common::Timer::GetCurrentValue(); + large_motor.last_update_time = Timer::GetCurrentValue(); large_motor.source->UpdateMotorState(large_motor.binding, small_motor.binding, large_or_single_motor_intensity, small_motor_intensity); } @@ -1623,12 +1623,12 @@ void InputManager::SetPadVibrationIntensity(u32 pad_index, float large_or_single // update motors independently if (large_motor.source && large_motor.last_intensity != large_or_single_motor_intensity) { - large_motor.last_update_time = Common::Timer::GetCurrentValue(); + large_motor.last_update_time = Timer::GetCurrentValue(); large_motor.source->UpdateMotorState(large_motor.binding, large_or_single_motor_intensity); } if (small_motor.source && small_motor.last_intensity != small_motor_intensity) { - small_motor.last_update_time = Common::Timer::GetCurrentValue(); + small_motor.last_update_time = Timer::GetCurrentValue(); small_motor.source->UpdateMotorState(small_motor.binding, small_motor_intensity); } } @@ -1658,7 +1658,7 @@ void InputManager::PauseVibration() void InputManager::UpdateContinuedVibration() { // update vibration intensities, so if the game does a long effect, it continues - const u64 current_time = Common::Timer::GetCurrentValue(); + const u64 current_time = Timer::GetCurrentValue(); for (PadVibrationBinding& pad : s_pad_vibration_array) { if (pad.AreMotorsCombined()) @@ -1669,7 +1669,7 @@ void InputManager::UpdateContinuedVibration() continue; // so only check the first one - const double dt = Common::Timer::ConvertValueToSeconds(current_time - large_motor.last_update_time); + const double dt = Timer::ConvertValueToSeconds(current_time - large_motor.last_update_time); if (dt < VIBRATION_UPDATE_INTERVAL_SECONDS) continue; @@ -1690,7 +1690,7 @@ void InputManager::UpdateContinuedVibration() if (!motor.source || motor.last_intensity == 0.0f) continue; - const double dt = Common::Timer::ConvertValueToSeconds(current_time - motor.last_update_time); + const double dt = Timer::ConvertValueToSeconds(current_time - motor.last_update_time); if (dt < VIBRATION_UPDATE_INTERVAL_SECONDS) continue; diff --git a/src/util/metal_device.mm b/src/util/metal_device.mm index afbc19776..343469013 100644 --- a/src/util/metal_device.mm +++ b/src/util/metal_device.mm @@ -2593,8 +2593,8 @@ void MetalDevice::EndPresent(GPUSwapChain* swap_chain, bool explicit_present, u6 DebugAssert(m_num_current_render_targets == 0 && !m_current_depth_target); EndAnyEncoding(); - Common::Timer::Value current_time; - if (present_time != 0 && (current_time = Common::Timer::GetCurrentValue()) < present_time) + Timer::Value current_time; + if (present_time != 0 && (current_time = Timer::GetCurrentValue()) < present_time) { // Need to convert to mach absolute time. Time values should already be in nanoseconds. const u64 mach_time_nanoseconds = CocoaTools::ConvertMachTimeBaseToNanoseconds(mach_absolute_time()); diff --git a/src/util/postprocessing.cpp b/src/util/postprocessing.cpp index 02f208fc4..030a77f40 100644 --- a/src/util/postprocessing.cpp +++ b/src/util/postprocessing.cpp @@ -53,7 +53,7 @@ ALWAYS_INLINE void ForAllChains(const T& F) Chain DisplayChain(Config::DISPLAY_CHAIN_SECTION); Chain InternalChain(Config::INTERNAL_CHAIN_SECTION); -static Common::Timer s_timer; +static Timer s_timer; static std::unordered_map> s_samplers; static std::unique_ptr s_dummy_texture; @@ -782,7 +782,7 @@ SettingsInterface& PostProcessing::GetLoadSettingsInterface(const char* section) return *Host::Internal::GetBaseSettingsLayer(); } -const Common::Timer& PostProcessing::GetTimer() +const Timer& PostProcessing::GetTimer() { return s_timer; } diff --git a/src/util/postprocessing.h b/src/util/postprocessing.h index c3d9c18fa..11c9d9444 100644 --- a/src/util/postprocessing.h +++ b/src/util/postprocessing.h @@ -11,9 +11,7 @@ #include #include -namespace Common { class Timer; -} class GPUSampler; class GPUTexture; @@ -171,7 +169,7 @@ void Shutdown(); GPUSampler* GetSampler(const GPUSampler::Config& config); GPUTexture* GetDummyTexture(); -const Common::Timer& GetTimer(); +const Timer& GetTimer(); extern Chain DisplayChain; extern Chain InternalChain; diff --git a/src/util/postprocessing_shader_fx.h b/src/util/postprocessing_shader_fx.h index f966c7210..ecc2c09d2 100644 --- a/src/util/postprocessing_shader_fx.h +++ b/src/util/postprocessing_shader_fx.h @@ -144,7 +144,7 @@ private: bool m_valid = false; bool m_wants_depth_buffer = false; - Common::Timer m_frame_timer; + Timer m_frame_timer; u32 m_frame_count = 0; // Specifically using a fixed seed, so that it's consistent from run-to-run.