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.
This commit is contained in:
DarkGuardsman 2013-11-03 01:00:28 -05:00
parent 27567fe18c
commit f0c156a442
5 changed files with 35 additions and 47 deletions

View file

@ -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 /** 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 */ * 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 /** 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 */ * 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 /** Can the fluid pass from one side to the next. Used by path finder to see if the fluid can
* move threw the pipes. * move threw the pipes.

View file

@ -51,7 +51,7 @@ public class NetworkFluidContainers extends NetworkFluidTiles
{ {
if (part instanceof IFluidHandler) 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) if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
{ {
@ -85,8 +85,8 @@ public class NetworkFluidContainers extends NetworkFluidTiles
/* Fill all tanks on this level */ /* Fill all tanks on this level */
for (INetworkFluidPart part : parts) for (INetworkFluidPart part : parts)
{ {
part.drainTankContent(0, Integer.MAX_VALUE, true, false); part.drainTankContent(0, Integer.MAX_VALUE, true);
fillStack.amount -= part.fillTankContent(0, FluidHelper.getStack(fillStack, fillvolume), true, true); fillStack.amount -= part.fillTankContent(0, FluidHelper.getStack(fillStack, fillvolume), true);
} }
} }
@ -95,14 +95,6 @@ public class NetworkFluidContainers extends NetworkFluidTiles
break; break;
} }
} }
for (INetworkPart part : this.getNetworkMemebers())
{
if (part instanceof TileEntity)
{
((TileEntity) part).worldObj.markBlockForUpdate(((TileEntity) part).xCoord, ((TileEntity) part).yCoord, ((TileEntity) part).zCoord);
}
}
} }
} }

View file

@ -11,7 +11,6 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import dark.api.ColorCode;
import dark.api.fluid.INetworkFluidPart; import dark.api.fluid.INetworkFluidPart;
import dark.api.parts.INetworkPart; import dark.api.parts.INetworkPart;
import dark.core.prefab.helpers.FluidHelper; import dark.core.prefab.helpers.FluidHelper;
@ -92,25 +91,25 @@ public class NetworkFluidTiles extends NetworkTileEntities
this.readDataFromTiles(); this.readDataFromTiles();
this.loadedLiquids = true; 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 drain = this.getNetworkTank().drain(volume, doDrain);
FluidStack r = this.getNetworkTank().drain(volume, doDrain); FluidStack after = this.getNetworkTank().getFluid();
FluidStack n = 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));
//System.out.println((world.isRemote ? "Client" : "Server") + " Network Drain: B:" + (p != null ? p.amount : 0) + " A:" + (n != null ? n.amount : 0));
if (doDrain) if (doDrain)
{ {
//Has the tank changed any. If yes then update all info and do a client update //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.sharedTankInfo = this.getNetworkTank().getInfo();
this.writeDataToTiles(); this.writeDataToTiles();
//TODO do a client update from the network rather than each pipe updating itself. /*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 *This will save on packet size but will increase the CPU load of the client since the client
//will need to do network calculations *will need to do network calculations */
} }
} }
return r; return drain;
} }
return null; return null;
} }
@ -132,11 +131,11 @@ public class NetworkFluidTiles extends NetworkTileEntities
if (par instanceof INetworkFluidPart) if (par instanceof INetworkFluidPart)
{ {
//EMPTY TANK //EMPTY TANK
((INetworkFluidPart) par).drainTankContent(0, Integer.MAX_VALUE, true, false); ((INetworkFluidPart) par).drainTankContent(0, Integer.MAX_VALUE, true);
//FILL TANK //FILL TANK
if (stack != null) 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++; membersFilled++;
} }
} }

View file

@ -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 //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;
}
} }

View file

