N3 Client prediction, reconciliation and interpolation #34

Closed
opened 2026-11-09 05:28:14 +00:00 by claude · 1 comment
Owner

Depends on: N2, W1

Predict the local player and reconcile with the server. Interpolate remote entities.

Acceptance

  • Tested with 100 ms latency, 20 ms jitter and 2% loss: local movement has no visible correction in normal play, measured as correction magnitude.
  • Remote players move smoothly through the same conditions.
**Depends on:** N2, W1 Predict the local player and reconcile with the server. Interpolate remote entities. **Acceptance** - Tested with 100 ms latency, 20 ms jitter and 2% loss: local movement has no visible correction in normal play, measured as correction magnitude. - Remote players move smoothly through the same conditions.
claude added this to the v0.5 Multiplayer milestone 2026-11-09 05:28:14 +00:00
claude added the priority/hightype/feature labels 2026-11-09 05:28:14 +00:00
claude added this to the Tidewall v1.0 project 2026-11-09 15:00:07 +00:00
eric closed this issue 2026-11-12 16:30:05 +00:00
Author
Owner

Done in 4111a28.

What changed

  • src/net/client_game.gd: a client's side of a match. Takes MATCH notices and snapshots, generates the island from the seed, plans the same barge route, and answers with commands. It works on packets, so it runs over a NetClient or a simulated link.
  • src/net/client_clock.gd: decides which tick the next command is for, from the server's echo of the newest command tick it has received. Holds three commands waiting at the server.
  • src/net/client_prediction.gd: runs each command on a copy of the client's own player with the server's own movement code (Movement.step, Water.update, Drop.ride). Each snapshot is compared with what was predicted for that tick; a difference is replayed from the server's state, and the drawn position eases to it.
  • src/net/snapshot_interpolator.gd: draws everyone else 4 ticks (two snapshots) in the past, on a clock steered gently by arrivals. Carries on for up to 3 ticks through a lost snapshot and blends away a wrong guess.
  • Snapshots carry the client's own block (37 bytes): exact position and velocity, the water around the player, stamina and flags. Protocol version is now 2.
  • Snapshot rate. N2 sent every third tick, which is 10 a second, not the 20 its documents said. It is now every second tick, 15 a second, and the documents say so. A 24-player match start now costs 4.1 KB/s per client on average (was 2.4 at 10 a second, without the own block), against the 40 KB/s limit.

How it was tested
make check passes: 413 tests, self-check and smoke.

test/net/test_prediction_link.gd plays two people through the drop and 75 s of walking, sprinting, strafing, jumping and crouching on a real island, with a real ServerLoop and NetGame, each client behind a simulated link. I read "100 ms latency" as 100 ms each way, the stricter reading.

Link Own movement The other player as drawn
100 ms each way, ±20 ms, 2% loss About 1,415 snapshots compared per client, 0 corrected. Largest correction 0.000 m. Mean 0.4 mm from what a perfect link would draw, max 5 cm and 13 cm. Mean 9 mm from the server's position at that moment. Drawing clock 0.489 to 0.511 ticks a frame (0.5 is even). 0 and 1 stalled frames of 4,500.
150 ms each way, ±40 ms, 10% loss 3 and 7 corrections, largest 13 cm and 22 cm, all blended, none shown at once. Mean 3 to 4 mm from a perfect link, max 35 cm.

Each player moved about 360 m on the server in the measured window, so the commands really arrived and were applied.

Also: unit tests for the clock (6), prediction on a hand-stepped simulation including the barge ride, the leap, swimming and a lost command (8), the interpolator (7), the own block (3), and ClientGame against a real server over loopback UDP (3).

What this does not show

  • These are headless measurements of the netcode's arithmetic over a simulated link. Nobody has felt it. That is for R6.
  • There is still no client program: ClientGame is driven by tests only. Follow-up issue opened for joining it to MatchView and real input.
  • Built pieces and broken props aren't replicated yet (N5), so a client standing on or against one will be corrected until they are.
  • The own block doesn't carry inventory, ammunition or materials. The HUD needs them (N5).
  • A stalled frame is still possible when a snapshot is lost just as someone starts moving: 1 frame in 9,000 at 2% loss.
Done in 4111a28. **What changed** - `src/net/client_game.gd`: a client's side of a match. Takes MATCH notices and snapshots, generates the island from the seed, plans the same barge route, and answers with commands. It works on packets, so it runs over a `NetClient` or a simulated link. - `src/net/client_clock.gd`: decides which tick the next command is for, from the server's echo of the newest command tick it has received. Holds three commands waiting at the server. - `src/net/client_prediction.gd`: runs each command on a copy of the client's own player with the server's own movement code (`Movement.step`, `Water.update`, `Drop.ride`). Each snapshot is compared with what was predicted for that tick; a difference is replayed from the server's state, and the drawn position eases to it. - `src/net/snapshot_interpolator.gd`: draws everyone else 4 ticks (two snapshots) in the past, on a clock steered gently by arrivals. Carries on for up to 3 ticks through a lost snapshot and blends away a wrong guess. - Snapshots carry the client's **own block** (37 bytes): exact position and velocity, the water around the player, stamina and flags. Protocol version is now 2. - **Snapshot rate.** N2 sent every third tick, which is 10 a second, not the 20 its documents said. It is now every second tick, 15 a second, and the documents say so. A 24-player match start now costs 4.1 KB/s per client on average (was 2.4 at 10 a second, without the own block), against the 40 KB/s limit. **How it was tested** `make check` passes: 413 tests, self-check and smoke. `test/net/test_prediction_link.gd` plays two people through the drop and 75 s of walking, sprinting, strafing, jumping and crouching on a real island, with a real `ServerLoop` and `NetGame`, each client behind a simulated link. I read "100 ms latency" as 100 ms each way, the stricter reading. | Link | Own movement | The other player as drawn | |---|---|---| | 100 ms each way, ±20 ms, 2% loss | About 1,415 snapshots compared per client, **0 corrected**. Largest correction 0.000 m. | Mean 0.4 mm from what a perfect link would draw, max 5 cm and 13 cm. Mean 9 mm from the server's position at that moment. Drawing clock 0.489 to 0.511 ticks a frame (0.5 is even). 0 and 1 stalled frames of 4,500. | | 150 ms each way, ±40 ms, 10% loss | 3 and 7 corrections, largest 13 cm and 22 cm, all blended, none shown at once. | Mean 3 to 4 mm from a perfect link, max 35 cm. | Each player moved about 360 m on the server in the measured window, so the commands really arrived and were applied. Also: unit tests for the clock (6), prediction on a hand-stepped simulation including the barge ride, the leap, swimming and a lost command (8), the interpolator (7), the own block (3), and `ClientGame` against a real server over loopback UDP (3). **What this does not show** - These are headless measurements of the netcode's arithmetic over a simulated link. Nobody has felt it. That is for R6. - There is still no client program: `ClientGame` is driven by tests only. Follow-up issue opened for joining it to `MatchView` and real input. - Built pieces and broken props aren't replicated yet (N5), so a client standing on or against one will be corrected until they are. - The own block doesn't carry inventory, ammunition or materials. The HUD needs them (N5). - A stalled frame is still possible when a snapshot is lost just as someone starts moving: 1 frame in 9,000 at 2% loss.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: claude/tidewall#34