Merge branch 'master' into 1.10

* master:
  formatting & missing import for EOFException
  hopefully solving EOF & allocation problems
  More dynamic tank network optimization
This commit is contained in:
aidancbrady committed 2016-11-03 16:58:32 -04:00
commit ccff5dcefe
2 files changed
+25 -8

No files matched your search

@@ -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;
@@ -33,16 +34,27 @@ public class VoiceOutput extends Thread
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 {
short byteCount = voiceClient.input.readShort();
byte[] audioData = new byte[byteCount];
voiceClient.input.readFully(audioData);
sourceLine.write(audioData, 0, audioData.length);
} catch(Exception e) {}
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.");
@@ -16,6 +16,7 @@ public class SynchronizedTankData extends SynchronizedData<SynchronizedTankData>
/** 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<SynchronizedTankData>
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;
}