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:
sukibaby
2024-09-22 01:27:45 -07:00
committed by teejusb
parent 53cd968b90
commit eb35a9b9af
24 changed files with 95 additions and 55 deletions
+14 -7
View File
@@ -32,14 +32,16 @@
const std::uint64_t ONE_SECOND_IN_MICROSECONDS_ULL = 1000000ULL;
const std::int64_t ONE_SECOND_IN_MICROSECONDS_LL = 1000000LL;
const uint_fast64_t ONE_SECOND_IN_MICROSECONDS_FAST_ULL = 1000000ULL;
const double ONE_SECOND_IN_MICROSECONDS_DBL = 1000000.0;
const RageTimer RageZeroTimer(0,0);
static std::uint64_t g_iStartTime = ArchHooks::GetMicrosecondsSinceStart();
static const std::uint64_t g_iStartTime = ArchHooks::GetSystemTimeInMicroseconds();
static uint_fast64_t g_iStartTimeFast64 = g_iStartTime;
static std::uint64_t GetTime()
{
return ArchHooks::GetMicrosecondsSinceStart();
return ArchHooks::GetSystemTimeInMicroseconds();
}
/* The accuracy of RageTimer::GetTimeSinceStart() is directly tied to the
@@ -52,14 +54,19 @@ static std::uint64_t GetTime()
* and do thorough testing if you change anything here. -sukibaby */
double RageTimer::GetTimeSinceStart()
{
std::uint64_t usecs = GetTime();
usecs -= g_iStartTime;
return usecs / ONE_SECOND_IN_MICROSECONDS_DBL;
constexpr double USEC_TO_SEC = 1.0 / 1000000.0;
return static_cast<double>(RageTimer::GetTimeSinceStartMicroseconds()) * USEC_TO_SEC;
}
std::uint64_t RageTimer::GetUsecsSinceStart()
int RageTimer::GetTimeSinceStartSeconds()
{
return GetTime() - g_iStartTime;
uint_fast64_t usec = RageTimer::GetTimeSinceStartMicroseconds();
return static_cast<int>(usec / ONE_SECOND_IN_MICROSECONDS_FAST_ULL);
}
uint_fast64_t RageTimer::GetTimeSinceStartMicroseconds()
{
return GetTime() - g_iStartTimeFast64;
}
void RageTimer::Touch()