move the mouse on the left · the ring on the right is where you really are
The internet makes no promises
late · lost · out of order
Late and lost
sent 0lost 0too old, ignored 0
Two ways to send
TCP
Every packet, in order.
Lost one? Ask again, and wait.
UDP
Whatever arrives.
Lost one? Too bad.
TCP vs UDP
sent 0lost 0sent again 0
For a position, only the newest one matters.
Who decides?
“I hit you first!”
on your screen
you fired first
on their screen
they fired first
Both are telling the truth.
One judge
client – server
Never trust the client
GET /in/7?l=0&r=1&j=3
GET /in/7?x=900&y=0&score=999999
The playground only listens for buttons.
Now everything is late
hold A or D, or the buttons
Don’t wait. Guess.
client-side prediction
Then fix the guess
server reconciliation
// every tick
const input = { seq: seq++, dir };
send(input); // tell the server
me.x = move(me.x, input); // don't wait: guess
pending.push(input);
onState(state => {
me.x = state.x; // the server is right
pending = pending.filter(i => i.seq > state.ack);
for (const i of pending) me.x = move(me.x, i); // replay
});
Other players?
You can’t guess what someone else will press.
Snapshots
Show them in the past
interpolation
You see yourself in the future. Everyone else in the past.
So who got hit?
Aim at what you see
shots 0hits 0
click to shoot · the dashed ring is where the server checked
Rewind time
shots 0hits 0
lag compensation
That’s why you die behind the wall.
Or: send only the inputs
lockstep
Every computer runs the same game.
1,500 archers. Only the orders cross the network.
Age of Empires · 1997
Rollback
guess what they pressed · rewind when you’re wrong