diff --git a/android/build.gradle b/android/build.gradle index b23dc0d3..6500d964 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 167 - versionName "2.10.6" + versionCode 168 + versionName "2.10.7" } buildTypes { release { diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index 431ec298..8fd7f2d9 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -37,7 +37,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: for (tileInfo in tileMap.values) { val tileGroup = WorldTileGroup(tileInfo) - tileGroup.onClick{onTileClicked(tileInfo, tileGroup)} + tileGroup.onClick{ onTileClicked(tileInfo, tileGroup)} val positionalVector = HexMath().hex2WorldCoords(tileInfo.position) val groupSize = 50 @@ -95,7 +95,10 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: val selectedUnit = worldScreen.bottomBar.unitTable.selectedUnit if (selectedUnit != null && selectedUnit.getTile() != tileInfo && selectedUnit.canMoveTo(tileInfo) && selectedUnit.movementAlgs().canReach(tileInfo)) { - addMoveHereButtonToTile(selectedUnit, tileInfo, tileGroup) + // this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread + kotlin.concurrent.thread { + addMoveHereButtonToTile(selectedUnit, tileInfo, tileGroup) + } } worldScreen.bottomBar.unitTable.tileSelected(tileInfo) @@ -119,16 +122,21 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: if (selectedUnit.currentMovement > 0) moveHereButton.onClick { - if (selectedUnit.movementAlgs().canReach(tileInfo)) { - selectedUnit.movementAlgs().headTowards(tileInfo) - if (selectedUnit.currentTile != tileInfo) - selectedUnit.action = "moveTo " + tileInfo.position.x.toInt() + "," + tileInfo.position.y.toInt() - } + // this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread + kotlin.concurrent.thread { + if (selectedUnit.movementAlgs().canReach(tileInfo)) { + selectedUnit.movementAlgs().headTowards(tileInfo) + if (selectedUnit.currentTile != tileInfo) + selectedUnit.action = "moveTo " + tileInfo.position.x.toInt() + "," + tileInfo.position.y.toInt() + } - worldScreen.update() - moveToOverlay!!.remove() - moveToOverlay = null + // we don't update it directly because we're on a different thread; instead, we tell it to update itself + worldScreen.shouldUpdate = true + moveToOverlay!!.remove() + moveToOverlay = null + } } + else moveHereButton.color.a = 0.5f addOverlayOnTileGroup(tileGroup, moveHereButton).apply { width = size; height = size } moveHereButton.y += tileGroup.height diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 05f1dcac..9c88f291 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -237,7 +237,7 @@ class WorldScreen : CameraStageBaseScreen() { // but the main thread does other stuff, including showing tutorials which guess what? Changes the game data // BOOM! Exception! // That's why this needs to be after the game is saved. - shouldUpdateBecauseOfNewTurn=true + shouldUpdate=true nextTurnButton.setText("Next turn".tr()) Gdx.input.inputProcessor = stage @@ -256,9 +256,9 @@ class WorldScreen : CameraStageBaseScreen() { } } - private var shouldUpdateBecauseOfNewTurn=false + var shouldUpdate=false override fun render(delta: Float) { - if(shouldUpdateBecauseOfNewTurn){ // This is so that updates happen in the MAIN THREAD, where there is a GL Context, + if(shouldUpdate){ // This is so that updates happen in the MAIN THREAD, where there is a GL Context, // otherwise images will not load properly! update() @@ -285,7 +285,7 @@ class WorldScreen : CameraStageBaseScreen() { if(civInfo.tech.getUniques().contains("Enables embarkation for land units")) displayTutorials("CanEmbark") - shouldUpdateBecauseOfNewTurn=false + shouldUpdate=false } super.render(delta) }