This file is mirrored from the libtw2 documentation and is dual-licensed under MIT or APACHE.
Teeworlds uses this format of so called “snapshots” to transmit the current state of the world over the network. The format allows one to transmit fixed-size “items”.
All integers in this document are little-endian integers.
An item key is a 32-bit unsigned integer that contains the 16-bit
type_id as the upper bits and
id as the lower bits.
An item consists of an item key
key and an array of 32-bit signed
A snapshot is a collection of items identified by their key.
The checksum of a snapshot is calculated by summing all the
elements of all items, using wrapping overflow behavior.
snapshot_delta: [ 4] num_removed_items [ 4] num_item_deltas [ 4] _zero [*4] removed_item_keys [ ] item_deltas
Snapshot deltas are used to describe the differences between two snapshots, the “old” and the “new” one. You can use the delta together with the old snapshot to construct the new one. Note that the reverse does not work, because the values of snapshot items present in the old but not the new snapshot are not recorded in the delta.
num_removed_itemsis a positive signed 32-bit integer describing the length of the
num_item_deltasis a positive signed 32-bit integer describing the number of item deltas in the
_zerois a padding field which must be zeroed by any snapshot delta writer and ignored by any snapshot delta reader.
removed_item_keysis an array of
num_removed_itemsitem keys that are present in old snapshot, but not in the new one.
item_deltasis a concatenation of
item_delta: [ 4] type_id [ 4] id [ 4] _size [*4] data_delta
type_idis a 32-bit unsigned integer containing the 16-bit type id of the item.
idis 32-bit unsigned integer containing the 16-bit id of the item.
_sizeis a field that is only present if the size of items of type
type_idis not pre-agreed for the protocol. A list of pre-agreed item sizes can be found in the appendix of this document.
data_deltais the data delta (an array of
_size32-bit signed integers). If the item was not present in the old snapshot (determined by the item key), then
data_deltajust contains the new item data. Otherwise, the
data_deltaneeds to be added onto the current item’s data (elementwise) using 32-bit integer addition that wraps around on overflow. Note that in the case of item update, the new size must be the same as the old size of the item data.
This describes the 0.6 protocol of Teeworlds.
size | name ———-+——–+————– 1 | 10 |
obj_player_input 2 | 6 | obj_projectile 3 | 5 | obj_laser 4 | 4 |
obj_pickup 5 | 3 | obj_flag 6 | 8 | obj_game_info 7 | 4 |
obj_game_data 8 | 15 | obj_character_core 9 | 22 | obj_character 10
| 5 | obj_player_info 11 | 17 | obj_client_info 12 | 3 |
obj_spectator_info 13 | 2 | event_common 14 | 2 | event_explosion 15
| 2 | event_spawn 16 | 2 | event_hammerhit 17 | 3 | event_death 18 |
3 | event_sound_global 19 | 3 | event_sound_world 20 | 3 |