# Contributing to pfeilstorch The [README](README.md) says what pfeilstorch is and how far along it is. ## Issues and pull requests Report bugs and open pull requests on the Tangled mirror: . ## Setting up Everything comes from the Nix flake: ```console $ nix develop $ zig build test --summary all $ zig build run ``` The development shell has Zig 0.17.0, the Vulkan loader and its validation layer, `spirv-val` (the tests check the shaders with it), REUSE, and for the Android build the Android SDK and NDK, `adb`, and a JDK for `apksigner` and `keytool`. ## Before you send a change All of these must pass, and CI runs each of them: ```console $ nix develop -c zig fmt --exclude zig-pkg --check . $ nix develop -c reuse lint $ nix develop -c zig build test --summary all $ nix develop -c zig build apk $ nix build ``` A bounded fuzz run is worth doing after touching the generator, the solver or the text format. A finding prints `input saved to '.zig-cache/f/crash'`: ```console $ nix develop -c zig build test --fuzz=1M ``` ## Dependencies Zig dependencies are in `build.zig.zon`, and the package build gets them from Nix rather than fetching them itself. After adding, removing or updating one, regenerate the list Nix fetches, check that the package still builds, and commit both files: ```console $ nix develop -c tools/zon2nix.sh $ nix build ``` ## How the code is laid out - `src/rules` is the game with no platform in it: no I/O, no clock, no allocation it does not ask its caller for. Anything that touches a window, a GPU or the file system belongs in a shell around it, not here. - A tap's outcome is decided at once. Animation is presentation, and the rules never wait for it. - `src/view` is the game on a screen, still with no platform: layout, taps, animation, and each frame as a list of shapes. It takes the time from its caller rather than reading a clock, which is what lets its tests step through an animation. - `src/vulkan` draws a list of shapes, and is meant for every platform that has Vulkan. `shaders/shapes.zig` is its shaders, in Zig. - `src/android` is the Android shell: the glue between `NativeActivity`'s callbacks and the game's own thread, input, the choreographer that paces frames, and the few JNI calls. `src/android.zig` is the root of that library, and `android/` holds the manifest and resources. - `src/wayland` is the Linux shell: the window, input, and handing frames to the compositor, the settings file, the desktop's accent color, and where the level reached is kept. `src/linux.zig` is the root of that build. To see a change to how the game draws without a screen, draw a frame into a PNG: ```console $ nix develop -c zig build run -- --snapshot out.png --level 30 --tap 3,0 --at 80 ``` and `--validation` turns on Vulkan's validation layer, which the devshell provides. ## Words and decisions Use the words in [GLOSSARY.md](GLOSSARY.md): an arrow *exits* or is *blocked*, and the arrow in the way is the *blocker*. A new concept gets its word added there. A decision that is hard to reverse, would surprise a reader, and came out of a real trade-off gets a short record in [docs/adr](docs/adr). ## Levels are seeds A level's board is built from its number by the generator, so changing `src/rules/level.zig`, `src/rules/generate.zig` or `src/rules/Random.zig` can change every level in the game. The test pinning level 1 fails when that happens; update it only when changing the levels is the point. ## Licensing Code is MIT. Every file carries an SPDX header, or is covered in `REUSE.toml` if it cannot hold one, and `reuse lint` must pass. ## Android `zig build apk` signs the package with `-Dkeystore=PATH` if that is given, otherwise with `~/.android/debug.keystore` if there is one, and otherwise with a key made for that build alone. A package can only be installed over one signed with the same key, so for installing again and again make the debug keystore once: ```console $ mkdir -p ~/.android $ nix develop -c keytool -genkeypair -keystore ~/.android/debug.keystore \ -storepass android -keypass android -alias androiddebugkey \ -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=Android Debug,O=Android,C=US" ``` To try the game without a phone, start an emulator and install into it: ```console $ nix run .#emulator $ nix develop -c zig build run-android ``` The emulator draws Vulkan in software unless it is given the host's GPU; `NIX_ANDROID_EMULATOR_FLAGS="-gpu host"` asks for that, and `-no-window` runs it with no window, for `adb exec-out screencap` to look at.