From b717ab348f702bd89e50e1d9bdf61b1b7711e112 Mon Sep 17 00:00:00 2001 From: tossaponk Date: Mon, 12 Sep 2016 01:40:54 +0700 Subject: [PATCH 1/3] More dynamic tank network optimization Currently, the dynamic tank will send update packet if stored fluid amount is changed even if the changed amount is very little and has no visual change(10000000->9999990) and wasting the server bandwidth. Instead of send change every time fluid amount changed. This edit will only send update packet when fluid level is noticeably changed saving a lot of bandwidth usage if the tank is actively getting filled and drained every tick. --- .../mekanism/common/content/tank/SynchronizedTankData.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/mekanism/common/content/tank/SynchronizedTankData.java b/src/main/java/mekanism/common/content/tank/SynchronizedTankData.java index b9d8f0278..c7e3db0d6 100644 --- a/src/main/java/mekanism/common/content/tank/SynchronizedTankData.java +++ b/src/main/java/mekanism/common/content/tank/SynchronizedTankData.java @@ -16,6 +16,7 @@ public class SynchronizedTankData extends SynchronizedData /** For use by rendering segment */ public FluidStack prevFluid; + public int prevFluidStage = 0; public ContainerEditMode editMode = ContainerEditMode.BOTH; @@ -32,7 +33,11 @@ public class SynchronizedTankData extends SynchronizedData if(fluidStored != null && prevFluid != null) { - if((fluidStored.getFluid() != prevFluid.getFluid()) || (fluidStored.amount != prevFluid.amount)) + int totalStage = (volHeight - 2) * (TankUpdateProtocol.FLUID_PER_TANK / 100); + int currentStage = (int)((fluidStored.amount / (float)(volume*TankUpdateProtocol.FLUID_PER_TANK)) * totalStage); + boolean stageChanged = currentStage != prevFluidStage; + prevFluidStage = currentStage; + if((fluidStored.getFluid() != prevFluid.getFluid()) || stageChanged) { return true; } From e7c4ac922f2448d00b8cfe1ae459929b0e06e38e Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 21 Oct 2016 17:08:06 +0200 Subject: [PATCH 2/3] hopefully solving EOF & allocation problems --- .../mekanism/client/voice/VoiceOutput.java | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main/java/mekanism/client/voice/VoiceOutput.java b/src/main/java/mekanism/client/voice/VoiceOutput.java index 9d8e43d82..cc262a7b4 100644 --- a/src/main/java/mekanism/client/voice/VoiceOutput.java +++ b/src/main/java/mekanism/client/voice/VoiceOutput.java @@ -30,20 +30,31 @@ public class VoiceOutput extends Thread public void run() { try { - sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker)); - sourceLine.open(voiceClient.format, 2200); - sourceLine.start(); - - while(voiceClient.running) - { - try { - short byteCount = voiceClient.input.readShort(); - byte[] audioData = new byte[byteCount]; - voiceClient.input.readFully(audioData); - - sourceLine.write(audioData, 0, audioData.length); - } catch(Exception e) {} + sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker)); + sourceLine.open(voiceClient.format, 2200); + sourceLine.start(); + byte[] audioData = new byte[4096]; // less allocation/gc (if done outside the loop) + int byteCount; + int length; + while(voiceClient.running) + { + try { + byteCount = voiceClient.input.readUnsignedShort(); //Why would we only read signed shorts? negative amount of waiting data doesn't make sense anyway :D + while(byteCount>0 && voiceClient.running){ + length=audioData.length; + if(length>byteCount) length=byteCount; + length = voiceClient.input.read(audioData, 0, length); // That one returns the actual read amount of data (we can begin transferring even if input is waiting/incomplete) + if(length<0) throw new EOFException(); + sourceLine.write(audioData, 0, length); + byteCount-=length; } + } catch(EOFException eof){ + Mekanism.logger.error("VoiceServer: Unexpected input EOF Exception occured."); + break; // voiceClient.input will continue throwing EOFs -> no need to go on checking + } catch(Exception e) { + /*Would a debug output be good here?*/ + } + } } catch(Exception e) { Mekanism.logger.error("VoiceServer: Error while running client output thread."); e.printStackTrace(); From 15d1f32be233931e4e1f8a6c32322f5df8af27fc Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 21 Oct 2016 17:13:14 +0200 Subject: [PATCH 3/3] formatting & missing import for EOFException --- .../mekanism/client/voice/VoiceOutput.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/mekanism/client/voice/VoiceOutput.java b/src/main/java/mekanism/client/voice/VoiceOutput.java index cc262a7b4..28de47f3d 100644 --- a/src/main/java/mekanism/client/voice/VoiceOutput.java +++ b/src/main/java/mekanism/client/voice/VoiceOutput.java @@ -3,6 +3,7 @@ package mekanism.client.voice; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.SourceDataLine; +import java.io.EOFException; import mekanism.common.Mekanism; import net.minecraftforge.fml.relauncher.Side; @@ -30,31 +31,31 @@ public class VoiceOutput extends Thread public void run() { try { - sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker)); - sourceLine.open(voiceClient.format, 2200); - sourceLine.start(); - byte[] audioData = new byte[4096]; // less allocation/gc (if done outside the loop) - int byteCount; - int length; - while(voiceClient.running) - { - try { - byteCount = voiceClient.input.readUnsignedShort(); //Why would we only read signed shorts? negative amount of waiting data doesn't make sense anyway :D - while(byteCount>0 && voiceClient.running){ - length=audioData.length; - if(length>byteCount) length=byteCount; - length = voiceClient.input.read(audioData, 0, length); // That one returns the actual read amount of data (we can begin transferring even if input is waiting/incomplete) - if(length<0) throw new EOFException(); - sourceLine.write(audioData, 0, length); - byteCount-=length; + sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker)); + sourceLine.open(voiceClient.format, 2200); + sourceLine.start(); + byte[] audioData = new byte[4096]; // less allocation/gc (if done outside the loop) + int byteCount; + int length; + while(voiceClient.running) + { + try { + byteCount = voiceClient.input.readUnsignedShort(); //Why would we only read signed shorts? negative amount of waiting data doesn't make sense anyway :D + while(byteCount>0 && voiceClient.running){ + length=audioData.length; + if(length>byteCount) length=byteCount; + length = voiceClient.input.read(audioData, 0, length); // That one returns the actual read amount of data (we can begin transferring even if input is waiting/incomplete) + if(length<0) throw new EOFException(); + sourceLine.write(audioData, 0, length); + byteCount-=length; + } + } catch(EOFException eof){ + Mekanism.logger.error("VoiceServer: Unexpected input EOF Exception occured."); + break; // voiceClient.input will continue throwing EOFs -> no need to go on checking + } catch(Exception e) { + /*Would a debug output be good here?*/ + } } - } catch(EOFException eof){ - Mekanism.logger.error("VoiceServer: Unexpected input EOF Exception occured."); - break; // voiceClient.input will continue throwing EOFs -> no need to go on checking - } catch(Exception e) { - /*Would a debug output be good here?*/ - } - } } catch(Exception e) { Mekanism.logger.error("VoiceServer: Error while running client output thread."); e.printStackTrace();