feat(space): 替换并发安全map实现以提升性能

将原来基于`utils.ConcurrentMap`的玩家存储结构替换为
`github.com/mhmtszr/concurrent-swiss-map`提供的`CsMap`,
以获得更高效的并发读写能力。

同时修改了相关API调用方式:
- `Set` 改为 `Store`
- `Remove` 改为 `Delete`
- `IterCb` 改为 `Range`,并支持提前终止迭代
- `Items()` 不再使用

此外,调整了部分业务逻辑中对玩家列表遍历的方式,
确保在发送网络包后及时跳出循环,避免不必要的操作。

新增战斗类型处理函数`PET_King`用于处理宠物王相关的
战斗请求,并修复了`PET_MELEE`方法中的逻辑问题。

更新了go.mod和go.sum引入新的依赖库。
```
This commit is contained in:
2025-11-15 15:22:58 +08:00
parent f919047ff6
commit 6979b7018d
19 changed files with 117 additions and 48 deletions

View File

@@ -14,8 +14,8 @@ 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).User.Set(c.Info.UserID, c) //添加玩家
c.Info.MapID = data.MapId //登录地图
space.GetSpace(c.Info.MapID).User.Store(c.Info.UserID, c) //添加玩家
result = maps.NewOutInfo()
c.Info.Pos = data.Point
@@ -39,7 +39,7 @@ func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *player.Player)
c.Canmon = false
c.Changemap = true //可以刷怪
data.Broadcast(c.Info.MapID, space.LeaveMapOutboundInfo{UserID: c.Info.UserID}) //同步广播
space.GetSpace(c.Info.MapID).User.Remove(c.Info.UserID)
space.GetSpace(c.Info.MapID).User.Delete(c.Info.UserID)
// 如果有正在运行的刷怪协程,发送停止信号
c.Info.MapID = 0 // 重置当前地图
@@ -49,11 +49,12 @@ func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *player.Play
result = &maps.ListMapPlayerOutboundInfo{}
result.Player = make([]maps.OutInfo, 0)
space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, player common.PlayerI) {
space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, player common.PlayerI) bool {
result1 := maps.NewOutInfo()
copier.CopyWithOption(result1, player.GetInfo(), copier.Option{DeepCopy: true})
result.Player = append(result.Player, *result1)
result.Player = LastFourElements(result.Player)
return false
})
c.Canmon = true //可以刷怪