Fixed world wrap coordinates check (#8724)

* Fixed world wrap coordinates check (#8724)
This commit is contained in:
Gualdimar
2023-02-23 01:16:37 +02:00
committed by GitHub
parent 5077477987
commit 16ffae6e00

View File

@ -58,6 +58,9 @@ class TileGroupMap<T: TileGroup>(
private var bottomX = Float.MAX_VALUE private var bottomX = Float.MAX_VALUE
private var bottomY = Float.MAX_VALUE private var bottomY = Float.MAX_VALUE
private var drawTopX = 0f
private var drawBottomX = 0f
init { init {
for (tileGroup in tileGroups) { for (tileGroup in tileGroups) {
@ -94,6 +97,9 @@ class TileGroupMap<T: TileGroup>(
group.moveBy(-bottomX, -bottomY) group.moveBy(-bottomX, -bottomY)
} }
drawTopX = topX - bottomX
drawBottomX = bottomX - bottomX
val baseLayers = ArrayList<TileLayerTerrain>() val baseLayers = ArrayList<TileLayerTerrain>()
val featureLayers = ArrayList<TileLayerFeatures>() val featureLayers = ArrayList<TileLayerFeatures>()
val borderLayers = ArrayList<TileLayerBorders>() val borderLayers = ArrayList<TileLayerBorders>()
@ -162,19 +168,17 @@ class TileGroupMap<T: TileGroup>(
override fun draw(batch: Batch?, parentAlpha: Float) { override fun draw(batch: Batch?, parentAlpha: Float) {
if (worldWrap) { if (worldWrap) {
// Prevent flickering when zoomed out so you can see entire map // Prevent flickering when zoomed out so you can see entire map
val visibleMapWidth: Float val visibleMapWidth = if (mapHolder.width > width) width - groupSize * 1.5f
if(mapHolder.width > width) visibleMapWidth = width - groupSize * 1.5f else mapHolder.width
else visibleMapWidth = mapHolder.width
// Where is viewport's boundaries // Where is viewport's boundaries
val rightSide = mapHolder.scrollX + visibleMapWidth/2f val rightSide = mapHolder.scrollX + visibleMapWidth / 2f
val leftSide = mapHolder.scrollX - visibleMapWidth/2f val leftSide = mapHolder.scrollX - visibleMapWidth / 2f
// Have we looked beyond map? // Have we looked beyond map?
val diffRight = rightSide - topX val diffRight = rightSide - drawTopX
val diffLeft = leftSide - bottomX val diffLeft = leftSide - drawBottomX
val beyondRight = diffRight >= 0f val beyondRight = diffRight >= 0f
val beyondLeft = diffLeft <= 0f val beyondLeft = diffLeft <= 0f
@ -190,23 +194,21 @@ class TileGroupMap<T: TileGroup>(
children.forEach { children.forEach {
if (beyondRight) { if (beyondRight) {
// Move from left to right // Move from left to right
if (it.x - bottomX <= diffRight) if (it.x - drawBottomX <= diffRight)
it.x += width it.x += width
} else if (beyondLeft) { } else if (beyondLeft) {
// Move from right to left // Move from right to left
if (it.x + groupSize >= topX + diffLeft) if (it.x + groupSize >= drawTopX + diffLeft)
it.x -= width it.x -= width
} }
newBottomX = min(newBottomX, it.x) newBottomX = min(newBottomX, it.x)
newTopX = max(newTopX, it.x + groupSize) newTopX = max(newTopX, it.x + groupSize)
} }
bottomX = newBottomX drawBottomX = newBottomX
topX = newTopX drawTopX = newTopX
} }
} }
super.draw(batch, parentAlpha) super.draw(batch, parentAlpha)
} }