diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4306017..ac66945d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,8 +46,9 @@ jobs: - { name: 'iOS', os: 'macos-15', generator: 'Xcode', dx5: false, config: false, brew: true, werror: true, clang-tidy: false, cmake-args: '-DCMAKE_SYSTEM_NAME=iOS', ios: true } - { name: 'Emscripten', os: 'ubuntu-latest', generator: 'Ninja', dx5: false, config: false, emsdk: true, werror: true, clang-tidy: false, cmake-wrapper: 'emcmake' } - { name: 'Nintendo 3DS', os: 'ubuntu-latest', generator: 'Ninja', dx5: false, config: false, n3ds: true, werror: true, clang-tidy: false, container: 'devkitpro/devkitarm:latest', cmake-args: '-DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake' } - - { name: 'Xbox One', os: 'windows-latest', generator: 'Visual Studio 17 2022', dx5: false, config: false, msvc: true, werror: false, clang-tidy: false, vc-arch: 'amd64', cmake-args: '-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.26100.0', xbox-one: true} - - { name: 'Android', os: 'ubuntu-latest', generator: 'Ninja', dx5: false, config: false, android: true, werror: true, clang-tidy: false,} + - { name: 'Xbox One', os: 'windows-latest', generator: 'Visual Studio 17 2022', dx5: false, config: false, msvc: true, werror: false, clang-tidy: false, vc-arch: 'amd64', cmake-args: '-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.26100.0', xbox-one: true } + - { name: 'Android', os: 'ubuntu-latest', generator: 'Ninja', dx5: false, config: false, android: true, werror: true, clang-tidy: false } + - { name: 'Linux (Debug) [SDL2]',os: 'ubuntu-latest', generator: 'Ninja', dx5: false, config: true, linux: true, werror: true, clang-tidy: false, debug: true, sdl2: true } steps: - name: Setup vcvars if: ${{ !!matrix.msvc }} @@ -170,7 +171,7 @@ jobs: -DENABLE_CLANG_TIDY=${{ !!matrix.clang-tidy }} \ -DISLE_WERROR=${{ !!matrix.werror }} \ -DISLE_DEBUG=${{ matrix.debug || 'OFF' }} \ - -Werror=dev + ${{ matrix.sdl2 && '-DUSE_SDL2=ON' || '-Werror=dev' }} - name: Build (CMake) if: ${{ !matrix.android }} diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index ea03ed07..0bda5e3b 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -48,31 +48,42 @@ add_library(libsmacker STATIC ) target_include_directories(libsmacker PUBLIC ${libsmacker_SOURCE_DIR}) -if(DOWNLOAD_DEPENDENCIES) - include(FetchContent) - FetchContent_Declare( - imgui - GIT_REPOSITORY "https://github.com/ocornut/imgui" - GIT_TAG f5befd2d29e66809cd1110a152e375a7f1981f06 - ) - FetchContent_MakeAvailable(imgui) -else() - set(imgui_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/imgui") -endif() +if(ISLE_DEBUG) + if(DOWNLOAD_DEPENDENCIES) + include(FetchContent) + FetchContent_Declare( + imgui + GIT_REPOSITORY "https://github.com/ocornut/imgui" + GIT_TAG f5befd2d29e66809cd1110a152e375a7f1981f06 + ) + FetchContent_MakeAvailable(imgui) + else() + set(imgui_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/imgui") + endif() -add_library(imgui STATIC - ${imgui_SOURCE_DIR}/imgui.cpp - ${imgui_SOURCE_DIR}/imgui_draw.cpp - ${imgui_SOURCE_DIR}/imgui_tables.cpp - ${imgui_SOURCE_DIR}/imgui_widgets.cpp - ${imgui_SOURCE_DIR}/imgui_demo.cpp - ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp - ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp -) -target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) -target_link_libraries(imgui PUBLIC SDL3::Headers) -target_link_libraries(imgui PRIVATE SDL3::SDL3) -set_property(TARGET imgui PROPERTY CXX_CLANG_TIDY "") + add_library(imgui STATIC + ${imgui_SOURCE_DIR}/imgui.cpp + ${imgui_SOURCE_DIR}/imgui_draw.cpp + ${imgui_SOURCE_DIR}/imgui_tables.cpp + ${imgui_SOURCE_DIR}/imgui_widgets.cpp + ${imgui_SOURCE_DIR}/imgui_demo.cpp + ) + if(USE_SDL2) + target_sources(imgui PRIVATE + ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.cpp + ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer2.cpp + ) + else() + target_sources(imgui PRIVATE + ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp + ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp + ) + endif() + + target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) + target_link_libraries(imgui PRIVATE SDL3::SDL3) + set_property(TARGET imgui PROPERTY CXX_CLANG_TIDY "") +endif() if(DOWNLOAD_DEPENDENCIES) include(FetchContent) diff --git a/3rdparty/sdl3-shim/CMakeLists.txt b/3rdparty/sdl3-shim/CMakeLists.txt new file mode 100644 index 00000000..efba6f52 --- /dev/null +++ b/3rdparty/sdl3-shim/CMakeLists.txt @@ -0,0 +1,18 @@ +file(GLOB SDL2_HEADERS "${SDL2_INCLUDE_DIR}/*.h") +foreach(header IN LISTS SDL2_HEADERS) + get_filename_component(fname ${header} NAME) + configure_file(${header} ${CMAKE_CURRENT_BINARY_DIR}/SDL3/${fname} COPYONLY) +endforeach() + +add_library(SDL3_shim STATIC + main.cpp +) + +target_link_libraries(SDL3_shim PUBLIC SDL2::SDL2) +target_include_directories(SDL3_shim PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}" +) + +add_library(SDL3::SDL3 ALIAS SDL3_shim) +add_library(SDL3::Headers ALIAS SDL3_shim) diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h new file mode 100644 index 00000000..8d0ea7c6 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -0,0 +1,210 @@ +#pragma once + +// 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_main.h" +#include "SDL_mutex.h" +#include "SDL_pixels.h" +#include "SDL_surface.h" +#include "SDL_timer.h" +#include "SDL_platform_defines.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 + +#define SDL_LogTrace SDL_LogVerbose + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh + +typedef int SDL_DisplayID; +inline SDL_DisplayID SDL_GetPrimaryDisplay() +{ + return 1; +} + +// Modified from 83bb0f9105922fd49282f0b931f7873a71877ac8 SDL_video.c#L1331 +inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(int displayID, int* count) +{ + int i; + if (count) *count = 0; + + const int num_modes = SDL_GetNumDisplayModes(displayID); + SDL_DisplayMode** result = static_cast(SDL_malloc(sizeof(SDL_DisplayMode*) * (num_modes + 1))); + SDL_DisplayMode* modes = static_cast(SDL_malloc(sizeof(SDL_DisplayMode) * num_modes)); + if (!result || !modes) { + SDL_free(result); + SDL_free(modes); + return NULL; + } + for (i = 0; i < num_modes; i++) { + if (SDL_GetDisplayMode(displayID, i, &modes[i]) == 0) { + result[i] = &modes[i]; + } + } + result[i] = NULL; + + if (count) { + *count = num_modes; + } + + return result; +} + +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_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 ) + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh + +#define SDL_GL_DestroyContext SDL_GL_DeleteContext + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_renderh + +// hardcode -1 as all uses are NULL or -1 (hacks out failure) +#define SDL_CreateRenderer(window, name) SDL_CreateRenderer(window, -1, 0) + +#define SDL_RenderTexture(...) (SDL_RenderCopyF(__VA_ARGS__) == 0) + +#define SDL_CreateWindowAndRenderer(title, width, height, flags, window, renderer) (SDL_CreateWindowAndRenderer(width, height, flags, window, renderer) == 0) + +#define SDL_SetRenderScale(...) (SDL_RenderSetScale(__VA_ARGS__) == 0) + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_keyboardh + +typedef int SDL_KeyboardID; + +#define SDL_GetKeyFromScancode(scancode, modstate, event) SDL_GetKeyFromScancode(scancode) + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_haptich +// SDL_MouseID/SDL_KeyboardID are new + +#define SDL_GetKeyboardState (const bool*)SDL_GetKeyboardState +typedef int SDL_HapticID; + + +#define SDL_CloseHaptic SDL_HapticClose +#define SDL_OpenHaptic SDL_HapticOpen +#define SDL_OpenHapticFromJoystick SDL_HapticOpenFromJoystick +#define SDL_OpenHapticFromMouse SDL_HapticOpenFromMouse +#define SDL_InitHapticRumble(...) (SDL_HapticRumbleInit(__VA_ARGS__) == 0) +#define SDL_PlayHapticRumble(...) (SDL_HapticRumblePlay(__VA_ARGS__) == 0) + +#define SDL_GetHapticID SDL_HapticIndex + +// Modified from cc9937201e421ec55b12ad3f07ff2268f15096e8 SDL_haptic.c#L150 +inline SDL_HapticID* SDL_GetHaptics(int *count) +{ + const int num_haptics = SDL_NumHaptics(); + if (count) *count = 0; + + SDL_HapticID* haptics = static_cast(SDL_malloc((num_haptics + 1) * sizeof(*haptics))); + if (haptics) { + if (count) { + *count = num_haptics; + } + int haptic_index = 0; + for (int device_index = 0; device_index < num_haptics; ++device_index) { + SDL_Haptic* haptic = SDL_HapticOpen(device_index); + if (haptic) { + haptics[haptic_index] = SDL_GetHapticID(haptic); + SDL_HapticClose(haptic); + ++haptic_index; + } + } + haptics[haptic_index] = 0; + } else { if (count) *count = 0; } + + return haptics; +} + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh + +#define SDL_CreateWindow(title, w, h, flags) SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, flags) +#define SDL_SetWindowFullscreen(...) (SDL_SetWindowFullscreen(__VA_ARGS__) == 0) + +#define SDL_GL_MakeCurrent(...) (SDL_GL_MakeCurrent(__VA_ARGS__) == 0) + +#define SDL_GetDisplayForWindow SDL_GetWindowDisplayIndex +#define SDL_SetWindowFullscreenMode(...) (SDL_SetWindowDisplayMode(__VA_ARGS__) == 0) +// #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 + +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 +#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 + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_inith + +#define SDL_Init(...) (SDL_Init(__VA_ARGS__) == 0) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_audio.h b/3rdparty/sdl3-shim/SDL3/SDL_audio.h new file mode 100644 index 00000000..9c66a418 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_audio.h @@ -0,0 +1,112 @@ +#pragma once + +#include "SDL.h" + +#include +#include +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_audioh + +#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_AudioDeviceID device; + SDL_AudioStream* stream; + SDL_AudioStreamCallback* callback; + void *userdata; + SDL_AudioSpec obtained; +}; + +static std::map g_audioCtxs; +static SDL_mutex *g_audioMutex = SDL_CreateMutex(); + +static void shim_audio_callback(void *userdata, Uint8 *data_stream, int len) { + const auto ctx = static_cast(userdata); + SDL_AudioStream* audio_stream = ctx->stream; + + int available = SDL_AudioStreamAvailable(audio_stream); + + int additional_amount = len - available; + if (additional_amount < 0) + additional_amount = 0; + + ctx->callback(ctx->userdata, audio_stream, additional_amount, len); + + int retrieved = SDL_AudioStreamGet(audio_stream, data_stream, len); + if (retrieved < len) { + memset(data_stream + retrieved, ctx->obtained.silence, len - retrieved); + } +} + +#define SDL_ResumeAudioDevice(device) SDL_PauseAudioDevice(device, 0) +#define SDL_PutAudioStreamData(...) (SDL_AudioStreamPut(__VA_ARGS__) == 0) + +inline SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream* stream) +{ + SDL_LockMutex(g_audioMutex); + const auto it = g_audioCtxs.find(stream); + if (it == g_audioCtxs.end()) { + return 0; + } + SDL_UnlockMutex(g_audioMutex); + return it->second->device; +} + +inline SDL_AudioStream * SDL_OpenAudioDeviceStream(const char* devid, const SDL_AudioSpec* desired, SDL_AudioStreamCallback callback, void* userdata) +{ + SDL_AudioSpec obtained{}; + SDL_AudioSpec desired2 = *desired; + + auto ctx = new ShimAudioCtx(); + ctx->callback = callback; + ctx->userdata = userdata; + ctx->stream = nullptr; + + desired2.callback = shim_audio_callback; + desired2.userdata = ctx; + const SDL_AudioDeviceID device = SDL_OpenAudioDevice(devid, 0, &desired2, &obtained, 0); + if (device <= 0) { + delete ctx; + return NULL; + } + + SDL_AudioStream* stream = SDL_NewAudioStream( + desired->format, desired->channels, desired->freq, + obtained.format, obtained.channels, obtained.freq + ); + if (!stream) { + SDL_CloseAudioDevice(device); + delete ctx; + return NULL; + } + + ctx->device = device; + ctx->stream = stream; + ctx->obtained = obtained; + + SDL_LockMutex(g_audioMutex); + g_audioCtxs[stream] = ctx; + SDL_UnlockMutex(g_audioMutex); + + return stream; +} + +inline SDL_bool SDL_DestroyAudioStream(SDL_AudioStream* stream) +{ + SDL_LockMutex(g_audioMutex); + if (const auto it = g_audioCtxs.find(stream); it != g_audioCtxs.end()) { + SDL_CloseAudioDevice(it->second->device); + delete it->second; + g_audioCtxs.erase(it); + SDL_UnlockMutex(g_audioMutex); + } + SDL_UnlockMutex(g_audioMutex); + + SDL_FreeAudioStream(stream); + return true; +} diff --git a/3rdparty/sdl3-shim/SDL3/SDL_events.h b/3rdparty/sdl3-shim/SDL3/SDL_events.h new file mode 100644 index 00000000..61113ed5 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_events.h @@ -0,0 +1,126 @@ +#pragma once + +#include "SDL.h" + +#include +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_eventsh + +#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 +// #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_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 + +inline SDL_Window* SDL_GetWindowFromEvent(const SDL_Event* event) +{ + Uint32 windowID = 0; + + if (event->type >= SDL_USEREVENT && event->type <= SDL_LASTEVENT) { + windowID = event->user.windowID; + } + else { + switch (event->type) { + case SDL_WINDOWEVENT: + windowID = event->window.windowID; + break; + + case SDL_KEYDOWN: + case SDL_KEYUP: + case SDL_KEYMAPCHANGED: + windowID = event->key.windowID; + break; + + case SDL_TEXTEDITING: + windowID = event->edit.windowID; + break; + case SDL_TEXTINPUT: + windowID = event->text.windowID; + break; + case SDL_TEXTEDITING_EXT: + windowID = event->editExt.windowID; + break; + + case SDL_MOUSEMOTION: + windowID = event->motion.windowID; + break; + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + windowID = event->button.windowID; + break; + case SDL_MOUSEWHEEL: + windowID = event->wheel.windowID; + break; + + case SDL_FINGERDOWN: + case SDL_FINGERUP: + case SDL_FINGERMOTION: + windowID = event->tfinger.windowID; + break; + + case SDL_DROPFILE: + case SDL_DROPTEXT: + case SDL_DROPBEGIN: + case SDL_DROPCOMPLETE: + windowID = event->drop.windowID; + break; + } + } + return SDL_GetWindowFromID(windowID); +} diff --git a/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h b/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h new file mode 100644 index 00000000..7515241a --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h @@ -0,0 +1,101 @@ +#pragma once + +#include "SDL.h" +#include "SDL_iostream.h" + +#include +#include + +typedef Uint32 SDL_GlobFlags; + +typedef enum SDL_PathType +{ + SDL_PATHTYPE_NONE, + SDL_PATHTYPE_FILE, + SDL_PATHTYPE_DIRECTORY, + SDL_PATHTYPE_OTHER +} SDL_PathType; + +typedef struct SDL_PathInfo +{ + SDL_PathType type; + Uint64 size; +} 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) +{ + if (!path || !count) return NULL; + *count = 0; + + std::vector entries; + try { + for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) { + entries.push_back(std::filesystem::relative(entry.path(), path).string()); + } + } catch (...) { + return NULL; + } + if (entries.empty()) return NULL; + + char** result = static_cast(SDL_malloc(sizeof(char*) * entries.size())); + if (!result) return NULL; + + for (size_t i = 0; i < entries.size(); ++i) { + result[i] = SDL_strdup(entries[i].c_str()); + if (!result[i]) { + for (size_t j = 0; j < i; ++j) { + SDL_free(result[j]); + } + SDL_free(result); + return NULL; + } + } + *count = static_cast(entries.size()); + return result; +} + +inline bool SDL_RemovePath(const char *path) +{ + if (!path) return SDL_InvalidParamError("path"); + if (std::filesystem::remove(path)) return true; + return false; +} +inline bool SDL_RenamePath(const char *oldpath, const char *newpath) +{ + if (!oldpath) return SDL_InvalidParamError("oldpath"); + if (!newpath) return SDL_InvalidParamError("newpath"); + + std::filesystem::rename(oldpath, newpath); + return true; +} + +inline bool SDL_GetPathInfo(const char *path, SDL_PathInfo *info) +{ + if (!path) return SDL_InvalidParamError("path"); + + SDL_PathInfo dummy; + if (!info) info = &dummy; + + SDL_zerop(info); + switch (const auto status = std::filesystem::status(path);status.type()) { + case std::filesystem::file_type::regular: + info->type = SDL_PATHTYPE_FILE; + info->size = std::filesystem::file_size(path); + break; + case std::filesystem::file_type::directory: + info->type = SDL_PATHTYPE_DIRECTORY; + info->size = 0; + break; + case std::filesystem::file_type::not_found: + info->type = SDL_PATHTYPE_NONE; + info->size = 0; + return false; + default: + info->type = SDL_PATHTYPE_OTHER; + info->size = 0; + break; + } + return true; +} diff --git a/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h b/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h new file mode 100644 index 00000000..469ac049 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h @@ -0,0 +1,111 @@ +#pragma once + +#include + +// 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 new file mode 100644 index 00000000..bdc8c9b6 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_iostream.h @@ -0,0 +1,49 @@ +#pragma once + +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_rwopsh + +#define SDL_IOStream SDL_RWops + +typedef int SDL_IOWhence; + +#define SDL_IO_SEEK_SET RW_SEEK_SET +#define SDL_IO_SEEK_CUR RW_SEEK_CUR +#define SDL_IO_SEEK_END RW_SEEK_END + +// #define SDL_IOFromConstMem SDL_RWFromConstMem +#define SDL_IOFromFile SDL_RWFromFile +#define SDL_IOFromMem SDL_RWFromMem +#define SDL_CloseIO SDL_RWclose +#define SDL_ReadIO(ctx, ptr, size) SDL_RWread(ctx, ptr, 1, size) +#define SDL_SeekIO SDL_RWseek +#define SDL_GetIOSize SDL_RWsize +#define SDL_TellIO SDL_RWtell +#define SDL_WriteIO(ctx, ptr, size) SDL_RWwrite(ctx, ptr, 1, size) +// #define SDL_ReadU16BE SDL_ReadBE16 +// #define SDL_ReadU32BE SDL_ReadBE32 +// #define SDL_ReadU64BE SDL_ReadBE64 +// #define SDL_ReadU16LE SDL_ReadLE16 +// #define SDL_ReadU32LE SDL_ReadLE32 +// #define SDL_ReadU64LE SDL_ReadLE64 +// #define SDL_WriteU16BE SDL_WriteBE16 +// #define SDL_WriteU32BE SDL_WriteBE32 +// #define SDL_WriteU64BE SDL_WriteBE64 +// #define SDL_WriteU16LE SDL_WriteLE16 +// #define SDL_WriteU32LE SDL_WriteLE32 +// #define SDL_WriteU64LE SDL_WriteLE64 + +// FIXME: If Write/Read fail SDL_GetIOStatus is not aware. +typedef enum SDL_IOStatus +{ + SDL_IO_STATUS_READY, + SDL_IO_STATUS_ERROR, +} SDL_IOStatus; +inline SDL_IOStatus SDL_GetIOStatus(SDL_RWops *context) +{ + if (!context) { + return SDL_IO_STATUS_ERROR; + } + return SDL_IO_STATUS_READY; +} diff --git a/3rdparty/sdl3-shim/SDL3/SDL_keycode.h b/3rdparty/sdl3-shim/SDL3/SDL_keycode.h new file mode 100644 index 00000000..b2fa5a42 --- /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_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 new file mode 100644 index 00000000..86f51626 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_mutex.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_mutexh + +#define SDL_Mutex SDL_mutex + +#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 new file mode 100644 index 00000000..6db5885e --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h @@ -0,0 +1,47 @@ +#pragma once + +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_pixelsh +#define bits_per_pixel BitsPerPixel + +typedef SDL_PixelFormat SDL2_PixelFormat; +#define SDL_PixelFormatDetails SDL2_PixelFormat +#define SDL_PixelFormat SDL_PixelFormatEnum + +#define SDL_GetRGBA(pixel, format, palette, r,g,b,a) SDL_GetRGBA(pixel, format, r,g,b,a) +#define SDL_MapRGBA(format, palette, r,g,b,a) SDL_MapRGBA(format, r,g,b,a) +#define SDL_GetRGB(pixel, format, palette, r,g,b) SDL_GetRGB(pixel, format, r,g,b) +#define SDL_MapRGB(format, palette, r,g,b) SDL_MapRGB(format, r,g,b) + +template +SDL_PixelFormatDetails* SDL_GetPixelFormatDetails(T format) { + if constexpr (std::is_same_v) { + return SDL_AllocFormat(format); + } else { + return SDL_AllocFormat(format->format); + } +} + + +static bool operator!=(SDL_PixelFormatDetails* lhs, SDL_PixelFormatEnum rhs) +{ + return lhs->format != rhs; +} + +#define SDL_CreatePalette SDL_AllocPalette +#define SDL_DestroyPalette SDL_FreePalette + +// #define SDL_GetPixelFormatForMasks (SDL_PixelFormat)SDL_MasksToPixelFormatEnum +inline SDL_PixelFormatEnum SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) +{ + // SDL2 checks if Rmask == 0; SDL3 just returns INDEX8 if Rmask doesn't match + // https://github.com/libsdl-org/SDL/blob/66d87bf0e1e29377b398d3c567e1ab3590760d8c/src/video/SDL_pixels.c#L310C5-L321C13 + // https://github.com/libsdl-org/SDL/blob/3669920fddcc418c5f9aca97e77a3f380308d9c0/src/video/SDL_pixels.c#L411-L418C16 + if (bpp == 8 && Rmask != 0xE0) { + return SDL_PIXELFORMAT_INDEX8; + } + return static_cast(SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask)); +} + +#define SDL_GetSurfacePalette(surface) (nullptr) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_platform_defines.h b/3rdparty/sdl3-shim/SDL3/SDL_platform_defines.h new file mode 100644 index 00000000..8d0574e4 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_platform_defines.h @@ -0,0 +1,43 @@ +#pragma once + +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_platformh + +// #define SDL_PLATFORM_3DS __3DS__ +// #define SDL_PLATFORM_AIX __AIX__ +// #define SDL_PLATFORM_ANDROID __ANDROID__ +// #define SDL_PLATFORM_APPLE __APPLE__ +// #define SDL_PLATFORM_BSDI __BSDI__ +#ifdef __CYGWIN__ +#define SDL_PLATFORM_CYGWIN 1 +#endif +// #define SDL_PLATFORM_EMSCRIPTEN __EMSCRIPTEN__ +// #define SDL_PLATFORM_FREEBSD __FREEBSD__ +// #define SDL_PLATFORM_GDK __GDK__ +// #define SDL_PLATFORM_HAIKU __HAIKU__ +// #define SDL_PLATFORM_HPUX __HPUX__ +// #define SDL_PLATFORM_IOS __IPHONEOS__ +// #define SDL_PLATFORM_IRIX __IRIX__ +// #define SDL_PLATFORM_LINUX __LINUX__ +// #define SDL_PLATFORM_MACOS __MACOSX__ +// #define SDL_PLATFORM_NETBSD __NETBSD__ +// #define SDL_PLATFORM_OPENBSD __OPENBSD__ +// #define SDL_PLATFORM_OS2 __OS2__ +// #define SDL_PLATFORM_OSF __OSF__ +// #define SDL_PLATFORM_PS2 __PS2__ +// #define SDL_PLATFORM_PSP __PSP__ +// #define SDL_PLATFORM_QNXNTO __QNXNTO__ +// #define SDL_PLATFORM_RISCOS __RISCOS__ +// #define SDL_PLATFORM_SOLARIS __SOLARIS__ +// #define SDL_PLATFORM_TVOS __TVOS__ +// #define SDL_PLATFORM_UNI __unix__ +// #define SDL_PLATFORM_VITA __VITA__ +// #define SDL_PLATFORM_WIN32 __WIN32__ +// #define SDL_PLATFORM_WINGDK __WINGDK__ +// #define SDL_PLATFORM_XBOXONE __XBOXONE__ +// #define SDL_PLATFORM_XBOXSERIES __XBOXSERIES__ + +#if defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) +#define SDL_PLATFORM_WINDOWS 1 +#endif diff --git a/3rdparty/sdl3-shim/SDL3/SDL_surface.h b/3rdparty/sdl3-shim/SDL3/SDL_surface.h new file mode 100644 index 00000000..2e856991 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_surface.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include "SDL_pixels.h" + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_surfaceh + +#define SDL_FillSurfaceRect(...) (SDL_FillRect(__VA_ARGS__) == 0) + +#define SDL_DestroySurface SDL_FreeSurface + +#define SDL_LockSurface(...) (SDL_LockSurface(__VA_ARGS__) == 0) + +template +SDL_Surface* SDL_CreateSurface( int width, int height, T format) { + if constexpr (std::is_same_v) { + return SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format) ,format); + } else { + return SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format->format) ,format->format); + } +} + +inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, SDL_PixelFormat format) +{ + return SDL_ConvertSurfaceFormat(surface, format, 0); +}; +inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, const SDL_PixelFormatDetails* formatDetails) +{ + return SDL_ConvertSurface(surface, formatDetails, 0); +} + +#define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear +#define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest + +#define SDL_BlitSurfaceScaled(surface, rect, destSurface, destRect, scaleMode) (SDL_BlitScaled(surface, rect, destSurface, destRect) == 0) +#define SDL_SetSurfaceColorKey(...) (SDL_SetColorKey(__VA_ARGS__) == 0) + +#define SDL_LoadBMP_IO SDL_LoadBMP_RW diff --git a/3rdparty/sdl3-shim/SDL3/SDL_timer.h b/3rdparty/sdl3-shim/SDL3/SDL_timer.h new file mode 100644 index 00000000..37c736ee --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_timer.h @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_timerh +// https://wiki.libsdl.org/SDL3/README-migration#sdl_timerh | SDL_GetTicksNS() + +#define SDL_GetTicksNS SDL_GetTicks + +// 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* callback; + void* userdata; + SDL_TimerID id; +}; + +inline std::map g_timers; +inline SDL_mutex* g_timerMutex = SDL_CreateMutex(); + +inline Uint32 shim_timer_callback(Uint32 interval, void* param) +{ + auto* shim = static_cast(param); + const Uint32 next = shim->callback(shim->userdata, 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* callback, void* 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); + g_timers[id] = shim; + SDL_UnlockMutex(g_timerMutex); + + return 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()) { + SDL_free(it->second); + g_timers.erase(it); + } + SDL_UnlockMutex(g_timerMutex); + + 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..7b46335d --- /dev/null +++ b/3rdparty/sdl3-shim/main.cpp @@ -0,0 +1,30 @@ +#include +#include "SDL3/SDL_events.h" +#include "SDL3/SDL_main.h" + +static void TranslateSDLEvents(SDL_Event* e) +{ + // Extend to SDL_DISPLAYEVENT & fully replace the event object passed to AppEvent + // if wanting to drop the ifs on key, mouse and keyboard events. + if (e->type == SDL_WINDOWEVENT) { + e->type = SDL_WINDOWEVENT + 2 + e->window.event; + } +} + +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)) { + TranslateSDLEvents(&e); + SDL_AppEvent(appstate, &e); + } + } + + SDL_AppQuit(appstate, static_cast(NULL)); + return 0; +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a4ec707..1deb9c2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ cmake_dependent_option(ISLE_COMPILE_SHADERS "Compile shaders" ON "SDL_SHADERCROS option(CMAKE_POSITION_INDEPENDENT_CODE "Build with -fPIC" ON) option(ENABLE_CLANG_TIDY "Enable clang-tidy") option(DOWNLOAD_DEPENDENCIES "Download dependencies" ON) +option(USE_SDL2 "Use SDL2 instead of SDL3 via a shim" OFF) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" CACHE PATH "Directory where to put executables and dll") set(ISLE_EMSCRIPTEN_HOST "" CACHE STRING "Host URL for Emscripten streaming (e.g., https://test.com)") cmake_dependent_option(BUILD_SHARED_LIBS "Build lego1 as a shared library" ON "NOT EMSCRIPTEN" OFF) @@ -66,6 +67,7 @@ message(STATUS "Internal miniwin: ${ISLE_MINIWIN}") message(STATUS "Isle extensions: ${ISLE_EXTENSIONS}") message(STATUS "Isle debugging: ${ISLE_DEBUG}") message(STATUS "Compile shaders: ${ISLE_COMPILE_SHADERS}") +message(STATUS "Use SDL2: ${USE_SDL2}") add_library(Isle::iniparser INTERFACE IMPORTED) @@ -74,26 +76,41 @@ if (DOWNLOAD_DEPENDENCIES) message(STATUS "Fetching SDL3 and iniparser. This might take a while...") include(FetchContent) - if(ANDROID) - # Built by Gradle - find_package(SDL3 REQUIRED CONFIG COMPONENTS Shared) - else() - if (WINDOWS_STORE) - FetchContent_Declare( - SDL3 - GIT_REPOSITORY "https://github.com/Helloyunho/SDL3-uwp.git" - GIT_TAG "main" - EXCLUDE_FROM_ALL - ) + if(NOT USE_SDL2) + if(ANDROID) + # Built by Gradle + find_package(SDL3 REQUIRED CONFIG COMPONENTS Shared) else() - FetchContent_Declare( - SDL3 - GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git" - GIT_TAG "main" - EXCLUDE_FROM_ALL - ) + if (WINDOWS_STORE) + FetchContent_Declare( + SDL3 + GIT_REPOSITORY "https://github.com/Helloyunho/SDL3-uwp.git" + GIT_TAG "main" + EXCLUDE_FROM_ALL + ) + else() + FetchContent_Declare( + SDL3 + GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git" + GIT_TAG "main" + EXCLUDE_FROM_ALL + ) + endif() + FetchContent_MakeAvailable(SDL3) endif() - FetchContent_MakeAvailable(SDL3) + else() + FetchContent_Declare( + SDL2 + GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git" + GIT_TAG SDL2 + EXCLUDE_FROM_ALL + ) +# set(SDL_STATIC ON CACHE BOOL "" FORCE) +# set(SDL_SHARED OFF CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(SDL2) + + set(SDL2_INCLUDE_DIR ${SDL2_SOURCE_DIR}/include) + add_subdirectory(3rdparty/sdl3-shim SYSTEM) endif() FetchContent_Declare( @@ -112,7 +129,12 @@ else() # find_package looks for already-installed system packages. # Configure with `-DCMAKE_PREFIX_PATH="/path/to/package1;/path/to/package2"` # to add search paths. - find_package(SDL3 CONFIG REQUIRED) + if(NOT USE_SDL2) + find_package(SDL3 CONFIG REQUIRED) + else() + find_package(SDL2 CONFIG REQUIRED) + add_subdirectory(3rdparty/sdl3-shim SYSTEM) + endif() find_package(iniparser REQUIRED CONFIG COMPONENTS shared) target_link_libraries(Isle::iniparser INTERFACE iniparser-shared) diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index c7444362..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); @@ -879,20 +887,34 @@ 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, 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 +936,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/ISLE/isledebug.cpp b/ISLE/isledebug.cpp index ab3433a5..111e05ca 100644 --- a/ISLE/isledebug.cpp +++ b/ISLE/isledebug.cpp @@ -12,8 +12,19 @@ #include "mxticklemanager.h" #include +#if SDL_MAJOR_VERSION >= 3 #include #include +#else +#include +#include +#define ImGui_ImplSDL3_InitForSDLRenderer ImGui_ImplSDL2_InitForSDLRenderer +#define ImGui_ImplSDLRenderer3_Init ImGui_ImplSDLRenderer2_Init +#define ImGui_ImplSDL3_ProcessEvent ImGui_ImplSDL2_ProcessEvent +#define ImGui_ImplSDLRenderer3_NewFrame ImGui_ImplSDLRenderer2_NewFrame +#define ImGui_ImplSDL3_NewFrame ImGui_ImplSDL2_NewFrame +#define ImGui_ImplSDLRenderer3_RenderDrawData ImGui_ImplSDLRenderer2_RenderDrawData +#endif #include #ifdef ISLE_VALGRIND @@ -221,7 +232,11 @@ bool IsleDebug_Event(SDL_Event* event) return false; } if (event->type == SDL_EVENT_KEY_DOWN) { +#if SDL_MAJOR_VERSION >= 3 if (event->key.scancode == SCANCODE_KEY_PAUSE) { +#else + if (event->key.keysym.scancode == SCANCODE_KEY_PAUSE) { +#endif if (!g_debugPaused) { IsleDebug_SetPaused(true); } @@ -230,7 +245,11 @@ bool IsleDebug_Event(SDL_Event* event) } return true; } +#if SDL_MAJOR_VERSION >= 3 if (event->key.scancode == SCANCODE_KEY_RESUME) { +#else + if (event->key.keysym.scancode == SCANCODE_KEY_RESUME) { +#endif g_debugDoStep = false; if (g_debugPaused) { IsleDebug_SetPaused(false); diff --git a/LEGO1/lego/legoomni/include/legoinputmanager.h b/LEGO1/lego/legoomni/include/legoinputmanager.h index f8a4bb0a..2a6a0f0b 100644 --- a/LEGO1/lego/legoomni/include/legoinputmanager.h +++ b/LEGO1/lego/legoomni/include/legoinputmanager.h @@ -8,6 +8,7 @@ #include "mxpresenter.h" #include "mxqueue.h" +#include #include #include #include diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index f8ef1bab..3c06c378 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -31,9 +31,12 @@ #include "realtime/realtime.h" #include "scripts.h" -#include +#if SDL_MAJOR_VERSION >= 3 #include +#endif +#include #include +#include #include #include #include @@ -322,8 +325,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); diff --git a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp index 613e5b9f..a5b6cccf 100644 --- a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp +++ b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp @@ -13,6 +13,7 @@ #include "roi/legoroi.h" #include +#include DECOMP_SIZE_ASSERT(LegoInputManager, 0x338) DECOMP_SIZE_ASSERT(LegoNotifyList, 0x18) @@ -783,14 +784,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{1}; +#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{1}; +#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{1}; +#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 f09f0cf1..4266e7b4 100644 --- a/LEGO1/mxdirectx/mxdirect3d.cpp +++ b/LEGO1/mxdirectx/mxdirect3d.cpp @@ -72,11 +72,16 @@ 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..3cee2c53 100644 --- a/LEGO1/mxdirectx/mxdirectxinfo.cpp +++ b/LEGO1/mxdirectx/mxdirectxinfo.cpp @@ -3,6 +3,7 @@ #include "omni/include/mxvideoparam.h" #include +#include #include #include #include // for vsprintf @@ -228,11 +229,16 @@ 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..ad072070 100644 --- a/LEGO1/omni/src/system/mxthread.cpp +++ b/LEGO1/omni/src/system/mxthread.cpp @@ -3,6 +3,7 @@ #include "decomp.h" #include +#include DECOMP_SIZE_ASSERT(MxThread, 0x1c) @@ -34,6 +35,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 +46,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; diff --git a/miniwin/CMakeLists.txt b/miniwin/CMakeLists.txt index 07f40b04..e80ec5b1 100644 --- a/miniwin/CMakeLists.txt +++ b/miniwin/CMakeLists.txt @@ -28,7 +28,9 @@ target_compile_definitions(miniwin PRIVATE ) list(APPEND GRAPHICS_BACKENDS USE_SOFTWARE_RENDER) -list(APPEND GRAPHICS_BACKENDS USE_SDL_GPU) +if(NOT USE_SDL2) + list(APPEND GRAPHICS_BACKENDS USE_SDL_GPU) +endif() if(NOT WINDOWS_STORE) find_package(OpenGL) @@ -116,11 +118,16 @@ endif() target_compile_definitions(miniwin PUBLIC MINIWIN) +target_include_directories(miniwin PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src/internal +) + +if(USE_SDL_GPU IN_LIST GRAPHICS_BACKENDS) target_include_directories(miniwin PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/src/internal ${CMAKE_CURRENT_SOURCE_DIR}/src/d3drm/backends/sdl3gpu/shaders/generated ) +endif() target_link_libraries(miniwin PUBLIC miniwin-headers) target_link_libraries(miniwin PRIVATE SDL3::SDL3) @@ -129,7 +136,7 @@ target_compile_definitions(miniwin PUBLIC ${GRAPHICS_BACKENDS}) # Shader stuff - +if(USE_SDL_GPU IN_LIST GRAPHICS_BACKENDS) set(shader_src_dir "${CMAKE_CURRENT_SOURCE_DIR}/src/d3drm/backends/sdl3gpu/shaders/src") set(shader_gen_dir "${CMAKE_CURRENT_SOURCE_DIR}/src/d3drm/backends/sdl3gpu/shaders/generated") set(py_gencshadersource "${CMAKE_CURRENT_SOURCE_DIR}/src/d3drm/backends/sdl3gpu/shaders/gencshadersource.py") @@ -213,7 +220,7 @@ endforeach() set(index_cpp "${shader_gen_dir}/ShaderIndex.cpp") set(index_h "${shader_gen_dir}/ShaderIndex.h") - +endif() if(ISLE_COMPILE_SHADERS) add_custom_command(OUTPUT "${index_h}" "${index_cpp}" COMMAND Python3::Interpreter "${py_gencshadersource}" "index" diff --git a/miniwin/src/ddraw/ddraw.cpp b/miniwin/src/ddraw/ddraw.cpp index b28a105b..bd35018a 100644 --- a/miniwin/src/ddraw/ddraw.cpp +++ b/miniwin/src/ddraw/ddraw.cpp @@ -152,7 +152,7 @@ HRESULT DirectDrawImpl::EnumDisplayModes( #ifdef MINIWIN_PIXELFORMAT format = MINIWIN_PIXELFORMAT; #else - format = modes[i]->format; + format = static_cast(modes[i]->format); #endif const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(format); @@ -245,7 +245,7 @@ HRESULT DirectDrawImpl::GetDisplayMode(LPDDSURFACEDESC lpDDSurfaceDesc) #ifdef MINIWIN_PIXELFORMAT format = MINIWIN_PIXELFORMAT; #else - format = mode->format; + format = static_cast(mode->format); #endif const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(format);