File: snapshots.txt

package info (click to toggle)
teeworlds 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,024 kB
  • sloc: cpp: 58,009; ansic: 14,468; python: 3,763; asm: 946; objc: 107; makefile: 37; xml: 21; sh: 7
file content (58 lines) | stat: -rw-r--r-- 3,346 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Title: Snapshots

Section: Overview

Topic: Definitions

- *Snapshot*. A is a serialized game state from which a client can render the game from. They are sent from the server at a regular interval and is created specifically for each client in order to reduce bandwidth.
- *Delta Snapshot*. A set of data that can be applied to a snapshot in order to create a new snapshot with the updated game state.

Topic: Structure

A snapshot contains a series of items. Each item have a type, id and data.

- *Type*. Type of item. Could be projectile or character for example.
- *Id*. A unique id so the client can identify the item between two snapshots.
- *Data*. A series of 32-bit integers that contains the per item type specific data.

Section: Server Side

Topic: Creating

Items can be added when <mods_snap> is called using the <snap_new_item> function to insert an item to the snapshot. The server can not inspect the snapshot that is in progress of being created.

Section: Client Side

Topic: Inspection
<modc_newsnapshot> is called when a new snapshot has arrived for processing. <snap_num_items>, <snap_get_item> and <snap_find_item> can be used to inspect the current and previous snapshot. This can be done anywhere while the client is running and not just in the <modc_newsnapshot> function. The client can also call <snap_invalidate_item> if an item contains improper information that could harm the operation of the client. This should however be done in <modc_newsnapshot> to assure that no bad data propagates into the rest of the client.

Topic: Rendering
DOCTODO

Section: In depth

Topic: Compression

After a snapshot have been created, compression is applied to reduce the bandwidth. There are several steps taken in order to reduce the size of the snapshot.

- *Delta*. The server looks in a clients backlog of snapshots to find a previous acked snapshot. It then compares the two snapshots and creates a delta snapshot containing the changes from the previous acked snapshot to the new one.
- *Variable Integers*. The delta snapshot which is only consisting of 32-bit integers is then encoded into variable integers similar to UTF-8. Each byte has a bit that tells the decoder that it needs one more byte to decode the 32-bit integer. The first byte also contains a bit for telling the sign of the integer.

> ESDDDDDD EDDDDDDD EDDDDDDD EDDDDDDD

> E = extend
> S = sign
> D = data bit

- *Huffman*. The last step is to compress the buffer with a huffman encoder. It uses a static tree that is weighted towards 0 because it's where most of the data will be because of the delta compression.

Topic: Interval

The interval for how often a client receives a snapshot changes during the course of the connection. There are three different snapshot rates.

- *Init*. 5 snapshots per second. Used when a client is connecting and used until the client has acknowledged a snapshot. This mechanism is used because delta compression can not be applied to the first snapshot.

- *Full*. Snapshot for every tick or every even tick depending on server configuration. This is used during normal gameplay and everything is running smooth.

- *Recovery*. 1 snapshot each second. A client enters recovery rate when it haven't acknowledged a snapshot over 1 second. This is to let the client to be able to recover if it has a slow connection.