增加并发锁

This commit is contained in:
1
2025-08-28 23:23:24 +00:00
parent fcb027c8d7
commit 1f835c1197
2 changed files with 28 additions and 20 deletions

View File

@@ -23,7 +23,6 @@ func (h *Controller) MapEnter(data *maps.InInfo, c *socket.Player) (result *maps
data.Broadcast(c.Info.MapID, *result) //同步广播
// 如果是无怪地图,直接返回
if mservice.NewMonsterService().GetId(c.Info.MapID) == nil {
return nil, -1
}
@@ -78,7 +77,7 @@ func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *socket.Player)
close(c.StopChan)
c.StopChan = nil
}
//c.MapID = 0 // 重置当前地图
c.Info.MapID = 0 // 重置当前地图
return nil, -1
}
func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *socket.Player) (result *maps.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的

View File

@@ -1,7 +1,12 @@
package space
import xml "blazing/common/data/xml/map"
import (
xml "blazing/common/data/xml/map"
"golang.org/x/sync/singleflight"
)
var requestGroup singleflight.Group // SingleFlight 实例
// MapHotInfo 表示地图热度信息
type MapHotInfo struct {
MapID uint32 `json:"mapId"` // 地图ID
@@ -10,27 +15,31 @@ type MapHotInfo struct {
func GetMapHot() []MapHotInfo {
tt := make(map[uint32]uint32)
result1, _, _ := requestGroup.Do("map_hot", func() (interface{}, error) {
for _, v := range xml.MapConfig.Maps {
tt := make(map[uint32]uint32)
t1, ok := tt[uint32(v.Super)]
if ok {
tt[uint32(v.Super)] = uint32(int(t1) + GetSpace(uint32(v.ID)).Len())
for _, v := range xml.MapConfig.Maps {
t1, ok := tt[uint32(v.Super)]
if ok {
tt[uint32(v.Super)] = uint32(int(t1) + GetSpace(uint32(v.ID)).Len())
} else {
tt[uint32(v.Super)] = uint32(GetSpace(uint32(v.ID)).Len())
}
} else {
tt[uint32(v.Super)] = uint32(GetSpace(uint32(v.ID)).Len())
}
var result = make([]MapHotInfo, 0)
for k, v := range tt {
}
var result = make([]MapHotInfo, 0)
for k, v := range tt {
result = append(result, MapHotInfo{
MapID: uint32(k),
Count: uint32(v),
})
result = append(result, MapHotInfo{
MapID: uint32(k),
Count: uint32(v),
})
}
return result
}
return result, nil
})
return result1.([]MapHotInfo)
}