Loading a new game while nextTurn is running no longer reverts you to that game

This commit is contained in:
Yair Morgenstern
2022-02-09 18:02:52 +02:00
parent 13f052878b
commit dcdb0ca892

View File

@ -636,12 +636,13 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
if (consoleLog)
println("\nNext turn starting " + Date().formatDate())
val startTime = System.currentTimeMillis()
val gameInfoClone = gameInfo.clone()
val originalGameInfo = gameInfo
val gameInfoClone = originalGameInfo.clone()
gameInfoClone.setTransients() // this can get expensive on large games, not the clone itself
gameInfoClone.nextTurn()
if (gameInfo.gameParameters.isOnlineMultiplayer) {
if (originalGameInfo.gameParameters.isOnlineMultiplayer) {
try {
OnlineMultiplayer().tryUploadGame(gameInfoClone, withPreview = true)
} catch (ex: Exception) {
@ -657,6 +658,9 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
}
}
if (game.gameInfo != originalGameInfo) // while this was turning we loaded another game
return@crashHandlingThread
game.gameInfo = gameInfoClone
if (consoleLog)
println("Next turn took ${System.currentTimeMillis()-startTime}ms")
@ -667,7 +671,6 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
// do this on main thread - it's the only one that has a GL context to create images from
postCrashHandlingRunnable {
if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName
&& !gameInfoClone.gameParameters.isOnlineMultiplayer)
game.setScreen(PlayerReadyScreen(gameInfoClone, gameInfoClone.getCurrentPlayerCivilization()))