mapserver/initialrenderer/job.go

109 lines
2.2 KiB
Go
Raw Normal View History

2019-01-21 11:11:07 +03:00
package initialrenderer
import (
"mapserver/app"
"mapserver/coords"
2019-01-21 18:27:31 +03:00
"time"
2019-01-21 22:13:38 +03:00
"github.com/sirupsen/logrus"
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-22 14:53:36 +03:00
//Render zoom 12
2019-01-21 13:31:50 +03:00
for _, mb := range mblist {
2019-01-22 14:53:36 +03:00
//zoom 13
2019-01-21 15:27:36 +03:00
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
2019-01-22 14:53:36 +03:00
//zoom 12
tc = tc.GetZoomedOutTile()
2019-01-21 22:13:38 +03:00
2019-01-22 14:53:36 +03:00
fields = logrus.Fields{
"X": tc.X,
"Y": tc.Y,
"Zoom": tc.Zoom,
"LayerId": tc.LayerId,
}
logrus.WithFields(fields).Debug("Dispatching tile rendering (z12)")
2019-01-21 22:13:38 +03:00
2019-01-22 14:53:36 +03:00
ctx.Objectdb.RemoveTile(tc)
_, err = ctx.Tilerenderer.Render(tc, 2)
if err != nil {
panic(err)
2019-01-21 15:27:36 +03:00
}
}
2019-01-22 14:53:36 +03:00
//Render zoom 11-1
2019-01-21 16:27:15 +03:00
for _, mb := range mblist {
2019-01-22 14:53:36 +03:00
//13
2019-01-21 15:27:36 +03:00
tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers)
2019-01-22 14:53:36 +03:00
//12
tc = tc.GetZoomedOutTile()
2019-01-21 15:27:36 +03:00
for tc.Zoom > 1 {
2019-01-22 14:53:36 +03:00
//11-1
2019-01-21 15:27:36 +03:00
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,
}
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 14:53:36 +03:00
ctx.Objectdb.RemoveTile(tc)
_, err = ctx.Tilerenderer.Render(tc, 1)
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
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")
}
}