mapserver/server/initialrenderer/job.go

113 lines
2.4 KiB
Go
Raw Normal View History

2019-01-21 11:11:07 +03:00
package initialrenderer
import (
"mapserver/app"
"mapserver/coords"
2019-01-22 15:35:15 +03:00
"strconv"
2019-01-22 15:46:58 +03:00
"time"
2019-01-21 22:13:38 +03:00
"github.com/sirupsen/logrus"
2019-01-21 11:11:07 +03:00
)
2019-01-22 15:35:15 +03:00
func getTileKey(tc *coords.TileCoords) string {
return strconv.Itoa(tc.X) + "/" + strconv.Itoa(tc.Y) + "/" + strconv.Itoa(tc.Zoom)
}
2019-01-21 11:11:07 +03:00
func Job(ctx *app.App) {
fields := logrus.Fields{}
logrus.WithFields(fields).Info("Starting initial rendering")
2019-01-22 15:53:11 +03:00
tilecount := 0
2019-01-21 11:11:07 +03:00
2019-01-23 14:46:45 +03:00
totalLegacyCount, err := ctx.Blockdb.CountLegacyBlocks()
if err != nil {
panic(err)
}
2019-01-21 12:53:58 +03:00
rstate := ctx.Config.RenderState
lastcoords := coords.NewMapBlockCoords(rstate.LastX, rstate.LastY, rstate.LastZ)
2019-01-21 11:11:07 +03:00
for true {
2019-01-21 18:27:31 +03:00
start := time.Now()
2019-01-23 14:46:45 +03:00
result, err := ctx.BlockAccessor.FindLegacyMapBlocks(lastcoords, ctx.Config.InitialRenderingFetchLimit, ctx.Config.Layers)
2019-01-21 11:11:07 +03:00
if err != nil {
panic(err)
}
2019-01-23 14:46:45 +03:00
if len(result.List) == 0 && !result.HasMore {
2019-01-22 15:53:11 +03:00
fields = logrus.Fields{
2019-01-23 14:46:45 +03:00
"blocks": rstate.LegacyProcessed,
2019-01-22 18:36:50 +03:00
"tiles": tilecount,
2019-01-22 15:53:11 +03:00
}
logrus.WithFields(fields).Info("Initial rendering complete")
2019-01-21 12:53:58 +03:00
rstate.InitialRun = false
ctx.Config.Save()
2019-01-21 11:11:07 +03:00
break
}
2019-01-23 14:46:45 +03:00
lastcoords = *result.LastPos
2019-01-21 13:18:27 +03:00
2019-01-22 15:35:15 +03:00
tileRenderedMap := make(map[string]bool)
2019-01-22 14:53:36 +03:00
2019-01-22 15:46:58 +03:00
for i := 12; i >= 1; i-- {
2019-01-23 14:46:45 +03:00
for _, mb := range result.List {
2019-01-22 15:35:15 +03:00
//13
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
2019-01-22 14:53:36 +03:00
2019-01-22 15:46:58 +03:00
//12-1
2019-01-22 15:35:15 +03:00
tc = tc.ZoomOut(13 - i)
key := getTileKey(tc)
if tileRenderedMap[key] {
continue
}
tileRenderedMap[key] = true
2019-01-21 15:27:36 +03:00
fields = logrus.Fields{
2019-01-21 15:45:35 +03:00
"X": tc.X,
"Y": tc.Y,
"Zoom": tc.Zoom,
2019-01-21 15:27:36 +03:00
"LayerId": tc.LayerId,
}
2019-01-22 14:53:36 +03:00
logrus.WithFields(fields).Debug("Dispatching tile rendering (z11-1)")
2019-01-21 13:31:50 +03:00
2019-01-22 15:53:11 +03:00
tilecount++
2019-01-22 14:53:36 +03:00
ctx.Objectdb.RemoveTile(tc)
2019-01-22 23:13:16 +03:00
_, err = ctx.Tilerenderer.Render(tc, 2)
2019-01-21 15:27:36 +03:00
if err != nil {
panic(err)
}
2019-01-21 13:31:50 +03:00
}
}
2019-01-21 11:11:07 +03:00
2019-01-21 12:53:58 +03:00
//Save current positions of initial run
rstate.LastX = lastcoords.X
rstate.LastY = lastcoords.Y
rstate.LastZ = lastcoords.Z
2019-01-23 14:46:45 +03:00
rstate.LegacyProcessed += result.UnfilteredCount
2019-01-21 12:53:58 +03:00
ctx.Config.Save()
2019-01-21 18:27:31 +03:00
t := time.Now()
elapsed := t.Sub(start)
2019-01-23 15:13:32 +03:00
progress := int(float64(rstate.LegacyProcessed) / float64(totalLegacyCount) * 100)
2019-01-23 14:46:45 +03:00
2019-01-21 11:11:07 +03:00
fields = logrus.Fields{
2019-01-23 15:13:32 +03:00
"count": len(result.List),
2019-01-23 14:46:45 +03:00
"processed": rstate.LegacyProcessed,
"progress%": progress,
2019-01-23 15:13:32 +03:00
"X": lastcoords.X,
"Y": lastcoords.Y,
"Z": lastcoords.Z,
"elapsed": elapsed,
2019-01-21 11:11:07 +03:00
}
logrus.WithFields(fields).Info("Initial rendering")
}
}