From e6b3222b6f58e0f59369a283b093790f27c21672 Mon Sep 17 00:00:00 2001 From: Markus Walther Date: Wed, 4 Sep 2024 16:57:31 +0100 Subject: [PATCH] remove deprecated Player.PreviousFramePosition due to performance concerns --- pkg/demoinfocs/common/player.go | 64 +++++++++------------------- pkg/demoinfocs/common/player_test.go | 23 ---------- pkg/demoinfocs/parsing.go | 4 -- pkg/demoinfocs/s2_commands.go | 6 --- 4 files changed, 19 insertions(+), 78 deletions(-) diff --git a/pkg/demoinfocs/common/player.go b/pkg/demoinfocs/common/player.go index e80aa8fd..dda05736 100644 --- a/pkg/demoinfocs/common/player.go +++ b/pkg/demoinfocs/common/player.go @@ -15,24 +15,23 @@ import ( type Player struct { demoInfoProvider demoInfoProvider // provider for demo info such as tick-rate or current tick - SteamID64 uint64 // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID - UserID int // Mostly used in game-events to address this player - Name string // Steam / in-game user name - Inventory map[int]*Equipment // All weapons / equipment the player is currently carrying. See also Weapons(). - AmmoLeft [32]int // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType - EntityID int // Usually the same as Entity.ID() but may be different between player death and re-spawn. - Entity st.Entity // May be nil between player-death and re-spawn - FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds) - FlashTick int // In-game tick at which the player was last flashed - TeamState *TeamState // When keeping the reference make sure you notice when the player changes teams - Team Team // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists). - IsBot bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot(). - IsConnected bool - IsDefusing bool - IsPlanting bool - IsReloading bool - IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162 - PreviousFramePosition r3.Vector // Deprecated: may be removed in v5 due to performance concerns, track this yourself. + SteamID64 uint64 // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID + UserID int // Mostly used in game-events to address this player + Name string // Steam / in-game user name + Inventory map[int]*Equipment // All weapons / equipment the player is currently carrying. See also Weapons(). + AmmoLeft [32]int // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType + EntityID int // Usually the same as Entity.ID() but may be different between player death and re-spawn. + Entity st.Entity // May be nil between player-death and re-spawn + FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds) + FlashTick int // In-game tick at which the player was last flashed + TeamState *TeamState // When keeping the reference make sure you notice when the player changes teams + Team Team // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists). + IsBot bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot(). + IsConnected bool + IsDefusing bool + IsPlanting bool + IsReloading bool + IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162 } func (p *Player) PlayerPawnEntity() st.Entity { @@ -535,30 +534,6 @@ func (p *Player) PositionEyes() r3.Vector { return pos } -// Velocity returns the player's velocity. -func (p *Player) Velocity() r3.Vector { - if p.demoInfoProvider.IsSource2() { - t := 64.0 - diff := p.Position().Sub(p.PreviousFramePosition) - - return r3.Vector{ - X: diff.X * t, - Y: diff.Y * t, - Z: diff.Z * t, - } - } - - if p.Entity == nil { - return r3.Vector{} - } - - return r3.Vector{ - X: float64(p.Entity.PropertyValueMust("localdata.m_vecVelocity[0]").FloatVal), - Y: float64(p.Entity.PropertyValueMust("localdata.m_vecVelocity[1]").FloatVal), - Z: float64(p.Entity.PropertyValueMust("localdata.m_vecVelocity[2]").FloatVal), - } -} - // see https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188 const ( flOnGround = 1 << iota @@ -825,9 +800,8 @@ type demoInfoProvider interface { // Intended for internal use only. func NewPlayer(demoInfoProvider demoInfoProvider) *Player { return &Player{ - Inventory: make(map[int]*Equipment), - demoInfoProvider: demoInfoProvider, - PreviousFramePosition: r3.Vector{}, + Inventory: make(map[int]*Equipment), + demoInfoProvider: demoInfoProvider, } } diff --git a/pkg/demoinfocs/common/player_test.go b/pkg/demoinfocs/common/player_test.go index a1cf379f..320ebc8e 100644 --- a/pkg/demoinfocs/common/player_test.go +++ b/pkg/demoinfocs/common/player_test.go @@ -476,29 +476,6 @@ func createPlayerForVelocityTest() *Player { return pl } -func TestPlayer_VelocityS2(t *testing.T) { - pl := createPlayerForVelocityTest() - pl.PreviousFramePosition = r3.Vector{X: 10, Y: 200, Z: 50} - - expected := r3.Vector{X: 640, Y: 6400, Z: 3200} - assert.Equal(t, expected, pl.Velocity()) -} - -func TestPlayer_VelocityDidNotChangeS2(t *testing.T) { - pl := createPlayerForVelocityTest() - pl.PreviousFramePosition = r3.Vector{X: 20, Y: 300, Z: 100} - - expected := r3.Vector{X: 0, Y: 0, Z: 0} - assert.Equal(t, expected, pl.Velocity()) -} - -func TestPlayer_Velocity_EntityNil(t *testing.T) { - pl := new(Player) - pl.demoInfoProvider = s1DemoInfoProvider - - assert.Empty(t, pl.Velocity()) -} - func TestPlayer_ClanTag(t *testing.T) { pl := playerWithResourceProperty("m_szClan", st.PropertyValue{Any: "SuperClan"}) pl.demoInfoProvider = demoInfoProviderMock{ diff --git a/pkg/demoinfocs/parsing.go b/pkg/demoinfocs/parsing.go index 0c19d5af..410db325 100644 --- a/pkg/demoinfocs/parsing.go +++ b/pkg/demoinfocs/parsing.go @@ -537,10 +537,6 @@ func (p *parser) handleFrameParsed(*frameParsedTokenType) { p.currentFrame++ p.eventDispatcher.Dispatch(events.FrameDone{}) - - if p.isSource2() { - p.updatePlayersPreviousFramePosition() - } } // CS2 demos playback info are available in the CDemoFileInfo message that should be parsed at the end of the demo. diff --git a/pkg/demoinfocs/s2_commands.go b/pkg/demoinfocs/s2_commands.go index 7988f52e..a70c79c5 100644 --- a/pkg/demoinfocs/s2_commands.go +++ b/pkg/demoinfocs/s2_commands.go @@ -383,9 +383,3 @@ func (p *parser) handleDemoFileHeader(msg *msgs2.CDemoFileHeader) { p.header.MapName = msg.GetMapName() p.header.NetworkProtocol = int(msg.GetNetworkProtocol()) } - -func (p *parser) updatePlayersPreviousFramePosition() { - for _, player := range p.GameState().Participants().Playing() { - player.PreviousFramePosition = player.Position() - } -}