Skip to content

Commit

Permalink
iOS port (for desktop_version) (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo60228 authored Nov 16, 2024
1 parent 6174d62 commit fa8517a
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions desktop_version/AppIcon.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "AppIcon.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions desktop_version/AppIcon.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
45 changes: 43 additions & 2 deletions desktop_version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ option(REMOVE_ABSOLUTE_PATHS "If supported by the compiler, replace all absolute


# Architecture Flags
if(APPLE)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Wow, Apple is a huge jerk these days huh?
set(OSX_10_9_SDK_PATH /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk)
if(NOT CMAKE_OSX_SYSROOT)
Expand All @@ -38,6 +38,8 @@ if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
link_directories(/usr/local/lib)
add_compile_options(-Werror=partial-availability)
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0) # SDL goes back to iOS 8.0, but modern Xcode doesn't
endif()

project(VVVVVV)
Expand All @@ -48,7 +50,10 @@ endif()

# RPATH
if(NOT WIN32)
if(APPLE)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(BIN_LIBROOT "Frameworks")
set(BIN_RPATH "@executable_path/Frameworks")
elseif(APPLE)
set(BIN_LIBROOT "osx")
set(BIN_RPATH "@executable_path/osx")
elseif(CMAKE_SIZEOF_VOID_P MATCHES "8")
Expand Down Expand Up @@ -128,6 +133,9 @@ endif()
if(GOG)
list(APPEND VVV_C_SRC src/GOGNetwork.c)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND VVV_C_SRC src/SDL_uikit_main.c)
endif()

set(VVV_SRC ${VVV_CXX_SRC} ${VVV_C_SRC})

Expand All @@ -136,6 +144,30 @@ if(WIN32)
add_executable(VVVVVV WIN32 ${VVV_SRC} icon.rc)
elseif(ANDROID)
add_library(VVVVVV SHARED ${VVV_SRC})
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
file(GLOB_RECURSE REPO_RESOURCES "fonts/*" "lang/*")

add_executable(VVVVVV MACOSX_BUNDLE ${VVV_SRC} ${DATA_ZIP} AppIcon.xcassets ${REPO_RESOURCES})
set_target_properties(VVVVVV PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.distractionware.vvvvvvmobile"
XCODE_ATTRIBUTE_PRODUCT_NAME "VVVVVV"
XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2" # iPhone, iPad
XCODE_ATTRIBUTE_CURRENT_PROJECT_VERSION "2.5"
XCODE_ATTRIBUTE_MARKETING_VERSION "2.5"
XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME AppIcon
XCODE_ATTRIBUTE_GENERATE_INFOPLIST_FILE YES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist"
XCODE_ATTRIBUTE_INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents YES
RESOURCE "${DATA_ZIP};AppIcon.xcassets"
)

