Skip to content
Merged
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
20 changes: 14 additions & 6 deletions .github/workflows/switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ name: Build Nintendo Switch NRO

on:
push:
branches:
- master
paths:
- '.github/workflows/switch.yml'
- 'CMakeLists.txt'
- 'src/**'
- 'thirdparty/**'
- 'shadowflare/**'
- 'thirdparty/twl/**'
- 'thirdparty/tal/**'
- 'tools/switch/**'
pull_request:
paths:
- '.github/workflows/switch.yml'
- 'CMakeLists.txt'
- 'src/**'
- 'thirdparty/**'
- 'shadowflare/**'
- 'thirdparty/twl/**'
- 'thirdparty/tal/**'
- 'tools/switch/**'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -34,11 +42,11 @@ jobs:
run: sh tools/switch/build-nro.sh

- name: Verify the NRO
run: test -s build/switch/release/src/SF_EXE/ShadowFlare_rebuilt.nro
run: test -s build/switch/release/OpenShadowFlare.nro

- name: Upload the NRO
uses: actions/upload-artifact@v4
with:
name: openshadowflare-switch-release
path: build/switch/release/src/SF_EXE/ShadowFlare_rebuilt.nro
path: build/switch/release/OpenShadowFlare.nro
if-no-files-found: error
17 changes: 8 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ option(
ON
)

if(NINTENDO_SWITCH)
set(OPENSHADOWFLARE_DEFAULT_PRESENTATION_BACKEND "nxfb")
else()
set(OPENSHADOWFLARE_DEFAULT_PRESENTATION_BACKEND "lgl")
endif()
set(OPENSHADOWFLARE_DEFAULT_PRESENTATION_BACKEND "lgl")
set(
OPENSHADOWFLARE_PRESENTATION_BACKEND
"${OPENSHADOWFLARE_DEFAULT_PRESENTATION_BACKEND}"
Expand All @@ -37,14 +33,17 @@ set(
)
set_property(
CACHE OPENSHADOWFLARE_PRESENTATION_BACKEND
PROPERTY STRINGS lgl nxfb
PROPERTY STRINGS lgl
)

add_subdirectory(thirdparty/lwl)
add_subdirectory(thirdparty/lal)
if(OPENSHADOWFLARE_BUILD_EXE OR BUILD_TESTING)
add_subdirectory(thirdparty/lwl)
add_subdirectory(thirdparty/lal)
endif()
add_subdirectory(thirdparty/twl)
add_subdirectory(thirdparty/tal)
if(OPENSHADOWFLARE_PRESENTATION_BACKEND STREQUAL "lgl" OR BUILD_TESTING)
if((OPENSHADOWFLARE_BUILD_EXE AND
OPENSHADOWFLARE_PRESENTATION_BACKEND STREQUAL "lgl") OR BUILD_TESTING)
add_subdirectory(thirdparty/lgl)
endif()

Expand Down
69 changes: 22 additions & 47 deletions documentation/switch-port.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,45 @@
# Nintendo Switch port

OpenShadowFlare builds as a Nintendo Switch homebrew application (`.nro`) via
libnx. The NRO does not include the original game data.
The Switch build compiles the small C99 ShadowFlare runtime and packages it as a
libnx homebrew application (`.nro`). It does not include retail game data.

## Build locally
## Install the toolchain

Install devkitPro's Switch environment (`devkitA64`, `libnx`, and
`switch-tools`). In the devkitPro MSYS2 shell or a POSIX shell on Linux, run from the repository root:
Install devkitPro's Switch toolchain and Ninja:

```bash
sh tools/switch/build-nro.sh
sudo dkp-pacman -S --needed switch-dev ninja
```

The script uses devkitPro's Switch CMake toolchain and Ninja, configures a
release build, disables host-only tests, and writes the result to:
Set `DEVKITPRO` if devkitPro is not installed at `/opt/devkitpro`.

```text
build/switch/release/src/SF_EXE/ShadowFlare_rebuilt.nro
```
## Build

If `build/switch/release` was previously configured with another CMake
generator, remove it once before running the script:
From the repository root:

```bash
rm -rf build/switch/release
sh tools/switch/build-nro.sh
```

## GitHub Actions

