1
0
forked from MTSR/mapserver

crude initial tile rendering

This commit is contained in:
NatureFreshMilk 2019-01-17 08:34:21 +01:00
parent b5d3e934b9
commit 39263d3e7f
3 changed files with 68 additions and 47 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@ mapserver
world.mt world.mt
output output
map.sqlite map.sqlite
tiles.sqlite
tiles.sqlite-journal

View File

@ -0,0 +1,56 @@
package initialrenderer
import (
"mapserver/mapblockrenderer"
"mapserver/tiledb"
"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, LayerId: 0, Data: result.Data.Bytes(), Mtime: time.Now().Unix()}
tdb.SetTile(&tile)
}
}()
from := coords.MinCoord
to := coords.MaxCoord
start := time.Now()
complete_count := (to - from) * (to - from)
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)
jobs <- mapblockrenderer.JobData{Pos1: pos1, Pos2: pos2}
current_count++
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)
}

57
main.go
View File

@ -3,16 +3,15 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"time"
"mapserver/colormapping" "mapserver/colormapping"
"mapserver/coords"
"mapserver/db" "mapserver/db"
"mapserver/mapblockaccessor" "mapserver/mapblockaccessor"
"mapserver/mapblockrenderer" "mapserver/mapblockrenderer"
"mapserver/params" "mapserver/params"
"mapserver/worldconfig" "mapserver/worldconfig"
"os"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"mapserver/initialrenderer"
"mapserver/tiledb"
) )
const ( const (
@ -60,55 +59,19 @@ func main() {
} }
r := mapblockrenderer.NewMapBlockRenderer(cache, c) r := mapblockrenderer.NewMapBlockRenderer(cache, c)
os.Mkdir("output", 0755)
results := make(chan mapblockrenderer.JobResult, 100) tdb, err := tiledb.NewSqliteAccessor("tiles.sqlite")
jobs := make(chan mapblockrenderer.JobData, 100)
for i := 0; i<3; i++ { if err != nil {
go mapblockrenderer.Worker(&r, jobs, results) panic(err)
} }
os.Mkdir("output", 0755) err = tdb.Migrate()
go func() { if err != nil {
for result := range results { panic(err)
if result.Data.Len() == 0 {
continue
} }
tc := coords.GetTileCoordsFromMapBlock(result.Job.Pos1) initialrenderer.Render(&r, tdb)
f, _ := os.Create(fmt.Sprintf("output/image_%d_%d.png", tc.X, tc.Y))
result.Data.WriteTo(f)
f.Close()
}
}()
from := coords.MinCoord
to := coords.MaxCoord
logrus.WithFields(logrus.Fields{"from": from, "to": to}).Info("Starting rendering")
start := time.Now()
complete_count := (to - from) * (to - from)
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)
jobs <- mapblockrenderer.JobData{Pos1: pos1, Pos2: pos2}
current_count++
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("Render progress")
}
}
}
close(jobs)
defer close(results)
} }