diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2016-09-18 02:38:01 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2016-09-18 02:38:01 +0200 |
commit | dc8479928c5aee4c6ad6fe4f59006fb604cee701 (patch) | |
tree | 569a7f13128450bbab973236615587ff00bced5f /src/common/timer.cpp | |
parent | Travis: Import Dolphin’s clang-format hook. (diff) | |
download | yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.gz yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.bz2 yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.lz yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.xz yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.zst yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/timer.cpp | 73 |
1 files changed, 29 insertions, 44 deletions
diff --git a/src/common/timer.cpp b/src/common/timer.cpp index b99835ac7..27560eb0b 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -16,11 +16,9 @@ #include "common/string_util.h" #include "common/timer.h" -namespace Common -{ +namespace Common { -u32 Timer::GetTimeMs() -{ +u32 Timer::GetTimeMs() { #ifdef _WIN32 return timeGetTime(); #else @@ -35,32 +33,27 @@ u32 Timer::GetTimeMs() // -------------------------------------------- // Set initial values for the class -Timer::Timer() - : m_LastTime(0), m_StartTime(0), m_Running(false) -{ +Timer::Timer() : m_LastTime(0), m_StartTime(0), m_Running(false) { Update(); } // Write the starting time -void Timer::Start() -{ +void Timer::Start() { m_StartTime = GetTimeMs(); m_Running = true; } // Stop the timer -void Timer::Stop() -{ +void Timer::Stop() { // Write the final time m_LastTime = GetTimeMs(); m_Running = false; } // Update the last time variable -void Timer::Update() -{ +void Timer::Update() { m_LastTime = GetTimeMs(); - //TODO(ector) - QPF + // TODO(ector) - QPF } // ------------------------------------- @@ -68,34 +61,32 @@ void Timer::Update() // ------------------------------------- // Get the number of milliseconds since the last Update() -u64 Timer::GetTimeDifference() -{ +u64 Timer::GetTimeDifference() { return GetTimeMs() - m_LastTime; } // Add the time difference since the last Update() to the starting time. // This is used to compensate for a paused game. -void Timer::AddTimeDifference() -{ +void Timer::AddTimeDifference() { m_StartTime += GetTimeDifference(); } // Get the time elapsed since the Start() -u64 Timer::GetTimeElapsed() -{ +u64 Timer::GetTimeElapsed() { // If we have not started yet, return 1 (because then I don't // have to change the FPS calculation in CoreRerecording.cpp . - if (m_StartTime == 0) return 1; + if (m_StartTime == 0) + return 1; // Return the final timer time if the timer is stopped - if (!m_Running) return (m_LastTime - m_StartTime); + if (!m_Running) + return (m_LastTime - m_StartTime); return (GetTimeMs() - m_StartTime); } // Get the formatted time elapsed since the Start() -std::string Timer::GetTimeElapsedFormatted() const -{ +std::string Timer::GetTimeElapsedFormatted() const { // If we have not started yet, return zero if (m_StartTime == 0) return "00:00:00:000"; @@ -114,50 +105,46 @@ std::string Timer::GetTimeElapsedFormatted() const // Hours u32 Hours = Minutes / 60; - std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i", - Hours, Minutes % 60, Seconds % 60, Milliseconds % 1000); + std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i", Hours, Minutes % 60, Seconds % 60, + Milliseconds % 1000); return TmpStr; } // Get current time -void Timer::IncreaseResolution() -{ +void Timer::IncreaseResolution() { #ifdef _WIN32 timeBeginPeriod(1); #endif } -void Timer::RestoreResolution() -{ +void Timer::RestoreResolution() { #ifdef _WIN32 timeEndPeriod(1); #endif } // Get the number of seconds since January 1 1970 -u64 Timer::GetTimeSinceJan1970() -{ +u64 Timer::GetTimeSinceJan1970() { time_t ltime; time(<ime); - return((u64)ltime); + return ((u64)ltime); } -u64 Timer::GetLocalTimeSinceJan1970() -{ +u64 Timer::GetLocalTimeSinceJan1970() { time_t sysTime, tzDiff, tzDST; - struct tm * gmTime; + struct tm* gmTime; time(&sysTime); // Account for DST where needed gmTime = localtime(&sysTime); - if(gmTime->tm_isdst == 1) + if (gmTime->tm_isdst == 1) tzDST = 3600; else tzDST = 0; // Lazy way to get local time in sec - gmTime = gmtime(&sysTime); + gmTime = gmtime(&sysTime); tzDiff = sysTime - mktime(gmTime); return (u64)(sysTime + tzDiff + tzDST); @@ -165,10 +152,9 @@ u64 Timer::GetLocalTimeSinceJan1970() // Return the current time formatted as Minutes:Seconds:Milliseconds // in the form 00:00:000. -std::string Timer::GetTimeFormatted() -{ +std::string Timer::GetTimeFormatted() { time_t sysTime; - struct tm * gmTime; + struct tm* gmTime; char tmp[13]; time(&sysTime); @@ -176,7 +162,7 @@ std::string Timer::GetTimeFormatted() strftime(tmp, 6, "%M:%S", gmTime); - // Now tack on the milliseconds +// Now tack on the milliseconds #ifdef _WIN32 struct timeb tp; (void)::ftime(&tp); @@ -190,8 +176,7 @@ std::string Timer::GetTimeFormatted() // Returns a timestamp with decimals for precise time comparisons // ---------------- -double Timer::GetDoubleTime() -{ +double Timer::GetDoubleTime() { #ifdef _WIN32 struct timeb tp; (void)::ftime(&tp); |