From eb793e49160129e4d634d15afd713f2fe86d0644 Mon Sep 17 00:00:00 2001
From: NatureFreshMilk <naturefreshmilk@github.com>
Date: Thu, 7 Feb 2019 09:58:10 +0100
Subject: [PATCH] initial render impl

---
 server/settings/settings.go       |  3 ++-
 server/tilerendererjob/initial.go | 14 ++++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/server/settings/settings.go b/server/settings/settings.go
index e9727b9..8676511 100644
--- a/server/settings/settings.go
+++ b/server/settings/settings.go
@@ -10,7 +10,8 @@ const (
 	SETTING_LASTX = "last_x"
 	SETTING_LASTY = "last_y"
 	SETTING_LASTZ = "last_z"
-	SETTING_INITIAL_RUN = "initial_run"
+  SETTING_INITIAL_RUN = "initial_run"
+  SETTING_LEGACY_PROCESSED = "legacy_processed"
 )
 
 type Settings struct {
diff --git a/server/tilerendererjob/initial.go b/server/tilerendererjob/initial.go
index 71a8348..5bf32e3 100644
--- a/server/tilerendererjob/initial.go
+++ b/server/tilerendererjob/initial.go
@@ -3,6 +3,7 @@ package tilerendererjob
 import (
 	"github.com/sirupsen/logrus"
 	"mapserver/app"
+	"mapserver/settings"
 	"mapserver/coords"
 	"time"
 )
@@ -13,7 +14,6 @@ type InitialRenderEvent struct {
 
 func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
 
-	rstate := ctx.Config.RenderState
 	totalLegacyCount, err := ctx.Blockdb.CountBlocks(0, 0)
 
 	if err != nil {
@@ -21,12 +21,15 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
 	}
 
 	fields := logrus.Fields{
-		"totalLegacyCount": totalLegacyCount,
-		"LastMtime":        rstate.LastMtime,
+		"totalLegacyCount": totalLegacyCount
 	}
 	logrus.WithFields(fields).Info("Starting initial rendering job")
 
-	lastcoords := coords.NewMapBlockCoords(rstate.LastX, rstate.LastY, rstate.LastZ)
+	lastx := ctx.Settings.GetInt(settings.SETTING_LASTX, -1)
+	lasty := ctx.Settings.GetInt(settings.SETTING_LASTY, -1)
+	lastz := ctx.Settings.GetInt(settings.SETTING_LASTZ, -1)
+
+	lastcoords := coords.NewMapBlockCoords(lastx, lasty, lastz)
 
 	for true {
 		start := time.Now()
@@ -38,8 +41,7 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
 		}
 
 		if len(result.List) == 0 && !result.HasMore {
-			rstate.InitialRun = false
-			ctx.Config.Save()
+			ctx.Settings.SetBool(settings.SETTING_INITIAL_RUN, false)
 
 			ev := InitialRenderEvent{
 				Progress: 100,