From d8fe5f960fc5b17fe4862e00e92c42c8ed01ef9b Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 2 Sep 2025 18:09:26 -0400 Subject: [PATCH 01/16] build --- 3rdparty/CMakeLists.txt | 83 +++++++++++++++++++++++++++++------------ CMakeLists.txt | 3 ++ miniwin/CMakeLists.txt | 15 ++++++-- 3 files changed, 73 insertions(+), 28 deletions(-) diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 54259e63..3ac4a72f 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -48,31 +48,33 @@ 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 + ${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 "") +endif() if(DOWNLOAD_DEPENDENCIES) include(FetchContent) @@ -93,3 +95,36 @@ add_library(libweaver STATIC ${libweaver_SOURCE_DIR}/lib/sitypes.cpp ) target_include_directories(libweaver PUBLIC ${libweaver_SOURCE_DIR}/lib) + +if(USE_SDL2) + if(DOWNLOAD_DEPENDENCIES) +# include(FetchContent) +# FetchContent_Declare( +# SDL2 +# GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git" +# GIT_TAG 5d249570393f7a37e037abf22cd6012a4cc56a71 +# EXCLUDE_FROM_ALL +# ) +# FetchContent_MakeAvailable(SDL2) + # Find SDL2 normally + find_package(SDL2 REQUIRED) + + endif() + + 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-shim/SDL3/${fname} COPYONLY) + 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::SDL3 ALIAS SDL3_shim) + + add_library(SDL3::Headers ALIAS SDL3_shim) + +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index deebda7e..dff8bd5c 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" ON) 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) @@ -74,6 +75,7 @@ if (DOWNLOAD_DEPENDENCIES) message(STATUS "Fetching SDL3 and iniparser. This might take a while...") include(FetchContent) + if(NOT USE_SDL2) if(ANDROID) # Built by Gradle find_package(SDL3 REQUIRED CONFIG COMPONENTS Shared) @@ -95,6 +97,7 @@ if (DOWNLOAD_DEPENDENCIES) endif() FetchContent_MakeAvailable(SDL3) endif() + endif() FetchContent_Declare( iniparser 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" From 6b177afbd607a3ebeea674c7a1e39c70039d7e4a Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 2 Sep 2025 22:28:10 -0400 Subject: [PATCH 02/16] checkpoint --- 3rdparty/sdl3-shim/SDL3/SDL.h | 120 ++++++++++++++++++ 3rdparty/sdl3-shim/SDL3/SDL_events.h | 18 +++ 3rdparty/sdl3-shim/SDL3/SDL_gamepad.h | 7 + 3rdparty/sdl3-shim/SDL3/SDL_iostream.h | 49 +++++++ 3rdparty/sdl3-shim/SDL3/SDL_mutex.h | 11 ++ 3rdparty/sdl3-shim/SDL3/SDL_pixels.h | 24 ++++ 3rdparty/sdl3-shim/SDL3/SDL_surface.h | 34 +++++ 3rdparty/sdl3-shim/SDL3/SDL_timer.h | 11 ++ .../lego/legoomni/include/legoinputmanager.h | 1 + miniwin/src/ddraw/ddraw.cpp | 4 +- 10 files changed, 277 insertions(+), 2 deletions(-) create mode 100644 3rdparty/sdl3-shim/SDL3/SDL.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_events.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_gamepad.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_iostream.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_mutex.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_pixels.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_surface.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_timer.h diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h new file mode 100644 index 00000000..6244a1ac --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -0,0 +1,120 @@ +#pragma once + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_stdinch +#define SDL_bool bool + +#include +#include "SDL_events.h" +#include "SDL_gamepad.h" +#include "SDL_iostream.h" +#include "SDL_keyboard.h" +#include "SDL_mutex.h" +#include "SDL_pixels.h" +#include "SDL_surface.h" +#include "SDL_timer.h" + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_logh + +#define SDL_LogTrace SDL_LogVerbose + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh + +typedef Uint32 SDL_DisplayID; +inline SDL_DisplayID SDL_GetPrimaryDisplay() +{ + return 0; +} + +// Modified from 83bb0f9105922fd49282f0b931f7873a71877ac8 SDL_video.c#L1331 +inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID 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)); + if (result) { + SDL_DisplayMode *modes = (SDL_DisplayMode *)((Uint8 *)result + ((num_modes + 1) * sizeof(*result))); + for (i = 0; i < num_modes; ++i) { + if (SDL_GetDisplayMode(displayID, i, &modes[i]) == 0) { + result[i] = modes++; + } + } + result[i] = NULL; + + if (count) { + *count = num_modes; + } + SDL_free(modes); + } else { + if (count) { + *count = 0; + } + } + return result; +} + +inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID) +{ + SDL_DisplayMode* mode = nullptr; + SDL_GetCurrentDisplayMode(displayID, mode); + return mode; +} + +#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 + +// 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; + + +#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 +#define SDL_PlayHapticRumble SDL_HapticRumblePlay + +#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; +} + diff --git a/3rdparty/sdl3-shim/SDL3/SDL_events.h b/3rdparty/sdl3-shim/SDL3/SDL_events.h new file mode 100644 index 00000000..20913d29 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_events.h @@ -0,0 +1,18 @@ +#pragma once + +#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_FINGER_CANCELED 0 + +#define SDL_EVENT_QUIT SDL_QUIT diff --git a/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h b/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h new file mode 100644 index 00000000..a5fc3fd6 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_gamepad.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_gamecontrollerh + +#define SDL_Gamepad SDL_GameController 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_mutex.h b/3rdparty/sdl3-shim/SDL3/SDL_mutex.h new file mode 100644 index 00000000..5cc68743 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_mutex.h @@ -0,0 +1,11 @@ +#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 diff --git a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h new file mode 100644 index 00000000..e057d3e4 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h @@ -0,0 +1,24 @@ +#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) + +#define SDL_GetPixelFormatDetails SDL_AllocFormat + +#define SDL_CreatePalette SDL_AllocPalette +#define SDL_DestroyPalette SDL_FreePalette + +#define SDL_GetPixelFormatForMasks (SDL_PixelFormat)SDL_MasksToPixelFormatEnum + +#define SDL_GetSurfacePalette(surface) (nullptr) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_surface.h b/3rdparty/sdl3-shim/SDL3/SDL_surface.h new file mode 100644 index 00000000..87c22922 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_surface.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include "SDL_pixels.h" + +// https://wiki.libsdl.org/SDL3/README-migration#sdl_surfaceh +struct SDL_SurfaceShim : SDL_Surface { + SDL_PixelFormat format; + + explicit SDL_SurfaceShim(const SDL_Surface* s) + : SDL_Surface(*s), format(static_cast(s->format->format)) {} +}; +#define SDL_Surface SDL_SurfaceShim + +#define SDL_FillSurfaceRect(...) (SDL_FillRect(__VA_ARGS__) == 0) + +// #define SDL_ConvertSurface(...) SDL_ConvertSurface(__VA_ARGS__, 0) + +#define SDL_DestroySurface SDL_FreeSurface + +#define SDL_CreateSurface(width, height, format) (SDL_Surface*)SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format) ,format) + +inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, SDL_PixelFormat format) +{ + const SDL_PixelFormatDetails* formatDetails = SDL_AllocFormat(format); + return static_cast(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 + diff --git a/3rdparty/sdl3-shim/SDL3/SDL_timer.h b/3rdparty/sdl3-shim/SDL3/SDL_timer.h new file mode 100644 index 00000000..8c4b9220 --- /dev/null +++ b/3rdparty/sdl3-shim/SDL3/SDL_timer.h @@ -0,0 +1,11 @@ +#pragma once + +#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) 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/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); From a7f7ea9e14725b458058af5ecdb8856de7e9ae9b Mon Sep 17 00:00:00 2001 From: Kylie C Date: Fri, 5 Sep 2025 00:29:22 -0400 Subject: [PATCH 03/16] legoomni compiles --- 3rdparty/sdl3-shim/SDL3/SDL.h | 60 +++++++++- 3rdparty/sdl3-shim/SDL3/SDL_audio.h | 101 +++++++++++++++++ 3rdparty/sdl3-shim/SDL3/SDL_events.h | 67 +++++++++-- 3rdparty/sdl3-shim/SDL3/SDL_filesystem.h | 50 +++++++++ 3rdparty/sdl3-shim/SDL3/SDL_gamepad.h | 104 ++++++++++++++++++ 3rdparty/sdl3-shim/SDL3/SDL_iostream.h | 2 +- 3rdparty/sdl3-shim/SDL3/SDL_keycode.h | 60 ++++++++++ 3rdparty/sdl3-shim/SDL3/SDL_mutex.h | 3 +- 3rdparty/sdl3-shim/SDL3/SDL_pixels.h | 2 +- 3rdparty/sdl3-shim/SDL3/SDL_surface.h | 4 +- 3rdparty/sdl3-shim/SDL3/SDL_timer.h | 57 +++++++++- ISLE/isleapp.cpp | 23 +++- .../legoomni/src/input/legoinputmanager.cpp | 12 ++ LEGO1/mxdirectx/mxdirect3d.cpp | 7 ++ LEGO1/mxdirectx/mxdirectxinfo.cpp | 7 ++ LEGO1/omni/src/system/mxthread.cpp | 6 + 16 files changed, 549 insertions(+), 16 deletions(-) create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_audio.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_filesystem.h create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_keycode.h 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; From 6ac4693c0be35c6442e23024048f112aebca0747 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Fri, 5 Sep 2025 00:58:16 -0400 Subject: [PATCH 04/16] clang-format --- ISLE/isleapp.cpp | 4 +++- LEGO1/mxdirectx/mxdirect3d.cpp | 6 ++---- LEGO1/mxdirectx/mxdirectxinfo.cpp | 6 ++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index 4ea8d66a..53d2a83c 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -900,7 +900,9 @@ MxResult IsleApp::SetupWindow() #else Uint32 flags = 0; flags |= SDL_WINDOW_OPENGL; - if (m_fullScreen) flags |= SDL_WINDOW_FULLSCREEN; + if (m_fullScreen) { + flags |= SDL_WINDOW_FULLSCREEN; + } window = SDL_CreateWindow( WINDOW_TITLE, SDL_WINDOWPOS_CENTERED, diff --git a/LEGO1/mxdirectx/mxdirect3d.cpp b/LEGO1/mxdirectx/mxdirect3d.cpp index 6a8cdd25..0f75b503 100644 --- a/LEGO1/mxdirectx/mxdirect3d.cpp +++ b/LEGO1/mxdirectx/mxdirect3d.cpp @@ -78,10 +78,8 @@ BOOL MxDirect3D::Create( nullptr ); #else - MxVideoParam* videoParam = (MxVideoParam*) SDL_GetWindowData( - reinterpret_cast(hWnd), - ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM - ); + MxVideoParam* videoParam = + (MxVideoParam*) SDL_GetWindowData(reinterpret_cast(hWnd), ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM); #endif #ifndef MXDIRECTX_FOR_CONFIG assert(videoParam); diff --git a/LEGO1/mxdirectx/mxdirectxinfo.cpp b/LEGO1/mxdirectx/mxdirectxinfo.cpp index b8ee33ad..c89ebbd3 100644 --- a/LEGO1/mxdirectx/mxdirectxinfo.cpp +++ b/LEGO1/mxdirectx/mxdirectxinfo.cpp @@ -235,10 +235,8 @@ BOOL MxDeviceEnumerate::EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc nullptr ); #else - MxVideoParam* videoParam = (MxVideoParam*) SDL_GetWindowData( - reinterpret_cast(m_hWnd), - ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM - ); + MxVideoParam* videoParam = (MxVideoParam*) + SDL_GetWindowData(reinterpret_cast(m_hWnd), ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM); #endif #ifndef MXDIRECTX_FOR_CONFIG assert(videoParam); From ab5fac59b4dfc3e834e0f67afc1b95c288c4e8fa Mon Sep 17 00:00:00 2001 From: Kylie C Date: Fri, 5 Sep 2025 01:27:21 -0400 Subject: [PATCH 05/16] bool conversion forgot these --- 3rdparty/sdl3-shim/SDL3/SDL.h | 8 ++++---- 3rdparty/sdl3-shim/SDL3/SDL_audio.h | 2 +- 3rdparty/sdl3-shim/SDL3/SDL_surface.h | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index e62d2e05..548b3b6b 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -94,7 +94,7 @@ inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID) // 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 +#define SDL_RenderTexture(...) (SDL_RenderCopyF(__VA_ARGS__) == 0) // https://wiki.libsdl.org/SDL3/README-migration#sdl_haptich // SDL_MouseID/SDL_KeyboardID are new @@ -109,8 +109,8 @@ typedef int SDL_HapticID; #define SDL_OpenHaptic SDL_HapticOpen #define SDL_OpenHapticFromJoystick SDL_HapticOpenFromJoystick #define SDL_OpenHapticFromMouse SDL_HapticOpenFromMouse -#define SDL_InitHapticRumble SDL_HapticRumbleInit -#define SDL_PlayHapticRumble SDL_HapticRumblePlay +#define SDL_InitHapticRumble(...) (SDL_HapticRumbleInit(__VA_ARGS__) == 0) +#define SDL_PlayHapticRumble(...) (SDL_HapticRumblePlay(__VA_ARGS__) == 0) #define SDL_GetHapticID SDL_HapticIndex @@ -143,7 +143,7 @@ inline SDL_HapticID* SDL_GetHaptics(int *count) // https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh #define SDL_GetDisplayForWindow SDL_GetWindowDisplayIndex -#define SDL_SetWindowFullscreenMode SDL_SetWindowDisplayMode +#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) { diff --git a/3rdparty/sdl3-shim/SDL3/SDL_audio.h b/3rdparty/sdl3-shim/SDL3/SDL_audio.h index 397f356e..43178147 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_audio.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_audio.h @@ -54,7 +54,7 @@ static void SDLCALL shim_audio_callback(void *userdata, Uint8 *stream, int len) } #define SDL_ResumeAudioDevice(device) SDL_PauseAudioDevice(device, 0) -#define SDL_PutAudioStreamData SDL_AudioStreamPut +#define SDL_PutAudioStreamData(...) (SDL_AudioStreamPut(__VA_ARGS__) == 0) inline SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream* stream) { diff --git a/3rdparty/sdl3-shim/SDL3/SDL_surface.h b/3rdparty/sdl3-shim/SDL3/SDL_surface.h index d943eee4..eaf2241a 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_surface.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_surface.h @@ -14,8 +14,6 @@ struct SDL_SurfaceShim : SDL_Surface { #define SDL_FillSurfaceRect(...) (SDL_FillRect(__VA_ARGS__) == 0) -// #define SDL_ConvertSurface(...) SDL_ConvertSurface(__VA_ARGS__, 0) - #define SDL_DestroySurface SDL_FreeSurface #define SDL_CreateSurface(width, height, format) (SDL_Surface*)SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format) ,format) @@ -30,7 +28,7 @@ inline SDL_Surface* SDL_ConvertSurface(SDL_Surface* surface, SDL_PixelFormat for #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 +#define SDL_SetSurfaceColorKey(...) (SDL_SetColorKey(__VA_ARGS__) == 0) #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 From cc6d3ee5635cc8bb5222ccc511bffc1821592548 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Fri, 5 Sep 2025 01:44:05 -0400 Subject: [PATCH 06/16] default USE_SDL2 off --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dff8bd5c..522b3d4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,11 +55,17 @@ 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" 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) +if(USE_SDL2) + add_compile_definitions(SDL_MAJOR_VERSION=2) +else() + add_compile_definitions(SDL_MAJOR_VERSION=3) +endif() + message(STATUS "Isle app: ${ISLE_BUILD_APP}") message(STATUS "Config app: ${ISLE_BUILD_CONFIG}") message(STATUS "Internal DirectX5 SDK: ${ISLE_USE_DX5}") From 68a4ee445d9d02a20048a673f483f492e11bf119 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Fri, 5 Sep 2025 06:59:24 -0400 Subject: [PATCH 07/16] get CONFIG working compiles and runs. more bool conversions fix memory issues --- 3rdparty/sdl3-shim/SDL3/SDL.h | 41 ++++++++++++++++----------- 3rdparty/sdl3-shim/SDL3/SDL_pixels.h | 15 +++++++++- 3rdparty/sdl3-shim/SDL3/SDL_surface.h | 31 ++++++++++++-------- ISLE/isleapp.cpp | 9 +----- 4 files changed, 58 insertions(+), 38 deletions(-) diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index 548b3b6b..f6f3640d 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -54,25 +54,24 @@ inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, if (count) *count = 0; const int num_modes = SDL_GetNumDisplayModes(displayID); - SDL_DisplayMode** result = static_cast(SDL_malloc(sizeof(SDL_DisplayMode*) * num_modes)); - if (result) { - SDL_DisplayMode *modes = (SDL_DisplayMode *)((Uint8 *)result + ((num_modes + 1) * sizeof(*result))); - for (i = 0; i < num_modes; ++i) { - if (SDL_GetDisplayMode(displayID, i, &modes[i]) == 0) { - result[i] = modes++; - } - } - result[i] = NULL; - - if (count) { - *count = num_modes; - } + 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); - } else { - if (count) { - *count = 0; - } + 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; } @@ -142,6 +141,11 @@ inline SDL_HapticID* SDL_GetHaptics(int *count) // 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 @@ -176,3 +180,6 @@ static void SDL_ShowCursor() { SDL_ShowCursor(SDL_ENABLE); } #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_pixels.h b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h index 36443152..b439434d 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h @@ -14,7 +14,20 @@ typedef SDL_PixelFormat SDL2_PixelFormat; #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) -#define SDL_GetPixelFormatDetails SDL_AllocFormat +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 diff --git a/3rdparty/sdl3-shim/SDL3/SDL_surface.h b/3rdparty/sdl3-shim/SDL3/SDL_surface.h index eaf2241a..792eb37c 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_surface.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_surface.h @@ -4,25 +4,33 @@ #include "SDL_pixels.h" // https://wiki.libsdl.org/SDL3/README-migration#sdl_surfaceh -struct SDL_SurfaceShim : SDL_Surface { - SDL_PixelFormat format; - - explicit SDL_SurfaceShim(const SDL_Surface* s) - : SDL_Surface(*s), format(static_cast(s->format->format)) {} -}; -#define SDL_Surface SDL_SurfaceShim #define SDL_FillSurfaceRect(...) (SDL_FillRect(__VA_ARGS__) == 0) #define SDL_DestroySurface SDL_FreeSurface -#define SDL_CreateSurface(width, height, format) (SDL_Surface*)SDL_CreateRGBSurfaceWithFormat(0 , width, height, SDL_BITSPERPIXEL(format) ,format) +#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) { - const SDL_PixelFormatDetails* formatDetails = SDL_AllocFormat(format); - return static_cast(SDL_ConvertSurface(surface, formatDetails, 0)); + SDL_PixelFormatDetails* formatDetails = SDL_AllocFormat(format); + SDL_Surface* result = SDL_ConvertSurface(surface, formatDetails, 0); + SDL_free(formatDetails); + return result; }; +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 @@ -30,5 +38,4 @@ 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(__VA_ARGS__) == 0) -#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 +#define SDL_LoadBMP_IO SDL_LoadBMP_RW diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index 53d2a83c..64667f2c 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -903,14 +903,7 @@ MxResult IsleApp::SetupWindow() if (m_fullScreen) { flags |= SDL_WINDOW_FULLSCREEN; } - window = SDL_CreateWindow( - WINDOW_TITLE, - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - g_targetWidth, - g_targetHeight, - flags - ); + window = SDL_CreateWindow(WINDOW_TITLE, g_targetWidth, g_targetHeight, flags); SDL_SetWindowData(window, ISLE_PROP_WINDOW_CREATE_VIDEO_PARAM, &m_videoParam); #endif From d8a584268e3086d9c11846e9834a808d805eff8f Mon Sep 17 00:00:00 2001 From: Kylie C Date: Fri, 5 Sep 2025 20:37:31 -0400 Subject: [PATCH 08/16] ISLE compiles & starts SDL_filesystem is just stubs so it cannot read any game data --- 3rdparty/CMakeLists.txt | 13 ++++++++----- 3rdparty/sdl3-shim/SDL3/SDL.h | 16 ++++++++++------ 3rdparty/sdl3-shim/SDL3/SDL_audio.h | 8 ++++---- 3rdparty/sdl3-shim/SDL3/SDL_events.h | 3 ++- 3rdparty/sdl3-shim/SDL3/SDL_filesystem.h | 4 ++-- 3rdparty/sdl3-shim/SDL3/SDL_gamepad.h | 2 +- 3rdparty/sdl3-shim/SDL3/SDL_iostream.h | 2 +- 3rdparty/sdl3-shim/SDL3/SDL_keycode.h | 2 +- 3rdparty/sdl3-shim/SDL3/SDL_main.h | 13 +++++++++++++ 3rdparty/sdl3-shim/SDL3/SDL_mutex.h | 2 +- 3rdparty/sdl3-shim/SDL3/SDL_pixels.h | 4 ++-- 3rdparty/sdl3-shim/SDL3/SDL_surface.h | 7 ++----- 3rdparty/sdl3-shim/SDL3/SDL_timer.h | 8 ++++++-- 3rdparty/sdl3-shim/main.cpp | 20 ++++++++++++++++++++ ISLE/isleapp.cpp | 10 +++++++++- LEGO1/lego/legoomni/src/common/legoutils.cpp | 2 ++ 16 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_main.h create mode 100644 3rdparty/sdl3-shim/main.cpp 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); From 75306f412d28db08ecea193ca3fa222bec8bc53c Mon Sep 17 00:00:00 2001 From: Kylie C Date: Sat, 6 Sep 2025 00:59:53 -0400 Subject: [PATCH 09/16] filesystem access --- 3rdparty/sdl3-shim/SDL3/SDL_filesystem.h | 75 ++++++++++++++++++++---- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h b/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h index b1e8f8b0..7515241a 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_filesystem.h @@ -3,7 +3,8 @@ #include "SDL.h" #include "SDL_iostream.h" -// TODO: properly implement ( +#include +#include typedef Uint32 SDL_GlobFlags; @@ -15,36 +16,86 @@ typedef enum SDL_PathType 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 NULL; + 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) { - return SDL_Unsupported(); + 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) { - return SDL_Unsupported(); + 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) { - return SDL_Unsupported(); + 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; } From 9614c0b97b6ca35cab84c6be80553c5bba0a5f34 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 14 Oct 2025 22:32:30 -0400 Subject: [PATCH 10/16] audio & correct mouse/keyboard indexing Create the mutexes properly --- 3rdparty/sdl3-shim/SDL3/SDL.h | 11 ++- 3rdparty/sdl3-shim/SDL3/SDL_audio.h | 96 ++++++++++--------- 3rdparty/sdl3-shim/SDL3/SDL_timer.h | 2 +- .../legoomni/src/input/legoinputmanager.cpp | 6 +- 4 files changed, 67 insertions(+), 48 deletions(-) diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index 0debbc81..838e8a6f 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -96,10 +96,19 @@ inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID) #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 -typedef int SDL_KeyboardID; #define SDL_GetKeyboardState (const bool*)SDL_GetKeyboardState typedef int SDL_HapticID; diff --git a/3rdparty/sdl3-shim/SDL3/SDL_audio.h b/3rdparty/sdl3-shim/SDL3/SDL_audio.h index d66cb2f9..3520469f 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_audio.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_audio.h @@ -7,8 +7,6 @@ // 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 @@ -16,40 +14,31 @@ 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 = NULL; +static std::map g_audioCtxs; +static SDL_mutex *g_audioMutex = SDL_CreateMutex(); -static void SDLCALL shim_audio_callback(void *userdata, Uint8 *stream, int len) { - SDL_AudioDeviceID devid = reinterpret_cast(userdata); +static void shim_audio_callback(void *userdata, Uint8 *data_stream, int len) { + const auto ctx = static_cast(userdata); + SDL_AudioStream* audio_stream = ctx->stream; - 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; - } + int available = SDL_AudioStreamAvailable(audio_stream); - ShimAudioCtx &ctx = it->second; - SDL_UnlockMutex(g_audioMutex); + int additional_amount = len - available; + if (additional_amount < 0) + additional_amount = 0; - // 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; + ctx->callback(ctx->userdata, audio_stream, additional_amount, len); - 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); + int retrieved = SDL_AudioStreamGet(audio_stream, data_stream, len); + if (retrieved < len) { + memset(data_stream + retrieved, ctx->obtained.silence, len - retrieved); } } @@ -59,43 +48,64 @@ static void SDLCALL shim_audio_callback(void *userdata, Uint8 *stream, int len) inline SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream* stream) { SDL_LockMutex(g_audioMutex); - const auto it = g_audioCtxs.find(reinterpret_cast(stream)); + const auto it = g_audioCtxs.find(stream); if (it == g_audioCtxs.end()) { return 0; } - return it->first; + 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 = reinterpret_cast(static_cast(0)); - SDL_AudioDeviceID device = SDL_OpenAudioDevice(devid, 0, &desired2, &obtained, 0); + 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); - return nullptr; + delete ctx; + return NULL; } - { - 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); - } + ctx->device = device; + ctx->stream = stream; + ctx->obtained = obtained; - SDL_LockAudioDevice(device); - desired2.userdata = reinterpret_cast(static_cast(device)); - SDL_UnlockAudioDevice(device); + 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_timer.h b/3rdparty/sdl3-shim/SDL3/SDL_timer.h index 5cdff813..57ff2d62 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_timer.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_timer.h @@ -22,7 +22,7 @@ struct SDL2TimerShimData { }; static std::map g_timers; -static SDL_mutex *g_timerMutex = NULL; +static SDL_mutex *g_timerMutex = SDL_CreateMutex(); inline Uint32 shim_timer_callback (Uint32 interval, void *param) { diff --git a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp index 82963f58..52f448f3 100644 --- a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp +++ b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp @@ -785,7 +785,7 @@ void LegoInputManager::UpdateLastInputMethod(SDL_Event* p_event) #if SDL_MAJOR_VERSION >= 3 m_lastInputMethod = SDL_KeyboardID_v{p_event->key.which}; #else - m_lastInputMethod = SDL_KeyboardID_v{0}; + m_lastInputMethod = SDL_KeyboardID_v{1}; #endif break; case SDL_EVENT_MOUSE_BUTTON_DOWN: @@ -793,14 +793,14 @@ void LegoInputManager::UpdateLastInputMethod(SDL_Event* p_event) #if SDL_MAJOR_VERSION >= 3 m_lastInputMethod = SDL_MouseID_v{p_event->button.which}; #else - m_lastInputMethod = SDL_MouseID_v{0}; + 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{0}; + m_lastInputMethod = SDL_MouseID_v{1}; #endif break; case SDL_EVENT_GAMEPAD_BUTTON_DOWN: From 98249834ffacfb3642a64dfde1c00f789372c8b9 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Sat, 18 Oct 2025 02:19:31 -0400 Subject: [PATCH 11/16] fix incorrect assumptions with display + clang format --- 3rdparty/sdl3-shim/SDL3/SDL.h | 24 +++++++++++++++------- 3rdparty/sdl3-shim/SDL3/SDL_events.h | 12 +++++------ 3rdparty/sdl3-shim/SDL3/SDL_timer.h | 30 +++++++++++++++------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index 838e8a6f..5286997d 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -42,14 +42,14 @@ inline float SDL_randf() // https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh -typedef Uint32 SDL_DisplayID; +typedef int SDL_DisplayID; inline SDL_DisplayID SDL_GetPrimaryDisplay() { - return 0; + return 1; } // Modified from 83bb0f9105922fd49282f0b931f7873a71877ac8 SDL_video.c#L1331 -inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count) +inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(int displayID, int* count) { int i; if (count) *count = 0; @@ -76,11 +76,21 @@ inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, return result; } -inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID) +inline SDL_DisplayMode g_displayMode; +inline SDL_mutex* g_displayMutex = SDL_CreateMutex(); + +// This does not handle the differences between the SDL_DisplayMode struct +// https://wiki.libsdl.org/SDL3/SDL_DisplayMode +// https://wiki.libsdl.org/SDL2/SDL_DisplayMode +inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(int displayID) { - SDL_DisplayMode* mode = nullptr; - SDL_GetCurrentDisplayMode(displayID, mode); - return mode; + SDL_LockMutex(g_displayMutex); + if (SDL_GetCurrentDisplayMode(displayID, &g_displayMode) == 0) { + SDL_UnlockMutex(g_timerMutex); + return &g_displayMode; + } + SDL_UnlockMutex(g_timerMutex); + return NULL; } #define SDL_GetWindowSize(...) (SDL_GetWindowSize(__VA_ARGS__), true ) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_events.h b/3rdparty/sdl3-shim/SDL3/SDL_events.h index 3e11a170..8d6b514a 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_events.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_events.h @@ -1,11 +1,15 @@ #pragma once #include "SDL.h" + #include // https://wiki.libsdl.org/SDL3/README-migration#sdl_eventsh -#define SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED SDL_WINDOWEVENT_SIZE_CHANGED +#define SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED (SDL_WINDOWEVENT + 2 + SDL_WINDOWEVENT_SIZE_CHANGED) +#define SDL_EVENT_WINDOW_CLOSE_REQUESTED (SDL_WINDOWEVENT + 2 + SDL_WINDOWEVENT_CLOSE) +#define SDL_EVENT_WINDOW_FOCUS_GAINED (SDL_WINDOWEVENT + 2 + SDL_WINDOWEVENT_FOCUS_GAINED) +#define SDL_EVENT_WINDOW_FOCUS_LOST (SDL_WINDOWEVENT + 2 + SDL_WINDOWEVENT_FOCUS_LOST) // #define SDL_EVENT_MOUSE_BUTTON_DOWN SDL_MOUSEBUTTONDOWN // #define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP @@ -18,12 +22,6 @@ #define SDL_EVENT_QUIT SDL_QUIT -#define SDL_EVENT_WINDOW_CLOSE_REQUESTED SDL_WINDOWEVENT_CLOSE - -#define SDL_EVENT_WINDOW_FOCUS_GAINED SDL_WINDOWEVENT_FOCUS_GAINED -#define SDL_EVENT_WINDOW_FOCUS_LOST SDL_WINDOWEVENT_FOCUS_LOST - - #define SDL_EVENT_GAMEPAD_AXIS_MOTION SDL_CONTROLLERAXISMOTION #define SDL_EVENT_GAMEPAD_BUTTON_DOWN SDL_CONTROLLERBUTTONDOWN #define SDL_EVENT_GAMEPAD_BUTTON_UP SDL_CONTROLLERBUTTONUP diff --git a/3rdparty/sdl3-shim/SDL3/SDL_timer.h b/3rdparty/sdl3-shim/SDL3/SDL_timer.h index 57ff2d62..37c736ee 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_timer.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_timer.h @@ -12,22 +12,21 @@ // time is in miliseconds not nanoseconds #define SDL_NS_TO_MS(MS) (MS) - -typedef Uint32 SDL3_TimerCallback (void *userdata, SDL_TimerID timerID, Uint32 interval); +typedef Uint32 SDL3_TimerCallback(void* userdata, SDL_TimerID timerID, Uint32 interval); struct SDL2TimerShimData { - SDL3_TimerCallback *callback2; - void *userdata2; + SDL3_TimerCallback* callback; + void* userdata; SDL_TimerID id; }; -static std::map g_timers; -static SDL_mutex *g_timerMutex = SDL_CreateMutex(); +inline std::map g_timers; +inline SDL_mutex* g_timerMutex = SDL_CreateMutex(); -inline Uint32 shim_timer_callback (Uint32 interval, void *param) +inline Uint32 shim_timer_callback(Uint32 interval, void* param) { - const auto shim = static_cast(param); - const Uint32 next = shim->callback2(shim->userdata2, shim->id, interval); + auto* shim = static_cast(param); + const Uint32 next = shim->callback(shim->userdata, shim->id, interval); if (next == 0) { SDL_LockMutex(g_timerMutex); @@ -39,13 +38,17 @@ inline Uint32 shim_timer_callback (Uint32 interval, void *param) return next; } -inline SDL_TimerID SDL_AddTimer(Uint32 interval, SDL3_TimerCallback callback3, void* userdata) +inline SDL_TimerID SDL_AddTimer(Uint32 interval, SDL3_TimerCallback* callback, void* userdata) { - const auto shim = static_cast(SDL_malloc(sizeof(SDL2TimerShimData))); - shim->callback2 = callback3; - shim->userdata2 = userdata; + auto* shim = static_cast(SDL_malloc(sizeof(SDL2TimerShimData))); + shim->callback = callback; + shim->userdata = userdata; const SDL_TimerID id = ::SDL_AddTimer(interval, shim_timer_callback, shim); + if (id == 0) { + SDL_free(shim); + return 0; + } shim->id = id; SDL_LockMutex(g_timerMutex); @@ -66,5 +69,4 @@ inline SDL_bool SDL_RemoveTimer2(SDL_TimerID id) return ::SDL_RemoveTimer(id); } - #define SDL_RemoveTimer SDL_RemoveTimer2 From 333867eb38ab9e728eba2b8589f9143f376536b5 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Sat, 18 Oct 2025 02:20:20 -0400 Subject: [PATCH 12/16] ISLE_DEBUG support and event changes --- 3rdparty/CMakeLists.txt | 15 ++++++- 3rdparty/sdl3-shim/SDL3/SDL_events.h | 58 ++++++++++++++++++++++++++++ 3rdparty/sdl3-shim/main.cpp | 10 +++++ ISLE/isledebug.cpp | 35 ++++++++++++++++- 4 files changed, 115 insertions(+), 3 deletions(-) diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index a1dffac7..10a527de 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -67,9 +67,19 @@ if(ISLE_DEBUG) ${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 ) + 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 PUBLIC SDL3::Headers) target_link_libraries(imgui PRIVATE SDL3::SDL3) @@ -123,6 +133,7 @@ if(USE_SDL2) ) target_link_libraries(SDL3_shim PRIVATE SDL2::SDL2) target_include_directories(SDL3_shim PUBLIC + ${SDL2_INCLUDE_DIRS} "${CMAKE_CURRENT_SOURCE_DIR}/sdl3-shim" "${CMAKE_CURRENT_BINARY_DIR}/sdl3-shim" ) diff --git a/3rdparty/sdl3-shim/SDL3/SDL_events.h b/3rdparty/sdl3-shim/SDL3/SDL_events.h index 8d6b514a..61113ed5 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_events.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_events.h @@ -3,6 +3,7 @@ #include "SDL.h" #include +#include // https://wiki.libsdl.org/SDL3/README-migration#sdl_eventsh @@ -66,3 +67,60 @@ #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/main.cpp b/3rdparty/sdl3-shim/main.cpp index b87237c7..7b46335d 100644 --- a/3rdparty/sdl3-shim/main.cpp +++ b/3rdparty/sdl3-shim/main.cpp @@ -2,6 +2,15 @@ #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) { @@ -11,6 +20,7 @@ int main(int argc, char *argv[]) { SDL_Event e; while (!SDL_AppIterate(appstate)) { while (SDL_PollEvent(&e)) { + TranslateSDLEvents(&e); SDL_AppEvent(appstate, &e); } } diff --git a/ISLE/isledebug.cpp b/ISLE/isledebug.cpp index ab3433a5..929f9c73 100644 --- a/ISLE/isledebug.cpp +++ b/ISLE/isledebug.cpp @@ -12,8 +12,13 @@ #include "mxticklemanager.h" #include +#if SDL_MAJOR_VERSION >= 3 #include #include +#else +#include +#include +#endif #include #ifdef ISLE_VALGRIND @@ -176,7 +181,11 @@ void IsleDebug_Init() ImGui::CreateContext(); ImGui::StyleColorsDark(); +#if SDL_MAJOR_VERSION >= 3 if (!ImGui_ImplSDL3_InitForSDLRenderer(g_debugWindow, g_debugRenderer)) { +#else + if (!ImGui_ImplSDL2_InitForSDLRenderer(g_debugWindow, g_debugRenderer)) { +#endif SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "ImGui_ImplSDL3_InitForSDLRenderer failed"); g_debugEnabled = false; break; @@ -188,7 +197,11 @@ void IsleDebug_Init() #else SDL_SetTextureScaleMode(g_videoPalette, SDL_SCALEMODE_NEAREST); #endif +#if SDL_MAJOR_VERSION >= 3 if (!ImGui_ImplSDLRenderer3_Init(g_debugRenderer)) { +#else + if (!ImGui_ImplSDLRenderer2_Init(g_debugRenderer)) { +#endif g_debugEnabled = false; break; } @@ -221,7 +234,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 +247,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); @@ -241,7 +262,11 @@ bool IsleDebug_Event(SDL_Event* event) if (SDL_GetWindowFromEvent(event) != g_debugWindow) { return false; } +#if SDL_MAJOR_VERSION >= 3 ImGui_ImplSDL3_ProcessEvent(event); +#else + ImGui_ImplSDL2_ProcessEvent(event); +#endif return true; } @@ -251,9 +276,13 @@ void IsleDebug_Render() return; } const ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - +#if SDL_MAJOR_VERSION >= 3 ImGui_ImplSDLRenderer3_NewFrame(); ImGui_ImplSDL3_NewFrame(); +#else + ImGui_ImplSDLRenderer2_NewFrame(); + ImGui_ImplSDL2_NewFrame(); +#endif ImGui::NewFrame(); ImGuiIO& io = ImGui::GetIO(); { @@ -346,7 +375,11 @@ void IsleDebug_Render() (Uint8) (clear_color.z * 255), (Uint8) (clear_color.w * 255) ); +#if SDL_MAJOR_VERSION >= 3 ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), g_debugRenderer); +#else + ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), g_debugRenderer); +#endif SDL_RenderPresent(g_debugRenderer); } From e0f1336a521413807bb04727dd32b3b9151787ed Mon Sep 17 00:00:00 2001 From: Kylie C Date: Mon, 20 Oct 2025 15:51:46 -0400 Subject: [PATCH 13/16] cleanup & fix oversight seems sdl2-compat doesn't translate the SDL_GetPixelFormatForMasks behaviour 1 to 1 :P --- 3rdparty/CMakeLists.txt | 42 +----------- 3rdparty/sdl3-shim/CMakeLists.txt | 18 ++++++ 3rdparty/sdl3-shim/SDL3/SDL.h | 1 + 3rdparty/sdl3-shim/SDL3/SDL_audio.h | 1 + 3rdparty/sdl3-shim/SDL3/SDL_pixels.h | 12 +++- CMakeLists.txt | 64 +++++++++++-------- ISLE/isledebug.cpp | 28 ++------ LEGO1/lego/legoomni/src/common/legoutils.cpp | 1 + .../legoomni/src/input/legoinputmanager.cpp | 1 + LEGO1/mxdirectx/mxdirectxinfo.cpp | 1 + LEGO1/omni/src/system/mxthread.cpp | 1 + 11 files changed, 82 insertions(+), 88 deletions(-) create mode 100644 3rdparty/sdl3-shim/CMakeLists.txt diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 10a527de..09f27988 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -75,13 +75,12 @@ if(ISLE_DEBUG) ) else() target_sources(imgui PRIVATE - ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp - ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp + ${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 PUBLIC SDL3::Headers) target_link_libraries(imgui PRIVATE SDL3::SDL3) set_property(TARGET imgui PROPERTY CXX_CLANG_TIDY "") endif() @@ -105,40 +104,3 @@ add_library(libweaver STATIC ${libweaver_SOURCE_DIR}/lib/sitypes.cpp ) target_include_directories(libweaver PUBLIC ${libweaver_SOURCE_DIR}/lib) - -if(USE_SDL2) - if(DOWNLOAD_DEPENDENCIES) -# include(FetchContent) -# FetchContent_Declare( -# SDL2 -# GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git" -# GIT_TAG 5d249570393f7a37e037abf22cd6012a4cc56a71 -# EXCLUDE_FROM_ALL -# ) -# FetchContent_MakeAvailable(SDL2) - # Find SDL2 normally - find_package(SDL2 REQUIRED) - - endif() - - 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-shim/SDL3/${fname} COPYONLY) - endforeach() - - - add_library(SDL3_shim STATIC - sdl3-shim/main.cpp - ) - target_link_libraries(SDL3_shim PRIVATE SDL2::SDL2) - target_include_directories(SDL3_shim PUBLIC - ${SDL2_INCLUDE_DIRS} - "${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/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 index 5286997d..fb16f4a3 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "SDL_audio.h" #include "SDL_events.h" diff --git a/3rdparty/sdl3-shim/SDL3/SDL_audio.h b/3rdparty/sdl3-shim/SDL3/SDL_audio.h index 3520469f..9c66a418 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_audio.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_audio.h @@ -2,6 +2,7 @@ #include "SDL.h" +#include #include #include diff --git a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h index fb8fd71c..6db5885e 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL_pixels.h +++ b/3rdparty/sdl3-shim/SDL3/SDL_pixels.h @@ -32,6 +32,16 @@ static bool operator!=(SDL_PixelFormatDetails* lhs, SDL_PixelFormatEnum rhs) #define SDL_CreatePalette SDL_AllocPalette #define SDL_DestroyPalette SDL_FreePalette -#define SDL_GetPixelFormatForMasks (SDL_PixelFormat)SDL_MasksToPixelFormatEnum +// #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/CMakeLists.txt b/CMakeLists.txt index 522b3d4a..9fc96826 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,12 +60,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" CACHE PATH "Directory w 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) -if(USE_SDL2) - add_compile_definitions(SDL_MAJOR_VERSION=2) -else() - add_compile_definitions(SDL_MAJOR_VERSION=3) -endif() - message(STATUS "Isle app: ${ISLE_BUILD_APP}") message(STATUS "Config app: ${ISLE_BUILD_CONFIG}") message(STATUS "Internal DirectX5 SDK: ${ISLE_USE_DX5}") @@ -82,27 +76,40 @@ if (DOWNLOAD_DEPENDENCIES) include(FetchContent) if(NOT USE_SDL2) - 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(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) - endif() + 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( @@ -121,7 +128,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/isledebug.cpp b/ISLE/isledebug.cpp index 929f9c73..111e05ca 100644 --- a/ISLE/isledebug.cpp +++ b/ISLE/isledebug.cpp @@ -18,6 +18,12 @@ #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 @@ -181,11 +187,7 @@ void IsleDebug_Init() ImGui::CreateContext(); ImGui::StyleColorsDark(); -#if SDL_MAJOR_VERSION >= 3 if (!ImGui_ImplSDL3_InitForSDLRenderer(g_debugWindow, g_debugRenderer)) { -#else - if (!ImGui_ImplSDL2_InitForSDLRenderer(g_debugWindow, g_debugRenderer)) { -#endif SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "ImGui_ImplSDL3_InitForSDLRenderer failed"); g_debugEnabled = false; break; @@ -197,11 +199,7 @@ void IsleDebug_Init() #else SDL_SetTextureScaleMode(g_videoPalette, SDL_SCALEMODE_NEAREST); #endif -#if SDL_MAJOR_VERSION >= 3 if (!ImGui_ImplSDLRenderer3_Init(g_debugRenderer)) { -#else - if (!ImGui_ImplSDLRenderer2_Init(g_debugRenderer)) { -#endif g_debugEnabled = false; break; } @@ -262,11 +260,7 @@ bool IsleDebug_Event(SDL_Event* event) if (SDL_GetWindowFromEvent(event) != g_debugWindow) { return false; } -#if SDL_MAJOR_VERSION >= 3 ImGui_ImplSDL3_ProcessEvent(event); -#else - ImGui_ImplSDL2_ProcessEvent(event); -#endif return true; } @@ -276,13 +270,9 @@ void IsleDebug_Render() return; } const ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); -#if SDL_MAJOR_VERSION >= 3 + ImGui_ImplSDLRenderer3_NewFrame(); ImGui_ImplSDL3_NewFrame(); -#else - ImGui_ImplSDLRenderer2_NewFrame(); - ImGui_ImplSDL2_NewFrame(); -#endif ImGui::NewFrame(); ImGuiIO& io = ImGui::GetIO(); { @@ -375,11 +365,7 @@ void IsleDebug_Render() (Uint8) (clear_color.z * 255), (Uint8) (clear_color.w * 255) ); -#if SDL_MAJOR_VERSION >= 3 ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), g_debugRenderer); -#else - ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), g_debugRenderer); -#endif SDL_RenderPresent(g_debugRenderer); } diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index ac1c3290..0eb9b6e5 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp index 52f448f3..8ad6132b 100644 --- a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp +++ b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp @@ -12,6 +12,7 @@ #include "roi/legoroi.h" #include +#include DECOMP_SIZE_ASSERT(LegoInputManager, 0x338) DECOMP_SIZE_ASSERT(LegoNotifyList, 0x18) diff --git a/LEGO1/mxdirectx/mxdirectxinfo.cpp b/LEGO1/mxdirectx/mxdirectxinfo.cpp index c89ebbd3..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 diff --git a/LEGO1/omni/src/system/mxthread.cpp b/LEGO1/omni/src/system/mxthread.cpp index 00c093b5..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) From de67c33987fe036a2a1c24042e3432e4596a826c Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 21 Oct 2025 16:14:07 -0400 Subject: [PATCH 14/16] SDL2 Linux CI --- .github/workflows/ci.yml | 7 ++++--- CMakeLists.txt | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) 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/CMakeLists.txt b/CMakeLists.txt index 9fc96826..19ed4a21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,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) From 188bcda73393823ab7e1c07ccd918c320bf1e516 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 21 Oct 2025 17:55:02 -0400 Subject: [PATCH 15/16] platform defines --- 3rdparty/sdl3-shim/SDL3/SDL.h | 1 + .../sdl3-shim/SDL3/SDL_platform_defines.h | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 3rdparty/sdl3-shim/SDL3/SDL_platform_defines.h diff --git a/3rdparty/sdl3-shim/SDL3/SDL.h b/3rdparty/sdl3-shim/SDL3/SDL.h index fb16f4a3..8d0ea7c6 100644 --- a/3rdparty/sdl3-shim/SDL3/SDL.h +++ b/3rdparty/sdl3-shim/SDL3/SDL.h @@ -20,6 +20,7 @@ #include "SDL_pixels.h" #include "SDL_surface.h" #include "SDL_timer.h" +#include "SDL_platform_defines.h" #include 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 From 8c6ee038a11f5325c378a181bcdd1ac237498330 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 21 Oct 2025 18:02:35 -0400 Subject: [PATCH 16/16] gate SDL_process include --- LEGO1/lego/legoomni/src/common/legoutils.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index 0eb9b6e5..3c06c378 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -31,8 +31,10 @@ #include "realtime/realtime.h" #include "scripts.h" -#include +#if SDL_MAJOR_VERSION >= 3 #include +#endif +#include #include #include #include