foreach(REPO_FILE ${REPO_RESOURCES})
file(RELATIVE_PATH REPO_FILE_REL "${CMAKE_CURRENT_SOURCE_DIR}" ${REPO_FILE})
get_filename_component(REPO_FILE_DIR ${REPO_FILE_REL} DIRECTORY)
set_property(SOURCE ${REPO_FILE} PROPERTY MACOSX_PACKAGE_LOCATION "Resources/${REPO_FILE_DIR}")
source_group("Resources/${REPO_FILE_DIR}" FILES "${REPO_FILE}")
endforeach()
else()
add_executable(VVVVVV ${VVV_SRC})
endif()
Expand Down Expand Up @@ -419,6 +451,15 @@ elseif (EMSCRIPTEN)
target_compile_options(faudio-static PUBLIC -sUSE_SDL=2)
target_link_libraries(faudio-static -sUSE_SDL=2)
endif()
elseif(DEFINED SDL2_FRAMEWORK)
message(STATUS "Using pre-defined SDL2 variable SDL2_FRAMEWORK")
target_include_directories(VVVVVV SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL2_FRAMEWORK}/Headers>")
target_link_libraries(VVVVVV ${SDL2_FRAMEWORK})
if(BUNDLE_DEPENDENCIES)
target_include_directories(faudio-static SYSTEM PRIVATE "$<BUILD_INTERFACE:${SDL2_FRAMEWORK}/Headers>")
target_link_libraries(faudio-static ${SDL2_FRAMEWORK})
endif()
set_target_properties(VVVVVV PROPERTIES XCODE_EMBED_FRAMEWORKS ${SDL2_FRAMEWORK})
else()
# Only try to autodetect if both SDL2 variables aren't explicitly set
find_package(SDL2 CONFIG)
Expand Down
8 changes: 8 additions & 0 deletions desktop_version/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIFileSharingEnabled</key>
<true/>
</dict>
</plist>
4 changes: 2 additions & 2 deletions desktop_version/VVVVVV-android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
defaultConfig {
minSdkVersion 29
targetSdkVersion 34
versionCode 20004000
versionName "2.4"
versionCode 20005000
versionName "2.5"
applicationId "air.com.distractionware.vvvvvvmobile"
externalNativeBuild {
cmake {
Expand Down
2 changes: 1 addition & 1 deletion desktop_version/src/ButtonGlyphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ bool BUTTONGLYPHS_keyboard_is_available(void)
return true;
}

#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(TARGET_OS_IPHONE)
return false;
#else
return !SDL_GetHintBoolean("SteamDeck", SDL_FALSE);
Expand Down
13 changes: 13 additions & 0 deletions desktop_version/src/FileSystemUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,19 @@ static int PLATFORM_getOSDirectory(char* output, const size_t output_size)
}
SDL_snprintf(output, output_size, "%s/", externalStoragePath);
return 1;
#elif defined(TARGET_OS_IPHONE)
// (ab)use SDL APIs to get the path to the Documents folder without needing Objective-C
const char* prefsPath = SDL_GetPrefPath("", "");
if (prefsPath == NULL)
{
vlog_error(
"Could not get OS directory: %s",
SDL_GetError()
);
return 0;
}
SDL_snprintf(output, output_size, "%s/../../Documents/", prefsPath);
return 1;
#else
const char* prefDir = PHYSFS_getPrefDir("distractionware", "VVVVVV");
if (prefDir == NULL)
Expand Down
2 changes: 1 addition & 1 deletion desktop_version/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void Game::init(void)
screenshot_border_timer = 0;
screenshot_saved_success = false;

#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(TARGET_OS_IPHONE)
checkpoint_saving = true;
#else
checkpoint_saving = false;
Expand Down
23 changes: 23 additions & 0 deletions desktop_version/src/SDL_uikit_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
SDL_uikit_main.c, placed in the public domain by Sam Lantinga 3/18/2019
*/

/* Include the SDL main definition header */
#include "SDL_main.h"

#if defined(__IPHONEOS__) || defined(__TVOS__)

#ifndef SDL_MAIN_HANDLED
#ifdef main
#undef main
#endif

int main(int argc, char *argv[])
{
return SDL_UIKitRunApp(argc, argv, SDL_main);
}
#endif /* !SDL_MAIN_HANDLED */

#endif /* __IPHONEOS__ || __TVOS__ */

/* vi: set ts=4 sw=4 expandtab: */
2 changes: 1 addition & 1 deletion desktop_version/src/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ bool Screen::isForcedFullscreen(void)
* If you're working on a tenfoot-only build, add a def that always
* returns true!
*/
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(TARGET_OS_IPHONE)
return true;
#else
return SDL_GetHintBoolean("SteamTenfoot", SDL_FALSE);
Expand Down
3 changes: 2 additions & 1 deletion desktop_version/src/Vlogging.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#include <stdarg.h>
#include <stdio.h>

#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(TARGET_OS_IPHONE)
// forward to SDL logging on Android, since stdout/stderr are /dev/null
// they exist on iOS, but just get forwarded to the system log anyway, so might as well provide proper metadata
#define VLOG_USE_SDL 1
#endif

Expand Down
2 changes: 2 additions & 0 deletions desktop_version/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ int main(int argc, char *argv[])
/* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */
SDL_SetHintWithPriority(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0", SDL_HINT_OVERRIDE);

SDL_SetHintWithPriority(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight", SDL_HINT_OVERRIDE);

if(!FILESYSTEM_init(argv[0], baseDir, assetsPath, langDir, fontsDir))
{
vlog_error("Unable to initialize filesystem!");
Expand Down

0 comments on commit fa8517a

Please sign in to comment.