Switch from Float to Integer Time Values
- Use fast data types where possible so the compiler can optimize for speed based on platform
- for example, 128 bits might be fastest on ARM
- good future-proofing
- Refactor GetTimeSinceStart() to be a bit faster
- multiplication is much faster than division
- Implement a RageTimer method to get the seconds value as a plain int, for the places which cast the seconds value to an int
- Changing from GetTimeSinceStartFast() to GetTimeSinceStart() where accuracy is important
- Changing from GetTimeSinceStart() to GetUsecsSinceStart() for timestamp diffs
- Adjust RageThreads to accomodate an unsigned timestamp value
- a constant for the maximum value of `uint_fast64_t` replaces `-1` to accommodate the change from signed to unsigned for the `locked_at` variable
- i have separate constants for `std::numeric_limits<std::uint_fast64_t>::max()` and `static_cast<std::uint_fast64_t>(-1)`, so the reader understands -1 represents an error code, though they evaluate to the same value, so i could remove one of the two
- Add two methods to calculate the MMSSMsMs / MMSSMsMsMs time value from usecs directly instead of inferring it from a seconds value, in RageUtil
- Use a similar counter/modulo based method for WheelNotifyIcon, similar to what i did for text_glow in NoteField in 2eeee03
- Make `g_iStartTime` static const for safety
Rename two timer functions:
GetUsecsSinceStart -> GetTimeSinceStartMicroseconds
GetMicrosecondsSinceStart -> GetSystemTimeAsMicroseconds
Remove std prefix from uint_fast64_t
This commit is contained in:
@@ -252,6 +252,16 @@ RString SecondsToMSSMsMs( float fSecs )
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
RString MicrosecondsToMMSSMsMs(uint64_t usecs)
|
||||
{
|
||||
const uint64_t totalSeconds = usecs / 1000000;
|
||||
const uint64_t iMinsDisplay = totalSeconds / 60;
|
||||
const uint64_t iSecsDisplay = totalSeconds % 60;
|
||||
const uint64_t iLeftoverDisplay = (usecs % 1000000) / 10000; // Adjusted for two decimal places
|
||||
RString sReturn = ssprintf("%02llu:%02llu.%02llu", iMinsDisplay, iSecsDisplay, std::min<uint64_t>(99, iLeftoverDisplay));
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
RString SecondsToMMSSMsMsMs( float fSecs )
|
||||
{
|
||||
const int iMinsDisplay = static_cast<int>(fSecs/60);
|
||||
@@ -261,6 +271,16 @@ RString SecondsToMMSSMsMsMs( float fSecs )
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
RString MicrosecondsToMMSSMsMsMs(uint64_t usecs)
|
||||
{
|
||||
const uint64_t totalSeconds = usecs / 1000000;
|
||||
const uint64_t iMinsDisplay = totalSeconds / 60;
|
||||
const uint64_t iSecsDisplay = totalSeconds % 60;
|
||||
const uint64_t iLeftoverDisplay = (usecs % 1000000) / 1000;
|
||||
RString sReturn = ssprintf("%02llu:%02llu.%03llu", iMinsDisplay, iSecsDisplay, std::min<uint64_t>(999, iLeftoverDisplay));
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
RString SecondsToMSS( float fSecs )
|
||||
{
|
||||
const int iMinsDisplay = static_cast<int>(fSecs/60);
|
||||
|
||||
Reference in New Issue
Block a user