diff options
author | BlueWeabo <ilia.iliev2005@gmail.com> | 2023-07-30 11:11:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-30 11:11:19 +0300 |
commit | 78b436b8f4b55b8f892c43aa4d34b6856547e20a (patch) | |
tree | 20b2692114707f57e886fa00c27ded57b8fd57ea /src/main/java/gregtech | |
parent | 190d29ec4eecb6508a91288639b1b6194e077fda (diff) | |
download | GT5-Unofficial-78b436b8f4b55b8f892c43aa4d34b6856547e20a.tar.gz GT5-Unofficial-78b436b8f4b55b8f892c43aa4d34b6856547e20a.tar.bz2 GT5-Unofficial-78b436b8f4b55b8f892c43aa4d34b6856547e20a.zip |
Fix Overclock Calculator Making Too many parallels and wrong eut consumption (#2190)
* fix overclock calculator making too many parallels and wrong eut consumptions
* fix duration increase when trying to do a noOverclock calculator
* spotless
* add correct api for no overclock
* address review
Diffstat (limited to 'src/main/java/gregtech')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_OverclockCalculator.java | 92 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/GT_ParallelHelper.java | 5 |
2 files changed, 56 insertions, 41 deletions
diff --git a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java index 5b4380028f..0ca9bf3f46 100644 --- a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java +++ b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java @@ -70,7 +70,7 @@ public class GT_OverclockCalculator { /** * How much the bits should be moved to the left when it is overclocking (Going up, 2 meaning it is multiplied with - * 4x)- + * 4x) */ private int eutIncreasePerOC = 2; /** @@ -113,7 +113,10 @@ public class GT_OverclockCalculator { * A supplier, which is used for machines which have a custom way of calculating duration, like Neutron Activator */ private Supplier<Double> durationUnderOneTickSupplier; - + /** + * Should we actually try to calculate overclocking + */ + private boolean noOverclock; /** * variable to check whether the overclocks have been calculated */ @@ -135,7 +138,8 @@ public class GT_OverclockCalculator { public static GT_OverclockCalculator ofNoOverclock(long eut, int duration) { return new GT_OverclockCalculator().setRecipeEUt(eut) .setDuration(duration) - .setEUt(eut); + .setEUt(eut) + .setNoOverclock(true); } /** @@ -144,37 +148,6 @@ public class GT_OverclockCalculator { public GT_OverclockCalculator() {} /** - * Constructor for creating a new calculator with the save values - * - * @param calculator Calculator to copy over - */ - public GT_OverclockCalculator(@Nonnull GT_OverclockCalculator calculator) { - this(); - setRecipeEUt(calculator.recipeVoltage); - setRecipeAmperage(calculator.recipeAmperage); - setEUt(calculator.machineVoltage); - setAmperage(calculator.machineAmperage); - setDuration(calculator.duration); - setParallel(calculator.parallel); - setRecipeHeat(calculator.recipeHeat); - setMachineHeat(calculator.machineHeat); - setHeatPerfectOC(calculator.durationDecreasePerHeatOC); - setHeatOC(calculator.heatOC); - setHeatDiscount(calculator.heatDiscount); - setHeatDiscountMultiplier((float) calculator.heatDiscountExponent); - setEUtDiscount((float) calculator.eutDiscount); - setSpeedBoost((float) calculator.speedBoost); - setEUtIncreasePerOC(calculator.eutIncreasePerOC); - setDurationDecreasePerOC(calculator.durationDecreasePerOC); - setOneTickDiscount(calculator.oneTickDiscount); - setLaserOC(calculator.laserOC); - setLaserOCPenalty(calculator.laserOCPenalty); - setAmperageOC(calculator.amperageOC); - maxOverclocks = calculator.maxOverclocks; - limitOverclocks = calculator.limitOverclocks; - } - - /** * @param recipeEUt Sets the Recipe's starting voltage */ public GT_OverclockCalculator setRecipeEUt(long recipeEUt) { @@ -388,6 +361,14 @@ public class GT_OverclockCalculator { } /** + * Sets if we should do overclocking or not + */ + public GT_OverclockCalculator setNoOverclock(boolean noOverclock) { + this.noOverclock = noOverclock; + return this; + } + + /** * Call this when all values have been put it. */ public GT_OverclockCalculator calculate() { @@ -400,6 +381,10 @@ public class GT_OverclockCalculator { } private void calculateOverclock() { + if (noOverclock) { + calculateFinalRecipeEUt(calculateHeatDiscountMultiplier()); + return; + } if (laserOC && amperageOC) { throw new IllegalStateException("Tried to calculate overclock with both laser and amperage overclocking"); } @@ -533,6 +518,7 @@ public class GT_OverclockCalculator { */ public double calculateDurationUnderOneTick() { if (durationUnderOneTickSupplier != null) return durationUnderOneTickSupplier.get(); + if (noOverclock) return duration; int normalOverclocks = calculateAmountOfOverclocks( calculateMachinePowerTier(), calculateRecipePowerTier(calculateHeatDiscountMultiplier())); @@ -549,13 +535,41 @@ public class GT_OverclockCalculator { * @param originalMaxParallel Parallels which are of the actual machine before the overclocking extra ones */ public long calculateEUtConsumptionUnderOneTick(int originalMaxParallel, int currentParallel) { - double parallelOverclocks = Math.log((double) currentParallel / originalMaxParallel) - / Math.log(1 << durationDecreasePerOC); - return (long) Math.floor( - recipeVoltage * Math.pow(1 << eutIncreasePerOC, parallelOverclocks) + if (noOverclock) return recipeVoltage; + double heatDiscountMultiplier = calculateHeatDiscountMultiplier(); + // So what we need to do here is as follows: + // - First we need to figure out what out parallel multiplier for getting to that OC was + // - Second we need to find how many of those were from heat overclocks + // - Third we need to find how many were from normal overclocking. + // = For that we need to find how much better heat overclocks are compared to normal ones + // = Then remove that many from our normal overclocks + // - Fourth we find how many total overclocks we have + // - Fifth we find how many of those are needed to one tick + // - Finally we calculate the formula + // = The energy increase from our overclocks for parallel + // = The energy increase from our overclock to reach maximum under one tick potential + // =- NOTE: This will always cause machine to use full power no matter what. Otherwise it creates many + // anomalies. + // = Everything else for recipe voltage is also calculated here. + + double parallelMultiplierFromOverclocks = (double) currentParallel / originalMaxParallel; + double amountOfParallelHeatOverclocks = Math.min( + Math.log(parallelMultiplierFromOverclocks) / Math.log(1 << durationDecreasePerHeatOC), + calculateAmountOfHeatOverclocks()); + double amountOfParallelOverclocks = Math.log(parallelMultiplierFromOverclocks) + / Math.log(1 << durationDecreasePerOC) + - amountOfParallelHeatOverclocks * (1 << durationDecreasePerHeatOC - durationDecreasePerOC); + double machineTier = calculateMachinePowerTier(); + double recipeTier = calculateRecipePowerTier(heatDiscountMultiplier); + double amountOfTotalOverclocks = calculateAmountOfOverclocks(machineTier, recipeTier); + return (long) Math.ceil( + recipeVoltage * Math.pow(1 << eutIncreasePerOC, amountOfParallelOverclocks + amountOfParallelHeatOverclocks) + * Math.pow( + 1 << eutIncreasePerOC, + amountOfTotalOverclocks - (amountOfParallelOverclocks + amountOfParallelHeatOverclocks)) * originalMaxParallel * eutDiscount * recipeAmperage - * calculateHeatDiscountMultiplier()); + * heatDiscountMultiplier); } } diff --git a/src/main/java/gregtech/api/util/GT_ParallelHelper.java b/src/main/java/gregtech/api/util/GT_ParallelHelper.java index 6d28dab036..7849efd277 100644 --- a/src/main/java/gregtech/api/util/GT_ParallelHelper.java +++ b/src/main/java/gregtech/api/util/GT_ParallelHelper.java @@ -404,9 +404,10 @@ public class GT_ParallelHelper { // Save the original max parallel before calculating our overclocking under 1 tick int originalMaxParallel = maxParallel; - double tickTimeAfterOC = calculator.calculateDurationUnderOneTick(); + double tickTimeAfterOC = calculator.setParallel(originalMaxParallel) + .calculateDurationUnderOneTick(); if (tickTimeAfterOC < 1) { - maxParallel = (int) Math.floor(maxParallel / tickTimeAfterOC); + maxParallel = (int) (maxParallel / tickTimeAfterOC); } int maxParallelBeforeBatchMode = maxParallel; |