From b7486a4474d8efcaa9f40d63785a3ba637760df9 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Fri, 29 Dec 2023 16:00:11 +0100 Subject: [PATCH] types / coords refactoring --- app/app.go | 2 - app/config.go | 4 +- app/setup.go | 4 - app/types.go | 8 +- areasparser/parser.go | 57 ---- areasparser/parser_test.go | 20 -- areasparser/testdata/areas.json | 323 -------------------- blockaccessor/blockaccessor.go | 43 --- blockaccessor/blockaccessor_test.go | 59 ---- coords/convert.go | 10 +- coords/convert_test.go | 9 +- coords/mapblockcoords_test.go | 7 +- coords/tileconvert.go | 14 +- coords/tileconvert_test.go | 23 +- db/accessor.go | 9 +- db/postgres/initialblocks.go | 6 +- db/postgres/postgres.go | 6 +- db/sqlite/initialblocks.go | 6 +- db/sqlite/sqlite.go | 3 +- db/sqlite/sqlite_test.go | 6 +- go.mod | 1 + go.sum | 2 + mapblockaccessor/get.go | 3 +- mapblockaccessor/legacyblocks.go | 3 +- mapblockaccessor/mapblockaccessor.go | 4 +- mapblockaccessor/mapblockaccessor_test.go | 4 +- mapblockaccessor/mtime.go | 10 +- mapblockaccessor/update.go | 4 +- mapblockrenderer/renderer.go | 10 +- mapblockrenderer/renderer_benchmark_test.go | 18 +- mapblockrenderer/renderer_test.go | 8 +- mapblockrenderer/worker.go | 4 +- mapobject/atm.go | 4 +- mapobject/bones.go | 4 +- mapobject/border.go | 4 +- mapobject/digilinelcd.go | 4 +- mapobject/digiterms.go | 4 +- mapobject/fancyvend.go | 4 +- mapobject/jumpdrive.go | 4 +- mapobject/label.go | 4 +- mapobject/listener.go | 4 +- mapobject/locator.go | 4 +- mapobject/luacontroller.go | 4 +- mapobject/mission.go | 4 +- mapobject/nuclearreactor.go | 4 +- mapobject/poi.go | 4 +- mapobject/privprotector.go | 4 +- mapobject/protector.go | 4 +- mapobject/quarry.go | 4 +- mapobject/sign.go | 4 +- mapobject/smartshop.go | 4 +- mapobject/technicanchor.go | 4 +- mapobject/technicswitch.go | 4 +- mapobject/train.go | 4 +- mapobject/travelnet.go | 4 +- mapobject/xpprotector.go | 4 +- mapobjectdb/accessor.go | 17 +- mapobjectdb/accessor_test.go | 4 +- mapobjectdb/postgres/mapobjects.go | 6 +- mapobjectdb/sqlite/mapobjects.go | 6 +- mapobjectdb/sqlite/mapobjects_test.go | 8 +- tilerenderer/renderer.go | 17 +- tilerenderer/renderer_benchmark_test.go | 4 +- tilerenderer/renderer_test.go | 4 +- {layer => types}/layer.go | 2 +- {coords => types}/mapblockcoords.go | 2 +- types/parsedmapblock.go | 6 +- web/areas.go | 3 +- web/config.go | 6 +- web/mapblock.go | 4 +- web/mapobjects.go | 6 +- web/viewblock.go | 4 +- 72 files changed, 190 insertions(+), 695 deletions(-) delete mode 100644 areasparser/parser.go delete mode 100644 areasparser/parser_test.go delete mode 100644 areasparser/testdata/areas.json delete mode 100644 blockaccessor/blockaccessor.go delete mode 100644 blockaccessor/blockaccessor_test.go rename {layer => types}/layer.go (96%) rename {coords => types}/mapblockcoords.go (97%) diff --git a/app/app.go b/app/app.go index 027b2b6..7be6769 100644 --- a/app/app.go +++ b/app/app.go @@ -1,7 +1,6 @@ package app import ( - "mapserver/blockaccessor" "mapserver/db" "mapserver/eventbus" "mapserver/mapblockaccessor" @@ -26,7 +25,6 @@ type App struct { Settings settings.Settings MapBlockAccessor *mapblockaccessor.MapBlockAccessor - BlockAccessor *blockaccessor.BlockAccessor Colormapping *colormapping.ColorMapping Mapblockrenderer *mapblockrenderer.MapBlockRenderer Tilerenderer *tilerenderer.TileRenderer diff --git a/app/config.go b/app/config.go index 8a06311..a2b5675 100644 --- a/app/config.go +++ b/app/config.go @@ -2,7 +2,7 @@ package app import ( "encoding/json" - "mapserver/layer" + "mapserver/types" "os" "runtime" "sync" @@ -43,7 +43,7 @@ func ParseConfig(filename string) (*Config, error) { SecretKey: RandStringRunes(16), } - layers := []*layer.Layer{ + layers := []*types.Layer{ { Id: 0, Name: "Ground", diff --git a/app/setup.go b/app/setup.go index 46d1d74..9b022d8 100644 --- a/app/setup.go +++ b/app/setup.go @@ -1,7 +1,6 @@ package app import ( - "mapserver/blockaccessor" "mapserver/db/postgres" "mapserver/db/sqlite" "mapserver/eventbus" @@ -89,9 +88,6 @@ func Setup(p params.ParamsType, cfg *Config) *App { expireDuration, purgeDuration, cfg.MapBlockAccessorCfg.MaxItems) - // block accessor - a.BlockAccessor = blockaccessor.New(a.MapBlockAccessor) - //color mapping a.Colormapping = colormapping.NewColorMapping() err = a.Colormapping.LoadDefaults() diff --git a/app/types.go b/app/types.go index a930a91..df542de 100644 --- a/app/types.go +++ b/app/types.go @@ -1,8 +1,6 @@ package app -import ( - "mapserver/layer" -) +import "mapserver/types" type Config struct { ConfigVersion int `json:"configversion"` @@ -15,7 +13,7 @@ type Config struct { EnableMediaRepository bool `json:"enablemediarepository"` Webdev bool `json:"webdev"` WebApi *WebApiConfig `json:"webapi"` - Layers []*layer.Layer `json:"layers"` + Layers []*types.Layer `json:"layers"` RenderingFetchLimit int `json:"renderingfetchlimit"` RenderingJobs int `json:"renderingjobs"` RenderingQueue int `json:"renderingqueue"` @@ -26,7 +24,7 @@ type Config struct { Skins *SkinsConfig `json:"skins"` WorldPath string `json:"worldpath"` DataPath string `json:"datapath"` - ColorsTxtPath string `json:colorstxtpath` + ColorsTxtPath string `json:"colorstxtpath"` } type MapBlockAccessorConfig struct { diff --git a/areasparser/parser.go b/areasparser/parser.go deleted file mode 100644 index 3360aa8..0000000 --- a/areasparser/parser.go +++ /dev/null @@ -1,57 +0,0 @@ -package areasparser - -import ( - "bytes" - "encoding/json" - "os" -) - -type GenericPos struct { - X int `json:"x"` - Y int `json:"y"` - Z int `json:"z"` -} - -type Area struct { - Owner string `json:"owner"` - Name string `json:"name"` - Parent int `json:"parent"` - Pos1 *GenericPos `json:"pos1"` - Pos2 *GenericPos `json:"pos2"` -} - -func getInt(o interface{}) int { - v, _ := o.(float64) - return int(v) -} - -func (pos *GenericPos) UnmarshalJSON(data []byte) error { - m := make(map[string]interface{}) - err := json.Unmarshal(data, &m) - if err != nil { - return err - } - - // float-like to int workaround - pos.X = getInt(m["x"]) - pos.Y = getInt(m["y"]) - pos.Z = getInt(m["z"]) - - return nil -} - -func ParseFile(filename string) ([]*Area, error) { - content, err := os.ReadFile(filename) - if err != nil { - return nil, err - } - - return Parse(content) -} - -func Parse(data []byte) ([]*Area, error) { - areas := make([]*Area, 0) - json.NewDecoder(bytes.NewReader(data)).Decode(&areas) - - return areas, nil -} diff --git a/areasparser/parser_test.go b/areasparser/parser_test.go deleted file mode 100644 index d21ec19..0000000 --- a/areasparser/parser_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package areasparser - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestParse(t *testing.T) { - a, err := ParseFile("testdata/areas.json") - assert.NoError(t, err) - assert.True(t, len(a) > 1) - - area := a[0] - assert.Equal(t, "ilai_house", area.Name) - assert.Equal(t, "ilai", area.Owner) - assert.NotNil(t, area.Pos1) - assert.NotNil(t, area.Pos2) - assert.Equal(t, 4970, area.Pos1.X) -} diff --git a/areasparser/testdata/areas.json b/areasparser/testdata/areas.json deleted file mode 100644 index 8eb44d6..0000000 --- a/areasparser/testdata/areas.json +++ /dev/null @@ -1,323 +0,0 @@ -[ - { - "name": "ilai_house", - "owner": "ilai", - "pos1": { - "x": 4970.0, - "y": 8.0, - "z": 88.0 - }, - "pos2": { - "x": 4983.0, - "y": 16.0, - "z": 99.0 - } - }, - { - "name": "temple", - "owner": "Lukc", - "pos1": { - "x": -1911.0, - "y": 18.0, - "z": -221.0 - }, - "pos2": { - "x": -1718.0, - "y": 68.0, - "z": -50.0 - } - }, - { - "name": "temple", - "owner": "BuckarooBanzai", - "parent": 2.0, - "pos1": { - "x": -1911.0, - "y": 18.0, - "z": -221.0 - }, - "pos2": { - "x": -1718.0, - "y": 68.0, - "z": -50.0 - } - }, - { - "name": "Spaceshipyard", - "owner": "Lukc", - "pos1": { - "x": -1784.0, - "y": -49.0, - "z": -1174.0 - }, - "pos2": { - "x": -1688.0, - "y": 58.0, - "z": -1068.0 - } - }, - { - "name": "Arena", - "owner": "Lukc", - "pos1": { - "x": -1860.0, - "y": -369.0, - "z": -1162.0 - }, - "pos2": { - "x": -1751.0, - "y": -310.0, - "z": -1061.0 - } - }, - { - "name": "Spaceshipyard", - "owner": "T4im", - "parent": 4.0, - "pos1": { - "x": -1784.0, - "y": -49.0, - "z": -1174.0 - }, - "pos2": { - "x": -1688.0, - "y": 58.0, - "z": -1068.0 - } - }, - { - "name": "temple", - "owner": "T4im", - "parent": 2.0, - "pos1": { - "x": -1911.0, - "y": 18.0, - "z": -221.0 - }, - "pos2": { - "x": -1718.0, - "y": 68.0, - "z": -50.0 - } - }, - { - "name": "Spaceshipyard", - "owner": "BuckarooBanzai", - "parent": 4.0, - "pos1": { - "x": -1784.0, - "y": -49.0, - "z": -1174.0 - }, - "pos2": { - "x": -1688.0, - "y": 58.0, - "z": -1068.0 - } - }, - { - "name": "Arena", - "owner": "T4im", - "parent": 5.0, - "pos1": { - "x": -1860.0, - "y": -369.0, - "z": -1162.0 - }, - "pos2": { - "x": -1751.0, - "y": -310.0, - "z": -1061.0 - } - }, - { - "name": "Humboldt Research Station", - "owner": "T4im", - "pos1": { - "x": -624.0, - "y": -32.0, - "z": 48.0 - }, - "pos2": { - "x": -369.0, - "y": 127.0, - "z": 351.0 - } - }, - { - "name": "centrifuge cascade", - "owner": "pipo", - "pos1": { - "x": -2995.0, - "y": -40.0, - "z": -3003.0 - }, - "pos2": { - "x": -2958.0, - "y": -26.0, - "z": -2990.0 - } - }, - { - "name": "centrifuge cascade", - "owner": "barsik", - "parent": 11.0, - "pos1": { - "x": -2995.0, - "y": -40.0, - "z": -3003.0 - }, - "pos2": { - "x": -2958.0, - "y": -26.0, - "z": -2990.0 - } - }, - { - "name": "centrifuge cascade", - "owner": "BuckarooBanzai", - "parent": 11.0, - "pos1": { - "x": -2995.0, - "y": -40.0, - "z": -3003.0 - }, - "pos2": { - "x": -2958.0, - "y": -26.0, - "z": -2990.0 - } - }, - { - "name": "centrifuge cascade", - "owner": "T4im", - "parent": 11.0, - "pos1": { - "x": -2995.0, - "y": -40.0, - "z": -3003.0 - }, - "pos2": { - "x": -2958.0, - "y": -26.0, - "z": -2990.0 - } - }, - { - "name": "centrifuge cascade", - "owner": "Lukc", - "parent": 11.0, - "pos1": { - "x": -2995.0, - "y": -40.0, - "z": -3003.0 - }, - "pos2": { - "x": -2958.0, - "y": -26.0, - "z": -2990.0 - } - }, - { - "name": "Spaceshipyard", - "owner": "pipo", - "parent": 6.0, - "pos1": { - "x": -1784.0, - "y": -49.0, - "z": -1174.0 - }, - "pos2": { - "x": -1688.0, - "y": 58.0, - "z": -1068.0 - } - }, - { - "name": "Emerald extention", - "owner": "Emerald", - "pos1": { - "x": 5055.0, - "y": 8.0, - "z": 48.0 - }, - "pos2": { - "x": 5059.0, - "y": 10.0, - "z": 54.0 - } - }, - { - "name": "tower1", - "owner": "pipo", - "parent": 19.0, - "pos1": { - "x": -14.0, - "y": -126.0, - "z": 587.0 - }, - "pos2": { - "x": 17.0, - "y": 103.0, - "z": 617.0 - } - }, - { - "name": "tower1", - "owner": "barsik", - "pos1": { - "x": -14.0, - "y": -126.0, - "z": 587.0 - }, - "pos2": { - "x": 17.0, - "y": 103.0, - "z": 617.0 - } - }, - { - "name": "tower1", - "owner": "BuckarooBanzai", - "parent": 19.0, - "pos1": { - "x": -14.0, - "y": -126.0, - "z": 587.0 - }, - "pos2": { - "x": 17.0, - "y": 103.0, - "z": 617.0 - } - }, - { - "name": "tower1", - "owner": "T4im", - "parent": 19.0, - "pos1": { - "x": -14.0, - "y": -126.0, - "z": 587.0 - }, - "pos2": { - "x": 17.0, - "y": 103.0, - "z": 617.0 - } - }, - { - "name": "Arboretum", - "owner": "pipo", - "pos1": { - "x": -1734.0, - "y": 7.0, - "z": 697.0 - }, - "pos2": { - "x": -1604.0, - "y": 50.0, - "z": 784.0 - } - } -] \ No newline at end of file diff --git a/blockaccessor/blockaccessor.go b/blockaccessor/blockaccessor.go deleted file mode 100644 index 52575d1..0000000 --- a/blockaccessor/blockaccessor.go +++ /dev/null @@ -1,43 +0,0 @@ -package blockaccessor - -import ( - "mapserver/coords" - "mapserver/mapblockaccessor" -) - -func New(mba *mapblockaccessor.MapBlockAccessor) *BlockAccessor { - return &BlockAccessor{mba: mba} -} - -type BlockAccessor struct { - mba *mapblockaccessor.MapBlockAccessor -} - -type Block struct { - Name string - //TODO: param1, param2 -} - -func (this *BlockAccessor) GetBlock(x, y, z int) (*Block, error) { - - mbc := coords.NewMapBlockCoordsFromBlock(x, y, z) - mapblock, err := this.mba.GetMapBlock(mbc) - - if err != nil { - return nil, err - } - - if mapblock == nil { - return nil, nil - } - - relx := x % 16 - rely := y % 16 - relz := z % 16 - - block := Block{ - Name: mapblock.GetNodeName(relx, rely, relz), - } - - return &block, nil -} diff --git a/blockaccessor/blockaccessor_test.go b/blockaccessor/blockaccessor_test.go deleted file mode 100644 index 28557f0..0000000 --- a/blockaccessor/blockaccessor_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package blockaccessor - -import ( - "fmt" - "io/ioutil" - "mapserver/db/sqlite" - "mapserver/mapblockaccessor" - "mapserver/testutils" - "os" - "testing" - "time" - - "github.com/sirupsen/logrus" -) - -func TestSimpleAccess(t *testing.T) { - logrus.SetLevel(logrus.DebugLevel) - - tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite") - if err != nil { - panic(err) - } - defer os.Remove(tmpfile.Name()) - testutils.CreateTestDatabase(tmpfile.Name()) - - a, err := sqlite.New(tmpfile.Name()) - if err != nil { - panic(err) - } - - err = a.Migrate() - if err != nil { - panic(err) - } - - mba := mapblockaccessor.NewMapBlockAccessor(a, 500*time.Millisecond, 1000*time.Millisecond, 1000) - - if mba == nil { - t.Fatal("Mapblockaccessor is nil") - } - - ba := New(mba) - - if ba == nil { - t.Fatal("blockaccessor is nil") - } - - block, err := ba.GetBlock(0, 2, 0) - - if err != nil { - panic(err) - } - - if block == nil { - t.Fatal("block is nil") - } - - fmt.Println(block.Name) -} diff --git a/coords/convert.go b/coords/convert.go index 1eaa323..18a0201 100644 --- a/coords/convert.go +++ b/coords/convert.go @@ -1,6 +1,8 @@ package coords -//https://bitbucket.org/s_l_teichmann/mtsatellite/src/e1bf980a2b278c570b3f44f9452c9c087558acb3/common/coords.go?at=default&fileviewer=file-view-default +import "mapserver/types" + +// https://bitbucket.org/s_l_teichmann/mtsatellite/src/e1bf980a2b278c570b3f44f9452c9c087558acb3/common/coords.go?at=default&fileviewer=file-view-default const ( numBitsPerComponent = 12 modulo = 1 << numBitsPerComponent @@ -11,7 +13,7 @@ const ( MinPlainCoord = -34351347711 ) -func CoordToPlain(c *MapBlockCoords) int64 { +func CoordToPlain(c *types.MapBlockCoords) int64 { return int64(c.Z)<<(2*numBitsPerComponent) + int64(c.Y)<> numBitsPerComponent c.Y = unsignedToSigned(pythonModulo(int16(i))) diff --git a/coords/convert_test.go b/coords/convert_test.go index 8798f7a..c92c063 100644 --- a/coords/convert_test.go +++ b/coords/convert_test.go @@ -1,6 +1,7 @@ package coords import ( + "mapserver/types" "testing" "github.com/sirupsen/logrus" @@ -13,7 +14,7 @@ func init() { } func TestMinCoord(t *testing.T) { - c := NewMapBlockCoords(MinCoord, MinCoord, MinCoord) + c := types.NewMapBlockCoords(types.MinCoord, types.MinCoord, types.MinCoord) pc := CoordToPlain(c) log.WithFields(logrus.Fields{"coords": c, "plain": pc, "plain-1": pc - 1}).Info("TestMinCoord") @@ -22,7 +23,7 @@ func TestMinCoord(t *testing.T) { } } -func testCoordConvert(t *testing.T, mb *MapBlockCoords) { +func testCoordConvert(t *testing.T, mb *types.MapBlockCoords) { log.WithFields(logrus.Fields{"coords": mb}).Info("MapblockCoords") p := CoordToPlain(mb) @@ -45,6 +46,6 @@ func testCoordConvert(t *testing.T, mb *MapBlockCoords) { } -func TestZeorCoord(t *testing.T) { - testCoordConvert(t, NewMapBlockCoords(0, 0, 0)) +func TestZeroCoord(t *testing.T) { + testCoordConvert(t, types.NewMapBlockCoords(0, 0, 0)) } diff --git a/coords/mapblockcoords_test.go b/coords/mapblockcoords_test.go index e2c8933..3015386 100644 --- a/coords/mapblockcoords_test.go +++ b/coords/mapblockcoords_test.go @@ -1,23 +1,24 @@ package coords import ( + "mapserver/types" "testing" ) func TestNewMapBlockCoordsFromBlock(t *testing.T) { - c := NewMapBlockCoordsFromBlock(1, 1, 1) + c := types.NewMapBlockCoordsFromBlock(1, 1, 1) if c.X != 0 || c.Y != 0 || c.Z != 0 { t.Fatal("mismatch", c) } - c = NewMapBlockCoordsFromBlock(16, 1, 1) + c = types.NewMapBlockCoordsFromBlock(16, 1, 1) if c.X != 1 || c.Y != 0 || c.Z != 0 { t.Fatal("mismatch", c) } - c = NewMapBlockCoordsFromBlock(16, 1, -1) + c = types.NewMapBlockCoordsFromBlock(16, 1, -1) if c.X != 1 || c.Y != 0 || c.Z != -1 { t.Fatal("mismatch", c) diff --git a/coords/tileconvert.go b/coords/tileconvert.go index 3e8b743..0fb377b 100644 --- a/coords/tileconvert.go +++ b/coords/tileconvert.go @@ -1,7 +1,7 @@ package coords import ( - "mapserver/layer" + "mapserver/types" "math" ) @@ -9,10 +9,10 @@ const ( MAX_ZOOM = 13 ) -func GetTileCoordsFromMapBlock(mbc *MapBlockCoords, layers []*layer.Layer) *TileCoords { +func GetTileCoordsFromMapBlock(mbc *types.MapBlockCoords, layers []*types.Layer) *TileCoords { tc := TileCoords{X: mbc.X, Y: (mbc.Z + 1) * -1, Zoom: MAX_ZOOM} - currentLayer := layer.FindLayerByY(layers, mbc.Y) + currentLayer := types.FindLayerByY(layers, mbc.Y) if currentLayer == nil { return nil @@ -23,7 +23,7 @@ func GetTileCoordsFromMapBlock(mbc *MapBlockCoords, layers []*layer.Layer) *Tile return &tc } -func GetMapBlockRangeFromTile(tc *TileCoords, y int) *MapBlockRange { +func GetMapBlockRangeFromTile(tc *TileCoords, y int) *types.MapBlockRange { scaleDiff := float64(MAX_ZOOM - tc.Zoom) scale := int(math.Pow(2, scaleDiff)) @@ -33,8 +33,8 @@ func GetMapBlockRangeFromTile(tc *TileCoords, y int) *MapBlockRange { mapBlockX2 := mapBlockX1 + scale - 1 mapBlockZ2 := (mapBlockZ1 + ((scale - 1) * -1)) - return &MapBlockRange{ - Pos1: NewMapBlockCoords(mapBlockX1, y, mapBlockZ1), - Pos2: NewMapBlockCoords(mapBlockX2, y, mapBlockZ2), + return &types.MapBlockRange{ + Pos1: types.NewMapBlockCoords(mapBlockX1, y, mapBlockZ1), + Pos2: types.NewMapBlockCoords(mapBlockX2, y, mapBlockZ2), } } diff --git a/coords/tileconvert_test.go b/coords/tileconvert_test.go index e6be805..8476e3b 100644 --- a/coords/tileconvert_test.go +++ b/coords/tileconvert_test.go @@ -1,15 +1,16 @@ package coords import ( - "github.com/stretchr/testify/assert" - "mapserver/layer" + "mapserver/types" "testing" + + "github.com/stretchr/testify/assert" ) func TestConvertMapblockToTile1(t *testing.T) { - mbc := NewMapBlockCoords(0, 0, 0) - layers := []*layer.Layer{ - &layer.Layer{ + mbc := types.NewMapBlockCoords(0, 0, 0) + layers := []*types.Layer{ + { Id: 0, Name: "Base", From: -16, @@ -47,9 +48,9 @@ func TestGetMapBlockRangeFromTile(t *testing.T) { } func TestConvertMapblockToTile2(t *testing.T) { - mbc := NewMapBlockCoords(1, 0, 1) - layers := []*layer.Layer{ - &layer.Layer{ + mbc := types.NewMapBlockCoords(1, 0, 1) + layers := []*types.Layer{ + { Id: 0, Name: "Base", From: -16, @@ -73,9 +74,9 @@ func TestConvertMapblockToTile2(t *testing.T) { } func TestConvertMapblockToTile3(t *testing.T) { - mbc := NewMapBlockCoords(-1, 0, -1) - layers := []*layer.Layer{ - &layer.Layer{ + mbc := types.NewMapBlockCoords(-1, 0, -1) + layers := []*types.Layer{ + { Id: 0, Name: "Base", From: -16, diff --git a/db/accessor.go b/db/accessor.go index 4db6e1b..788aeb4 100644 --- a/db/accessor.go +++ b/db/accessor.go @@ -1,13 +1,12 @@ package db import ( - "mapserver/coords" - "mapserver/layer" "mapserver/settings" + "mapserver/types" ) type Block struct { - Pos *coords.MapBlockCoords + Pos *types.MapBlockCoords Data []byte Mtime int64 } @@ -25,6 +24,6 @@ type DBAccessor interface { GetTimestamp() (int64, error) FindBlocksByMtime(gtmtime int64, limit int) ([]*Block, error) - FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*InitialBlocksResult, error) - GetBlock(pos *coords.MapBlockCoords) (*Block, error) + FindNextInitialBlocks(s settings.Settings, layers []*types.Layer, limit int) (*InitialBlocksResult, error) + GetBlock(pos *types.MapBlockCoords) (*Block, error) } diff --git a/db/postgres/initialblocks.go b/db/postgres/initialblocks.go index 9fd0529..c7bad15 100644 --- a/db/postgres/initialblocks.go +++ b/db/postgres/initialblocks.go @@ -3,8 +3,8 @@ package postgres import ( "mapserver/coords" "mapserver/db" - "mapserver/layer" "mapserver/settings" + "mapserver/types" "math" "github.com/sirupsen/logrus" @@ -53,7 +53,7 @@ func (a *PostgresAccessor) countBlocks(x1, y1, z1, x2, y2, z2 int) (int, error) //Zoom 9: //10 mapblocks height * 16 * 16 == 2560 -func (a *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) { +func (a *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers []*types.Layer, limit int) (*db.InitialBlocksResult, error) { lastlayer := s.GetInt(SETTING_LAST_LAYER, 0) lastxblock := s.GetInt(SETTING_LAST_X_BLOCK, -129) @@ -88,7 +88,7 @@ func (a *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers []* } tc := coords.NewTileCoords(lastxblock, lastyblock, 9, lastlayer) - currentlayer := layer.FindLayerById(layers, lastlayer) + currentlayer := types.FindLayerById(layers, lastlayer) tcr := coords.GetMapBlockRangeFromTile(tc, 0) tcr.Pos1.Y = currentlayer.From diff --git a/db/postgres/postgres.go b/db/postgres/postgres.go index 13a4da1..1fa906f 100644 --- a/db/postgres/postgres.go +++ b/db/postgres/postgres.go @@ -3,8 +3,8 @@ package postgres import ( "database/sql" "embed" - "mapserver/coords" "mapserver/db" + "mapserver/types" "time" _ "github.com/lib/pq" @@ -47,7 +47,7 @@ func (db *PostgresAccessor) Migrate() error { } func convertRows(posx, posy, posz int, data []byte, mtime int64) *db.Block { - c := coords.NewMapBlockCoords(posx, posy, posz) + c := types.NewMapBlockCoords(posx, posy, posz) return &db.Block{Pos: c, Data: data, Mtime: mtime} } @@ -122,7 +122,7 @@ func (a *PostgresAccessor) GetTimestamp() (int64, error) { return 0, nil } -func (a *PostgresAccessor) GetBlock(pos *coords.MapBlockCoords) (*db.Block, error) { +func (a *PostgresAccessor) GetBlock(pos *types.MapBlockCoords) (*db.Block, error) { rows, err := a.db.Query(getBlockQuery, pos.X, pos.Y, pos.Z) if err != nil { return nil, err diff --git a/db/sqlite/initialblocks.go b/db/sqlite/initialblocks.go index 8969d8b..66355f8 100644 --- a/db/sqlite/initialblocks.go +++ b/db/sqlite/initialblocks.go @@ -3,8 +3,8 @@ package sqlite import ( "mapserver/coords" "mapserver/db" - "mapserver/layer" "mapserver/settings" + "mapserver/types" ) const ( @@ -21,7 +21,7 @@ order by b.pos asc, b.mtime asc limit ? ` -func (a *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) { +func (a *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers []*types.Layer, limit int) (*db.InitialBlocksResult, error) { result := &db.InitialBlocksResult{} blocks := make([]*db.Block, 0) @@ -70,7 +70,7 @@ func (a *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers []*l lastpos = pos blockcoordy := mb.Pos.Y - currentlayer := layer.FindLayerByY(layers, blockcoordy) + currentlayer := types.FindLayerByY(layers, blockcoordy) if currentlayer != nil { blocks = append(blocks, mb) diff --git a/db/sqlite/sqlite.go b/db/sqlite/sqlite.go index cd74f48..cc5f3d0 100644 --- a/db/sqlite/sqlite.go +++ b/db/sqlite/sqlite.go @@ -6,6 +6,7 @@ import ( "errors" "mapserver/coords" "mapserver/db" + "mapserver/types" "time" "github.com/sirupsen/logrus" @@ -140,7 +141,7 @@ func (db *Sqlite3Accessor) GetTimestamp() (int64, error) { return 0, nil } -func (db *Sqlite3Accessor) GetBlock(pos *coords.MapBlockCoords) (*db.Block, error) { +func (db *Sqlite3Accessor) GetBlock(pos *types.MapBlockCoords) (*db.Block, error) { ppos := coords.CoordToPlain(pos) rows, err := db.db.Query(getBlockQuery, ppos) diff --git a/db/sqlite/sqlite_test.go b/db/sqlite/sqlite_test.go index 0e0b846..1a9fe37 100644 --- a/db/sqlite/sqlite_test.go +++ b/db/sqlite/sqlite_test.go @@ -2,8 +2,8 @@ package sqlite import ( "io/ioutil" - "mapserver/coords" "mapserver/testutils" + "mapserver/types" "os" "testing" @@ -11,7 +11,7 @@ import ( ) func TestMigrateEmpty(t *testing.T) { - tmpfile, err := ioutil.TempFile("", "TestMigrateEmpty.*.sqlite") + tmpfile, err := os.CreateTemp("", "TestMigrateEmpty.*.sqlite") if err != nil { panic(err) } @@ -64,7 +64,7 @@ func TestMigrateAndQuery(t *testing.T) { panic(err) } - block, err := a.GetBlock(coords.NewMapBlockCoords(0, 0, 0)) + block, err := a.GetBlock(types.NewMapBlockCoords(0, 0, 0)) if err != nil { panic(err) diff --git a/go.mod b/go.mod index 514ee58..eaccfaf 100644 --- a/go.mod +++ b/go.mod @@ -30,6 +30,7 @@ require ( github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-sqlite3 v1.14.16 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect + github.com/minetest-go/areasparser v1.0.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect github.com/prometheus/common v0.44.0 // indirect diff --git a/go.sum b/go.sum index 9b28c16..f1ddfad 100644 --- a/go.sum +++ b/go.sum @@ -184,6 +184,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/minetest-go/areasparser v1.0.5 h1:kyfb7mk4S7Gvx5N42uJK8ze3BAbfj8uyLsv2Tuy43MQ= +github.com/minetest-go/areasparser v1.0.5/go.mod h1:NvohBk60WBrAbfvgmJccCEblz9I/Ygba4k9V81rwoNc= github.com/minetest-go/colormapping v1.0.2 h1:VpbSt6olNcb0yFw3z6wQC/RnZtJVRvtqhpzG+X8mrrc= github.com/minetest-go/colormapping v1.0.2/go.mod h1:arMBjO6+z8+yhLvrsX4tCnYq5fzGcPFUOj/4Xb78Ktc= github.com/minetest-go/mapparser v0.1.8 h1:tmkno1Qi8nIdjQXJLlnq38uVGygZWA8i3ilre/bB9W8= diff --git a/mapblockaccessor/get.go b/mapblockaccessor/get.go index dda7ae1..e6df226 100644 --- a/mapblockaccessor/get.go +++ b/mapblockaccessor/get.go @@ -1,7 +1,6 @@ package mapblockaccessor import ( - "mapserver/coords" "mapserver/eventbus" "mapserver/types" "sync" @@ -14,7 +13,7 @@ import ( var lock = &sync.RWMutex{} -func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapparser.MapBlock, error) { +func (a *MapBlockAccessor) GetMapBlock(pos *types.MapBlockCoords) (*mapparser.MapBlock, error) { cache_enabled := a.maxcount > 0 key := getKey(pos) diff --git a/mapblockaccessor/legacyblocks.go b/mapblockaccessor/legacyblocks.go index 6e8d10c..234b663 100644 --- a/mapblockaccessor/legacyblocks.go +++ b/mapblockaccessor/legacyblocks.go @@ -2,7 +2,6 @@ package mapblockaccessor import ( "mapserver/eventbus" - "mapserver/layer" "mapserver/settings" "mapserver/types" @@ -19,7 +18,7 @@ type FindNextLegacyBlocksResult struct { LastMtime int64 } -func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*FindNextLegacyBlocksResult, error) { +func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []*types.Layer, limit int) (*FindNextLegacyBlocksResult, error) { nextResult, err := a.accessor.FindNextInitialBlocks(s, layers, limit) diff --git a/mapblockaccessor/mapblockaccessor.go b/mapblockaccessor/mapblockaccessor.go index d867da2..da6397e 100644 --- a/mapblockaccessor/mapblockaccessor.go +++ b/mapblockaccessor/mapblockaccessor.go @@ -2,9 +2,9 @@ package mapblockaccessor import ( "fmt" - "mapserver/coords" "mapserver/db" "mapserver/eventbus" + "mapserver/types" "time" @@ -18,7 +18,7 @@ type MapBlockAccessor struct { maxcount int } -func getKey(pos *coords.MapBlockCoords) string { +func getKey(pos *types.MapBlockCoords) string { return fmt.Sprintf("Coord %d/%d/%d", pos.X, pos.Y, pos.Z) } diff --git a/mapblockaccessor/mapblockaccessor_test.go b/mapblockaccessor/mapblockaccessor_test.go index af9a2f8..0105c0f 100644 --- a/mapblockaccessor/mapblockaccessor_test.go +++ b/mapblockaccessor/mapblockaccessor_test.go @@ -2,9 +2,9 @@ package mapblockaccessor import ( "io/ioutil" - "mapserver/coords" "mapserver/db/sqlite" "mapserver/testutils" + "mapserver/types" "os" "testing" "time" @@ -33,7 +33,7 @@ func TestSimpleAccess(t *testing.T) { } cache := NewMapBlockAccessor(a, 500*time.Millisecond, 1000*time.Millisecond, 1000) - mb, err := cache.GetMapBlock(coords.NewMapBlockCoords(0, 0, 0)) + mb, err := cache.GetMapBlock(types.NewMapBlockCoords(0, 0, 0)) if err != nil { panic(err) diff --git a/mapblockaccessor/mtime.go b/mapblockaccessor/mtime.go index 31c9ae5..a00b9b6 100644 --- a/mapblockaccessor/mtime.go +++ b/mapblockaccessor/mtime.go @@ -1,9 +1,7 @@ package mapblockaccessor import ( - "mapserver/coords" "mapserver/eventbus" - "mapserver/layer" "mapserver/types" "github.com/minetest-go/mapparser" @@ -14,13 +12,13 @@ import ( type FindMapBlocksByMtimeResult struct { HasMore bool - LastPos *coords.MapBlockCoords + LastPos *types.MapBlockCoords LastMtime int64 List []*types.ParsedMapblock UnfilteredCount int } -func (a *MapBlockAccessor) FindMapBlocksByMtime(lastmtime int64, limit int, layerfilter []*layer.Layer) (*FindMapBlocksByMtimeResult, error) { +func (a *MapBlockAccessor) FindMapBlocksByMtime(lastmtime int64, limit int, layerfilter []*types.Layer) (*FindMapBlocksByMtimeResult, error) { fields := logrus.Fields{ "lastmtime": lastmtime, @@ -41,7 +39,7 @@ func (a *MapBlockAccessor) FindMapBlocksByMtime(lastmtime int64, limit int, laye result := FindMapBlocksByMtimeResult{} mblist := make([]*types.ParsedMapblock, 0) - var newlastpos *coords.MapBlockCoords + var newlastpos *types.MapBlockCoords result.HasMore = len(blocks) == limit result.UnfilteredCount = len(blocks) @@ -51,7 +49,7 @@ func (a *MapBlockAccessor) FindMapBlocksByMtime(lastmtime int64, limit int, laye result.LastMtime = block.Mtime } - currentLayer := layer.FindLayerByY(layerfilter, block.Pos.Y) + currentLayer := types.FindLayerByY(layerfilter, block.Pos.Y) if currentLayer == nil { continue diff --git a/mapblockaccessor/update.go b/mapblockaccessor/update.go index ba81796..fa62b4b 100644 --- a/mapblockaccessor/update.go +++ b/mapblockaccessor/update.go @@ -1,13 +1,13 @@ package mapblockaccessor import ( - "mapserver/coords" + "mapserver/types" "github.com/minetest-go/mapparser" cache "github.com/patrickmn/go-cache" ) -func (a *MapBlockAccessor) Update(pos *coords.MapBlockCoords, mb *mapparser.MapBlock) { +func (a *MapBlockAccessor) Update(pos *types.MapBlockCoords, mb *mapparser.MapBlock) { key := getKey(pos) cacheBlockCount.Inc() a.blockcache.Set(key, mb, cache.DefaultExpiration) diff --git a/mapblockrenderer/renderer.go b/mapblockrenderer/renderer.go index 90e9f04..3118f44 100644 --- a/mapblockrenderer/renderer.go +++ b/mapblockrenderer/renderer.go @@ -4,8 +4,8 @@ import ( "errors" "image" "image/color" - "mapserver/coords" "mapserver/mapblockaccessor" + "mapserver/types" "time" "github.com/minetest-go/colormapping" @@ -73,7 +73,7 @@ func addColorComponent(c *color.RGBA, value int) *color.RGBA { } } -func (r *MapBlockRenderer) Render(pos1, pos2 *coords.MapBlockCoords) (*image.NRGBA, error) { +func (r *MapBlockRenderer) Render(pos1, pos2 *types.MapBlockCoords) (*image.NRGBA, error) { if pos1.X != pos2.X { return nil, errors.New("x does not line up") } @@ -111,7 +111,7 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *coords.MapBlockCoords) (*image.NRG } for mapBlockY := maxY; mapBlockY >= minY; mapBlockY-- { - currentPos := coords.NewMapBlockCoords(pos1.X, mapBlockY, pos1.Z) + currentPos := types.NewMapBlockCoords(pos1.X, mapBlockY, pos1.Z) mb, err := r.accessor.GetMapBlock(currentPos) if err != nil { @@ -154,7 +154,7 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *coords.MapBlockCoords) (*image.NRG } else { //neighbouring mapblock - neighbourPos := coords.NewMapBlockCoords(currentPos.X-1, currentPos.Y, currentPos.Z) + neighbourPos := types.NewMapBlockCoords(currentPos.X-1, currentPos.Y, currentPos.Z) neighbourMapblock, err := r.accessor.GetMapBlock(neighbourPos) if neighbourMapblock != nil && err == nil { @@ -174,7 +174,7 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *coords.MapBlockCoords) (*image.NRG } else { //neighbouring mapblock - neighbourPos := coords.NewMapBlockCoords(currentPos.X, currentPos.Y, currentPos.Z+1) + neighbourPos := types.NewMapBlockCoords(currentPos.X, currentPos.Y, currentPos.Z+1) neighbourMapblock, err := r.accessor.GetMapBlock(neighbourPos) if neighbourMapblock != nil && err == nil { diff --git a/mapblockrenderer/renderer_benchmark_test.go b/mapblockrenderer/renderer_benchmark_test.go index 8c6eef8..55702e2 100644 --- a/mapblockrenderer/renderer_benchmark_test.go +++ b/mapblockrenderer/renderer_benchmark_test.go @@ -2,10 +2,10 @@ package mapblockrenderer import ( "io/ioutil" - "mapserver/coords" "mapserver/db/sqlite" "mapserver/mapblockaccessor" "mapserver/testutils" + "mapserver/types" "os" "testing" "time" @@ -59,8 +59,8 @@ func BenchmarkRenderEmptySingle(b *testing.B) { for n := 0; n < b.N; n++ { - pos1 := coords.NewMapBlockCoords(10, 0, 10) - pos2 := coords.NewMapBlockCoords(10, 0, 10) + pos1 := types.NewMapBlockCoords(10, 0, 10) + pos2 := types.NewMapBlockCoords(10, 0, 10) _, err := r.Render(pos1, pos2) @@ -76,8 +76,8 @@ func BenchmarkRenderSingle(b *testing.B) { for n := 0; n < b.N; n++ { - pos1 := coords.NewMapBlockCoords(0, 0, 0) - pos2 := coords.NewMapBlockCoords(0, 0, 0) + pos1 := types.NewMapBlockCoords(0, 0, 0) + pos2 := types.NewMapBlockCoords(0, 0, 0) _, err := r.Render(pos1, pos2) @@ -93,8 +93,8 @@ func BenchmarkRenderStride(b *testing.B) { for n := 0; n < b.N; n++ { - pos1 := coords.NewMapBlockCoords(0, 10, 0) - pos2 := coords.NewMapBlockCoords(0, -1, 0) + pos1 := types.NewMapBlockCoords(0, 10, 0) + pos2 := types.NewMapBlockCoords(0, -1, 0) _, err := r.Render(pos1, pos2) @@ -110,8 +110,8 @@ func BenchmarkRenderBigStride(b *testing.B) { for n := 0; n < b.N; n++ { - pos1 := coords.NewMapBlockCoords(0, 1000, 0) - pos2 := coords.NewMapBlockCoords(0, -1000, 0) + pos1 := types.NewMapBlockCoords(0, 1000, 0) + pos2 := types.NewMapBlockCoords(0, -1000, 0) _, err := r.Render(pos1, pos2) diff --git a/mapblockrenderer/renderer_test.go b/mapblockrenderer/renderer_test.go index a53ebca..d3694d3 100644 --- a/mapblockrenderer/renderer_test.go +++ b/mapblockrenderer/renderer_test.go @@ -5,9 +5,9 @@ import ( "io/ioutil" "mapserver/coords" "mapserver/db/sqlite" - "mapserver/layer" "mapserver/mapblockaccessor" "mapserver/testutils" + "mapserver/types" "os" "testing" "time" @@ -20,7 +20,7 @@ import ( func TestSimpleRender(t *testing.T) { logrus.SetLevel(logrus.InfoLevel) - layers := []*layer.Layer{ + layers := []*types.Layer{ { Id: 0, Name: "Base", @@ -81,8 +81,8 @@ func TestSimpleRender(t *testing.T) { for x := from; x < to; x++ { for z := from; z < to; z++ { - pos1 := coords.NewMapBlockCoords(x, 10, z) - pos2 := coords.NewMapBlockCoords(x, -1, z) + pos1 := types.NewMapBlockCoords(x, 10, z) + pos2 := types.NewMapBlockCoords(x, -1, z) jobs <- JobData{Pos1: pos1, Pos2: pos2} } diff --git a/mapblockrenderer/worker.go b/mapblockrenderer/worker.go index 87340db..cd76ad2 100644 --- a/mapblockrenderer/worker.go +++ b/mapblockrenderer/worker.go @@ -3,12 +3,12 @@ package mapblockrenderer import ( "bytes" "image/png" - "mapserver/coords" + "mapserver/types" "time" ) type JobData struct { - Pos1, Pos2 *coords.MapBlockCoords + Pos1, Pos2 *types.MapBlockCoords } type JobResult struct { diff --git a/mapobject/atm.go b/mapobject/atm.go index 05106f3..bf0af10 100644 --- a/mapobject/atm.go +++ b/mapobject/atm.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type ATM struct{} -func (this *ATM) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *ATM) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { nodename := block.GetNodeName(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "atm") diff --git a/mapobject/bones.go b/mapobject/bones.go index d070c79..8c7bf2e 100644 --- a/mapobject/bones.go +++ b/mapobject/bones.go @@ -1,8 +1,8 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "strconv" "github.com/minetest-go/mapparser" @@ -10,7 +10,7 @@ import ( type BonesBlock struct{} -func (this *BonesBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *BonesBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) invMap := block.Metadata.GetInventoryMapAtPos(x, y, z) diff --git a/mapobject/border.go b/mapobject/border.go index 850314f..87a8edf 100644 --- a/mapobject/border.go +++ b/mapobject/border.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type BorderBlock struct{} -func (this *BorderBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *BorderBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "border") diff --git a/mapobject/digilinelcd.go b/mapobject/digilinelcd.go index 13d8531..6fab52b 100644 --- a/mapobject/digilinelcd.go +++ b/mapobject/digilinelcd.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type DigilineLcdBlock struct{} -func (this *DigilineLcdBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *DigilineLcdBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "digilinelcd") diff --git a/mapobject/digiterms.go b/mapobject/digiterms.go index 0d6d79c..6d87463 100644 --- a/mapobject/digiterms.go +++ b/mapobject/digiterms.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type DigitermsBlock struct{} -func (this *DigitermsBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *DigitermsBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "digiterm") diff --git a/mapobject/fancyvend.go b/mapobject/fancyvend.go index 2d233ca..32ddbe2 100644 --- a/mapobject/fancyvend.go +++ b/mapobject/fancyvend.go @@ -1,9 +1,9 @@ package mapobject import ( - "mapserver/coords" "mapserver/luaparser" "mapserver/mapobjectdb" + "mapserver/types" "math" "strconv" @@ -13,7 +13,7 @@ import ( type FancyVend struct{} -func (this *FancyVend) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *FancyVend) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) nodename := block.GetNodeName(x, y, z) invMap := block.Metadata.GetInventoryMapAtPos(x, y, z) diff --git a/mapobject/jumpdrive.go b/mapobject/jumpdrive.go index c7ce5e4..0bf94cb 100644 --- a/mapobject/jumpdrive.go +++ b/mapobject/jumpdrive.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type JumpdriveBlock struct{} -func (this *JumpdriveBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *JumpdriveBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "jumpdrive") diff --git a/mapobject/label.go b/mapobject/label.go index 662764b..20064ec 100644 --- a/mapobject/label.go +++ b/mapobject/label.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type LabelBlock struct{} -func (this *LabelBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *LabelBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "label") diff --git a/mapobject/listener.go b/mapobject/listener.go index 4f6fc46..a97f68b 100644 --- a/mapobject/listener.go +++ b/mapobject/listener.go @@ -12,11 +12,11 @@ import ( ) type MapObjectListener interface { - onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject + onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject } type MapMultiObjectListener interface { - onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) []*mapobjectdb.MapObject + onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) []*mapobjectdb.MapObject } type Listener struct { diff --git a/mapobject/locator.go b/mapobject/locator.go index d555d05..7d12d78 100644 --- a/mapobject/locator.go +++ b/mapobject/locator.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type Locator struct{} -func (this *Locator) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *Locator) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) nodename := block.GetNodeName(x, y, z) diff --git a/mapobject/luacontroller.go b/mapobject/luacontroller.go index d777bc4..83101fd 100644 --- a/mapobject/luacontroller.go +++ b/mapobject/luacontroller.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type LuaControllerBlock struct{} -func (this *LuaControllerBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *LuaControllerBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { //md := block.Metadata.GetMetadata(x, y, z) nodename := block.GetNodeName(x, y, z) diff --git a/mapobject/mission.go b/mapobject/mission.go index 57bb82f..755861f 100644 --- a/mapobject/mission.go +++ b/mapobject/mission.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type MissionBlock struct{} -func (this *MissionBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *MissionBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) if md["hidden"] == "1" { diff --git a/mapobject/nuclearreactor.go b/mapobject/nuclearreactor.go index 6558938..5946baf 100644 --- a/mapobject/nuclearreactor.go +++ b/mapobject/nuclearreactor.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type NuclearReactorBlock struct{} -func (this *NuclearReactorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *NuclearReactorBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "nuclearreactor") diff --git a/mapobject/poi.go b/mapobject/poi.go index 16c2604..b46740b 100644 --- a/mapobject/poi.go +++ b/mapobject/poi.go @@ -1,8 +1,8 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) @@ -11,7 +11,7 @@ type PoiBlock struct { Color string } -func (this *PoiBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *PoiBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "poi") diff --git a/mapobject/privprotector.go b/mapobject/privprotector.go index 798c0a5..a5c4481 100644 --- a/mapobject/privprotector.go +++ b/mapobject/privprotector.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type PrivProtectorBlock struct{} -func (this *PrivProtectorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *PrivProtectorBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "privprotector") diff --git a/mapobject/protector.go b/mapobject/protector.go index d661bca..9bfaa9d 100644 --- a/mapobject/protector.go +++ b/mapobject/protector.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type ProtectorBlock struct{} -func (this *ProtectorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *ProtectorBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "protector") diff --git a/mapobject/quarry.go b/mapobject/quarry.go index 52c4652..cf7a454 100644 --- a/mapobject/quarry.go +++ b/mapobject/quarry.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type QuarryBlock struct{} -func (this *QuarryBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *QuarryBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) if md["owner"] == "" { diff --git a/mapobject/sign.go b/mapobject/sign.go index 97b9ff9..f3a6cc1 100644 --- a/mapobject/sign.go +++ b/mapobject/sign.go @@ -1,8 +1,8 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) @@ -11,7 +11,7 @@ type SignBlock struct { Material string } -func (this *SignBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *SignBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "sign") diff --git a/mapobject/smartshop.go b/mapobject/smartshop.go index 75b710f..eafb9f3 100644 --- a/mapobject/smartshop.go +++ b/mapobject/smartshop.go @@ -1,8 +1,8 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "math" "strconv" @@ -11,7 +11,7 @@ import ( type SmartShopBlock struct{} -func (this *SmartShopBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) []*mapobjectdb.MapObject { +func (this *SmartShopBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) []*mapobjectdb.MapObject { list := make([]*mapobjectdb.MapObject, 0) md := block.Metadata.GetMetadata(x, y, z) diff --git a/mapobject/technicanchor.go b/mapobject/technicanchor.go index d1852f8..7286213 100644 --- a/mapobject/technicanchor.go +++ b/mapobject/technicanchor.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type TechnicAnchorBlock struct{} -func (this *TechnicAnchorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *TechnicAnchorBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "technicanchor") diff --git a/mapobject/technicswitch.go b/mapobject/technicswitch.go index e6430ae..0c9054f 100644 --- a/mapobject/technicswitch.go +++ b/mapobject/technicswitch.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type TechnicSwitchBlock struct{} -func (this *TechnicSwitchBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *TechnicSwitchBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "technicswitch") diff --git a/mapobject/train.go b/mapobject/train.go index cd7af7b..8710e1d 100644 --- a/mapobject/train.go +++ b/mapobject/train.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type TrainBlock struct{} -func (this *TrainBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *TrainBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "train") diff --git a/mapobject/travelnet.go b/mapobject/travelnet.go index 64f35bf..ffe0156 100644 --- a/mapobject/travelnet.go +++ b/mapobject/travelnet.go @@ -1,8 +1,8 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "strings" "github.com/minetest-go/mapparser" @@ -10,7 +10,7 @@ import ( type TravelnetBlock struct{} -func (tn *TravelnetBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (tn *TravelnetBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) // ignore (P) prefixed stations diff --git a/mapobject/xpprotector.go b/mapobject/xpprotector.go index 7360e39..a2bfb61 100644 --- a/mapobject/xpprotector.go +++ b/mapobject/xpprotector.go @@ -1,15 +1,15 @@ package mapobject import ( - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "github.com/minetest-go/mapparser" ) type XPProtectorBlock struct{} -func (this *XPProtectorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { +func (this *XPProtectorBlock) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { md := block.Metadata.GetMetadata(x, y, z) o := mapobjectdb.NewMapObject(mbpos, x, y, z, "xpprotector") diff --git a/mapobjectdb/accessor.go b/mapobjectdb/accessor.go index 0bb44d3..3641c4e 100644 --- a/mapobjectdb/accessor.go +++ b/mapobjectdb/accessor.go @@ -2,6 +2,7 @@ package mapobjectdb import ( "mapserver/coords" + "mapserver/types" "time" "github.com/sirupsen/logrus" @@ -21,7 +22,7 @@ type Tile struct { type MapObject struct { //mapblock position - MBPos *coords.MapBlockCoords `json:"mapblock"` + MBPos *types.MapBlockCoords `json:"mapblock"` //block position X int `json:"x"` @@ -33,7 +34,7 @@ type MapObject struct { Attributes map[string]string `json:"attributes"` } -func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject { +func NewMapObject(MBPos *types.MapBlockCoords, x int, y int, z int, _type string) *MapObject { fields := logrus.Fields{ "mbpos": MBPos, @@ -64,11 +65,11 @@ type SearchAttributeLike struct { type SearchQuery struct { //mapblock position - Pos1 *coords.MapBlockCoords `json:"pos1"` - Pos2 *coords.MapBlockCoords `json:"pos2"` - Type string `json:"type"` - AttributeLike *SearchAttributeLike `json:"attributelike"` - Limit *int `json:"limit"` + Pos1 *types.MapBlockCoords `json:"pos1"` + Pos2 *types.MapBlockCoords `json:"pos2"` + Type string `json:"type"` + AttributeLike *SearchAttributeLike `json:"attributelike"` + Limit *int `json:"limit"` } type DBAccessor interface { @@ -77,7 +78,7 @@ type DBAccessor interface { //Generic map objects (poi, etc) GetMapData(q *SearchQuery) ([]*MapObject, error) - RemoveMapData(pos *coords.MapBlockCoords) error + RemoveMapData(pos *types.MapBlockCoords) error AddMapData(data *MapObject) error //Settings diff --git a/mapobjectdb/accessor_test.go b/mapobjectdb/accessor_test.go index 0ce7da0..9490880 100644 --- a/mapobjectdb/accessor_test.go +++ b/mapobjectdb/accessor_test.go @@ -2,7 +2,7 @@ package mapobjectdb import ( "fmt" - "mapserver/coords" + "mapserver/types" "testing" ) @@ -10,7 +10,7 @@ func TestNewMapBlockCoords(t *testing.T) { attrs := make(map[string]string) attrs["X"] = "y" - pos := coords.NewMapBlockCoords(1, 2, 3) + pos := types.NewMapBlockCoords(1, 2, 3) fmt.Println(pos) obj := NewMapObject(pos, 10, 12, 14, "xy") diff --git a/mapobjectdb/postgres/mapobjects.go b/mapobjectdb/postgres/mapobjects.go index 1701261..fd61777 100644 --- a/mapobjectdb/postgres/mapobjects.go +++ b/mapobjectdb/postgres/mapobjects.go @@ -2,8 +2,8 @@ package postgres import ( "database/sql" - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "unicode/utf8" "github.com/google/uuid" @@ -63,7 +63,7 @@ func (a *PostgresAccessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobjectd } if currentUID == "" || currentUID != id { - pos := coords.NewMapBlockCoords(posx, posy, posz) + pos := types.NewMapBlockCoords(posx, posy, posz) mo := &mapobjectdb.MapObject{ MBPos: pos, Type: Type, @@ -87,7 +87,7 @@ func (a *PostgresAccessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobjectd return result, nil } -func (a *PostgresAccessor) RemoveMapData(pos *coords.MapBlockCoords) error { +func (a *PostgresAccessor) RemoveMapData(pos *types.MapBlockCoords) error { _, err := a.db.Exec(removeMapDataQuery, pos.X, pos.Y, pos.Z) return err } diff --git a/mapobjectdb/sqlite/mapobjects.go b/mapobjectdb/sqlite/mapobjects.go index 6446f8a..2f16f46 100644 --- a/mapobjectdb/sqlite/mapobjects.go +++ b/mapobjectdb/sqlite/mapobjects.go @@ -2,8 +2,8 @@ package sqlite import ( "database/sql" - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "unicode/utf8" "github.com/google/uuid" @@ -63,7 +63,7 @@ func (db *Sqlite3Accessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobjectd } if currentUID == "" || currentUID != uid { - pos := coords.NewMapBlockCoords(posx, posy, posz) + pos := types.NewMapBlockCoords(posx, posy, posz) mo := &mapobjectdb.MapObject{ MBPos: pos, Type: Type, @@ -86,7 +86,7 @@ func (db *Sqlite3Accessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobjectd return result, nil } -func (a *Sqlite3Accessor) RemoveMapData(pos *coords.MapBlockCoords) error { +func (a *Sqlite3Accessor) RemoveMapData(pos *types.MapBlockCoords) error { _, err := a.db.Exec(removeMapDataAttributesQuery, pos.X, pos.Y, pos.Z) if err != nil { return err diff --git a/mapobjectdb/sqlite/mapobjects_test.go b/mapobjectdb/sqlite/mapobjects_test.go index 89c8d95..0f5b452 100644 --- a/mapobjectdb/sqlite/mapobjects_test.go +++ b/mapobjectdb/sqlite/mapobjects_test.go @@ -3,8 +3,8 @@ package sqlite import ( "fmt" "io/ioutil" - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "os" "testing" ) @@ -48,7 +48,7 @@ func TestMapObjects(t *testing.T) { attrs := make(map[string]string) attrs["X"] = "y" - pos := coords.NewMapBlockCoords(0, 0, 0) + pos := types.NewMapBlockCoords(0, 0, 0) o := mapobjectdb.MapObject{ MBPos: pos, @@ -105,7 +105,7 @@ func TestMapObjectsQueryWithAttribute(t *testing.T) { attrs := make(map[string]string) attrs["X"] = "y" - pos := coords.NewMapBlockCoords(0, 0, 0) + pos := types.NewMapBlockCoords(0, 0, 0) o := mapobjectdb.MapObject{ MBPos: pos, @@ -169,7 +169,7 @@ func TestMapObjectsQueryWithAttributeIgnoreCase(t *testing.T) { attrs := make(map[string]string) attrs["X"] = "ABC" - pos := coords.NewMapBlockCoords(0, 0, 0) + pos := types.NewMapBlockCoords(0, 0, 0) o := mapobjectdb.MapObject{ MBPos: pos, diff --git a/tilerenderer/renderer.go b/tilerenderer/renderer.go index 38ada5f..1b0854f 100644 --- a/tilerenderer/renderer.go +++ b/tilerenderer/renderer.go @@ -3,24 +3,25 @@ package tilerenderer import ( "bytes" "errors" - "github.com/prometheus/client_golang/prometheus" - "github.com/sirupsen/logrus" "image" "image/draw" "image/png" "mapserver/coords" "mapserver/db" "mapserver/eventbus" - "mapserver/layer" "mapserver/mapblockrenderer" "mapserver/tiledb" + "mapserver/types" "strconv" "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/sirupsen/logrus" ) type TileRenderer struct { mapblockrenderer *mapblockrenderer.MapBlockRenderer - layers []*layer.Layer + layers []*types.Layer tdb *tiledb.TileDB dba db.DBAccessor Eventbus *eventbus.Eventbus @@ -56,7 +57,7 @@ func resizeImage(src *image.NRGBA, tgt *image.NRGBA, xoffset int, yoffset int) { func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer, tdb *tiledb.TileDB, dba db.DBAccessor, - layers []*layer.Layer) *TileRenderer { + layers []*types.Layer) *TileRenderer { return &TileRenderer{ mapblockrenderer: mapblockrenderer, @@ -123,14 +124,14 @@ func (tr *TileRenderer) renderImage(tc *coords.TileCoords, recursionDepth int) ( timer := prometheus.NewTimer(renderDuration) defer timer.ObserveDuration() - currentLayer := layer.FindLayerById(tr.layers, tc.LayerId) + currentLayer := types.FindLayerById(tr.layers, tc.LayerId) if currentLayer == nil { - return nil, errors.New("No layer found") + return nil, errors.New("no layer found") } if tc.Zoom > 13 || tc.Zoom < 1 { - return nil, errors.New("Invalid zoom") + return nil, errors.New("invalid zoom") } if tc.Zoom == 13 { diff --git a/tilerenderer/renderer_benchmark_test.go b/tilerenderer/renderer_benchmark_test.go index dbb89ce..2dda233 100644 --- a/tilerenderer/renderer_benchmark_test.go +++ b/tilerenderer/renderer_benchmark_test.go @@ -4,11 +4,11 @@ import ( "io/ioutil" "mapserver/coords" "mapserver/db/sqlite" - "mapserver/layer" "mapserver/mapblockaccessor" "mapserver/mapblockrenderer" "mapserver/testutils" "mapserver/tiledb" + "mapserver/types" "os" "testing" "time" @@ -53,7 +53,7 @@ func BenchmarkTileRender(b *testing.B) { tdb, _ := tiledb.New(tiletmpdir) - layers := []*layer.Layer{ + layers := []*types.Layer{ { Id: 0, Name: "Base", diff --git a/tilerenderer/renderer_test.go b/tilerenderer/renderer_test.go index 0b79a42..7b2b789 100644 --- a/tilerenderer/renderer_test.go +++ b/tilerenderer/renderer_test.go @@ -4,11 +4,11 @@ import ( "io/ioutil" "mapserver/coords" "mapserver/db/sqlite" - "mapserver/layer" "mapserver/mapblockaccessor" "mapserver/mapblockrenderer" "mapserver/testutils" "mapserver/tiledb" + "mapserver/types" "os" "testing" "time" @@ -53,7 +53,7 @@ func TestTileRender(t *testing.T) { tdb, _ := tiledb.New(tiletmpdir) - layers := []*layer.Layer{ + layers := []*types.Layer{ { Id: 0, Name: "Base", diff --git a/layer/layer.go b/types/layer.go similarity index 96% rename from layer/layer.go rename to types/layer.go index dd93899..de8487d 100644 --- a/layer/layer.go +++ b/types/layer.go @@ -1,4 +1,4 @@ -package layer +package types type Layer struct { Id int `json:"id"` diff --git a/coords/mapblockcoords.go b/types/mapblockcoords.go similarity index 97% rename from coords/mapblockcoords.go rename to types/mapblockcoords.go index 85c2b88..6a37d1e 100644 --- a/coords/mapblockcoords.go +++ b/types/mapblockcoords.go @@ -1,4 +1,4 @@ -package coords +package types import ( "math" diff --git a/types/parsedmapblock.go b/types/parsedmapblock.go index 078202b..c9a30b5 100644 --- a/types/parsedmapblock.go +++ b/types/parsedmapblock.go @@ -1,16 +1,14 @@ package types import ( - "mapserver/coords" - "github.com/minetest-go/mapparser" ) type ParsedMapblock struct { Mapblock *mapparser.MapBlock - Pos *coords.MapBlockCoords + Pos *MapBlockCoords } -func NewParsedMapblock(mb *mapparser.MapBlock, pos *coords.MapBlockCoords) *ParsedMapblock { +func NewParsedMapblock(mb *mapparser.MapBlock, pos *MapBlockCoords) *ParsedMapblock { return &ParsedMapblock{Mapblock: mb, Pos: pos} } diff --git a/web/areas.go b/web/areas.go index 0a08b2d..b30610f 100644 --- a/web/areas.go +++ b/web/areas.go @@ -3,12 +3,13 @@ package web import ( "encoding/json" "mapserver/app" - "mapserver/areasparser" "net/http" "os" "sync" "time" + + "github.com/minetest-go/areasparser" ) type AreasHandler struct { diff --git a/web/config.go b/web/config.go index d4737e1..6eceaf3 100644 --- a/web/config.go +++ b/web/config.go @@ -3,14 +3,14 @@ package web import ( "encoding/json" "mapserver/app" - "mapserver/layer" + "mapserver/types" "net/http" ) -//Public facing config +// Public facing config type PublicConfig struct { Version string `json:"version"` - Layers []*layer.Layer `json:"layers"` + Layers []*types.Layer `json:"layers"` MapObjects *app.MapObjectConfig `json:"mapobjects"` DefaultOverlays []string `json:"defaultoverlays"` EnableSearch bool `json:"enablesearch"` diff --git a/web/mapblock.go b/web/mapblock.go index 3d8decb..0770e4e 100644 --- a/web/mapblock.go +++ b/web/mapblock.go @@ -2,7 +2,7 @@ package web import ( "encoding/json" - "mapserver/coords" + "mapserver/types" "net/http" "strconv" "strings" @@ -21,7 +21,7 @@ func (api *Api) GetMapBlockData(resp http.ResponseWriter, req *http.Request) { y, _ := strconv.Atoi(parts[1]) z, _ := strconv.Atoi(parts[2]) - c := coords.NewMapBlockCoords(x, y, z) + c := types.NewMapBlockCoords(x, y, z) mb, err := api.Context.MapBlockAccessor.GetMapBlock(c) if err != nil { diff --git a/web/mapobjects.go b/web/mapobjects.go index ac7ece7..d0a1b2c 100644 --- a/web/mapobjects.go +++ b/web/mapobjects.go @@ -2,8 +2,8 @@ package web import ( "encoding/json" - "mapserver/coords" "mapserver/mapobjectdb" + "mapserver/types" "net/http" "github.com/prometheus/client_golang/prometheus" @@ -31,11 +31,11 @@ func (api *Api) QueryMapobjects(resp http.ResponseWriter, req *http.Request) { } if q.Pos1 == nil { - q.Pos1 = &coords.MapBlockCoords{X: -2048, Y: -2048, Z: -2048} + q.Pos1 = &types.MapBlockCoords{X: -2048, Y: -2048, Z: -2048} } if q.Pos2 == nil { - q.Pos2 = &coords.MapBlockCoords{X: 2048, Y: 2048, Z: 2048} + q.Pos2 = &types.MapBlockCoords{X: 2048, Y: 2048, Z: 2048} } objects, err := api.Context.Objectdb.GetMapData(&q) diff --git a/web/viewblock.go b/web/viewblock.go index ad998a8..21560de 100644 --- a/web/viewblock.go +++ b/web/viewblock.go @@ -2,7 +2,7 @@ package web import ( "encoding/json" - "mapserver/coords" + "mapserver/types" "net/http" "strconv" "strings" @@ -26,7 +26,7 @@ func (api *Api) GetBlockData(resp http.ResponseWriter, req *http.Request) { y, _ := strconv.Atoi(parts[1]) z, _ := strconv.Atoi(parts[2]) - c := coords.NewMapBlockCoords(x, y, z) + c := types.NewMapBlockCoords(x, y, z) mb, err := api.Context.MapBlockAccessor.GetMapBlock(c) if err != nil {