@@ -438,25 +438,44 @@ func (e *Entity) readFields(r *reader, paths *[]*fieldPath) {
438
438
}
439
439
}
440
440
441
- // updateFlag is a bitmask representing the type of operation performed on an Entity
442
- type updateFlag = uint32
441
+ const (
442
+ updateFlagDelete = 0b10
443
+ updateFlagVisibleInPVS = 0b10000
444
+ )
445
+
446
+ type updateType = uint32
443
447
444
448
const (
445
- updateFlagCreate updateFlag = 0b10
446
- updateFlagLeave updateFlag = 0b01
447
- updateFlagDelete updateFlag = 0b10
448
- updateFlagPreserveEnt updateFlag = 0b01000
449
- updateFlagVisibleInPVS updateFlag = 0b10000
449
+ updateTypeEnter updateType = iota
450
+ updateTypeLeave
451
+ updateTypeDelta
452
+ updateTypePreserve
450
453
)
451
454
455
+ func readEntityUpdateType (r * reader , has_vis_bits uint32 ) (updateType , uint32 ) {
456
+ flags := r .readBits (2 )
457
+ if flags & 0x01 != 0 {
458
+ return updateTypeLeave , flags
459
+ }
460
+ if flags & 0x02 != 0 {
461
+ return updateTypeEnter , flags
462
+ }
463
+ if has_vis_bits != 0 {
464
+ flags = r .readBits (2 ) << 3
465
+ if flags & 0x08 != 0 {
466
+ return updateTypePreserve , flags
467
+ }
468
+ }
469
+ return updateTypeDelta , flags
470
+ }
471
+
452
472
// Internal Callback for OnCSVCMsg_PacketEntities.
453
473
func (p * Parser ) OnPacketEntities (m * msgs2.CSVCMsg_PacketEntities ) error {
454
474
r := newReader (m .GetEntityData ())
455
475
456
476
var (
457
477
index = int32 (- 1 )
458
478
updates = int (m .GetUpdatedEntries ())
459
- cmd uint32
460
479
classId int32
461
480
serial int32
462
481
)
@@ -478,7 +497,7 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
478
497
paths = make ([]* fieldPath , 0 )
479
498
)
480
499
481
- isPvsPacket := m .GetHasPvsVisBits () != 0
500
+ hasVisBits := m .GetHasPvsVisBits ()
482
501
for ; updates > 0 ; updates -- {
483
502
var (
484
503
e * Entity
@@ -488,68 +507,62 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
488
507
next := index + int32 (r .readUBitVar ()) + 1
489
508
index = next
490
509
491
- cmd = r .readBits (2 )
492
- if cmd == 0 && isPvsPacket {
493
- cmd = r .readBits (2 ) << 3
494
- }
495
-
496
- if cmd & updateFlagLeave == 0 {
497
- if cmd & updateFlagCreate != 0 {
498
- classId = int32 (r .readBits (p .classIdSize ))
499
- serial = int32 (r .readBits (17 ))
500
- r .readVarUint32 ()
501
-
502
- class := p .classesById [classId ]
503
- if class == nil {
504
- _panicf ("unable to find new class %d" , classId )
505
- }
510
+ updateType , flags := readEntityUpdateType (r , hasVisBits )
511
+ switch updateType {
512
+ case updateTypeEnter :
513
+ classId = int32 (r .readBits (p .classIdSize ))
514
+ serial = int32 (r .readBits (17 ))
515
+ r .readVarUint32 ()
506
516
507
- baseline := p .classBaselines [classId ]
508
- if baseline == nil {
509
- _panicf ("unable to find new baseline %d" , classId )
510
- }
517
+ class := p .classesById [classId ]
518
+ if class == nil {
519
+ _panicf ("unable to find new class %d" , classId )
520
+ }
511
521
512
- e = newEntity (index , serial , class )
513
- p .entities [index ] = e
522
+ baseline := p .classBaselines [classId ]
523
+ if baseline == nil {
524
+ _panicf ("unable to find new baseline %d" , classId )
525
+ }
514
526
515
- e . readFields ( newReader ( baseline ), & paths )
516
- paths = paths [: 0 ]
527
+ e = newEntity ( index , serial , class )
528
+ p . entities [ index ] = e
517
529
518
- e .readFields (r , & paths )
519
- paths = paths [:0 ]
530
+ e .readFields (newReader ( baseline ) , & paths )
531
+ paths = paths [:0 ]
520
532
521
- // Fire created-handlers so update-handlers can be registered
522
- for _ , h := range class .createdHandlers {
523
- h (e )
524
- }
533
+ e .readFields (r , & paths )
534
+ paths = paths [:0 ]
525
535
526
- // Fire all post-creation actions
527
- for _ , f := range e . onCreateFinished {
528
- f ( )
529
- }
536
+ // Fire created-handlers so update-handlers can be registered
537
+ for _ , h := range class . createdHandlers {
538
+ h ( e )
539
+ }
530
540
531
- op = st .EntityOpCreated | st .EntityOpEntered
532
- } else if cmd & updateFlagPreserveEnt != 0 {
533
- // todo: handle visibility
534
- // visibleInPvs := !isPvsPacket || cmd&updateFlagVisibleInPVS != 0
535
- // fmt.Println("preserve visible in pvs", visibleInPvs)
536
- } else { // delta update
537
- if e = p .entities [index ]; e == nil {
538
- _panicf ("unable to find existing entity %d" , index )
539
- }
541
+ // Fire all post-creation actions
542
+ for _ , f := range e .onCreateFinished {
543
+ f ()
544
+ }
540
545
541
- op = st .EntityOpUpdated
542
- if ! e . active {
543
- e . active = true
544
- op |= st . EntityOpEntered
545
- }
546
+ op = st .EntityOpCreated | st . EntityOpEntered
547
+ case updateTypeDelta :
548
+ if e = p . entities [ index ]; e == nil {
549
+ _panicf ( "unable to find existing entity %d" , index )
550
+ }
546
551
547
- e . readFields ( r , & paths )
548
- paths = paths [: 0 ]
549
- // todo: handle visibility
550
- // visibleInPVS := !isPvsPacket || cmd&updateFlagVisibleInPVS != 0
552
+ op = st . EntityOpUpdated
553
+ if ! e . active {
554
+ e . active = true
555
+ op |= st . EntityOpEntered
551
556
}
552
- } else {
557
+
558
+ e .readFields (r , & paths )
559
+ paths = paths [:0 ]
560
+ // todo: handle visibility
561
+ // visibleInPVS := hasVisBits == 0 || flags&updateFlagVisibleInPVS != 0
562
+ // fmt.Println("visible in pvs", visibleInPVS)
563
+ case updateTypePreserve :
564
+ // visibleInPVS := hasVisBits == 0 || flags&updateFlagVisibleInPVS != 0
565
+ case updateTypeLeave :
553
566
e = p .entities [index ]
554
567
if e == nil {
555
568
continue
@@ -561,7 +574,7 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
561
574
}
562
575
563
576
op = st .EntityOpLeft
564
- if cmd & updateFlagDelete != 0 {
577
+ if flags & updateFlagDelete != 0 {
565
578
op |= st .EntityOpDeleted
566
579
567
580
e .Destroy ()
0 commit comments