working tile rendering via cli
This commit is contained in:
parent
deff39ea93
commit
7503c2c281
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
mapserver
|
||||
world.mt
|
||||
output
|
||||
map.sqlite
|
||||
|
2
go.mod
2
go.mod
@ -1,8 +1,10 @@
|
||||
module mapserver
|
||||
|
||||
require (
|
||||
github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.10.0
|
||||
github.com/mjibson/esc v0.1.0 // indirect
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/sirupsen/logrus v1.3.0
|
||||
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 // indirect
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -1,5 +1,7 @@
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163 h1:beB+Da4k9B1zmgag78k3k1Bx4L/fdWr5FwNa0f8RxmY=
|
||||
github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
|
||||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
@ -14,6 +16,8 @@ github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 h1:Pn8fQdvx+z1avAi7fdM2kRYWQNxGlavNDSyzrQg2SsU=
|
||||
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
|
||||
|
84
main.go
84
main.go
@ -1,10 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"mapserver/params"
|
||||
"mapserver/worldconfig"
|
||||
"flag"
|
||||
"fmt"
|
||||
"image/png"
|
||||
"mapserver/colormapping"
|
||||
"mapserver/coords"
|
||||
"mapserver/db"
|
||||
"mapserver/mapblockaccessor"
|
||||
"mapserver/mapblockrenderer"
|
||||
"mapserver/params"
|
||||
"mapserver/worldconfig"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -12,7 +21,30 @@ const (
|
||||
Version = "2.0-DEV"
|
||||
)
|
||||
|
||||
type JobData struct {
|
||||
pos1, pos2 coords.MapBlockCoords
|
||||
x, z int
|
||||
}
|
||||
|
||||
func worker(r *mapblockrenderer.MapBlockRenderer, jobs <-chan JobData) {
|
||||
for d := range jobs {
|
||||
img, _ := r.Render(d.pos1, d.pos2)
|
||||
|
||||
if img != nil {
|
||||
f, _ := os.Create(fmt.Sprintf("output/image_%d_%d.png", d.x, d.z))
|
||||
start := time.Now()
|
||||
png.Encode(f, img)
|
||||
f.Close()
|
||||
t := time.Now()
|
||||
elapsed := t.Sub(start)
|
||||
logrus.WithFields(logrus.Fields{"elapsed": elapsed}).Debug("Encoding completed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
|
||||
p := params.Parse()
|
||||
|
||||
if p.Help {
|
||||
@ -27,7 +59,51 @@ func main() {
|
||||
}
|
||||
|
||||
worldcfg := worldconfig.Parse(p.Worlddir + "world.mt")
|
||||
logrus.WithFields(logrus.Fields{"version":Version}).Info("Starting mapserver")
|
||||
logrus.WithFields(logrus.Fields{"version": Version}).Info("Starting mapserver")
|
||||
|
||||
fmt.Println("Config ", worldcfg)
|
||||
if worldcfg.Backend != worldconfig.BACKEND_SQLITE3 {
|
||||
panic("no sqlite3 backend found!")
|
||||
}
|
||||
|
||||
a, err := db.NewSqliteAccessor("map.sqlite")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.Migrate()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cache := mapblockaccessor.NewMapBlockAccessor(a)
|
||||
c := colormapping.NewColorMapping()
|
||||
err = c.LoadVFSColors(false, "/colors.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
r := mapblockrenderer.NewMapBlockRenderer(cache, c)
|
||||
os.Mkdir("output", 0755)
|
||||
|
||||
jobs := make(chan JobData, 100)
|
||||
go worker(&r, jobs)
|
||||
go worker(&r, jobs)
|
||||
go worker(&r, jobs)
|
||||
go worker(&r, jobs)
|
||||
|
||||
from := -500
|
||||
to := 500
|
||||
|
||||
logrus.WithFields(logrus.Fields{"from": from, "to": to}).Info("Starting rendering")
|
||||
|
||||
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 <- JobData{pos1: pos1, pos2: pos2, x: x, z: z}
|
||||
}
|
||||
}
|
||||
|
||||
close(jobs)
|
||||
}
|
||||
|
@ -1,89 +1,89 @@
|
||||
package mapblockrenderer
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"mapserver/colormapping"
|
||||
"mapserver/coords"
|
||||
"testing"
|
||||
"fmt"
|
||||
"mapserver/testutils"
|
||||
"mapserver/db"
|
||||
"mapserver/colormapping"
|
||||
"mapserver/mapblockaccessor"
|
||||
"image/png"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
"mapserver/mapblockaccessor"
|
||||
"mapserver/testutils"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type JobData struct {
|
||||
pos1, pos2 coords.MapBlockCoords
|
||||
x,z int
|
||||
pos1, pos2 coords.MapBlockCoords
|
||||
x, z int
|
||||
}
|
||||
|
||||
func worker(r *MapBlockRenderer, jobs <-chan JobData) {
|
||||
for d := range jobs {
|
||||
img, _ := r.Render(d.pos1, d.pos2)
|
||||
for d := range jobs {
|
||||
img, _ := r.Render(d.pos1, d.pos2)
|
||||
|
||||
if img != nil {
|
||||
f, _ := os.Create(fmt.Sprintf("../output/image_%d_%d.png", d.x, d.z))
|
||||
start := time.Now()
|
||||
png.Encode(f, img)
|
||||
f.Close()
|
||||
t := time.Now()
|
||||
elapsed := t.Sub(start)
|
||||
log.WithFields(logrus.Fields{"elapsed":elapsed}).Debug("Encoding completed")
|
||||
}
|
||||
}
|
||||
if img != nil {
|
||||
f, _ := os.Create(fmt.Sprintf("../output/image_%d_%d.png", d.x, d.z))
|
||||
start := time.Now()
|
||||
png.Encode(f, img)
|
||||
f.Close()
|
||||
t := time.Now()
|
||||
elapsed := t.Sub(start)
|
||||
logrus.WithFields(logrus.Fields{"elapsed": elapsed}).Debug("Encoding completed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleRender(t *testing.T) {
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.Remove(tmpfile.Name())
|
||||
testutils.CreateTestDatabase(tmpfile.Name())
|
||||
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.Remove(tmpfile.Name())
|
||||
testutils.CreateTestDatabase(tmpfile.Name())
|
||||
|
||||
a, err := db.NewSqliteAccessor(tmpfile.Name())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
a, err := db.NewSqliteAccessor(tmpfile.Name())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = a.Migrate()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = a.Migrate()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cache := mapblockaccessor.NewMapBlockAccessor(a)
|
||||
c := colormapping.NewColorMapping()
|
||||
err = c.LoadVFSColors(false, "/colors.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cache := mapblockaccessor.NewMapBlockAccessor(a)
|
||||
c := colormapping.NewColorMapping()
|
||||
err = c.LoadVFSColors(false, "/colors.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := NewMapBlockRenderer(cache, c)
|
||||
os.Mkdir("../output", 0755)
|
||||
r := NewMapBlockRenderer(cache, c)
|
||||
os.Mkdir("../output", 0755)
|
||||
|
||||
jobs := make(chan JobData, 100)
|
||||
go worker(&r, jobs)
|
||||
go worker(&r, jobs)
|
||||
go worker(&r, jobs)
|
||||
jobs := make(chan JobData, 100)
|
||||
go worker(&r, jobs)
|
||||
go worker(&r, jobs)
|
||||
go worker(&r, jobs)
|
||||
|
||||
from := -1
|
||||
to := 1
|
||||
from := -10
|
||||
to := 10
|
||||
|
||||
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 x := from; x < to; x++ {
|
||||
for z := from; z < to; z++ {
|
||||
pos1 := coords.NewMapBlockCoords(x, 10, z)
|
||||
pos2 := coords.NewMapBlockCoords(x, -1, z)
|
||||
|
||||
jobs <- JobData{pos1:pos1, pos2:pos2, x:x, z:z}
|
||||
}
|
||||
}
|
||||
|
||||
close(jobs)
|
||||
jobs <- JobData{pos1: pos1, pos2: pos2, x: x, z: z}
|
||||
}
|
||||
}
|
||||
|
||||
close(jobs)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user