From 09089eeee0bf6022cc7681214e51546d134402ea Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sun, 17 Jul 2022 20:43:47 -0700 Subject: Common::Timer: use chrono::steady_clock internally --- Source/Core/VideoCommon/OnScreenDisplay.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoCommon/OnScreenDisplay.cpp') diff --git a/Source/Core/VideoCommon/OnScreenDisplay.cpp b/Source/Core/VideoCommon/OnScreenDisplay.cpp index 4bc7cd9494..d2c211c861 100644 --- a/Source/Core/VideoCommon/OnScreenDisplay.cpp +++ b/Source/Core/VideoCommon/OnScreenDisplay.cpp @@ -32,12 +32,12 @@ static std::atomic s_obscured_pixels_top = 0; struct Message { Message() = default; - Message(std::string text_, u32 timestamp_, u32 duration_, u32 color_) + Message(std::string text_, u64 timestamp_, u32 duration_, u32 color_) : text(std::move(text_)), timestamp(timestamp_), duration(duration_), color(color_) { } std::string text; - u32 timestamp = 0; + u64 timestamp = 0; u32 duration = 0; bool ever_drawn = false; u32 color = 0; @@ -93,20 +93,20 @@ void AddTypedMessage(MessageType type, std::string message, u32 ms, u32 argb) { std::lock_guard lock{s_messages_mutex}; s_messages.erase(type); - s_messages.emplace(type, Message(std::move(message), Common::Timer::GetTimeMs() + ms, ms, argb)); + s_messages.emplace(type, Message(std::move(message), Common::Timer::NowMs() + ms, ms, argb)); } void AddMessage(std::string message, u32 ms, u32 argb) { std::lock_guard lock{s_messages_mutex}; s_messages.emplace(MessageType::Typeless, - Message(std::move(message), Common::Timer::GetTimeMs() + ms, ms, argb)); + Message(std::move(message), Common::Timer::NowMs() + ms, ms, argb)); } void DrawMessages() { const bool draw_messages = Config::Get(Config::MAIN_OSD_MESSAGES); - const u32 now = Common::Timer::GetTimeMs(); + const u64 now = Common::Timer::NowMs(); const float current_x = LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x + s_obscured_pixels_left; float current_y = TOP_MARGIN * ImGui::GetIO().DisplayFramebufferScale.y + s_obscured_pixels_top; -- cgit v1.2.3 From fec61f89a3bce9bf857a15ed4789629624e66584 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Mon, 18 Jul 2022 11:48:20 -0700 Subject: Timer: protect usages of ms timers from rollover --- Source/Core/VideoCommon/OnScreenDisplay.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Source/Core/VideoCommon/OnScreenDisplay.cpp') diff --git a/Source/Core/VideoCommon/OnScreenDisplay.cpp b/Source/Core/VideoCommon/OnScreenDisplay.cpp index d2c211c861..e860c53ec0 100644 --- a/Source/Core/VideoCommon/OnScreenDisplay.cpp +++ b/Source/Core/VideoCommon/OnScreenDisplay.cpp @@ -32,12 +32,14 @@ static std::atomic s_obscured_pixels_top = 0; struct Message { Message() = default; - Message(std::string text_, u64 timestamp_, u32 duration_, u32 color_) - : text(std::move(text_)), timestamp(timestamp_), duration(duration_), color(color_) + Message(std::string text_, u32 duration_, u32 color_) + : text(std::move(text_)), duration(duration_), color(color_) { + timer.Start(); } + s64 TimeRemaining() const { return duration - timer.ElapsedMs(); } std::string text; - u64 timestamp = 0; + Common::Timer timer; u32 duration = 0; bool ever_drawn = false; u32 color = 0; @@ -93,20 +95,18 @@ void AddTypedMessage(MessageType type, std::string message, u32 ms, u32 argb) { std::lock_guard lock{s_messages_mutex}; s_messages.erase(type); - s_messages.emplace(type, Message(std::move(message), Common::Timer::NowMs() + ms, ms, argb)); + s_messages.emplace(type, Message(std::move(message), ms, argb)); } void AddMessage(std::string message, u32 ms, u32 argb) { std::lock_guard lock{s_messages_mutex}; - s_messages.emplace(MessageType::Typeless, - Message(std::move(message), Common::Timer::NowMs() + ms, ms, argb)); + s_messages.emplace(MessageType::Typeless, Message(std::move(message), ms, argb)); } void DrawMessages() { const bool draw_messages = Config::Get(Config::MAIN_OSD_MESSAGES); - const u64 now = Common::Timer::NowMs(); const float current_x = LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x + s_obscured_pixels_left; float current_y = TOP_MARGIN * ImGui::GetIO().DisplayFramebufferScale.y + s_obscured_pixels_top; @@ -117,7 +117,7 @@ void DrawMessages() for (auto it = s_messages.begin(); it != s_messages.end();) { Message& msg = it->second; - const int time_left = static_cast(msg.timestamp - now); + const s64 time_left = msg.TimeRemaining(); // Make sure we draw them at least once if they were printed with 0ms, // unless enough time has expired, in that case, we drop them -- cgit v1.2.3