Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FSCKING LAG

Secret Lab
September 01, 2015

FSCKING LAG

A lightning talk on multiplayer networking that we gave at /dev/world/2015.

Secret Lab

September 01, 2015
Tweet

More Decks by Secret Lab

Other Decks in Programming

Transcript

  1. View Slide

  2. FSCKING LAG

    View Slide

  3. Video Games!

    View Slide

  4. Multi-player video
    games!

    View Slide

  5. Server

    View Slide

  6. Server
    Client Client Client

    View Slide

  7. Server
    Client Client Client

    View Slide

  8. Server
    Client

    View Slide

  9. Server
    Client
    “I just killed player 1”

    View Slide

  10. Server
    Client
    “I just killed player 1”
    “ok”

    View Slide

  11. Server
    Client
    “I just killed player 1”
    “ok”
    BAD

    View Slide

  12. Server
    Client
    “I pressed
    these buttons”
    “This is where
    things are”

    View Slide

  13. Server
    Client
    “I pressed
    these buttons”
    “This is where
    things are”
    BETTER

    View Slide

  14. PROBLEM

    View Slide

  15. 1 2
    Lag = 1 second Lag = 0.1 seconds

    View Slide

  16. 1
    2
    Shoots!
    Runs!
    FROM PLAYER 1’S PERSPECTIVE:

    View Slide

  17. Server
    Player 1 Player 2

    View Slide

  18. Server
    Player 1 Player 2
    “I’m shooting!”
    (1 second ago)

    View Slide

  19. Server
    Player 1 Player 2
    “I’m shooting!”
    (1 second ago)
    “I’m running around
    the corner!”
    (0.1 second ago)

    View Slide

  20. Server
    Player 1 has shot, and
    Player 2 is around the corner.
    Player 1’s shot missed.

    View Slide

  21. Server
    Player 1 Player 2
    “Player 2 is now
    around the corner.
    Player 1 shot, but
    missed.”

    View Slide

  22. Counter-Strike

    View Slide

  23. Server
    Player 1 shot, and at the
    time, they were aiming at
    Player 2. Their should would
    have hit.

    View Slide

  24. Server
    Player 1 Player 2
    “Player 1 shot
    Player 2.”

    View Slide

  25. Server
    Player 1 Player 2
    “Player 1 shot
    Player 2.”
    “Oh, and Player
    2 still ran
    around the
    corner. lol.”

    View Slide

  26. Server
    Player 1 Player 2
    “Player 1 shot
    Player 2.”
    “Oh, and Player
    2 still ran
    around the
    corner. lol.”
    wtf

    View Slide

  27. Age of Empires

    View Slide

  28. 1500 Archers on a 28.8:
    Network Programming
    in Age of Empires and
    Beyond
    Mark Terrano, Paul Bettner

    View Slide

  29. PROBLEM:
    1500 archers
    Each one has a position
    Each one is moving

    View Slide

  30. Each position is
    about 4 bytes each

    View Slide

  31. 4 bytes ✕ 1500 =
    6000 bytes

    View Slide

  32. 6000 bytes ✕ 30
    frames/sec
    = 175 kB/s

    View Slide

  33. SOLUTION:

    View Slide

  34. DON’T SYNC STATE

    View Slide

  35. SYNC PLAYER INTENT

    View Slide

  36. Client
    Client
    Client

    View Slide

  37. Client
    Client
    Client
    “I told my
    archers to move.”

    View Slide

  38. Client
    Client
    Client
    “I told my
    archers to move.”
    “I told a villager to
    gather wood.”

    View Slide

  39. Client
    Client
    Client
    Wait for everyone to finish this frame….

    View Slide

  40. Client
    Client
    Client
    Archers are moving, and the
    villager is gathering wood.

    View Slide

  41. NOT PERFECT

    View Slide

  42. RUNS AT THE
    SLOWEST PLAYER

    View Slide

  43. DESYNCS

    View Slide

  44. @thesecretlab
    rocketboxgame.tumblr.com

    View Slide