diff --git a/logic/controller/map.go b/logic/controller/map.go index a5e946bd3..21a8066e0 100644 --- a/logic/controller/map.go +++ b/logic/controller/map.go @@ -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应该是空的 diff --git a/logic/service/space/hot.go b/logic/service/space/hot.go index f173f36d8..39aee604f 100644 --- a/logic/service/space/hot.go +++ b/logic/service/space/hot.go @@ -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) }