# Networking ## How it was measured A dedicated server and two clients, each its own process with no window, both clients sending with 150 ms of lag and 5% packet loss. Client A drives a fixed 30 s course: full throttle to about 115 km/h, a slalom, a long turn, braking into a turn, a handbrake turn, braking to a stop and backing up. Client B only watches A. The lab is in the repository (`NetVehicleLab`, `Tools/net_lab.py`). Measured on A: corrections from the server, jumps of the drawn car (a frame where it moves more than its velocity explains, over 5 cm), pops (a change of velocity over 10 cm in one 60 FPS frame), and how far it is from the path the server drove. On B: the same for A as B draws it. ## Results (one run each) | Course | Corrections | Pops the driver sees | Driver off the server's path (95%) | What the other player sees | |---|---|---|---|---| | Car alone | 0 | 0 | 0.1 cm | 6 jumps a minute, 4 pops | | Crash into a parked car and pushing it 3 s | 0 | 1 (13 cm) | 0.1 cm | the parked car pushed 64 m, in the same place on all three machines | | Two players head-on | 1 | 2 (15 cm) | 0.1 cm | 58 jumps a minute, 7 pops (57 cm worst) | | Truck with semi-trailer | 0 | 0 | 0.1 cm (trailer 0.1 cm) | 0 jumps, 0 pops | | Getting in, driving, getting out | 0 | 0 | 0.1 cm | | The driver drives about 280 ms ahead of the server, so the car answers at once at 150 ms. In the head-on course the other player's car, predicted near the watcher, is jumpier: when that player changes input, 280 ms of prediction with the old input is wrong and the car slides over to where it is. That is the cost of predicting another player, and every game that does it has it; a longer **Correction Smooth Time** hides more of it. The same lab with the template's Chaos Vehicles sports car, one run each: | Chaos setup | Driver | Other player | |---|---|---| | Default (template) | jumps of up to 4.2 m at 125 km/h, 12.7 cm off the path | 16 jumps a minute, 10 pops (4.2 m) | | Physics Prediction, Predictive Interpolation | 2 jumps a minute, 15.9 cm off the path | 4 jumps a minute, 0 pops | | Physics Prediction, Resimulation | 0 jumps, 270 ms ahead | 196 jumps a minute, up to 1 m off the path | ## Cost On the game thread, 50 cars driving on their own, no window: 0.066 ms per car in each 60 Hz vehicle frame. The template's Chaos sports car: 0.127 ms per car per frame. ## Known limits - **Pushing a parked car for a long time.** A player who keeps pushing a car parked with its handbrake on (its wheels locked, sliding) is corrected often: measured in the example town, a car pushed at 5 m/s for most of 30 s, the driver was corrected about 90 times a minute, 8 to 39 cm each, along the way it drives. Locked wheels sliding make the push very sensitive to where the two touch, and the client predicts the parked car from the server's last frame. A short hit and push (a parked car hit at 70 km/h and pushed 64 m) has no corrections. - **What a watcher sees.** Another player's vehicle, drawn in the past between server frames, shows small steps of about 4 ms of its own path now and then (about 20 a minute): the watcher's clock keeping in step with the server's. They go along the path, 0 to 0.1 cm aside. - **A character, not a vehicle.** After getting out, the player's own character is predicted by the engine's Character Movement about 300 ms ahead of the server, as any character is; that is not Drivecraft. ## Settings | Setting | Default | What it does | |---|---|---| | Correction Threshold | 1 cm | How far a vehicle simulated here may be from the server's state for the same frame before it runs again from it | | Correction Smooth Time | 0.1 s | How long a correction takes to fade out of the drawn car | | Interpolation Delay | 0.1 s | How far in the past vehicles far from the player are drawn | | Predict Near Local Player | on | Vehicles near the player are simulated ahead instead of drawn in the past. Never a bike: run ahead on old steering its lean is wrong at once, so it is drawn in the past | | Prediction Distance | 30 m | How near | | Max Substep | 1/120 s | Longest step of the simulation; each 1/60 s frame is split into steps no longer than this | To show it in game, the world subsystem `DRCVehicleSubsystem` (Get World Subsystem) gives **Get Frame**, **Get Rollback Count** and **Get Average Frame Cost Ms** (with **Reset Frame Cost**); each vehicle's movement gives **Get Correction Count**, **Get Last Correction Distance** and **Is Locally Predicted**.