From d2add82ac36bba2fbf5ea17838b253ca6f520204 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Sun, 31 Oct 2021 22:38:48 +0200 Subject: [PATCH] Solved ANRs caused by slow "quickstarts" --- core/src/com/unciv/MainMenuScreen.kt | 28 +++++++++++++++++++---- core/src/com/unciv/logic/city/CityInfo.kt | 5 ++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/MainMenuScreen.kt b/core/src/com/unciv/MainMenuScreen.kt index 5cfe17d7e8..ad7ace2113 100644 --- a/core/src/com/unciv/MainMenuScreen.kt +++ b/core/src/com/unciv/MainMenuScreen.kt @@ -17,6 +17,7 @@ import com.unciv.models.ruleset.RulesetCache import com.unciv.ui.MultiplayerScreen import com.unciv.ui.mapeditor.* import com.unciv.models.metadata.GameSetupInfo +import com.unciv.models.translations.tr import com.unciv.ui.newgamescreen.NewGameScreen import com.unciv.ui.pickerscreens.ModManagementScreen import com.unciv.ui.saves.LoadGameScreen @@ -235,11 +236,28 @@ class MainMenuScreen: CameraStageBaseScreen() { } private fun quickstartNewGame() { - try { - val newGame = GameStarter.startNewGame(GameSetupInfo.fromSettings("Chieftain")) - game.loadGame(newGame) - } catch (ex: Exception) { - ToastPopup("Cannot start game with the default new game parameters!", this) + ToastPopup("Working...", this) + val errorText = "Cannot start game with the default new game parameters!" + thread { + val newGame: GameInfo + // Can fail when starting the game... + try { + newGame = GameStarter.startNewGame(GameSetupInfo.fromSettings("Chieftain")) + } catch (ex: Exception) { + Gdx.app.postRunnable { ToastPopup(errorText, this) } + return@thread + } + + // ...or when loading the game + Gdx.app.postRunnable { + try { + game.loadGame(newGame) + } catch (outOfMemory: OutOfMemoryError) { + ToastPopup("Not enough memory on phone to load game!", this) + } catch (ex: Exception) { + ToastPopup(errorText, this) + } + } } } diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 22b2d72a56..dd6a64f9ff 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -709,9 +709,8 @@ class CityInfo { // The localUniques might not be filtered when passed as a parameter, so we filter it anyway // The time loss shouldn't be that large I don't think return civInfo.getMatchingUniques(placeholderText, this) + - localUniques.filter { - it.placeholderText == placeholderText - && it.params.none { param -> param == "in other cities" } + localUniques.filter { + !it.isAntiLocalEffect && it.placeholderText == placeholderText } }