Files
bl/logic/service/space/space.go
昔念 646eeeaa2b fix(space): 修复地图ID判断逻辑并优化空间初始化流程
移除未使用的地图ID字段,调整GetSpace函数中关于玩家地图的判断条件,
确保能正确加载星球配置并初始化Space实例。同时清理冗余代码,
提升逻辑可读性与执行效率。
2025-10-10 23:16:45 +08:00

73 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package space
import (
"blazing/common/data/xmlres"
"blazing/common/utils"
"blazing/logic/service/common"
)
// Space 针对Player的并发安全map键为uint32类型
type Space struct {
User utils.ConcurrentMap[uint32, common.PlayerI] // 存储玩家数据的map键为玩家ID
CanRefresh bool //是否能够刷怪
//ID uint32 // 地图ID
Name string //地图名称
// DefaultPos model.Pos //默认位置DefaultPos
//Positions map[uint32]model.Pos //从上一个地图跳转后默认位置 无任何写操作
}
// NewSyncMap 创建一个新的玩家同步map
func NewSpace() *Space {
return &Space{
User: utils.NewWithCustomShardingFunction[uint32, common.PlayerI](func(key uint32) uint32 {
return key
}),
}
}
// // Range 遍历所有玩家并执行回调函数
// // 读操作使用RLock遍历过程中不会阻塞其他读操作
// func (m *Space) Range(f func(playerID uint32, player common.PlayerI) bool) {
// m.mu.RLock()
// defer m.mu.RUnlock()
// for id, player := range m.User {
// // 若回调返回false则停止遍历
// if !f(id, player) {
// break
// }
// }
// }
// 获取星球
func GetSpace(id uint32) *Space {
planet, ok := planetmap.Load(id)
if ok {
return planet
}
t := NewSpace()
if id < 10000 { //说明是玩家地图GetSpace
for _, v := range xmlres.MapConfig.Maps {
if v.ID == int(id) { //找到这个地图
t := NewSpace()
t.Name = v.Name
}
}
}
planetmap.Store(id, t)
return t
}
var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据
type LeaveMapOutboundInfo struct {
// 米米号
UserID uint32 `struc:"uint32" fieldDesc:"米米号" json:"user_id"`
}