Expand description
Deterministic Netcode Foundation
Frame-based deterministic simulation wrapper for lockstep/rollback netcode.
§Core Principle
Same Inputs + Same Initial State → Bit-Exact Same Output (on all clients)Because ALICE-Physics uses 128-bit fixed-point arithmetic with fixed iteration counts, the simulation is fully deterministic. This means:
- No state synchronization needed — only sync player inputs
- Bandwidth: ~20 bytes/player/frame instead of ~160 bytes/body/frame
- Rollback: Save/restore snapshots for client-side prediction
- Desync detection: Compare state checksums across clients
§Usage
use alice_physics::netcode::{DeterministicSimulation, FrameInput, NetcodeConfig};
use alice_physics::Vec3Fix;
// Both clients create identical simulation
let mut sim = DeterministicSimulation::new(NetcodeConfig::default());
// Each frame: collect inputs from all players, advance simulation
let inputs = vec![
FrameInput::new(0).with_movement(Vec3Fix::from_int(1, 0, 0)),
FrameInput::new(1).with_movement(Vec3Fix::from_int(0, 0, -1)),
];
let checksum = sim.advance_frame(&inputs);
// checksum is identical on all clients if inputs match§Bandwidth Model
| Approach | Per-Frame Bandwidth (10 bodies) |
|---|---|
| State sync (traditional) | ~1,600 bytes (160B × 10) |
| Input sync (ALICE) | ~40 bytes (20B × 2 players) |
| Savings | 97.5% |
Structs§
- Default
Input Applicator - Default input applicator: movement → velocity, action bit 0 → jump.
- Deterministic
Simulation - Frame-based deterministic simulation wrapper.
- Frame
Input - Player input for a single simulation frame.
- Netcode
Config - Configuration for deterministic netcode simulation
- Simulation
Checksum - XOR rolling checksum of the entire physics state.
- Simulation
Snapshot - Complete physics state snapshot for rollback.
Traits§
- Input
Applicator - Trait for mapping player inputs to physics forces/impulses.