From e16ea5c80339c88add03969bd20b83ba66d7ba54 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 21 Nov 2018 20:02:12 +0200 Subject: [PATCH] Performance: Added Transient list of researched technologies --- android/build.gradle | 4 ++-- .../unciv/logic/civilization/CivilizationInfo.kt | 2 +- .../src/com/unciv/logic/civilization/TechManager.kt | 13 ++++++++----- .../com/unciv/ui/worldscreen/WorldScreenTopBar.kt | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index c94cf7668f..d65688c6e6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 163 - versionName "2.10.3" + versionCode 165 + versionName "2.10.4" } buildTypes { release { diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index d175fd0c77..6e2de64e36 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -237,7 +237,7 @@ class CivilizationInfo { fun isDefeated()= cities.isEmpty() && !getCivUnits().any{it.name=="Settler"} fun getEra(): TechEra { - val maxEraOfTech = tech.getResearchedTechs() + val maxEraOfTech = tech.researchedTechnologies .map { it.era() } .max() if(maxEraOfTech!=null) return maxEraOfTech diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index c9850e437c..7b63e72a00 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -9,8 +9,8 @@ import com.unciv.ui.utils.tr import java.util.* class TechManager { - @Transient - lateinit var civInfo: CivilizationInfo + @Transient lateinit var civInfo: CivilizationInfo + @Transient val researchedTechnologies=ArrayList() var freeTechs = 0 var techsResearched = HashSet() @@ -57,9 +57,7 @@ class TechManager { return GameBasics.Technologies[TechName]!!.prerequisites.all { isResearched(it) } } - fun getResearchedTechs() = techsResearched.map { GameBasics.Technologies[it]!! } - - fun getUniques() = getResearchedTechs().flatMap { it.uniques } + fun getUniques() = researchedTechnologies.flatMap { it.uniques } //endregion @@ -77,6 +75,7 @@ class TechManager { if(currentTechnology!="Future Tech") techsToResearch.remove(currentTechnology) techsResearched.add(currentTechnology) + researchedTechnologies.add(GameBasics.Technologies[currentTechnology]!!) civInfo.addNotification("Research of [$currentTechnology] has completed!", null, Color.BLUE) val currentEra = civInfo.getEra() @@ -109,6 +108,10 @@ class TechManager { city.cityConstructions.currentConstruction = currentConstructionUnit.upgradesTo!! } } + + fun setTransients(){ + researchedTechnologies.addAll(techsResearched.map { GameBasics.Technologies[it]!! }) + } } diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt b/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt index 9cc336dcd8..b914fc5466 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt @@ -131,7 +131,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() { val nextTurnStats = civInfo.getStatsForNextTurn() val goldPerTurn = "(" + (if (nextTurnStats.gold > 0) "+" else "") + Math.round(nextTurnStats.gold) + ")" - goldLabel.setText("" + Math.round(civInfo.gold.toFloat()) + goldPerTurn) + goldLabel.setText(Math.round(civInfo.gold.toFloat()).toString() + goldPerTurn) scienceLabel.setText("+" + Math.round(nextTurnStats.science))