feat sn 改成 int64

This commit is contained in:
2026-01-30 11:56:11 +08:00
parent 2f2bcf64a9
commit b87858fbf1
5 changed files with 24 additions and 24 deletions

2
go.mod
View File

@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-scene
go 1.24.0 go 1.24.0
require ( 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 github.com/judwhite/go-svc v1.2.1
go.uber.org/zap v1.27.0 go.uber.org/zap v1.27.0
google.golang.org/grpc v1.77.0 google.golang.org/grpc v1.77.0

4
go.sum
View File

@@ -1,7 +1,7 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= 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-20260130035320-5dc5391b07ed h1:O08p0egfekFqQSnc4sfEJUTI5dGiEyiDRNW/VYa/Ce4=
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/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE= github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=

View File

@@ -20,25 +20,25 @@ import (
// Instance 场景类 // Instance 场景类
type Instance struct { type Instance struct {
wg sync.WaitGroup wg sync.WaitGroup
players map[string]*npc.PlayerNode // 存储所有玩家节点 [usn] players map[int64]*npc.PlayerNode // 存储所有玩家节点 [usn]
ctx context.Context // 停止指令 ctx context.Context // 停止指令
cancel context.CancelFunc // 停止函数 cancel context.CancelFunc // 停止函数
logger *zap.SugaredLogger // 日志 logger *zap.SugaredLogger // 日志
lastLogicTime int64 // 上次逻辑帧执行时间(毫秒时间戳) lastLogicTime int64 // 上次逻辑帧执行时间(毫秒时间戳)
SID string // 服务ID SID int64 // 服务ID
InstanceID int32 // 副本ID InstanceID int32 // 副本ID
UniqueNo string // 唯一编号 UniqueNo int64 // 唯一编号
EventIn chan proto.Message // 消息入口 EventIn chan proto.Message // 消息入口
} }
// NewScene 初始化场景 // NewScene 初始化场景
func NewScene(sid string, instanceID int32) *Instance { func NewScene(sid int64, instanceID int32) *Instance {
s := &Instance{ s := &Instance{
players: make(map[string]*npc.PlayerNode), players: make(map[int64]*npc.PlayerNode),
SID: sid, SID: sid,
InstanceID: instanceID, InstanceID: instanceID,
UniqueNo: utils.SnowflakeInstance().Generate().String(), UniqueNo: utils.SnowflakeInstance().Generate().Int64(),
EventIn: make(chan proto.Message, 1024), EventIn: make(chan proto.Message, 1024),
} }
s.logger = log.GetLogger().Named(fmt.Sprintf("instance %v:%v", s.InstanceID, s.UniqueNo)) 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) { func (i *Instance) onLogic(delta int64) {
positionUpdate := make([]*ss_pb.PositionInfo, 0) positionUpdate := make([]*ss_pb.PositionInfo, 0)
sid := "" sid := int64(0)
// 处理玩家指令 // 处理玩家指令
for _, node := range i.players { for _, node := range i.players {
if node.LogicAction(delta) { if node.LogicAction(delta) {
@@ -121,7 +121,7 @@ func (i *Instance) onLogic(delta int64) {
Info: positionUpdate, Info: positionUpdate,
}) })
if err := grpc_client.SendMessageToGateway(sid, grpc_client.FunToClient, &grpc_pb.ToClientReq{ if err := grpc_client.SendMessageToGateway(sid, grpc_client.FunToClient, &grpc_pb.ToClientReq{
USN: "", USN: -1,
MessageID: int32(ss_pb.MessageID_MESSAGE_ID_POSITION), MessageID: int32(ss_pb.MessageID_MESSAGE_ID_POSITION),
Payload: payload, Payload: payload,
}); err != nil { }); err != nil {

View File

@@ -8,34 +8,34 @@ var Mgr *insManager
type insManager struct { type insManager struct {
sync.RWMutex sync.RWMutex
insMap map[string]*Instance // [uniqueNo] insMap map[int64]*Instance // [uniqueNo]
} }
func init() { func init() {
Mgr = &insManager{ 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() m.Lock()
defer m.Unlock() defer m.Unlock()
m.insMap[uniqueNo] = ins m.insMap[uniqueNo] = ins
} }
func (m *insManager) Delete(uniqueNo string) { func (m *insManager) Delete(uniqueNo int64) {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
delete(m.insMap, uniqueNo) delete(m.insMap, uniqueNo)
} }
func (m *insManager) GetAll() map[string]*Instance { func (m *insManager) GetAll() map[int64]*Instance {
m.RLock() m.RLock()
defer m.RUnlock() defer m.RUnlock()
return m.insMap return m.insMap
} }
func (m *insManager) GetByUniqueNo(uniqueNo string) *Instance { func (m *insManager) GetByUniqueNo(uniqueNo int64) *Instance {
m.RLock() m.RLock()
defer m.RUnlock() defer m.RUnlock()
return m.insMap[uniqueNo] return m.insMap[uniqueNo]

View File

@@ -7,8 +7,8 @@ import (
// PlayerNode 定义玩家节点结构体 // PlayerNode 定义玩家节点结构体
type PlayerNode struct { type PlayerNode struct {
USN string // 用户ID USN int64 // 用户ID
GatewaySID string // 网关服务ID GatewaySID int64 // 网关服务ID
MoveSpeed float32 // 移动速度 MoveSpeed float32 // 移动速度
Position [2]float32 // 二维坐标 [x, y] Position [2]float32 // 二维坐标 [x, y]
@@ -17,7 +17,7 @@ type PlayerNode struct {
Action []*grpc_pb.ActionReq // 其他操作 Action []*grpc_pb.ActionReq // 其他操作
} }
func NewPlayerNode(gatewaySID string, usn string) *PlayerNode { func NewPlayerNode(gatewaySID int64, usn int64) *PlayerNode {
return &PlayerNode{ return &PlayerNode{
USN: usn, USN: usn,
GatewaySID: gatewaySID, GatewaySID: gatewaySID,