Finished logic to supress pyramid regeneration in mtwebmapper. Untested.

This commit is contained in:
Sascha L. Teichmann 2016-05-08 15:38:50 +02:00
parent 4bed73d9e3
commit 0900bd16ce
3 changed files with 30 additions and 15 deletions

View File

@ -68,7 +68,7 @@ func createBaseLevel(
btc := common.NewBaseTileCreator( btc := common.NewBaseTileCreator(
client, colors, bg, client, colors, bg,
int16(yMin), int16(yMax), int16(yMin), int16(yMax),
transparent, baseDir, false) transparent, baseDir, nil)
go createTiles(btc, jobs, &done) go createTiles(btc, jobs, &done)
} }

View File

@ -177,6 +177,8 @@ func activeChanges(changes []xzc) map[xz]bool {
func (tu *tileUpdater) doUpdates() { func (tu *tileUpdater) doUpdates() {
bth := common.NewBaseTileHash()
for { for {
tu.cond.L.Lock() tu.cond.L.Lock()
for len(tu.changes) == 0 { for len(tu.changes) == 0 {
@ -201,7 +203,7 @@ func (tu *tileUpdater) doUpdates() {
btc := common.NewBaseTileCreator( btc := common.NewBaseTileCreator(
client, tu.colors, tu.bg, client, tu.colors, tu.bg,
tu.yMin, tu.yMax, tu.yMin, tu.yMax,
tu.transparent, baseDir, true) tu.transparent, baseDir, bth.Update)
done.Add(1) done.Add(1)
go tu.updateBaseTiles(jobs, btc, &done) go tu.updateBaseTiles(jobs, btc, &done)
} }
@ -334,8 +336,12 @@ func (tu *tileUpdater) updateBaseTiles(
for job := range jobs { for job := range jobs {
xz := job.dequantize() xz := job.dequantize()
//log.Printf("%d/%d %d/%d", x, z, job.X, job.Z) //log.Printf("%d/%d %d/%d", x, z, job.X, job.Z)
if err := btc.CreateTile(xz.X-1, xz.Z-1, int(job.X), int(job.Z)); err != nil { updated, err := btc.CreateTile(xz.X-1, xz.Z-1, int(job.X), int(job.Z))
if err != nil {
log.Printf("WARN: create tile failed: %s\n", err) log.Printf("WARN: create tile failed: %s\n", err)
} }
if !updated {
job.canceled = true
}
} }
} }

View File

@ -5,6 +5,7 @@
package common package common
import ( import (
"image"
"image/color" "image/color"
"io/ioutil" "io/ioutil"
"log" "log"
@ -49,6 +50,8 @@ var tileDepths = [...][2]int16{
var BackgroundColor = color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff} var BackgroundColor = color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
type BaseTileUpdateFunc func(x, y int, img image.Image) bool
type BaseTileCreator struct { type BaseTileCreator struct {
client *RedisClient client *RedisClient
colors *Colors colors *Colors
@ -57,7 +60,7 @@ type BaseTileCreator struct {
yMin int16 yMin int16
yMax int16 yMax int16
baseDir string baseDir string
update bool update BaseTileUpdateFunc
emptyImage []byte emptyImage []byte
bg color.RGBA bg color.RGBA
} }
@ -69,7 +72,7 @@ func NewBaseTileCreator(
yMin, yMax int16, yMin, yMax int16,
transparent bool, transparent bool,
baseDir string, baseDir string,
update bool) *BaseTileCreator { update BaseTileUpdateFunc) *BaseTileCreator {
renderer := NewRenderer(tileWidth, tileHeight, transparent) renderer := NewRenderer(tileWidth, tileHeight, transparent)
yMin, yMax = Order16(yMin, yMax) yMin, yMax = Order16(yMin, yMax)
return &BaseTileCreator{ return &BaseTileCreator{
@ -88,7 +91,7 @@ func (btc *BaseTileCreator) Close() error {
return btc.client.Close() return btc.client.Close()
} }
func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error { func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) (bool, error) {
btc.renderer.Reset() btc.renderer.Reset()
btc.renderer.SetPos(x, z) btc.renderer.SetPos(x, z)
btc.yOrder.Reset() btc.yOrder.Reset()
@ -128,7 +131,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
c2.Z = area.Z2 + z c2.Z = area.Z2 + z
query := Cuboid{P1: c1, P2: c2} query := Cuboid{P1: c1, P2: c2}
if err := btc.client.QueryCuboid(query, drawBlock); err != nil { if err := btc.client.QueryCuboid(query, drawBlock); err != nil {
return err return false, err
} }
if err := btc.yOrder.Drain(btc.colors); err != nil { if err := btc.yOrder.Drain(btc.colors); err != nil {
log.Printf("WARN: rendering block failed: %s\n", err) log.Printf("WARN: rendering block failed: %s\n", err)
@ -140,28 +143,34 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
path := filepath.Join(btc.baseDir, strconv.Itoa(i), strconv.Itoa(j)+".png") path := filepath.Join(btc.baseDir, strconv.Itoa(i), strconv.Itoa(j)+".png")
// Empty images are likely to be produced during seeding. // Empty images are likely to be produced during seeding.
if !btc.update && btc.renderer.IsEmpty() { if btc.update == nil && btc.renderer.IsEmpty() {
// To avoid redundant encoding cache the resulting empty image. // To avoid redundant encoding cache the resulting empty image.
if btc.emptyImage == nil { if btc.emptyImage == nil {
var err error var err error
m := BackgroundImage((tileWidth-2)*16, (tileHeight-2)*16, btc.bg) m := BackgroundImage((tileWidth-2)*16, (tileHeight-2)*16, btc.bg)
if btc.emptyImage, err = EncodeToMem(m); err != nil { if btc.emptyImage, err = EncodeToMem(m); err != nil {
return err return false, err
} }
} }
//log.Printf("Writing empty (%d, %d) to file %s\n", x, z, path) //log.Printf("Writing empty (%d, %d) to file %s\n", x, z, path)
return ioutil.WriteFile(path, btc.emptyImage, 0666) return true, ioutil.WriteFile(path, btc.emptyImage, 0666)
} }
image := btc.renderer.CreateShadedImage( image := btc.renderer.CreateShadedImage(
16, 16, (tileWidth-2)*16, (tileHeight-2)*16, 16, 16, (tileWidth-2)*16, (tileHeight-2)*16,
btc.colors, btc.bg) btc.colors, btc.bg)
log.Printf("Writing (%d, %d) to file %s\n", x, z, path) if btc.update == nil {
log.Printf("Writing (%d, %d) to file %s.\n", x, z, path)
if !btc.update { return true, SaveAsPNG(path, image)
return SaveAsPNG(path, image)
} }
return SaveAsPNGAtomic(path, image) if btc.update(i, j, image) {
log.Printf("Writing (%d, %d) to file %s.\n", x, z, path)
return true, SaveAsPNGAtomic(path, image)
}
log.Printf("File %s does not change.\n", path)
return false, nil
} }