Engine & contributing
Architecture
How rugen-engine is split into crates, why the simulation stays pure, and the determinism rules that make rollback netplay possible.
rugen is a drop-in replacement for M.U.G.E.N / Ikemen GO content, written in Rust, with two hard requirements:
- Runs everywhere. Windows, Linux, macOS (x86_64 and aarch64), one
codebase, one
cargo build. - Online play that is actually smooth. Rollback netplay, designed in from the first line.
Everything else (interactive stages, tools, modes) is layered on after those two hold. Compatibility comes first: “quirks are features”, and Ikemen GO’s source is the reference for semantics.
The project
| Repository | What |
|---|---|
| rugen-engine | The game: a Cargo workspace of the crates below, binary rugen. |
| rugen-server | The online hub rugen-server, plus deploy/. Uses rugen-proto, rugen-fair, rugen-formats (and rugen-sim for re-simulation) from the engine as git dependencies. |
| rugen-docs | This site. |
Crates
rugen-engine/
crates/
formats/ .sff .air .snd .act .fnt .def parsers. Zero engine deps. Fuzzable.
cns/ lexer, Pratt expression parser, bytecode compiler, VM
sim/ deterministic game simulation. No I/O, no platform libm, no render.
net/ ggrs integration, direct P2P, TURN and relay clients, path choice, lobby API client
proto/ wire types shared by rugen-server and the game
fair/ fingerprints, packages, fairness analysis (no GPU / audio)
content/ chars/ and stages/ content library: imports into .rgc / .rgs content files
render/ wgpu renderer, camera, palette-on-GPU
audio/ kira playback with MUGEN channel semantics
ui/ data-driven menu engine: TOML screens, binds, focus, tweens
app/ winit, gilrs, config, UI glue; the `rugen` binary
| Crate | Package | Role |
|---|---|---|
formats | rugen-formats | Pure, synchronous parsers for every MUGEN file format. Community files are often malformed, so parsers never panic: they return an error or degrade gracefully. |
cns | rugen-cns | MUGEN’s state and expression language: the int / float / bottom value model with MUGEN’s promotion rules, lexer and parser to flat stack bytecode, VM. |
sim | rugen-sim | The fighting game: characters, states, controllers, triggers, hit detection, helpers, projectiles, stages, camera, rounds. Plain data, Clone, no I/O. |
net | rugen-net | Rollback via ggrs (only 11 button bits per player travel), the direct peer-to-peer path (STUN, hole punching, HMAC-authenticated datagrams), the TURN client, the relay client over UDP or WebSocket, the path selector, input delay policy and time sync, and the lobby API client. |
proto | rugen-proto | JSON types for the lobby API and WebSocket, and the binary framing of relayed match traffic. The server never puts another player’s IP in a payload; direct-path candidates travel as opaque relay data between the two players only, and only when both allow direct connections. |
fair | rugen-fair | Gameplay file sets, fingerprints, optimised packages and the static CNS analysis behind FAIR / UNBALANCED / BLOCKED. Shared with the server. |
content | rugen-content | The content library: finds chars/, stages/, motif/, data/; converts zip / rar / folders into .rgc / .rgs content files (and back, with rugen export), with hash-keyed manifests and verification verdicts. |
render | rugen-render | wgpu: Vulkan, DX12, Metal from one API. Indexed sprites stay 8-bit on the GPU and resolve through a palette texture. |
audio | rugen-audio | kira (cpal). Decodes .snd WAVs once; MUGEN channel rules. |
ui | rugen-ui | Menus as TOML trees laid out in a virtual 1280x720 space, with data binds, keyboard / pad / mouse focus and tweens. |
app | rugen | The binary: window (winit), gamepads (gilrs), rugen.toml, screens, theme generators, CLI. |
Determinism
The netplay foundation, enforced in sim:
- Numbers are
i32andf32, because CNS semantics (int / float promotion,7/2 = 3,7.0/2 = 3.5, truncating casts) are defined on them. Fixed-point would break compatibility. f32add / sub / mul / div / sqrt are bit-exact across x86_64 and aarch64 as long as nothing fuses or extends precision: nomul_add, no fast-math.- Transcendentals (
sin,pow,exp, …) come from the pure-Rustlibmcrate, never from the platform’s libm. - Simulation state is plain data, arena plus indices: no
Rc, noBox<dyn>, no pointers. It must beCloneand cheap. - The PRNG is seeded per match and lives inside the state. CNS
Randomreads from it. Offline matches draw a fresh seed (replays record it); online matches derive it from the server’s match id (headless::online_seed), so both players, spectators and the server’s re-simulation agree without exchanging it; LAN hosts send theirs in the handshake. Older replays and LAN peers fall back to seed 1. - Ordered containers only (
Vec,BTreeMap,IndexMap); never iterate aHashMapin the simulation. - The CNS VM state is part of the snapshot.
- The simulation runs at a fixed 60 Hz. Rendering reads the state and never mutates it. Target: a full frame step under 2 ms, so a 7-frame rollback fits the budget.
Cross-platform stack
Pure Rust, no C dependencies:
| Need | Crate |
|---|---|
| GPU | wgpu |
| Window | winit |
| Gamepads | gilrs |
| Audio | kira (cpal) |
| Math | libm |
| Rollback | ggrs |
| Lexing | logos |
| Config | serde + toml |
| Server | axum, rusqlite (SQLite, bundled), argon2 |
Something wrong on this page? Edit it on GitHub.