Improve extra path search performance
This commit is contained in:
parent
bb9d5d9ae0
commit
614ba26da6
@ -9,6 +9,7 @@ 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.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
|
||||||
@ -69,6 +70,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
|
|
||||||
class SegmentPath(private val a: BlockPos, private val b: BlockPos) {
|
class SegmentPath(private val a: BlockPos, private val b: BlockPos) {
|
||||||
val segments = LinkedHashSet<Segment>()
|
val segments = LinkedHashSet<Segment>()
|
||||||
|
val nodes = HashSet<EnergyCableBlockEntity.Node>()
|
||||||
var shortCircuit = false
|
var shortCircuit = false
|
||||||
private var lastTickTransfers = 0
|
private var lastTickTransfers = 0
|
||||||
private var lastTick = 0
|
private var lastTick = 0
|
||||||
@ -81,7 +83,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator fun contains(node: EnergyCableBlockEntity.Node): Boolean {
|
operator fun contains(node: EnergyCableBlockEntity.Node): Boolean {
|
||||||
return segments.any { node in it }
|
return node in nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -284,11 +286,13 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
fun remove(node: EnergyCableBlockEntity.Node) {
|
fun remove(node: EnergyCableBlockEntity.Node) {
|
||||||
check(nodes.remove(node)) { "Tried to remove node $node from segment $this, but that node does not belong to this segment" }
|
check(nodes.remove(node)) { "Tried to remove node $node from segment $this, but that node does not belong to this segment" }
|
||||||
|
|
||||||
|
paths.forEach { it.nodes.remove(node) }
|
||||||
throughputKnown = false
|
throughputKnown = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(node: EnergyCableBlockEntity.Node) {
|
fun add(node: EnergyCableBlockEntity.Node) {
|
||||||
check(nodes.add(node)) { "Tried to add node $node to segment $this, but we already have that node added" }
|
check(nodes.add(node)) { "Tried to add node $node to segment $this, but we already have that node added" }
|
||||||
|
paths.forEach { it.nodes.add(node) }
|
||||||
|
|
||||||
if (throughputKnown)
|
if (throughputKnown)
|
||||||
throughput = maxOf(throughput, node.energyThroughput)
|
throughput = maxOf(throughput, node.energyThroughput)
|
||||||
@ -297,12 +301,14 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
fun add(path: SegmentPath) {
|
fun add(path: SegmentPath) {
|
||||||
if (paths.add(path)) {
|
if (paths.add(path)) {
|
||||||
check(path.segments.add(this)) { "Path set and Segment disagree whenever $this is absent from $path" }
|
check(path.segments.add(this)) { "Path set and Segment disagree whenever $this is absent from $path" }
|
||||||
|
path.nodes.addAll(nodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun remove(path: SegmentPath) {
|
fun remove(path: SegmentPath) {
|
||||||
check(paths.remove(path)) { "Path $path should already contain $this" }
|
check(paths.remove(path)) { "Path $path should already contain $this" }
|
||||||
check(path.segments.remove(this)) { "Path set and Segment disagree whenever $this is present in $path" }
|
check(path.segments.remove(this)) { "Path set and Segment disagree whenever $this is present in $path" }
|
||||||
|
path.nodes.removeAll(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// breaks "instant snapshots" of segments atm
|
// breaks "instant snapshots" of segments atm
|
||||||
|
Loading…
Reference in New Issue
Block a user