initial render

This commit is contained in:
NatureFreshMilk 2019-01-17 14:20:29 +01:00
parent 4218baedd2
commit d44aa103d4
2 changed files with 48 additions and 46 deletions

View File

@ -1,56 +1,63 @@
package initialrenderer
import (
"mapserver/mapblockrenderer"
"mapserver/tiledb"
"mapserver/tilerenderer"
"mapserver/layerconfig"
"mapserver/coords"
"github.com/sirupsen/logrus"
"time"
)
func Render(renderer *mapblockrenderer.MapBlockRenderer,
tdb tiledb.DBAccessor){
results := make(chan mapblockrenderer.JobResult, 100)
jobs := make(chan mapblockrenderer.JobData, 100)
for i := 0; i<3; i++ {
go mapblockrenderer.Worker(renderer, jobs, results)
}
go func() {
for result := range results {
tc := coords.GetTileCoordsFromMapBlock(result.Job.Pos1)
tile := tiledb.Tile{Pos: tc, Data: result.Data.Bytes(), Mtime: time.Now().Unix()}
tdb.SetTile(&tile)
}
}()
from := coords.MinCoord
to := coords.MaxCoord
func Render(tr *tilerenderer.TileRenderer,
layers []layerconfig.Layer){
start := time.Now()
complete_count := (to - from) * (to - from)
complete_count := 512*512
current_count := 0
for x := from; x < to; x++ {
for z := from; z < to; z++ {
pos1 := coords.NewMapBlockCoords(x, 10, z)
pos2 := coords.NewMapBlockCoords(x, -1, z)
for _, layer := range(layers) {
jobs <- mapblockrenderer.JobData{Pos1: pos1, Pos2: pos2}
current_count++
// zoom:1 == length=1
// zoom:2 == length=2
// zoom:3 == length=4
// zoom:4 == length=8
// zoom:5 == length=16
// zoom:6 == length=32
// zoom:7 == length=64
// zoom:8 == length=128
// zoom:9 == length=256
// zoom:10 == length=512
// zoom:11 == length=1024
// zoom:12 == length=2048
// zoom:13 == length=4096
//zoom 10 iterator
for x := -255; x<256; x++ {
for y := -255; y<256; y++ {
tc := coords.NewTileCoords(x,y,10,layer.Id)
_, err := tr.Render(tc)
current_count++
if err != nil {
panic(err)
}
if time.Now().Sub(start).Seconds() > 2 {
start = time.Now()
progress := float64(current_count) / float64(complete_count) * 100
fields := logrus.Fields{
"x": x,
"y": y,
"progress%": progress,
"layer": layer.Name,
}
logrus.WithFields(fields).Info("Initial render progress")
}
}
}
if time.Now().Sub(start).Seconds() > 2 {
start = time.Now()
progress := float64(current_count) / float64(complete_count) * 100
logrus.WithFields(logrus.Fields{"x": x, "z": z, "progress%": progress}).Info("Initial render progress")
}
}
}
close(jobs)
defer close(results)
}

View File

@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"mapserver/initialrenderer"
"mapserver/colormapping"
"mapserver/db"
"mapserver/mapblockaccessor"
@ -13,7 +14,6 @@ import (
"mapserver/tilerenderer"
"mapserver/tiledb"
"mapserver/layerconfig"
"mapserver/coords"
)
@ -77,11 +77,6 @@ func main() {
tr := tilerenderer.NewTileRenderer(r, tdb, layerconfig.DefaultLayers)
tc := coords.NewTileCoords(0,0,9,0)
_, err = tr.Render(tc)
if err != nil {
panic(err)
}
initialrenderer.Render(tr, layerconfig.DefaultLayers)
}