diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 3ac4a72f..a1dffac7 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -118,13 +118,16 @@ if(USE_SDL2) endforeach() - add_library(SDL3_shim INTERFACE) - target_link_libraries(SDL3_shim INTERFACE SDL2::SDL2) - target_include_directories(SDL3_shim INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/sdl3-shim") - target_include_directories(SDL3_shim INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/sdl3-shim/") + add_library(SDL3_shim STATIC + sdl3-shim/main.cpp + ) + target_link_libraries(SDL3_shim PRIVATE SDL2::SDL2) + target_include_directories(SDL3_shim PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/sdl3-shim" + "${CMAKE_CURRENT_BINARY_DIR}/sdl3-shim" + ) add_library(SDL3::SDL3 ALIAS SDL3_shim) - add_library(SDL3::Headers ALIAS SDL3_shim) endif() diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index f6f3640d..0debbc81 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -3,21 +3,22 @@ // https://wiki.libsdl.org/SDL3/README-migration#sdl_stdinch #define SDL_bool bool -#include +#include +#include +#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_main.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 @@ -98,7 +99,6 @@ inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID) // https://wiki.libsdl.org/SDL3/README-migration#sdl_haptich // SDL_MouseID/SDL_KeyboardID are new -typedef int SDL_MouseID; typedef int SDL_KeyboardID; #define SDL_GetKeyboardState (const bool*)SDL_GetKeyboardState typedef int SDL_HapticID; @@ -165,9 +165,13 @@ inline bool SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, // https://wiki.libsdl.org/SDL3/README-migration#sdl_mouseh +typedef Uint32 SDL_MouseID; + static void SDL_HideCursor() { SDL_ShowCursor(SDL_DISABLE); } static void SDL_ShowCursor() { SDL_ShowCursor(SDL_ENABLE); } +typedef Uint32 SDL_MouseButtonFlags; + #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 diff --git a/3rdparty/sdl3-shim/SDL3/SDL_audio.h b/3rdparty/sdl3-shim/SDL3/SDL_audio.h index 43178147..d66cb2f9 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_audio.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_audio.h @@ -68,14 +68,14 @@ inline SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream* stream) inline SDL_AudioStream * SDL_OpenAudioDeviceStream(const char* devid, const SDL_AudioSpec* desired, SDL_AudioStreamCallback callback, void* userdata) { - SDL_AudioSpec* obtained{}; + 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_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 + obtained.format, obtained.channels, obtained.freq ); if (!stream) { SDL_CloseAudioDevice(device); @@ -88,7 +88,7 @@ inline SDL_AudioStream * SDL_OpenAudioDeviceStream(const char* devid, const SDL_ ctx.stream = stream; ctx.callback = callback; ctx.userdata = userdata; - ctx.obtained = *obtained; + ctx.obtained = obtained; g_audioCtxs[device] = ctx; SDL_UnlockMutex(g_audioMutex); } diff --git a/3rdparty/sdl3-shim/SDL3/SDL_events.h b/3rdparty/sdl3-shim/SDL3/SDL_events.h index 5f30011d..3e11a170 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_events.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_events.h @@ -1,6 +1,7 @@ #pragma once -#include +#include "SDL.h" +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_eventsh diff --git a/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h b/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h index bf645535..b1e8f8b0 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h @@ -28,11 +28,11 @@ typedef struct 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) +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)); + return NULL; } inline bool SDL_RemovePath(const char *path) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h b/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h index 1468698a..469ac049 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h @@ -1,6 +1,6 @@ #pragma once -#include +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_gamecontrollerh diff --git a/3rdparty/sdl3-shim/SDL3/SDL_iostream.h b/3rdparty/sdl3-shim/SDL3/SDL_iostream.h index e3af3b92..bdc8c9b6 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 index f898ee4f..b2fa5a42 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_keycode.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_keycode.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #define SDLK_MEDIA_FAST_FORWARD SDLK_AUDIOFASTFORWARD #define SDL_KMOD_ALT KMOD_ALT diff --git a/3rdparty/sdl3-shim/SDL3/SDL_main.h b/3rdparty/sdl3-shim/SDL3/SDL_main.h new file mode 100644 index 00000000..92b7fbbd --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_main.h @@ -0,0 +1,13 @@ +#pragma once + +typedef enum SDL_AppResult +{ + SDL_APP_CONTINUE, + SDL_APP_SUCCESS, + SDL_APP_FAILURE +} SDL_AppResult; + +SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]); +SDL_AppResult SDL_AppIterate(void *appstate); +SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event); +void SDL_AppQuit(void *appstate, SDL_AppResult result); diff --git a/3rdparty/sdl3-shim/SDL3/SDL_mutex.h b/3rdparty/sdl3-shim/SDL3/SDL_mutex.h index fd9ef578..86f51626 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 diff --git a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h index b439434d..fb8fd71c 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 @@ -26,7 +26,7 @@ SDL_PixelFormatDetails* SDL_GetPixelFormatDetails(T format) { static bool operator!=(SDL_PixelFormatDetails* lhs, SDL_PixelFormatEnum rhs) { - return lhs->format == rhs; + return lhs->format != rhs; } #define SDL_CreatePalette SDL_AllocPalette diff --git a/3rdparty/sdl3-shim/SDL3/SDL_surface.h b/3rdparty/sdl3-shim/SDL3/SDL_surface.h index 792eb37c..2e856991 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 @@ -22,10 +22,7 @@ SDL_Surface* SDL_CreateSurface( int width, int height, T format) { inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, SDL_PixelFormat format) { - SDL_PixelFormatDetails* formatDetails = SDL_AllocFormat(format); - SDL_Surface* result = SDL_ConvertSurface(surface, formatDetails, 0); - SDL_free(formatDetails); - return result; + return SDL_ConvertSurfaceFormat(surface, format, 0); }; inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, const SDL_PixelFormatDetails* formatDetails) { diff --git a/3rdparty/sdl3-shim/SDL3/SDL_timer.h b/3rdparty/sdl3-shim/SDL3/SDL_timer.h index d1bec955..5cdff813 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_timer.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_timer.h @@ -1,6 +1,8 @@ #pragma once -#include +#include +#include +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_timerh // https://wiki.libsdl.org/SDL3/README-migration#sdl_timerh | SDL_GetTicksNS() @@ -53,7 +55,7 @@ inline SDL_TimerID SDL_AddTimer(Uint32 interval, SDL3_TimerCallback callback3, v return id; } -inline SDL_bool SDL_RemoveTimer(SDL_TimerID id) +inline SDL_bool SDL_RemoveTimer2(SDL_TimerID id) { SDL_LockMutex(g_timerMutex); if (const auto it = g_timers.find(id); it != g_timers.end()) { @@ -64,3 +66,5 @@ inline SDL_bool SDL_RemoveTimer(SDL_TimerID id) return ::SDL_RemoveTimer(id); } + +#define SDL_RemoveTimer SDL_RemoveTimer2 diff --git a/3rdparty/sdl3-shim/main.cpp b/3rdparty/sdl3-shim/main.cpp new file mode 100644 index 00000000..b87237c7 --- /dev/null +++ b/3rdparty/sdl3-shim/main.cpp @@ -0,0 +1,20 @@ +#include +#include "SDL3/SDL_events.h" +#include "SDL3/SDL_main.h" + +int main(int argc, char *argv[]) { + void *appstate = NULL; + if (SDL_AppInit(&appstate, argc, argv) != 0) { + return 1; + } + + SDL_Event e; + while (!SDL_AppIterate(appstate)) { + while (SDL_PollEvent(&e)) { + SDL_AppEvent(appstate, &e); + } + } + + SDL_AppQuit(appstate, static_cast(NULL)); + return 0; +} diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index 64667f2c..8d4f1a82 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -480,10 +480,16 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) if (event->key.repeat) { break; } - +#if SDL_MAJOR_VERSION >= 3 SDL_Keycode keyCode = event->key.key; if ((event->key.mod & SDL_KMOD_LALT) && keyCode == SDLK_RETURN) { +#else + SDL_Keycode keyCode = event->key.keysym.sym; + + if ((event->key.keysym.mod & SDL_KMOD_LALT) && keyCode == SDLK_RETURN) { +#endif + SDL_SetWindowFullscreen(window, !(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN)); } else { @@ -493,6 +499,7 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) } break; } +#if SDL_MAJOR_VERSION >= 3 case SDL_EVENT_KEYBOARD_ADDED: if (InputManager()) { InputManager()->AddKeyboard(event->kdevice.which); @@ -513,6 +520,7 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) InputManager()->RemoveMouse(event->mdevice.which); } break; +#endif case SDL_EVENT_GAMEPAD_ADDED: if (InputManager()) { InputManager()->AddJoystick(event->jdevice.which); diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index f8ef1bab..ac1c3290 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -322,8 +322,10 @@ void InvokeAction(Extra::ActionType p_actionId, const MxAtomId& p_pAtom, MxS32 p break; case Extra::ActionType::e_run: { +#if SDL_MAJOR_VERSION >= 3 const char* args[] = {"/lego/sources/main/main.exe", "/script", p_pAtom.GetInternal(), NULL}; SDL_Process* process = SDL_CreateProcess(args, false); +#endif } break; case Extra::ActionType::e_enable: assert(p_streamId != DS_NOT_A_STREAM);