Compare commits
2 Commits
3f87459f35
...
fdc9944c17
Author | SHA1 | Date | |
---|---|---|---|
fdc9944c17 | |||
8544368ab2 |
@ -3,15 +3,12 @@ package ru.dbotthepony.mc.otm.block.entity.cable
|
|||||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
|
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
|
||||||
import it.unimi.dsi.fastutil.objects.ReferenceArraySet
|
import it.unimi.dsi.fastutil.objects.ReferenceArraySet
|
||||||
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet
|
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet
|
||||||
import net.minecraft.core.BlockPos
|
|
||||||
import org.apache.logging.log4j.LogManager
|
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.config.CablesConfig
|
||||||
import ru.dbotthepony.mc.otm.core.addAll
|
|
||||||
import ru.dbotthepony.mc.otm.core.collect.map
|
import ru.dbotthepony.mc.otm.core.collect.map
|
||||||
import ru.dbotthepony.mc.otm.core.collect.max
|
|
||||||
import ru.dbotthepony.mc.otm.core.collect.reduce
|
import ru.dbotthepony.mc.otm.core.collect.reduce
|
||||||
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
|
||||||
@ -480,7 +477,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
private var searchedOnTick = 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 || energyToTransfer <= Decimal.ZERO)
|
||||||
return listOf()
|
return listOf()
|
||||||
|
|
||||||
if (searchedOnTick != UNIVERSE_TICKS) {
|
if (searchedOnTick != UNIVERSE_TICKS) {
|
||||||
@ -493,17 +490,18 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
val maxSearches = CablesConfig.SEARCHES_PER_TICK
|
val maxSearches = CablesConfig.SEARCHES_PER_TICK
|
||||||
|
|
||||||
if (!list.saturated && lastTickSearches <= maxSearches) {
|
if (!list.saturated && lastTickSearches <= maxSearches) {
|
||||||
var maxThroughput = list.paths.iterator().map { it.availableThroughput }.reduce(Decimal.ZERO, Decimal::plus)
|
var maxThroughput = list.paths.maxOfOrNull { it.availableThroughput } ?: Decimal.ZERO
|
||||||
|
var combinedThroughput = list.paths.iterator().map { it.availableThroughput }.reduce(Decimal.ZERO, Decimal::plus)
|
||||||
|
|
||||||
while (maxThroughput < energyToTransfer && !list.saturated && ++lastTickSearches <= maxSearches) {
|
while (combinedThroughput < energyToTransfer && !list.saturated && ++lastTickSearches <= maxSearches) {
|
||||||
// TODO: Heuristics here is wrong
|
|
||||||
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) {
|
||||||
list.saturated = true
|
list.saturated = true
|
||||||
} else {
|
} else {
|
||||||
list.paths.add(find)
|
list.paths.add(find)
|
||||||
maxThroughput += find.availableThroughput
|
combinedThroughput += find.availableThroughput
|
||||||
|
maxThroughput = maxOf(maxThroughput, find.availableThroughput)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,7 +523,6 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
|
|
||||||
node.segment.paths.forEach {
|
node.segment.paths.forEach {
|
||||||
pathCache.remove(it.a to it.b)
|
pathCache.remove(it.a to it.b)
|
||||||
pathCache.remove(it.b to it.a)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node.segment.paths = ReferenceLinkedOpenHashSet()
|
node.segment.paths = ReferenceLinkedOpenHashSet()
|
||||||
@ -561,7 +558,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
val it = side.neighbour.get() ?: continue
|
val it = side.neighbour.get() ?: continue
|
||||||
if (it is EnergyCableBlockEntity.CableSide) continue
|
if (it is EnergyCableBlockEntity.CableSide) continue
|
||||||
|
|
||||||
val paths = getPath(fromNode, node, residue, !simulate)
|
val paths = getPath(fromNode, node, it.receiveEnergy(residue, true), !simulate)
|
||||||
hit = true
|
hit = true
|
||||||
|
|
||||||
if (paths.size == 1) {
|
if (paths.size == 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user