1
0
forked from MTSR/mapserver
mapserver/mapblockaccessor/legacyblocks.go

82 lines
1.9 KiB
Go
Raw Normal View History

2019-02-10 22:27:53 +03:00
package mapblockaccessor
import (
"mapserver/eventbus"
2019-02-14 11:05:39 +03:00
"mapserver/settings"
"mapserver/types"
2019-02-10 22:27:53 +03:00
2021-10-12 08:44:07 +03:00
"github.com/minetest-go/mapparser"
2019-02-10 22:27:53 +03:00
cache "github.com/patrickmn/go-cache"
"github.com/sirupsen/logrus"
)
2019-02-10 22:34:11 +03:00
type FindNextLegacyBlocksResult struct {
HasMore bool
List []*types.ParsedMapblock
2019-02-10 22:34:11 +03:00
UnfilteredCount int
2019-02-15 11:08:22 +03:00
Progress float64
2019-02-15 19:33:49 +03:00
LastMtime int64
2019-02-10 22:34:11 +03:00
}
2023-12-29 18:00:11 +03:00
func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []*types.Layer, limit int) (*FindNextLegacyBlocksResult, error) {
2019-02-10 22:27:53 +03:00
2019-02-14 10:50:54 +03:00
nextResult, err := a.accessor.FindNextInitialBlocks(s, layers, limit)
2019-02-10 22:27:53 +03:00
if err != nil {
return nil, err
}
2019-02-15 19:33:49 +03:00
blocks := nextResult.List
2019-02-10 22:34:11 +03:00
result := FindNextLegacyBlocksResult{}
2019-02-10 22:27:53 +03:00
mblist := make([]*types.ParsedMapblock, 0)
2019-02-14 10:50:54 +03:00
result.HasMore = nextResult.HasMore
result.UnfilteredCount = nextResult.UnfilteredCount
2019-02-15 10:58:04 +03:00
result.Progress = nextResult.Progress
2019-02-15 19:33:49 +03:00
result.LastMtime = nextResult.LastMtime
2019-02-10 22:27:53 +03:00
for _, block := range blocks {
2019-02-14 22:18:14 +03:00
2019-02-10 22:27:53 +03:00
fields := logrus.Fields{
"x": block.Pos.X,
"y": block.Pos.Y,
"z": block.Pos.Z,
}
logrus.WithFields(fields).Trace("mapblock")
key := getKey(block.Pos)
2021-10-12 08:44:07 +03:00
mapblock, err := mapparser.Parse(block.Data)
2019-02-10 22:27:53 +03:00
if err != nil {
2019-02-28 22:19:20 +03:00
fields := logrus.Fields{
"x": block.Pos.X,
"y": block.Pos.Y,
"z": block.Pos.Z,
"err": err,
}
logrus.WithFields(fields).Error("mapblock-parse")
2019-02-28 22:19:20 +03:00
2019-02-10 22:27:53 +03:00
return nil, err
}
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, types.NewParsedMapblock(mapblock, block.Pos))
2019-02-10 22:27:53 +03:00
2019-03-13 12:41:37 +03:00
a.blockcache.Set(key, mapblock, cache.DefaultExpiration)
cacheBlockCount.Inc()
mblist = append(mblist, types.NewParsedMapblock(mapblock, block.Pos))
2019-02-10 22:27:53 +03:00
}
result.List = mblist
2019-02-14 10:50:54 +03:00
fields := logrus.Fields{
2019-02-10 22:27:53 +03:00
"len(List)": len(result.List),
"unfilteredCount": result.UnfilteredCount,
"hasMore": result.HasMore,
"limit": limit,
}
logrus.WithFields(fields).Debug("FindMapBlocksByPos:Result")
return &result, nil
}