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
|
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,
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user