Skip to content

Commit

Permalink
Level Maintainer: don't queue jobs when all CPUs are busy. (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffle authored Mar 27, 2024
1 parent f175d70 commit f7d25c6
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
Expand Down Expand Up @@ -141,6 +142,17 @@ private TickRateModulation doWork() {
final IGrid grid = getProxy().getGrid();
final IItemList<IAEItemStack> inv = getProxy().getStorage().getItemInventory().getStorageList();

// Check there are available crafting CPUs before doing any work.
// This hopefully stops level maintainers busy-looping calculating
// crafting tasks that cannot be successfully submitted.
boolean allBusy = true;
for (final ICraftingCPU cpu : craftingGrid.getCpus()) {
if (!cpu.isBusy()) {
allBusy = false;
break;
}
}

// Find a request that we can submit to the network.
// If there is none, find the next request we can begin calculating.
ICraftingJob jobToSubmit = null;
Expand All @@ -163,9 +175,10 @@ private TickRateModulation doWork() {
boolean shouldCraft = isCraftable && aeItem.getStackSize() < quantity;
if (isDone) requests.updateState(i, State.Idle);
if (!isCraftable) requests.updateState(i, State.Error);
if (craftingGrid.canEmitFor(craftItem) || craftingGrid.isRequesting(craftItem)
|| !isDone
|| !shouldCraft)
if (allBusy || !isDone
|| !shouldCraft
|| craftingGrid.canEmitFor(craftItem)
|| craftingGrid.isRequesting(craftItem))
continue;
// do crafting
Future<ICraftingJob> jobTask = requests.getJob(i);
Expand Down

0 comments on commit f7d25c6

Please sign in to comment.