Trying to buffer update rate for tank

Before they could update as fast as they want. Now i'm limiting update
to once a second. After this i'm going to work on sending a packet from
server tile network to client tile network. Then have the client update
its volume. This will reduce packet size but will increase CPU time on
the client.
This commit is contained in:
DarkGuardsman 2013-11-02 21:03:57 -04:00
parent 50b1bc8752
commit 6636b47004

View file

@ -40,11 +40,13 @@ import dark.fluid.common.FluidPartsMaterial;
public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice implements INetworkFluidPart, ISimplePacketReceiver public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice implements INetworkFluidPart, ISimplePacketReceiver
{ {
private int updateTick = 1; private int updateTick = 1;
public static int refreshRate = 20;
protected FluidTank tank; protected FluidTank tank;
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[] 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;
@ -89,6 +91,11 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
this.updateTick = this.worldObj.rand.nextInt(5) * 40 + 20; this.updateTick = this.worldObj.rand.nextInt(5) * 40 + 20;
this.refresh(); this.refresh();
} }
if (ticks % this.refreshRate == 0)
{
this.updateTank = false;
this.sendTankUpdate(0);
}
} }
} }
@ -248,7 +255,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
//TODO add a catch to this so we don't send a dozen packets for one updates //TODO add a catch to this so we don't send a dozen packets for one updates
if (update) if (update)
{ {
this.sendTankUpdate(index); this.updateTank = true;
} }
this.internalTanksInfo[index] = this.getTank().getInfo(); this.internalTanksInfo[index] = this.getTank().getInfo();
} }
@ -268,7 +275,7 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i
{ {
if (update) if (update)
{ {
this.sendTankUpdate(index); this.updateTank = true;
} }
this.internalTanksInfo[index] = this.getTank().getInfo(); this.internalTanksInfo[index] = this.getTank().getInfo();
} }