Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 94 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.16.0 FATAL_ERROR)

if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0")
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
endif()

# Set the project version and language
project(Spaghettify VERSION 1.0.0 LANGUAGES C CXX ASM)
include(FetchContent)
Expand Down Expand Up @@ -59,6 +63,8 @@ endif()
message("Spaghetti Kart version: ${PROJECT_VERSION} ${PROJECT_PATCH_WORD}")

if(APPLE)
set_source_files_properties(src/port/audio/HMAS.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++")
enable_language(OBJC)
enable_language(OBJCXX)
endif()

Expand Down Expand Up @@ -187,6 +193,20 @@ set(SKIP_XCODE_VERSION_CHECK ON)
set(GFX_DEBUG_DISASSEMBLER OFF)

# Add compile definitions for the target
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
check_c_compiler_flag("-Wno-error=int-conversion" HAS_WNO_ERROR_INT_CONVERSION)
check_cxx_compiler_flag("-Wno-error=changes-meaning" HAS_WNO_ERROR_CHANGES_MEANING)

add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wno-error=incompatible-pointer-types>" "$<$<COMPILE_LANGUAGE:CXX>:-Wno-error=narrowing>")

if(HAS_WNO_ERROR_INT_CONVERSION)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wno-error=int-conversion>")
endif()

if(HAS_WNO_ERROR_CHANGES_MEANING)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-error=changes-meaning>")
endif()
add_compile_definitions(
VERSION_US=1
ENABLE_RUMBLE=1
Expand Down Expand Up @@ -263,6 +283,7 @@ file(GLOB_RECURSE ALL_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"src/port/*.h"
"src/port/*.c"
"src/port/*.cpp"
"src/port/*.mm"
"src/mods/*.h"
"src/mods/*.c"
"src/mods/*.cpp"
Expand Down Expand Up @@ -298,13 +319,15 @@ list(FILTER ALL_FILES EXCLUDE REGEX ".*.inc.c")
list(FILTER ALL_FILES EXCLUDE REGEX "./src/debug/crash_screen_enhancement.c")

if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(IOS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libultraship/ios)
set(IOS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ios)

set(STORYBOARD_FILE ${IOS_DIR}/Launch.storyboard)
set(IMAGE_FILES ${IOS_DIR}/PoweredBy.png)
set(ICON_FILES ${IOS_DIR}/Icon.png)
set(ICON_FILES ${CMAKE_CURRENT_SOURCE_DIR}/icon.png)

list(APPEND ALL_FILES ${STORYBOARD_FILE} ${ICON_FILES})

add_compile_definitions(__IOS__)

list(APPEND ALL_FILES ${STORYBOARD_FILE} ${IMAGE_FILES} ${ICON_FILES})

add_executable(${PROJECT_NAME} ${ALL_FILES})
set_xcode_property(${PROJECT_NAME} PRODUCT_BUNDLE_IDENTIFIER ${PROJECT_ID} All)
Expand All @@ -313,7 +336,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${IOS_DIR}/plist.in
RESOURCE "${IMAGE_FILES};${STORYBOARD_FILE};${ICON_FILES}"
RESOURCE "${STORYBOARD_FILE};${ICON_FILES}"
)
else()
add_executable(${PROJECT_NAME} ${ALL_FILES})
Expand Down Expand Up @@ -483,6 +506,52 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
target_include_directories(${PROJECT_NAME} PRIVATE
${DEVKITPRO}/portlibs/wiiu/include/
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(INSTALL_DOCS OFF CACHE BOOL "" FORCE)
set(INSTALL_PKG_CONFIG_MODULE OFF CACHE BOOL "" FORCE)

FetchContent_Declare(
libogg
GIT_REPOSITORY https://github.com/xiph/ogg.git
GIT_TAG v1.3.6
)
FetchContent_MakeAvailable(libogg)

set(OGG_ROOT "${libogg_BINARY_DIR}" CACHE PATH "" FORCE)
set(OGG_INCLUDE_DIR "${libogg_SOURCE_DIR}/include" CACHE PATH "" FORCE)
set(OGG_LIBRARY "${libogg_BINARY_DIR}/libogg.a" CACHE FILEPATH "" FORCE)

if(TARGET ogg AND NOT TARGET Ogg::ogg)
add_library(Ogg::ogg ALIAS ogg)
endif()

FetchContent_Declare(
libvorbis
GIT_REPOSITORY https://github.com/xiph/vorbis.git
GIT_TAG v1.3.7
)
FetchContent_MakeAvailable(libvorbis)

if(TARGET vorbis AND NOT TARGET Vorbis::vorbis)
add_library(Vorbis::vorbis ALIAS vorbis)
endif()

if(TARGET vorbisenc AND NOT TARGET Vorbis::vorbisenc)
add_library(Vorbis::vorbisenc ALIAS vorbisenc)
endif()

if(TARGET vorbisfile AND NOT TARGET Vorbis::vorbisfile)
add_library(Vorbis::vorbisfile ALIAS vorbisfile)
endif()

set(ADDITIONAL_LIBRARY_DEPENDENCIES
"Ogg::ogg"
"Vorbis::vorbis"
"Vorbis::vorbisenc"
"Vorbis::vorbisfile"
)
else()
find_package(Ogg REQUIRED)
find_package(Vorbis REQUIRED)
Expand Down Expand Up @@ -655,14 +724,24 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
endif()
endif()

file(WRITE ${CMAKE_BINARY_DIR}/copy_if_exists.cmake "if(EXISTS \"\${SRC}\")\n execute_process(COMMAND \${CMAKE_COMMAND} -E copy_if_different \"\${SRC}\" \"\${DST}\")\nendif()\n")

add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMENT "Copying asset yamls..."
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config.yml" "$<TARGET_FILE_DIR:Spaghettify>/config.yml"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/yamls/" "$<TARGET_FILE_DIR:Spaghettify>/yamls/"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/meta/" "$<TARGET_FILE_DIR:Spaghettify>/meta/"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config.yml" "$<TARGET_FILE_DIR:Spaghettify>/config.yml"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/yamls/" "$<TARGET_FILE_DIR:Spaghettify>/yamls/"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/meta/" "$<TARGET_FILE_DIR:Spaghettify>/meta/"
)

if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMENT "Copying packaged O2R assets..."
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_BINARY_DIR}/spaghetti.o2r" "$<TARGET_FILE_DIR:Spaghettify>/spaghetti.o2r"
)
endif()

