From 36f9ba6f8c0646dd69fa712cae4a49f308d69eef Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 29 May 2018 12:26:43 +0300 Subject: [PATCH] Moved autosave to a concurrent thread so you won't have to wait for it to finish saving to continue your game UpdateTiles is now cleaner - doesn't update viewed tiles twice, only once --- .../com/unciv/ui/worldscreen/TileMapHolder.kt | 23 +++++++------------ .../com/unciv/ui/worldscreen/WorldScreen.kt | 2 +- .../unciv/ui/worldscreen/unit/UnitTable.kt | 1 - 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index 5f1af8a9..7a1831f9 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -85,27 +85,20 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: } internal fun updateTiles() { + val civViewableTiles = civInfo.getViewableTiles().toHashSet() + for (WG in tileGroups.values){ - WG.update(false) - } - - val civViewableTiles = civInfo.getViewableTiles() - for (string in civViewableTiles - .filter { tileGroups.containsKey(it) }) { - - tileGroups[string]!!.run { - update(true) - } + WG.update(civViewableTiles.contains(WG.tileInfo)) } if(worldScreen.bottomBar.unitTable.selectedUnit!=null){ val unit = worldScreen.bottomBar.unitTable.selectedUnit!! tileGroups[unit.getTile()]!!.addWhiteHaloAroundUnit() - val attackableTiles:List - when(unit.getBaseUnit().unitType){ - UnitType.Civilian -> attackableTiles = listOf() - UnitType.Melee, UnitType.Mounted -> attackableTiles = unit.getDistanceToTiles().keys.toList() - UnitType.Archery, UnitType.Siege -> attackableTiles = unit.getTile().getTilesInDistance(2) + + val attackableTiles: List = when(unit.getBaseUnit().unitType){ + UnitType.Civilian -> listOf() + UnitType.Melee, UnitType.Mounted -> unit.getDistanceToTiles().keys.toList() + UnitType.Archery, UnitType.Siege -> unit.getTile().getTilesInDistance(2) UnitType.City -> throw Exception("A unit shouldn't have a City unittype!") } diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index a74ce825..b5e7f5a7 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -115,7 +115,7 @@ class WorldScreen : CameraStageBaseScreen() { game.gameInfo.nextTurn() bottomBar.unitTable.currentlyExecutingAction = null - GameSaver.saveGame(game.gameInfo, "Autosave") + kotlin.concurrent.thread { GameSaver.saveGame(game.gameInfo, "Autosave") } update() displayTutorials("NextTurn") diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index f68fbdfb..65b93c06 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -60,7 +60,6 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ unitDescriptionLabel.setText(unitLabelText) - } else { unitNameLabel.setText("")