3. Limitations
◇ Network bandwidth limitations
◇ Networks packet take time to travel (ping time)
◇ Hard to synchronize client & server states
4. Client-Server
Client-Server:
◇ Expensive to maintain
◇ Server acts as a host
◇ Prevent hacking
◇ Heavy testing needed
Peers to peers:
◇ No maintenance costs
◇ Playable through LAN
◇ Easy to setup
◇ Hard to prevent hacks
5. Server simulates the game in time steps called ticks.
Default, the timestep is 15ms, so 66.666 per second.
Each tick, the server processes incoming user
commands, runs a physical simulation, checks game
rules, and updates all object states.
Counter-Strike, Left 4 Dead and Team Fortress.
Dedicated Server
6. Client is used as a host and acts as a server.
This client will receives messages from other clients.
Proceed them as a normal client would, executes
physics, checks for logics, and then send back new
states to other clients.
UNet uses this model.
Client as Server
8. Design & Optimize
To solve network issues, techniques such as data compression and lag compensation are implemented.
Client then performs prediction and interpolation to further improve the experience.
9. In games such as Half Life, Quake and Unreal, there is a single server which is responsible for
running game logic. To it are connected one or more "dumb" clients. These clients were nothing
more than a way for user input to be sampled and forwarded to the server for execution.
10. Using the above data structures, first, the client creates and sends a command to server. The
server then executes user command and sends updated positions of everything back to client.
Which, the client renders the scene with all of these objects.
11. The main problem is that the client truly is "dumb",all it does is sampling movement inputs and
wait. If the client has 500 milliseconds of latency, then it will take 500 milliseconds for any
client actions to be acknowledged by the server and for the results to be perceptible on the
client.
13. Each user command (and time it was generated) is stored on the client. The prediction
algorithm uses these stored commands. In Half-Life, minimizing discrepancies between
client and server is accomplished by sharing identical movement code for players in both
the server code and the client-side code
14. The firing logic can be layered on top of the movement logic because the state of firing
buttons is included in the command data structure that is shared between the client and
the server.
typedef struct usercmd_s
{
// Interpolation time on client
short lerp_msec;
// Duration in ms of command
byte msec;
// Command view angles.
vec3_t viewangles;
// Forward velocity.
float forwardmove;
// Sideways velocity.
float sidemove;
// Upward velocity.
float upmove;
// Attack buttons
unsigned short buttons;
} usercmd_t;
16. Although you hear weapon fire immediately, the results the shot is subject to latency. If you
aim at a player and you have 100 milliseconds latency and the player is running at 500
units per second, then you'll need to aim 50 units in front of the target to hit the target.
The greater the latency, the greater the lead targeting needed. Getting a "feel" for your
latency is difficult.
17. - When you shoot, client sends event to server with timestamp and exact aim of shot.
- Server gets input with timestamps, it reconstruct the world at any instant in the past.
- The server can know exactly what was on weapon’s sights instant you shot.
- It was the past position of your enemy’s head, but the server knows it was the position of
his head in your present.
- The server processes the shot at that point in time, and updates the clients.
19. - Server gets inputs from all the clients, with timestamps
- Server processes inputs and updates world status
- Server sends regular world snapshots to all clients
- Client sends input and simulates their effects locally
Client get world updates and
- Syncs predicted state to authoritative state
- Interpolates known past states for other entities
From a player’s POV, this has two important consequences:
- Player sees himself in the present
- Player sees other entities in the past
Summary