From 2cf84989d19c15ea117f3ea8b1bc56ae0f4ff336 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sun, 18 May 2014 21:36:32 -0500 Subject: [PATCH] IC2 Double Buffer Approach. --- parts/p2p/PartP2PIC2Power.java | 42 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/parts/p2p/PartP2PIC2Power.java b/parts/p2p/PartP2PIC2Power.java index 69f42bfa2..70e744611 100644 --- a/parts/p2p/PartP2PIC2Power.java +++ b/parts/p2p/PartP2PIC2Power.java @@ -36,20 +36,24 @@ public class PartP2PIC2Power extends PartP2PTunnel implements i throw new RuntimeException( "IC2 Not installed!" ); } - double OutputPacket; + // two packet buffering... + double OutputPacketA; + double OutputPacketB; @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT( tag ); - tag.setDouble( "OutputPacket", OutputPacket ); + tag.setDouble( "OutputPacket", OutputPacketA ); + tag.setDouble( "OutputPacket2", OutputPacketB ); } @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT( tag ); - OutputPacket = tag.getDouble( "OutputPacket" ); + OutputPacketA = tag.getDouble( "OutputPacket" ); + OutputPacketB = tag.getDouble( "OutputPacket2" ); } @SideOnly(Side.CLIENT) @@ -84,7 +88,7 @@ public class PartP2PIC2Power extends PartP2PTunnel implements i { for (PartP2PIC2Power t : getOutputs()) { - if ( t.OutputPacket <= 0.0001 ) + if ( t.OutputPacketA <= 0.0001 || t.OutputPacketB <= 0.0001 ) { return 2048; } @@ -128,10 +132,17 @@ public class PartP2PIC2Power extends PartP2PTunnel implements i LinkedList Options = new LinkedList(); for (PartP2PIC2Power o : outs) { - if ( o.OutputPacket <= 0.01 ) + if ( o.OutputPacketA <= 0.01 ) Options.add( o ); } + if ( Options.isEmpty() ) + { + for (PartP2PIC2Power o : outs) + if ( o.OutputPacketB <= 0.01 ) + Options.add( o ); + } + if ( Options.isEmpty() ) { for (PartP2PIC2Power o : outs) @@ -142,10 +153,18 @@ public class PartP2PIC2Power extends PartP2PTunnel implements i return amount; PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options ); - if ( x != null && x.OutputPacket <= 0.001 ) + + if ( x != null && x.OutputPacketA <= 0.001 ) { QueueTunnelDrain( PowerUnits.EU, amount ); - x.OutputPacket = amount; + x.OutputPacketA = amount; + return 0; + } + + if ( x != null && x.OutputPacketB <= 0.001 ) + { + QueueTunnelDrain( PowerUnits.EU, amount ); + x.OutputPacketB = amount; return 0; } @@ -162,14 +181,19 @@ public class PartP2PIC2Power extends PartP2PTunnel implements i public double getOfferedEnergy() { if ( output ) - return OutputPacket; + return OutputPacketA; return 0; } @Override public void drawEnergy(double amount) { - OutputPacket -= amount; + OutputPacketA -= amount; + if ( OutputPacketA < 0.001 ) + { + OutputPacketA = OutputPacketB; + OutputPacketB = 0; + } } }