Skip to content

Commit

Permalink
Show used channels and their passive drain in the network status (#5837)
Browse files Browse the repository at this point in the history
Fixes #99.
Fixes #115.
  • Loading branch information
Technici4n committed Dec 20, 2021
1 parent d8f83e6 commit 5db872a
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/main/java/appeng/api/networking/energy/IEnergyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@
public interface IEnergyService extends IGridService, IEnergySource {

/**
* @return the current calculated idle energy drain each tick, is used internally to drain power for each tick.
* Return the current calculated idle energy drain each tick, is used internally to drain power for each tick. It's
* the sum of the {@linkplain #getChannelPowerUsage() idle channel power usage} and the idle usages of the machines
* in the network.
*/
@Nonnegative
double getIdlePowerUsage();

/**
* @return the current idle power usage of channels
*/
@Nonnegative
double getChannelPowerUsage();

/**
* @return the average power drain over the past 10 ticks, includes idle usage during this time, and all use of
* extractPower.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public interface IPathingService extends IGridService {
* @return The current mode used for channel calculations.
*/
ChannelMode getChannelMode();

/**
* @return The total number of channels currently used by this network.
*/
int getUsedChannels();
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ public NetworkStatusScreen(NetworkStatusMenu menu, Inventory playerInventory,
protected void updateBeforeRender() {
super.updateBeforeRender();

setTextContent("dialog_title", GuiText.NetworkDetails.text(status.getChannelsUsed()));
setTextContent("stored_power", GuiText.StoredPower.text(Platform.formatPower(status.getStoredPower(), false)));
setTextContent("max_power", GuiText.MaxPower.text(Platform.formatPower(status.getMaxStoredPower(), false)));
setTextContent("power_input_rate",
GuiText.PowerInputRate.text(Platform.formatPower(status.getAveragePowerInjection(), true)));
setTextContent("power_usage_rate",
GuiText.PowerUsageRate.text(Platform.formatPower(status.getAveragePowerUsage(), true)));
setTextContent("channel_power_rate",
GuiText.ChannelEnergyDrain.text(Platform.formatPower(status.getChannelPower(), true)));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/core/localization/GuiText.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum GuiText {

IOPort, BytesUsed, Types, QuantumLinkChamber, PortableCell,

NetworkTool, PowerUsageRate, PowerInputRate, Installed, EnergyDrain,
NetworkTool, PowerUsageRate, PowerInputRate, Installed, EnergyDrain, ChannelEnergyDrain,

StorageBus, StorageBusFluids, Priority, Security, Encoded, Blank, Unlinked, Linked,

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/appeng/me/service/EnergyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ public double getIdlePowerUsage() {
return this.drainPerTick + this.pgc.getChannelPowerUsage();
}

@Override
public double getChannelPowerUsage() {
return this.pgc.getChannelPowerUsage();
}

private void publicPowerState(final boolean newState, final IGrid grid) {
if (this.publicHasPower == newState) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/appeng/me/service/PathingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ public void setForcedChannelMode(@Nullable ChannelMode forcedChannelMode) {
}
}

@Override
public int getUsedChannels() {
return channelsInUse;
}

@Override
public void onSplit(IGridStorage destinationStorage) {
populateGridStorage(destinationStorage);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/appeng/menu/me/networktool/NetworkStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class NetworkStatus {
private double averagePowerUsage;
private double storedPower;
private double maxStoredPower;
private double channelPower;
private int channelsUsed;

private List<MachineGroup> groupedMachines = Collections.emptyList();

Expand All @@ -56,6 +58,8 @@ public static NetworkStatus fromGrid(IGrid grid) {
status.averagePowerUsage = eg.getAvgPowerUsage();
status.storedPower = eg.getStoredPower();
status.maxStoredPower = eg.getMaxStoredPower();
status.channelPower = eg.getChannelPowerUsage();
status.channelsUsed = grid.getPathingService().getUsedChannels();

// This is essentially a groupBy machineRepresentation + count, sum(idlePowerUsage)
Map<AEItemKey, MachineGroup> groupedMachines = new HashMap<>();
Expand Down Expand Up @@ -94,6 +98,14 @@ public double getMaxStoredPower() {
return maxStoredPower;
}

public double getChannelPower() {
return channelPower;
}

public int getChannelsUsed() {
return channelsUsed;
}

/**
* @return Machines grouped by their UI representation.
*/
Expand All @@ -110,6 +122,8 @@ public static NetworkStatus read(FriendlyByteBuf data) {
status.averagePowerUsage = data.readDouble();
status.storedPower = data.readDouble();
status.maxStoredPower = data.readDouble();
status.channelPower = data.readDouble();
status.channelsUsed = data.readVarInt();

int count = data.readVarInt();
ImmutableList.Builder<MachineGroup> machines = ImmutableList.builder();
Expand All @@ -129,6 +143,8 @@ public void write(FriendlyByteBuf data) {
data.writeDouble(averagePowerUsage);
data.writeDouble(storedPower);
data.writeDouble(maxStoredPower);
data.writeDouble(channelPower);
data.writeVarInt(channelsUsed);
data.writeVarInt(groupedMachines.size());
for (MachineGroup machine : groupedMachines) {
machine.write(data);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/ae2/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"gui.ae2.CalculatingWait": "Calculating Please Wait...",
"gui.ae2.Cancel": "Cancel",
"gui.ae2.CellWorkbench": "Cell Workbench",
"gui.ae2.ChannelEnergyDrain": "Channel Passive Drain: %s",
"gui.ae2.ChargedQuartz": "Charged Certus Quartz is crafted by inserting an uncharged Certus Quartz Crystal into the Charger, and powering it.",
"gui.ae2.Chest": "ME Chest",
"gui.ae2.Clean": "Clean",
Expand Down Expand Up @@ -230,7 +231,7 @@
"gui.ae2.Missing": "Missing: %s",
"gui.ae2.MolecularAssembler": "Molecular Assembler",
"gui.ae2.MultipleOutputs": "%1$d%% second, %2$d%% third output.",
"gui.ae2.NetworkDetails": "Network Details",
"gui.ae2.NetworkDetails": "Network Details (%d Channels)",
"gui.ae2.NetworkTool": "Network Tool",
"gui.ae2.Next": "Next",
"gui.ae2.No": "No",
Expand Down
15 changes: 9 additions & 6 deletions src/main/resources/assets/ae2/screens/network_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
"includes": ["common/common.json"],
"background": {
"texture": "guis/networkstatus.png",
"srcRect": [0, 0, 195, 147]
"srcRect": [0, 0, 195, 157]
},
"text": {
"dialog_title": {
"text": {
"translate": "gui.ae2.NetworkDetails"
},
"position": {
"left": 8,
"top": 6
Expand All @@ -27,17 +24,23 @@
"top": 26
}
},
"power_usage_rate": {
"channel_power_rate": {
"position": {
"left": 13,
"top": 123
}
},
"power_input_rate": {
"power_usage_rate": {
"position": {
"left": 13,
"top": 133
}
},
"power_input_rate": {
"position": {
"left": 13,
"top": 143
}
}
},
"widgets": {
Expand Down
Binary file modified src/main/resources/assets/ae2/textures/guis/networkstatus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5db872a

Please sign in to comment.