diff --git a/doc/config.md b/doc/config.md index e362dc5..becc4a5 100644 --- a/doc/config.md +++ b/doc/config.md @@ -93,7 +93,7 @@ More layers can be added here: } ], ``` -*from* and *to* are in blocks (not mapblocks) +*from* and *to* are in mapblocks (16x16x16 blocks) Don't reuse the `id` after the tiles are generated. If you make more substantial changes here you may have to remove all existing tiles and start rendering from scratch. diff --git a/server/app/config.go b/server/app/config.go index 94d1db9..50e0cec 100644 --- a/server/app/config.go +++ b/server/app/config.go @@ -98,14 +98,14 @@ func ParseConfig(filename string) (*Config, error) { &layer.Layer{ Id: 0, Name: "Ground", - From: -16, - To: 160, + From: -1, + To: 10, }, &layer.Layer{ Id: 1, Name: "Sky", - From: 160, - To: 320, + From: 11, + To: 24, }, } diff --git a/server/coords/tileconvert.go b/server/coords/tileconvert.go index df1653b..631f7db 100644 --- a/server/coords/tileconvert.go +++ b/server/coords/tileconvert.go @@ -14,7 +14,7 @@ func GetTileCoordsFromMapBlock(mbc *MapBlockCoords, layers []*layer.Layer) *Tile var layerid *int for _, l := range layers { - if (mbc.Y*16) >= l.From && (mbc.Y*16) <= l.To { + if mbc.Y >= l.From && mbc.Y <= l.To { layerid = &l.Id break } diff --git a/server/db/postgres/initialblocks.go b/server/db/postgres/initialblocks.go index 05801ba..f0276ce 100644 --- a/server/db/postgres/initialblocks.go +++ b/server/db/postgres/initialblocks.go @@ -90,12 +90,9 @@ func (this *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers tc := coords.NewTileCoords(lastxblock, lastyblock, 9, lastlayer) currentlayer := layer.FindLayerById(layers, lastlayer) - fromY := int(currentlayer.From / 16) - toY := int(currentlayer.To / 16) - tcr := coords.GetMapBlockRangeFromTile(tc, 0) - tcr.Pos1.Y = fromY - tcr.Pos2.Y = toY + tcr.Pos1.Y = currentlayer.From + tcr.Pos2.Y = currentlayer.To fields := logrus.Fields{ "layerId": lastlayer, @@ -112,20 +109,6 @@ func (this *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers minZ := int(math.Min(float64(tcr.Pos1.Z), float64(tcr.Pos2.Z))) maxZ := int(math.Max(float64(tcr.Pos1.Z), float64(tcr.Pos2.Z))) - //upper left: https://pandorabox.io/map/tiles/0/9/-121/-121 - //lower right: https://pandorabox.io/map/tiles/0/9/120/120 - // INFO[0007] Initial rendering elapsed=24.749287ms mapblocks=0 progress%=2 tiles=0 - //INFO[0007] Initial-Query layerId=0 pos1="&{-1968 -1 1935}" pos2="&{-1953 10 1920}" prefix=postgres-db tile="&{-123 -121 9 0}" - //INFO[0007] Initial rendering elapsed=24.587519ms mapblocks=0 progress%=2 tiles=0 - //INFO[0007] Initial-Query layerId=0 pos1="&{-1952 -1 1935}" pos2="&{-1937 10 1920}" prefix=postgres-db tile="&{-122 -121 9 0}" - //INFO[0007] Initial rendering elapsed=24.607329ms mapblocks=0 progress%=2 tiles=0 - //INFO[0007] Initial-Query layerId=0 pos1="&{-1936 -1 1935}" pos2="&{-1921 10 1920}" prefix=postgres-db tile="&{-121 -121 9 0}" - //INFO[0007] Initial rendering elapsed=25.090037ms mapblocks=0 progress%=2 tiles=0 - //INFO[0007] Initial-Query layerId=0 pos1="&{-1920 -1 1935}" pos2="&{-1905 10 1920}" prefix=postgres-db tile="&{-120 -121 9 0}" - //INFO[0007] Initial rendering elapsed=24.754558ms mapblocks=0 progress%=2 tiles=0 - //INFO[0007] Initial-Query layerId=0 pos1="&{-1904 -1 1935}" pos2="&{-1889 10 1920}" prefix=postgres-db tile="&{-119 -121 9 0}" - //INFO[0007] Initial rendering elapsed=24.711348ms mapblocks=0 progress%=2 tiles=0 - if lastxblock <= -128 { //first x entry, check z stride stridecount := this.intQuery(` diff --git a/server/db/sqlite/initialblocks.go b/server/db/sqlite/initialblocks.go index 01af62b..5154f78 100644 --- a/server/db/sqlite/initialblocks.go +++ b/server/db/sqlite/initialblocks.go @@ -71,7 +71,7 @@ func (this *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers [ // new position lastpos = pos - blockcoordy := mb.Pos.Y * 16 + blockcoordy := mb.Pos.Y currentlayer := layer.FindLayerByY(layers, blockcoordy) if currentlayer != nil { diff --git a/server/mapblockaccessor/mtime.go b/server/mapblockaccessor/mtime.go index e3f4ac6..75b797e 100644 --- a/server/mapblockaccessor/mtime.go +++ b/server/mapblockaccessor/mtime.go @@ -52,7 +52,7 @@ func (a *MapBlockAccessor) FindMapBlocksByMtime(lastmtime int64, limit int, laye inLayer := false for _, l := range layerfilter { - if (block.Pos.Y*16) >= l.From && (block.Pos.Y*16) <= l.To { + if block.Pos.Y >= l.From && block.Pos.Y <= l.To { inLayer = true break } diff --git a/server/static/js/overlays/AbstractGeoJsonOverlay.js b/server/static/js/overlays/AbstractGeoJsonOverlay.js index eae3095..8023985 100644 --- a/server/static/js/overlays/AbstractGeoJsonOverlay.js +++ b/server/static/js/overlays/AbstractGeoJsonOverlay.js @@ -55,8 +55,8 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({ var min = this._map.getBounds().getSouthWest(); var max = this._map.getBounds().getNorthEast(); - var y1 = parseInt(mapLayer.from/16); - var y2 = parseInt(mapLayer.to/16); + var y1 = parseInt(mapLayer.from); + var y2 = parseInt(mapLayer.to); var x1 = parseInt(min.lng/16); var x2 = parseInt(max.lng/16); var z1 = parseInt(min.lat/16); diff --git a/server/static/js/overlays/AbstractIconOverlay.js b/server/static/js/overlays/AbstractIconOverlay.js index 6ed528f..b78e576 100644 --- a/server/static/js/overlays/AbstractIconOverlay.js +++ b/server/static/js/overlays/AbstractIconOverlay.js @@ -65,8 +65,8 @@ var AbstractIconOverlay = L.LayerGroup.extend({ var min = this.map.getBounds().getSouthWest(); var max = this.map.getBounds().getNorthEast(); - var y1 = parseInt(mapLayer.from/16); - var y2 = parseInt(mapLayer.to/16); + var y1 = parseInt(mapLayer.from); + var y2 = parseInt(mapLayer.to); var x1 = parseInt(min.lng/16); var x2 = parseInt(max.lng/16); var z1 = parseInt(min.lat/16); diff --git a/server/static/js/overlays/PlayerOverlay.js b/server/static/js/overlays/PlayerOverlay.js index 26b02d8..20c30f4 100644 --- a/server/static/js/overlays/PlayerOverlay.js +++ b/server/static/js/overlays/PlayerOverlay.js @@ -55,7 +55,7 @@ var PlayerOverlay = L.LayerGroup.extend({ isPlayerInCurrentLayer: function(player){ var mapLayer = this.layerMgr.getCurrentLayer() - return (player.pos.y >= mapLayer.from && player.pos.y <= mapLayer.to) + return (player.pos.y >= (mapLayer.from*16) && player.pos.y <= (mapLayer.to*16)) }, onMinetestUpdate: function(info){ diff --git a/server/tilerenderer/renderer.go b/server/tilerenderer/renderer.go index 26fd6a2..39b75ac 100644 --- a/server/tilerenderer/renderer.go +++ b/server/tilerenderer/renderer.go @@ -103,15 +103,9 @@ func (tr *TileRenderer) renderImage(tc *coords.TileCoords, recursionDepth int) ( timer := prometheus.NewTimer(renderDuration) defer timer.ObserveDuration() - var layer *layer.Layer + currentLayer := layer.FindLayerById(tr.layers, tc.LayerId) - for _, l := range tr.layers { - if l.Id == tc.LayerId { - layer = l - } - } - - if layer == nil { + if currentLayer == nil { return nil, nil, errors.New("No layer found") } @@ -122,8 +116,8 @@ func (tr *TileRenderer) renderImage(tc *coords.TileCoords, recursionDepth int) ( if tc.Zoom == 13 { //max zoomed in on mapblock level mbr := coords.GetMapBlockRangeFromTile(tc, 0) - mbr.Pos1.Y = layer.From - mbr.Pos2.Y = layer.To + mbr.Pos1.Y = currentLayer.From + mbr.Pos2.Y = currentLayer.To img, err := tr.mapblockrenderer.Render(mbr.Pos1, mbr.Pos2)