Hopefully solved ANR when loading the game initially

This commit is contained in:
Yair Morgenstern
2019-12-17 20:46:30 +02:00
parent e82cdd42fa
commit b0a0638e84

View File

@ -40,28 +40,34 @@ class UncivGame(val version: String) : Game() {
lateinit var ruleset:Ruleset
override fun create() {
// If this takes too long players, especially with older phones, get ANR problems.
// Whatever needs graphics needs to be done on the main thread,
// So it's basically a long set of deferred actions.
// We probably could make this better by moving stuff that we can to another thread but ehhhhhhh
Current = this
ruleset = Ruleset(true)
Gdx.app.postRunnable {
ruleset = Ruleset(true)
if(Gdx.app.type!= Application.ApplicationType.Desktop)
viewEntireMapForDebug=false
Gdx.input.setCatchKey(Input.Keys.BACK, true)
settings = GameSaver().getGeneralSettings()
if(settings.userId=="") { // assign permanent user id
settings.userId = UUID.randomUUID().toString()
settings.save()
}
if (GameSaver().getSave("Autosave").exists()) {
try {
loadGame("Autosave")
} catch (ex: Exception) { // silent fail if we can't read the autosave
startNewGame()
if (Gdx.app.type != Application.ApplicationType.Desktop)
viewEntireMapForDebug = false
Gdx.input.setCatchKey(Input.Keys.BACK, true)
settings = GameSaver().getGeneralSettings()
if (settings.userId == "") { // assign permanent user id
settings.userId = UUID.randomUUID().toString()
settings.save()
}
}
else setScreen(LanguagePickerScreen())
if (GameSaver().getSave("Autosave").exists()) {
try {
loadGame("Autosave")
} catch (ex: Exception) { // silent fail if we can't read the autosave
startNewGame()
}
} else setScreen(LanguagePickerScreen())
thread { startMusic() }
isInitialized=true
thread { startMusic() }
isInitialized = true
}
}
fun startMusic(){