@@ -167,66 +167,51 @@ func (e *Entity) ApplyUpdate(reader *bit.BitReader) {
167167const (
168168 serverClassPlayer = "CCSPlayerPawn"
169169
170- maxCoordInt = 16384
171-
172- propCellBits = "m_cellbits"
173- propCellX = "CBodyComponent.m_cellX"
174- propCellY = "CBodyComponent.m_cellY"
175- propCellZ = "CBodyComponent.m_cellZ"
176- propVecOrigin = "m_vecOrigin"
177- propVecOriginPlayerXY = "cslocaldata.m_vecOrigin"
178- propVecOriginPlayerZ = "cslocaldata.m_vecOrigin[2]"
170+ propCellX = "CBodyComponent.m_cellX"
171+ propCellY = "CBodyComponent.m_cellY"
172+ propCellZ = "CBodyComponent.m_cellZ"
173+ propVecX = "CBodyComponent.m_vecX"
174+ propVecY = "CBodyComponent.m_vecY"
175+ propVecZ = "CBodyComponent.m_vecZ"
179176)
180177
181178func (e * Entity ) isPlayer () bool {
182179 return e .class .name == serverClassPlayer
183180}
184181
185182// Returns a coordinate from a cell + offset
186- func coordFromCell (cell , cellWidth int , offset float64 ) float64 {
187- return float64 (cell * cellWidth - maxCoordInt ) + offset
183+ func coordFromCell (cell uint64 , offset float32 ) float64 {
184+ const (
185+ cellBits = 9
186+ maxCoordInt = 16384
187+ )
188+
189+ return float64 (cell * (1 << cellBits )- maxCoordInt ) + float64 (offset )
188190}
189191
190192func (e * Entity ) Position () r3.Vector {
191- return r3.Vector {} // FIXME: implement
192-
193- if e .isPlayer () {
194- // FIXME: POV demo support
195- xyProp := e .Property (propVecOriginPlayerXY )
196- zProp := e .Property (propVecOriginPlayerZ )
197-
198- xy := xyProp .Value ().VectorVal
199- z := float64 (zProp .Value ().FloatVal )
200-
201- return r3.Vector {
202- X : xy .X ,
203- Y : xy .Y ,
204- Z : z ,
205- }
206- }
207-
208- cellBitsProp := e .Property (propCellBits )
209193 cellXProp := e .Property (propCellX )
210194 cellYProp := e .Property (propCellY )
211195 cellZProp := e .Property (propCellZ )
212- offsetProp := e .Property (propVecOrigin )
196+ offsetXProp := e .Property (propVecX )
197+ offsetYProp := e .Property (propVecY )
198+ offsetZProp := e .Property (propVecZ )
213199
214- cellWidth := 1 << uint (cellBitsProp .Value ().IntVal )
215- cellX := cellXProp .Value ().IntVal
216- cellY := cellYProp .Value ().IntVal
217- cellZ := cellZProp .Value ().IntVal
218- offset := offsetProp .Value ().VectorVal
200+ cellX := cellXProp .Value ().S2UInt64 ()
201+ cellY := cellYProp .Value ().S2UInt64 ()
202+ cellZ := cellZProp .Value ().S2UInt64 ()
203+ offsetX := offsetXProp .Value ().Float ()
204+ offsetY := offsetYProp .Value ().Float ()
205+ offsetZ := offsetZProp .Value ().Float ()
219206
220207 return r3.Vector {
221- X : coordFromCell (cellX , cellWidth , offset . X ),
222- Y : coordFromCell (cellY , cellWidth , offset . Y ),
223- Z : coordFromCell (cellZ , cellWidth , offset . Z ),
208+ X : coordFromCell (cellX , offsetX ),
209+ Y : coordFromCell (cellY , offsetY ),
210+ Z : coordFromCell (cellZ , offsetZ ),
224211 }
225212}
226213
227214func (e * Entity ) OnPositionUpdate (h func (pos r3.Vector )) {
228- return // FIXME: implement
229-
230215 pos := new (r3.Vector )
231216 firePosUpdate := func (st.PropertyValue ) {
232217 newPos := e .Position ()
@@ -236,15 +221,12 @@ func (e *Entity) OnPositionUpdate(h func(pos r3.Vector)) {
236221 }
237222 }
238223
239- if e .isPlayer () {
240- e .Property (propVecOriginPlayerXY ).OnUpdate (firePosUpdate ) // FIXME: POV demos use different property names
241- e .Property (propVecOriginPlayerZ ).OnUpdate (firePosUpdate )
242- } else {
243- e .Property (propCellX ).OnUpdate (firePosUpdate )
244- e .Property (propCellY ).OnUpdate (firePosUpdate )
245- e .Property (propCellZ ).OnUpdate (firePosUpdate )
246- e .Property (propVecOrigin ).OnUpdate (firePosUpdate )
247- }
224+ e .Property (propCellX ).OnUpdate (firePosUpdate )
225+ e .Property (propCellY ).OnUpdate (firePosUpdate )
226+ e .Property (propCellZ ).OnUpdate (firePosUpdate )
227+ e .Property (propVecX ).OnUpdate (firePosUpdate )
228+ e .Property (propVecY ).OnUpdate (firePosUpdate )
229+ e .Property (propVecZ ).OnUpdate (firePosUpdate )
248230}
249231
250232func (e * Entity ) OnDestroy (delegate func ()) {
@@ -417,12 +399,14 @@ func (p *Parser) FindEntityByHandle(handle uint64) *Entity {
417399
418400// FilterEntity finds entities by callback
419401func (p * Parser ) FilterEntity (fb func (* Entity ) bool ) []* Entity {
420- entities := make ([]* Entity , 0 , 0 )
402+ entities := make ([]* Entity , 0 )
403+
421404 for _ , et := range p .entities {
422405 if fb (et ) {
423406 entities = append (entities , et )
424407 }
425408 }
409+
426410 return entities
427411}
428412
@@ -435,20 +419,17 @@ func (e *Entity) readFields(r *reader) {
435419 val := decoder (r )
436420 e .state .set (fp , val )
437421
438- upd := e .updateHandlers [e .class .getNameForFieldPath (fp )]
439- if upd != nil {
440- for _ , h := range upd {
441- h (st.PropertyValue {
442- VectorVal : r3.Vector {},
443- IntVal : 0 ,
444- Int64Val : 0 ,
445- ArrayVal : nil ,
446- StringVal : "" ,
447- FloatVal : 0 ,
448- Any : val ,
449- S2 : true ,
450- })
451- }
422+ for _ , h := range e .updateHandlers [e .class .getNameForFieldPath (fp )] {
423+ h (st.PropertyValue {
424+ VectorVal : r3.Vector {},
425+ IntVal : 0 ,
426+ Int64Val : 0 ,
427+ ArrayVal : nil ,
428+ StringVal : "" ,
429+ FloatVal : 0 ,
430+ Any : val ,
431+ S2 : true ,
432+ })
452433 }
453434
454435 fp .release ()
0 commit comments