Skip to content

Commit 5c50ac6

Browse files
committed
Documented more fields (#1)
1 parent 2e0939b commit 5c50ac6

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

common/structs.go

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import (
1212

1313
// DemoHeader contains information from a demo's header.
1414
type DemoHeader struct {
15-
Filestamp string
16-
Protocol int
17-
NetworkProtocol int
18-
ServerName string
19-
ClientName string
20-
MapName string
21-
GameDirectory string
22-
PlaybackTime float32
23-
PlaybackTicks int
24-
PlaybackFrames int
25-
SignonLength int
15+
Filestamp string // aka. File-type, must be HL2DEMO
16+
Protocol int // Should be 4
17+
NetworkProtocol int // Not sure what this is for
18+
ServerName string // Server's 'hostname' config value
19+
ClientName string // Usually 'GOTV Demo'
20+
MapName string // E.g. de_cache, de_nuke, cs_office, etc.
21+
GameDirectory string // Usually 'csgo'
22+
PlaybackTime float32 // Demo duration in seconds (= PlaybackTicks / Server's tickrate)
23+
PlaybackTicks int // Game duration in ticks (= PlaybackTime * Server's tickrate)
24+
PlaybackFrames int // Amount of 'frames' aka demo-ticks recorded (= PlaybackTime * Demo's recording rate)
25+
SignonLength int // Length of the Signon package in bytes
2626
}
2727

2828
// FrameRate returns the frame rate of the demo (frames / demo-ticks per second).
@@ -49,34 +49,32 @@ func (h DemoHeader) TickTime() time.Duration {
4949

5050
// Player contains mostly game-relevant player information.
5151
type Player struct {
52-
SteamID int64
53-
Position r3.Vector
54-
LastAlivePosition r3.Vector
55-
Velocity r3.Vector
56-
EntityID int
57-
UserID int
58-
Name string
52+
SteamID int64 // int64 representation of the User's Steam ID
53+
Position r3.Vector // In-game coordinates. Like the one you get from cl_showpos 1
54+
LastAlivePosition r3.Vector // The location where the player was last alive. Should be equal to Position if the player is still alive.
55+
Velocity r3.Vector // Movement velocity
56+
EntityID int // The ID of the player-entity, see Entity field
57+
UserID int // Mostly used in game-events to address this player
58+
Name string // Steam / in-game user name
5959
Hp int
6060
Armor int
6161
Money int
6262
CurrentEquipmentValue int
6363
FreezetimeEndEquipmentValue int
6464
RoundStartEquipmentValue int
65-
ActiveWeaponID int
66-
RawWeapons map[int]*Equipment
67-
AmmoLeft [32]int
65+
ActiveWeaponID int // Used internally to set the active weapon, see ActiveWeapon()
66+
RawWeapons map[int]*Equipment // All weapons the player is currently carrying
67+
AmmoLeft [32]int // Ammo left in the various weapons, index corresponds to key of RawWeapons
6868
Entity *st.Entity
69-
AdditionalPlayerInformation *AdditionalPlayerInformation
69+
AdditionalPlayerInformation *AdditionalPlayerInformation // Mostly scoreboard information such as kills, deaths, etc.
7070
ViewDirectionX float32
7171
ViewDirectionY float32
72-
FlashDuration float32
72+
FlashDuration float32 // How long this player is flashed for from now on
7373
Team Team
7474
IsBot bool
7575
IsDucking bool
76-
IsDisconnected bool
7776
HasDefuseKit bool
7877
HasHelmet bool
79-
Connected bool
8078
}
8179

8280
// IsAlive returns true if the Hp of the player are > 0.
@@ -130,10 +128,10 @@ type Equipment struct {
130128
type GrenadeProjectile struct {
131129
EntityID int
132130
Weapon EquipmentElement
133-
Thrower *Player
134-
Owner *Player
131+
Thrower *Player // Always seems to be the same as Owner, even if the grenade was picked up
132+
Owner *Player // Always seems to be the same as Thrower, even if the grenade was picked up
135133
Position r3.Vector
136-
Trajectory []r3.Vector
134+
Trajectory []r3.Vector // List of all known locations of the grenade up to the current point
137135

138136
// uniqueID is used to distinguish different grenades (which potentially have the same, reused entityID) from each other.
139137
uniqueID int64

game_state.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (gs GameState) Infernos() map[int]*common.Inferno {
6969
}
7070

7171
// Entities returns all currently existing entities.
72+
// (Almost?) everything in the game is an entity, such as weapons, players, fire etc.
7273
func (gs GameState) Entities() map[int]*st.Entity {
7374
return gs.entities
7475
}
@@ -114,14 +115,15 @@ func (ts TeamState) ClanName() string {
114115
}
115116

116117
// Flag returns the team's country flag.
118+
// E.g. DE, FR, etc.
117119
//
118120
// Watch out, in some demos this is upper-case and in some lower-case.
119121
func (ts TeamState) Flag() string {
120122
return ts.flag
121123
}
122124

123125
// Participants provides helper functions on top of the currently connected players.
124-
// E.g. ByUserID(), ByEntityID(), TeamMembers() etc.
126+
// E.g. ByUserID(), ByEntityID(), TeamMembers(), etc.
125127
//
126128
// See GameState.Participants()
127129
type Participants struct {

parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ func (p *Parser) ServerClasses() st.ServerClasses {
9090
}
9191

9292
// Header returns the DemoHeader which contains the demo's metadata.
93+
// Only possible after ParserHeader() has been called.
9394
func (p *Parser) Header() common.DemoHeader {
9495
return *p.header
9596
}
9697

9798
// GameState returns the current game-state.
99+
// It contains most of the relevant information about the game such as players, teams, scores, grenades etc.
98100
func (p *Parser) GameState() *GameState {
99101
return &p.gameState
100102
}

0 commit comments

Comments
 (0)