@@ -2,6 +2,7 @@ package sendtables2
22
33import (
44 "fmt"
5+ "os"
56 "strings"
67
78 "github.com/golang/geo/r3"
@@ -252,6 +253,8 @@ func (e *Entity) OnDestroy(delegate func()) {
252253}
253254
254255func (e * Entity ) Destroy () {
256+ e .active = false
257+
255258 for _ , delegate := range e .onDestroy {
256259 delegate ()
257260 }
@@ -467,6 +470,17 @@ func (e *Entity) readFields(r *reader, paths *[]*fieldPath) {
467470
468471// Internal Callback for OnCSVCMsg_PacketEntities.
469472func (p * Parser ) OnPacketEntities (m * msgs2.CSVCMsg_PacketEntities ) error {
473+ defer func () {
474+ if p .packetEntitiesPanicWarnFunc == nil {
475+ return
476+ }
477+
478+ r := recover ()
479+ if r != nil {
480+ fmt .Fprintf (os .Stderr , "error in OnPacketEntities: %v\n " , r )
481+ }
482+ }()
483+
470484 r := newReader (m .GetEntityData ())
471485
472486 var (
@@ -481,6 +495,7 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
481495 if p .entityFullPackets > 0 {
482496 return nil
483497 }
498+
484499 p .entityFullPackets ++
485500 }
486501
@@ -496,12 +511,7 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
496511 index = next
497512
498513 cmd = r .readBits (2 )
499- if cmd == 0 && m .GetHasPvsVisBits () > 0 {
500- cmd = r .readBits (2 ) << 3
501- if cmd & 0x08 == 8 {
502- continue
503- }
504- }
514+
505515 if cmd & 0x01 == 0 {
506516 if cmd & 0x02 != 0 {
507517 classID = int32 (r .readBits (p .classIdSize ))
@@ -537,7 +547,12 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
537547
538548 op = st .EntityOpCreated | st .EntityOpEntered
539549 } else {
540- if e = p .entities [index ]; e == nil {
550+ if m .GetHasPvsVisBits () > 0 && r .readBits (2 )& 0x01 != 0 {
551+ continue
552+ }
553+
554+ e = p .entities [index ]
555+ if e == nil {
541556 _panicf ("unable to find existing entity %d" , index )
542557 }
543558
@@ -552,21 +567,18 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
552567 } else {
553568 e = p .entities [index ]
554569 if e == nil {
555- continue
556570 _panicf ("unable to find existing entity %d" , index )
557571 }
558572
559573 if ! e .active {
560- _panicf ( "entity %d (%s) ordered to leave, already inactive" , e . class . classId , e . class . name )
574+ continue // entity has already been destroyed
561575 }
562576
563577 op = st .EntityOpLeft
564578 if cmd & 0x02 != 0 {
565579 op |= st .EntityOpDeleted
566580
567581 e .Destroy ()
568-
569- delete (p .entities , index )
570582 }
571583 }
572584
0 commit comments