From b13c0f1b43d087c3236acc4f90a4381f44c00df7 Mon Sep 17 00:00:00 2001
From: pogokeen <pogokeen@1a8010ca-5511-0410-912e-c29ae57300e0>
Date: Fri, 30 Aug 2019 06:05:06 +0000
Subject: [PATCH] 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
---
 source/build/include/clockticks.hpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/source/build/include/clockticks.hpp b/source/build/include/clockticks.hpp
index 609c61a2f..f116f9fc0 100644
--- a/source/build/include/clockticks.hpp
+++ b/source/build/include/clockticks.hpp
@@ -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); }