diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index 6244a1ac..e62d2e05 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -3,15 +3,37 @@ // https://wiki.libsdl.org/SDL3/README-migration#sdl_stdinch #define SDL_bool bool -#include +#include +#include "SDL_audio.h" #include "SDL_events.h" +#include "SDL_filesystem.h" #include "SDL_gamepad.h" #include "SDL_iostream.h" +#include "SDL_keycode.h" #include "SDL_keyboard.h" #include "SDL_mutex.h" #include "SDL_pixels.h" +// #include "SDL_properties.h" #include "SDL_surface.h" #include "SDL_timer.h" +#include "SDL_video.h" +#include "SDL_mouse.h" + +#include + +static std::mt19937 rng(SDL_GetPerformanceCounter()); +inline Sint32 SDL_rand(const Sint32 n) +{ + std::uniform_int_distribution dist(0, n - 1); + return dist(rng); +} +inline float SDL_randf() +{ + static std::uniform_real_distribution dist(0.0f, 1.0f); + return dist(rng); +} + +#define SDL_strtok_r SDL_strtokr // https://wiki.libsdl.org/SDL3/README-migration#sdl_logh @@ -118,3 +140,39 @@ inline SDL_HapticID* SDL_GetHaptics(int *count) return haptics; } +// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh + +#define SDL_GetDisplayForWindow SDL_GetWindowDisplayIndex +#define SDL_SetWindowFullscreenMode SDL_SetWindowDisplayMode +// #define SDL_GetClosestFullscreenDisplayMode SDL_GetClosestDisplayMode +inline bool SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, bool include_high_density_modes, SDL_DisplayMode *closest) +{ + SDL_DisplayMode desired{}; + desired.w = w; + desired.h = h; + desired.refresh_rate = static_cast(refresh_rate); + desired.format = 0; + desired.driverdata = nullptr; + + SDL_DisplayMode *result = SDL_GetClosestDisplayMode(displayID, &desired, closest); + return result != nullptr; +} + + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_mouseh + +static void SDL_HideCursor() { SDL_ShowCursor(SDL_DISABLE); } +static void SDL_ShowCursor() { SDL_ShowCursor(SDL_ENABLE); } + +#define SDL_SYSTEM_CURSOR_COUNT SDL_NUM_SYSTEM_CURSORS +#define SDL_SYSTEM_CURSOR_DEFAULT SDL_SYSTEM_CURSOR_ARROW +#define SDL_SYSTEM_CURSOR_POINTER SDL_SYSTEM_CURSOR_HAND +#define SDL_SYSTEM_CURSOR_TEXT SDL_SYSTEM_CURSOR_IBEAM +#define SDL_SYSTEM_CURSOR_NOT_ALLOWED SDL_SYSTEM_CURSOR_NO +#define SDL_SYSTEM_CURSOR_MOVE SDL_SYSTEM_CURSOR_SIZEALL +#define SDL_SYSTEM_CURSOR_NESW_RESIZE SDL_SYSTEM_CURSOR_SIZENESW +#define SDL_SYSTEM_CURSOR_NS_RESIZE SDL_SYSTEM_CURSOR_SIZENS +#define SDL_SYSTEM_CURSOR_NWSE_RESIZE SDL_SYSTEM_CURSOR_SIZENWSE +#define SDL_SYSTEM_CURSOR_EW_RESIZE SDL_SYSTEM_CURSOR_SIZEWE +#define SDL_SYSTEM_CURSOR_PROGRESS SDL_SYSTEM_CURSOR_WAITARROW + diff --git a/3rdparty/sdl3-shim/SDL3/SDL_audio.h b/3rdparty/sdl3-shim/SDL3/SDL_audio.h new file mode 100644 index 00000000..397f356e --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_audio.h @@ -0,0 +1,101 @@ +#pragma once + +#include "SDL.h" + +#include +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_audioh + +#define SDL_DestroyAudioStream SDL_FreeAudioStream + +#define SDL_AUDIO_F32 AUDIO_F32SYS + +#define SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK NULL + +typedef void SDL_AudioStreamCallback(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount); + +struct ShimAudioCtx { + SDL_AudioStream* stream; + SDL_AudioStreamCallback* callback; + void *userdata; + SDL_AudioSpec obtained; +}; + +static std::map g_audioCtxs; +static SDL_mutex *g_audioMutex = NULL; + +static void SDLCALL shim_audio_callback(void *userdata, Uint8 *stream, int len) { + SDL_AudioDeviceID devid = reinterpret_cast(userdata); + + SDL_LockMutex(g_audioMutex); + const auto it = g_audioCtxs.find(devid); + if (it == g_audioCtxs.end()) { + SDL_UnlockMutex(g_audioMutex); + SDL_memset(stream, 0, len); + return; + } + + ShimAudioCtx &ctx = it->second; + SDL_UnlockMutex(g_audioMutex); + + // How many sample frames the device is asking for + const int frame_size = (SDL_AUDIO_BITSIZE(ctx.obtained.format) / 8) * ctx.obtained.channels; + const int needed_frames = len / frame_size; + + int total = (SDL_AudioStreamAvailable(ctx.stream) / frame_size) + needed_frames; + // SDL3 callback pushes more into the stream + ctx.callback(ctx.userdata, ctx.stream, needed_frames, total); + + int got = SDL_AudioStreamGet(ctx.stream, stream, len); + if (got < len) { + SDL_memset(stream + got, 0, len - got); + } +} + +#define SDL_ResumeAudioDevice(device) SDL_PauseAudioDevice(device, 0) +#define SDL_PutAudioStreamData SDL_AudioStreamPut + +inline SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream* stream) +{ + SDL_LockMutex(g_audioMutex); + const auto it = g_audioCtxs.find(reinterpret_cast(stream)); + if (it == g_audioCtxs.end()) { + return 0; + } + return it->first; +} + +inline SDL_AudioStream * SDL_OpenAudioDeviceStream(const char* devid, const SDL_AudioSpec* desired, SDL_AudioStreamCallback callback, void* userdata) +{ + SDL_AudioSpec* obtained{}; + SDL_AudioSpec desired2 = *desired; + desired2.callback = shim_audio_callback; + desired2.userdata = reinterpret_cast(static_cast(0)); + SDL_AudioDeviceID device = SDL_OpenAudioDevice(devid, 0, &desired2, obtained, 0); + SDL_AudioStream* stream = SDL_NewAudioStream( + desired->format, desired->channels, desired->freq, + obtained->format, obtained->channels, obtained->freq + ); + if (!stream) { + SDL_CloseAudioDevice(device); + return nullptr; + } + + { + SDL_LockMutex(g_audioMutex); + ShimAudioCtx ctx; + ctx.stream = stream; + ctx.callback = callback; + ctx.userdata = userdata; + ctx.obtained = *obtained; + g_audioCtxs[device] = ctx; + SDL_UnlockMutex(g_audioMutex); + } + + SDL_LockAudioDevice(device); + desired2.userdata = reinterpret_cast(static_cast(device)); + SDL_UnlockAudioDevice(device); + + return stream; +} diff --git a/3rdparty/sdl3-shim/SDL3/SDL_events.h b/3rdparty/sdl3-shim/SDL3/SDL_events.h index 20913d29..5f30011d 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_events.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_events.h @@ -1,18 +1,69 @@ #pragma once -#include +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_eventsh #define SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED SDL_WINDOWEVENT_SIZE_CHANGED -#define SDL_EVENT_MOUSE_BUTTON_DOWN SDL_MOUSEBUTTONDOWN -#define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP -#define SDL_EVENT_MOUSE_MOTION SDL_MOUSEMOTION - -#define SDL_EVENT_FINGER_MOTION SDL_FINGERMOTION -#define SDL_EVENT_FINGER_DOWN SDL_FINGERDOWN -#define SDL_EVENT_FINGER_UP SDL_FINGERUP +// #define SDL_EVENT_MOUSE_BUTTON_DOWN SDL_MOUSEBUTTONDOWN +// #define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP +// #define SDL_EVENT_MOUSE_MOTION SDL_MOUSEMOTION +// +// #define SDL_EVENT_FINGER_MOTION SDL_FINGERMOTION +// #define SDL_EVENT_FINGER_DOWN SDL_FINGERDOWN +// #define SDL_EVENT_FINGER_UP SDL_FINGERUP #define SDL_EVENT_FINGER_CANCELED 0 #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 +#define SDL_EVENT_GAMEPAD_ADDED SDL_CONTROLLERDEVICEADDED +// #define SDL_EVENT_GAMEPAD_REMAPPED SDL_CONTROLLERDEVICEREMAPPED +#define SDL_EVENT_GAMEPAD_REMOVED SDL_CONTROLLERDEVICEREMOVED +// #define SDL_EVENT_GAMEPAD_SENSOR_UPDATE SDL_CONTROLLERSENSORUPDATE +// #define SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED SDL_CONTROLLERSTEAMHANDLEUPDATED +// #define SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN SDL_CONTROLLERTOUCHPADDOWN +// #define SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION SDL_CONTROLLERTOUCHPADMOTION +// #define SDL_EVENT_GAMEPAD_TOUCHPAD_UP SDL_CONTROLLERTOUCHPADUP +// #define SDL_EVENT_DROP_BEGIN SDL_DROPBEGIN +// #define SDL_EVENT_DROP_COMPLETE SDL_DROPCOMPLETE +// #define SDL_EVENT_DROP_FILE SDL_DROPFILE +// #define SDL_EVENT_DROP_TEXT SDL_DROPTEXT +#define SDL_EVENT_FINGER_DOWN SDL_FINGERDOWN +#define SDL_EVENT_FINGER_MOTION SDL_FINGERMOTION +#define SDL_EVENT_FINGER_UP SDL_FINGERUP +// #define SDL_EVENT_FIRST SDL_FIRSTEVENT +// #define SDL_EVENT_JOYSTICK_AXIS_MOTION SDL_JOYAXISMOTION +// #define SDL_EVENT_JOYSTICK_BALL_MOTION SDL_JOYBALLMOTION +// #define SDL_EVENT_JOYSTICK_BATTERY_UPDATED SDL_JOYBATTERYUPDATED +// #define SDL_EVENT_JOYSTICK_BUTTON_DOWN SDL_JOYBUTTONDOWN +// #define SDL_EVENT_JOYSTICK_BUTTON_UP SDL_JOYBUTTONUP +// #define SDL_EVENT_JOYSTICK_ADDED SDL_JOYDEVICEADDED +// #define SDL_EVENT_JOYSTICK_REMOVED SDL_JOYDEVICEREMOVED +// #define SDL_EVENT_JOYSTICK_HAT_MOTION SDL_JOYHATMOTION +#define SDL_EVENT_KEY_DOWN SDL_KEYDOWN +// #define SDL_EVENT_KEYMAP_CHANGED SDL_KEYMAPCHANGED +#define SDL_EVENT_KEY_UP SDL_KEYUP +// #define SDL_EVENT_LAST SDL_LASTEVENT +// #define SDL_EVENT_LOCALE_CHANGED SDL_LOCALECHANGED +#define SDL_EVENT_MOUSE_BUTTON_DOWN SDL_MOUSEBUTTONDOWN +#define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP +#define SDL_EVENT_MOUSE_MOTION SDL_MOUSEMOTION +// #define SDL_EVENT_MOUSE_WHEEL SDL_MOUSEWHEEL +// #define SDL_EVENT_POLL_SENTINEL SDL_POLLSENTINEL + + + +#define fingerID fingerId +#define touchID touchId +#define gaxis caxis +#define gbutton cbutton diff --git a/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h b/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h new file mode 100644 index 00000000..bf645535 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h @@ -0,0 +1,50 @@ +#pragma once + +#include "SDL.h" +#include "SDL_iostream.h" + +// TODO: properly implement ( + +typedef Uint32 SDL_GlobFlags; + +typedef enum SDL_PathType +{ + SDL_PATHTYPE_NONE, + SDL_PATHTYPE_FILE, + SDL_PATHTYPE_DIRECTORY, + SDL_PATHTYPE_OTHER +} SDL_PathType; + +typedef Sint64 SDL_Time; + +typedef struct SDL_PathInfo +{ + SDL_PathType type; + Uint64 size; + SDL_Time create_time; + SDL_Time modify_time; + SDL_Time access_time; +} SDL_PathInfo; + +// https://github.com/libsdl-org/SDL/blob/main/src/filesystem/ + +inline char ** SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count) +{ + // since the one use of this doesnt use pattern or flags this should be a pretty simple stub + SDL_Unsupported(); + return static_cast(SDL_malloc(0)); +} + +inline bool SDL_RemovePath(const char *path) +{ + return SDL_Unsupported(); +} +inline bool SDL_RenamePath(const char *oldpath, const char *newpath) +{ + return SDL_Unsupported(); +} + +inline bool SDL_GetPathInfo(const char *path, SDL_PathInfo *info) +{ + return SDL_Unsupported(); +} diff --git a/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h b/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h index a5fc3fd6..1468698a 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h @@ -5,3 +5,107 @@ // https://wiki.libsdl.org/SDL3/README-migration#sdl_gamecontrollerh #define SDL_Gamepad SDL_GameController + +#define SDL_INIT_GAMEPAD SDL_INIT_GAMECONTROLLER + +// #define SDL_CloseGamepad SDL_GameControllerClose + +// +// #define SDL_GamepadAxis SDL_GameControllerAxis +// #define SDL_GamepadBindingType SDL_GameControllerBindType +// #define SDL_GamepadButton SDL_GameControllerButton +// #define SDL_GamepadType SDL_GameControllerType + +// #define SDL_AddGamepadMapping SDL_GameControllerAddMapping +// #define SDL_AddGamepadMappingsFromFile SDL_GameControllerAddMappingsFromFile +// #define SDL_AddGamepadMappingsFromIO SDL_GameControllerAddMappingsFromRW +#define SDL_CloseGamepad SDL_GameControllerClose +// #define SDL_GetGamepadFromID SDL_GameControllerFromInstanceID +// #define SDL_GetGamepadFromPlayerIndex SDL_GameControllerFromPlayerIndex +// #define SDL_GetGamepadAppleSFSymbolsNameForAxis SDL_GameControllerGetAppleSFSymbolsNameForAxis +// #define SDL_GetGamepadAppleSFSymbolsNameForButton SDL_GameControllerGetAppleSFSymbolsNameForButton +// #define SDL_GamepadConnected SDL_GameControllerGetAttached +#define SDL_GetGamepadAxis SDL_GameControllerGetAxis +// #define SDL_GetGamepadAxisFromString SDL_GameControllerGetAxisFromString +// #define SDL_GetGamepadButton SDL_GameControllerGetButton +// #define SDL_GetGamepadButtonFromString SDL_GameControllerGetButtonFromString +// #define SDL_GetGamepadFirmwareVersion SDL_GameControllerGetFirmwareVersion +#define SDL_GetGamepadJoystick SDL_GameControllerGetJoystick +// #define SDL_GetNumGamepadTouchpadFingers SDL_GameControllerGetNumTouchpadFingers +// #define SDL_GetNumGamepadTouchpads SDL_GameControllerGetNumTouchpads +// #define SDL_GetGamepadPlayerIndex SDL_GameControllerGetPlayerIndex +// #define SDL_GetGamepadProduct SDL_GameControllerGetProduct +// #define SDL_GetGamepadProductVersion SDL_GameControllerGetProductVersion +// #define SDL_GetGamepadSensorData SDL_GameControllerGetSensorData, returns bool +// #define SDL_GetGamepadSensorDataRate SDL_GameControllerGetSensorDataRate +// #define SDL_GetGamepadSerial SDL_GameControllerGetSerial +// #define SDL_GetGamepadSteamHandle SDL_GameControllerGetSteamHandle +// #define SDL_GetGamepadStringForAxis SDL_GameControllerGetStringForAxis +// #define SDL_GetGamepadStringForButton SDL_GameControllerGetStringForButton +// #define SDL_GetGamepadTouchpadFinger SDL_GameControllerGetTouchpadFinger, returns bool +// #define SDL_GetGamepadType SDL_GameControllerGetType +// #define SDL_GetGamepadVendor SDL_GameControllerGetVendor +// #define SDL_GamepadHasAxis SDL_GameControllerHasAxis +// #define SDL_GamepadHasButton SDL_GameControllerHasButton +// #define SDL_GamepadHasSensor SDL_GameControllerHasSensor +// #define SDL_GamepadSensorEnabled SDL_GameControllerIsSensorEnabled +// #define SDL_GetGamepadMapping SDL_GameControllerMapping +// #define SDL_GetGamepadMappingForGUID SDL_GameControllerMappingForGUID +// #define SDL_GetGamepadName SDL_GameControllerName +#define SDL_OpenGamepad SDL_GameControllerOpen +// #define SDL_GetGamepadPath SDL_GameControllerPath +#define SDL_RumbleGamepad(...) (SDL_GameControllerRumble(__VA_ARGS__) == 0) +// #define SDL_RumbleGamepadTriggers SDL_GameControllerRumbleTriggers, returns bool +// #define SDL_SendGamepadEffect SDL_GameControllerSendEffect, returns bool +// #define SDL_SetGamepadLED SDL_GameControllerSetLED, returns bool +// #define SDL_SetGamepadPlayerIndex SDL_GameControllerSetPlayerIndex, returns bool +// #define SDL_SetGamepadSensorEnabled SDL_GameControllerSetSensorEnabled, returns bool +// #define SDL_UpdateGamepads SDL_GameControllerUpdate +// #define SDL_IsGamepad SDL_IsGameController + +// #define SDL_GAMEPAD_AXIS_INVALID SDL_CONTROLLER_AXIS_INVALID +#define SDL_GAMEPAD_AXIS_LEFTX SDL_CONTROLLER_AXIS_LEFTX +#define SDL_GAMEPAD_AXIS_LEFTY SDL_CONTROLLER_AXIS_LEFTY +// #define SDL_GAMEPAD_AXIS_COUNT SDL_CONTROLLER_AXIS_MAX +#define SDL_GAMEPAD_AXIS_RIGHTX SDL_CONTROLLER_AXIS_RIGHTX +#define SDL_GAMEPAD_AXIS_RIGHTY SDL_CONTROLLER_AXIS_RIGHTY +#define SDL_GAMEPAD_AXIS_LEFT_TRIGGER SDL_CONTROLLER_AXIS_TRIGGERLEFT +#define SDL_GAMEPAD_AXIS_RIGHT_TRIGGER SDL_CONTROLLER_AXIS_TRIGGERRIGHT +// #define SDL_GAMEPAD_BINDTYPE_AXIS SDL_CONTROLLER_BINDTYPE_AXIS +// #define SDL_GAMEPAD_BINDTYPE_BUTTON SDL_CONTROLLER_BINDTYPE_BUTTON +// #define SDL_GAMEPAD_BINDTYPE_HAT SDL_CONTROLLER_BINDTYPE_HAT +#define SDL_GAMEPAD_BINDTYPE_NONE SDL_CONTROLLER_BINDTYPE_NONE +#define SDL_GAMEPAD_BUTTON_SOUTH SDL_CONTROLLER_BUTTON_A +#define SDL_GAMEPAD_BUTTON_EAST SDL_CONTROLLER_BUTTON_B +// #define SDL_GAMEPAD_BUTTON_BACK SDL_CONTROLLER_BUTTON_BACK +#define SDL_GAMEPAD_BUTTON_DPAD_DOWN SDL_CONTROLLER_BUTTON_DPAD_DOWN +#define SDL_GAMEPAD_BUTTON_DPAD_LEFT SDL_CONTROLLER_BUTTON_DPAD_LEFT +#define SDL_GAMEPAD_BUTTON_DPAD_RIGHT SDL_CONTROLLER_BUTTON_DPAD_RIGHT +#define SDL_GAMEPAD_BUTTON_DPAD_UP SDL_CONTROLLER_BUTTON_DPAD_UP +// #define SDL_GAMEPAD_BUTTON_GUIDE SDL_CONTROLLER_BUTTON_GUIDE +// #define SDL_GAMEPAD_BUTTON_INVALID SDL_CONTROLLER_BUTTON_INVALID +// #define SDL_GAMEPAD_BUTTON_LEFT_SHOULDER SDL_CONTROLLER_BUTTON_LEFTSHOULDER +// #define SDL_GAMEPAD_BUTTON_LEFT_STICK SDL_CONTROLLER_BUTTON_LEFTSTICK +// #define SDL_GAMEPAD_BUTTON_COUNT SDL_CONTROLLER_BUTTON_MAX +// #define SDL_GAMEPAD_BUTTON_MISC1 SDL_CONTROLLER_BUTTON_MISC1 +// #define SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1 SDL_CONTROLLER_BUTTON_PADDLE1 +// #define SDL_GAMEPAD_BUTTON_LEFT_PADDLE1 SDL_CONTROLLER_BUTTON_PADDLE2 +// #define SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2 SDL_CONTROLLER_BUTTON_PADDLE3 +// #define SDL_GAMEPAD_BUTTON_LEFT_PADDLE2 SDL_CONTROLLER_BUTTON_PADDLE4 +// #define SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER SDL_CONTROLLER_BUTTON_RIGHTSHOULDER +// #define SDL_GAMEPAD_BUTTON_RIGHT_STICK SDL_CONTROLLER_BUTTON_RIGHTSTICK +#define SDL_GAMEPAD_BUTTON_START SDL_CONTROLLER_BUTTON_START +// #define SDL_GAMEPAD_BUTTON_TOUCHPAD SDL_CONTROLLER_BUTTON_TOUCHPAD +// #define SDL_GAMEPAD_BUTTON_WEST SDL_CONTROLLER_BUTTON_X +// #define SDL_GAMEPAD_BUTTON_NORTH SDL_CONTROLLER_BUTTON_Y +// #define SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT +// #define SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR +// #define SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT +// #define SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO +// #define SDL_GAMEPAD_TYPE_PS3 SDL_CONTROLLER_TYPE_PS3 +// #define SDL_GAMEPAD_TYPE_PS4 SDL_CONTROLLER_TYPE_PS4 +// #define SDL_GAMEPAD_TYPE_PS5 SDL_CONTROLLER_TYPE_PS5 +// #define SDL_GAMEPAD_TYPE_STANDARD SDL_CONTROLLER_TYPE_UNKNOWN +// #define SDL_GAMEPAD_TYPE_VIRTUAL SDL_CONTROLLER_TYPE_VIRTUAL +// #define SDL_GAMEPAD_TYPE_XBOX360 SDL_CONTROLLER_TYPE_XBOX360 +// #define SDL_GAMEPAD_TYPE_XBOXONE SDL_CONTROLLER_TYPE_XBOXONE diff --git a/3rdparty/sdl3-shim/SDL3/SDL_iostream.h b/3rdparty/sdl3-shim/SDL3/SDL_iostream.h index bdc8c9b6..e3af3b92 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_iostream.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_iostream.h @@ -1,6 +1,6 @@ #pragma once -#include +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_rwopsh diff --git a/3rdparty/sdl3-shim/SDL3/SDL_keycode.h b/3rdparty/sdl3-shim/SDL3/SDL_keycode.h new file mode 100644 index 00000000..f898ee4f --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_keycode.h @@ -0,0 +1,60 @@ +#pragma once + +#include + +#define SDLK_MEDIA_FAST_FORWARD SDLK_AUDIOFASTFORWARD +#define SDL_KMOD_ALT KMOD_ALT +#define SDL_KMOD_CAPS KMOD_CAPS +#define SDL_KMOD_CTRL KMOD_CTRL +#define SDL_KMOD_GUI KMOD_GUI +#define SDL_KMOD_LALT KMOD_LALT +#define SDL_KMOD_LCTRL KMOD_LCTRL +#define SDL_KMOD_LGUI KMOD_LGUI +#define SDL_KMOD_LSHIFT KMOD_LSHIFT +#define SDL_KMOD_MODE KMOD_MODE +#define SDL_KMOD_NONE KMOD_NONE +#define SDL_KMOD_NUM KMOD_NUM +#define SDL_KMOD_RALT KMOD_RALT +#define SDL_KMOD_RCTRL KMOD_RCTRL +#define SDL_KMOD_RGUI KMOD_RGUI +#define SDL_KMOD_RSHIFT KMOD_RSHIFT +#define SDL_KMOD_SCROLL KMOD_SCROLL +#define SDL_KMOD_SHIFT KMOD_SHIFT +#define SDLK_MEDIA_FAST_FORWARD SDLK_AUDIOFASTFORWARD +#define SDLK_MUTE SDLK_AUDIOMUTE +#define SDLK_MEDIA_NEXT_TRACK SDLK_AUDIONEXT +#define SDLK_MEDIA_PLAY SDLK_AUDIOPLAY +#define SDLK_MEDIA_PREVIOUS_TRACK SDLK_AUDIOPREV +#define SDLK_MEDIA_REWIND SDLK_AUDIOREWIND +#define SDLK_MEDIA_STOP SDLK_AUDIOSTOP +#define SDLK_GRAVE SDLK_BACKQUOTE +#define SDLK_MEDIA_EJECT SDLK_EJECT +#define SDLK_MEDIA_SELECT SDLK_MEDIASELECT +#define SDLK_APOSTROPHE SDLK_QUOTE +#define SDLK_DBLAPOSTROPHE SDLK_QUOTEDBL +#define SDLK_A SDLK_a +#define SDLK_B SDLK_b +#define SDLK_C SDLK_c +#define SDLK_D SDLK_d +#define SDLK_E SDLK_e +#define SDLK_F SDLK_f +#define SDLK_G SDLK_g +#define SDLK_H SDLK_h +#define SDLK_I SDLK_i +#define SDLK_J SDLK_j +#define SDLK_K SDLK_k +#define SDLK_L SDLK_l +#define SDLK_M SDLK_m +#define SDLK_N SDLK_n +#define SDLK_O SDLK_o +#define SDLK_P SDLK_p +#define SDLK_Q SDLK_q +#define SDLK_R SDLK_r +#define SDLK_S SDLK_s +#define SDLK_T SDLK_t +#define SDLK_U SDLK_u +#define SDLK_V SDLK_v +#define SDLK_W SDLK_w +#define SDLK_X SDLK_x +#define SDLK_Y SDLK_y +#define SDLK_Z SDLK_z diff --git a/3rdparty/sdl3-shim/SDL3/SDL_mutex.h b/3rdparty/sdl3-shim/SDL3/SDL_mutex.h index 5cc68743..fd9ef578 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_mutex.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_mutex.h @@ -1,6 +1,6 @@ #pragma once -#include +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_mutexh @@ -9,3 +9,4 @@ #define SDL_Semaphore SDL_sem #define SDL_WaitSemaphore SDL_SemWait +#define SDL_SignalSemaphore SDL_SemPost diff --git a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h index e057d3e4..36443152 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h @@ -1,6 +1,6 @@ #pragma once -#include +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_pixelsh #define bits_per_pixel BitsPerPixel diff --git a/3rdparty/sdl3-shim/SDL3/SDL_surface.h b/3rdparty/sdl3-shim/SDL3/SDL_surface.h index 87c22922..d943eee4 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_surface.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_surface.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "SDL_pixels.h" // https://wiki.libsdl.org/SDL3/README-migration#sdl_surfaceh @@ -32,3 +32,5 @@ inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, SDL_PixelFormat for #define SDL_BlitSurfaceScaled(surface, rect, destSurface, destRect, scaleMode) (SDL_BlitScaled(surface, rect, destSurface, destRect) == 0) #define SDL_SetSurfaceColorKey SDL_SetColorKey +#define SDL_LoadBMP_IO (SDL_Surface*)SDL_LoadBMP_RW +#define SDL_LoadBMP(file) (SDL_Surface*)SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1) //yoinked the existing SDL_LoadBMP macro so it could be cast diff --git a/3rdparty/sdl3-shim/SDL3/SDL_timer.h b/3rdparty/sdl3-shim/SDL3/SDL_timer.h index 8c4b9220..d1bec955 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_timer.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_timer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_timerh // https://wiki.libsdl.org/SDL3/README-migration#sdl_timerh | SDL_GetTicksNS() @@ -9,3 +9,58 @@ // time is in miliseconds not nanoseconds #define SDL_NS_TO_MS(MS) (MS) + + +typedef Uint32 SDL3_TimerCallback (void *userdata, SDL_TimerID timerID, Uint32 interval); + +struct SDL2TimerShimData { + SDL3_TimerCallback *callback2; + void *userdata2; + SDL_TimerID id; +}; + +static std::map g_timers; +static SDL_mutex *g_timerMutex = NULL; + +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); + + if (next == 0) { + SDL_LockMutex(g_timerMutex); + g_timers.erase(shim->id); + SDL_free(shim); + SDL_UnlockMutex(g_timerMutex); + } + + return next; +} + +inline SDL_TimerID SDL_AddTimer(Uint32 interval, SDL3_TimerCallback callback3, void* userdata) +{ + const auto shim = static_cast(SDL_malloc(sizeof(SDL2TimerShimData))); + shim->callback2 = callback3; + shim->userdata2 = userdata; + + const SDL_TimerID id = ::SDL_AddTimer(interval, shim_timer_callback, shim); + shim->id = id; + + SDL_LockMutex(g_timerMutex); + g_timers[id] = shim; + SDL_UnlockMutex(g_timerMutex); + + return id; +} + +inline SDL_bool SDL_RemoveTimer(SDL_TimerID id) +{ + SDL_LockMutex(g_timerMutex); + if (const auto it = g_timers.find(id); it != g_timers.end()) { + SDL_free(it->second); + g_timers.erase(it); + } + SDL_UnlockMutex(g_timerMutex); + + return ::SDL_RemoveTimer(id); +} diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index c7444362..4ea8d66a 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -879,20 +879,39 @@ MxResult IsleApp::SetupWindow() m_cursorBusyBitmap = &busy_cursor; m_cursorNoBitmap = &no_cursor; +#if SDL_MAJOR_VERSION >= 3 SDL_PropertiesID props = SDL_CreateProperties(); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, g_targetWidth); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, g_targetHeight); SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FULLSCREEN_BOOLEAN, m_fullScreen); SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, WINDOW_TITLE); +#endif #if defined(MINIWIN) && !defined(__3DS__) && !defined(WINDOWS_STORE) +#if SDL_MAJOR_VERSION >= 3 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true); +#endif SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); #endif +#if SDL_MAJOR_VERSION >= 3 window = SDL_CreateWindowWithProperties(props); SDL_SetPointerProperty(SDL_GetWindowProperties(window), ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM, &m_videoParam); +#else + Uint32 flags = 0; + flags |= SDL_WINDOW_OPENGL; + if (m_fullScreen) flags |= SDL_WINDOW_FULLSCREEN; + window = SDL_CreateWindow( + WINDOW_TITLE, + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + g_targetWidth, + g_targetHeight, + flags + ); + SDL_SetWindowData(window, ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM, &m_videoParam); +#endif if (m_exclusiveFullScreen && m_fullScreen) { SDL_DisplayMode closestMode; SDL_DisplayID displayID = SDL_GetDisplayForWindow(window); @@ -914,9 +933,9 @@ MxResult IsleApp::SetupWindow() m_windowHandle = (HWND) SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); #endif - +#if SDL_MAJOR_VERSION >= 3 SDL_DestroyProperties(props); - +#endif if (!m_windowHandle) { return FAILURE; } diff --git a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp index b56acab1..82963f58 100644 --- a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp +++ b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp @@ -782,14 +782,26 @@ void LegoInputManager::UpdateLastInputMethod(SDL_Event* p_event) switch (p_event->type) { case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_UP: +#if SDL_MAJOR_VERSION >= 3 m_lastInputMethod = SDL_KeyboardID_v{p_event->key.which}; +#else + m_lastInputMethod = SDL_KeyboardID_v{0}; +#endif break; case SDL_EVENT_MOUSE_BUTTON_DOWN: case SDL_EVENT_MOUSE_BUTTON_UP: +#if SDL_MAJOR_VERSION >= 3 m_lastInputMethod = SDL_MouseID_v{p_event->button.which}; +#else + m_lastInputMethod = SDL_MouseID_v{0}; +#endif break; case SDL_EVENT_MOUSE_MOTION: +#if SDL_MAJOR_VERSION >= 3 m_lastInputMethod = SDL_MouseID_v{p_event->motion.which}; +#else + m_lastInputMethod = SDL_MouseID_v{0}; +#endif break; case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_BUTTON_UP: diff --git a/LEGO1/mxdirectx/mxdirect3d.cpp b/LEGO1/mxdirectx/mxdirect3d.cpp index 84ff77d3..6a8cdd25 100644 --- a/LEGO1/mxdirectx/mxdirect3d.cpp +++ b/LEGO1/mxdirectx/mxdirect3d.cpp @@ -71,11 +71,18 @@ BOOL MxDirect3D::Create( } if (m_pDirect3d->QueryInterface(IID_IDirect3DMiniwin, (void**) &miniwind3d) == DD_OK) { +#if SDL_MAJOR_VERSION >= 3 MxVideoParam* videoParam = (MxVideoParam*) SDL_GetPointerProperty( SDL_GetWindowProperties(reinterpret_cast(hWnd)), ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM, nullptr ); +#else + MxVideoParam* videoParam = (MxVideoParam*) SDL_GetWindowData( + reinterpret_cast(hWnd), + ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM + ); +#endif #ifndef MXDIRECTX_FOR_CONFIG assert(videoParam); #endif diff --git a/LEGO1/mxdirectx/mxdirectxinfo.cpp b/LEGO1/mxdirectx/mxdirectxinfo.cpp index 765d32f7..b8ee33ad 100644 --- a/LEGO1/mxdirectx/mxdirectxinfo.cpp +++ b/LEGO1/mxdirectx/mxdirectxinfo.cpp @@ -228,11 +228,18 @@ BOOL MxDeviceEnumerate::EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc result = lpDD->QueryInterface(IID_IDirect3DMiniwin, (void**) &miniwind3d); if (result == DD_OK) { +#if SDL_MAJOR_VERSION >= 3 MxVideoParam* videoParam = (MxVideoParam*) SDL_GetPointerProperty( SDL_GetWindowProperties(reinterpret_cast(m_hWnd)), ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM, nullptr ); +#else + MxVideoParam* videoParam = (MxVideoParam*) SDL_GetWindowData( + reinterpret_cast(m_hWnd), + ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM + ); +#endif #ifndef MXDIRECTX_FOR_CONFIG assert(videoParam); #endif diff --git a/LEGO1/omni/src/system/mxthread.cpp b/LEGO1/omni/src/system/mxthread.cpp index 307db15a..00c093b5 100644 --- a/LEGO1/omni/src/system/mxthread.cpp +++ b/LEGO1/omni/src/system/mxthread.cpp @@ -34,6 +34,7 @@ MxResult MxThread::Start(MxS32 p_stackSize, MxS32 p_flag) } { +#if SDL_MAJOR_VERSION >= 3 const SDL_PropertiesID props = SDL_CreateProperties(); SDL_SetPointerProperty(props, SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER, (void*) MxThread::ThreadProc); SDL_SetPointerProperty(props, SDL_PROP_THREAD_CREATE_USERDATA_POINTER, this); @@ -44,6 +45,11 @@ MxResult MxThread::Start(MxS32 p_stackSize, MxS32 p_flag) } SDL_DestroyProperties(props); +#else + if (!((m_thread = SDL_CreateThread(&MxThread::ThreadProc, "MxThread", this)))) { + goto done; + } +#endif } result = SUCCESS;