game network programming

95
Game network programming PotHix (Willian Molinari) Diego Souza (marciano)

Upload: willian-molinari

Post on 15-Jan-2015

2.042 views

Category:

Technology


0 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Game network programming

Game network programmingPotHix (Willian Molinari)Diego Souza (marciano)

Page 2: Game network programming

Why?

Page 3: Game network programming
Page 4: Game network programming

Skeleton Jigsaw: http://plaev.me/skeleton-jigsaw

Shameless self promotion

Page 5: Game network programming

To have fun, bro!

Page 6: Game network programming

■ Synchronous RTS

■ Peer to peer

■ Client / server

■ UDP

■ Quake strategy

■ TCP

■ Web and HTML5

Agenda

Page 7: Game network programming

Synchronous RTS

Page 8: Game network programming

RTS's and Supreme commander

Page 9: Game network programming

Peer to peer

Page 10: Game network programming

Everything in sync

Page 11: Game network programming

Two gameloops!

Page 12: Game network programming

LatencyMy life for the horde!

Page 13: Game network programming

Player1 Player2 Player3

tick 100ms

tick 200ms

tick 300ms

tick 400ms

tick 0ms

Page 14: Game network programming

Player1 Player2 Player3

tick 100ms

tick 200ms

tick 300ms

tick 400ms

tick 0ms

Page 15: Game network programming

Player1 Player2 Player3

tick 100ms

tick 200ms

tick 300ms

tick 400ms

tick 0ms

Page 16: Game network programming

Player1 Player2 Player3

tick 100ms

tick 200ms

tick 300ms

tick 400ms

tick 0ms

Page 17: Game network programming

butterfly effect

Page 18: Game network programming

So...

Page 19: Game network programming

Player1 Player2 Player3

tick 100ms

tick 200ms

tick 300ms

tick 400ms

tick 0ms

Page 20: Game network programming

Player1 Player2 Player3

tick 100ms

tick 200ms

tick 300ms

tick 400ms

tick 0ms

UI OK!

Page 21: Game network programming

Desync

Page 22: Game network programming

Age of empires1500 archers with a 28.8 modem [1]

Page 23: Game network programming

Client / Server

Page 24: Game network programming

Authoritative server

Page 25: Game network programming

Client Server

pos (0,0)

Page 26: Game network programming

Client Server

pos (0,0)

pos (0,0)

Page 27: Game network programming

Client Server

pos (0,0)

pos (0,0)

move

pos (1,0)

Page 28: Game network programming

Client Server

pos (0,0)

pos (0,0)

move

pos (1,0)

pos (1,0)

Page 29: Game network programming

Smartass

Page 30: Game network programming

Client Server

pos (0,0)

Page 31: Game network programming

Client Server

pos (0,0)

pos (0,0)

Page 32: Game network programming

Client Server

pos (0,0)

pos (0,0)

move

pos (100,200)

Page 33: Game network programming

Client Server

pos (0,0)

pos (0,0)

move

pos (100,200)

pos (100,200)

Page 34: Game network programming
Page 35: Game network programming

Client Server

pos (0,0)

Page 36: Game network programming

Client Server

pos (0,0)

pos (0,0)

Page 37: Game network programming

Client Server

pos (0,0)

pos (0,0)

move right

pos (1,0)

Page 38: Game network programming

Client Server

pos (0,0)

pos (0,0)

move right

pos (1,0)

pos (1,0)

Page 39: Game network programming

Victory!

Page 40: Game network programming

Client side prediction

Page 41: Game network programming

Client Server

pos (0,0)

Page 42: Game network programming

Client Server

pos (0,0)

pos (0,0)

Page 43: Game network programming

Client Server

pos (0,0)

pos (0,0)

move right

pos (1,0)

Page 44: Game network programming

Client Server

pos (0,0)

pos (0,0)

move right

pos (1,0)

pos (1,0)

Page 45: Game network programming

Client Server

pos (0,0)

pos (0,0)

move right

pos (1,0)

pos (1,0)

Latency

Page 46: Game network programming

Client Server

pos (0,0)

pos (0,0)

move right

pos (1,0)

pos (1,0)

Animation

Predicting

Page 47: Game network programming

Client Server

pos (0,0)

pos (0,0)

move right

pos (1,0)

pos (1,0)

Animation

Predicting

Page 48: Game network programming

Client Server

pos (0,0)

pos (0,0)

move right

pos (2,0)

pos (1,0)

Animation

Page 49: Game network programming

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

Quakehttps://github.com/id-Software

Page 51: Game network programming

UDPdatagrams, unreliable, unordered

Page 52: Game network programming

rcv_buf >= snd_bufAll receive operations return only one packet

watch out for MSG_TRUNC

Page 53: Game network programming

auto ip_mtu_discover enabled by default

EMSGSIZE signals packet too big

Page 54: Game network programming

65k max theoretical packet limit (headers included)

rfc defines the size header to 16bits

Page 55: Game network programming

however, 1472 is likely the max you may get, 576 to be

sureMTU - headers

Page 56: Game network programming

remember the TOSthroughput, reliability, lowdelay (etc.)

Page 57: Game network programming

Quake worldhttps://github.com/id-Software/Quake

Page 58: Game network programming

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

Quake III arenahttps://github.com/id-Software/Quake-III-Arena

Page 60: Game network programming

Snapshots based

Page 61: Game network programming

All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php

Page 62: Game network programming

All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php

Page 63: Game network programming

All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php

Page 64: Game network programming

All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php

Page 65: Game network programming

All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php

Page 66: Game network programming

All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php

Page 67: Game network programming

Open source code!https://github.com/id-Software/Quake-III-Arena/blob/master/code/qcommon/msg.c

Page 68: Game network programming

TCPStreaming, reliable, connection oriented

Page 69: Game network programming

TCP tuning

Page 70: Game network programming

Long story short: use auto-tune You probably just need to tune the maximum values

(system wide)

Page 71: Game network programming

High-performance extensions

refer to rfc1323

Page 72: Game network programming

Bandwidth-delay product data link's capacity (in bits per second) and its end-to-

end delay (in seconds).

Page 73: Game network programming

10Mbs x 1ms = 1.22 KB10Mbs x 200ms = 244 KB

rfc1323: huge buffers

Page 74: Game network programming

CORKdon't send partial frames

Page 75: Game network programming

NODELAYdisable nagle's algorithm

Page 76: Game network programming

socket options

Page 77: Game network programming

https://gist.github.com/4036204

Page 78: Game network programming

benchmarking

Page 79: Game network programming
Page 80: Game network programming
Page 81: Game network programming

BBG* and HTML5*Browser based games

Page 82: Game network programming

The same thing......but not...

Page 83: Game network programming

No TCP No UDP

No peer to peer

Page 84: Game network programming

Chrome support!?http://developer.chrome.com/apps/app_network.html

Page 85: Game network programming

HTTP

Page 86: Game network programming

Websockets

Page 87: Game network programming

Mozilla multiplayer game: http://browserquest.mozilla.org

Page 88: Game network programming

BrowsersIE

Firefox

ChromeOpera

Safari

Android browser

Mobile safari

Opera mini

Blackberry browser

Page 89: Game network programming

Caniuse.com: websockets marketshare

Page 90: Game network programming

Socket.ioFallbacks all over the place

Page 91: Game network programming

BandwidthWe're back again

Page 94: Game network programming

■ http://tools.ietf.org/html/rfc1046

■ http://linux.die.net/man/7/tcp

References

Page 95: Game network programming

Game over