@ -45,8 +45,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
protected FluidTankInfo[] internalTanksInfo = new FluidTankInfo[1]; protected FluidTankInfo[] internalTanksInfo = new FluidTankInfo[1];
protected List<TileEntity> connectedBlocks = new ArrayList<TileEntity>(); protected List<TileEntity> connectedBlocks = new ArrayList<TileEntity>();
public boolean[] renderConnection = new boolean[6]; 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 heat = 0, maxHeat = 20000;
protected int damage = 0, maxDamage = 1000; protected int damage = 0, maxDamage = 1000;
protected int subID = 0; protected int subID = 0;
@ -94,7 +92,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
} }
if (ticks % TileEntityFluidNetworkTile.refreshRate == 0) if (ticks % TileEntityFluidNetworkTile.refreshRate == 0)
{ {
this.updateTank = false;
if (this.getTank().getFluid() == null && this.prevStack == null) if (this.getTank().getFluid() == null && this.prevStack == null)
{ {
//Do nothing //Do nothing
@ -118,7 +115,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
@Override @Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) 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); return this.getTileNetwork().fillNetworkTank(this.worldObj, resource, doFill);
} }
@ -128,11 +125,11 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
@Override @Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) 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)) 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 @Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) 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; return null;
} }
@ -152,13 +149,13 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
@Override @Override
public boolean canFill(ForgeDirection from, Fluid fluid) public boolean canFill(ForgeDirection from, Fluid fluid)
{ {
return this.canConnectSide[from.ordinal()] && this.damage < this.maxDamage; return true;
} }
@Override @Override
public boolean canDrain(ForgeDirection from, Fluid fluid) public boolean canDrain(ForgeDirection from, Fluid fluid)
{ {
return this.canConnectSide[from.ordinal()] && this.damage < this.maxDamage; return true;
} }
@Override @Override
@ -253,7 +250,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
} }
@Override @Override
public int fillTankContent(int index, FluidStack stack, boolean doFill, boolean update) public int fillTankContent(int index, FluidStack stack, boolean doFill)
{ {
if (index == 0) if (index == 0)
{ {
@ -261,11 +258,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
int fill = this.getTank().fill(stack, doFill); int fill = this.getTank().fill(stack, doFill);
if (p != fill && 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(); this.internalTanksInfo[index] = this.getTank().getInfo();
} }
return fill; return fill;
@ -274,7 +266,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
} }
@Override @Override
public FluidStack drainTankContent(int index, int volume, boolean doDrain, boolean update) public FluidStack drainTankContent(int index, int volume, boolean doDrain)
{ {
if (index == 0) if (index == 0)
{ {
@ -282,10 +274,6 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
FluidStack stack = this.getTank().drain(volume, doDrain); FluidStack stack = this.getTank().drain(volume, doDrain);
if (prev != null && (stack == null || prev.amount != stack.amount) && doDrain) if (prev != null && (stack == null || prev.amount != stack.amount) && doDrain)
{ {
if (update)
{
this.updateTank = true;
}
this.internalTanksInfo[index] = this.getTank().getInfo(); this.internalTanksInfo[index] = this.getTank().getInfo();
} }
return stack; return stack;
@ -401,6 +389,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
this.tank = new FluidTank(data.readInt()); this.tank = new FluidTank(data.readInt());
this.getTank().readFromNBT(PacketHandler.instance().readNBTTagCompound(data)); this.getTank().readFromNBT(PacketHandler.instance().readNBTTagCompound(data));
this.internalTanksInfo[0] = this.getTank().getInfo(); this.internalTanksInfo[0] = this.getTank().getInfo();
System.out.println("DescriptionPacket");
return true; return true;
} }
else if (id.equalsIgnoreCase("RenderPacket")) else if (id.equalsIgnoreCase("RenderPacket"))
@ -412,6 +401,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
this.renderConnection[3] = data.readBoolean(); this.renderConnection[3] = data.readBoolean();
this.renderConnection[4] = data.readBoolean(); this.renderConnection[4] = data.readBoolean();
this.renderConnection[5] = data.readBoolean(); this.renderConnection[5] = data.readBoolean();
System.out.println("RenderPacket");
return true; return true;
} }
else if (id.equalsIgnoreCase("SingleTank")) else if (id.equalsIgnoreCase("SingleTank"))
@ -419,6 +409,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
this.tank = new FluidTank(data.readInt()); this.tank = new FluidTank(data.readInt());
this.getTank().readFromNBT(PacketHandler.instance().readNBTTagCompound(data)); this.getTank().readFromNBT(PacketHandler.instance().readNBTTagCompound(data));
this.internalTanksInfo[0] = this.getTank().getInfo(); this.internalTanksInfo[0] = this.getTank().getInfo();
System.out.println("TankPacket");
return true; return true;
} }
} }