diff options
| author | 2016-09-18 09:38:01 +0900 | |
|---|---|---|
| committer | 2016-09-18 09:38:01 +0900 | |
| commit | dc8479928c5aee4c6ad6fe4f59006fb604cee701 (patch) | |
| tree | 569a7f13128450bbab973236615587ff00bced5f /src/common/timer.cpp | |
| parent | Travis: Import Dolphin’s clang-format hook. (diff) | |
| download | yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.gz yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.xz yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.zip | |
Sources: Run clang-format on everything.
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 @@ | |||
| 16 | #include "common/string_util.h" | 16 | #include "common/string_util.h" |
| 17 | #include "common/timer.h" | 17 | #include "common/timer.h" |
| 18 | 18 | ||
| 19 | namespace Common | 19 | namespace Common { |
| 20 | { | ||
| 21 | 20 | ||
| 22 | u32 Timer::GetTimeMs() | 21 | u32 Timer::GetTimeMs() { |
| 23 | { | ||
| 24 | #ifdef _WIN32 | 22 | #ifdef _WIN32 |
| 25 | return timeGetTime(); | 23 | return timeGetTime(); |
| 26 | #else | 24 | #else |
| @@ -35,32 +33,27 @@ u32 Timer::GetTimeMs() | |||
| 35 | // -------------------------------------------- | 33 | // -------------------------------------------- |
| 36 | 34 | ||
| 37 | // Set initial values for the class | 35 | // Set initial values for the class |
| 38 | Timer::Timer() | 36 | Timer::Timer() : m_LastTime(0), m_StartTime(0), m_Running(false) { |
| 39 | : m_LastTime(0), m_StartTime(0), m_Running(false) | ||
| 40 | { | ||
| 41 | Update(); | 37 | Update(); |
| 42 | } | 38 | } |
| 43 | 39 | ||
| 44 | // Write the starting time | 40 | // Write the starting time |
| 45 | void Timer::Start() | 41 | void Timer::Start() { |
| 46 | { | ||
| 47 | m_StartTime = GetTimeMs(); | 42 | m_StartTime = GetTimeMs(); |
| 48 | m_Running = true; | 43 | m_Running = true; |
| 49 | } | 44 | } |
| 50 | 45 | ||
| 51 | // Stop the timer | 46 | // Stop the timer |
| 52 | void Timer::Stop() | 47 | void Timer::Stop() { |
| 53 | { | ||
| 54 | // Write the final time | 48 | // Write the final time |
| 55 | m_LastTime = GetTimeMs(); | 49 | m_LastTime = GetTimeMs(); |
| 56 | m_Running = false; | 50 | m_Running = false; |
| 57 | } | 51 | } |
| 58 | 52 | ||
| 59 | // Update the last time variable | 53 | // Update the last time variable |
| 60 | void Timer::Update() | 54 | void Timer::Update() { |
| 61 | { | ||
| 62 | m_LastTime = GetTimeMs(); | 55 | m_LastTime = GetTimeMs(); |
| 63 | //TODO(ector) - QPF | 56 | // TODO(ector) - QPF |
| 64 | } | 57 | } |
| 65 | 58 | ||
| 66 | // ------------------------------------- | 59 | // ------------------------------------- |
| @@ -68,34 +61,32 @@ void Timer::Update() | |||
| 68 | // ------------------------------------- | 61 | // ------------------------------------- |
| 69 | 62 | ||
| 70 | // Get the number of milliseconds since the last Update() | 63 | // Get the number of milliseconds since the last Update() |
| 71 | u64 Timer::GetTimeDifference() | 64 | u64 Timer::GetTimeDifference() { |
| 72 | { | ||
| 73 | return GetTimeMs() - m_LastTime; | 65 | return GetTimeMs() - m_LastTime; |
| 74 | } | 66 | } |
| 75 | 67 | ||
| 76 | // Add the time difference since the last Update() to the starting time. | 68 | // Add the time difference since the last Update() to the starting time. |
| 77 | // This is used to compensate for a paused game. | 69 | // This is used to compensate for a paused game. |
| 78 | void Timer::AddTimeDifference() | 70 | void Timer::AddTimeDifference() { |
| 79 | { | ||
| 80 | m_StartTime += GetTimeDifference(); | 71 | m_StartTime += GetTimeDifference(); |
| 81 | } | 72 | } |
| 82 | 73 | ||
| 83 | // Get the time elapsed since the Start() | 74 | // Get the time elapsed since the Start() |
| 84 | u64 Timer::GetTimeElapsed() | 75 | u64 Timer::GetTimeElapsed() { |
| 85 | { | ||
| 86 | // If we have not started yet, return 1 (because then I don't | 76 | // If we have not started yet, return 1 (because then I don't |
| 87 | // have to change the FPS calculation in CoreRerecording.cpp . | 77 | // have to change the FPS calculation in CoreRerecording.cpp . |
| 88 | if (m_StartTime == 0) return 1; | 78 | if (m_StartTime == 0) |
| 79 | return 1; | ||
| 89 | 80 | ||
| 90 | // Return the final timer time if the timer is stopped | 81 | // Return the final timer time if the timer is stopped |
| 91 | if (!m_Running) return (m_LastTime - m_StartTime); | 82 | if (!m_Running) |
| 83 | return (m_LastTime - m_StartTime); | ||
| 92 | 84 | ||
| 93 | return (GetTimeMs() - m_StartTime); | 85 | return (GetTimeMs() - m_StartTime); |
| 94 | } | 86 | } |
| 95 | 87 | ||
| 96 | // Get the formatted time elapsed since the Start() | 88 | // Get the formatted time elapsed since the Start() |
| 97 | std::string Timer::GetTimeElapsedFormatted() const | 89 | std::string Timer::GetTimeElapsedFormatted() const { |
| 98 | { | ||
| 99 | // If we have not started yet, return zero | 90 | // If we have not started yet, return zero |
| 100 | if (m_StartTime == 0) | 91 | if (m_StartTime == 0) |
| 101 | return "00:00:00:000"; | 92 | return "00:00:00:000"; |
| @@ -114,50 +105,46 @@ std::string Timer::GetTimeElapsedFormatted() const | |||
| 114 | // Hours | 105 | // Hours |
| 115 | u32 Hours = Minutes / 60; | 106 | u32 Hours = Minutes / 60; |
| 116 | 107 | ||
| 117 | std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i", | 108 | std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i", Hours, Minutes % 60, Seconds % 60, |
| 118 | Hours, Minutes % 60, Seconds % 60, Milliseconds % 1000); | 109 | Milliseconds % 1000); |
| 119 | return TmpStr; | 110 | return TmpStr; |
| 120 | } | 111 | } |
| 121 | 112 | ||
| 122 | // Get current time | 113 | // Get current time |
| 123 | void Timer::IncreaseResolution() | 114 | void Timer::IncreaseResolution() { |
| 124 | { | ||
| 125 | #ifdef _WIN32 | 115 | #ifdef _WIN32 |
| 126 | timeBeginPeriod(1); | 116 | timeBeginPeriod(1); |
| 127 | #endif | 117 | #endif |
| 128 | } | 118 | } |
| 129 | 119 | ||
| 130 | void Timer::RestoreResolution() | 120 | void Timer::RestoreResolution() { |
| 131 | { | ||
| 132 | #ifdef _WIN32 | 121 | #ifdef _WIN32 |
| 133 | timeEndPeriod(1); | 122 | timeEndPeriod(1); |
| 134 | #endif | 123 | #endif |
| 135 | } | 124 | } |
| 136 | 125 | ||
| 137 | // Get the number of seconds since January 1 1970 | 126 | // Get the number of seconds since January 1 1970 |
| 138 | u64 Timer::GetTimeSinceJan1970() | 127 | u64 Timer::GetTimeSinceJan1970() { |
| 139 | { | ||
| 140 | time_t ltime; | 128 | time_t ltime; |
| 141 | time(<ime); | 129 | time(<ime); |
| 142 | return((u64)ltime); | 130 | return ((u64)ltime); |
| 143 | } | 131 | } |
| 144 | 132 | ||
| 145 | u64 Timer::GetLocalTimeSinceJan1970() | 133 | u64 Timer::GetLocalTimeSinceJan1970() { |
| 146 | { | ||
| 147 | time_t sysTime, tzDiff, tzDST; | 134 | time_t sysTime, tzDiff, tzDST; |
| 148 | struct tm * gmTime; | 135 | struct tm* gmTime; |
| 149 | 136 | ||
| 150 | time(&sysTime); | 137 | time(&sysTime); |
| 151 | 138 | ||
| 152 | // Account for DST where needed | 139 | // Account for DST where needed |
| 153 | gmTime = localtime(&sysTime); | 140 | gmTime = localtime(&sysTime); |
| 154 | if(gmTime->tm_isdst == 1) | 141 | if (gmTime->tm_isdst == 1) |
| 155 | tzDST = 3600; | 142 | tzDST = 3600; |
| 156 | else | 143 | else |
| 157 | tzDST = 0; | 144 | tzDST = 0; |
| 158 | 145 | ||
| 159 | // Lazy way to get local time in sec | 146 | // Lazy way to get local time in sec |
| 160 | gmTime = gmtime(&sysTime); | 147 | gmTime = gmtime(&sysTime); |
| 161 | tzDiff = sysTime - mktime(gmTime); | 148 | tzDiff = sysTime - mktime(gmTime); |
| 162 | 149 | ||
| 163 | return (u64)(sysTime + tzDiff + tzDST); | 150 | return (u64)(sysTime + tzDiff + tzDST); |
| @@ -165,10 +152,9 @@ u64 Timer::GetLocalTimeSinceJan1970() | |||
| 165 | 152 | ||
| 166 | // Return the current time formatted as Minutes:Seconds:Milliseconds | 153 | // Return the current time formatted as Minutes:Seconds:Milliseconds |
| 167 | // in the form 00:00:000. | 154 | // in the form 00:00:000. |
| 168 | std::string Timer::GetTimeFormatted() | 155 | std::string Timer::GetTimeFormatted() { |
| 169 | { | ||
| 170 | time_t sysTime; | 156 | time_t sysTime; |
| 171 | struct tm * gmTime; | 157 | struct tm* gmTime; |
| 172 | char tmp[13]; | 158 | char tmp[13]; |
| 173 | 159 | ||
| 174 | time(&sysTime); | 160 | time(&sysTime); |
| @@ -176,7 +162,7 @@ std::string Timer::GetTimeFormatted() | |||
| 176 | 162 | ||
| 177 | strftime(tmp, 6, "%M:%S", gmTime); | 163 | strftime(tmp, 6, "%M:%S", gmTime); |
| 178 | 164 | ||
| 179 | // Now tack on the milliseconds | 165 | // Now tack on the milliseconds |
| 180 | #ifdef _WIN32 | 166 | #ifdef _WIN32 |
| 181 | struct timeb tp; | 167 | struct timeb tp; |
| 182 | (void)::ftime(&tp); | 168 | (void)::ftime(&tp); |
| @@ -190,8 +176,7 @@ std::string Timer::GetTimeFormatted() | |||
| 190 | 176 | ||
| 191 | // Returns a timestamp with decimals for precise time comparisons | 177 | // Returns a timestamp with decimals for precise time comparisons |
| 192 | // ---------------- | 178 | // ---------------- |
| 193 | double Timer::GetDoubleTime() | 179 | double Timer::GetDoubleTime() { |
| 194 | { | ||
| 195 | #ifdef _WIN32 | 180 | #ifdef _WIN32 |
| 196 | struct timeb tp; | 181 | struct timeb tp; |
| 197 | (void)::ftime(&tp); | 182 | (void)::ftime(&tp); |