From cd0c726308c335c662384b41d9e23af0457290f7 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Fri, 15 Apr 2016 20:47:26 +0300 Subject: [PATCH] `GetTimer()` now should handle overflows --- src/game/g_window.pas | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 419e135..33fc80c 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -42,6 +42,8 @@ var wLoadingProgress: Boolean = False; wLoadingQuit: Boolean = False; {wWinPause: Byte = 0;} + ticksOverflow: Int64 = -1; + lastTicks: Uint32 = 0; // to detect overflow const // TODO: move this to a separate file @@ -424,8 +426,28 @@ begin end; function GetTimer(): Int64; +var + t: Uint32; + tt: Int64; begin - Result := SDL_GetTicks() {* 1000}; // TODO: do we really need microseconds here? k8: NOPE! + t := SDL_GetTicks() {* 1000}; // TODO: do we really need microseconds here? k8: NOPE! + if ticksOverflow = -1 then + begin + ticksOverflow := 0; + lastTicks := t; + end + else + begin + if lastTicks > t then + begin + // overflow, increment overflow ;-) + ticksOverflow := ticksOverflow+(Int64($ffffffff)+Int64(1)); + tt := (Int64($ffffffff)+Int64(1))+Int64(t); + t := Uint32(tt-lastTicks); + end; + end; + lastTicks := t; + result := ticksOverflow+Int64(t); end; procedure ResetTimer(); -- 2.29.2