Throttle cable path searches
This commit is contained in:
parent
1f669ba2b2
commit
bb9d5d9ae0
@ -8,6 +8,7 @@ import org.apache.logging.log4j.LogManager
|
|||||||
import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
|
import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
|
||||||
import ru.dbotthepony.mc.otm.UNIVERSE_TICKS
|
import ru.dbotthepony.mc.otm.UNIVERSE_TICKS
|
||||||
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
||||||
|
import ru.dbotthepony.mc.otm.config.CablesConfig
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
||||||
import ru.dbotthepony.mc.otm.core.shuffle
|
import ru.dbotthepony.mc.otm.core.shuffle
|
||||||
@ -446,16 +447,26 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastTickSearches = 0
|
||||||
|
private var searchedOnTick = 0
|
||||||
|
|
||||||
private fun getPath(a: EnergyCableBlockEntity.Node, b: EnergyCableBlockEntity.Node, energyToTransfer: Decimal, sort: Boolean): List<SegmentPath> {
|
private fun getPath(a: EnergyCableBlockEntity.Node, b: EnergyCableBlockEntity.Node, energyToTransfer: Decimal, sort: Boolean): List<SegmentPath> {
|
||||||
if (!a.canTraverse || !b.canTraverse)
|
if (!a.canTraverse || !b.canTraverse)
|
||||||
return listOf()
|
return listOf()
|
||||||
|
|
||||||
|
if (searchedOnTick != UNIVERSE_TICKS) {
|
||||||
|
searchedOnTick = UNIVERSE_TICKS
|
||||||
|
lastTickSearches = 0
|
||||||
|
}
|
||||||
|
|
||||||
val list = pathCache.computeIfAbsent(a to b) { CacheEntry() }
|
val list = pathCache.computeIfAbsent(a to b) { CacheEntry() }
|
||||||
|
|
||||||
if (!list.saturated) {
|
val maxSearches = CablesConfig.SEARCHES_PER_TICK
|
||||||
|
|
||||||
|
if (!list.saturated && lastTickSearches <= maxSearches) {
|
||||||
var maxThroughput = list.paths.maxOfOrNull { it.availableThroughput } ?: Decimal.ZERO
|
var maxThroughput = list.paths.maxOfOrNull { it.availableThroughput } ?: Decimal.ZERO
|
||||||
|
|
||||||
while (maxThroughput < energyToTransfer && !list.saturated) {
|
while (maxThroughput < energyToTransfer && !list.saturated && ++lastTickSearches <= maxSearches) {
|
||||||
val find = findPath(a, b, list.paths, maxThroughput)
|
val find = findPath(a, b, list.paths, maxThroughput)
|
||||||
|
|
||||||
if (find == null || find in list.paths) {
|
if (find == null || find in list.paths) {
|
||||||
|
@ -27,4 +27,10 @@ object CablesConfig : AbstractConfig("cables") {
|
|||||||
init {
|
init {
|
||||||
E.SUPERCONDUCTOR
|
E.SUPERCONDUCTOR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val SEARCHES_PER_TICK: Int by builder
|
||||||
|
.comment("How many paths are allowed to be searched for during single tick *per* cable network")
|
||||||
|
.comment("Too low value will make huge cable networks woozy when their cabling changes (e.g. cable added or removed, or valve switched)")
|
||||||
|
.comment("Too high value will create lag spikes depending on complexity of cable network at hand when cabling changes")
|
||||||
|
.defineInRange("SEARCHER_PER_TICK", 40, 1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user