Skip to content

Commit

Permalink
Rename field, tweak javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Dec 17, 2024
1 parent a9e336b commit 132f263
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/main/java/appeng/me/GridNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class GridNode implements IGridNode, IPathItem, IDebugExportable {
/**
* Used to quickly walk the path to the controller when checking channel assignability, based on the observation
* that the max channel count increases as we get to the controller, and that we only need to check the highest node
* of each type.
* of each max channel count.
* <p>
* For example, on the following path:
* {@code controller - dense cable 1 - dense cable 2 - dense cable 3 - cable 1 - cable 2 - cable 3 - device}, we
Expand All @@ -123,7 +123,7 @@ public class GridNode implements IGridNode, IPathItem, IDebugExportable {
* This field is used to jump up the path. It is {@code null} if the next node is a controller.
*/
@Nullable
private GridNode highestSimilarParent = null;
private GridNode highestSimilarAncestor = null;
private int subtreeMaxChannels;
private boolean subtreeAllowsCompressedChannels;

Expand Down Expand Up @@ -599,8 +599,8 @@ public IPathItem getControllerRoute() {
return this.connections.getFirst();
}

public @Nullable GridNode getHighestSimilarParent() {
return highestSimilarParent;
public @Nullable GridNode getHighestSimilarAncestor() {
return highestSimilarAncestor;
}

public boolean getSubtreeAllowsCompressedChannels() {
Expand All @@ -613,19 +613,19 @@ public void setControllerRoute(IPathItem fast) {

var nodeParent = (GridNode) fast.getControllerRoute();
if (nodeParent.getOwner() instanceof ControllerBlockEntity) {
this.highestSimilarParent = null;
this.highestSimilarAncestor = null;
this.subtreeMaxChannels = getMaxChannels();
this.subtreeAllowsCompressedChannels = !hasFlag(GridFlags.CANNOT_CARRY_COMPRESSED);
} else {
if (nodeParent.highestSimilarParent == null) {
if (nodeParent.highestSimilarAncestor == null) {
// Parent is connected to a controller, it is the bottleneck.
this.highestSimilarParent = nodeParent;
} else if (nodeParent.subtreeMaxChannels == nodeParent.highestSimilarParent.subtreeMaxChannels) {
this.highestSimilarAncestor = nodeParent;
} else if (nodeParent.subtreeMaxChannels == nodeParent.highestSimilarAncestor.subtreeMaxChannels) {
// Parent is not restricting the number of channels, go as high as possible.
this.highestSimilarParent = nodeParent.highestSimilarParent;
this.highestSimilarAncestor = nodeParent.highestSimilarAncestor;
} else {
// Parent is restricting the number of channels, link to it directly.
this.highestSimilarParent = nodeParent;
this.highestSimilarAncestor = nodeParent;
}
this.subtreeMaxChannels = Math.min(nodeParent.subtreeMaxChannels, getMaxChannels());
this.subtreeAllowsCompressedChannels = nodeParent.subtreeAllowsCompressedChannels
Expand Down Expand Up @@ -695,7 +695,7 @@ public void incrementChannelCount(int usedChannels) {

@Override
public void finalizeChannels() {
this.highestSimilarParent = null;
this.highestSimilarAncestor = null;

if (hasFlag(GridFlags.CANNOT_CARRY)) {
return;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/appeng/me/pathfinding/PathingCalculation.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@
/**
* Calculation to assign channels starting from the controllers. The full computation is split in two steps, each linear
* time.
*
* <p>
* First, a BFS is performed starting from the controllers. This establishes a tree that connects all path items to a
* controller. As nodes that require channels are visited, they are assigned a channel if possible. This is done by
* checking the channel count of a few key nodes (max 3) along the path.
*
* <p>
* Second, a DFS is performed to propagate the channel count upwards.
*/
Expand Down Expand Up @@ -187,14 +185,14 @@ private boolean tryUseChannel(GridNode start) {
return false;
}

pi = pi.getHighestSimilarParent();
pi = pi.getHighestSimilarAncestor();
}

// Allocate the channel along the path.
pi = start;
while (pi != null) {
channelBottlenecks.addTo(pi, 1);
pi = pi.getHighestSimilarParent();
pi = pi.getHighestSimilarAncestor();
}

channelNodes.add(start);
Expand Down

0 comments on commit 132f263

Please sign in to comment.