Solved ANRs caused by slow "quickstarts"

This commit is contained in:
yairm210
2021-10-31 22:38:48 +02:00
parent b7f9472308
commit d2add82ac3
2 changed files with 25 additions and 8 deletions

View File

@ -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)
}
}
}
}

View File

@ -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
}
}