From 98249834ffacfb3642a64dfde1c00f789372c8b9 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Sat, 18 Oct 2025 02:19:31 -0400 Subject: [PATCH] fix incorrect assumptions with display + clang format --- 3rdparty/sdl3-shim/SDL3/SDL.h | 24 +++++++++++++++------- 3rdparty/sdl3-shim/SDL3/SDL_events.h | 12 +++++------ 3rdparty/sdl3-shim/SDL3/SDL_timer.h | 30 +++++++++++++++------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index 838e8a6f..5286997d 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -42,14 +42,14 @@ inline float SDL_randf() // https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh -typedef Uint32 SDL_DisplayID; +typedef int SDL_DisplayID; inline SDL_DisplayID SDL_GetPrimaryDisplay() { - return 0; + return 1; } // Modified from 83bb0f9105922fd49282f0b931f7873a71877ac8 SDL_video.c#L1331 -inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count) +inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(int displayID, int* count) { int i; if (count) *count = 0; @@ -76,11 +76,21 @@ inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, return result; } -inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID) +inline SDL_DisplayMode g_displayMode; +inline SDL_mutex* g_displayMutex = SDL_CreateMutex(); + +// This does not handle the differences between the SDL_DisplayMode struct +// https://wiki.libsdl.org/SDL3/SDL_DisplayMode +// https://wiki.libsdl.org/SDL2/SDL_DisplayMode +inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(int displayID) { - SDL_DisplayMode* mode = nullptr; - SDL_GetCurrentDisplayMode(displayID, mode); - return mode; + SDL_LockMutex(g_displayMutex); + if (SDL_GetCurrentDisplayMode(displayID, &g_displayMode) == 0) { + SDL_UnlockMutex(g_timerMutex); + return &g_displayMode; + } + SDL_UnlockMutex(g_timerMutex); + return NULL; } #define SDL_GetWindowSize(...) (SDL_GetWindowSize(__VA_ARGS__), true ) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_events.h b/3rdparty/sdl3-shim/SDL3/SDL_events.h index 3e11a170..8d6b514a 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_events.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_events.h @@ -1,11 +1,15 @@ #pragma once #include "SDL.h" + #include // https://wiki.libsdl.org/SDL3/README-migration#sdl_eventsh -#define SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED SDL_WINDOWEVENT_SIZE_CHANGED +#define SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED (SDL_WINDOWEVENT + 2 + SDL_WINDOWEVENT_SIZE_CHANGED) +#define SDL_EVENT_WINDOW_CLOSE_REQUESTED (SDL_WINDOWEVENT + 2 + SDL_WINDOWEVENT_CLOSE) +#define SDL_EVENT_WINDOW_FOCUS_GAINED (SDL_WINDOWEVENT + 2 + SDL_WINDOWEVENT_FOCUS_GAINED) +#define SDL_EVENT_WINDOW_FOCUS_LOST (SDL_WINDOWEVENT + 2 + SDL_WINDOWEVENT_FOCUS_LOST) // #define SDL_EVENT_MOUSE_BUTTON_DOWN SDL_MOUSEBUTTONDOWN // #define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP @@ -18,12 +22,6 @@ #define SDL_EVENT_QUIT SDL_QUIT -#define SDL_EVENT_WINDOW_CLOSE_REQUESTED SDL_WINDOWEVENT_CLOSE - -#define SDL_EVENT_WINDOW_FOCUS_GAINED SDL_WINDOWEVENT_FOCUS_GAINED -#define SDL_EVENT_WINDOW_FOCUS_LOST SDL_WINDOWEVENT_FOCUS_LOST - - #define SDL_EVENT_GAMEPAD_AXIS_MOTION SDL_CONTROLLERAXISMOTION #define SDL_EVENT_GAMEPAD_BUTTON_DOWN SDL_CONTROLLERBUTTONDOWN #define SDL_EVENT_GAMEPAD_BUTTON_UP SDL_CONTROLLERBUTTONUP diff --git a/3rdparty/sdl3-shim/SDL3/SDL_timer.h b/3rdparty/sdl3-shim/SDL3/SDL_timer.h index 57ff2d62..37c736ee 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_timer.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_timer.h @@ -12,22 +12,21 @@ // time is in miliseconds not nanoseconds #define SDL_NS_TO_MS(MS) (MS) - -typedef Uint32 SDL3_TimerCallback (void *userdata, SDL_TimerID timerID, Uint32 interval); +typedef Uint32 SDL3_TimerCallback(void* userdata, SDL_TimerID timerID, Uint32 interval); struct SDL2TimerShimData { - SDL3_TimerCallback *callback2; - void *userdata2; + SDL3_TimerCallback* callback; + void* userdata; SDL_TimerID id; }; -static std::map g_timers; -static SDL_mutex *g_timerMutex = SDL_CreateMutex(); +inline std::map g_timers; +inline SDL_mutex* g_timerMutex = SDL_CreateMutex(); -inline Uint32 shim_timer_callback (Uint32 interval, void *param) +inline Uint32 shim_timer_callback(Uint32 interval, void* param) { - const auto shim = static_cast(param); - const Uint32 next = shim->callback2(shim->userdata2, shim->id, interval); + auto* shim = static_cast(param); + const Uint32 next = shim->callback(shim->userdata, shim->id, interval); if (next == 0) { SDL_LockMutex(g_timerMutex); @@ -39,13 +38,17 @@ inline Uint32 shim_timer_callback (Uint32 interval, void *param) return next; } -inline SDL_TimerID SDL_AddTimer(Uint32 interval, SDL3_TimerCallback callback3, void* userdata) +inline SDL_TimerID SDL_AddTimer(Uint32 interval, SDL3_TimerCallback* callback, void* userdata) { - const auto shim = static_cast(SDL_malloc(sizeof(SDL2TimerShimData))); - shim->callback2 = callback3; - shim->userdata2 = userdata; + auto* shim = static_cast(SDL_malloc(sizeof(SDL2TimerShimData))); + shim->callback = callback; + shim->userdata = userdata; const SDL_TimerID id = ::SDL_AddTimer(interval, shim_timer_callback, shim); + if (id == 0) { + SDL_free(shim); + return 0; + } shim->id = id; SDL_LockMutex(g_timerMutex); @@ -66,5 +69,4 @@ inline SDL_bool SDL_RemoveTimer2(SDL_TimerID id) return ::SDL_RemoveTimer(id); } - #define SDL_RemoveTimer SDL_RemoveTimer2