N4: Lag-compensated hit validation
A network client draws other players in the past and its commands take time to arrive, so by the time the server fires a shot the target has moved on: 8 ticks at a 50 ms round trip, 12 at 200 ms. Each PlayerCommand now carries view_lag: how far back its player was seeing everyone else, in quarter ticks. The simulation keeps where every player's body has been for the last 15 ticks (HitHistory), and a hitscan shot is traced against other players where they were at the moment the shooter saw, and against the world as it is now. Projectiles aren't rewound. The client claims only when it was looking and where it aimed; the server works out the hit from its own record. The moment is never more than Tuning.LAG_COMPENSATION_MAX_TICKS back, never in the future, and never earlier than a moment the same player has already claimed. Commands are 15 bytes, so the command log's version is 2. The lag is in the log, and replays judge every shot as the match did. Measured in test/net/test_lag_compensation_link.gd over a simulated link: a client firing at a walking target as drawn on its own screen hits 41 of 41 shots at 50, 100 and 200 ms round trips, 0 of 41 with the lag ignored, and 0 of 41 at 500 ms, past the cap. Closes #35 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
## the simulation takes nothing else in. See MatchReplay.
|
||||
##
|
||||
## Each record is the simulation tick the command arrived on, the handle it came from
|
||||
## and the command's own 14 bytes. Commands are logged whether or not the simulation
|
||||
## and the command's own 15 bytes. Commands are logged whether or not the simulation
|
||||
## accepted them, so a replay turns the same ones down.
|
||||
##
|
||||
## On disk: "TWCL", a u32 header length, the header as JSON, a u32 length of the raw
|
||||
@@ -13,7 +13,7 @@ class_name CommandLog
|
||||
extends RefCounted
|
||||
|
||||
const MAGIC: String = "TWCL"
|
||||
const VERSION: int = 1
|
||||
const VERSION: int = 2
|
||||
## at-tick u32, handle s32, then the command.
|
||||
const RECORD_SIZE: int = 8 + PlayerCommand.ENCODED_SIZE
|
||||
## Refuse files that claim more than this many raw bytes: about four full matches.
|
||||
|
||||
Reference in New Issue
Block a user