Game networkprogrammingPotHix (Willian Molinari)Diego Souza (marciano)
Why?
Skeleton Jigsaw: http://plaev.me/skeleton-jigsaw              Shameless self promotion
To have fun, bro!
Agenda■ Synchronous RTS■ Peer to peer■ Client / server■ UDP■ Quake strategy■ TCP■ Web and HTML5
Synchronous RTS
RTSs and Supreme commander
Peer to peer
Everything in sync
Two gameloops!
LatencyMy life for the horde!
Player1   Player2   Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
Player1   Player2   Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
Player1   Player2   Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
Player1   Player2   Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
butterfly effect
So...
Player1   Player2   Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
Player1        Player2   Player3 tick 0mstick 100ms                   UI OK!tick 200mstick 300mstick 400ms
Desync
Age of empires1500 archers with a 28.8 modem [1]
Client / Server
Authoritative server
Client   Server                  pos (0,0)
Client   Server                              pos (0,0)pos (0,0)
Client   Server                              pos (0,0)pos (0,0)movepos (1,0)
Client   Server                              pos (0,0)pos (0,0)movepos (1,0)                              pos (1,0)
Smartass
Client   Server                  pos (0,0)
Client   Server                              pos (0,0)pos (0,0)
Client   Server                                  pos (0,0)pos (0,0)movepos (100,200)
Client   Server                                      pos (0,0)pos (0,0)movepos (100,200)                                  ...
Client   Server                  pos (0,0)
Client   Server                              pos (0,0)pos (0,0)
Client   Server                               pos (0,0)pos (0,0)move right                               pos (1,0)
Client   Server                               pos (0,0)pos (0,0)move right                               pos (1,0) pos (1,0)
Victory!
Client side prediction
Client   Server                  pos (0,0)
Client   Server                              pos (0,0)pos (0,0)
Client   Server                               pos (0,0)pos (0,0)move right                               pos (1,0)
Client   Server                               pos (0,0)pos (0,0)move right                               pos (1,0) pos (1,0)
Client   Server                                  pos (0,0)   pos (0,0)   move rightLatency                           pos (...
Client   Server                                           pos (0,0)      pos (0,0)       move rightAnimation              ...
Client   Server                                           pos (0,0)      pos (0,0)       move rightAnimation              ...
Client   Server                                      pos (0,0)      pos (0,0)       move rightAnimation                   ...
Client   Server                                      pos (0,0)       pos (0,0)       move rightAnimation                  ...
Quakehttps://github.com/id-Software
UDPdatagrams, unreliable, unordered
rcv_buf >= snd_bufAll receive operations return only one packet          watch out for MSG_TRUNC
auto ip_mtu_discover enabled by default  EMSGSIZE signals packet too big
65k max theoretical packet limit (headers included)    rfc defines the size header to 16bits
however, 1472 is likely themax you may get, 576 to be          sure         MTU - headers
remember the TOSthroughput, reliability, lowdelay (etc.)
Quake worldhttps://github.com/id-Software/Quake
All credits to Fabien Sanglard: http://fabiensanglard.net/quakeSource/quakeSourceNetWork.php        Code: https://github.c...
Quake III arenahttps://github.com/id-Software/Quake-III-Arena
Snapshots based
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
Open source code!https://github.com/id-Software/Quake-III-Arena/blob/master/code/qcommon/msg.c
TCPStreaming, reliable, connection oriented
TCP tuning
Long story short: use auto-tuneYou probably just need to tune the maximum values                   (system wide)
High-performance extensions        refer to rfc1323
Bandwidth-delay productdata links capacity (in bits per second) and its end-to-                end delay (in seconds).
10Mbs x 1ms = 1.22 KB10Mbs x 200ms = 244 KB    rfc1323: huge buffers
CORKdont send partial frames
NODELAYdisable nagles algorithm
socket options
https://gist.github.com/4036204
benchmarking
BBG* and HTML5  *Browser based games
The same thing...     ...but not...
No TCP   No UDPNo peer to peer
Chrome support!?http://developer.chrome.com/apps/app_network.html
HTTP
Websockets
Mozilla multiplayer game: http://browserquest.mozilla.org
Blackberry                                browser           Chrome                                             OperaMobile...
Caniuse.com: websockets marketshare
Socket.ioFallbacks all over the place
BandwidthWere back again
References■ [1] Age of empires paper■ Synchronous RTS engines■ Client / server tricks■ Quake code reviews■ Improving bandw...
References■ http://linux.die.net/man/7/udp■ http://linux.die.net/man/7/ip■ http://linux.die.net/man/7/socket■ http://en.wi...
References■ http://tools.ietf.org/html/rfc1046■ http://linux.die.net/man/7/tcp
Game over
Game network programming
Game network programming
Game network programming
Game network programming
Upcoming SlideShare
Loading in …5
×

Game network programming

2,597 views

Published on

Presentation about our studies on some game network concepts and optimizations used by some games.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,597
On SlideShare
0
From Embeds
0
Number of Embeds
975
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Game network programming

  1. 1. Game networkprogrammingPotHix (Willian Molinari)Diego Souza (marciano)
  2. 2. Why?
  3. 3. Skeleton Jigsaw: http://plaev.me/skeleton-jigsaw Shameless self promotion
  4. 4. To have fun, bro!
  5. 5. Agenda■ Synchronous RTS■ Peer to peer■ Client / server■ UDP■ Quake strategy■ TCP■ Web and HTML5
  6. 6. Synchronous RTS
  7. 7. RTSs and Supreme commander
  8. 8. Peer to peer
  9. 9. Everything in sync
  10. 10. Two gameloops!
  11. 11. LatencyMy life for the horde!
  12. 12. Player1 Player2 Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
  13. 13. Player1 Player2 Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
  14. 14. Player1 Player2 Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
  15. 15. Player1 Player2 Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
  16. 16. butterfly effect
  17. 17. So...
  18. 18. Player1 Player2 Player3 tick 0mstick 100mstick 200mstick 300mstick 400ms
  19. 19. Player1 Player2 Player3 tick 0mstick 100ms UI OK!tick 200mstick 300mstick 400ms
  20. 20. Desync
  21. 21. Age of empires1500 archers with a 28.8 modem [1]
  22. 22. Client / Server
  23. 23. Authoritative server
  24. 24. Client Server pos (0,0)
  25. 25. Client Server pos (0,0)pos (0,0)
  26. 26. Client Server pos (0,0)pos (0,0)movepos (1,0)
  27. 27. Client Server pos (0,0)pos (0,0)movepos (1,0) pos (1,0)
  28. 28. Smartass
  29. 29. Client Server pos (0,0)
  30. 30. Client Server pos (0,0)pos (0,0)
  31. 31. Client Server pos (0,0)pos (0,0)movepos (100,200)
  32. 32. Client Server pos (0,0)pos (0,0)movepos (100,200) pos (100,200)
  33. 33. Client Server pos (0,0)
  34. 34. Client Server pos (0,0)pos (0,0)
  35. 35. Client Server pos (0,0)pos (0,0)move right pos (1,0)
  36. 36. Client Server pos (0,0)pos (0,0)move right pos (1,0) pos (1,0)
  37. 37. Victory!
  38. 38. Client side prediction
  39. 39. Client Server pos (0,0)
  40. 40. Client Server pos (0,0)pos (0,0)
  41. 41. Client Server pos (0,0)pos (0,0)move right pos (1,0)
  42. 42. Client Server pos (0,0)pos (0,0)move right pos (1,0) pos (1,0)
  43. 43. Client Server pos (0,0) pos (0,0) move rightLatency pos (1,0) pos (1,0)
  44. 44. Client Server pos (0,0) pos (0,0) move rightAnimation pos (1,0) pos (1,0) Predicting
  45. 45. Client Server pos (0,0) pos (0,0) move rightAnimation pos (1,0) pos (1,0) Predicting
  46. 46. Client Server pos (0,0) pos (0,0) move rightAnimation pos (2,0) pos (1,0)
  47. 47. Client Server pos (0,0) pos (0,0) move rightAnimation pos (2,0) pos (1,0)Correction pos (2,0)
  48. 48. Quakehttps://github.com/id-Software
  49. 49. UDPdatagrams, unreliable, unordered
  50. 50. rcv_buf >= snd_bufAll receive operations return only one packet watch out for MSG_TRUNC
  51. 51. auto ip_mtu_discover enabled by default EMSGSIZE signals packet too big
  52. 52. 65k max theoretical packet limit (headers included) rfc defines the size header to 16bits
  53. 53. however, 1472 is likely themax you may get, 576 to be sure MTU - headers
  54. 54. remember the TOSthroughput, reliability, lowdelay (etc.)
  55. 55. Quake worldhttps://github.com/id-Software/Quake
  56. 56. All credits to Fabien Sanglard: http://fabiensanglard.net/quakeSource/quakeSourceNetWork.php Code: https://github.com/id-Software/Quake/blob/master/QW/client/net_chan.c
  57. 57. Quake III arenahttps://github.com/id-Software/Quake-III-Arena
  58. 58. Snapshots based
  59. 59. All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
  60. 60. All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
  61. 61. All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
  62. 62. All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
  63. 63. All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
  64. 64. All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
  65. 65. Open source code!https://github.com/id-Software/Quake-III-Arena/blob/master/code/qcommon/msg.c
  66. 66. TCPStreaming, reliable, connection oriented
  67. 67. TCP tuning
  68. 68. Long story short: use auto-tuneYou probably just need to tune the maximum values (system wide)
  69. 69. High-performance extensions refer to rfc1323
  70. 70. Bandwidth-delay productdata links capacity (in bits per second) and its end-to- end delay (in seconds).
  71. 71. 10Mbs x 1ms = 1.22 KB10Mbs x 200ms = 244 KB rfc1323: huge buffers
  72. 72. CORKdont send partial frames
  73. 73. NODELAYdisable nagles algorithm
  74. 74. socket options
  75. 75. https://gist.github.com/4036204
  76. 76. benchmarking
  77. 77. BBG* and HTML5 *Browser based games
  78. 78. The same thing... ...but not...
  79. 79. No TCP No UDPNo peer to peer
  80. 80. Chrome support!?http://developer.chrome.com/apps/app_network.html
  81. 81. HTTP
  82. 82. Websockets
  83. 83. Mozilla multiplayer game: http://browserquest.mozilla.org
  84. 84. Blackberry browser Chrome OperaMobile safari Browsers IE Android browser Firefox Opera mini Safari
  85. 85. Caniuse.com: websockets marketshare
  86. 86. Socket.ioFallbacks all over the place
  87. 87. BandwidthWere back again
  88. 88. References■ [1] Age of empires paper■ Synchronous RTS engines■ Client / server tricks■ Quake code reviews■ Improving bandwidth for websockets■ Unreal networking architecture■ http://tools.ietf.org/html/rfc1323
  89. 89. References■ http://linux.die.net/man/7/udp■ http://linux.die.net/man/7/ip■ http://linux.die.net/man/7/socket■ http://en.wikipedia.org/wiki/Nagles_algorithm■ http://en.wikipedia.org/wiki/Bandwidth- delay_product
  90. 90. References■ http://tools.ietf.org/html/rfc1046■ http://linux.die.net/man/7/tcp
  91. 91. Game over

×