2019-02-10 22:27:53 +03:00
|
|
|
package mapblockaccessor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"mapserver/eventbus"
|
|
|
|
"mapserver/layer"
|
|
|
|
"mapserver/mapblockparser"
|
2019-02-14 11:05:39 +03:00
|
|
|
"mapserver/settings"
|
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 []*mapblockparser.MapBlock
|
|
|
|
UnfilteredCount int
|
2019-02-15 11:08:22 +03:00
|
|
|
Progress float64
|
2019-02-10 22:34:11 +03:00
|
|
|
}
|
|
|
|
|
2019-02-14 10:50:54 +03:00
|
|
|
func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []*layer.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-11 18:32:39 +03:00
|
|
|
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)
|
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-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)
|
|
|
|
|
|
|
|
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.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
|
|
|
|
}
|