2019-01-11 13:44:17 +03:00
|
|
|
package mapblockrenderer
|
|
|
|
|
|
|
|
import (
|
2019-01-13 18:32:54 +03:00
|
|
|
"fmt"
|
|
|
|
"image/png"
|
2019-01-11 13:44:17 +03:00
|
|
|
"io/ioutil"
|
2019-01-13 18:32:54 +03:00
|
|
|
"mapserver/colormapping"
|
2019-01-11 13:44:17 +03:00
|
|
|
"mapserver/coords"
|
|
|
|
"mapserver/db"
|
2019-01-13 18:32:54 +03:00
|
|
|
"mapserver/mapblockaccessor"
|
|
|
|
"mapserver/testutils"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2019-01-11 13:44:17 +03:00
|
|
|
)
|
|
|
|
|
2019-01-11 16:37:35 +03:00
|
|
|
type JobData struct {
|
2019-01-13 18:32:54 +03:00
|
|
|
pos1, pos2 coords.MapBlockCoords
|
|
|
|
x, z int
|
2019-01-11 16:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func worker(r *MapBlockRenderer, jobs <-chan JobData) {
|
2019-01-13 18:32:54 +03:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
2019-01-11 16:37:35 +03:00
|
|
|
}
|
|
|
|
|
2019-01-11 13:44:17 +03:00
|
|
|
func TestSimpleRender(t *testing.T) {
|
2019-01-13 18:32:54 +03:00
|
|
|
logrus.SetLevel(logrus.InfoLevel)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
jobs <- JobData{pos1: pos1, pos2: pos2, x: x, z: z}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(jobs)
|
2019-01-11 16:37:35 +03:00
|
|
|
|
2019-01-11 13:44:17 +03:00
|
|
|
}
|