mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-21 23:10:06 +00:00
switched NPC autoincremented ID to atomic int
This commit is contained in:
parent
c4325475ed
commit
3559d9ba9b
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user