Netcode
Rollback with ggrs, adaptive input delay, smooth time sync, direct / TURN / relay paths, rollback-safe audio and result verification. What the client does to make online play feel local.
rugen was built for online play from the first commit: the simulation is deterministic and runs at a fixed 60 Hz, so only inputs travel over the network.
Rollback
rugen uses ggrs for rollback with a
12-frame rollback window ([net] prediction_window): the game may run up
to 12 frames ahead of the opponent’s last received input, predicting it
(repeat the last input). When the real input arrives and differs, the game
rewinds, applies it and re-simulates to the present. A sync-test session
(rugen play ... --synctest, also an automated 600-frame test) proves the
simulation stays identical under rollback.
Input delay
With [net] input_delay = "auto" (the default) the game adds input delay
only for the latency the rollback window cannot hide. When the match starts
it takes the 95th percentile of the round trip on the chosen path (so jitter
counts) and computes
clamp(ceil((rtt_p95 / 2 + 16.7 ms) / 16.7 ms) - (window - headroom), min_delay, 8)
with a 12-frame window, 3 frames of headroom kept free for jitter, and
min_delay = 1:
| Round trip (p95) | Input delay |
|---|---|
| up to ~300 ms | 1 frame |
| 301-333 ms | 2 frames |
| 334-366 ms | 3 frames |
| 367-400 ms | 4 frames |
| beyond | +1 frame per 33 ms, at most 8 |
[net] input_delay = n forces a value; OPTIONS > ONLINE > NET INPUT DELAY
cycles AUTO / 0-8. The HUD shows the delay in use (D1, see
During the match).
Time sync
When one side runs ahead of the other, it slows down smoothly instead of freezing: the tick stretches by 1.5 % per frame of (smoothed) advantage, at most 8 % (58.5 Hz at two frames ahead). ggrs’ recommendation to skip whole frames is not used, and the renderer keeps the display rate.
Correction smoothing
When a rollback moves a fighter or projectile that is already on screen, the picture does not jump: the renderer eases it from where it was shown to the corrected position over about 4 frames. Corrections over 48 px and getting hit snap at once (easing those would show a fighter somewhere it never was). This is display only; the simulation is never touched.
Low-latency rendering
[video] low_latency = true (the default) draws each frame right after its
tick with at most one frame queued (mailbox, or FIFO). Off: the driver’s
default vsync with frames drawn continuously (up to two queued).
Rollback-safe audio and effects
Sounds and announcer calls are keyed by (frame, event). Re-simulated frames never replay or cut a sound, events revealed by a rollback play once, and round calls (FIGHT, KO, …) are deduplicated across a window.
Paths: direct, TURN, relay
An online match can travel three ways, chosen by round trip and jitter, with hysteresis so it does not flap between similar paths (on a tie the more direct one wins):
- Direct, peer to peer over UDP (the default). A small ICE: local
addresses, the public address seen by Cloudflare STUN
(
stun.cloudflare.com:3478) and addresses learned from authenticated checks. Both sides check every address pair at once every 50 ms (which opens both NATs); the first pair that works is used, a faster one takes over. Every datagram carries a counter (64-entry replay window) and a truncated HMAC-SHA256 tag keyed per match. Skipped when either player turns DIRECT CONNECTION off, and when both are behind symmetric NATs. - TURN, when the server offers it (Cloudflare Realtime TURN on the official server): both players allocate a relayed address and exchange those (a TURN server’s address, never a player’s). All messages of a tick are packed into one datagram, about 3.4 KB/s per player and direction.
- The server relay: player → server → player, over the UDP fast path
on the server’s port 7001, or the WebSocket
/relaythrough HTTPS when the UDP probe fails within 1.5 s ([net] websocket_only = trueskips the probe).
A path that goes quiet for 0.8 s is left at once; a better one takes over after holding for 2 s. The relay session stays open all match, for the direct-path signalling and as the last fallback. Relay datagrams are authenticated per session and slot with a random 128-bit token handed to each player over HTTPS. Who sees your IP address, and which networks connect directly, is on How a match connects.
Connection quality
1-4 bars and a PATH PING D<delay> line (for example DIRECT 34 MS D1) sit
in the corner of the match; CONNECTION UNSTABLE appears on interruptions,
large frame advantage or deep rollbacks. Rooms and the queue show the
estimated ping before you play, and the matchup screen adds HIGH PING
above 200 ms.
Determinism and desyncs
- Numbers follow CNS semantics on
i32/f32; no fused multiply-add, and transcendental functions come from the pure-Rustlibmcrate, so x86_64 and aarch64 produce the same bits. - The simulation state is plain data, the PRNG lives inside it, and only ordered containers are iterated.
- A per-frame state hash is exchanged: a desync surfaces as an error, never as silent drift.
Result verification
Both clients report winner, last frame, world checksum and the confirmed
input stream. Disagreement marks the match disputed (no rating change).
Ranked input streams are stored as replays, and a server built with the
resim feature can re-simulate disputed matches to settle them (see
Re-simulation).
Diagnostics
Environment variables for the game:
| Variable | Effect |
|---|---|
RUGEN_LATENCY=1 | Every 5 s, logs the local input-to-display latency: key to tick, tick to present, time blocked on vsync, and an estimate of when the frame reaches the screen. |
RUGEN_PRESENT=fifo / mailbox / immediate | Forces that presentation mode, when the GPU offers it. |
Developer examples in the engine repository:
# two rollback peers through a delaying, lossy UDP proxy, on recorded inputs
cargo run --release -p rugen-net --example netsim -- \
--p1 chars/a.def --p2 chars/b.def --data data/ --replays replays/ \
--rtt 180 [--jitter 8] [--loss 1] [--secs 40] [--warmup 5]
# cost of one rollback: save, load, one re-simulated frame, checksum
cargo run --release -p rugen-sim --example rollbench -- <p1.def> <p2.def> <data_dir> [frames] [--render-ms N]
# misprediction rate of input prediction strategies on recorded replays
cargo run --release -p rugen-net --example predict -- <replays dir>
netsim reports per peer the input delay chosen, rollbacks per second and
their depth, hard stalls, displayed frames per second, the longest freeze
and the netcode’s CPU time per tick.
Something wrong on this page? Edit it on GitHub.