@@ -15,11 +15,14 @@ import (
1515type entity struct {
1616 serverClass * ServerClass
1717 id int
18+ serialNum int
1819 props []property
1920
20- onCreateFinished []func ()
21- onDestroy []func ()
22- position func () r3.Vector
21+ onCreateFinished []func ()
22+ onDestroy []func ()
23+ position func () r3.Vector
24+ positionPropNameXY string
25+ positionPropNameZ string
2326}
2427
2528// ServerClass returns the entity's server-class.
@@ -32,6 +35,11 @@ func (e *entity) ID() int {
3235 return e .id
3336}
3437
38+ // SerialNum returns the entity's serial number.
39+ func (e * entity ) SerialNum () int {
40+ return e .serialNum
41+ }
42+
3543// Properties returns all properties of the entity.
3644func (e * entity ) Properties () (out []Property ) {
3745 for i := range e .props {
@@ -189,25 +197,36 @@ func (e *entity) applyBaseline(baseline map[int]PropertyValue) {
189197const (
190198 maxCoordInt = 16384
191199
192- propCellBits = "m_cellbits"
193- propCellX = "m_cellX"
194- propCellY = "m_cellY"
195- propCellZ = "m_cellZ"
196- propVecOrigin = "m_vecOrigin"
197- propVecOriginPlayerXY = "cslocaldata.m_vecOrigin"
198- propVecOriginPlayerZ = "cslocaldata.m_vecOrigin[2]"
200+ propCellBits = "m_cellbits"
201+ propCellX = "m_cellX"
202+ propCellY = "m_cellY"
203+ propCellZ = "m_cellZ"
204+ propVecOrigin = "m_vecOrigin"
205+ propVecOriginPlayerXY = "cslocaldata.m_vecOrigin"
206+ propVecOriginPlayerZ = "cslocaldata.m_vecOrigin[2]"
207+ nonLocalPropVecOriginPlayerXY = "csnonlocaldata.m_vecOrigin"
208+ nonLocalPropVecOriginPlayerZ = "csnonlocaldata.m_vecOrigin[2]"
199209
200210 serverClassPlayer = "CCSPlayer"
201211)
202212
203213// Sets up the entity.Position() function
204214// Necessary because Property() is fairly slow
205215// This way we only need to find the necessary properties once
206- func (e * entity ) initialize () {
216+ func (e * entity ) initialize (recordingPlayerSlot int ) {
207217 // Player positions are calculated differently
208218 if e .isPlayer () {
209- xyProp := e .Property (propVecOriginPlayerXY )
210- zProp := e .Property (propVecOriginPlayerZ )
219+ isGOTV := recordingPlayerSlot == - 1
220+ isRecording := recordingPlayerSlot == e .id - 1
221+ if isGOTV || isRecording {
222+ e .positionPropNameXY = propVecOriginPlayerXY
223+ e .positionPropNameZ = propVecOriginPlayerZ
224+ } else {
225+ e .positionPropNameXY = nonLocalPropVecOriginPlayerXY
226+ e .positionPropNameZ = nonLocalPropVecOriginPlayerZ
227+ }
228+ xyProp := e .Property (e .positionPropNameXY )
229+ zProp := e .Property (e .positionPropNameZ )
211230
212231 e .position = func () r3.Vector {
213232 xy := xyProp .Value ().VectorVal
@@ -266,8 +285,8 @@ func (e *entity) OnPositionUpdate(h func(pos r3.Vector)) {
266285 }
267286
268287 if e .isPlayer () {
269- e .Property (propVecOriginPlayerXY ).OnUpdate (firePosUpdate )
270- e .Property (propVecOriginPlayerZ ).OnUpdate (firePosUpdate )
288+ e .Property (e . positionPropNameXY ).OnUpdate (firePosUpdate )
289+ e .Property (e . positionPropNameZ ).OnUpdate (firePosUpdate )
271290 } else {
272291 e .Property (propCellX ).OnUpdate (firePosUpdate )
273292 e .Property (propCellY ).OnUpdate (firePosUpdate )
@@ -366,6 +385,7 @@ func (pe *property) firePropertyUpdate() {
366385Bind binds a property's value to a pointer.
367386
368387Example:
388+
369389 var i int
370390 property.Bind(&i, ValTypeInt)
371391
0 commit comments