Skip to content

Add native macOS build (.app) and display-rate-aware vsync - #44

Open
Jp4Real wants to merge 1 commit into
mstan:mainfrom
Jp4Real:macos-port
Open

Jp4Real wants to merge 1 commit into
mstan:mainfrom
Jp4Real:macos-port

Conversation

@Jp4Real

@Jp4Real Jp4Real commented Nov 27, 2026

Copy link
Copy Markdown

Adds a working native macOS build that produces a self-contained SuperMarioWorld.app, plus a vsync fix for non-60 Hz displays that benefits every platform.

Tested on a MacBook Air M5 (arm64) with macOS 27, AppleClang 21 and SDL 3.4.20: the app builds cleanly and both the launcher and gameplay work. Full write-up: docs/macos.md.

What changes

  • tools/build-macos.sh: rewrote the bundling, which had fallen behind build-linux.sh.
    • Launcher assets go in Contents/Resources, where SDL_GetBasePath() resolves inside a bundle.
    • The built-in mod catalog is bundled and refreshed on each launch, as the AppImage does.
    • User state (config.ini, keybinds.ini, rom.cfg, saves/, logs/, mods/) lives in ~/Library/Application Support/SuperMarioWorld, never inside the signed bundle (which can also be read-only under App Translocation).
    • Also: the app icon is generated from the box art, the version is read from CMakeLists.txt, dylibbundler runs only when non-system dylibs are linked, and the bundle is ad-hoc signed.
    • The Falcon cache helper is bundled only when the build Python has Pillow and PyInstaller.
    • Opt-in diagnostics are driven by marker files placed next to the .app (diag.flag, bench.flag), so the signed bundle never has to be edited.
  • macos/build-on-mac.sh: one-shot script. It installs the missing Homebrew packages (cmake, sdl3, dylibbundler, plus rust for the first regen), generates src/gen from the owner's smw.sfc on the first run, builds, and logs everything to macos/build.log.
  • macos/patches/snesrecomp-macos-data-dir.patch: on macOS, host_paths.c and keybinds.c now honour SNESRECOMP_DATA_DIR (previously Android-only). It is kept as a patch, applied idempotently by build-macos.sh, so the submodule still points at the upstream pin. Happy to send it to snesrecomp separately if you prefer.
  • src/main.c, src/opengl.c: display-rate-aware vsync. The main loop already paces to 60 Hz with its frame delay. Waiting on vsync as well only works on a ~60 Hz panel. On a 100 Hz monitor, Metal blocked about 20 ms per frame. Stall-log measurement: draw_ms median 19.35 ms, run_ms 0.68 ms. The game dropped to 50 fps, with slow motion and audio crackle. Vsync is now enabled only while the window's display runs at ~60 Hz, and this is re-checked about every 0.5 s so it follows the window across displays. This applies to both the SDL and OpenGL presenters, and to Windows and Linux too (75/100/144 Hz monitors).
  • src/mods/falcon/smw_falcon_presentation_runtime.c: on macOS, the helper is located with _NSGetExecutablePath + realpath, since there is no /proc.
  • tools/regen.sh: replaced a GNU-only sed -i (co-op path) with a portable equivalent for BSD sed.
  • Also adds a README pointer and .gitignore entries for release-macos/ and macos/build.log.

Measurements (M5, after the fix)

  • --benchmark 1800: about 100 fps. The ceiling is the 100 Hz panel's presentation, not the CPU.
  • --benchmark-audio-paced 1800: 60.0 fps, audio_health.ok, 0 underflows.

Not covered

  • The legacy IPS co-op target was not tested on macOS.
  • The app is not notarized.
  • The Linux build was checked to compile with these changes. I did not test a Windows/MSVC build.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KD5Psut8yQnHGZHQ13ARSr

- tools/build-macos.sh: working .app bundling (assets in Resources, built-in
  mod catalog, user state in ~/Library/Application Support, app icon,
  version from CMakeLists, dylib bundling, ad-hoc signing, opt-in
  diagnostics via marker files), applies the engine patch below.
- macos/build-on-mac.sh: one-shot setup (Homebrew deps, first-run regen
  from the owner's ROM) and build, logged to macos/build.log.
- macos/patches/snesrecomp-macos-data-dir.patch: honour
  SNESRECOMP_DATA_DIR on macOS in host_paths.c and keybinds.c so nothing
  is written inside the signed bundle. Kept as a patch so the submodule
  still points at the upstream pin.
- src/main.c, src/opengl.c: enable vsync only when the window's display
  runs at ~60 Hz (re-checked periodically). On a 100 Hz monitor the
  60 Hz frame timer plus vsync made Metal block ~20 ms per frame
  (50 fps, slow motion and audio crackle).
- Falcon cache helper path via _NSGetExecutablePath (no /proc on macOS).
- tools/regen.sh: portable sed for BSD sed.
- docs/macos.md: build instructions, layout, measurements, limitations.

Tested on a MacBook Air M5 (macOS 27, SDL 3.4): builds cleanly, launcher
and gameplay run; audio-paced benchmark 60.0 fps with no underflows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KD5Psut8yQnHGZHQ13ARSr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant