lets play together
TRANSCRIPT
“Let’s Play Together” Networked Mul-player Games
Amir H. Fassihi Fanafzar
Background
Garshasp: The Monster Slayer, PC 2011
Garshasp: Temple of the Dragon, PC 2012
Shadow Blade, iOS, Android Fall, 2013
Current Game
• Coopera-ve Mul-player Game
Mul-player Games
• Co-‐op/PvP • Local/LAN/Internet • Real-‐-me/Asynchronous
This Talk
• LAN/Internet • Co-‐op/PvP • Real-me
Game Networking
Gameplay Code
High Level Network Code
Low Level Network Code
Low Level Networking
• Sockets • Transfer Protocols • NAT (Network Address Transla9on)
Sockets
• Socket – IP – Port
• OS Support – BSD Sockets – WinSock – …
Transfer Protocols
• UDP – Unreliable – Un-‐ordered – Connec-on-‐less using Datagrams (1400 bytes)
• TCP – Reliable – Ordered – Stream Based
Game Networking
UDP + reliability + order
NAT
• Network Address Transla-on • Connec-on Problem with NAT Box – Server Listening on Port – Client changing port
• NAT Punch-‐through with Facilitator Server
High Level Networking
• Architecture • Data to Transfer • Lag Compensa-on
Network Architecture
• Peer to Peer • Client Server • Mixed
Peer to Peer
Client 1 Client 2
Client 3 Client 4
Client-‐Server
Client 1
Client 2
Client 3
Server
Data Transfer
How To Share The Same Experience?
What to Send?
1. Share Inputs 2. Share Input and State (Authorita-ve Server) 3. Share Input and State (Mixed Authority)
Game Loop (Simplified)
1. Read User Input 2. Do Simula-on
1. Logic 2. AI 3. Physics …
3. Output 1. Render Graphics 2. Play Sound/Music 3. Update UI …
Sharing Input
Client 1 Client 2
User 1 Input
User 2 Input
Shared Input P2P
Main Requirement:
Determinis=c Simula=on
Shared Input P2P
Constraint (for Lockstep):
Lag Effect On Clients No mid-‐game join!
Shared Input P2P
Risk:
Chea=ng
Shared Input P2P
Advantage:
Low Bandwidth Requirements
Shared Input P2P
Used for:
Strategy Games (Starcra', Age of Empires, …)
1500 Archers
• 1500 Archers on a 28.8: Network Programming in Age of Empires and Beyond, Gamasutra
Shared State
Server
Client 1 Client 2
Input 1 Input 2
Game State
Game State
Shared State
Main Requirement:
Simula=on Only On Server
Shared State
Constraint:
High Bandwidth (Especially the Server!)
Shared State
• Cheat Proof • Non-‐determinis-c simula-on is ok • Different client lag will not stall • Mid-‐game joining possible
Shared State
Good For:
Ac=on Games Compe==ve Games (eSports)
Main Challenge
Biggest Challenge in Game Networking is:
Lag!!!
Lag in Client-‐Server
Client Server Press Buaon
Press Buaon Fire
Fire
Lag in Client-‐Server
Client Server Press Buaon
Press Buaon Fire
Fire
Lag
Solu-on #1
Client Side Predic=on
Client-‐side Predic-on
Client Server Press Buaon
Press Buaon Fire
Fire
Check Validity
Client-‐side Predic-on
• Fix Client State if different • State History on Client • Useful for player state • Can be used for other objects (extrapola-on)
Client-‐side Predic-on
Popularized by:
Solu-on #2
Input Latency
Input Latency
• Input marked for future • 50-‐100ms • Client will interpolate
Input Latency
Client Server Move Forward T = +100ms
Move Forward Find posi-on for: +100
Pos: +100ms Current t: +70ms
Interpolate between previous pos and pos at +100ms for +70ms
Client Interpola-on
-me = 1200 -me = 1300 pos = 1, 1, 1 pos = 2, 2, 1
9me = 1250 pos = 1.5, 1.5, 1
Interpolated State
Solu-on #3
Server-‐side Lag Compensa=on
Server-‐side Lag Compensa-on
• Rewind simula-on on server based on client lag.
• Re-‐simulate game.
Source Engine Lag Compensa-on
Gameplay Inconsistencies
• Wrong posi-on (no compensa9on)
• Late Hits (with compensa9on)
Problem with Lag Compensa-on
A
B
High Lag
Low Lag
Problem with Lag Compensa-on
A
B
High Lag
Low Lag
B
Design
Lag Compensa=on Strategy can be a “Game Design” decision.
Doom III Solu-on
Player Extrapola=on
Player Extrapola-on
• A kind of Predic-on • Assume controls don’t change • Simulate fully (with Physics) like the server • AKA Dead Reckoning
Mixed Authority
• Clients with Authority over some objects. • Example: Sync Host in FUSE (Overstrike), Game Developer Magazine, Feb 2012
Network Op-miza-on
• High Level – Architecture Selec-on – Update Frequency – Data Relevancy – Priori-za-on
Network Op-miza-on
• Low Level – Bitpacking (bitstreams) – Compression – Delta Values
Delta Compression in Quake (1996)
Quake Delta Compression
Delta + Reliable UDP
Quake Network Stack
Doom (1993)
• Doom used P2P Lockstep Model. Good for LAN only.
Quake Engine Evolu-on
Quake Engine Evolu-on
Quake Engine Evolu-on
Quake Engine Evolu-on
Cloud Gaming
Main Challenge:
Lag!
Figh-ng Game Networking
• Peer to Peer – Input Latency – Rollback Technique Example: GGPO Networking Library
Networking Libraries
• Enet • RakNet • Ice • PocoProject • Torque Network Library • ZeroMQ • Boost ASIO
Conclusion
• Networking is a tradeoff between: – Consistency – Responsiveness – Bandwidth – Latency
References 1
• Robust Efficient Networking, Ben Garney, GDC 2008
• Torque Networking Library (opentnl.org) • Video Game Op-miza-on, Ben Garney • “I Shot You First”, Halo Reach Networking, David Aldridge, GDC 2011
References 2
• QuakeWorld hap://en.wikipedia.org/wiki/QuakeWorld
• Network Systems in Insomniac Games’ Overstrike (FUSE), Game Developer Magazine, Feb 2012
• 1500 Archers on a 28.8, hap://www.gamasutra.com/view/feature/131503/1500_archers_on_a_288_network_.php?page=1
References 3
• “The TRIBES Engine Networking Model”, Frohnmayer and Gis, GDC 1999
• Understanding Figh-ng Game Networking, hap://mauve.mizuumi.net/2012/07/05/understanding-‐figh-ng-‐game-‐networking/
• GGOP Networking Library, hap://ggpo.net/
• The Doom III Network Architecture hap://mrelusive.com/publica-ons/papers/The-‐DOOM-‐III-‐Network-‐Architecture.pdf
References 4
• The Quake 3 Networking Model, Brian Hook, hap://trac.bookouook.com/bookouook/trac.cgi/wiki/Quake3Networking
• What Every Programmer Needs To Know About Game Networking, Glenn Fiedler, hap://gafferongames.com/networking-‐for-‐game-‐programmers/what-‐every-‐programmer-‐needs-‐to-‐know-‐about-‐game-‐networking/
• Unreal Networking Architectures hap://udn.epicgames.com/Three/NetworkingOverview.html
References 5
• “Latency Compensa-ng Methods in Client/Server in-‐game Protocol Design”, Yahn Bernier, Valve haps://developer.valvesosware.com/wiki/Latency_Compensa-ng_Methods_in_Client/Server_In-‐game_Protocol_Design_and_Op-miza-on#Lag_Compensa-on
• Believable Dead Reckoning for Networked Games, Cur-ss Murphy, Game Engine Gems 2
• Choosing a Game Network Library, Patrick Wyaa, hap://www.codeouonor.com/blog/choosing-‐a-‐game-‐network-‐lib
References 6
• Dead Reckoning: Latency Hiding for Networked games hap://www.gamasutra.com/view/feature/3230/dead_reckoning_latency_hiding_for_.php
Special Thanks
• Yaser Zhian • Hojjat Jafary • Ashkan Saeidi