@@ -438,6 +438,17 @@ func (e *Entity) readFields(r *reader, paths *[]*fieldPath) {
438438 }
439439}
440440
441+ // updateFlag is a bitmask representing the type of operation performed on an Entity
442+ type updateFlag = uint32
443+
444+ const (
445+ updateFlagCreate updateFlag = 0b10
446+ updateFlagLeave updateFlag = 0b01
447+ updateFlagDelete updateFlag = 0b10
448+ updateFlagPreserveEnt updateFlag = 0b01000
449+ updateFlagVisibleInPVS updateFlag = 0b10000
450+ )
451+
441452// Internal Callback for OnCSVCMsg_PacketEntities.
442453func (p * Parser ) OnPacketEntities (m * msgs2.CSVCMsg_PacketEntities ) error {
443454 r := newReader (m .GetEntityData ())
@@ -467,6 +478,7 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
467478 paths = make ([]* fieldPath , 0 )
468479 )
469480
481+ isPvsPacket := m .GetHasPvsVisBits () != 0
470482 for ; updates > 0 ; updates -- {
471483 var (
472484 e * Entity
@@ -477,14 +489,12 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
477489 index = next
478490
479491 cmd = r .readBits (2 )
480- if cmd == 0 && m . GetHasPvsVisBits () > 0 {
492+ if cmd == 0 && isPvsPacket {
481493 cmd = r .readBits (2 ) << 3
482- if cmd & 0x08 == 8 {
483- continue
484- }
485494 }
486- if cmd & 0x01 == 0 {
487- if cmd & 0x02 != 0 {
495+
496+ if cmd & updateFlagLeave == 0 {
497+ if cmd & updateFlagCreate != 0 {
488498 classId = int32 (r .readBits (p .classIdSize ))
489499 serial = int32 (r .readBits (17 ))
490500 r .readVarUint32 ()
@@ -519,7 +529,11 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
519529 }
520530
521531 op = st .EntityOpCreated | st .EntityOpEntered
522- } else {
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
523537 if e = p .entities [index ]; e == nil {
524538 _panicf ("unable to find existing entity %d" , index )
525539 }
@@ -532,6 +546,8 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
532546
533547 e .readFields (r , & paths )
534548 paths = paths [:0 ]
549+ // todo: handle visibility
550+ // visibleInPVS := !isPvsPacket || cmd&updateFlagVisibleInPVS != 0
535551 }
536552 } else {
537553 e = p .entities [index ]
@@ -545,7 +561,7 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
545561 }
546562
547563 op = st .EntityOpLeft
548- if cmd & 0x02 != 0 {
564+ if cmd & updateFlagDelete != 0 {
549565 op |= st .EntityOpDeleted
550566
551567 e .Destroy ()
0 commit comments