Skip to content

Commit e6b3222

Browse files
committed
remove deprecated Player.PreviousFramePosition due to performance concerns
1 parent 12b4d70 commit e6b3222

File tree

4 files changed

+19
-78
lines changed

4 files changed

+19
-78
lines changed

pkg/demoinfocs/common/player.go

+19-45
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@ import (
1515
type Player struct {
1616
demoInfoProvider demoInfoProvider // provider for demo info such as tick-rate or current tick
1717

18-
SteamID64 uint64 // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID
19-
UserID int // Mostly used in game-events to address this player
20-
Name string // Steam / in-game user name
21-
Inventory map[int]*Equipment // All weapons / equipment the player is currently carrying. See also Weapons().
22-
AmmoLeft [32]int // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType
23-
EntityID int // Usually the same as Entity.ID() but may be different between player death and re-spawn.
24-
Entity st.Entity // May be nil between player-death and re-spawn
25-
FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds)
26-
FlashTick int // In-game tick at which the player was last flashed
27-
TeamState *TeamState // When keeping the reference make sure you notice when the player changes teams
28-
Team Team // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists).
29-
IsBot bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot().
30-
IsConnected bool
31-
IsDefusing bool
32-
IsPlanting bool
33-
IsReloading bool
34-
IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162
35-
PreviousFramePosition r3.Vector // Deprecated: may be removed in v5 due to performance concerns, track this yourself.
18+
SteamID64 uint64 // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID
19+
UserID int // Mostly used in game-events to address this player
20+
Name string // Steam / in-game user name
21+
Inventory map[int]*Equipment // All weapons / equipment the player is currently carrying. See also Weapons().
22+
AmmoLeft [32]int // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType
23+
EntityID int // Usually the same as Entity.ID() but may be different between player death and re-spawn.
24+
Entity st.Entity // May be nil between player-death and re-spawn
25+
FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds)
26+
FlashTick int // In-game tick at which the player was last flashed
27+
TeamState *TeamState // When keeping the reference make sure you notice when the player changes teams
28+
Team Team // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists).
29+
IsBot bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot().
30+
IsConnected bool
31+
IsDefusing bool
32+
IsPlanting bool
33+
IsReloading bool
34+
IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162
3635
}
3736

3837
func (p *Player) PlayerPawnEntity() st.Entity {
@@ -535,30 +534,6 @@ func (p *Player) PositionEyes() r3.Vector {
535534
return pos
536535
}
537536

538-
// Velocity returns the player's velocity.
539-
func (p *Player) Velocity() r3.Vector {
540-
if p.demoInfoProvider.IsSource2() {
541-
t := 64.0
542-
diff := p.Position().Sub(p.PreviousFramePosition)
543-
544-
return r3.Vector{
545-
X: diff.X * t,
546-
Y: diff.Y * t,
547-
Z: diff.Z * t,
548-
}
549-
}
550-
551-
if p.Entity == nil {
552-
return r3.Vector{}
553-
}
554-
555-
return r3.Vector{
556-
X: float64(p.Entity.PropertyValueMust("localdata.m_vecVelocity[0]").FloatVal),
557-
Y: float64(p.Entity.PropertyValueMust("localdata.m_vecVelocity[1]").FloatVal),
558-
Z: float64(p.Entity.PropertyValueMust("localdata.m_vecVelocity[2]").FloatVal),
559-
}
560-
}
561-
562537
// see https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
563538
const (
564539
flOnGround = 1 << iota
@@ -825,9 +800,8 @@ type demoInfoProvider interface {
825800
// Intended for internal use only.
826801
func NewPlayer(demoInfoProvider demoInfoProvider) *Player {
827802
return &Player{
828-
Inventory: make(map[int]*Equipment),
829-
demoInfoProvider: demoInfoProvider,
830-
PreviousFramePosition: r3.Vector{},
803+
Inventory: make(map[int]*Equipment),
804+
demoInfoProvider: demoInfoProvider,
831805
}
832806
}
833807

pkg/demoinfocs/common/player_test.go

-23
Original file line numberDiff line numberDiff line change
@@ -476,29 +476,6 @@ func createPlayerForVelocityTest() *Player {
476476
return pl
477477
}
478478

479-
func TestPlayer_VelocityS2(t *testing.T) {
480-
pl := createPlayerForVelocityTest()
481-
pl.PreviousFramePosition = r3.Vector{X: 10, Y: 200, Z: 50}
482-
483-
expected := r3.Vector{X: 640, Y: 6400, Z: 3200}
484-
assert.Equal(t, expected, pl.Velocity())
485-
}
486-
487-
func TestPlayer_VelocityDidNotChangeS2(t *testing.T) {
488-
pl := createPlayerForVelocityTest()
489-
pl.PreviousFramePosition = r3.Vector{X: 20, Y: 300, Z: 100}
490-
491-
expected := r3.Vector{X: 0, Y: 0, Z: 0}
492-
assert.Equal(t, expected, pl.Velocity())
493-
}
494-
495-
func TestPlayer_Velocity_EntityNil(t *testing.T) {
496-
pl := new(Player)
497-
pl.demoInfoProvider = s1DemoInfoProvider
498-
499-
assert.Empty(t, pl.Velocity())
500-
}
501-
502479
func TestPlayer_ClanTag(t *testing.T) {
503480
pl := playerWithResourceProperty("m_szClan", st.PropertyValue{Any: "SuperClan"})
504481
pl.demoInfoProvider = demoInfoProviderMock{

pkg/demoinfocs/parsing.go

-4
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,6 @@ func (p *parser) handleFrameParsed(*frameParsedTokenType) {
537537

538538
p.currentFrame++
539539
p.eventDispatcher.Dispatch(events.FrameDone{})
540-
541-
if p.isSource2() {
542-
p.updatePlayersPreviousFramePosition()
543-
}
544540
}
545541

546542
// CS2 demos playback info are available in the CDemoFileInfo message that should be parsed at the end of the demo.

pkg/demoinfocs/s2_commands.go

-6
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,3 @@ func (p *parser) handleDemoFileHeader(msg *msgs2.CDemoFileHeader) {
383383
p.header.MapName = msg.GetMapName()
384384
p.header.NetworkProtocol = int(msg.GetNetworkProtocol())
385385
}
386-
387-
func (p *parser) updatePlayersPreviousFramePosition() {
388-
for _, player := range p.GameState().Participants().Playing() {
389-
player.PreviousFramePosition = player.Position()
390-
}
391-
}

0 commit comments

Comments
 (0)