From 289707803297f9a59e873921ca325d003abbc43a Mon Sep 17 00:00:00 2001 From: "SnepOMatic (Rhew)" Date: Mon, 10 Nov 2025 23:59:37 +0000 Subject: [PATCH] Switch Port Todo: Fix: Misc crashes when interacting on island. Todo: Fix: Joystick pointer is slow to move. Todo: Fix: Touch doesn't behave. --- CMakeLists.txt | 29 +++++++++++++++++++++++++++-- ISLE/isleapp.cpp | 9 +++++++++ ISLE/switch/config.cpp | 11 +++++++++++ ISLE/switch/config.h | 8 ++++++++ ISLE/switch/filesys.cpp | 30 ++++++++++++++++++++++++++++++ ISLE/switch/filesys.h | 10 ++++++++++ miniwin/CMakeLists.txt | 6 ++++++ 7 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 ISLE/switch/config.cpp create mode 100644 ISLE/switch/config.h create mode 100644 ISLE/switch/filesys.cpp create mode 100644 ISLE/switch/filesys.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 60e742d0..f47211e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,12 @@ if (EMSCRIPTEN) set(SDL_PTHREADS ON CACHE BOOL "Enable SDL pthreads" FORCE) endif() +if (NINTENDO_SWITCH) + set(CMAKE_TOOLCHAIN_FILE "${DEVKITPRO}/cmake/Switch.cmake" CACHE PATH "toolchain file") + add_compile_definitions(__SWITCH__) + add_compile_definitions(SDL_VIDEO_DRIVER_SWITCH) +endif() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") include(CheckCXXSourceCompiles) @@ -50,7 +56,7 @@ cmake_dependent_option(ISLE_DEBUG "Enable imgui debug" ON "NOT VITA" OFF) cmake_dependent_option(ISLE_USE_DX5 "Build with internal DirectX 5 SDK" "${NOT_MINGW}" "WIN32;CMAKE_SIZEOF_VOID_P EQUAL 4" OFF) cmake_dependent_option(ISLE_MINIWIN "Use miniwin" ON "NOT ISLE_USE_DX5" OFF) cmake_dependent_option(ISLE_EXTENSIONS "Use extensions" ON "NOT ISLE_USE_DX5;NOT WINDOWS_STORE" OFF) -cmake_dependent_option(ISLE_BUILD_CONFIG "Build CONFIG.EXE application" ON "MSVC OR ISLE_MINIWIN;NOT NINTENDO_3DS;NOT WINDOWS_STORE;NOT VITA" OFF) +cmake_dependent_option(ISLE_BUILD_CONFIG "Build CONFIG.EXE application" ON "MSVC OR ISLE_MINIWIN;NOT NINTENDO_3DS;NOT NINTENDO_SWITCH;NOT WINDOWS_STORE;NOT VITA" OFF) cmake_dependent_option(ISLE_COMPILE_SHADERS "Compile shaders" ON "SDL_SHADERCROSS_BIN;TARGET Python3::Interpreter" OFF) cmake_dependent_option(CMAKE_POSITION_INDEPENDENT_CODE "Build with -fPIC" ON "NOT VITA" OFF) option(ENABLE_CLANG_TIDY "Enable clang-tidy") @@ -85,6 +91,18 @@ if (DOWNLOAD_DEPENDENCIES) GIT_TAG "main" EXCLUDE_FROM_ALL ) + elseif (NINTENDO_SWITCH) + FetchContent_Declare( + SDL3 + # Official repo missing Threads support? + #GIT_REPOSITORY "https://github.com/devkitPro/SDL.git" + #GIT_TAG "switch-sdl-3.2" + GIT_REPOSITORY "https://github.com/vs49688/SDL.git" + GIT_TAG "switch-sdl-3.2.14" + EXCLUDE_FROM_ALL + ) + set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON CACHE BOOL "Disable PCH globally" FORCE) + #set(SDL_PLATFORM_SWITCH ON CACHE BOOL "Enable Switch platform backend" FORCE) else() FetchContent_Declare( SDL3 @@ -178,7 +196,8 @@ target_include_directories(Vec::Vec INTERFACE "${CMAKE_SOURCE_DIR}/3rdparty/vec" add_library(lego1 LEGO1/main.cpp ) -target_precompile_headers(lego1 PRIVATE "LEGO1/lego1_pch.h") +target_include_directories(lego1 PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1") +target_precompile_headers(lego1 PRIVATE "") set_property(TARGET lego1 PROPERTY DEFINE_SYMBOL "LEGO1_DLL") target_include_directories(lego1 PUBLIC "$") target_include_directories(lego1 PUBLIC "$") @@ -585,6 +604,12 @@ if (ISLE_BUILD_APP) ISLE/3ds/config.cpp ) endif() + if(NINTENDO_SWITCH) + target_sources(isle PRIVATE + ISLE/switch/filesys.cpp + ISLE/switch/config.cpp + ) + endif() if(WINDOWS_STORE) target_sources(isle PRIVATE ISLE/xbox_one_series/config.cpp diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index e8cde906..5bd2d3eb 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -65,6 +65,12 @@ #include "3ds/config.h" #endif +#ifdef __SWITCH__ +#include +#include "switch/filesys.h" +#include "switch/config.h" +#endif + #ifdef WINDOWS_STORE #include "xbox_one_series/config.h" #endif @@ -1142,6 +1148,9 @@ bool IsleApp::LoadConfig() #ifdef __3DS__ N3DS_SetupDefaultConfigOverrides(dict); #endif +#ifdef __SWITCH__ + NX_SetupDefaultConfigOverrides(dict); +#endif #ifdef WINDOWS_STORE XBONE_SetupDefaultConfigOverrides(dict); #endif diff --git a/ISLE/switch/config.cpp b/ISLE/switch/config.cpp new file mode 100644 index 00000000..883f8226 --- /dev/null +++ b/ISLE/switch/config.cpp @@ -0,0 +1,11 @@ +#include "config.h" + +#include +#include + +void NX_SetupDefaultConfigOverrides(dictionary* p_dictionary) +{ + iniparser_set(p_dictionary, "isle:diskpath", "sdmc:/switch/isle/LEGO/"); + iniparser_set(p_dictionary, "isle:cdpath", "sdmc:/switch/isle/"); + iniparser_set(p_dictionary, "isle:savepath", "sdmc:/switch/isle/"); +} diff --git a/ISLE/switch/config.h b/ISLE/switch/config.h new file mode 100644 index 00000000..7545de51 --- /dev/null +++ b/ISLE/switch/config.h @@ -0,0 +1,8 @@ +#ifndef NX_CONFIG_H +#define NX_CONFIG_H + +#include "dictionary.h" + +void NX_SetupDefaultConfigOverrides(dictionary* p_dictionary); + +#endif // NX_CONFIG_H diff --git a/ISLE/switch/filesys.cpp b/ISLE/switch/filesys.cpp new file mode 100644 index 00000000..dd34b69d --- /dev/null +++ b/ISLE/switch/filesys.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include "filesys.h" + +bool NX_GetPathInfo(const char *path, SDL_PathInfo *info) +{ + struct stat st_info; + if (stat(path, &st_info) != 0) + { + if (info) info->type = SDL_PATHTYPE_NONE; + return false; + } + + if (st_info.st_mode & S_IFDIR) + { + if (info)info->type = SDL_PATHTYPE_DIRECTORY; + return true; + } + + if (info) info->type = SDL_PATHTYPE_FILE; + if (!info) return true; + + auto *fp = fopen(path, "r"); + fseek(fp, 0, SEEK_END); + if (info) info->size = ftell(fp); + fclose(fp); + + return true; +} \ No newline at end of file diff --git a/ISLE/switch/filesys.h b/ISLE/switch/filesys.h new file mode 100644 index 00000000..51c52e37 --- /dev/null +++ b/ISLE/switch/filesys.h @@ -0,0 +1,10 @@ +#ifndef NX_FILESYS_H +#define NX_FILESYS_H + +#include + +#define SDL_GetPathInfo NX_GetPathInfo // Override broken SDL_GetPathInfo + +bool NX_GetPathInfo(const char *path, SDL_PathInfo *info); + +#endif // NX_FILESYS_H \ No newline at end of file diff --git a/miniwin/CMakeLists.txt b/miniwin/CMakeLists.txt index 4293780e..a7b348e1 100644 --- a/miniwin/CMakeLists.txt +++ b/miniwin/CMakeLists.txt @@ -69,6 +69,12 @@ if(NOT (VITA OR WINDOWS_STORE)) endif() endif() +if(NINTENDO_SWITCH) + # Remove USE_OPENGL1 as incompatible. + # Remove everything else as not needed. + list(REMOVE_ITEM GRAPHICS_BACKENDS USE_SOFTWARE_RENDER USE_OPENGL1 USE_OPENGLES2) #USE_SDL_GPU +endif() + if(VITA) add_subdirectory(src/d3drm/backends/gxm/shaders)