Network synchronization of
Online Games
Li , Zetan
What is cyber game?
• Players share the same scenery and interact with each other. Compare to traditional single games.
• Usually require access to internet.(Or at least local area network)
How does cyber game work
• Sharing one virtual world? It's an illusion. :PWhat is actually going on underneath is quite different from what you see.What you perceive as a shared reality is only an approximation unique to your
own point of view and place in time.
Message exchange
Two different games running on two different
machines, and try to maintain same scenery
through massage exchange.
Synchronization
• Peer-to-peer lockstep
• Client/server
Synchronization
• Peer-to-peer lockstepIn the beginning games were networked peer-to-peer, with each other computer exchanging information with each other in a fully connected mesh topology.
Synchronization—— peer-to-peer lock step
• Abstract the game into a series of turns and a set of command messages when processed at the beginning of each turn direct the evolution of the game state.
• Advantage – Simple to implement• Drawback & Limitation-- Cannot guarantee 100% deterministic of a game. One tiny difference will
results in complete desynchronization over time-- Have to wait until all the players’ messages are collected--- Impossible to join in the middle of game. • Still using in RTS game today
Synchronization
• Client/Server modelMost lagged player makes game slow? Using client/server
model!• First appear in Quake ,1996• Using widely in games today, especially action games.
Synchronization—— Client/Server
• Each player was now a “client” and they all communicated with just one computer called the “server”.
• Game only exist on the server, client act like a terminal
• Each player send their input to server. Server response with their new states.
• Possible for players to come and go in the middle of the game
msgmsg
Client
Client
Server
Problems for Client/Server model
• Latency makes game sucksSolution
• Client-Side Prediction • Latency Compensation
Client-Side Prediction
• Client immediately in response to player’s input
• Using server’s response to correct player’s state
——Why not let client manipulate the state of itself: prevent cheating
——Circular buffer of past character state*Brief introduction on Latency Compensation
Networked Physics
• What is physics engine
• Game with physics simulation
How to synchronize physics performance
• Send state of all objects? You are challenging bandwidth
• Simple illustration: FPS1. Character physics are completely driven from input data2. Physics state is known and can be fully encapsulated in a
state structure3. The physics simulation is reasonably deterministic given the
same initial state and inputs
Example: FPS• Arrange input and state information:
• Physics is run on the server according to a stream of input from clients• Clients approximate server physics locally• Deal with latency1. Client prediction2. Packet loss
struct Input { bool left; bool right; bool forward; bool back; bool jump; };
struct State { Vector position; Vector velocity; };
Protocol
• TCP v.s UDP• TCP• Connection based• Guaranteed reliable and ordered• Automatically breaks up your data into packets for you• Makes sure it doesn’t send data too fast for the internet connection to handle (flow control)• Easy to use, you just read and write data like its a file
• UDP• No concept of connection, you have to code this yourself• No guarantee of reliability or ordering of packets, they may arrive out of order, be duplicated, or not arrive
at all!• You have to manually break your data up into packets and send them• You have to make sure you don’t send data too fast for your internet connection to handle• If a packet is lost, you need to devise some way to detect this, and resend that data if necessary
Why Not TCP?
• Games have a real time requirement on packet delivery. Packet loss will make game stop and wait for packet resent.
References• http://gafferongames.com/networking-for-game-programmers/what-ev
ery-programmer-needs-to-know-about-game-networking/
• http://gafferongames.com/networking-for-game-programmers/sending-and-receiving-packets/
• http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/
• http://gafferongames.com/game-physics/networked-physics/
• http://www.gamasutra.com/view/feature/3094/1500_archers_on_a_288_network_.php
Thank You!
Questions??
Top Related