mapserver/initialrenderer/job.go

92 lines
1.9 KiB
Go
Raw Normal View History

2019-01-21 11:11:07 +03:00
package initialrenderer
import (
"github.com/sirupsen/logrus"
"mapserver/app"
"mapserver/coords"
2019-01-21 18:27:31 +03:00
"time"
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-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-21 16:27:15 +03:00
hasMore, newlastcoords, mblist, 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-21 16:27:15 +03:00
if len(mblist) == 0 && !hasMore {
2019-01-21 11:11:07 +03:00
logrus.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-21 13:18:27 +03:00
lastcoords = *newlastcoords
2019-01-21 15:27:36 +03:00
//Invalidate zoom 12-1
2019-01-21 13:31:50 +03:00
for _, mb := range mblist {
2019-01-21 15:27:36 +03:00
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
if tc == nil {
2019-01-21 16:27:15 +03:00
panic("tile not in any layer")
2019-01-21 15:27:36 +03:00
}
for tc.Zoom > 1 {
tc = tc.GetZoomedOutTile()
2019-01-21 17:13:33 +03:00
ctx.Objectdb.RemoveTile(tc)
2019-01-21 15:27:36 +03:00
}
}
//Render zoom 12-1
2019-01-21 16:27:15 +03:00
for _, mb := range mblist {
2019-01-21 15:27:36 +03:00
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
for tc.Zoom > 1 {
tc = tc.GetZoomedOutTile()
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,
}
logrus.WithFields(fields).Debug("Dispatching tile rendering")
2019-01-21 13:31:50 +03:00
2019-01-21 15:27:36 +03:00
_, err = ctx.Tilerenderer.Render(tc)
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
ctx.Config.Save()
2019-01-21 18:27:31 +03:00
t := time.Now()
elapsed := t.Sub(start)
2019-01-21 11:11:07 +03:00
fields = logrus.Fields{
2019-01-21 18:27:31 +03:00
"count": len(mblist),
"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")
}
}