Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Making Sense of Multiplayer

421 views

Published on

In this presentation, we'll explore the unique concerns of a system that supports dozens of concurrent players in real time. We'll use a mobile game written in JavaScript to test different implementation options and you'll leave ready to go home and design your own multiplayer experience.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Making Sense of Multiplayer

  1. 1. @hunterloftis Making Sense of Multiplayer Hunter Loftis Engineering Manager, Heroku @ Connect.Tech 2018
  2. 2. 1962
  3. 3. 1987
  4. 4. 1996
  5. 5. 1998
  6. 6. 2004
  7. 7. Pre-2011 "Netcode" experts C++, TCP, UDP, ICMP, routing @hunterloftis
  8. 8. 2011 Renaissance WebSocket protocol (+Node.js) @hunterloftis
  9. 9. Shared Spaces
  10. 10. Shared Spaces
  11. 11. Shared Spaces
  12. 12. Shared Spaces
  13. 13. Shared Spaces
  14. 14. @hunterloftis But...
  15. 15. @hunterloftis Most people fail the first time.
  16. 16. @hunterloftis Most people fail the first time. I did!
  17. 17. @hunterloftis Most people fail the first time. I did! ... and the second, third, and fourth times too.
  18. 18. @hunterloftis Common issues
  19. 19. @hunterloftis Common issues • Choppy updates
  20. 20. @hunterloftis Common issues • Choppy updates • Laggy controls
  21. 21. @hunterloftis Common issues • Choppy updates • Laggy controls • Changes being applied and then un-applied
  22. 22. @hunterloftis Common issues • Choppy updates • Laggy controls • Changes being applied and then un-applied • Inconsistent client behavior
  23. 23. @hunterloftis Common issues • Choppy updates • Laggy controls • Changes being applied and then un-applied • Inconsistent client behavior • Rule breaking
  24. 24. @hunterloftis We're ignoring decades of experience!
  25. 25. @hunterloftis Netcode 101
  26. 26. @hunterloftis What is real-time multiplayer?
  27. 27. @hunterloftis What is real-time multiplayer? A Lie.
  28. 28. "It turns out it’s all an illusion. A massive sleight-of-hand." - Glenn Fiedler, Networking for Game Programmers @hunterloftis
  29. 29. @hunterloftis 100% Scientific bandwidth / $ compute / $ speed of light / $ Time
  30. 30. @hunterloftis bandwidth / $ compute / $ speed of light / $ Time
  31. 31. @hunterloftis Sharing an environment over thousands of miles is impossible.
  32. 32. @hunterloftis Instead, create an illusion:
  33. 33. @hunterloftis Instead, create an illusion: 1. Input gives feedback immediately.
  34. 34. @hunterloftis Instead, create an illusion: 1. Input gives feedback immediately. 2. Players believe they are sharing an environment.
  35. 35. @hunterloftis Instead, create an illusion: 1. Input gives feedback immediately. 2. Players believe they are sharing an environment. 3. Everyone eventually ends up in the same state.
  36. 36. @hunterloftis How? Entities + Stacked State
  37. 37. @hunterloftis How? Entities + Stacked State View
  38. 38. @hunterloftis How? Entities + Stacked State View Predicted
  39. 39. @hunterloftis How? Entities + Stacked State View Predicted Interpolated
  40. 40. @hunterloftis How? Entities + Stacked State View Predicted Interpolated Authoritative
  41. 41. @hunterloftis How? Entities + Stacked State View Predicted Interpolated Authoritative
  42. 42. @hunterloftis Entities
  43. 43. @hunterloftis Entities
  44. 44. @hunterloftis Entities • Have a unique ID.
  45. 45. @hunterloftis Entities • Have a unique ID. • Belong to an owner.
  46. 46. @hunterloftis Entities • Have a unique ID. • Belong to an owner. • Belong to a timeline.
  47. 47. Entities provide a way to partition state { id: 4, x: 50, y: 22, angle: 0, health: 0.7, firing: false }
  48. 48. @hunterloftis Entities from different timelines can coexist. time = 1.5s time = 1.75s
  49. 49. @hunterloftis Divergence sacrifices accuracy for smoothness.
  50. 50. @hunterloftis Authoritative State
  51. 51. sendToServer({ hit: true })
  52. 52. @hunterloftis Input In - State Out Server { leftKey: true } [{ id: 1, x: -10, y: 0 } { id: 2, x: 10, y: 0 }] { rightKey: true }
  53. 53. @hunterloftis Authoritative Server
  54. 54. @hunterloftis Authoritative Server • Prevents cheating
  55. 55. @hunterloftis Authoritative Server • Prevents cheating • Ensures eventual consistency
  56. 56. @hunterloftis Authoritative Server • Prevents cheating • Ensures eventual consistency • Allows secrets
  57. 57. @hunterloftis "Update Rate" How frequently the server sends updates to clients. (eg, 10 Hz)
  58. 58. @hunterloftis Interpolated State
  59. 59. @hunterloftis Interpolation
  60. 60. @hunterloftis Interpolation • Stores the last two authoritative states in history.
  61. 61. @hunterloftis Interpolation • Stores the last two authoritative states in history. • Animates from history[0] to history[1].
  62. 62. @hunterloftis Interpolation • Stores the last two authoritative states in history. • Animates from history[0] to history[1]. • Extrapolates if new data doesn't arrive on time.
  63. 63. history[0] history[1] extrapolated
  64. 64. @hunterloftis Predicted State
  65. 65. @hunterloftis Client-Side Prediction
  66. 66. @hunterloftis Client-Side Prediction • Records a buffer of local input.
  67. 67. @hunterloftis Client-Side Prediction • Records a buffer of local input. • Applies the buffer over the most recent authoritative state.
  68. 68. @hunterloftis Client-Side Prediction • Records a buffer of local input. • Applies the buffer over the most recent authoritative state. • Only simulates a subset of the rules.
  69. 69. @hunterloftis Local input stacks on top of authoritative history to push local entities further in time. history[0] history[1] input inputinput
  70. 70. @hunterloftis View State
  71. 71. @hunterloftis View State
  72. 72. @hunterloftis View State • Isn't propagated across the network.
  73. 73. @hunterloftis View State • Isn't propagated across the network. • May be different per-client.
  74. 74. @hunterloftis View State • Isn't propagated across the network. • May be different per-client. • Adds details to authoritative state.
  75. 75. @hunterloftis Putting it all together
  76. 76. @hunterloftis A moment in time Server input 45input 46input 47 state (43)state (42) state (41) input 44 state (40)
  77. 77. @hunterloftis Player B Sees himself start moving up immediately, then sees Player A start moving up. Player A Sees herself start moving up immediately, then sees Player B start moving up. Both players press UP at the same time.
  78. 78. @hunterloftis Player B Sees himself stop moving immediately, then sees Player A stop moving at the same height. Player A Sees herself stop moving immediately, then sees Player B stop moving at the same height. Both players release UP at the same time.
  79. 79. @hunterloftis The illusion has limits Latency Fighters/Sports Twitchy shooters Today's demo Real-time strategy Chess
  80. 80. @hunterloftis Questions so far?
  81. 81. @hunterloftis Questions so far? View
  82. 82. @hunterloftis Questions so far? View Predicted
  83. 83. @hunterloftis Questions so far? View Predicted Interpolated
  84. 84. @hunterloftis Questions so far? View Predicted Interpolated Authoritative
  85. 85. @hunterloftis Questions so far? View Predicted Interpolated Authoritative
  86. 86. @hunterloftis ctdf.herokuapp.com
  87. 87. @hunterloftis Questions? https://github.com/hunterloftis/dogfight http://www.pages.drexel.edu/~ecb44/print.html https://www.pcgamer.com/netcode-explained/ http://www.gabrielgambetta.com/client-server-game-architecture.html https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking http://www.gamasutra.com/view/news/128323/Seven_Years_Of_World_Of_Warcraft.php https://gafferongames.com/post/what_every_programmer_needs_to_know_about_game_networking https://stackoverflow.com/questions/11436311/realtime-multiplayer-game-principles-for-tcp-and-node-js "250 Handdrawn Textures" art by Daniel Cook Plane sprites by Sujit Yadav Particle sprites by Kenney

×