From 4bed73d9e34b7208c307201290759e64e832635e Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 8 May 2016 15:13:40 +0200 Subject: [PATCH] Prepare tiles updater in webmapper to have unupdated base tiles. --- cmd/mtwebmapper/tilesupdater.go | 54 ++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/cmd/mtwebmapper/tilesupdater.go b/cmd/mtwebmapper/tilesupdater.go index 1e91a3a..5cd8cc1 100644 --- a/cmd/mtwebmapper/tilesupdater.go +++ b/cmd/mtwebmapper/tilesupdater.go @@ -48,6 +48,11 @@ type xz struct { Z int16 } +type xzc struct { + xz + canceled bool +} + type xzm struct { P xz Mask uint16 @@ -150,21 +155,40 @@ func (tu *tileUpdater) ServeHTTP(rw http.ResponseWriter, r *http.Request) { rw.WriteHeader(http.StatusOK) } +func extractChanges(changes map[xz]bool) []xzc { + chs := make([]xzc, len(changes)) + var i int + for ch := range changes { + chs[i] = xzc{ch, false} + i++ + } + return chs +} + +func activeChanges(changes []xzc) map[xz]bool { + chs := make(map[xz]bool) + for i := range changes { + if !changes[i].canceled { + chs[changes[i].xz] = true + } + } + return chs +} + func (tu *tileUpdater) doUpdates() { for { - var changes map[xz]bool tu.cond.L.Lock() for len(tu.changes) == 0 { tu.cond.Wait() } - changes = tu.changes + changes := extractChanges(tu.changes) tu.changes = map[xz]bool{} tu.cond.L.Unlock() baseDir := filepath.Join(tu.mapDir, "8") - jobs := make(chan xz) + jobs := make(chan *xzc) var done sync.WaitGroup for i, n := 0, common.Min(tu.workers, len(changes)); i < n; i++ { @@ -182,17 +206,25 @@ func (tu *tileUpdater) doUpdates() { go tu.updateBaseTiles(jobs, btc, &done) } - parentJobs := make(map[xz]uint16) - - for c := range changes { + for i := range changes { //log.Printf("job: %+v\n", c) - jobs <- c - pxz := c.parent() - parentJobs[pxz.P] |= pxz.Mask + jobs <- &changes[i] } close(jobs) done.Wait() + actChs := activeChanges(changes) + + if len(actChs) == 0 { + continue + } + + parentJobs := make(map[xz]uint16) + for c := range actChs { + pxz := c.parent() + parentJobs[pxz.P] |= pxz.Mask + } + for level := 7; level >= 0; level-- { pJobs := make(chan xzm) for i, n := 0, common.Min(len(parentJobs), tu.workers); i < n; i++ { @@ -211,7 +243,7 @@ func (tu *tileUpdater) doUpdates() { } if tu.btu != nil { - tu.btu.BaseTilesUpdated(changes) + tu.btu.BaseTilesUpdated(actChs) } } } @@ -294,7 +326,7 @@ func (tu *tileUpdater) updatePyramidTile(scratch, resized *image.RGBA, level int } func (tu *tileUpdater) updateBaseTiles( - jobs chan xz, + jobs chan *xzc, btc *common.BaseTileCreator, done *sync.WaitGroup) { defer btc.Close()