Skip to content

Commit

Permalink
- Fix InfItemFluidHandler use a lot of memory.
Browse files Browse the repository at this point in the history
- Fix MEPatternProvider throwing NPE.
- TimeRecorder improvements.
- RecipeCraftingContext internal changes.
  • Loading branch information
KasumiNova committed Oct 14, 2024
1 parent 672b518 commit be2bd18
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {

// Project properties
group = "hellfirepvp.modularmachinery"
version = "2.1.0"
version = "2.1.1"

// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,13 @@ protected void refreshPattern(final int slot) {
details.set(slot, detail);
}

if (workMode == WorkModeSetting.ENHANCED_BLOCKING_MODE && slot == currentPatternIdx && !currentPattern.equals(detail)) {
resetCurrentPattern();
if (workMode == WorkModeSetting.ENHANCED_BLOCKING_MODE && slot == currentPatternIdx) {
// If it is reading NBT.
if (currentPattern == null) {
currentPattern = detail;
} else if (!currentPattern.equals(detail)) {
resetCurrentPattern();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ public synchronized int fill(final FluidStack resource, final boolean doFill) {

for (int i = 0; i < fluidStackList.size(); i++) {
final FluidStack stackInSlot = fluidStackList.get(i);
if (stackInSlot != null && stackInSlot.isFluidEqual(resource)) {
if (stackInSlot == null) {
fluidStackList.set(i, resource.copy());
if (onFluidChanged != null) {
onFluidChanged.accept(i);
}
toFill = 0;
break;
}
if (stackInSlot.isFluidEqual(resource)) {
int maxCanFill = Math.min(toFill, Integer.MAX_VALUE - stackInSlot.amount);
stackInSlot.amount += maxCanFill;
if (onFluidChanged != null) {
Expand Down Expand Up @@ -504,7 +512,16 @@ public int receiveGas(@Nullable final EnumFacing ignored, final GasStack toRecei
int toReceiveAmount = toReceive.amount;
for (int i = 0; i < gasStackList.size(); i++) {
final GasStack stackInSlot = gasStackList.get(i);
if (stackInSlot == null || !stackInSlot.isGasEqual(toReceive)) {
if (stackInSlot == null) {
gasStackList.set(i, toReceive.copy());
if (onGasChanged != null) {
onGasChanged.accept(i);
}
toReceiveAmount = 0;
break;
}

if (!stackInSlot.isGasEqual(toReceive)) {
continue;
}

Expand Down
34 changes: 15 additions & 19 deletions src/main/java/github/kasuminova/mmce/common/util/TimeRecorder.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package github.kasuminova.mmce.common.util;

import github.kasuminova.mmce.common.util.concurrent.ActionExecutor;

import java.util.ArrayDeque;
import java.util.Deque;
import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue;

public class TimeRecorder {
private final Deque<Integer> usedTimeList = new ArrayDeque<>(100 + 2);
private final Deque<Integer> searchUsedTimeList = new ArrayDeque<>(20 + 2);
private final IntArrayFIFOQueue usedTimeList = new IntArrayFIFOQueue();
private final IntArrayFIFOQueue searchUsedTimeList = new IntArrayFIFOQueue();
private int usedTimeCache = 0;
private int searchUsedTimeCache = 0;

Expand All @@ -17,39 +15,36 @@ public void updateUsedTime(ActionExecutor executor) {

public void incrementUsedTime(int add) {
usedTimeCache += add;
Integer first = usedTimeList.getFirst();
if (first != null) {
usedTimeList.removeFirst();
usedTimeList.addFirst(first + add);

if (!usedTimeList.isEmpty()) {
usedTimeList.enqueueFirst(usedTimeList.dequeueInt() + add);
} else {
usedTimeList.addFirst(add);
usedTimeList.enqueueFirst(add);
}
}

public void addUsedTime(int time) {
usedTimeCache += time;
usedTimeList.addFirst(time);
usedTimeList.enqueueFirst(time);
if (usedTimeList.size() > 100) {
usedTimeCache -= usedTimeList.pollLast();
usedTimeCache -= usedTimeList.dequeueLastInt();
}
}

public void addRecipeResearchUsedTime(int time) {
searchUsedTimeCache += time;
searchUsedTimeList.addFirst(time);
searchUsedTimeList.enqueueFirst(time);
if (searchUsedTimeList.size() > 20) {
searchUsedTimeCache -= searchUsedTimeList.pollLast();
searchUsedTimeCache -= searchUsedTimeList.dequeueLastInt();
}
}

public void incrementRecipeResearchUsedTime(int add) {
searchUsedTimeCache += add;
Integer first = searchUsedTimeList.getFirst();
if (first != null) {
searchUsedTimeList.removeFirst();
searchUsedTimeList.addFirst(first + add);
if (!searchUsedTimeList.isEmpty()) {
searchUsedTimeList.enqueueFirst(searchUsedTimeList.dequeueInt() + add);
} else {
searchUsedTimeList.addFirst(add);
searchUsedTimeList.enqueueFirst(add);
}
}

Expand All @@ -66,4 +61,5 @@ public int recipeSearchUsedTimeAvg() {
}
return searchUsedTimeCache / searchUsedTimeList.size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ public RecipeCraftingContext init(final ActiveMachineRecipe activeRecipe,
final TileMultiblockMachineController ctrl)
{
this.controller = ctrl;
this.activeRecipe = activeRecipe;
if (this.activeRecipe == null || this.activeRecipe.getRecipe() != activeRecipe.getRecipe()) {
this.activeRecipe = activeRecipe;
this.requirements.clear();
for (ComponentRequirement<?, ?> requirement : getParentRecipe().getCraftingRequirements()) {
this.requirements.add(this.requirements.size(), requirement.deepCopy().postDeepCopy(requirement));
}
} else {
this.activeRecipe = activeRecipe;
}
this.commandSender = new ControllerCommandSender(this.controller);

reset();
Expand Down

0 comments on commit be2bd18

Please sign in to comment.