aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Java/gtPlusPlus/GTplusplus.java2
-rw-r--r--src/Java/gtPlusPlus/core/util/data/ArrayUtils.java6
-rw-r--r--src/Java/gtPlusPlus/core/util/sys/SystemUtils.java13
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_ThreadedSuperBuffer.java5
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_ThreadedSuperBuffer.java17
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java37
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java50
7 files changed, 109 insertions, 21 deletions
diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java
index 7d4f20aa56..6ea182f472 100644
--- a/src/Java/gtPlusPlus/GTplusplus.java
+++ b/src/Java/gtPlusPlus/GTplusplus.java
@@ -43,6 +43,7 @@ import gtPlusPlus.core.util.minecraft.*;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.core.util.sys.GeoUtils;
import gtPlusPlus.core.util.sys.NetworkUtils;
+import gtPlusPlus.core.util.sys.SystemUtils;
import gtPlusPlus.plugin.manager.Core_Manager;
import gtPlusPlus.xmod.gregtech.api.objects.GregtechBufferThread;
import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy;
@@ -178,6 +179,7 @@ public class GTplusplus implements ActionListener {
for (GregtechBufferThread i : GregtechBufferThread.mBufferThreadAllocation.values()) {
i.destroy();
}
+ SystemUtils.invokeGC();
}
}
diff --git a/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java b/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java
index 0c752c20e0..52316c8a43 100644
--- a/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java
+++ b/src/Java/gtPlusPlus/core/util/data/ArrayUtils.java
@@ -8,13 +8,13 @@ import gtPlusPlus.api.objects.data.AutoMap;
public class ArrayUtils {
- public static Object[] expandArray(final Object[] someArray, final Object newValueToAdd) {
- Object[] series = someArray;
+ public static <V> V[] expandArray(final V[] someArray, final V newValueToAdd) {
+ V[] series = someArray;
series = addElement(series, newValueToAdd);
return series;
}
- private static Object[] addElement(Object[] series, final Object newValueToAdd) {
+ private static <V> V[] addElement(V[] series, final V newValueToAdd) {
series = Arrays.copyOf(series, series.length + 1);
series[series.length - 1] = newValueToAdd;
return series;
diff --git a/src/Java/gtPlusPlus/core/util/sys/SystemUtils.java b/src/Java/gtPlusPlus/core/util/sys/SystemUtils.java
index efcfaf8d04..2788ba688e 100644
--- a/src/Java/gtPlusPlus/core/util/sys/SystemUtils.java
+++ b/src/Java/gtPlusPlus/core/util/sys/SystemUtils.java
@@ -14,6 +14,19 @@ public class SystemUtils {
}
}
+ /**
+ * Try invoke the runtime's Garbage Collector.
+ */
+ public static void invokeGC() {
+ try {
+ Runtime r = Runtime.getRuntime();
+ r.gc();
+ }
+ catch (Throwable t) {
+ //Do nothing.
+ }
+ }
+
public static boolean isWindows() {
return (getOSString().indexOf("win") >= 0);
}
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_ThreadedSuperBuffer.java b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_ThreadedSuperBuffer.java
index 7adcfb9683..51ad334a01 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_ThreadedSuperBuffer.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_ThreadedSuperBuffer.java
@@ -2,6 +2,7 @@ package gtPlusPlus.xmod.gregtech.api.gui;
import gregtech.api.util.GT_Utility;
+import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_ThreadedBuffer;
import gtPlusPlus.xmod.gregtech.common.tileentities.automation.GT_MetaTileEntity_ThreadedChestBuffer;
import net.minecraft.item.ItemStack;
@@ -14,8 +15,12 @@ import net.minecraft.entity.player.InventoryPlayer;
import gregtech.api.gui.GT_ContainerMetaTile_Machine;
public class CONTAINER_ThreadedSuperBuffer extends GT_ContainerMetaTile_Machine {
+
+ protected int cacheTime = 0;
+
public CONTAINER_ThreadedSuperBuffer(final InventoryPlayer aInventoryPlayer, final IGregTechTileEntity aTileEntity) {
super(aInventoryPlayer, aTileEntity);
+ cacheTime = ((GT_MetaTileEntity_ThreadedBuffer)aTileEntity.getMetaTileEntity()).mThreadTimeLeft;
}
public void addSlots(final InventoryPlayer aInventoryPlayer) {
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_ThreadedSuperBuffer.java b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_ThreadedSuperBuffer.java
index 83e96cd85b..2ca0b25e23 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_ThreadedSuperBuffer.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/GUI_ThreadedSuperBuffer.java
@@ -1,15 +1,28 @@
package gtPlusPlus.xmod.gregtech.api.gui;
-import gregtech.api.gui.GT_ContainerMetaTile_Machine;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import net.minecraft.entity.player.InventoryPlayer;
import gregtech.api.gui.GT_GUIContainerMetaTile_Machine;
public class GUI_ThreadedSuperBuffer extends GT_GUIContainerMetaTile_Machine {
+
+ int cacheTime = 0;
+
public GUI_ThreadedSuperBuffer(final InventoryPlayer aInventoryPlayer, final IGregTechTileEntity aTileEntity) {
- super((GT_ContainerMetaTile_Machine) new CONTAINER_ThreadedSuperBuffer(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/SuperBuffer.png");
+ super(new CONTAINER_ThreadedSuperBuffer(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/SuperBuffer.png");
+ }
+
+ private void updateVars(){
+ this.cacheTime = ((CONTAINER_ThreadedSuperBuffer)this.mContainer).cacheTime;
+ }
+
+ @Override
+ protected void drawGuiContainerForegroundLayer(final int par1, final int par2){
+ this.updateVars();
+ this.fontRendererObj.drawString("Time Remaining: "+cacheTime, 76, 61, 4210752);
}
+ @Override
protected void drawGuiContainerBackgroundLayer(final float par1, final int par2, final int par3) {
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
final int x = (this.width - this.xSize) / 2;
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java
index 855b856f49..9642ff63ee 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java
@@ -7,6 +7,7 @@ import gregtech.api.enums.GT_Values;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.minecraft.BlockPos;
+import gtPlusPlus.core.util.data.ArrayUtils;
import gtPlusPlus.xmod.gregtech.api.objects.GregtechBufferThread;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
@@ -378,4 +379,40 @@ public abstract class GT_MetaTileEntity_ThreadedBuffer extends GT_MetaTileEntity
this.mInventorySynchro[aIndex] = aStack;
}
}
+
+ private synchronized void cleanup() {
+ if (this.mLogicThread != null) {
+ this.mLogicThread.destroy();
+ this.mLogicThread = null;
+ }
+ }
+
+ @Override
+ public void onExplosion() {
+ cleanup();
+ super.onExplosion();
+ }
+
+ @Override
+ public void onRemoval() {
+ cleanup();
+ super.onRemoval();
+ }
+
+ @Override
+ public boolean isGivingInformation() {
+ return true;
+ }
+
+ @Override
+ public String[] getInfoData() {
+ String mResult[] = super.getInfoData();
+ String mAdditive[] = new String[] {
+ "info"
+ };
+ for (String s : mAdditive) {
+ ArrayUtils.expandArray(mResult, s);
+ }
+ return mResult;
+ }
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java
index cf477b0889..1e7d73bacd 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java
@@ -26,7 +26,7 @@ public class GregtechBufferThread extends Thread {
public static synchronized final GregtechBufferThread getBufferThread(BlockPos pos) {
if (pos != null && mBufferThreadAllocation.containsKey(""+pos.getUniqueIdentifier())){
- Logger.INFO("[SB] Found an existing thread for this dimension.");
+ Logger.INFO("[SB] Found an existing thread for this Buffer.");
return mBufferThreadAllocation.get(""+pos.getUniqueIdentifier());
}
else {
@@ -47,12 +47,18 @@ public class GregtechBufferThread extends Thread {
mBlockPos = null;
}
this.setName("GTPP-SuperBuffer("+mID+")");
+ this.setDaemon(true);
if (mBlockPos != null && !this.isAlive()) {
- start();
- Logger.INFO("[SB] Created a SuperBuffer Thread for dimension "+mID+".");
+ try {
+ start();
+ Logger.INFO("[SB] Created a SuperBuffer Thread for dimension "+mID+".");
+ }
+ catch (Throwable t_) {
+ //Do nothing.
+ }
}
}
-
+
public synchronized int getTimeLeft() {
return this.mLifeCycleTime;
}
@@ -119,11 +125,11 @@ public class GregtechBufferThread extends Thread {
* Some GT logic we'd like to move off thread
*/
- public synchronized static boolean areStacksEqual(final ItemStack aStack1, final ItemStack aStack2) {
+ public synchronized boolean areStacksEqual(final ItemStack aStack1, final ItemStack aStack2) {
return areStacksEqual(aStack1, aStack2, false);
}
- public synchronized static boolean areStacksEqual(final ItemStack aStack1, final ItemStack aStack2, final boolean aIgnoreNBT) {
+ public synchronized boolean areStacksEqual(final ItemStack aStack1, final ItemStack aStack2, final boolean aIgnoreNBT) {
return aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem()
&& (aIgnoreNBT || (aStack1.getTagCompound() == null == (aStack2.getTagCompound() == null)
&& (aStack1.getTagCompound() == null
@@ -132,7 +138,7 @@ public class GregtechBufferThread extends Thread {
|| Items.feather.getDamage(aStack1) == 32767 || Items.feather.getDamage(aStack2) == 32767);
}
- public synchronized static byte moveStackFromSlotAToSlotB(final IInventory aTileEntity1, final IInventory aTileEntity2,
+ public synchronized byte moveStackFromSlotAToSlotB(final IInventory aTileEntity1, final IInventory aTileEntity2,
final int aGrabFrom, final int aPutTo, byte aMaxTargetStackSize, final byte aMinTargetStackSize,
final byte aMaxMoveAtOnce, final byte aMinMoveAtOnce) {
if (aTileEntity1 == null || aTileEntity2 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0
@@ -183,13 +189,18 @@ public class GregtechBufferThread extends Thread {
@Override
public void run() {
//While thread is alive.
- while (mRunning) {
+ run: while (mRunning) {
//While thread is active, lets tick it's life down.
- while (mLifeCycleTime > 0) {
- //Remove invalid threads
- if (this.mBlockPos.world == null) {
- mLifeCycleTime = 0;
+ life: while (mLifeCycleTime > 0) {
+ if (!mRunning) {
+ break life;
}
+
+ //Remove invalid threads
+ if (this.mBlockPos.world == null || this.mBlockPos.getBlockAtPos() == null) {
+ destroy();
+ break run;
+ }
//Prevent Overflows
if (mLifeCycleTime > mMaxLife) {
mLifeCycleTime = mMaxLife;
@@ -197,7 +208,7 @@ public class GregtechBufferThread extends Thread {
try {
sleep(1000);
mLifeCycleTime--;
- Logger.INFO("[SB] Ticking Thread "+mID+" | Remaining: "+mLifeCycleTime+"s");
+ Logger.WARNING("[SB] Ticking Thread "+mID+" | Remaining: "+mLifeCycleTime+"s");
}
catch (InterruptedException e) {
mLifeCycleTime = 0;
@@ -205,17 +216,24 @@ public class GregtechBufferThread extends Thread {
}
if (mLifeCycleTime <= 0) {
destroy();
+ break run;
}
}
}
+ @SuppressWarnings("deprecation")
@Override
public void destroy() {
+ mRunning = false;
GregtechBufferThread.mBufferThreadAllocation.remove(mID, this);
Logger.INFO("[SB] Removing Thread "+mID);
- mRunning = false;
- mLifeCycleTime = 0;
- stop();
+ try {
+ stop();
+ this.finalize();
+ }
+ catch (Throwable t) {
+ //Do nothing.
+ }
}