mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-05 21:11:35 +07:00
perf: minor memory perf
This commit is contained in:
parent
2647b24e09
commit
563925bbf5
@ -76,8 +76,8 @@ class WorkerAutomation(
|
||||
// Must be called before any getPriority checks to guarantee the local road cache is processed
|
||||
val citiesToConnect = roadBetweenCitiesAutomation.getNearbyCitiesToConnect(unit)
|
||||
// Shortcut, we are working a suitable tile, and we're better off minimizing worker-turns by finishing everything on this tile
|
||||
if (!dangerousTiles.contains(currentTile) && getFullPriority(unit.getTile(), unit, localUniqueCache) >= 2
|
||||
&& currentTile.improvementInProgress != null) {
|
||||
if (currentTile.improvementInProgress != null && !dangerousTiles.contains(currentTile)
|
||||
&& getFullPriority(unit.getTile(), unit, localUniqueCache) >= 2) {
|
||||
return
|
||||
}
|
||||
val tileToWork = findTileToWork(unit, dangerousTiles, localUniqueCache)
|
||||
|
@ -12,6 +12,13 @@ import kotlin.random.Random
|
||||
|
||||
object Conditionals {
|
||||
|
||||
private fun getStateBasedRandom(state: StateForConditionals, unique: Unique?): Float {
|
||||
var seed = state.gameInfo?.turns?.hashCode() ?: 0
|
||||
seed = seed * 31 + (unique?.hashCode() ?: 0)
|
||||
seed = seed * 31 + state.hashCode()
|
||||
return Random(seed).nextFloat()
|
||||
}
|
||||
|
||||
fun conditionalApplies(
|
||||
unique: Unique?,
|
||||
conditional: Unique,
|
||||
@ -21,13 +28,6 @@ object Conditionals {
|
||||
if (conditional.type?.targetTypes?.any { it.modifierType == UniqueTarget.ModifierType.Other } == true)
|
||||
return true // not a filtering condition, includes e.g. ModifierHiddenFromUsers
|
||||
|
||||
val stateBasedRandom by lazy {
|
||||
var seed = state.gameInfo?.turns?.hashCode() ?: 0
|
||||
seed = seed * 31 + (unique?.hashCode() ?: 0)
|
||||
seed = seed * 31 + state.hashCode()
|
||||
Random(seed)
|
||||
}
|
||||
|
||||
/** Helper to simplify conditional tests requiring gameInfo */
|
||||
fun checkOnGameInfo(predicate: (GameInfo.() -> Boolean)): Boolean {
|
||||
if (state.gameInfo == null) return false
|
||||
@ -103,7 +103,7 @@ object Conditionals {
|
||||
}
|
||||
|
||||
return when (conditional.type) {
|
||||
UniqueType.ConditionalChance -> stateBasedRandom.nextFloat() < conditional.params[0].toFloat() / 100f
|
||||
UniqueType.ConditionalChance -> getStateBasedRandom(state, unique) < conditional.params[0].toFloat() / 100f
|
||||
UniqueType.ConditionalEveryTurns -> checkOnGameInfo { turns % conditional.params[0].toInt() == 0 }
|
||||
UniqueType.ConditionalBeforeTurns -> checkOnGameInfo { turns < conditional.params[0].toInt() }
|
||||
UniqueType.ConditionalAfterTurns -> checkOnGameInfo { turns >= conditional.params[0].toInt() }
|
||||
|
Loading…
Reference in New Issue
Block a user