Skip to content
cleoankaPublic

About

Native-Metal build of engine-sim (real-time combustion-engine simulator) for Apple-Silicon macOS

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

redline

A native-Metal build of the real-time combustion-engine simulator, for Apple Silicon macOS.

macOS build Platform Renderer License

redline running a Chevrolet 454 V8, revving from idle to redline

A Chevrolet 454 big-block, simulated in real time — pistons pumping, crank spinning, exhaust waveform dancing, gauges sweeping to redline. Rendered natively through Metal.


What is this?

engine-sim by AngeTheGreat is a real-time internal-combustion-engine simulation that generates its own engine audio from a physical model of the gas dynamics, combustion, and valvetrain — you build an engine in a small script language and hear it idle, rev, and hit the limiter.

The catch: it only runs on Windows, through DirectX 11. redline brings it to Apple Silicon macOS with a native Metal renderer, SDL2 for windowing/input/audio, a modern 2026 toolchain, the long-standing rendering bugs fixed, and a proper double-clickable .app.

the V8 cross-section, pistons pumping    redline app icon

It's a toy for making engine sounds and exploring engine response — not a scientific engineering tool.

Why this fork

A Metal port already existed — boxofbox/engine-sim-APPLE_ARM had done the hard work of writing a native Metal backend (metal-cpp) into engine-sim's renderer, delta-studio. But it went dormant in early 2023: it no longer builds on a modern macOS toolchain, and it shipped with three known rendering bugs. redline revives it — builds on macOS 26 (Tahoe) / CMake 4 / Apple clang 21 / Boost 1.90, fixes the bugs, and packages it as a real app.

The headline fix

Two of the three bugs were HiDPI point-vs-pixel mistakes. The interesting one was the scrambled engine cross-section: engine-sim renders the engine into a sub-region of the screen (its own viewport) while the UI is drawn full-screen — but in the Metal backend the sub-render-target functions were stubs, and SetRenderTarget's signature didn't even match the one the render loop calls. So the engine, projected for its little box, was drawn across the whole screen, on top of the gauges. Implementing the viewport fixed it:

before: engine drawn full-screen over the UI; after: a clean V8 confined to its region

Architecture

The valuable core — the physics and the audio synthesis — is portable C++ and untouched. redline only replaces the platform layer: the renderer (→ Metal) and windowing/audio (→ SDL2).

redline data-flow: .mr script → piranha → Simulator → { synthesizer → SDL2 audio } + { delta-studio → Metal → screen }

Build

# arm64 Homebrew (/opt/homebrew)
brew install cmake boost bison sse2neon sdl2 sdl2_image flex

git clone https://github.com/cleoanka/redline.git
cd redline
export PATH="/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/flex/bin:/opt/homebrew/bin:$PATH"
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DDISCORD_ENABLED=OFF
cmake --build build --target engine-sim-app -j

cd build && ./engine-sim-app     # run from build/ so it finds ../assets

Package as a double-clickable app

cmake --build build --target redline-app   # -> dist/redline.app
open dist/redline.app                       # or double-click it in Finder

Controls

Minimal, keyboard-driven:

Key Action Key Action
O / P Change engine (prev / next) Enter Reload engine script
A Toggle ignition S Hold for starter
D Enable dyno H RPM hold (needs dyno)
Q W E R Throttle presets Space Fine throttle (+scroll)
↑ / ↓ Shift gear up/down Shift Clutch
Z/X/C/V/B + scroll Audio mix Tab Change screen
M / , View layer up/down F Fullscreen
1–5 Time-warp (slow-mo) Esc Quit

Change the engine live with O (previous) and P (next) — cycles through 16 built-in engines (Chevy 454 V8, Hayabusa I4, 2JZ I6, LFA V10, Merlin V12, radials, …). No file editing. ([ / ] also work on a US keyboard.)

Gamepad (Xbox controller)

Plug in an Xbox (or any SDL-recognised) controller — hot-plug works, no config:

Control Action Control Action
Right trigger Analog throttle Left trigger Clutch
A Starter (hold) B Ignition
X Dyno Y Reload engine
RB / LB Next / previous engine D-pad ↑/↓ Shift gear
Left stick ↕ Volume Right stick ↕ Time-warp
Start Pause

Keyboard and gamepad compose — either works at any time.

Headless capture & demo knobs (how the GIFs above were made)

The macOS sandbox this was developed in has no Screen-Recording permission, so redline grew a way to record itself — the app reads back its own Metal drawable:

Env var Effect
REDLINE_CAPTURE=<path> dump a frame as raw BGRA8 (int32 w, int32 h, then pixels)
REDLINE_CAPTURE_FRAME=<n> which single frame (default 90)
REDLINE_CAPTURE_SEQ=start,stride,count dump a sequence → <path>.000, .001, …
REDLINE_AUTORUN=1 crank + rev the engine unattended (for demos / captures)

All are no-ops unless set. The GIFs on this page are REDLINE_AUTORUN=1 + REDLINE_CAPTURE_SEQ assembled with Pillow.

Credits & lineage

redline stands on a chain of open-source work — thank you to everyone in it:

See docs/DESIGN.md · CHANGELOG.md · docs/METAL_BACKEND.md.

License

MIT — see LICENSE and NOTICE. Upstream copyright preserved.

About

Native-Metal build of engine-sim (real-time combustion-engine simulator) for Apple-Silicon macOS

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages