1
0
forked from MTSR/mapserver

types / coords refactoring

This commit is contained in:
BuckarooBanzay 2023-12-29 16:00:11 +01:00
parent 1e1d0813e8
commit b7486a4474
72 changed files with 190 additions and 695 deletions

View File

@ -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

View File

@ -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",

View File

@ -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()

View File

@ -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 {

View File

@ -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
}

View File

@ -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)
}

View File

@ -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
}
}
]

View File

@ -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
}

View File

@ -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)
}

View File

@ -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 +
int64(c.X)
@ -33,8 +35,8 @@ func pythonModulo(i int16) int16 {
return modulo - -i&mask
}
func PlainToCoord(i int64) *MapBlockCoords {
c := MapBlockCoords{}
func PlainToCoord(i int64) *types.MapBlockCoords {
c := types.MapBlockCoords{}
c.X = unsignedToSigned(pythonModulo(int16(i)))
i = (i - int64(c.X)) >> numBitsPerComponent
c.Y = unsignedToSigned(pythonModulo(int16(i)))

View File

@ -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))
}

View File

@ -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)

View File

@ -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),
}
}

View File

@ -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,

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

1
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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)

View File

@ -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)

View File

@ -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)
}

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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 {

View File

@ -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)

View File

@ -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}
}

View File

@ -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 {

View File

@ -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")

View File

@ -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)

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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)

View File

@ -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")

View File

@ -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")

View File

@ -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 {

View File

@ -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)

View File

@ -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)

View File

@ -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" {

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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"] == "" {

View File

@ -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")

View File

@ -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)

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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")

View File

@ -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
}

View File

@ -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

View File

@ -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,

View File

@ -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 {

View File

@ -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",

View File

@ -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",

View File

@ -1,4 +1,4 @@
package layer
package types
type Layer struct {
Id int `json:"id"`

View File

@ -1,4 +1,4 @@
package coords
package types
import (
"math"

View File

@ -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}
}

View File

@ -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 {

View File

@ -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"`

View File

@ -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 {

View File

@ -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)

View File

@ -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 {