feat sn 改成 int64
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-scene
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed
|
||||
github.com/judwhite/go-svc v1.2.1
|
||||
go.uber.org/zap v1.27.0
|
||||
google.golang.org/grpc v1.77.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f h1:U0HnB8i3ZTKrg3XBQpwFcI64LB6mraj02yNAqV3MBws=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed h1:O08p0egfekFqQSnc4sfEJUTI5dGiEyiDRNW/VYa/Ce4=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
|
||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
||||
|
||||
@@ -20,25 +20,25 @@ import (
|
||||
// Instance 场景类
|
||||
type Instance struct {
|
||||
wg sync.WaitGroup
|
||||
players map[string]*npc.PlayerNode // 存储所有玩家节点 [usn]
|
||||
players map[int64]*npc.PlayerNode // 存储所有玩家节点 [usn]
|
||||
ctx context.Context // 停止指令
|
||||
cancel context.CancelFunc // 停止函数
|
||||
logger *zap.SugaredLogger // 日志
|
||||
lastLogicTime int64 // 上次逻辑帧执行时间(毫秒时间戳)
|
||||
|
||||
SID string // 服务ID
|
||||
SID int64 // 服务ID
|
||||
InstanceID int32 // 副本ID
|
||||
UniqueNo string // 唯一编号
|
||||
UniqueNo int64 // 唯一编号
|
||||
EventIn chan proto.Message // 消息入口
|
||||
}
|
||||
|
||||
// NewScene 初始化场景
|
||||
func NewScene(sid string, instanceID int32) *Instance {
|
||||
func NewScene(sid int64, instanceID int32) *Instance {
|
||||
s := &Instance{
|
||||
players: make(map[string]*npc.PlayerNode),
|
||||
players: make(map[int64]*npc.PlayerNode),
|
||||
SID: sid,
|
||||
InstanceID: instanceID,
|
||||
UniqueNo: utils.SnowflakeInstance().Generate().String(),
|
||||
UniqueNo: utils.SnowflakeInstance().Generate().Int64(),
|
||||
EventIn: make(chan proto.Message, 1024),
|
||||
}
|
||||
s.logger = log.GetLogger().Named(fmt.Sprintf("instance %v:%v", s.InstanceID, s.UniqueNo))
|
||||
@@ -104,7 +104,7 @@ func (i *Instance) onEvent(e proto.Message) {
|
||||
// 逻辑帧
|
||||
func (i *Instance) onLogic(delta int64) {
|
||||
positionUpdate := make([]*ss_pb.PositionInfo, 0)
|
||||
sid := ""
|
||||
sid := int64(0)
|
||||
// 处理玩家指令
|
||||
for _, node := range i.players {
|
||||
if node.LogicAction(delta) {
|
||||
@@ -121,7 +121,7 @@ func (i *Instance) onLogic(delta int64) {
|
||||
Info: positionUpdate,
|
||||
})
|
||||
if err := grpc_client.SendMessageToGateway(sid, grpc_client.FunToClient, &grpc_pb.ToClientReq{
|
||||
USN: "",
|
||||
USN: -1,
|
||||
MessageID: int32(ss_pb.MessageID_MESSAGE_ID_POSITION),
|
||||
Payload: payload,
|
||||
}); err != nil {
|
||||
|
||||
@@ -8,34 +8,34 @@ var Mgr *insManager
|
||||
|
||||
type insManager struct {
|
||||
sync.RWMutex
|
||||
insMap map[string]*Instance // [uniqueNo]
|
||||
insMap map[int64]*Instance // [uniqueNo]
|
||||
}
|
||||
|
||||
func init() {
|
||||
Mgr = &insManager{
|
||||
insMap: make(map[string]*Instance),
|
||||
insMap: make(map[int64]*Instance),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *insManager) Add(uniqueNo string, ins *Instance) {
|
||||
func (m *insManager) Add(uniqueNo int64, ins *Instance) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
m.insMap[uniqueNo] = ins
|
||||
}
|
||||
|
||||
func (m *insManager) Delete(uniqueNo string) {
|
||||
func (m *insManager) Delete(uniqueNo int64) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
delete(m.insMap, uniqueNo)
|
||||
}
|
||||
|
||||
func (m *insManager) GetAll() map[string]*Instance {
|
||||
func (m *insManager) GetAll() map[int64]*Instance {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
return m.insMap
|
||||
}
|
||||
|
||||
func (m *insManager) GetByUniqueNo(uniqueNo string) *Instance {
|
||||
func (m *insManager) GetByUniqueNo(uniqueNo int64) *Instance {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
return m.insMap[uniqueNo]
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
// PlayerNode 定义玩家节点结构体
|
||||
type PlayerNode struct {
|
||||
USN string // 用户ID
|
||||
GatewaySID string // 网关服务ID
|
||||
USN int64 // 用户ID
|
||||
GatewaySID int64 // 网关服务ID
|
||||
MoveSpeed float32 // 移动速度
|
||||
|
||||
Position [2]float32 // 二维坐标 [x, y]
|
||||
@@ -17,7 +17,7 @@ type PlayerNode struct {
|
||||
Action []*grpc_pb.ActionReq // 其他操作
|
||||
}
|
||||
|
||||
func NewPlayerNode(gatewaySID string, usn string) *PlayerNode {
|
||||
func NewPlayerNode(gatewaySID int64, usn int64) *PlayerNode {
|
||||
return &PlayerNode{
|
||||
USN: usn,
|
||||
GatewaySID: gatewaySID,
|
||||
|
||||
Reference in New Issue
Block a user