if(NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
include(ExternalProject)
ExternalProject_Add(TorchExternal
Expand All @@ -680,25 +759,27 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")

add_custom_target(
ExtractAssets
DEPENDS TorchExternal
DEPENDS ${TORCH_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${TORCH_EXECUTABLE} header -o baserom.us.z64
COMMAND ${TORCH_EXECUTABLE} o2r baserom.us.z64 --additional-files meta/mods.toml
COMMAND ${TORCH_EXECUTABLE} pack assets spaghetti.o2r o2r
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/mk64.o2r" "${CMAKE_BINARY_DIR}/mk64.o2r"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/spaghetti.o2r" "${CMAKE_BINARY_DIR}/spaghetti.o2r"
)
)

add_custom_target(
GenerateO2R
DEPENDS TorchExternal
DEPENDS TorchExternal "${CMAKE_SOURCE_DIR}/assets"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${TORCH_EXECUTABLE} pack assets spaghetti.o2r o2r
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/spaghetti.o2r" "${CMAKE_BINARY_DIR}/spaghetti.o2r"
)
)

add_dependencies(${PROJECT_NAME} GenerateO2R)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
install(FILES "${CMAKE_BINARY_DIR}/spaghetti.o2r" DESTINATION . COMPONENT ${PROJECT_NAME})
install(FILES "${CMAKE_BINARY_DIR}/spaghetti.o2r" DESTINATION . COMPONENT ${PROJECT_NAME} OPTIONAL)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
Expand Down
87 changes: 87 additions & 0 deletions docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,93 @@ cpack
cmake --build build-cmake --target clean
```

## iOS
Requires:
* macOS with Xcode installed
* CMake and Ninja in `PATH`
* Homebrew packages: `cmake ninja sdl2 libpng glew nlohmann-json libzip vorbis-tools sdl2_net tinyxml2 pkg-config git`
* Your own supported Mario Kart 64 ROM

Install the Homebrew dependencies:

```bash
brew install cmake ninja sdl2 libpng glew nlohmann-json libzip vorbis-tools sdl2_net tinyxml2 pkg-config git
```

Build steps:

```bash
# Clone the repo
git clone --recurse-submodules https://github.com/HarbourMasters/SpaghettiKart.git
cd SpaghettiKart

# If needed later
git submodule update --init --recursive

# Put your supported ROM at the repo root with this filename
ln -sf "/path/to/your/baserom.us.z64" baserom.us.z64

# Generate mk64.o2r and spaghetti.o2r from your own ROM
cmake -S . -B build-cmake -GNinja
cmake --build build-cmake --target ExtractAssets

# Configure the iOS build
cmake -S . -B build-ios-make -DCMAKE_BUILD_TYPE=Release -DIOS=ON -DSIGN_LIBRARY=OFF

# Build the app
cmake --build build-ios-make --config Release

# Package an unsigned IPA
# The IPA must contain Payload/ at the archive root.
rm -rf ipa-package
mkdir -p ipa-package/Payload
cp -R build-ios-make/Spaghettify.app ipa-package/Payload/Spaghettify.app
(cd ipa-package && zip -qry ../SpaghettiKart-unsigned.ipa Payload)

# Output
ls SpaghettiKart-unsigned.ipa
```

Notes:
* The IPA produced by these steps is unsigned.
* The build generates `mk64.o2r` and `spaghetti.o2r` from your own ROM and copies them into the iOS app bundle.
* Do not zip `build-ios-make/Payload` directly, or the archive will have the wrong root folder for signing tools.
* No additional mod pack is required for the current iOS build flow.

## iOS Simulator (macOS)
To run the project on the iOS Simulator on a macOS host (Apple Silicon `arm64`), use the following steps. This assumes you have already extracted the assets as shown in the iOS or macOS sections.

### Build steps

```bash
# Clean previous builds to avoid conflicts
rm -rf build-ios-make

# Configure the project for the simulator
# This ensures we target the simulator's arm64 architecture instead of physical devices
cmake -B build-ios-make -G "Unix Makefiles" \
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.toolchain.cmake \
-DPLATFORM=SIMULATORARM64 \
-DCMAKE_OSX_SYSROOT=iphonesimulator \
-DCMAKE_OSX_ARCHITECTURES=arm64

# Compile the project
cmake --build build-ios-make
```

### Running on the Simulator

```bash
# Boot your preferred simulator (e.g., iPhone 16 Pro)
xcrun simctl boot "iPhone 16 Pro"

# Install the app onto the booted simulator
xcrun simctl install booted build-ios-make/Spaghettify.app

# Launch the app
xcrun simctl launch booted dev.net64.game
```

## Getting CI to work on your fork

The CI works via [Github Actions](https://github.com/features/actions) where we mostly make use of machines hosted by Github; except for the very first step of the CI process called "Extract assets". This steps extracts assets from the game file and generates an "assets" folder in `mm/`.
Expand Down
36 changes: 36 additions & 0 deletions ios/Launch.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_12" orientation="landscape" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="932" height="430"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="SpaghettiKart" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vUN-kp-3ea">
<fontDescription key="fontDescription" type="boldSystem" pointSize="34"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
<color key="backgroundColor" red="0.1098039216" green="0.0862745098" blue="0.06274509804" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="vUN-kp-3ea" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="6Tk-OE-BBY"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="RMr-rA-vyq"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
47 changes: 47 additions & 0 deletions ios/plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>@PROJECT_NAME@</string>
<key>CFBundleExecutable</key>
<string>@PROJECT_NAME@</string>
<key>CFBundleIdentifier</key>
<string>@PROJECT_ID@</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>@PROJECT_NAME@</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
</dict>
<key>UILaunchStoryboardName</key>
<string>Launch</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion libultraship
Submodule libultraship updated 150 files
5 changes: 4 additions & 1 deletion src/engine/RaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ void RaceManager::BeginPlay() {
}
}
}
gEditor.AddLight("Sun", nullptr, D_800DC610[1].l->l.dir);

if (gEditor.IsEnabled()) {
gEditor.AddLight("Sun", nullptr, D_800DC610[1].l->l.dir);
}

track->BeginPlay();
}
Expand Down
Loading
Loading