Improve cable path search performance when there are a lot of paths existing already

This commit is contained in:
DBotThePony 2025-02-11 11:12:11 +07:00
parent 590f420c07
commit 89ca0fbce8
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -426,6 +426,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
openNodes.add(SearchNode(a, b, null, seenTop))
val existingNodes = HashSet<EnergyCableBlockEntity.Node>()
existing.forEach { existingNodes.addAll(it.nodes) }
while (openNodes.isNotEmpty()) {
val first = openNodes.remove()
openNodes.remove(first)
@ -466,7 +469,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
} else {
for (neighbour in first.node.neighboursView.values) {
if (!seenNodes.add(neighbour) || !neighbour.canTraverse) continue
val seen = existing.any { neighbour in it }
val seen = neighbour in existingNodes
if (seen && neighbour.energyThroughput <= threshold) continue
openNodes.add(SearchNode(neighbour, b, first, seen))
}