diff --git a/.gitignore b/.gitignore index 77394c4..82cd8d7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ mapserver world.mt output map.sqlite +tiles.sqlite +tiles.sqlite-journal diff --git a/initialrenderer/renderer.go b/initialrenderer/renderer.go new file mode 100644 index 0000000..345cad7 --- /dev/null +++ b/initialrenderer/renderer.go @@ -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) + +} diff --git a/main.go b/main.go index 6411863..2f0d89b 100644 --- a/main.go +++ b/main.go @@ -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) + }