2019-01-24 17:56:37 +03:00
|
|
|
package tilerendererjob
|
|
|
|
|
|
|
|
import (
|
|
|
|
"mapserver/app"
|
|
|
|
"mapserver/coords"
|
2019-02-07 20:44:40 +03:00
|
|
|
"mapserver/settings"
|
2019-01-24 17:56:37 +03:00
|
|
|
"time"
|
2019-02-07 20:44:40 +03:00
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2019-01-24 17:56:37 +03:00
|
|
|
)
|
|
|
|
|
2019-02-01 16:50:39 +03:00
|
|
|
type InitialRenderEvent struct {
|
|
|
|
Progress int `json:"progress"`
|
|
|
|
}
|
|
|
|
|
2019-01-24 17:56:37 +03:00
|
|
|
func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
|
|
|
|
|
|
|
|
totalLegacyCount, err := ctx.Blockdb.CountBlocks(0, 0)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fields := logrus.Fields{
|
2019-02-07 20:44:40 +03:00
|
|
|
"totalLegacyCount": totalLegacyCount,
|
2019-01-24 17:56:37 +03:00
|
|
|
}
|
|
|
|
logrus.WithFields(fields).Info("Starting initial rendering job")
|
|
|
|
|
2019-02-08 10:11:06 +03:00
|
|
|
lastx := ctx.Settings.GetInt(settings.SETTING_LASTX, coords.MinCoord-1)
|
|
|
|
lasty := ctx.Settings.GetInt(settings.SETTING_LASTY, coords.MinCoord-1)
|
|
|
|
lastz := ctx.Settings.GetInt(settings.SETTING_LASTZ, coords.MinCoord-1)
|
2019-02-07 11:58:10 +03:00
|
|
|
|
|
|
|
lastcoords := coords.NewMapBlockCoords(lastx, lasty, lastz)
|
2019-01-24 17:56:37 +03:00
|
|
|
|
|
|
|
for true {
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
result, err := ctx.BlockAccessor.FindMapBlocksByPos(lastcoords, ctx.Config.RenderingFetchLimit, ctx.Config.Layers)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:44:40 +03:00
|
|
|
legacyProcessed := ctx.Settings.GetInt(settings.SETTING_LEGACY_PROCESSED, 0)
|
|
|
|
|
2019-01-24 17:56:37 +03:00
|
|
|
if len(result.List) == 0 && !result.HasMore {
|
2019-02-07 11:58:10 +03:00
|
|
|
ctx.Settings.SetBool(settings.SETTING_INITIAL_RUN, false)
|
2019-01-24 17:56:37 +03:00
|
|
|
|
2019-02-01 16:50:39 +03:00
|
|
|
ev := InitialRenderEvent{
|
|
|
|
Progress: 100,
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.WebEventbus.Emit("initial-render-progress", &ev)
|
|
|
|
|
2019-01-24 17:56:37 +03:00
|
|
|
fields := logrus.Fields{
|
2019-02-07 20:44:40 +03:00
|
|
|
"legacyblocks": legacyProcessed,
|
2019-01-24 17:56:37 +03:00
|
|
|
}
|
|
|
|
logrus.WithFields(fields).Info("initial rendering complete")
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-01-24 18:33:54 +03:00
|
|
|
tiles := renderMapblocks(ctx, jobs, result.List)
|
2019-01-24 17:56:37 +03:00
|
|
|
|
2019-02-06 10:38:08 +03:00
|
|
|
lastcoords = result.LastPos
|
2019-02-07 20:44:40 +03:00
|
|
|
ctx.Settings.SetInt64(settings.SETTING_LAST_MTIME, result.LastMtime)
|
2019-01-24 17:56:37 +03:00
|
|
|
|
|
|
|
//Save current positions of initial run
|
2019-02-07 20:44:40 +03:00
|
|
|
ctx.Settings.SetInt(settings.SETTING_LASTX, lastcoords.X)
|
|
|
|
ctx.Settings.SetInt(settings.SETTING_LASTY, lastcoords.Y)
|
|
|
|
ctx.Settings.SetInt(settings.SETTING_LASTZ, lastcoords.Z)
|
|
|
|
legacyProcessed += result.UnfilteredCount
|
|
|
|
|
|
|
|
ctx.Settings.SetInt(settings.SETTING_LEGACY_PROCESSED, legacyProcessed)
|
2019-01-24 17:56:37 +03:00
|
|
|
|
|
|
|
t := time.Now()
|
|
|
|
elapsed := t.Sub(start)
|
|
|
|
|
2019-02-07 20:44:40 +03:00
|
|
|
progress := int(float64(legacyProcessed) / float64(totalLegacyCount) * 100)
|
2019-01-24 17:56:37 +03:00
|
|
|
|
2019-02-01 16:50:39 +03:00
|
|
|
ev := InitialRenderEvent{
|
|
|
|
Progress: progress,
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.WebEventbus.Emit("initial-render-progress", &ev)
|
|
|
|
|
2019-01-24 17:56:37 +03:00
|
|
|
fields := logrus.Fields{
|
2019-01-24 18:33:54 +03:00
|
|
|
"mapblocks": len(result.List),
|
|
|
|
"tiles": tiles,
|
2019-02-07 20:44:40 +03:00
|
|
|
"processed": legacyProcessed,
|
2019-01-24 17:56:37 +03:00
|
|
|
"progress%": progress,
|
|
|
|
"X": lastcoords.X,
|
|
|
|
"Y": lastcoords.Y,
|
|
|
|
"Z": lastcoords.Z,
|
|
|
|
"elapsed": elapsed,
|
|
|
|
}
|
|
|
|
logrus.WithFields(fields).Info("Initial rendering")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|