From f0c156a442aeb1b300fd42a01607358b84fc90f2 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Sun, 3 Nov 2013 01:00:28 -0500 Subject: [PATCH] Removed a bit issue with packet updates Tanks were being forced updated by a world update call every time they got any fluid. This would easily cause 100 packets a tick per machine. --- src/dark/api/fluid/INetworkFluidPart.java | 4 +-- .../fluid/NetworkFluidContainers.java | 14 ++------ .../tilenetwork/fluid/NetworkFluidTiles.java | 25 +++++++------- .../fluid/common/pipes/TileEntityPipe.java | 6 ++++ .../prefab/TileEntityFluidNetworkTile.java | 33 +++++++------------ 5 files changed, 35 insertions(+), 47 deletions(-) diff --git a/src/dark/api/fluid/INetworkFluidPart.java b/src/dark/api/fluid/INetworkFluidPart.java index e2a0fd99..3e55f9a8 100644 --- a/src/dark/api/fluid/INetworkFluidPart.java +++ b/src/dark/api/fluid/INetworkFluidPart.java @@ -21,11 +21,11 @@ public interface INetworkFluidPart extends IFluidHandler, INetworkPart /** Fills the pipe in the same way that fill method is called in IFluidHandler. This is used so * the network has a direct method to access the pipes internal fluid storage */ - public int fillTankContent(int index, FluidStack stack, boolean doFill, boolean update); + public int fillTankContent(int index, FluidStack stack, boolean doFill); /** Removes from from the pipe in the same way that drain method is called in IFluidHandler. This * is used so the network has a direct method to access the pipes internal fluid storage */ - public FluidStack drainTankContent(int index, int volume, boolean doDrain, boolean update); + public FluidStack drainTankContent(int index, int volume, boolean doDrain); /** Can the fluid pass from one side to the next. Used by path finder to see if the fluid can * move threw the pipes. diff --git a/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidContainers.java b/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidContainers.java index cb56854e..bd012da2 100644 --- a/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidContainers.java +++ b/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidContainers.java @@ -51,7 +51,7 @@ public class NetworkFluidContainers extends NetworkFluidTiles { if (part instanceof IFluidHandler) { - ((INetworkFluidPart) part).drainTankContent(0, Integer.MAX_VALUE, true, false); + ((INetworkFluidPart) part).drainTankContent(0, Integer.MAX_VALUE, true); } if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY) { @@ -85,8 +85,8 @@ public class NetworkFluidContainers extends NetworkFluidTiles /* Fill all tanks on this level */ for (INetworkFluidPart part : parts) { - part.drainTankContent(0, Integer.MAX_VALUE, true, false); - fillStack.amount -= part.fillTankContent(0, FluidHelper.getStack(fillStack, fillvolume), true, true); + part.drainTankContent(0, Integer.MAX_VALUE, true); + fillStack.amount -= part.fillTankContent(0, FluidHelper.getStack(fillStack, fillvolume), true); } } @@ -95,14 +95,6 @@ public class NetworkFluidContainers extends NetworkFluidTiles break; } } - - for (INetworkPart part : this.getNetworkMemebers()) - { - if (part instanceof TileEntity) - { - ((TileEntity) part).worldObj.markBlockForUpdate(((TileEntity) part).xCoord, ((TileEntity) part).yCoord, ((TileEntity) part).zCoord); - } - } } } diff --git a/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidTiles.java b/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidTiles.java index 3dab171d..2d7c42cd 100644 --- a/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidTiles.java +++ b/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidTiles.java @@ -11,7 +11,6 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import dark.api.ColorCode; import dark.api.fluid.INetworkFluidPart; import dark.api.parts.INetworkPart; import dark.core.prefab.helpers.FluidHelper; @@ -92,25 +91,25 @@ public class NetworkFluidTiles extends NetworkTileEntities this.readDataFromTiles(); this.loadedLiquids = true; } - if (!world.isRemote && this.getNetworkTank() != null) + FluidStack before = this.getNetworkTank().getFluid(); + if (!world.isRemote && this.getNetworkTank() != null && before != null) { - FluidStack p = this.getNetworkTank().getFluid(); - FluidStack r = this.getNetworkTank().drain(volume, doDrain); - FluidStack n = this.getNetworkTank().getFluid(); - //System.out.println((world.isRemote ? "Client" : "Server") + " Network Drain: B:" + (p != null ? p.amount : 0) + " A:" + (n != null ? n.amount : 0)); + FluidStack drain = this.getNetworkTank().drain(volume, doDrain); + FluidStack after = this.getNetworkTank().getFluid(); + // System.out.println((doDrain ? "" : "Fake") + " Network Drain for " + volume + " B:" + (before != null ? before.amount : 0) + " A:" + (after != null ? after.amount : 0) + " D:" + (drain != null ? drain.amount : 0)); if (doDrain) { //Has the tank changed any. If yes then update all info and do a client update - if (!p.isFluidEqual(n) || (p != null && n != null && p.amount != n.amount)) + if (!before.isFluidEqual(after) || (before != null && after != null && before.amount != after.amount)) { this.sharedTankInfo = this.getNetworkTank().getInfo(); this.writeDataToTiles(); - //TODO do a client update from the network rather than each pipe updating itself. - //This will save on packet size but will increase the CPU load of the client since it - //will need to do network calculations + /*TODO do a client update from the network rather than each pipe updating itself. + *This will save on packet size but will increase the CPU load of the client since the client + *will need to do network calculations */ } } - return r; + return drain; } return null; } @@ -132,11 +131,11 @@ public class NetworkFluidTiles extends NetworkTileEntities if (par instanceof INetworkFluidPart) { //EMPTY TANK - ((INetworkFluidPart) par).drainTankContent(0, Integer.MAX_VALUE, true, false); + ((INetworkFluidPart) par).drainTankContent(0, Integer.MAX_VALUE, true); //FILL TANK if (stack != null) { - stack.amount -= ((INetworkFluidPart) par).fillTankContent(0, FluidHelper.getStack(stack, fillVol), true, true); + stack.amount -= ((INetworkFluidPart) par).fillTankContent(0, FluidHelper.getStack(stack, fillVol), true); membersFilled++; } } diff --git a/src/dark/fluid/common/pipes/TileEntityPipe.java b/src/dark/fluid/common/pipes/TileEntityPipe.java index fe902ee1..155eaa1d 100644 --- a/src/dark/fluid/common/pipes/TileEntityPipe.java +++ b/src/dark/fluid/common/pipes/TileEntityPipe.java @@ -189,4 +189,10 @@ public class TileEntityPipe extends TileEntityFluidNetworkTile implements IColor { //TODO only send tank update for pipes that need to visually render the fluid, eg glass, stone, wood } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) + { + return false; + } } diff --git a/src/dark/fluid/common/prefab/TileEntityFluidNetworkTile.java b/src/dark/fluid/common/prefab/TileEntityFluidNetworkTile.java index dfa0e9cc..e01e212f 100644 --- a/src/dark/fluid/common/prefab/TileEntityFluidNetworkTile.java +++ b/src/dark/fluid/common/prefab/TileEntityFluidNetworkTile.java @@ -45,8 +45,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i protected FluidTankInfo[] internalTanksInfo = new FluidTankInfo[1]; protected List connectedBlocks = new ArrayList(); public boolean[] renderConnection = new boolean[6]; - public boolean[] canConnectSide = new boolean[] { true, true, true, true, true, true, true }; - public boolean updateTank = false; protected int heat = 0, maxHeat = 20000; protected int damage = 0, maxDamage = 1000; protected int subID = 0; @@ -94,7 +92,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i } if (ticks % TileEntityFluidNetworkTile.refreshRate == 0) { - this.updateTank = false; if (this.getTank().getFluid() == null && this.prevStack == null) { //Do nothing @@ -118,7 +115,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - if (this.getTileNetwork() != null && this.canConnectSide[from.ordinal()] && resource != null) + if (this.getTileNetwork() != null && resource != null) { return this.getTileNetwork().fillNetworkTank(this.worldObj, resource, doFill); } @@ -128,11 +125,11 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - if (this.getTileNetwork() != null && this.canConnectSide[from.ordinal()] && resource != null) + if (this.getTileNetwork() != null && resource != null) { if (this.getTileNetwork().getNetworkTank() != null && this.getTileNetwork().getNetworkTank().getFluid() != null && this.getTileNetwork().getNetworkTank().getFluid().isFluidEqual(resource)) { - this.getTileNetwork().drainNetworkTank(this.worldObj, resource.amount, doDrain); + return this.getTileNetwork().drainNetworkTank(this.worldObj, resource.amount, doDrain); } } @@ -142,9 +139,9 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - if (this.getTileNetwork() != null && this.canConnectSide[from.ordinal()]) + if (this.getTileNetwork() != null) { - this.getTileNetwork().drainNetworkTank(this.worldObj, maxDrain, doDrain); + return this.getTileNetwork().drainNetworkTank(this.worldObj, maxDrain, doDrain); } return null; } @@ -152,13 +149,13 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i @Override public boolean canFill(ForgeDirection from, Fluid fluid) { - return this.canConnectSide[from.ordinal()] && this.damage < this.maxDamage; + return true; } @Override public boolean canDrain(ForgeDirection from, Fluid fluid) { - return this.canConnectSide[from.ordinal()] && this.damage < this.maxDamage; + return true; } @Override @@ -253,7 +250,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i } @Override - public int fillTankContent(int index, FluidStack stack, boolean doFill, boolean update) + public int fillTankContent(int index, FluidStack stack, boolean doFill) { if (index == 0) { @@ -261,11 +258,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i int fill = this.getTank().fill(stack, doFill); if (p != fill && doFill) { - //TODO add a catch to this so we don't send a dozen packets for one updates - if (update) - { - this.updateTank = true; - } this.internalTanksInfo[index] = this.getTank().getInfo(); } return fill; @@ -274,7 +266,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i } @Override - public FluidStack drainTankContent(int index, int volume, boolean doDrain, boolean update) + public FluidStack drainTankContent(int index, int volume, boolean doDrain) { if (index == 0) { @@ -282,10 +274,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i FluidStack stack = this.getTank().drain(volume, doDrain); if (prev != null && (stack == null || prev.amount != stack.amount) && doDrain) { - if (update) - { - this.updateTank = true; - } this.internalTanksInfo[index] = this.getTank().getInfo(); } return stack; @@ -401,6 +389,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i this.tank = new FluidTank(data.readInt()); this.getTank().readFromNBT(PacketHandler.instance().readNBTTagCompound(data)); this.internalTanksInfo[0] = this.getTank().getInfo(); + System.out.println("DescriptionPacket"); return true; } else if (id.equalsIgnoreCase("RenderPacket")) @@ -412,6 +401,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i this.renderConnection[3] = data.readBoolean(); this.renderConnection[4] = data.readBoolean(); this.renderConnection[5] = data.readBoolean(); + System.out.println("RenderPacket"); return true; } else if (id.equalsIgnoreCase("SingleTank")) @@ -419,6 +409,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i this.tank = new FluidTank(data.readInt()); this.getTank().readFromNBT(PacketHandler.instance().readNBTTagCompound(data)); this.internalTanksInfo[0] = this.getTank().getInfo(); + System.out.println("TankPacket"); return true; } }