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

View File

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

View File

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