Skip to content

Commit a3164c5

Browse files
committed
Participants: document that returned slices are snapshots (fixes #100)
1 parent f25b28f commit a3164c5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

game_state.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ type Participants struct {
143143
}
144144

145145
// ByUserID returns all currently connected players in a map where the key is the user-ID.
146-
// The map is a snapshot and is not updated (not a reference to the actual, underlying map).
146+
// The returned map is a snapshot and is not updated on changes (not a reference to the actual, underlying map).
147147
// Includes spectators.
148148
func (ptcp Participants) ByUserID() map[int]*common.Player {
149149
res := make(map[int]*common.Player)
@@ -154,7 +154,7 @@ func (ptcp Participants) ByUserID() map[int]*common.Player {
154154
}
155155

156156
// ByEntityID returns all currently connected players in a map where the key is the entity-ID.
157-
// The map is a snapshot and is not updated (not a reference to the actual, underlying map).
157+
// The returned map is a snapshot and is not updated on changes (not a reference to the actual, underlying map).
158158
// Includes spectators.
159159
func (ptcp Participants) ByEntityID() map[int]*common.Player {
160160
res := make(map[int]*common.Player)
@@ -165,6 +165,7 @@ func (ptcp Participants) ByEntityID() map[int]*common.Player {
165165
}
166166

167167
// All returns all currently connected players & spectators.
168+
// The returned slice is a snapshot and is not updated on changes.
168169
func (ptcp Participants) All() []*common.Player {
169170
res := make([]*common.Player, 0, len(ptcp.playersByUserID))
170171
for _, p := range ptcp.playersByUserID {
@@ -174,6 +175,7 @@ func (ptcp Participants) All() []*common.Player {
174175
}
175176

176177
// Playing returns all players that aren't spectating or unassigned.
178+
// The returned slice is a snapshot and is not updated on changes.
177179
func (ptcp Participants) Playing() []*common.Player {
178180
res := make([]*common.Player, 0, len(ptcp.playersByUserID))
179181
for _, p := range ptcp.playersByUserID {
@@ -185,6 +187,7 @@ func (ptcp Participants) Playing() []*common.Player {
185187
}
186188

187189
// TeamMembers returns all players belonging to the requested team at this time.
190+
// The returned slice is a snapshot and is not updated on changes.
188191
func (ptcp Participants) TeamMembers(team common.Team) []*common.Player {
189192
res := make([]*common.Player, 0, len(ptcp.playersByUserID))
190193
for _, ptcp := range ptcp.playersByUserID {

participants_interface.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@ import (
1313
// See GameState.Participants()
1414
type IParticipants interface {
1515
// ByUserID returns all currently connected players in a map where the key is the user-ID.
16-
// The map is a snapshot and is not updated (not a reference to the actual, underlying map).
16+
// The returned map is a snapshot and is not updated on changes (not a reference to the actual, underlying map).
1717
// Includes spectators.
1818
ByUserID() map[int]*common.Player
1919
// ByEntityID returns all currently connected players in a map where the key is the entity-ID.
20-
// The map is a snapshot and is not updated (not a reference to the actual, underlying map).
20+
// The returned map is a snapshot and is not updated on changes (not a reference to the actual, underlying map).
2121
// Includes spectators.
2222
ByEntityID() map[int]*common.Player
2323
// All returns all currently connected players & spectators.
24+
// The returned slice is a snapshot and is not updated on changes.
2425
All() []*common.Player
2526
// Playing returns all players that aren't spectating or unassigned.
27+
// The returned slice is a snapshot and is not updated on changes.
2628
Playing() []*common.Player
2729
// TeamMembers returns all players belonging to the requested team at this time.
30+
// The returned slice is a snapshot and is not updated on changes.
2831
TeamMembers(team common.Team) []*common.Player
2932
// FindByHandle attempts to find a player by his entity-handle.
3033
// The entity-handle is often used in entity-properties when referencing other entities such as a weapon's owner.

0 commit comments

Comments
 (0)