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

@@ -37,7 +37,7 @@ func (h Controller) UserMoreInfo(data *user.MoreUserInfoInboundInfo, c *player.P
func (h Controller) Aimat(data *user.AimatInboundInfo, c *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) {
defer space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, player common.PlayerI) {
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, player common.PlayerI) bool {
ret := &user.AimatOutboundInfo{
ItemId: data.ItemId,
@@ -47,14 +47,14 @@ func (h Controller) Aimat(data *user.AimatInboundInfo, c *player.Player) (result
}
data.Head.Result = 0
player.SendPack(data.Head.Pack(ret))
return false
})
return nil, -1
}
func (h Controller) Chat(data *user.ChatInboundInfo, c *player.Player) (result *user.ChatOutboundInfo, err errorcode.ErrorCode) {
defer space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, v common.PlayerI) {
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, v common.PlayerI) bool {
result = &user.ChatOutboundInfo{
Message: string([]byte(data.Message)[:data.MessageLen-1]),
@@ -64,6 +64,7 @@ func (h Controller) Chat(data *user.ChatInboundInfo, c *player.Player) (result *
result.Message = cool.Filter.Replace(result.Message, '*')
data.Head.Result = 0
v.SendPack(data.Head.Pack(result))
return false
})
return nil, -1
@@ -76,7 +77,7 @@ func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *play
c.Info.Color = data.Color
c.Info.Texture = 0
defer space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, v common.PlayerI) {
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, v common.PlayerI) bool {
data.Head.Result = 0
result = &user.ChangeColorOutboundInfo{
UserId: c.Info.UserID,
@@ -85,6 +86,7 @@ func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *play
Texture: c.Info.Texture,
}
v.SendPack(data.Head.Pack(result))
return false
})
return nil, -1
@@ -95,7 +97,7 @@ func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *pl
}
c.Info.Texture = data.Id
c.Info.Color = data.Color
defer space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, v common.PlayerI) {
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, v common.PlayerI) bool {
data.Head.Result = 0
result = &user.ChangeDoodleOutboundInfo{
UserId: c.Info.UserID,
@@ -104,6 +106,7 @@ func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *pl
Texture: c.Info.Texture,
}
v.SendPack(data.Head.Pack(result))
return false
})
return nil, -1