aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMartin Robertz <dream-master@gmx.net>2018-06-19 15:08:40 +0200
committerGitHub <noreply@github.com>2018-06-19 15:08:40 +0200
commit6c439032a6ec092c812599ec5efa3658ea5ff189 (patch)
treea6c6f792b552191b5b2e1b11b75372629dc9c176 /src/main
parent50a323b8bfc64c82fd2660f1992d836842a13c6d (diff)
parentd9463c99d2b710a5169fa69e70f180b3520adfee (diff)
downloadGT5-Unofficial-6c439032a6ec092c812599ec5efa3658ea5ff189.tar.gz
GT5-Unofficial-6c439032a6ec092c812599ec5efa3658ea5ff189.tar.bz2
GT5-Unofficial-6c439032a6ec092c812599ec5efa3658ea5ff189.zip
Merge pull request #130 from GTNewHorizons/debug/speedylag
Attempt to fix for #3030. Checking in on branch and doing PR so it c…
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/gregtech/GT_Mod.java1
-rw-r--r--src/main/java/gregtech/api/enums/GT_Values.java4
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java10
-rw-r--r--src/main/java/gregtech/api/metatileentity/MetaTileEntity.java3
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java10
5 files changed, 25 insertions, 3 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java
index 95273f6d7e..07d8694f96 100644
--- a/src/main/java/gregtech/GT_Mod.java
+++ b/src/main/java/gregtech/GT_Mod.java
@@ -202,6 +202,7 @@ public class GT_Mod implements IGT_Mod {
GT_Values.oreveinAttempts = tMainConfig.get(aTextGeneral, "oreveinAttempts_64",64).getInt(64);
GT_Values.oreveinMaxPlacementAttempts = tMainConfig.get(aTextGeneral, "oreveinMaxPlacementAttempts_8",8).getInt(8);
//GT_Values.oreveinMaxSize = tMainConfig.get(aTextGeneral, "oreveinMaxSize_64",64).getInt(64);
+ GT_Values.ticksBetweenSounds = tMainConfig.get("machines", "TicksBetweenSounds", 30).getInt(30);
GregTech_API.TICKS_FOR_LAG_AVERAGING = tMainConfig.get(aTextGeneral, "TicksForLagAveragingWithScanner", 25).getInt(25);
GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING = tMainConfig.get(aTextGeneral, "MillisecondsPassedInGTTileEntityUntilLagWarning", 100).getInt(100);
diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java
index 94d268fd58..3ba0dc407a 100644
--- a/src/main/java/gregtech/api/enums/GT_Values.java
+++ b/src/main/java/gregtech/api/enums/GT_Values.java
@@ -159,6 +159,10 @@ public class GT_Values {
*/
public static boolean debugStones = false;
/**
+ * Number of ticks between sending sound packets to clients for electric machines. Default is 1.5 seconds. Trying to mitigate lag and FPS drops.
+ */
+ public static int ticksBetweenSounds = 30;
+ /**
* If you have to give something a World Parameter but there is no World... (Dummy World)
*/
public static World DW;
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index 95f3416a00..9e38ba60cd 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -64,7 +64,10 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
private byte mColor = 0, oColor = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, oTexturePage=0, oLightValueClient = -1, oLightValue = -1, mLightValue = 0, mOtherUpgrades = 0, mFacing = 0, oFacing = 0, mWorkData = 0;
private int mDisplayErrorCode = 0, oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0, mLagWarningCount = 0;
private short mID = 0;
- private long mTickTimer = 0, oOutput = 0, mAcceptedAmperes = Long.MAX_VALUE;
+ public long mTickTimer = 0;
+ private long oOutput = 0, mAcceptedAmperes = Long.MAX_VALUE;
+ public long mLastSoundTick = 0;
+ private long mLastCheckTick = 0;
private String mOwnerName = "";
private NBTTagCompound mRecipeStuff = new NBTTagCompound();
@@ -715,7 +718,10 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
// Uncomment this line to print out tick-by-tick times.
//tList.add("tTime " + tTime);
}
- tList.add("Average CPU-load of ~" + (tAverageTime / mTimeStatistics.length) + "ns over " + mTimeStatistics.length + " ticks with worst time of " + tWorstTime + "ns.");
+ tList.add("Average CPU load of ~" + (tAverageTime / mTimeStatistics.length) + "ns over " + mTimeStatistics.length + " ticks with worst time of " + tWorstTime + "ns.");
+ tList.add("Recorded " + mMetaTileEntity.mSoundRequests + " sound requests in " + (mTickTimer - mLastCheckTick) + " ticks." );
+ mLastCheckTick = mTickTimer;
+ mMetaTileEntity.mSoundRequests = 0;
}
if (mLagWarningCount > 0) {
tList.add("Caused " + (mLagWarningCount >= 10 ? "more than 10" : mLagWarningCount) + " Lag Spike Warnings (anything taking longer than " + GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING + "ms) on the Server.");
diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
index 7486a61445..7c3df98955 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
@@ -61,6 +61,8 @@ public abstract class MetaTileEntity implements IMetaTileEntity {
*/
private IGregTechTileEntity mBaseMetaTileEntity;
+ public long mSoundRequests=0;
+
/**
* This registers your Machine at the List.
* Use only ID's larger than 2048, because i reserved these ones.
@@ -259,6 +261,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity {
@Override
public final void sendLoopStart(byte aIndex) {
if (!getBaseMetaTileEntity().hasMufflerUpgrade()) getBaseMetaTileEntity().sendBlockEvent((byte) 5, aIndex);
+ mSoundRequests++;
}
@Override
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
index 0de978cc08..cdb0d94826 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
@@ -6,6 +6,7 @@ import gregtech.api.gui.GT_GUIContainer_BasicMachine;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.BaseMetaTileEntity;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_ModHandler.RecipeBits;
@@ -22,6 +23,7 @@ import java.util.Random;
import static gregtech.api.enums.GT_Values.V;
import static gregtech.api.enums.GT_Values.W;
+import static gregtech.api.enums.GT_Values.ticksBetweenSounds;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
@@ -694,7 +696,13 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
@Override
public void startProcess() {
- if (GT_Utility.isStringValid(mSound)) sendLoopStart((byte) 1);
+ BaseMetaTileEntity myMetaTileEntity = ((BaseMetaTileEntity)getBaseMetaTileEntity());
+ // Added to throttle sounds. To reduce lag, this is on the server side so BlockUpdate packets aren't sent.
+ if (myMetaTileEntity.mTickTimer > (myMetaTileEntity.mLastSoundTick+ticksBetweenSounds)) {
+ if (GT_Utility.isStringValid(mSound)) sendLoopStart((byte) 1);
+ // Does not have overflow protection, but they are longs.
+ myMetaTileEntity.mLastSoundTick = myMetaTileEntity.mTickTimer;
+ }
}
@Override