RUGENDOCS
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:

  1. Runs everywhere. Windows, Linux, macOS (x86_64 and aarch64), one codebase, one cargo build.
  2. 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

RepositoryWhat
rugen-engineThe game: a Cargo workspace of the crates below, binary rugen.
rugen-serverThe 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-docsThis 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
CratePackageRole
formatsrugen-formatsPure, synchronous parsers for every MUGEN file format. Community files are often malformed, so parsers never panic: they return an error or degrade gracefully.
cnsrugen-cnsMUGEN’s state and expression language: the int / float / bottom value model with MUGEN’s promotion rules, lexer and parser to flat stack bytecode, VM.
simrugen-simThe fighting game: characters, states, controllers, triggers, hit detection, helpers, projectiles, stages, camera, rounds. Plain data, Clone, no I/O.
netrugen-netRollback 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.
protorugen-protoJSON 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.
fairrugen-fairGameplay file sets, fingerprints, optimised packages and the static CNS analysis behind FAIR / UNBALANCED / BLOCKED. Shared with the server.
contentrugen-contentThe 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.
renderrugen-renderwgpu: Vulkan, DX12, Metal from one API. Indexed sprites stay 8-bit on the GPU and resolve through a palette texture.
audiorugen-audiokira (cpal). Decodes .snd WAVs once; MUGEN channel rules.
uirugen-uiMenus as TOML trees laid out in a virtual 1280x720 space, with data binds, keyboard / pad / mouse focus and tweens.
apprugenThe binary: window (winit), gamepads (gilrs), rugen.toml, screens, theme generators, CLI.

Determinism

The netplay foundation, enforced in sim:

  • Numbers are i32 and f32, 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.
  • f32 add / sub / mul / div / sqrt are bit-exact across x86_64 and aarch64 as long as nothing fuses or extends precision: no mul_add, no fast-math.
  • Transcendentals (sin, pow, exp, …) come from the pure-Rust libm crate, never from the platform’s libm.
  • Simulation state is plain data, arena plus indices: no Rc, no Box<dyn>, no pointers. It must be Clone and cheap.
  • The PRNG is seeded per match and lives inside the state. CNS Random reads 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 a HashMap in 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:

NeedCrate
GPUwgpu
Windowwinit
Gamepadsgilrs
Audiokira (cpal)
Mathlibm
Rollbackggrs
Lexinglogos
Configserde + toml
Serveraxum, rusqlite (SQLite, bundled), argon2

Something wrong on this page? Edit it on GitHub.

SEARCH !!

    ↑↓ to move, Enter to open