Waiting for
players…

$ ./host --players 40

Join the game

QR code to playground.hackenshaw.com/join

playground.hackenshaw.com/join

playground.hackenshaw.com/join

Did your jump
feel late?

Where is the game?

YOUR PHONE SERVER THIS LAPTOP sends buttons left · right · jump remembers who is holding what asks every 130 ms, runs the world

Every arrow
takes time.

Ping

-- ms

this laptop → playground.hackenshaw.com → back

Light is slow

Eindhoven → New York
5,900 km

light in glass fibre: 200,000 km/s

30 ms one way. 60 there and back.

At 60 fps, one frame is 16 ms.

A 100 ms ping is six frames late.

Delay

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 0 lost 0 too 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 0 lost 0 sent 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

SERVER player 1 player 2 player 3 player 4

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 0 hits 0

click to shoot · the dashed ring is where the server checked

Rewind time

shots 0 hits 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

So what did
the playground do?

  • Your phone sends only buttons
  • The server only remembers them
  • This laptop asks every 130 ms and runs the world
  • No prediction. No interpolation.

That’s why your jump
felt late.

playground.hackenshaw.com/join

Questions?

Connection
closed

$ exit