mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
Fixed some concurrency problems
This commit is contained in:
parent
fe67fda906
commit
8b90571a77
@ -105,6 +105,7 @@ class GameInfo {
|
||||
toReturn.tileMap=tileMap.clone()
|
||||
toReturn.notifications.addAll(notifications)
|
||||
toReturn.turns=turns
|
||||
toReturn.setTransients()
|
||||
return toReturn
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.unciv.logic
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.unciv.GameSettings
|
||||
import com.unciv.OldGameSettings
|
||||
import com.unciv.UnCivGame
|
||||
@ -10,6 +9,8 @@ import com.unciv.UnCivGame
|
||||
class GameSaver {
|
||||
private val saveFilesFolder = "SaveFiles"
|
||||
|
||||
fun json() = UnCivGame.Current.json
|
||||
|
||||
fun getSave(GameName: String): FileHandle {
|
||||
return Gdx.files.local("$saveFilesFolder/$GameName")
|
||||
}
|
||||
@ -19,11 +20,11 @@ class GameSaver {
|
||||
}
|
||||
|
||||
fun saveGame(game: GameInfo, GameName: String) {
|
||||
getSave(GameName).writeString(Json().toJson(game), false)
|
||||
getSave(GameName).writeString(json().toJson(game), false)
|
||||
}
|
||||
|
||||
fun loadGame(GameName: String) : GameInfo {
|
||||
val game = UnCivGame.Current.json.fromJson(GameInfo::class.java, getSave(GameName).readString())
|
||||
val game = json().fromJson(GameInfo::class.java, getSave(GameName).readString())
|
||||
game.setTransients()
|
||||
return game
|
||||
}
|
||||
@ -40,14 +41,14 @@ class GameSaver {
|
||||
val settingsFile = getGeneralSettingsFile()
|
||||
if(!settingsFile.exists()) return GameSettings()
|
||||
try {
|
||||
return UnCivGame.Current.json.fromJson(GameSettings::class.java, settingsFile)
|
||||
return json().fromJson(GameSettings::class.java, settingsFile)
|
||||
}
|
||||
catch(ex:Exception) {
|
||||
return UnCivGame.Current.json.fromJson(OldGameSettings::class.java, settingsFile).toGameSettings()
|
||||
return json().fromJson(OldGameSettings::class.java, settingsFile).toGameSettings()
|
||||
}
|
||||
}
|
||||
|
||||
fun setGeneralSettings(gameSettings: GameSettings){
|
||||
getGeneralSettingsFile().writeString(Json().toJson(gameSettings), false)
|
||||
getGeneralSettingsFile().writeString(json().toJson(gameSettings), false)
|
||||
}
|
||||
}
|
||||
|
@ -320,6 +320,4 @@ class CivilizationInfo {
|
||||
toReturn.civName=civName
|
||||
return toReturn
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -84,6 +84,7 @@ class TileMap {
|
||||
fun clone(): TileMap {
|
||||
val toReturn = TileMap()
|
||||
toReturn.tiles.putAll(tiles.values.map { it.clone() }.associateBy{it.position.toString()})
|
||||
setTransients()
|
||||
return toReturn
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,11 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
|
||||
|
||||
fun update() {
|
||||
kotlin.concurrent.thread { civInfo.happiness = civInfo.getHappinessForNextTurn().values.sum().toInt() }
|
||||
val gameClone = gameInfo.clone()
|
||||
// so we don't get a concurrent modification exception, we clone the entire game (yes really, it's actually very fast)
|
||||
kotlin.concurrent.thread {
|
||||
civInfo.happiness = gameClone.getPlayerCivilization().getHappinessForNextTurn().values.sum().toInt()
|
||||
}
|
||||
|
||||
if(UnCivGame.Current.settings.hasCrashedRecently){
|
||||
displayTutorials("GameCrashed")
|
||||
|
Loading…
Reference in New Issue
Block a user