Download - Game network programming
Game network programmingPotHix (Willian Molinari)Diego Souza (marciano)
Why?
Skeleton Jigsaw: http://plaev.me/skeleton-jigsaw
Shameless self promotion
To have fun, bro!
■ Synchronous RTS
■ Peer to peer
■ Client / server
■ UDP
■ Quake strategy
■ TCP
■ Web and HTML5
Agenda
Synchronous RTS
RTS's and Supreme commander
Peer to peer
Everything in sync
Two gameloops!
LatencyMy life for the horde!
Player1 Player2 Player3
tick 100ms
tick 200ms
tick 300ms
tick 400ms
tick 0ms
Player1 Player2 Player3
tick 100ms
tick 200ms
tick 300ms
tick 400ms
tick 0ms
Player1 Player2 Player3
tick 100ms
tick 200ms
tick 300ms
tick 400ms
tick 0ms
Player1 Player2 Player3
tick 100ms
tick 200ms
tick 300ms
tick 400ms
tick 0ms
butterfly effect
So...
Player1 Player2 Player3
tick 100ms
tick 200ms
tick 300ms
tick 400ms
tick 0ms
Player1 Player2 Player3
tick 100ms
tick 200ms
tick 300ms
tick 400ms
tick 0ms
UI OK!
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)
move
pos (1,0)
Client Server
pos (0,0)
pos (0,0)
move
pos (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)
move
pos (100,200)
Client Server
pos (0,0)
pos (0,0)
move
pos (100,200)
pos (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 right
pos (1,0)
pos (1,0)
Latency
Client Server
pos (0,0)
pos (0,0)
move right
pos (1,0)
pos (1,0)
Animation
Predicting
Client Server
pos (0,0)
pos (0,0)
move right
pos (1,0)
pos (1,0)
Animation
Predicting
Client Server
pos (0,0)
pos (0,0)
move right
pos (2,0)
pos (1,0)
Animation
Client Server
pos (0,0)
pos (0,0)
move right
pos (2,0)
pos (1,0)
Animation
pos (2,0)
Correction
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 the max you may get, 576 to be
sureMTU - 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.com/id-Software/Quake/blob/master/QW/client/net_chan.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-tune You probably just need to tune the maximum values
(system wide)
High-performance extensions
refer to rfc1323
Bandwidth-delay product data link's 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
CORKdon't send partial frames
NODELAYdisable nagle's algorithm
socket options
https://gist.github.com/4036204
benchmarking
BBG* and HTML5*Browser based games
The same thing......but not...
No TCP No UDP
No peer to peer
Chrome support!?http://developer.chrome.com/apps/app_network.html
HTTP
Websockets
Mozilla multiplayer game: http://browserquest.mozilla.org
BrowsersIE
Firefox
ChromeOpera
Safari
Android browser
Mobile safari
Opera mini
Blackberry browser
Caniuse.com: websockets marketshare
Socket.ioFallbacks all over the place
BandwidthWe're back again
■ [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
■ 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
■ http://tools.ietf.org/html/rfc1046
■ http://linux.die.net/man/7/tcp
References
Game over