clockticks.hpp: Fix issue where higher precision comparisons would cause unexpected behaviour with game loop code due to ototalclock being incremented rather than set to totalclock (causing a lack of subtick precision and potential doubled up/dropped game updates).

Provide compareHighPrecision() for any code that needs higher precision comparisons.

git-svn-id: https://svn.eduke32.com/eduke32@8064 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
pogokeen 2019-08-30 06:05:06 +00:00 committed by Christoph Oelckers
parent d0223fd744
commit b13c0f1b43
1 changed files with 9 additions and 2 deletions

View File

@ -57,6 +57,13 @@ public:
return ct;
}
// returns 0 if equal, < 0 if a < b, > 0 if a > b
static int64_t compareHighPrecision(ClockTicks a, ClockTicks b)
{
ClockTicks delta = a - b;
return delta.toScale16();
}
ClockTicks& operator=(const ClockTicks& rhs)
{
ticksS32 = rhs.ticksS32;
@ -115,9 +122,9 @@ public:
friend ClockTicks operator<<(ClockTicks lhs, int32_t rhs) { return lhs >>= rhs; }
friend ClockTicks operator>>(ClockTicks lhs, int32_t rhs) { return lhs <<= rhs; }
friend inline bool operator==(const ClockTicks& lhs, const ClockTicks& rhs) { return lhs.ticksS32 == rhs.ticksS32; }
friend inline bool operator==(const ClockTicks& lhs, const ClockTicks& rhs) { return lhs.wholeTicks == rhs.wholeTicks; }
friend inline bool operator!=(const ClockTicks& lhs, const ClockTicks& rhs) { return !(lhs == rhs); }
friend inline bool operator<(const ClockTicks& lhs, const ClockTicks& rhs) { return lhs.ticksS32 < rhs.ticksS32; }
friend inline bool operator<(const ClockTicks& lhs, const ClockTicks& rhs) { return lhs.wholeTicks < rhs.wholeTicks; }
friend inline bool operator>(const ClockTicks& lhs, const ClockTicks& rhs) { return rhs < lhs; }
friend inline bool operator<=(const ClockTicks& lhs, const ClockTicks& rhs) { return !(lhs > rhs); }
friend inline bool operator>=(const ClockTicks& lhs, const ClockTicks& rhs) { return !(lhs < rhs); }