The engine now uses SDL3 on every platform, built from the official
sources and linked statically (SDL3 3.4.16, SDL3_image 3.4.6,
SDL3_mixer 3.2.4, SDL3_ttf 3.2.2, FreeType 2.13.3). Runs on the
R36S Plus (dArkOS, Mali-G31).
- No dependency on the firmware's SDL2 any more: the binary only needs
OpenGL ES and libc, SDL3 loads display, sound and input libraries at
run time (min glibc 2.29)
- Device build: KMSDRM console build, libdrm/gbm headers in the
Docker image
- Take over SDL2-era variables set by PortMaster (SDL_VIDEO_EGL_DRIVER
-> SDL_EGL_LIBRARY), so the Mali driver is used instead of Mesa
- Rotated panels: rotation from the kernel's panel orientation or
ROTATE, the frame is turned on present - one build for all devices
- Display diagnostics in log.txt when no GL window can be opened
- SDL main callbacks: no main() any more, SDL owns the loop
(SDL_AppInit/Event/Iterate/Quit); engine input gets input_event,
input_frame and input_next_frame
- Audio rewritten for SDL3_mixer, new sound_channel_pitch()
- Linux: try ALSA before PulseAudio (no error in the log on firmwares
without PulseAudio)
- Engine sound: recorded propeller plane ("Prop Plane" by Mozfoo,
CC0) cut to a seamless loop by tools/make_engine_loop.py, pitch
follows the throttle; generated hum as fallback
- HUD names keyboard keys or gamepad buttons, depending on what was
used last ({A}, {DPAD}, ... tokens in the translations)
- Start screen explains throttle and brake; HUD text that is too wide
is scaled down instead of cut off
- New debug switches START_Y, START_TIME, START_DIAMONDS, BUTTONS;
PortMaster screenshot shows collecting a diamond below a bird flock
- Licenses and README updated (SDL3, hidapi, dr_libs, FreeType,
engine sound)
Signed-off-by: Peter Siegmund <developer@mars3142.org>
Barnstormer
A 3D side-scrolling flight game for the R36S Plus (720x720) and the R36S (640x480), ArkOS/dArkOS, aarch64, launched as a PortMaster port. Inspired by the flying part of DuckTales: The Quest for Gold (1990): take off, fly the course without touching anything, and land at the finish.
The course: take-off runway, hills with peaks and bird flocks, a rocky canyon with a ceiling, stalactites and stalagmites, more hills, the approach and a landing runway with a hangar. Diamonds can be collected along the way.
| Button (device) | Key (Mac) | Action |
|---|---|---|
| A | Space | throttle up (hold) |
| B | Left Shift | throttle down, on the ground: brake |
| D-pad up/down, left stick | Arrow keys | nose up/down |
| Start | Enter | pause; after a crash/landing: new flight |
| X (start screen) | C | switch language (English / Deutsch) |
| Select + Start | Esc | quit |
Flying:
- Take-off: Open the throttle. From about 60 km/h the nose can be lifted. If you don't pull up, you roll off the end of the runway.
- Climbing: Climbing costs speed, descending gains speed. Below about 45 km/h the plane stalls and drops.
- Landing: Only the wheels may touch down, and only on the runway. The sink rate must stay below 4.5 m/s; the variometer at the bottom right turns green, yellow or red. Then brake with B before the hangar.
- Score: diamonds × 100, a time bonus and the runway length left.
Best flights: Every landing enters the list of the five best flights; a crash does not count.
The list is shown on the start screen and after the landing, with the new place in gold.
It is kept in highscores.txt in the data folder. On the device that is ports/barnstormer/conf/barnstormer/, because the launcher sets XDG_DATA_HOME to conf/.
On the Mac it is ~/Library/Application Support/barnstormer/.
The file is first written to a temporary file which is then renamed, so switching the device off while saving keeps the old list instead of a broken one.
Autopilot runs save nothing unless DATA_DIR is set.
Language: English is the default, German is included.
The language is chosen like this: the saved choice (language.txt in the data folder, switched with X on the start screen), otherwise the system language via SDL, otherwise English.
Firmwares usually don't pass their language on to ports, which is why the game can switch it itself.
All texts are in src/i18n/i18n.c. The game logic only hands out text ids, e.g. for crash reasons.
Button names in texts are tokens ({A}, {DPAD}, ...): the HUD names the gamepad's buttons or the keyboard's keys, depending on what was used last
(without a gamepad from the start: the keyboard).
Sound: The engine is a real recording of a propeller plane ("Prop Plane" by Mozfoo, CC0), cut to a seamless 5 s loop by tools/make_engine_loop.py.
Its pitch follows the throttle and speed. It is high-passed at 150 Hz, since handheld speakers can't play deeper sounds anyway.
All other sounds (diamond, crash, touchdown, stall warning, fanfare) are generated at run time.
If assets/sounds/engine.wav is missing, a generated engine hum takes its place.
Requirements
- Docker Desktop (Apple Silicon: the arm64 container runs natively)
- On the Mac only CMake and the Xcode command line tools. CMake fetches SDL3, SDL3_image, SDL3_mixer, SDL3_ttf, FreeType and flecs itself (official release archives, SHA256-checked) and builds them; Homebrew is not needed.
Building
make run # build natively on the Mac and start in a 720x720 window (R36S Plus)
make run-r36 # the same in a 640x480 window (R36S)
make test # unit and smoke tests on the Mac
make screenshot # recreate the PortMaster screenshot (port/screenshot.png, 640x480)
make package # build for the device (Docker, incl. tests on aarch64) -> dist/
make install-card # copy to the mounted SD card (CARD=/Volumes/R36S-PLUS)
make deploy # copy to the running device via SSH (HOST=ark@<ip>)
Then refresh the game list on the device. The game appears under Ports.
Renaming
The name is set in one place only: project(...) in CMakeLists.txt.
Binary, port folder, launcher, window title and Docker image are derived from it.
PortMaster requires lowercase letters, digits, _ and . for the port folder.
The menu entry on the device (= the name of the .sh file) is the capitalised name (barnstormer → Barnstormer.sh, canyon_flyer → Canyon Flyer.sh).
It can also be set separately:
make package TITLE="Sky Run" # -> Sky Run.sh
The first make package pulls the official PortMaster build image once (docker/Dockerfile, Ubuntu 20.04, pinned to a tested digest).
The first build (Mac and container) needs internet access, because CMake downloads the libraries. Afterwards they are in build-*/_deps/.
PortMaster package
make package creates the port according to the PortMaster packaging spec:
dist/
├── barnstormer/ as in the PortMaster-New repository (for a pull request)
│ ├── port.json metadata (min_glibc is read from the binary)
│ ├── README.md notes, thanks, controls, build instructions
│ ├── screenshot.png 640x480 (4:3), gameplay
│ ├── gameinfo.xml entry for the game list
│ ├── Barnstormer.sh launcher (from port/launcher.sh.in)
│ └── barnstormer/
│ ├── barnstormer.aarch64 binary (stripped)
│ ├── assets/
│ ├── licenses/ licenses of everything included (overview: README.txt)
│ └── screenshot.png image for gameinfo.xml on the device
└── barnstormer.zip installable archive: launcher + game folder
The templates are in port/. The launcher follows the current PortMaster template:
control.txt and get_controls, $GPTOKEYB only for the exit hotkey, pm_platform_helper and pm_finish.
It passes ShellCheck without findings. Packaging also validates port.json (JSON) and gameinfo.xml (XML).
The screenshot is always taken in English, PortMaster's language.
Still missing for a PortMaster submission:
- testing on several firmwares (AmberELEC, dArkOS, muOS, ROCKNIX, Knulli) at 640x480 and higher, documented in the Discord channel #testing-n-dev
- check
porterinport/port.json.in(currentlymars3142)
3D rendering
The scene is drawn with OpenGL: OpenGL ES 2.0 on the device (Mesa/Panfrost),
OpenGL 2.1 on the Mac. Shaders are written without #version; gl_program() prepends the matching line
(#version 100 or #version 120). Both versions accept the same shader code.
- Camera: perspective, beside the flight lane, looking slightly down. The field of view follows the aspect ratio, so at least 22 × 17 m are visible at 1:1 as well as at 4:3. At 4:3 you therefore see further ahead.
- Terrain (
terrain.c): built once as a mesh from the level's height profile; only the visible columns are drawn. In the flight lane it matches the collision profile exactly. Behind it, hills rise; in the canyon, floor and ceiling close into a cave. A cut face towards the camera shows the profile. - Lighting: sun, a headlight on the plane inside the canyon, distance fog, rock strata, grass and runway markings in the shader.
- Objects: a biplane built from primitives with a spinning propeller, birds flapping their wings, diamonds, trees, tower, hangar, windsock, runway lights.
- Effects: exhaust, dust when rolling and touching down, an explosion with debris, sparks, camera shake.
- HUD: scaled by the shorter screen side (text stays sharp).
Debug variables for ./build-desktop/<name>:
| Variable | Effect |
|---|---|
WINDOW=640x480 |
window size |
SCREENSHOT=out.bmp |
saves frame SCREENSHOT_FRAME (default 90) and quits |
START_X=600 |
starts in the air at this position on the course |
START_Y=8 |
... at this height (default: the safe line between ground and ceiling) |
START_TIME=48.6, START_DIAMONDS=11 |
... with this flight time and diamond count on the HUD (realistic screenshots) |
AUTOPILOT=1 |
flies by itself and logs the crash or landing (exit code 1 if it does not land) |
FAST=1 |
fixed 1/60 s steps without vsync: as fast as the GPU renders, same result |
DATA_DIR=dir/ |
folder for best flights and language instead of the default data folder |
BUTTONS=pad |
the HUD names gamepad buttons (or keyboard keys) regardless of what was used last |
ROTATE=90 |
turn the picture (0, 90, 180, 270) for panels mounted rotated that don't report it |
Tests
make test (on the Mac) and make build (in the container, on aarch64) run the unit tests with ctest:
| Test | checks |
|---|---|
tests/test_level.c |
course is reproducible, runways are flat, the canyon is never too narrow, slopes are flyable, diamonds and birds are in free space |
tests/test_systems.c |
every ECS system on its own in a small hand-built world: movement, input reaches only the player, patrols (range, turning, deterministic), collecting incl. deleting the entity, hitbox overlap, lift, optional Controls, controls, runway end, rolling out, touchdown and rock ceiling |
tests/test_game.c |
the whole game: take-off, stall, climbing costs speed, cloud ceiling, collisions with ceiling/mountain/bird, diamonds, soft and hard landing, landing beside the runway, overrunning, pause, restart (world rebuilt, no leftovers), a landing enters the best flights, a crash does not. An autopilot also flies the whole course and has to land. |
tests/test_highscore.c |
best flights: order, only five places, the older entry wins a tie, saving and loading, missing or damaged file, no temporary file left over, unwritable path |
tests/test_i18n.c |
English as default, every text in every language, the same printf conversions in all languages, language codes and locales (de_DE.UTF-8), switching, saved choice |
tests/test_math.c |
vectors, matrices, rotations, camera and shadow projection of the engine |
smoke_flight_plus / smoke_flight_r36 |
Mac only: the real game (window, OpenGL, HUD, audio) flies the whole course by autopilot at 720x720 and 640x480. Fails on an OpenGL error or if it does not land. |
smoke_highscore_saved |
Mac only: after the 720x720 flight (with a fresh DATA_DIR) the landing must be in highscores.txt |
smoke_screenshot |
Mac only: screenshot from inside the canyon (build-desktop/smoke.bmp) |
The smoke tests run with FAST=1 (fixed 1/60 s steps without vsync) and take about 9 seconds together; a window opens briefly.
The container (make build) has no display, so only the unit tests run there.
Coverage (lines, all tests on the Mac): game logic (level, world, systems, game) and terrain 100 %, rendering 88 %, HUD 94 %, main.c 87 %.
What is missing are mainly error paths (shader does not compile, font missing) and inputs the autopilot never presses.
ECS (flecs)
The moving things are entities in a flecs world (v4.1.6, MIT).
CMake fetches flecs at configure time with FetchContent (release archive, SHA256-checked) and builds only the parts the game uses (systems, query language).
| Entity | Components |
|---|---|
| Plane | Player (tag), Transform, Motion, Aircraft, Controls, Body, Hitbox, Visual |
| Diamond | Transform, Pickup, Visual |
| Bird | Transform, Patrol, Hitbox, Hazard, Visual |
The systems (systems.c) know no game states: they report what happened (SimEvents: crash, touchdown, collected, ...).
game.c turns that into rules (states, score, messages).
The systems have no pipeline phase: game.c runs them with ecs_run in a fixed order and in fixed physics sub-steps.
This keeps the result deterministic, so the autopilot test always flies the same way.
The renderer draws birds and diamonds through a query on Transform, Visual, ?Patrol.
Engine and game
The engine (engine/) is a CMake library of its own and knows no game:
- Its only include path is
engine/include/- an#include "game.h"inside the engine breaks the build. - Game values (title, resolution, deadzone) are passed in at start-up (
PlatformConfig,input_init). inputprovides generic handheld buttons (BTN_A,BTN_START, ...); the game decides what they mean. It works with SDL's main callbacks (input_eventper event,input_frame/input_next_frameper frame) as well as with a polling loop (input_update). Keyboard on the Mac: arrows = D-pad, Space = A, Left Shift = B, C/V = X/Y, Q/E = L1/R1, Enter = Start, Backspace = Select, Esc = quit.audioloads sound files (sound_load) or generates tones (sound_sweep).
For a second game it is enough to take engine/ along (e.g. as a git submodule).
Target system and libraries
Tested for dArkOS RE on the R36S Plus (RK3326, 720x720, Mesa/Panfrost) and the R36S (640x480). Built with the official PortMaster image (glibc 2.31), so the binary also starts on systems with an older base.
The engine uses SDL3 on every platform, built from the official source and linked statically:
| Library | version | notes |
|---|---|---|
| SDL3 | 3.4.16 | on the device: KMSDRM (straight to the display), OpenGL ES, ALSA/PulseAudio, udev |
| SDL3_image | 3.4.6 | PNG/JPG via the built-in stb_image |
| SDL3_mixer | 3.2.4 | WAV, OGG (stb_vorbis), MP3/FLAC (dr_libs) built in |
| SDL3_ttf | 3.2.2 | with FreeType 2.13.3 from the official FreeType release |
| flecs | 4.1.6 |
SDL3 loads the system libraries it needs (libdrm, gbm, EGL, ALSA, udev) at run time, as every firmware has them.
The port therefore ships no libs.aarch64/; readelf -d shows only libGLESv2 and the libc libraries.
The firmware's own SDL2 (and dArkOS' SDL3 built on top of it) is never used.
The build image needs the libdrm and gbm headers for SDL3's KMSDRM driver; docker/Dockerfile installs them.
Rotated displays: dArkOS patches its SDL2 to turn the picture with the RGA chip on devices whose panel is mounted rotated,
in a separate build per device type. Barnstormer does it at run time instead:
SDL3 reports the kernel's "panel orientation", and in that case the game draws into an offscreen buffer of the upright size,
which platform_present() puts on the screen turned. ROTATE=90 (or 180, 270) in the launcher overrides it for panels that don't report it.
Without rotation the game draws straight to the screen.
Adding a library: preferably with FetchContent in engine/CMakeLists.txt, linked statically.
If that is not possible, the .so goes into <name>/libs.aarch64/; the launcher already sets LD_LIBRARY_PATH for it.
VS Code
On opening, VS Code suggests the matching extensions (.vscode/extensions.json):
clangd, CodeLLDB, CMake Tools, Container Tools, ShellCheck and Remote-SSH.
Microsoft's C/C++ extension is deliberately left out because it conflicts with clangd.
- F5: build on the Mac and start with the debugger (CodeLLDB)
- ⇧⌘B: build on the Mac
- Tasks: Run Task:
Mac: run,Mac: run as R36S (640x480),Mac: test,R36: package,R36: install to SD card,R36: deploy via SSH,clean
clangd needs compile_commands.json. It is created by the first make desktop or ⇧⌘B.
Layout
engine/ reusable base as a static library (libengine.a)
CMakeLists.txt fetches and builds SDL3, SDL3_image/mixer/ttf and FreeType (static); only include/ is public
include/engine/ interface: platform.h, input.h, audio.h, gl.h, mat4.h, draw.h, vec2.h, scalar.h
src/ implementation
src/ the game (sees only engine/include/, never engine/src/); includes start at src/: "logic/game.h"
main.c SDL main callbacks (no main(): SDL_AppInit/Event/Iterate/Quit), data folder, language, debug switches
config.h game constants (flight model, limits, font)
logic/ game logic without graphics or sound = library game_logic, fully tested
level.c/.h course generator: height profile, canyon, runways, diamonds, birds
world.c/.h ECS components (flecs)
systems.c/.h ECS systems: input, patrol, controls, flight model, movement,
rolling, terrain collision, collecting, hazards
game.c/.h states, score, entities of the course, order of the systems
autopilot.c/.h flies by itself (AUTOPILOT=1, tests)
highscore.c/.h best flights: sorting, loading, saving
storage.c/.h writing files safely (temporary file + rename)
i18n/ translations (English, German), language choice
render/ OpenGL
terrain.c/.h 3D terrain from the height profile
render.c/.h shaders, camera, the steps of a frame
models.c/.h the 3D objects: biplane, birds, diamonds, trees, buildings, runway lights
effects.c/.h particles and debris (simulation only, no OpenGL)
internal.h what the render files share (camera, render_mesh)
hud.c/.h sky, instruments, messages, best flights
sound/ generated sounds: engine, stall warning, events
tests/ unit tests (ctest), check.h = minimal test framework
assets/ copied into the port as a whole: fonts/ (DejaVu Sans), sounds/ (engine loop, CREDITS.txt)
tools/ make_engine_loop.py: cuts the engine loop from the recording
port/ PortMaster templates: launcher.sh.in, port.json.in, gameinfo.xml.in, README.md.in,
licenses-README.txt, screenshot.png (@NAME@/@TITLE@ are filled in when packaging)
docker/Dockerfile build environment: the official PortMaster image (aarch64)
Makefile build / run / test / package / install-card / deploy
IMPROVEMENTS.md what could still be improved, by priority
On the SD card:
ports/
├── <TITLE>.sh
└── <name>/
├── <name>.aarch64 binary
├── assets/ fonts, images, sounds
├── licenses/
├── conf/ the game's XDG_DATA_HOME
└── log.txt output of the last start
Debugging
ports/<name>/log.txtcontains allSDL_Logoutput of the last start.- SSH: in ArkOS Options → Enable Remote Services, login usually
ark/ark.
License
The game is released under the MIT license (LICENSE).
All dependencies are compatible with it; none of them is copyleft:
| Component | License | in the port |
|---|---|---|
| flecs | MIT | linked statically |
| SDL3, SDL3_image, SDL3_mixer, SDL3_ttf | zlib | linked statically |
| hidapi (in SDL3) | BSD (chosen out of GPLv3 / BSD / original) | linked statically |
| FreeType 2.13.3 | FTL (chosen instead of GPLv2) | linked statically |
| stb_image, stb_vorbis | public domain / MIT | linked statically |
| dr_flac, dr_mp3 | public domain / MIT-0 | linked statically |
| DejaVu Sans | Bitstream Vera license | assets/fonts/ |
| Engine sound: "Prop Plane" by Mozfoo (Freesound 440163) | CC0 1.0 | assets/sounds/engine.wav |
| OpenGL ES, libdrm, gbm, ALSA, udev, glibc | driver / MIT / LGPL | not included, provided by the device |
make package puts all license texts into <name>/licenses/.
The FTL requires a credit in the documentation; it is in the port's README (port/README.md.in).