```
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:
@@ -3,14 +3,15 @@ package space
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/utils"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
|
||||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||||
)
|
||||
|
||||
// Space 针对Player的并发安全map,键为uint32类型
|
||||
type Space struct {
|
||||
User utils.ConcurrentMap[uint32, common.PlayerI] // 存储玩家数据的map,键为玩家ID
|
||||
CanRefresh bool //是否能够刷怪
|
||||
User *csmap.CsMap[uint32, common.PlayerI] // 存储玩家数据的map,键为玩家ID
|
||||
CanRefresh bool //是否能够刷怪
|
||||
//ID uint32 // 地图ID
|
||||
Name string //地图名称
|
||||
// DefaultPos model.Pos //默认位置DefaultPos
|
||||
@@ -21,9 +22,20 @@ type Space struct {
|
||||
// NewSyncMap 创建一个新的玩家同步map
|
||||
func NewSpace() *Space {
|
||||
return &Space{
|
||||
User: utils.NewWithCustomShardingFunction[uint32, common.PlayerI](func(key uint32) uint32 {
|
||||
return key
|
||||
}),
|
||||
User: csmap.New[uint32, common.PlayerI](
|
||||
// set the number of map shards. the default value is 32.
|
||||
csmap.WithShardCount[uint32, common.PlayerI](32),
|
||||
|
||||
// // if don't set custom hasher, use the built-in maphash.
|
||||
// csmap.WithCustomHasher[string, int](func(key string) uint64 {
|
||||
// hash := fnv.New64a()
|
||||
// hash.Write([]byte(key))
|
||||
// return hash.Sum64()
|
||||
// }),
|
||||
|
||||
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
|
||||
// csmap.WithSize[string, int](1000),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user