aboutsummaryrefslogtreecommitdiff
path: root/src/time.cc
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2026-02-26 04:52:55 -0300
committerfusion32 <marcopuzziello@gmail.com>2026-02-26 04:52:55 -0300
commit419e6bf9902851e23b4dfe04918521c9d19be524 (patch)
treed6f5021bb65ef8909d3fe37b90eced9f4a90d550 /src/time.cc
parentb1fd46d8c5e2febf6a6fe61e5aaa2daaeffc3954 (diff)
downloadgame-419e6bf9902851e23b4dfe04918521c9d19be524.tar.gz
game-419e6bf9902851e23b4dfe04918521c9d19be524.zip
network code robustness
This should address some quirks of both game and query manager connections while keeping roughly the same overall design.
Diffstat (limited to 'src/time.cc')
-rw-r--r--src/time.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/time.cc b/src/time.cc
index b2ba545..c615462 100644
--- a/src/time.cc
+++ b/src/time.cc
@@ -17,6 +17,23 @@ struct tm GetLocalTimeTM(time_t t){
return result;
}
+int64 GetClockMonotonicMS(void){
+#if OS_WINDOWS
+ LARGE_INTEGER Counter, Frequency;
+ QueryPerformanceCounter(&Counter);
+ QueryPerformanceFrequency(&Frequency);
+ return (int64)((Counter.QuadPart * 1000) / Frequency.QuadPart);
+#else
+ // NOTE(fusion): The coarse monotonic clock has a larger resolution but is
+ // supposed to be faster, even avoiding system calls in some cases. It should
+ // be fine for millisecond precision which is what we're using.
+ struct timespec Time;
+ clock_gettime(CLOCK_MONOTONIC_COARSE, &Time);
+ return ((int64)Time.tv_sec * 1000)
+ + ((int64)Time.tv_nsec / 1000000);
+#endif
+}
+
void GetRealTime(int *Hour, int *Minute){
struct tm LocalTime = GetLocalTimeTM(time(NULL));
*Hour = LocalTime.tm_hour;