mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-19 22:01:14 +00:00
fix incorrect assumptions with display
+ clang format
This commit is contained in:
parent
9614c0b97b
commit
98249834ff
24
3rdparty/sdl3-shim/SDL3/SDL.h
vendored
24
3rdparty/sdl3-shim/SDL3/SDL.h
vendored
@ -42,14 +42,14 @@ inline float SDL_randf()
|
|||||||
|
|
||||||
// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh
|
// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh
|
||||||
|
|
||||||
typedef Uint32 SDL_DisplayID;
|
typedef int SDL_DisplayID;
|
||||||
inline SDL_DisplayID SDL_GetPrimaryDisplay()
|
inline SDL_DisplayID SDL_GetPrimaryDisplay()
|
||||||
{
|
{
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modified from 83bb0f9105922fd49282f0b931f7873a71877ac8 SDL_video.c#L1331
|
// 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;
|
int i;
|
||||||
if (count) *count = 0;
|
if (count) *count = 0;
|
||||||
@ -76,11 +76,21 @@ inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID,
|
|||||||
return result;
|
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_LockMutex(g_displayMutex);
|
||||||
SDL_GetCurrentDisplayMode(displayID, mode);
|
if (SDL_GetCurrentDisplayMode(displayID, &g_displayMode) == 0) {
|
||||||
return mode;
|
SDL_UnlockMutex(g_timerMutex);
|
||||||
|
return &g_displayMode;
|
||||||
|
}
|
||||||
|
SDL_UnlockMutex(g_timerMutex);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SDL_GetWindowSize(...) (SDL_GetWindowSize(__VA_ARGS__), true )
|
#define SDL_GetWindowSize(...) (SDL_GetWindowSize(__VA_ARGS__), true )
|
||||||
|
|||||||
12
3rdparty/sdl3-shim/SDL3/SDL_events.h
vendored
12
3rdparty/sdl3-shim/SDL3/SDL_events.h
vendored
@ -1,11 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_events.h>
|
#include <SDL2/SDL_events.h>
|
||||||
|
|
||||||
// https://wiki.libsdl.org/SDL3/README-migration#sdl_eventsh
|
// 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_DOWN SDL_MOUSEBUTTONDOWN
|
||||||
// #define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP
|
// #define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP
|
||||||
@ -18,12 +22,6 @@
|
|||||||
|
|
||||||
#define SDL_EVENT_QUIT SDL_QUIT
|
#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_AXIS_MOTION SDL_CONTROLLERAXISMOTION
|
||||||
#define SDL_EVENT_GAMEPAD_BUTTON_DOWN SDL_CONTROLLERBUTTONDOWN
|
#define SDL_EVENT_GAMEPAD_BUTTON_DOWN SDL_CONTROLLERBUTTONDOWN
|
||||||
#define SDL_EVENT_GAMEPAD_BUTTON_UP SDL_CONTROLLERBUTTONUP
|
#define SDL_EVENT_GAMEPAD_BUTTON_UP SDL_CONTROLLERBUTTONUP
|
||||||
|
|||||||
30
3rdparty/sdl3-shim/SDL3/SDL_timer.h
vendored
30
3rdparty/sdl3-shim/SDL3/SDL_timer.h
vendored
@ -12,22 +12,21 @@
|
|||||||
// time is in miliseconds not nanoseconds
|
// time is in miliseconds not nanoseconds
|
||||||
#define SDL_NS_TO_MS(MS) (MS)
|
#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 {
|
struct SDL2TimerShimData {
|
||||||
SDL3_TimerCallback *callback2;
|
SDL3_TimerCallback* callback;
|
||||||
void *userdata2;
|
void* userdata;
|
||||||
SDL_TimerID id;
|
SDL_TimerID id;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::map<SDL_TimerID, void*> g_timers;
|
inline std::map<SDL_TimerID, SDL2TimerShimData*> g_timers;
|
||||||
static SDL_mutex *g_timerMutex = SDL_CreateMutex();
|
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<SDL2TimerShimData*>(param);
|
auto* shim = static_cast<SDL2TimerShimData*>(param);
|
||||||
const Uint32 next = shim->callback2(shim->userdata2, shim->id, interval);
|
const Uint32 next = shim->callback(shim->userdata, shim->id, interval);
|
||||||
|
|
||||||
if (next == 0) {
|
if (next == 0) {
|
||||||
SDL_LockMutex(g_timerMutex);
|
SDL_LockMutex(g_timerMutex);
|
||||||
@ -39,13 +38,17 @@ inline Uint32 shim_timer_callback (Uint32 interval, void *param)
|
|||||||
return next;
|
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<SDL2TimerShimData*>(SDL_malloc(sizeof(SDL2TimerShimData)));
|
auto* shim = static_cast<SDL2TimerShimData*>(SDL_malloc(sizeof(SDL2TimerShimData)));
|
||||||
shim->callback2 = callback3;
|
shim->callback = callback;
|
||||||
shim->userdata2 = userdata;
|
shim->userdata = userdata;
|
||||||
|
|
||||||
const SDL_TimerID id = ::SDL_AddTimer(interval, shim_timer_callback, shim);
|
const SDL_TimerID id = ::SDL_AddTimer(interval, shim_timer_callback, shim);
|
||||||
|
if (id == 0) {
|
||||||
|
SDL_free(shim);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
shim->id = id;
|
shim->id = id;
|
||||||
|
|
||||||
SDL_LockMutex(g_timerMutex);
|
SDL_LockMutex(g_timerMutex);
|
||||||
@ -66,5 +69,4 @@ inline SDL_bool SDL_RemoveTimer2(SDL_TimerID id)
|
|||||||
|
|
||||||
return ::SDL_RemoveTimer(id);
|
return ::SDL_RemoveTimer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SDL_RemoveTimer SDL_RemoveTimer2
|
#define SDL_RemoveTimer SDL_RemoveTimer2
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user