diff options
author | HoleFish <48403212+HoleFish@users.noreply.github.com> | 2023-11-12 11:03:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-12 12:03:17 +0900 |
commit | c7c4ca2a716df221351998c275599707972df229 (patch) | |
tree | f633eaff69c7df3ba2da3f423451580c6d5d1e6a /src/main/java/gregtech/api/util/GT_ParallelHelper.java | |
parent | 581d16e61ddd8ed195fa5e6618fe0cea6fdde167 (diff) | |
download | GT5-Unofficial-c7c4ca2a716df221351998c275599707972df229.tar.gz GT5-Unofficial-c7c4ca2a716df221351998c275599707972df229.tar.bz2 GT5-Unofficial-c7c4ca2a716df221351998c275599707972df229.zip |
fix lag caused by too much parallel (#2358)
* Update GT_Recipe.java
add a method to calculate max parallel by inputs
* remove incredible loop in parallel calculation
* Update GT_Recipe.java
overwrite maxParallelCalculatedByInput
split isRecipeInputEqual into maxParallelCalculatedByInput and consumeInput
* Fix
* spotless and fix
* spotless
* optimize
* batch mode optimize
* Update notes
Diffstat (limited to 'src/main/java/gregtech/api/util/GT_ParallelHelper.java')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_ParallelHelper.java | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/main/java/gregtech/api/util/GT_ParallelHelper.java b/src/main/java/gregtech/api/util/GT_ParallelHelper.java index 8430f28fa0..e848d87092 100644 --- a/src/main/java/gregtech/api/util/GT_ParallelHelper.java +++ b/src/main/java/gregtech/api/util/GT_ParallelHelper.java @@ -456,26 +456,23 @@ public class GT_ParallelHelper { maxParallelBeforeBatchMode = Math.min(maxParallel, maxParallelBeforeBatchMode); - // Consume inputs to determine normal parallel + // determine normal parallel + int actualMaxParallel = (int) Math.min(maxParallelBeforeBatchMode, availableEUt / tRecipeEUt); if (recipeCheck != null) { - int actualMaxParallel = (int) Math.min(maxParallelBeforeBatchMode, availableEUt / tRecipeEUt); currentParallel = recipeCheck.checkRecipeInputs(true, actualMaxParallel, itemInputs, fluidInputs); } else { - long tCurrentUsage = 0; - boolean builtRecipeCheck = false; - for (; currentParallel < maxParallelBeforeBatchMode - && tCurrentUsage < (availableEUt - tRecipeEUt); currentParallel++) { - if (!tryConsumeRecipeInputs(recipe, fluidInputs, itemInputs)) { - break; - } - tCurrentUsage += tRecipeEUt; - if (tSingleRecipeCheckBuilder != null && !builtRecipeCheck) { + currentParallel = (int) recipe.maxParallelCalculatedByInputs(actualMaxParallel, fluidInputs, itemInputs); + if (currentParallel > 0) { + if (tSingleRecipeCheckBuilder != null) { // If recipe checker is not built yet, build and set it + recipe.consumeInput(1, fluidInputs, itemInputs); SingleRecipeCheck builtCheck = tSingleRecipeCheckBuilder.setAfter(itemInputs, fluidInputs) .setRecipe(recipe) .build(); singleRecipeMachine.setSingleRecipeCheck(builtCheck); - builtRecipeCheck = true; + recipe.consumeInput(currentParallel - 1, fluidInputs, itemInputs); + } else { + recipe.consumeInput(currentParallel, fluidInputs, itemInputs); } } } @@ -502,10 +499,9 @@ public class GT_ParallelHelper { if (recipeCheck != null) { tExtraParallels = recipeCheck.checkRecipeInputs(true, maxExtraParallels, itemInputs, fluidInputs); } else { - while (tExtraParallels < maxExtraParallels - && tryConsumeRecipeInputs(recipe, fluidInputs, itemInputs, currentParallel)) { - tExtraParallels += currentParallel; - } + tExtraParallels = (int) recipe + .maxParallelCalculatedByInputs(maxExtraParallels, fluidInputs, itemInputs); + recipe.consumeInput(tExtraParallels, fluidInputs, itemInputs); } durationMultiplier = 1.0f + (float) tExtraParallels / currentParallel; currentParallel += tExtraParallels; |