Compare commits
No commits in common. "436456dcc53bbc89e3fd4060e6b6b21fd85934cf" and "43afa73df7743bc28578e1f8a383ffa037043dda" have entirely different histories.
436456dcc5
...
43afa73df7
@ -20,14 +20,10 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
private val livelyNodesList = ArrayList<EnergyCableBlockEntity.Node>()
|
private val livelyNodesList = ArrayList<EnergyCableBlockEntity.Node>()
|
||||||
|
|
||||||
fun addLivelyNode(node: EnergyCableBlockEntity.Node) {
|
fun addLivelyNode(node: EnergyCableBlockEntity.Node) {
|
||||||
when (contains(node)) {
|
require(node in nodesSet) { "$node does not belong to $this" }
|
||||||
ContainsStatus.ABOUT_TO_BE_REMOVED, ContainsStatus.ABOUT_TO_BE_ADDED -> { } // do nothing
|
|
||||||
ContainsStatus.DOES_NOT_BELONG -> throw IllegalArgumentException("$node does not belong to $this")
|
if (livelyNodes.add(node)) {
|
||||||
ContainsStatus.CONTAINS -> {
|
livelyNodesList.add(node)
|
||||||
if (livelyNodes.add(node)) {
|
|
||||||
livelyNodesList.add(node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,14 +95,8 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
var transferredLastTick = Decimal.ZERO
|
var transferredLastTick = Decimal.ZERO
|
||||||
private set
|
private set
|
||||||
|
|
||||||
val availableThroughput: Decimal get() {
|
val availableThroughput: Decimal
|
||||||
if (!throughputKnown) {
|
get() = throughput - transferredLastTick
|
||||||
throughput = nodes.maxOf { it.energyThroughput }
|
|
||||||
throughputKnown = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return throughput - transferredLastTick
|
|
||||||
}
|
|
||||||
|
|
||||||
private var throughputKnown = false
|
private var throughputKnown = false
|
||||||
private var lastTick = 0
|
private var lastTick = 0
|
||||||
|
@ -22,26 +22,6 @@ open class GraphNodeList<N : GraphNode<N, G>, G : GraphNodeList<N, G>> : ICondit
|
|||||||
val nodesSet: Set<N> = Collections.unmodifiableSet(nodesSetInternal)
|
val nodesSet: Set<N> = Collections.unmodifiableSet(nodesSetInternal)
|
||||||
val size get() = nodesInternal.size
|
val size get() = nodesInternal.size
|
||||||
|
|
||||||
enum class ContainsStatus(val belongs: Boolean, val potentiallyBelongs: Boolean) {
|
|
||||||
ABOUT_TO_BE_REMOVED(true, false),
|
|
||||||
DOES_NOT_BELONG(false, false),
|
|
||||||
ABOUT_TO_BE_ADDED(false, true),
|
|
||||||
CONTAINS(true, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun contains(node: N): ContainsStatus {
|
|
||||||
if (node in nodesSet) {
|
|
||||||
if (node in queuedRemove)
|
|
||||||
return ContainsStatus.ABOUT_TO_BE_REMOVED
|
|
||||||
|
|
||||||
return ContainsStatus.CONTAINS
|
|
||||||
} else if (node in queuedAdd) {
|
|
||||||
return ContainsStatus.ABOUT_TO_BE_ADDED
|
|
||||||
} else {
|
|
||||||
return ContainsStatus.DOES_NOT_BELONG
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var isValid = true
|
var isValid = true
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user