1
0
forked from MTSR/mapserver
This commit is contained in:
Thomas Rudin 2019-01-13 16:37:03 +01:00
parent 7503c2c281
commit bc223722af
28 changed files with 209 additions and 210 deletions

View File

@ -1,14 +1,14 @@
package colormapping
import (
"mapserver/vfs"
"bufio"
"errors"
"bytes"
"strings"
"strconv"
"errors"
"github.com/sirupsen/logrus"
"image/color"
"mapserver/vfs"
"strconv"
"strings"
)
type ColorMapping struct {
@ -56,7 +56,7 @@ func (m *ColorMapping) LoadBytes(buffer []byte) error {
return err
}
c := color.RGBA{uint8(r),uint8(g),uint8(b), 0xFF}
c := color.RGBA{uint8(r), uint8(g), uint8(b), 0xFF}
m.colors[parts[0]] = &c
}

View File

@ -5,6 +5,7 @@ import (
)
var log *logrus.Entry
func init(){
func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "colormapping"})
}

View File

@ -9,7 +9,6 @@ const (
maxValue = 1<<(numBitsPerComponent-1) - 1
)
func CoordToPlain(c MapBlockCoords) int64 {
return int64(c.Z)<<(2*numBitsPerComponent) +
int64(c.Y)<<numBitsPerComponent +

View File

@ -1,24 +1,24 @@
package coords
import (
"testing"
"github.com/sirupsen/logrus"
"testing"
)
var log *logrus.Entry
func init(){
func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "coords/convert_test"})
}
func testCoordConvert(t *testing.T, mb MapBlockCoords){
log.WithFields(logrus.Fields{"coords":mb}).Info("MapblockCoords")
func testCoordConvert(t *testing.T, mb MapBlockCoords) {
log.WithFields(logrus.Fields{"coords": mb}).Info("MapblockCoords")
p := CoordToPlain(mb)
log.WithFields(logrus.Fields{"plain":p}).Info("MapblockCoords")
log.WithFields(logrus.Fields{"plain": p}).Info("MapblockCoords")
mb2 := PlainToCoord(p)
log.WithFields(logrus.Fields{"coords2":mb2}).Info("MapblockCoords")
log.WithFields(logrus.Fields{"coords2": mb2}).Info("MapblockCoords")
if mb.X != mb2.X {
t.Fatal("X mismatch")
@ -34,7 +34,7 @@ func testCoordConvert(t *testing.T, mb MapBlockCoords){
}
func TestConvertPlainMapBlock(t *testing.T){
func TestConvertPlainMapBlock(t *testing.T) {
testCoordConvert(t, NewMapBlockCoords(10, 0, -10))
testCoordConvert(t, NewMapBlockCoords(-2048, 2047, -10))
testCoordConvert(t, NewMapBlockCoords(-3, 0, 2047)) //0...2047

View File

@ -1,11 +1,11 @@
package coords
type MapBlockCoords struct {
X,Y,Z int
X, Y, Z int
}
func NewMapBlockCoords(x,y,z int) MapBlockCoords {
return MapBlockCoords{X:x, Y:y, Z:z}
func NewMapBlockCoords(x, y, z int) MapBlockCoords {
return MapBlockCoords{X: x, Y: y, Z: z}
}
type MapBlockRange struct {

View File

@ -4,7 +4,6 @@ const (
MAX_ZOOM = 13
)
func GetTileCoordsFromMapBlock(mbc MapBlockCoords) TileCoords {
return TileCoords{X:mbc.X, Y:(mbc.Z + 1) * -1, Zoom:MAX_ZOOM};
return TileCoords{X: mbc.X, Y: (mbc.Z + 1) * -1, Zoom: MAX_ZOOM}
}

View File

@ -5,7 +5,7 @@ import (
)
type TileCoords struct {
X,Y int
X, Y int
Zoom int
}
@ -13,8 +13,8 @@ type TileQuadrants struct {
UpperLeft, UpperRight, LowerLeft, LowerRight TileCoords
}
func NewTileCoords(x,y,zoom int) TileCoords {
return TileCoords{X:x, Y:y, Zoom:zoom}
func NewTileCoords(x, y, zoom int) TileCoords {
return TileCoords{X: x, Y: y, Zoom: zoom}
}
func (tc TileCoords) GetZoomedOutTile() TileCoords {
@ -30,10 +30,10 @@ func (tc TileCoords) GetZoomedQuadrantsFromTile() TileQuadrants {
nextZoomX := tc.X * 2
nextZoomY := tc.Y * 2
upperLeft := TileCoords{X: nextZoomX, Y:nextZoomY, Zoom:nextZoom}
upperRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY, Zoom:nextZoom}
lowerLeft := TileCoords{X: nextZoomX, Y: nextZoomY + 1, Zoom:nextZoom}
lowerRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY + 1, Zoom:nextZoom}
upperLeft := TileCoords{X: nextZoomX, Y: nextZoomY, Zoom: nextZoom}
upperRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY, Zoom: nextZoom}
lowerLeft := TileCoords{X: nextZoomX, Y: nextZoomY + 1, Zoom: nextZoom}
lowerRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY + 1, Zoom: nextZoom}
return TileQuadrants{
UpperLeft: upperLeft,

View File

@ -5,6 +5,7 @@ import (
)
var log *logrus.Entry
func init(){
func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "db"})
}

View File

@ -34,7 +34,7 @@ type Sqlite3Accessor struct {
func (db *Sqlite3Accessor) Migrate() error {
//RW connection
rwdb, err := sql.Open("sqlite3", db.filename + "?mode=rw")
rwdb, err := sql.Open("sqlite3", db.filename+"?mode=rw")
if err != nil {
return err
}
@ -48,7 +48,7 @@ func (db *Sqlite3Accessor) Migrate() error {
}
if !hasMtime {
log.WithFields(logrus.Fields{"filename":db.filename}).Info("Migrating database")
log.WithFields(logrus.Fields{"filename": db.filename}).Info("Migrating database")
start := time.Now()
_, err = rwdb.Exec(migrateScript)
if err != nil {
@ -56,7 +56,7 @@ func (db *Sqlite3Accessor) Migrate() error {
}
t := time.Now()
elapsed := t.Sub(start)
log.WithFields(logrus.Fields{"elapsed":elapsed}).Info("Migration completed")
log.WithFields(logrus.Fields{"elapsed": elapsed}).Info("Migration completed")
}
return nil
@ -64,7 +64,7 @@ func (db *Sqlite3Accessor) Migrate() error {
func convertRows(pos int64, data []byte, mtime int64) Block {
c := coords.PlainToCoord(pos)
return Block{Pos:c, Data:data, Mtime:mtime}
return Block{Pos: c, Data: data, Mtime: mtime}
}
func (db *Sqlite3Accessor) FindLatestBlocks(mintime int64, limit int) ([]Block, error) {
@ -100,9 +100,8 @@ func (db *Sqlite3Accessor) GetBlock(pos coords.MapBlockCoords) (*Block, error) {
return nil, nil
}
func NewSqliteAccessor(filename string) (*Sqlite3Accessor, error) {
db, err := sql.Open("sqlite3", filename + "?mode=ro")
db, err := sql.Open("sqlite3", filename+"?mode=ro")
if err != nil {
return nil, err
}

View File

@ -1,15 +1,14 @@
package db
import (
_ "github.com/mattn/go-sqlite3"
"io/ioutil"
"mapserver/coords"
"mapserver/testutils"
"os"
"testing"
"mapserver/testutils"
_ "github.com/mattn/go-sqlite3"
)
func TestMigrateEmpty(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateEmpty.*.sqlite")
if err != nil {

View File

@ -5,6 +5,7 @@ import (
)
var log *logrus.Entry
func init(){
func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "mapblockaccessor"})
}

View File

@ -1,12 +1,12 @@
package mapblockaccessor
import (
"fmt"
"github.com/patrickmn/go-cache"
"mapserver/coords"
"mapserver/db"
"mapserver/mapblockparser"
"github.com/patrickmn/go-cache"
"time"
"fmt"
)
type MapBlockAccessor struct {

View File

@ -1,13 +1,13 @@
package mapblockaccessor
import (
"os"
"github.com/sirupsen/logrus"
"io/ioutil"
"mapserver/coords"
"testing"
"mapserver/testutils"
"mapserver/db"
"github.com/sirupsen/logrus"
"mapserver/testutils"
"os"
"testing"
)
func TestSimpleAccess(t *testing.T) {

View File

@ -9,14 +9,14 @@ type CountedReader struct {
Count int
}
func (r *CountedReader) Read(p []byte) (int, error){
i,err := r.Reader.Read(p)
func (r *CountedReader) Read(p []byte) (int, error) {
i, err := r.Reader.Read(p)
r.Count += i
return i, err
}
func (r *CountedReader) ReadByte() (byte, error){
i,err := r.Reader.ReadByte()
func (r *CountedReader) ReadByte() (byte, error) {
i, err := r.Reader.ReadByte()
r.Count++
return i, err
}

View File

@ -5,6 +5,7 @@ import (
)
var log *logrus.Entry
func init(){
func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "mapblockaccessor"})
}

View File

@ -8,13 +8,13 @@ type MapBlock struct {
BlockMapping map[int]string
}
func getNodePos(x,y,z int) int {
func getNodePos(x, y, z int) int {
return x + (y * 16) + (z * 256)
}
func (mb *MapBlock) GetNodeName(x,y,z int) string {
pos := getNodePos(x,y,z)
id := readU16(mb.Mapdata, pos * 2)
func (mb *MapBlock) GetNodeName(x, y, z int) string {
pos := getNodePos(x, y, z)
id := readU16(mb.Mapdata, pos*2)
return mb.BlockMapping[id]
}

View File

@ -5,10 +5,10 @@ import (
"bytes"
"compress/zlib"
"errors"
"github.com/sirupsen/logrus"
"io"
"strconv"
"strings"
"github.com/sirupsen/logrus"
)
const (

View File

@ -5,6 +5,7 @@ import (
)
var log *logrus.Entry
func init(){
func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "mapblockrenderer"})
}

View File

@ -1,14 +1,14 @@
package mapblockrenderer
import (
"errors"
"github.com/sirupsen/logrus"
"image"
"image/draw"
"mapserver/colormapping"
"mapserver/coords"
"mapserver/mapblockaccessor"
"image"
"image/draw"
"errors"
"time"
"github.com/sirupsen/logrus"
)
type MapBlockRenderer struct {
@ -23,7 +23,7 @@ func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *co
const (
IMG_SCALE = 16
IMG_SIZE = IMG_SCALE * 16
EXPECTED_BLOCKS_PER_FLAT_MAPBLOCK = 16*16
EXPECTED_BLOCKS_PER_FLAT_MAPBLOCK = 16 * 16
)
func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGBA, error) {
@ -36,10 +36,10 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB
}
start := time.Now()
defer func(){
defer func() {
t := time.Now()
elapsed := t.Sub(start)
log.WithFields(logrus.Fields{"elapsed":elapsed}).Debug("Rendering completed")
log.WithFields(logrus.Fields{"elapsed": elapsed}).Debug("Rendering completed")
}()
upLeft := image.Point{0, 0}
@ -78,7 +78,7 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB
continue
}
nodeName := mb.GetNodeName(x,y,z)
nodeName := mb.GetNodeName(x, y, z)
if nodeName == "" {
continue

View File

@ -1,17 +1,15 @@
package testutils
import (
"database/sql"
"fmt"
_ "github.com/mattn/go-sqlite3"
"io"
"path/filepath"
"os"
"fmt"
"path/filepath"
"runtime"
)
const emptyBlocksScript = `
create table blocks (
pos int,
@ -41,10 +39,9 @@ func copy(src, dst string) error {
func CreateTestDatabase(filename string) error {
_, currentfilename, _, _ := runtime.Caller(0)
return copy(filepath.Dir(currentfilename) + "/testdata/map.sqlite", filename)
return copy(filepath.Dir(currentfilename)+"/testdata/map.sqlite", filename)
}
func CreateEmptyDatabase(filename string) {
db, err := sql.Open("sqlite3", filename)
if err != nil {

View File

@ -5,6 +5,7 @@ import (
)
var log *logrus.Entry
func init(){
func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "tilerenderer"})
}

View File

@ -1,10 +1,10 @@
package tilerenderer
import (
"image"
"mapserver/coords"
"mapserver/mapblockrenderer"
"mapserver/tiledb"
"image"
)
type TileRenderer struct {

View File

@ -1,11 +1,11 @@
package worldconfig
import (
"fmt"
"bufio"
"fmt"
"os"
"strings"
"strconv"
"strings"
)
const (

View File

@ -1,8 +1,8 @@
package worldconfig
import (
"testing"
"fmt"
"testing"
)
func TestParseSqlite(t *testing.T) {