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