From 9ecccffd9436d9684311820b184e35d5328415da Mon Sep 17 00:00:00 2001 From: Technus Date: Mon, 24 Oct 2016 18:11:15 +0200 Subject: [PATCH] Optimized overclockedness --- .../GT_MetaTileEntity_BasicMachine.java | 16 +++++++------ .../GT_MetaTileEntity_MultiBlockBase.java | 16 +++++++------ .../basic/GT_MetaTileEntity_Disassembler.java | 24 ++++++++++++------- .../GT_MetaTileEntity_Massfabricator.java | 18 +++++++------- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 60cb3c45..c68ea4a6 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -533,13 +533,13 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B protected void calculateOverclockedNess(int aEUt, int aDuration) { if(mTier==0){ //Long time calculation - long xMaxProgresstime = (long)aDuration*2L; + long xMaxProgresstime = ((long)aDuration)<<1; if(xMaxProgresstime>Integer.MAX_VALUE-1){ //make impossible if too long mEUt=Integer.MAX_VALUE-1; mMaxProgresstime=Integer.MAX_VALUE-1; }else{ - mEUt=aEUt/4; + mEUt=aEUt>>2; mMaxProgresstime=(int)xMaxProgresstime; } }else{ @@ -551,18 +551,20 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B mMaxProgresstime = aDuration; while (tempEUt <= V[mTier -1] * (long)mAmperage) { - tempEUt *= 4;//this actually controls overclocking + tempEUt<<=2;//this actually controls overclocking //xEUt *= 4;//this is effect of everclocking - mMaxProgresstime /= 2;//this is effect of overclocking - xEUt = mMaxProgresstime==0 ? (long)(xEUt/1.1D) : xEUt*4;//U know, if the time is less than 1 tick make the machine use 2x less power + mMaxProgresstime>>=1;//this is effect of overclocking + xEUt = mMaxProgresstime==0 ? xEUt>>1 : xEUt<<2;//U know, if the time is less than 1 tick make the machine use 2x less power } if(xEUt>Integer.MAX_VALUE-1){ mEUt = Integer.MAX_VALUE-1; mMaxProgresstime = Integer.MAX_VALUE-1; }else{ mEUt = (int)xEUt; - mEUt = mEUt == 0 ? 1 : mEUt; - mMaxProgresstime = mMaxProgresstime<1 ? 1 : mMaxProgresstime;//set time to 1 tick + if(mEUt==0) + mEUt = 1; + if(mMaxProgresstime==0) + mMaxProgresstime = 1;//set time to 1 tick } } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 5b8a8232..97cbe952 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -524,13 +524,13 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { byte mTier=(byte)Math.max(0,GT_Utility.getTier(maxInputVoltage)); if(mTier==0){ //Long time calculation - long xMaxProgresstime = (long)aDuration*2L; + long xMaxProgresstime = ((long)aDuration)<<1; if(xMaxProgresstime>Integer.MAX_VALUE-1){ //make impossible if too long mEUt=Integer.MAX_VALUE-1; mMaxProgresstime=Integer.MAX_VALUE-1; }else{ - mEUt=aEUt/4; + mEUt=aEUt>>2; mMaxProgresstime=(int)xMaxProgresstime; } }else{ @@ -542,18 +542,20 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { mMaxProgresstime = aDuration; while (tempEUt <= V[mTier -1] * mAmperage) { - tempEUt *= 4;//this actually controls overclocking + tempEUt<<=2;//this actually controls overclocking //xEUt *= 4;//this is effect of everclocking - mMaxProgresstime /= 2;//this is effect of overclocking - xEUt = mMaxProgresstime==0 ? (long)(xEUt/1.1D) : xEUt*4;//U know, if the time is less than 1 tick make the machine use less power + mMaxProgresstime>>=1;//this is effect of overclocking + xEUt = mMaxProgresstime==0 ? xEUt>>1 : xEUt<<2;//U know, if the time is less than 1 tick make the machine use less power } if(xEUt>Integer.MAX_VALUE-1){ mEUt = Integer.MAX_VALUE-1; mMaxProgresstime = Integer.MAX_VALUE-1; }else{ mEUt = (int)xEUt; - mEUt = mEUt == 0 ? 1 : mEUt; - mMaxProgresstime = mMaxProgresstime<1 ? 1 : mMaxProgresstime;//set time to 1 tick + if(mEUt==0) + mEUt = 1; + if(mMaxProgresstime==0) + mMaxProgresstime = 1;//set time to 1 tick } } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java index 2ddd24b1..2f59b568 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java @@ -41,25 +41,30 @@ public class GT_MetaTileEntity_Disassembler if (getBaseMetaTileEntity().getRandomNumber(100) < 50 + 10 * this.mTier) { this.mOutputItems[i] = GT_Utility.loadItem(tNBT, "Ingredient." + i); if (this.mOutputItems[i] != null) { - this.mMaxProgresstime *= (mTier>5 ? 1.7F-(mTier/10.0F) : 1.7F); + this.mMaxProgresstime *= 1.7F; isAnyOutput=true; } } } - if(!isAnyOutput){ - return 0; + if(!isAnyOutput) + return DID_NOT_FIND_RECIPE; + for(int i=mTier-5;i>0;i--){ + this.mMaxProgresstime>>=1; + if(this.mMaxProgresstime==0) + this.mEUt = this.mEUt>>1; } + this.mMaxProgresstime = this.mMaxProgresstime==0 ? 1 : this.mMaxProgresstime; getInputAt(0).stackSize -= 1; - return 2; + return FOUND_AND_SUCCESSFULLY_USED_RECIPE; } } } - return 0; + return DID_NOT_FIND_RECIPE; } private void calculateOverclockedNessDisassembler(int aEUt) { if(mTier==0){ - mEUt=aEUt/4; + mEUt=aEUt>>2; }else{ //Long EUt calculation long xEUt=aEUt; @@ -67,14 +72,15 @@ public class GT_MetaTileEntity_Disassembler long tempEUt = xEUtInteger.MAX_VALUE-1){ mEUt = Integer.MAX_VALUE-1; }else{ mEUt = (int)xEUt; - mEUt = mEUt == 0 ? 1 : mEUt; + if(mEUt==0) + mEUt = 1; } } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java index 5035cfa8..25ce3060 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java @@ -70,17 +70,16 @@ public class GT_MetaTileEntity_Massfabricator private void calculateOverclockedNessMassFabricator() { if(mTier==0){ //Long time calculation - long xMaxProgresstime = (long)sDurationMultiplier*2L; + long xMaxProgresstime = ((long)sDurationMultiplier)<<1; if(xMaxProgresstime>Integer.MAX_VALUE-1){ //make impossible if too long mEUt=Integer.MAX_VALUE-1; mMaxProgresstime=Integer.MAX_VALUE-1; }else{ - mEUt= (int)(GT_Values.V[1] * 4); + mEUt= (int)(GT_Values.V[1]<<2);//2^2=4 so shift <<2 mMaxProgresstime=(int)xMaxProgresstime; } }else{ - //TODO: CHECK IF THAT WORKS //Long EUt calculation long xEUt=GT_Values.V[1] * (long)Math.pow(2,mTier+2); @@ -89,17 +88,20 @@ public class GT_MetaTileEntity_Massfabricator mMaxProgresstime = sDurationMultiplier; while (tempEUt <= V[mTier -1]) { - tempEUt *= 4;//this actually controls overclocking - mMaxProgresstime /= 2;//this is effect of overclocking - xEUt = mMaxProgresstime==0 ? (long)(xEUt/1.1D) : xEUt;//U know, if the time is less than 1 tick make the machine use less power + tempEUt<<=2;//this actually controls overclocking + mMaxProgresstime>>=1;//this is effect of overclocking + if(mMaxProgresstime==0) + xEUt = (long)(xEUt/1.1D);//U know, if the time is less than 1 tick make the machine use less power } if(xEUt>Integer.MAX_VALUE-1){ mEUt = Integer.MAX_VALUE-1; mMaxProgresstime = Integer.MAX_VALUE-1; }else{ mEUt = (int)xEUt; - mEUt = mEUt == 0 ? 1 : mEUt; - mMaxProgresstime = mMaxProgresstime<1 ? 1 : mMaxProgresstime;//set time to 1 tick + if(mEUt==0) + mEUt = 1; + if(mMaxProgresstime==0) + mMaxProgresstime = 1;//set time to 1 tick } } }