mapserver/mapblockrenderer/renderer_test.go

94 lines
1.7 KiB
Go
Raw Permalink Normal View History

2019-01-11 13:44:17 +03:00
package mapblockrenderer
import (
2019-01-13 18:32:54 +03:00
"fmt"
2019-01-11 13:44:17 +03:00
"io/ioutil"
"mapserver/coords"
2019-02-05 15:13:34 +03:00
"mapserver/db/sqlite"
2019-01-13 18:32:54 +03:00
"mapserver/mapblockaccessor"
"mapserver/testutils"
2023-12-29 18:00:11 +03:00
"mapserver/types"
2019-01-13 18:32:54 +03:00
"os"
"testing"
2019-02-25 09:23:27 +03:00
"time"
2019-06-19 22:12:04 +03:00
2023-01-20 19:44:59 +03:00
"github.com/minetest-go/colormapping"
2019-06-19 22:12:04 +03:00
"github.com/sirupsen/logrus"
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)
2023-12-29 18:00:11 +03:00
layers := []*types.Layer{
2023-10-11 18:35:39 +03:00
{
2019-01-21 15:27:36 +03:00
Id: 0,
Name: "Base",
From: -16,
To: 160,
},
}
2019-01-13 18:32:54 +03:00
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
testutils.CreateTestDatabase(tmpfile.Name())
2019-02-05 15:13:34 +03:00
a, err := sqlite.New(tmpfile.Name())
2019-01-13 18:32:54 +03:00
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
2019-03-21 17:08:30 +03:00
cache := mapblockaccessor.NewMapBlockAccessor(a, 500*time.Millisecond, 1000*time.Millisecond, 1000)
2019-01-13 18:32:54 +03:00
c := colormapping.NewColorMapping()
2023-01-20 20:02:37 +03:00
err = c.LoadDefaults()
2019-01-13 18:32:54 +03:00
if err != nil {
t.Fatal(err)
}
2019-06-20 08:14:14 +03:00
r := NewMapBlockRenderer(cache, c)
2019-04-04 12:05:24 +03:00
os.Mkdir("../test-output", 0755)
2019-01-13 18:32:54 +03:00
2019-01-16 18:15:50 +03:00
results := make(chan JobResult, 100)
2019-01-13 18:32:54 +03:00
jobs := make(chan JobData, 100)
2019-01-16 18:15:50 +03:00
2019-01-17 12:04:09 +03:00
go Worker(r, jobs, results)
go Worker(r, jobs, results)
go Worker(r, jobs, results)
2019-01-16 18:15:50 +03:00
go func() {
for result := range results {
if result.Data.Len() == 0 {
continue
}
2019-01-17 09:45:32 +03:00
2019-01-21 15:27:36 +03:00
tc := coords.GetTileCoordsFromMapBlock(result.Job.Pos1, layers)
2019-04-04 12:05:24 +03:00
f, _ := os.Create(fmt.Sprintf("../test-output/image_%d_%d.png", tc.X, tc.Y))
2019-01-16 18:15:50 +03:00
result.Data.WriteTo(f)
f.Close()
}
}()
2019-01-13 18:32:54 +03:00
2019-01-17 15:35:46 +03:00
from := -10
to := 10
2019-01-13 18:32:54 +03:00
for x := from; x < to; x++ {
for z := from; z < to; z++ {
2023-12-29 18:00:11 +03:00
pos1 := types.NewMapBlockCoords(x, 10, z)
pos2 := types.NewMapBlockCoords(x, -1, z)
2019-01-13 18:32:54 +03:00
2019-01-17 09:45:32 +03:00
jobs <- JobData{Pos1: pos1, Pos2: pos2}
2019-01-13 18:32:54 +03:00
}
}
close(jobs)
2019-01-11 16:37:35 +03:00
2019-01-11 13:44:17 +03:00
}