diff --git a/.github/workflows/build-validation.yml b/.github/workflows/build-validation.yml index 003927f08..97a54f37e 100644 --- a/.github/workflows/build-validation.yml +++ b/.github/workflows/build-validation.yml @@ -28,6 +28,25 @@ jobs: name: soh-mac path: build-cmake/src/*.a if-no-files-found: error + build-ios: + runs-on: macos-12 + steps: + - uses: actions/checkout@v2 + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ${{ runner.os }}-ccache + - name: Build libultraship + run: | + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + cmake --no-warn-unused-cli -H. -Bbuild-cmake -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 -DCMAKE_BUILD_TYPE:STRING=Release + cmake --build build-cmake --config Release --parallel 10 + - name: Upload build + uses: actions/upload-artifact@v3 + with: + name: soh-ios + path: build-cmake/src/*/*.a + if-no-files-found: error build-linux: runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index fea92c673..12318ab93 100644 --- a/.gitignore +++ b/.gitignore @@ -346,3 +346,22 @@ ZAPDUtils.lib .vs/ .idea/ cmake-build-** +cmake_install.cmake +*.a +*.o +*.pc +*.vcxproj +*.sln +*.filters +*.stamp +*.depend +*.lib +*.tlog +*.recipe +src/install_config.h +# Removed jsonConfig and jsonConfigVersion +extern/nlohmann-json/*_jsonConfig* +*.pbxproj +*.xcworkspace +*.xcsettings +build* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 038aff757..d69a5dfb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,14 @@ cmake_minimum_required(VERSION 3.24.0) option(NON_PORTABLE "Build a non-portable version" OFF) +if(CMAKE_SYSTEM_NAME STREQUAL "iOS") + option(SIGN_LIBRARY "Enable xcode signing" OFF) + option(BUNDLE_ID "Bundle ID for xcode signing" "com.example.libultraship") + set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) +endif() + project(libultraship LANGUAGES C CXX) -if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") enable_language(OBJCXX) set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -fobjc-arc") set(CMAKE_OBJCXX_FLAGS "${CMAKE_OBJCXX_FLAGS} -fobjc-arc") @@ -14,15 +20,34 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows") endif() include(cmake/Utils.cmake) +set(ADDITIONAL_LIB_INCLUDES "") include(cmake/dependencies/common.cmake) if (CMAKE_SYSTEM_NAME STREQUAL "Android") include(cmake/dependencies/android.cmake) +elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS") + include(cmake/dependencies/ios.cmake) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") + include(cmake/dependencies/windows.cmake) endif() -if (CMAKE_SYSTEM_NAME STREQUAL "Windows") - include(cmake/dependencies/windows.cmake) + +if(CMAKE_SYSTEM_NAME STREQUAL "iOS") + set(PLATFORM "OS64COMBINED") + include(FetchContent) + FetchContent_Declare(iostoolchain + GIT_REPOSITORY https://github.com/leetal/ios-cmake + GIT_TAG 06465b27698424cf4a04a5ca4904d50a3c966c45 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + ) + FetchContent_GetProperties(iostoolchain) + if(NOT iostoolchain_POPULATED) + FetchContent_Populate(iostoolchain) + endif() + set(CMAKE_IOS_TOOLCHAIN_FILE ${iostoolchain_SOURCE_DIR}/ios.toolchain.cmake) + set_property(GLOBAL PROPERTY IOS_TOOLCHAIN_FILE ${CMAKE_IOS_TOOLCHAIN_FILE}) + include(${CMAKE_IOS_TOOLCHAIN_FILE}) endif() add_subdirectory("extern") add_subdirectory("src") - diff --git a/cmake/dependencies/ios.cmake b/cmake/dependencies/ios.cmake new file mode 100644 index 000000000..0ae20499b --- /dev/null +++ b/cmake/dependencies/ios.cmake @@ -0,0 +1,44 @@ +#=================== SDL2 =================== +find_package(SDL2 QUIET) +if (NOT ${SDL2_FOUND}) + include(FetchContent) + FetchContent_Declare( + SDL2 + GIT_REPOSITORY https://github.com/libsdl-org/SDL.git + GIT_TAG release-2.28.1 + OVERRIDE_FIND_PACKAGE + ) + FetchContent_MakeAvailable(SDL2) +endif() + +#=================== nlohmann-json =================== +find_package(nlohmann_json QUIET) +if (NOT ${nlohmann_json_FOUND}) + FetchContent_Declare( + nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.11.3 + OVERRIDE_FIND_PACKAGE + ) + FetchContent_MakeAvailable(nlohmann_json) +endif() + +#=================== libzip =================== +find_package(libzip QUIET) +if (NOT ${libzip_FOUND}) + set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) + set(BUILD_TOOLS OFF) + set(BUILD_REGRESS OFF) + set(BUILD_EXAMPLES OFF) + set(BUILD_DOC OFF) + set(BUILD_OSSFUZZ OFF) + set(BUILD_SHARED_LIBS OFF) + FetchContent_Declare( + libzip + GIT_REPOSITORY https://github.com/nih-at/libzip.git + GIT_TAG v1.10.1 + OVERRIDE_FIND_PACKAGE + ) + FetchContent_MakeAvailable(libzip) + list(APPEND ADDITIONAL_LIB_INCLUDES ${libzip_SOURCE_DIR}/lib ${libzip_BINARY_DIR}) +endif() \ No newline at end of file diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index c39a69fc5..79e1764a3 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -62,7 +62,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows") ${IMGUI_DIR}/backends/imgui_impl_dx11.cpp ${IMGUI_DIR}/backends/imgui_impl_win32.cpp ) -elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") target_sources(ImGui PRIVATE ${IMGUI_DIR}/backends/imgui_impl_metal.mm @@ -77,13 +77,15 @@ endif() target_include_directories(ImGui PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends PRIVATE ${SDL2_INCLUDE_DIRS}) -if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") target_include_directories(ImGui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/metal-cpp) target_compile_definitions(ImGui PUBLIC IMGUI_IMPL_METAL_CPP) endif() if (CMAKE_SYSTEM_NAME STREQUAL "Windows") target_link_libraries(ImGui PUBLIC SDL2::SDL2 SDL2::SDL2main) +elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS") + target_link_libraries(ImGui PUBLIC SDL2::SDL2-static SDL2::SDL2main) elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") target_link_libraries(ImGui PUBLIC SDL2::SDL2-static) else() @@ -97,7 +99,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") find_package(GLEW REQUIRED) target_link_libraries(ImGui PUBLIC ${OPENGL_opengl_LIBRARY} GLEW::GLEW) set_target_properties(ImGui PROPERTIES - XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES + XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES ) elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") if (USE_OPENGLES) diff --git a/include/libultraship/classes.h b/include/libultraship/classes.h index 7d444f05c..21e1b9e0e 100644 --- a/include/libultraship/classes.h +++ b/include/libultraship/classes.h @@ -36,7 +36,7 @@ #endif #include "audio/SDLAudioPlayer.h" #ifdef __APPLE__ -#include "utils/OSXFolderManager.h" +#include "utils/AppleFolderManager.h" #endif #ifdef __SWITCH__ #include "port/switch/SwitchImpl.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 430b95e07..ce0f315b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,11 +101,11 @@ target_sources(libultraship PRIVATE ${Source_Files__Window__Gui}) file(GLOB Source_Files__Utils RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "utils/*.h" "utils/*.cpp") -if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") - list(APPEND Source_Files__Utils ${CMAKE_CURRENT_SOURCE_DIR}/utils/OSXFolderManager.mm) - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/utils/OSXFolderManager.mm PROPERTIES COMPILE_FLAGS -fno-objc-arc) +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") + list(APPEND Source_Files__Utils ${CMAKE_CURRENT_SOURCE_DIR}/utils/AppleFolderManager.mm) + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/utils/AppleFolderManager.mm PROPERTIES COMPILE_FLAGS -fno-objc-arc) else() - list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/utils/OSXFolderManager.h) + list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/utils/AppleFolderManager.h) endif() source_group("utils" FILES ${Source_Files__Utils}) @@ -131,10 +131,10 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") ${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchImpl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchPerformanceProfiles.h ) -elseif (CMAKE_SYSTEM_NAME STREQUAL "Android") +elseif (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") set(Source_Files__Port - ${CMAKE_CURRENT_SOURCE_DIR}/port/android/AndroidImpl.h - ${CMAKE_CURRENT_SOURCE_DIR}/port/android/AndroidImpl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/port/mobile/MobileImpl.h + ${CMAKE_CURRENT_SOURCE_DIR}/port/mobile/MobileImpl.cpp ) endif() @@ -167,10 +167,14 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/dxsdk/*") endif() -if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") +if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_SYSTEM_NAME STREQUAL "iOS") list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_metal*") endif() +if (CMAKE_SYSTEM_NAME STREQUAL "iOS") + list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_opengl*") +endif() + if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS") list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_wiiu*") list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gx2*") @@ -184,7 +188,7 @@ target_sources(libultraship PRIVATE ${Source_Files__Graphic}) #=================== metal-cpp =================== -if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") target_include_directories(libultraship PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern/metal-cpp) endif() @@ -205,7 +209,7 @@ endif() target_include_directories(libultraship PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern ${CMAKE_CURRENT_BINARY_DIR} $<$:${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/lib/libgfxd> - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../extern/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../extern/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb ${ADDITIONAL_LIB_INCLUDES} ) if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") @@ -248,7 +252,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "NintendoS target_link_libraries(libultraship PRIVATE Threads::Threads) endif() -if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") find_Library(OSX_FOUNDATION Foundation) find_Library(OSX_AVFOUNDATION AVFoundation) find_library(METAL Metal) @@ -277,30 +281,57 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows") ) endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES ) endif() -if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS") +if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") + target_compile_definitions(libultraship PRIVATE + $<$:_DEBUG> + $<$>:NDEBUG> + SPDLOG_NO_THREAD_ID + SPDLOG_NO_TLS + STBI_NO_THREAD_LOCALS + SPDLOG_ACTIVE_LEVEL=3 + ) +elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS") target_compile_definitions(libultraship PRIVATE - ENABLE_OPENGL $<$:_DEBUG> $<$>:NDEBUG> $<$:SPDLOG_ACTIVE_LEVEL=0> $<$>:SPDLOG_ACTIVE_LEVEL=1> - $<$:USE_OPENGLES> - $<$:GFX_DEBUG_DISASSEMBLER> + __IOS__ ) -else () + + set_xcode_property(${PROJECT_NAME} PRODUCT_BUNDLE_IDENTIFIER ${BUNDLE_ID} All) + + if(NOT SIGN_LIBRARY) + set_target_properties(${PROJECT_NAME} PROPERTIES + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" + XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO" + ) + + set_target_properties(SDL2 PROPERTIES + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" + XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO" + ) + + set_target_properties(zip PROPERTIES + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" + XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO" + ) + endif() +else() target_compile_definitions(libultraship PRIVATE + ENABLE_OPENGL $<$:_DEBUG> $<$>:NDEBUG> - SPDLOG_NO_THREAD_ID - SPDLOG_NO_TLS - STBI_NO_THREAD_LOCALS - SPDLOG_ACTIVE_LEVEL=3 + $<$:SPDLOG_ACTIVE_LEVEL=0> + $<$>:SPDLOG_ACTIVE_LEVEL=1> + $<$:USE_OPENGLES> + $<$:GFX_DEBUG_DISASSEMBLER> ) endif() @@ -341,6 +372,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang") -Wno-parentheses -Wno-narrowing -Wno-missing-field-initializers + -Wno-implicit-function-declaration $<$:-Wno-int-conversion> ) endif() diff --git a/src/Context.cpp b/src/Context.cpp index 610e7b1f9..bb9eb7977 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -12,7 +12,7 @@ #endif #ifdef __APPLE__ -#include "utils/OSXFolderManager.h" +#include "utils/AppleFolderManager.h" #elif defined(__SWITCH__) #include "port/switch/SwitchImpl.h" #elif defined(__WIIU__) @@ -216,6 +216,10 @@ void Context::InitResourceManager(const std::vector& otrFiles, SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OTR file not found", "Main OTR file not found. Please generate one", nullptr); SPDLOG_ERROR("Main OTR file not found!"); +#ifdef __IOS__ + // We need this exit to close the app when we dismiss the dialog + exit(0); +#endif #endif return; } @@ -334,6 +338,12 @@ std::string Context::GetAppBundlePath() { return externaldir; } #endif + +#ifdef __IOS__ + const char* home = getenv("HOME"); + return std::string(home) + "/Documents"; +#endif + #ifdef NON_PORTABLE return CMAKE_INSTALL_PREFIX; #else @@ -370,6 +380,11 @@ std::string Context::GetAppDirectoryPath(std::string appName) { } #endif +#ifdef __IOS__ + const char* home = getenv("HOME"); + return std::string(home) + "/Documents"; +#endif + #if defined(__linux__) || defined(__APPLE__) char* fpath = std::getenv("SHIP_HOME"); if (fpath != NULL) { diff --git a/src/graphic/Fast3D/gfx_metal.cpp b/src/graphic/Fast3D/gfx_metal.cpp index db030cc7c..05a9b37e2 100644 --- a/src/graphic/Fast3D/gfx_metal.cpp +++ b/src/graphic/Fast3D/gfx_metal.cpp @@ -186,12 +186,17 @@ static MTL::SamplerAddressMode gfx_cm_to_metal(uint32_t val) { // MARK: - ImGui & SDL Wrappers bool Metal_IsSupported() { +#ifdef __IOS__ + // iOS always supports Metal and MTLCopyAllDevices is not available + return true; +#else NS::Array* devices = MTLCopyAllDevices(); NS::UInteger count = devices->count(); devices->release(); return count > 0; +#endif } bool Metal_Init(SDL_Renderer* renderer) { @@ -274,7 +279,7 @@ static void gfx_metal_init(void) { struct CoordUniforms { uint2 coords[1024]; }; - + kernel void depthKernel(depth2d depth_texture [[ texture(0) ]], constant CoordUniforms& query_coords [[ buffer(0) ]], device float* output_values [[ buffer(1) ]], diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index 9180e20ca..6683d1f2c 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -358,7 +358,11 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s height = window_height; #endif +#ifdef __IOS__ + Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_SHOWN; +#else Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; +#endif if (use_opengl) { flags = flags | SDL_WINDOW_OPENGL; diff --git a/src/port/android/AndroidImpl.cpp b/src/port/mobile/MobileImpl.cpp similarity index 81% rename from src/port/android/AndroidImpl.cpp rename to src/port/mobile/MobileImpl.cpp index b9ce25e85..2e6c12ba2 100644 --- a/src/port/android/AndroidImpl.cpp +++ b/src/port/mobile/MobileImpl.cpp @@ -1,5 +1,5 @@ -#ifdef __ANDROID__ -#include "AndroidImpl.h" +#if defined(__ANDROID__) || defined(__IOS__) +#include "MobileImpl.h" #include #include "public/bridge/consolevariablebridge.h" @@ -7,7 +7,7 @@ static bool isShowingVirtualKeyboard = true; -void LUS::Android::ImGuiProcessEvent(bool wantsTextInput) { +void LUS::Mobile::ImGuiProcessEvent(bool wantsTextInput) { ImGuiInputTextState* state = ImGui::GetInputTextState(ImGui::GetActiveID()); if (wantsTextInput) { diff --git a/src/port/android/AndroidImpl.h b/src/port/mobile/MobileImpl.h similarity index 92% rename from src/port/android/AndroidImpl.h rename to src/port/mobile/MobileImpl.h index 548469872..a239c0606 100644 --- a/src/port/android/AndroidImpl.h +++ b/src/port/mobile/MobileImpl.h @@ -7,7 +7,7 @@ namespace LUS { -class Android { +class Mobile { public: static void ImGuiProcessEvent(bool wantsTextInput); }; diff --git a/src/utils/OSXFolderManager.h b/src/utils/AppleFolderManager.h similarity index 94% rename from src/utils/OSXFolderManager.h rename to src/utils/AppleFolderManager.h index d6be2c6a8..9eb40207f 100644 --- a/src/utils/OSXFolderManager.h +++ b/src/utils/AppleFolderManager.h @@ -1,12 +1,11 @@ // -// OSXFolderManager.h +// AppleFolderManager.h // libultraship // // Created by David Chavez on 28.06.22. // -#ifndef OSXFolderManager_h -#define OSXFolderManager_h +#pragma once #include namespace LUS { @@ -65,6 +64,4 @@ class FolderManager { private: void* m_autoreleasePool; }; -}; // namespace LUS - -#endif /* OSXFolderManager_h */ +}; // namespace LUS \ No newline at end of file diff --git a/src/utils/OSXFolderManager.mm b/src/utils/AppleFolderManager.mm similarity index 96% rename from src/utils/OSXFolderManager.mm rename to src/utils/AppleFolderManager.mm index e27e7c5c2..05833d492 100644 --- a/src/utils/OSXFolderManager.mm +++ b/src/utils/AppleFolderManager.mm @@ -1,11 +1,11 @@ // -// OSXFolderManager.m +// AppleFolderManager.m // libultraship // // Created by David Chavez on 28.06.22. // -#include "OSXFolderManager.h" +#include "AppleFolderManager.h" #import using namespace LUS; diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 4ee637920..7a1b670b3 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -16,7 +16,7 @@ #include "Context.h" #ifdef __APPLE__ -#include "utils/OSXFolderManager.h" +#include "utils/AppleFolderManager.h" #elif defined(__SWITCH__) #include "port/switch/SwitchImpl.h" #elif defined(__WIIU__) @@ -45,8 +45,7 @@ Window::~Window() { } void Window::Init() { - bool steamDeckGameMode = false; - bool androidGameMode = false; + bool mGameMode = false; #ifdef __linux__ std::ifstream osReleaseFile("/etc/os-release"); @@ -55,29 +54,24 @@ void Window::Init() { while (std::getline(osReleaseFile, line)) { if (line.find("VARIANT_ID") != std::string::npos) { if (line.find("steamdeck") != std::string::npos) { - steamDeckGameMode = std::getenv("XDG_CURRENT_DESKTOP") != nullptr && - std::string(std::getenv("XDG_CURRENT_DESKTOP")) == "gamescope"; + mGameMode = std::getenv("XDG_CURRENT_DESKTOP") != nullptr && + std::string(std::getenv("XDG_CURRENT_DESKTOP")) == "gamescope"; } break; } } } +#elif defined(__ANDROID__) || defined(__IOS__) + mGameMode = true; #endif -#ifdef __ANDROID__ - androidGameMode = true; -#endif - - mIsFullscreen = LUS::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", false) || - steamDeckGameMode || androidGameMode; + mIsFullscreen = LUS::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", false) || mGameMode; mPosX = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.PositionX", mPosX); mPosY = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.PositionY", mPosY); if (mIsFullscreen) { - mWidth = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Width", - steamDeckGameMode || androidGameMode ? 1280 : 1920); - mHeight = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Height", - steamDeckGameMode || androidGameMode ? 800 : 1080); + mWidth = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Width", mGameMode ? 1280 : 1920); + mHeight = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Height", mGameMode ? 800 : 1080); } else { mWidth = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Width", 640); mHeight = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Height", 480); @@ -237,18 +231,18 @@ void Window::InitWindowManager() { mWindowManagerApi = &gfx_dxgi_api; break; #endif -#if defined(ENABLE_OPENGL) || defined(__APPLE__) +#ifdef ENABLE_OPENGL case WindowBackend::SDL_OPENGL: mRenderingApi = &gfx_opengl_api; mWindowManagerApi = &gfx_sdl; break; +#endif #ifdef __APPLE__ case WindowBackend::SDL_METAL: mRenderingApi = &gfx_metal_api; mWindowManagerApi = &gfx_sdl; break; #endif -#endif #ifdef __WIIU__ case WindowBackend::GX2: mRenderingApi = &gfx_gx2_api; diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index a4cef5437..0d0256475 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -45,8 +45,8 @@ #include "port/switch/SwitchImpl.h" #endif -#ifdef __ANDROID__ -#include "port/android/AndroidImpl.h" +#if defined(__ANDROID__) || defined(__IOS__) +#include "port/mobile/MobileImpl.h" #endif #ifdef ENABLE_OPENGL @@ -209,7 +209,9 @@ void Gui::ImGuiBackendInit() { case WindowBackend::GX2: ImGui_ImplGX2_Init(); break; -#else +#endif + +#ifdef ENABLE_OPENGL case WindowBackend::SDL_OPENGL: #ifdef __APPLE__ ImGui_ImplOpenGL3_Init("#version 410 core"); @@ -288,12 +290,10 @@ void Gui::Update(WindowEvent event) { case WindowBackend::SDL_OPENGL: case WindowBackend::SDL_METAL: ImGui_ImplSDL2_ProcessEvent(static_cast(event.Sdl.Event)); - #ifdef __SWITCH__ LUS::Switch::ImGuiProcessEvent(mImGuiIo->WantTextInput); -#endif -#ifdef __ANDROID__ - LUS::Android::ImGuiProcessEvent(mImGuiIo->WantTextInput); +#elif defined(__ANDROID__) || defined(__IOS__) + LUS::Mobile::ImGuiProcessEvent(mImGuiIo->WantTextInput); #endif break; #endif @@ -463,21 +463,25 @@ void Gui::ImGuiBackendNewFrame() { mImGuiIo->DeltaTime = (float)frametime / 1000.0f / 1000.0f; ImGui_ImplGX2_NewFrame(); break; -#else +#endif + +#ifdef ENABLE_OPENGL case WindowBackend::SDL_OPENGL: ImGui_ImplOpenGL3_NewFrame(); break; #endif -#ifdef __APPLE__ - case WindowBackend::SDL_METAL: - Metal_NewFrame(mImpl.Metal.Renderer); - break; -#endif + #if defined(ENABLE_DX11) || defined(ENABLE_DX12) case WindowBackend::DX11: ImGui_ImplDX11_NewFrame(); break; #endif + +#ifdef __APPLE__ + case WindowBackend::SDL_METAL: + Metal_NewFrame(mImpl.Metal.Renderer); + break; +#endif default: break; } @@ -719,16 +723,20 @@ void Gui::ImGuiRenderDrawData(ImDrawData* data) { GX2SetScissor(0, 0, mImGuiIo->DisplaySize.x, mImGuiIo->DisplaySize.y); ImGui_ImplWiiU_DrawKeyboardOverlay(); break; -#else +#endif + +#ifdef ENABLE_OPENGL case WindowBackend::SDL_OPENGL: ImGui_ImplOpenGL3_RenderDrawData(data); break; #endif + #ifdef __APPLE__ case WindowBackend::SDL_METAL: Metal_RenderDrawData(data); break; #endif + #if defined(ENABLE_DX11) || defined(ENABLE_DX12) case WindowBackend::DX11: ImGui_ImplDX11_RenderDrawData(data); diff --git a/src/window/gui/StatsWindow.cpp b/src/window/gui/StatsWindow.cpp index aaefd7e5e..1248f14f1 100644 --- a/src/window/gui/StatsWindow.cpp +++ b/src/window/gui/StatsWindow.cpp @@ -22,6 +22,8 @@ void StatsWindow::DrawElement() { #if defined(_WIN32) ImGui::Text("Platform: Windows"); +#elif defined(__IOS__) + ImGui::Text("Platform: iOS"); #elif defined(__APPLE__) ImGui::Text("Platform: macOS"); #elif defined(__SWITCH__)