sdl2-compat: implement SDL_GetTicks and SDL_GetTicks64 after SDL3 timer changes

From 842c8c9b28d7d5345cf684b5972351a2d5ca6aae Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Mon, 5 Dec 2022 07:03:24 +0300
Subject: [PATCH] implement SDL_GetTicks and SDL_GetTicks64 after SDL3 timer
 changes

The library is broken at present:
- The SDL_Event structures have changed timestamp from 32 bits to 64 bits.
- GameControllerGetSensorDataWithTimestamp and SensorGetDataWithTimestamp
  are removed from SDL3: they are still in sdl3 syms.h as passthrough and
  load attempts will fail only because I didn't want builds to fail: Even
  if you add stubs for them the library will segfault miserably, because
  the event changes aren't handled properly yet.
---
 src/sdl2_compat.c | 12 ++++++++++++
 src/sdl3_syms.h   |  9 +++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index b11cb54..4a09de5 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -858,6 +858,18 @@ SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int dept
     return SDL3_CreateSurfaceFrom(pixels, width, height, pitch, format);
 }
 
+DECLSPEC Uint32
+SDLCALL SDL_GetTicks(void)
+{
+    return (Uint32) SDL3_GetTicks();
+}
+
+DECLSPEC Uint64
+SDLCALL SDL_GetTicks64(void)
+{
+    return SDL_NS_TO_MS(SDL3_GetTicksNS());
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index e4c8ef5..eaf9c30 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -500,7 +500,8 @@ SDL3_SYM_PASSTHROUGH(void,DetachThread,(SDL_Thread *a),(a),)
 SDL3_SYM_PASSTHROUGH(SDL_TLSID,TLSCreate,(void),(),return)
 SDL3_SYM_PASSTHROUGH(void*,TLSGet,(SDL_TLSID a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,TLSSet,(SDL_TLSID a, const void *b, void (SDLCALL *c)(void*)),(a,b,c),return)
-SDL3_SYM_PASSTHROUGH(Uint32,GetTicks,(void),(),return)
+SDL3_SYM(Uint64,GetTicks,(void),(),return)
+SDL3_SYM(Uint64,GetTicksNS,(void),(),return)
 SDL3_SYM_PASSTHROUGH(Uint64,GetPerformanceCounter,(void),(),return)
 SDL3_SYM_PASSTHROUGH(Uint64,GetPerformanceFrequency,(void),(),return)
 SDL3_SYM_PASSTHROUGH(void,Delay,(Uint32 a),(a),)
@@ -866,7 +867,6 @@ SDL3_SYM_PASSTHROUGH(int,RenderSetVSync,(SDL_Renderer *a, int b),(a,b),return)
 SDL3_SYM_VARARGS(int,asprintf,(char **a, SDL_PRINTF_FORMAT_STRING const char *b, ...))
 SDL3_SYM_PASSTHROUGH(int,vasprintf,(char **a, const char *b, va_list c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(void*,GetWindowICCProfile,(SDL_Window *a, size_t *b),(a,b),return)
-SDL3_SYM_PASSTHROUGH(Uint64,GetTicks64,(void),(),return)
 #ifdef __LINUX__
 SDL3_SYM_PASSTHROUGH(int,LinuxSetThreadPriorityAndPolicy,(Sint64 a, int b, int c),(a,b,c),return)
 #endif
@@ -945,10 +945,11 @@ SDL3_SYM_PASSTHROUGH(void,GetJoystickGUIDInfo,(SDL_JoystickGUID a, Uint16 *b, Ui
 SDL3_SYM_PASSTHROUGH(int,SetPrimarySelectionText,(const char *a),(a),return)
 SDL3_SYM_PASSTHROUGH(char*,GetPrimarySelectionText,(void),(),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,HasPrimarySelectionText,(void),(),return)
-SDL3_SYM_PASSTHROUGH(int,GameControllerGetSensorDataWithTimestamp,(SDL_GameController *a, SDL_SensorType b, Uint64 *c, float *d, int e),(a,b,c,d,e),return)
-SDL3_SYM_PASSTHROUGH(int,SensorGetDataWithTimestamp,(SDL_Sensor *a, Uint64 *b, float *c, int d),(a,b,c,d),return)
 SDL3_SYM_PASSTHROUGH(void,ResetHints,(void),(),)
 SDL3_SYM_PASSTHROUGH(char*,strcasestr,(const char *a, const char *b),(a,b),return)
+/* FIXME: IMPLEMENT AND THESE TWO: */
+SDL3_SYM_PASSTHROUGH(int,GameControllerGetSensorDataWithTimestamp,(SDL_GameController *a, SDL_SensorType b, Uint64 *c, float *d, int e),(a,b,c,d,e),return)
+SDL3_SYM_PASSTHROUGH(int,SensorGetDataWithTimestamp,(SDL_Sensor *a, Uint64 *b, float *c, int d),(a,b,c,d),return)
 
 #undef SDL3_SYM
 #undef SDL3_SYM_PASSTHROUGH