Memory improvements, hoping to mitigate OutOfMemory errors

This commit is contained in:
Yair Morgenstern 2019-07-22 22:36:14 +03:00
parent 133b0d7abe
commit 78b9908479
3 changed files with 17 additions and 10 deletions

View file

@ -75,6 +75,7 @@ class UnCivGame(val version: String) : Game() {
if(gameInfo.civilizations.isEmpty())
return create()
if(::worldScreen.isInitialized) worldScreen.dispose() // I hope this will solve some of the many OuOfMemory exceptions...
worldScreen = WorldScreen()
setWorldScreen()
}

View file

@ -118,16 +118,22 @@ class CityConstructions {
fun turnsToConstruction(constructionName: String): Int {
val workLeft = getRemainingWork(constructionName)
// The ol' Switcharoo - what would our stats be if that was our current construction?
// Since this is only ever used for UI purposes, I feel fine with having it be a bit inefficient
// and recalculating the entire city stats
val currConstruction = currentConstruction
currentConstruction = constructionName
cityInfo.cityStats.update()
val cityStatsForConstruction = cityInfo.cityStats.currentCityStats
// revert!
currentConstruction = currConstruction
cityInfo.cityStats.update()
val cityStatsForConstruction: Stats
if (currentConstruction == constructionName) cityStatsForConstruction = cityInfo.cityStats.currentCityStats
else {
// The ol' Switcharoo - what would our stats be if that was our current construction?
// Since this is only ever used for UI purposes, I feel fine with having it be a bit inefficient
// and recalculating the entire city stats
currentConstruction = constructionName
cityInfo.cityStats.update()
cityStatsForConstruction = cityInfo.cityStats.currentCityStats
// revert!
currentConstruction = currConstruction
cityInfo.cityStats.update()
}
var production = Math.round(cityStatsForConstruction.production)
if (constructionName == Constants.settler) production += cityStatsForConstruction.food.toInt()

View file

@ -37,7 +37,7 @@ class CivInfoStats(val civInfo: CivilizationInfo){
private fun getTransportationUpkeep(): Int {
var transportationUpkeep = 0
for (it in civInfo.gameInfo.tileMap.values.filter { it.getOwner()==civInfo }.filterNot { it.isCityCenter() }) {
for (it in civInfo.cities.flatMap { it.getTiles() }.filter{ !it.isCityCenter() }) {
when(it.roadStatus) {
RoadStatus.Road -> transportationUpkeep += 1
RoadStatus.Railroad -> transportationUpkeep += 2