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
output
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 (
"flag"
"fmt"
"time"
"mapserver/colormapping"
"mapserver/coords"
"mapserver/db"
"mapserver/mapblockaccessor"
"mapserver/mapblockrenderer"
"mapserver/params"
"mapserver/worldconfig"
"os"
"github.com/sirupsen/logrus"
"mapserver/initialrenderer"
"mapserver/tiledb"
)
const (
@ -60,55 +59,19 @@ func main() {
}
r := mapblockrenderer.NewMapBlockRenderer(cache, c)
os.Mkdir("output", 0755)
results := make(chan mapblockrenderer.JobResult, 100)
jobs := make(chan mapblockrenderer.JobData, 100)
tdb, err := tiledb.NewSqliteAccessor("tiles.sqlite")
for i := 0; i<3; i++ {
go mapblockrenderer.Worker(&r, jobs, results)
if err != nil {
panic(err)
}
os.Mkdir("output", 0755)
err = tdb.Migrate()
go func() {
for result := range results {
if result.Data.Len() == 0 {
continue
}
tc := coords.GetTileCoordsFromMapBlock(result.Job.Pos1)
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")
}
}
if err != nil {
panic(err)
}
close(jobs)
defer close(results)
initialrenderer.Render(&r, tdb)
}