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)