修改地图结构

This commit is contained in:
1
2025-10-10 04:31:52 +00:00
parent 6b06c580ff
commit ac671408f7
2 changed files with 16 additions and 15 deletions

View File

@@ -14,8 +14,9 @@ import (
func (h *Controller) MapEnter(data *maps.InInfo, c *player.Player) (result *maps.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
c.Info.MapID = data.MapId //登录地图
space.GetSpace(c.Info.MapID).Set(c.Info.UserID, c) //添加玩家
c.Info.MapID = data.MapId //登录地图
t := space.GetSpace(c.Info.MapID)
t.Set(c.Info.UserID, c) //添加玩家
result = maps.NewOutInfo()
c.Info.Pos = data.Point
copier.Copy(result, c.Info)

View File

@@ -12,14 +12,14 @@ import (
// Space 针对Player的并发安全map键为uint32类型
type Space struct {
mu sync.RWMutex // 读写锁,读多写少场景更高效
data utils.ConcurrentMap[uint32, common.PlayerI]// 存储玩家数据的map键为玩家ID
CanRefresh bool //是否能够刷怪
ID uint32 // 地图ID
Name string //地图名称
DefaultPos model.Pos //默认位置DefaultPos
Positions *utils.SyncMap[uint32, model.Pos] //从上一个地图跳转后默认位置
mu sync.RWMutex // 读写锁,读多写少场景更高效
data 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
@@ -96,14 +96,14 @@ func GetSpace(id uint32) *Space {
for _, v := range xmlres.MapConfig.Maps {
if v.ID == int(id) { //找到这个地图
t := NewSpace()
t.DefaultPos = model.Pos{X: uint32(v.X), Y: uint32(v.Y)}
//t.DefaultPos = model.Pos{X: uint32(v.X), Y: uint32(v.Y)}
t.ID = uint32(v.ID)
t.Name = v.Name
t.Positions = make(map[uint32]model.Pos)
for _, v := range v.Entries.Entries { //添加地图入口
t.Positions[uint32(v.FromMap)] = model.Pos{X: uint32(v.PosX), Y: uint32(v.PosY)}
// t.Positions = make(map[uint32]model.Pos)
// for _, v := range v.Entries.Entries { //添加地图入口
// t.Positions[uint32(v.FromMap)] = model.Pos{X: uint32(v.PosX), Y: uint32(v.PosY)}
}
// }
planetmap.Store(id, t)
return t