five-on-it / packages/net-client/src/predicted-pieces
packages/net-client/src/predicted-pieces
The level's light pieces drawn at the local time near what the player controls.
A light piece (a hydrant, a lamp, a bench: @foi/sim's breakables.ts) is knocked loose by the same rule in the local world as on the server, the controlled car being simulated there in full: the prediction knocks it loose on the tick the server will. But a loose piece is an entity of the snapshots (prop), drawn like every remote a hundred milliseconds behind the newest snapshot, itself a trip across the network old: the piece the player's car ran into stood on screen, untouched, while the car was drawn on through where it stood, and flew off a quarter of a second later (measured by tests/netcode/impact.ts at a hydrant on test-breakables: the drawn piece first moved 200 to 350 ms after the prediction knocked it, the car drawn 4 to 8 m on by then). A piece is drawn where the local world has it instead, the way the cars near the player are (PredictedRemotes), while it lies loose there and is near: within NEAR_MARGIN plus what it and the controlled entity cover in PIECE_HORIZON at their speeds, and from then on until it has come to rest (REST_SPEED) out of that reach for PREDICTED_BLEND_SECONDS. A piece the prediction has just knocked loose (planted on the last update) starts there at once: its other timeline still has it standing where it stood, which is where it is. One already lying loose that comes near is blended in from the snapshots' drawing, and one that leaves is blended back out, at the pace bound the cars' blend goes by (blendSeconds).
Each snapshot that rewinds the prediction sets the loose pieces to the server's word and the replay brings them back up to the present (one the prediction stands on is left alone: Predictor.standing); the jump that makes in a piece drawn here is kept as a decaying offset (SmoothingOffset), as a near car's is. A piece the server never knocked loose is planted again by the snapshots, and leaves this timeline with it.