switched NPC autoincremented ID to atomic int

This commit is contained in:
unknown 2023-06-27 20:06:51 -05:00
parent c4325475ed
commit 3559d9ba9b
3 changed files with 9 additions and 6 deletions

View File

@ -1,6 +1,10 @@
package entity
import "github.com/CPunch/gopenfusion/core/protocol"
import (
"sync/atomic"
"github.com/CPunch/gopenfusion/core/protocol"
)
type NPC struct {
ID int
@ -12,12 +16,11 @@ type NPC struct {
Chunk ChunkPosition
}
var nextNPCID = 0
var nextNPCID = &atomic.Int32{}
func NewNPC(X, Y, Z, Angle int, npcType int) *NPC {
nextNPCID++
return &NPC{
ID: nextNPCID,
ID: int(nextNPCID.Add(1)),
X: X,
Y: Y,
Z: Z,

View File

@ -105,7 +105,7 @@ func (server *LoginServer) handlePacket(peer *protocol.CNPeer, typeID uint32, pk
return err
}
} else {
log.Printf("[WARN] invalid packet ID: %x\n", typeID)
log.Printf("[WARN] unknown packet ID: %x\n", typeID)
}
return nil

View File

@ -108,7 +108,7 @@ func (server *ShardServer) handlePacket(peer *protocol.CNPeer, typeID uint32, pk
return err
}
} else {
log.Printf("[WARN] invalid packet ID: %x\n", typeID)
log.Printf("[WARN] unknown packet ID: %x\n", typeID)
}
return nil