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
* 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.

View file

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

View file

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

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
}
@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 List<TileEntity> connectedBlocks = new ArrayList<TileEntity>();
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;
}
}