List of snap items
Note there is also documentation about snapshots in libtw2.
The network messages NETMSG_SNAP, NETMSG_SNAPEMPTY, NETMSG_SNAPSINGLE and NETMSG_SNAPSMALL
contain snapshots which represent the current game state.
The snapshot data is containing snap items which represent things like tees, projectiles and similar.
All of those items are encoded as packed integers.
The snapshot is build by the server and sent to the client.
Item order
For some snap items the order they appear in the snap matters. For example obj_game_info is usually the first item in the snap. And obj_client_info should not be added in the snap before it. Because the client code loops over all snap items in the order they were added. And when inserting the clients it looks at theobj_game_info->m_GameFlags
and if the teams flag is set
the clients tee is colored in team colors. If the obj_game_info would be after the
obj_client_info the client would not know yet about it and assume no teams are set.
All snapshot items are deltas
The entire snapshot payload should always be seen as a delta to a previous snapshot. The payload (data) of a snapshot starts with a short header:
- NumDeletedItems
- NumUpdatedItems
- Unused
m_X
set to -4 it does not mean
that in the actual world there is a tee located at coordinate -4 it just means that this character
moved 4 units to the left compared to its previous known location. Same if m_Health
is set to 0
it does not mean that the character is dead. It just means that the health did not change.
This allows the int packer to do its magic which performs well on small numbers. Let's say we have a big map and a tee moving around on the x coordinate 16777215 (maps that big are actually not possible this is just for the example sake) which is a 3 byte integer but the tee only moved 10 units since the last synced snapshot so the new snapshot only needs one byte to represent the coordinate of this tee. It also means every unchanged value will be one null byte which then helps the huffman compression that is applied on top. Because it works best if it is given consecutive bytes.
The delta is created by the server against the last snapshot that the client acknowledged. The snap message also contains the game tick of the snapshot that was used as a base for the delta. So the client is supposed to keep a few snapshots with their game ticks locally. To then find the correct one to unpack new deltas against.
Also the first snapshot can be unpacked like a delta. And the delta can be applied to an empty snapshot. In that case game tick - delta_tick should evaluate to
-1
Known size table
type_id | size | name | parameters | description |
---|---|---|---|---|
1 | 10 | obj_player_input |
int m_Direction; int m_TargetX; int m_TargetY; int m_Jump; int m_Fire; int m_Hook; int m_PlayerFlags; int m_WantedWeapon; int m_NextWeapon; int m_PrevWeapon; |
This is a special snap item that is not actually included in the snap.
But instead sent by the client in the system message
NETMSG_INPUT
The m_PlayerFlags field has the following flags:
|
2 | 6 | obj_projectile |
int m_X; int m_Y; int m_VelX; int m_VelY; int m_Type; int m_StartTick; |
desc |
3 | 5 | obj_laser |
int m_X; int m_Y; int m_FromX; int m_FromY; int m_StartTick; |
desc |
4 | 4 | obj_pickup |
int m_X; int m_Y; int m_Type; int m_Subtype; |
m_Type can be on of those:
m_Subtype is only used if the type is POWERUP_WEAPON And its value can be one of those:
|
5 | 3 | obj_flag |
int m_X; int m_Y; int m_Team; |
desc |
6 | 8 | obj_game_info |
int m_GameFlags; int m_GameStateFlags; int m_RoundStartTick; int m_WarmupTimer; int m_ScoreLimit; int m_TimeLimit; int m_RoundNum; int m_RoundCurrent; |
Possible m_GameFlags are:
m_GameStateFlags are:
|
7 | 4 | obj_game_data |
int m_TeamscoreRed; int m_TeamscoreBlue; int m_FlagCarrierRed; int m_FlagCarrierBlue; |
desc |
8 | 15 | obj_character_core |
int m_Tick; int m_X; int m_Y; int m_VelX; int m_VelY; int m_Angle; int m_Direction; int m_Jumped; int m_HookedPlayer; int m_HookState; int m_HookTick; int m_HookX; int m_HookY; int m_HookDx; int m_HookDy; |
This item is not being sent in the snap directly.
It is only ever sent as part of obj_character.
So the snap item type id 8 is unused.
<Zwelf>
m_HookTick has the type NetTick
in protocol.py,
but is used as HookDuration. Starting with zero and incrementing one each tick until the roughly 60 ticks = 1.2s are passed.
|
9 | 22 | obj_character |
/* core */ int m_Tick; int m_X; int m_Y; int m_VelX; int m_VelY; int m_Angle; int m_Direction; int m_Jumped; int m_HookedPlayer; int m_HookState; int m_HookTick; int m_HookX; int m_HookY; int m_HookDx; int m_HookDy; /* character extension */ int m_PlayerFlags; int m_Health; int m_Armor; int m_AmmoCount; int m_Weapon; int m_Emote; int m_AttackTick; |
desc |
10 | 5 | obj_player_info |
int m_Local; int m_ClientID; int m_Team; int m_Score; int m_Latency; |
Unpacked by the client in gameclient.cpp
|
11 | 17 | obj_client_info |
int m_Name0; int m_Name1; int m_Name2; int m_Name3; int m_Clan0; int m_Clan1; int m_Clan2; int m_Country; int m_Skin0; int m_Skin1; int m_Skin2; int m_Skin3; int m_Skin4; int m_Skin5; int m_UseCustomColor; int m_ColorBody; int m_ColorFeet; |
This snap items ID field matches the corresponding Client ID.
As you can see in this gameclient.cpp snippet.
|
12 | 3 | obj_spectator_info |
int m_SpectatorID; int m_X; int m_Y; |
desc |
13 | 2 | event_common |
int m_X; int m_Y; |
This item is not being sent in the snap directly. It is only ever sent as part of other events. So the snap item type id 13 is unused. |
14 | 2 | event_explosion |
int m_X; int m_Y; |
desc |
15 | 2 | event_spawn |
int m_X; int m_Y; |
desc |
16 | 2 | event_hammerhit |
int m_X; int m_Y; |
desc |
17 | 3 | event_death |
/* common */ int m_X; int m_Y; /* death */ int m_ClientID; |
desc |
18 | 3 | event_sound_global |
/* common */ int m_X; int m_Y; /* sound_global */ int m_SoundID; |
desc |
19 | 3 | event_sound_world |
/* common */ int m_X; int m_Y; /* sound_world */ int m_SoundID; |
desc |
20 | 3 | event_damage_indicator |
/* common */ int m_X; int m_Y; /* damage_indicator */ int m_Angle; |
desc |