Try to search for better path when cabling changes even if current path set is sufficient
This commit is contained in:
parent
486060c8a4
commit
be9641fc03
@ -90,6 +90,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
private class CacheEntry {
|
private class CacheEntry {
|
||||||
val paths = ArrayList<SegmentPath>(1)
|
val paths = ArrayList<SegmentPath>(1)
|
||||||
var saturated = false
|
var saturated = false
|
||||||
|
var forceExploreAlternatives = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: LRU cache?
|
// TODO: LRU cache?
|
||||||
@ -548,7 +549,8 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
var maxThroughput = list.paths.maxOfOrNull { it.availableThroughput } ?: Decimal.ZERO
|
var maxThroughput = list.paths.maxOfOrNull { it.availableThroughput } ?: Decimal.ZERO
|
||||||
var combinedThroughput = list.paths.iterator().map { it.availableThroughput }.reduce(Decimal.ZERO, Decimal::plus)
|
var combinedThroughput = list.paths.iterator().map { it.availableThroughput }.reduce(Decimal.ZERO, Decimal::plus)
|
||||||
|
|
||||||
while (combinedThroughput < energyToTransfer && !list.saturated && ++lastTickSearches <= maxSearches) {
|
while ((list.forceExploreAlternatives || combinedThroughput < energyToTransfer) && !list.saturated && ++lastTickSearches <= maxSearches) {
|
||||||
|
list.forceExploreAlternatives = false
|
||||||
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) {
|
||||||
@ -568,7 +570,10 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun notifyThroughputsChanged() {
|
fun notifyThroughputsChanged() {
|
||||||
pathCache.values.forEach { it.saturated = false }
|
pathCache.values.forEach {
|
||||||
|
it.saturated = false
|
||||||
|
it.forceExploreAlternatives = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNodeRemoved(node: EnergyCableBlockEntity.Node) {
|
override fun onNodeRemoved(node: EnergyCableBlockEntity.Node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user