mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-05 21:11:35 +07:00
perf: Save resource uniques when resources change, so we only need one lookup for all resources for uniques
*significant* impact, estimated at 6% of runtime (!)
This commit is contained in:
parent
7c46b3533b
commit
2647b24e09
@ -47,11 +47,7 @@ import com.unciv.models.ruleset.tile.ResourceSupplyList
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.ruleset.tile.TileImprovement
|
||||
import com.unciv.models.ruleset.tile.TileResource
|
||||
import com.unciv.models.ruleset.unique.StateForConditionals
|
||||
import com.unciv.models.ruleset.unique.TemporaryUnique
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.ruleset.unique.getMatchingUniques
|
||||
import com.unciv.models.ruleset.unique.*
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
@ -119,6 +115,9 @@ class Civilization : IsPartOfGameInfoSerialization {
|
||||
|
||||
@Transient
|
||||
var summarizedCivResourceSupply = ResourceSupplyList()
|
||||
|
||||
@Transient
|
||||
var civResourcesUniqueMap = UniqueMap()
|
||||
|
||||
@Transient
|
||||
val cityStateFunctions = CityStateFunctions(this)
|
||||
@ -535,11 +534,7 @@ class Civilization : IsPartOfGameInfoSerialization {
|
||||
if (religionManager.religion != null)
|
||||
yieldAll(religionManager.religion!!.founderBeliefUniqueMap.getMatchingUniques(uniqueType, stateForConditionals))
|
||||
|
||||
yieldAll(getCivResourceSupply().asSequence()
|
||||
.filter { it.amount > 0 && it.resource.uniques.isNotEmpty() }
|
||||
.flatMap { it.resource.getMatchingUniques(uniqueType, stateForConditionals) }
|
||||
)
|
||||
|
||||
yieldAll(civResourcesUniqueMap.getMatchingUniques(uniqueType, stateForConditionals))
|
||||
yieldAll(gameInfo.ruleset.globalUniques.getMatchingUniques(uniqueType, stateForConditionals))
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,7 @@ import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.ruleset.tile.ResourceSupplyList
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.ruleset.tile.TileImprovement
|
||||
import com.unciv.models.ruleset.unique.StateForConditionals
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.ruleset.unique.*
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.utils.DebugUtils
|
||||
@ -359,8 +356,16 @@ class CivInfoTransientCache(val civInfo: Civilization) {
|
||||
// Check if anything has actually changed so we don't update stats for no reason - this uses List equality which means it checks the elements
|
||||
if (civInfo.detailedCivResources == newDetailedCivResources) return
|
||||
|
||||
val summarizedResourceSupply = newDetailedCivResources.sumByResource("All")
|
||||
|
||||
val newResourceUniqueMap = UniqueMap()
|
||||
for (resource in civInfo.summarizedCivResourceSupply)
|
||||
if (resource.amount > 0)
|
||||
newResourceUniqueMap.addUniques(resource.resource.uniqueObjects)
|
||||
|
||||
civInfo.detailedCivResources = newDetailedCivResources
|
||||
civInfo.summarizedCivResourceSupply = newDetailedCivResources.sumByResource("All")
|
||||
civInfo.summarizedCivResourceSupply = summarizedResourceSupply
|
||||
civInfo.civResourcesUniqueMap = newResourceUniqueMap
|
||||
|
||||
civInfo.updateStatsForNextTurn() // More or less resources = more or less happiness, with potential domino effects
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user