Skip to content

Commit

Permalink
Cleanup and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Dec 17, 2024
1 parent 3b8663e commit 5943112
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 245 deletions.
8 changes: 0 additions & 8 deletions src/main/java/appeng/core/AEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ public void setChannelModel(ChannelMode mode) {
}
}

public int getPathfindingStepsPerTick() {
return common.pathfindingStepsPerTick.get();
}

/**
* @return True if an in-world preview of parts and facade placement should be shown when holding one in hand.
*/
Expand Down Expand Up @@ -531,7 +527,6 @@ private static class CommonConfig {
public final BooleanValue matterCannonBlockDamage;
public final BooleanValue tinyTntBlockDamage;
public final EnumValue<ChannelMode> channels;
public final IntValue pathfindingStepsPerTick;
public final BooleanValue spatialAnchorEnableRandomTicks;

public final IntValue growthAcceleratorSpeed;
Expand Down Expand Up @@ -601,9 +596,6 @@ public CommonConfig() {
"Enables the ability of Tiny TNT to break blocks.");
channels = defineEnum(builder, "channels", ChannelMode.DEFAULT,
"Changes the channel capacity that cables provide in AE2.");
pathfindingStepsPerTick = define(builder, "pathfindingStepsPerTick", 4,
1, 1024,
"The number of pathfinding steps that are taken per tick and per grid that is booting. Lower numbers will mean booting takes longer, but less work is done per tick.");
spatialAnchorEnableRandomTicks = define(builder, "spatialAnchorEnableRandomTicks", true,
"Whether Spatial Anchors should force random chunk ticks and entity spawning.");
builder.pop();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/debug/DebugCardItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
partHost.markForUpdate();
if (center != null) {
final GridNode n = (GridNode) center.getGridNode();
this.outputSecondaryMessage(player, "Node Channels", Integer.toString(n.usedChannels()));
this.outputSecondaryMessage(player, "Node Channels", Integer.toString(n.getUsedChannels()));
for (var entry : n.getInWorldConnections().entrySet()) {
this.outputSecondaryMessage(player, "Channels " + entry.getKey().getName(),
Integer.toString(entry.getValue().getUsedChannels()));
Expand Down
52 changes: 22 additions & 30 deletions src/main/java/appeng/me/GridConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@

public class GridConnection implements IGridConnection, IPathItem {

private int usedChannels = 0;
/**
* Will be modified during pathing and should not be exposed outside of that purpose.
*/
int usedChannels = 0;
/**
* Finalized version of {@link #usedChannels} once pathing is done.
*/
private int lastUsedChannels = 0;
private Object visitorIterationNumber = null;
/**
Expand Down Expand Up @@ -109,7 +115,12 @@ public boolean isInWorld() {

@Override
public int getUsedChannels() {
return usedChannels;
return lastUsedChannels;
}

@Override
public void setAdHocChannels(int channels) {
this.usedChannels = channels;
}

@Override
Expand All @@ -118,8 +129,8 @@ public GridNode getControllerRoute() {
}

@Override
public void setControllerRoute(@Nullable IPathItem fast) {
this.lastUsedChannels = 0;
public void setControllerRoute(IPathItem fast) {
this.usedChannels = 0;

// If the shortest route to the controller is via side B, we need to flip the
// connections sides because side A should be the closest route to the controller.
Expand All @@ -133,11 +144,6 @@ public void setControllerRoute(@Nullable IPathItem fast) {
}
}

@Override
public boolean canSupportMoreChannels() {
return this.getLastUsedChannels() < getMaxChannels();
}

@Override
public int getMaxChannels() {
var mode = sideB.getGrid().getPathingService().getChannelMode();
Expand All @@ -147,39 +153,29 @@ public int getMaxChannels() {
return 32 * mode.getCableCapacityFactor();
}

@Override
public int getUsedChannelCount() {
return getLastUsedChannels();
}

@Override
public Iterable<IPathItem> getPossibleOptions() {
return ImmutableList.of((IPathItem) this.a(), (IPathItem) this.b());
}

@Override
public void incrementChannelCount(int usedChannels) {
this.lastUsedChannels += usedChannels;
return ImmutableList.of(this.a(), this.b());
}

@Override
public boolean hasFlag(GridFlags flag) {
return false;
}

@Override
public void aggregateChildChannels() {
public int propagateChannelsUpwards() {
if (this.sideB.getControllerRoute() == this) { // Check that we are in B's route
this.lastUsedChannels = this.sideB.getUsedChannels();
this.usedChannels = this.sideB.usedChannels;
} else {
this.lastUsedChannels = 0;
this.usedChannels = 0;
}
return this.usedChannels;
}

@Override
public void finalizeChannels() {
if (this.getUsedChannels() != this.getLastUsedChannels()) {
this.usedChannels = this.lastUsedChannels;
if (this.lastUsedChannels != this.usedChannels) {
this.lastUsedChannels = this.usedChannels;

if (this.sideA.getInternalGrid() != null) {
this.sideA.notifyStatusChange(IGridNodeListener.State.CHANNEL);
Expand All @@ -191,10 +187,6 @@ public void finalizeChannels() {
}
}

private int getLastUsedChannels() {
return this.lastUsedChannels;
}

Object getVisitorIterationNumber() {
return this.visitorIterationNumber;
}
Expand Down
Loading

0 comments on commit 5943112

Please sign in to comment.