`Build Nintendo Switch NRO` runs the same script in the pinned devkitPro
container and uploads `openshadowflare-switch-release` as a workflow artifact.
Download that artifact to test a CI build; no local devkitPro or Android Studio
installation is required.

## Add game data

On Switch hardware, place the NRO beside a `ShadowFlare` directory:
The application is written to:

```text
sdmc:/switch/OpenShadowFlare/
ShadowFlare_rebuilt.nro
ShadowFlare/
SFlare.Cfg
System/
...
build/switch/release/OpenShadowFlare.nro
```

## Move the game files

The retail data is loaded from the SD card and is never bundled. Copy your
ShadowFlare `System` folder and `SFlare.Cfg` into a `ShadowFlare` folder at the
SD root:

```text
<Emulator data folder>/sdcard/switch/ShadowFlare/
sdmc:/ShadowFlare/
SFlare.Cfg
System/
...
...
```

Load the NRO with **File > Load Application**

## Controls

| Switch input | Game action |
| --- | --- |
| Touchscreen | Pointer movement and primary click |
| D-pad | Menu navigation and movement |
| A / Plus | Confirm |
| B / Minus | Back / cancel |
| X | Inventory |
| Y | Map |
| L | Mission list |
| R | Toggle walk/run |
| ZL | Open the character-name keyboard |
On an emulator this is the `sdcard/ShadowFlare/` folder inside its data
directory. Copy `OpenShadowFlare.nro` to `sdmc:/switch/` and launch it from the
homebrew menu.
12 changes: 12 additions & 0 deletions shadowflare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,15 @@ if(OPENSHADOWFLARE_ENABLE_DEBUG_TOOLS)
Twl::Twl
)
endif()

if(NINTENDO_SWITCH)
target_compile_definitions(
shadowflare_core PRIVATE SF_RETAIL_ROOT_FALLBACK="sdmc:/ShadowFlare")

if(NOT COMMAND nx_create_nro)
message(FATAL_ERROR
"nx_create_nro is unavailable. Configure the Switch build with "
"-DCMAKE_TOOLCHAIN_FILE=$ENV{DEVKITPRO}/cmake/Switch.cmake.")
endif()
nx_create_nro(osf ICON "${PROJECT_SOURCE_DIR}/readme/sf-logo-sm.jpg")
endif()
3 changes: 3 additions & 0 deletions shadowflare/assets/retail_paths.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ bool sf_retail_root_find(
root[0] = '\0';
if (requested_root)
return sf_retail_try_root(root, capacity, requested_root);
#ifdef SF_RETAIL_ROOT_FALLBACK
if (sf_retail_try_root(root, capacity, SF_RETAIL_ROOT_FALLBACK)) return true;
#endif
if (sf_retail_executable_directory(
executable_directory, sizeof(executable_directory), executable_path)) {
if (sf_retail_try_root(root, capacity, executable_directory)) return true;
Expand Down
3 changes: 0 additions & 3 deletions src/SF_EXE/cmake/configure_platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ function(osf_configure_platform target)
if(EMSCRIPTEN)
include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/platforms/Emscripten.cmake")
osf_configure_emscripten_platform(${target})
elseif(NINTENDO_SWITCH)
include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/platforms/Switch.cmake")
osf_configure_switch_platform(${target})
elseif(
WIN32
OR APPLE
Expand Down
6 changes: 0 additions & 6 deletions src/SF_EXE/cmake/configure_presentation.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ function(osf_configure_presentation target)
runtime/presentation/lgl_surface_presenter.cpp
)
target_link_libraries(${target} PRIVATE Lgl::Lgl)
elseif(OPENSHADOWFLARE_PRESENTATION_BACKEND STREQUAL "nxfb")
target_sources(
${target}
PRIVATE
runtime/presentation/switch_surface_presenter.cpp
)
else()
message(FATAL_ERROR
"Unsupported presentation backend: "
Expand Down
20 changes: 0 additions & 20 deletions src/SF_EXE/cmake/platforms/Switch.cmake

This file was deleted.

13 changes: 0 additions & 13 deletions src/SF_EXE/runtime/platform/switch/application_loop.cpp

This file was deleted.

Loading
Loading