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

96 lines
2.0 KiB
Go
Raw Normal View History

2019-02-10 22:27:53 +03:00
package mapblockaccessor
import (
"mapserver/coords"
"mapserver/eventbus"
"mapserver/layer"
2019-02-14 10:34:16 +03:00
"mapserver/settings"
2019-02-10 22:27:53 +03:00
"mapserver/mapblockparser"
cache "github.com/patrickmn/go-cache"
"github.com/sirupsen/logrus"
)
2019-02-10 22:34:11 +03:00
type FindNextLegacyBlocksResult struct {
HasMore bool
List []*mapblockparser.MapBlock
UnfilteredCount int
}
2019-02-14 10:34:16 +03:00
func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []layer.Layer, limit int) (*FindNextLegacyBlocksResult, error) {
2019-02-10 22:27:53 +03:00
fields := logrus.Fields{
"x": lastpos.X,
"y": lastpos.Y,
"z": lastpos.Z,
"limit": limit,
}
logrus.WithFields(fields).Debug("FindMapBlocksByPos")
2019-02-11 18:32:39 +03:00
nextResult, err := a.accessor.FindNextInitialBlocks(lastpos, limit)
blocks := nextResult.List
2019-02-10 22:27:53 +03:00
if err != nil {
return nil, err
}
2019-02-10 22:34:11 +03:00
result := FindNextLegacyBlocksResult{}
2019-02-10 22:27:53 +03:00
mblist := make([]*mapblockparser.MapBlock, 0)
var newlastpos *coords.MapBlockCoords
result.HasMore = len(blocks) == limit
result.UnfilteredCount = len(blocks)
for _, block := range blocks {
newlastpos = block.Pos
if result.LastMtime < block.Mtime {
result.LastMtime = block.Mtime
}
inLayer := false
for _, l := range layerfilter {
if (block.Pos.Y*16) >= l.From && (block.Pos.Y*16) <= l.To {
inLayer = true
break
}
}
if !inLayer {
continue
}
fields := logrus.Fields{
"x": block.Pos.X,
"y": block.Pos.Y,
"z": block.Pos.Z,
}
logrus.WithFields(fields).Trace("mapblock")
key := getKey(block.Pos)
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime, block.Pos)
if err != nil {
return nil, err
}
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, mapblock)
a.c.Set(key, mapblock, cache.DefaultExpiration)
mblist = append(mblist, mapblock)
}
result.LastPos = newlastpos
result.List = mblist
fields = logrus.Fields{
"len(List)": len(result.List),
"unfilteredCount": result.UnfilteredCount,
"hasMore": result.HasMore,
"limit": limit,
}
logrus.WithFields(fields).Debug("FindMapBlocksByPos:Result")
return &result, nil
}