Small optimisations to Camera registry, etc.

Updated monitor to only work with an empty hand
Removed useless calls to invalidate (Forge already do it)
Fixed Camera & LaserCamera not always removed from registry
Improved server & network load when updating Camera & LaserCamera
registration
Updated debug logs to state client/server side
This commit is contained in:
LemADEC 2014-08-10 16:47:26 +02:00
parent 147f4f4ebc
commit f2921db45c
13 changed files with 54 additions and 95 deletions

View file

@ -148,7 +148,7 @@ public class WarpDrive implements LoadingCallback {
return; return;
} }
if (WarpDriveConfig.debugMode) { if (WarpDriveConfig.debugMode) {
System.out.println(out); System.out.println((FMLCommonHandler.instance().getEffectiveSide().isClient() ? "Client ":"Server ") + out);
} }
} }

View file

@ -97,14 +97,4 @@ public class BlockAirGenerator extends BlockContainer
return false; return false;
} }
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null) {
te.invalidate();
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
} }

View file

@ -44,7 +44,7 @@ public class BlockCamera extends BlockContainer {
} }
@Override @Override
public TileEntity createNewTileEntity(World var1) { public TileEntity createNewTileEntity(World parWorld) {
return new TileEntityCamera(); return new TileEntityCamera();
} }
@ -60,7 +60,7 @@ public class BlockCamera extends BlockContainer {
* Returns the ID of the items to drop on destruction. * Returns the ID of the items to drop on destruction.
*/ */
@Override @Override
public int idDropped(int par1, Random par2Random, int par3) { public int idDropped(int par1, Random par2Random, int par3) {
return this.blockID; return this.blockID;
} }
@ -75,7 +75,7 @@ public class BlockCamera extends BlockContainer {
// Get camera frequency // Get camera frequency
TileEntity te = par1World.getBlockTileEntity(x, y, z); TileEntity te = par1World.getBlockTileEntity(x, y, z);
if (te != null && te instanceof TileEntityCamera) { if (te != null && te instanceof TileEntityCamera && (par5EntityPlayer.getHeldItem() == null)) {
int frequency = ((TileEntityCamera)te).getFrequency(); int frequency = ((TileEntityCamera)te).getFrequency();
CamRegistryItem cam = WarpDrive.instance.cams.getCamByFrequency(par1World, frequency); CamRegistryItem cam = WarpDrive.instance.cams.getCamByFrequency(par1World, frequency);

View file

@ -64,14 +64,4 @@ public class BlockCloakingCoil extends Block {
public int idDropped(int par1, Random par2Random, int par3) { public int idDropped(int par1, Random par2Random, int par3) {
return this.blockID; return this.blockID;
} }
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null) {
te.invalidate();
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
} }

View file

@ -91,8 +91,6 @@ public class BlockCloakingDeviceCore extends BlockContainer {
if (te != null && te instanceof TileEntityCloakingDeviceCore) { if (te != null && te instanceof TileEntityCloakingDeviceCore) {
((TileEntityCloakingDeviceCore)te).isEnabled = false; ((TileEntityCloakingDeviceCore)te).isEnabled = false;
((TileEntityCloakingDeviceCore)te).disableCloakingField(); ((TileEntityCloakingDeviceCore)te).disableCloakingField();
te.invalidate();
} }
super.breakBlock(par1World, par2, par3, par4, par5, par6); super.breakBlock(par1World, par2, par3, par4, par5, par6);

View file

@ -96,12 +96,4 @@ public class BlockLift extends BlockContainer
return false; return false;
} }
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null) {
te.invalidate();
}
}
} }

View file

@ -75,7 +75,6 @@ public class BlockMonitor extends BlockContainer {
if (te != null && te instanceof TileEntityMonitor && (par5EntityPlayer.getHeldItem() == null)) { if (te != null && te instanceof TileEntityMonitor && (par5EntityPlayer.getHeldItem() == null)) {
int frequency = ((TileEntityMonitor)te).getFrequency(); int frequency = ((TileEntityMonitor)te).getFrequency();
WarpDrive.instance.cams.removeDeadCams(par1World);
CamRegistryItem cam = WarpDrive.instance.cams.getCamByFrequency(par1World, frequency); CamRegistryItem cam = WarpDrive.instance.cams.getCamByFrequency(par1World, frequency);
if (cam == null) { if (cam == null) {
par5EntityPlayer.addChatMessage(getLocalizedName() + " Frequency '" + frequency + "' is invalid or camera is too far!"); par5EntityPlayer.addChatMessage(getLocalizedName() + " Frequency '" + frequency + "' is invalid or camera is too far!");

View file

@ -92,14 +92,4 @@ public class BlockParticleBooster extends BlockContainer {
return false; return false;
} }
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null) {
te.invalidate();
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
} }

View file

@ -99,14 +99,4 @@ public class BlockRadar extends BlockContainer
return false; return false;
} }
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null) {
te.invalidate();
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
} }

View file

@ -104,7 +104,6 @@ public class BlockReactor extends BlockContainer {
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4); TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null && te instanceof TileEntityReactor) { if (te != null && te instanceof TileEntityReactor) {
WarpDrive.instance.warpCores.removeFromRegistry((TileEntityReactor)te); WarpDrive.instance.warpCores.removeFromRegistry((TileEntityReactor)te);
te.invalidate();
} }
WarpDrive.instance.warpCores.removeDeadCores(); WarpDrive.instance.warpCores.removeDeadCores();

View file

@ -85,12 +85,4 @@ public class BlockShipScanner extends BlockContainer {
return false; return false;
} }
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null) {
te.invalidate();
}
}
} }

View file

@ -25,27 +25,27 @@ public class TileEntityCamera extends TileEntity implements IPeripheral {
"freq" "freq"
}; };
private final int REGISTRY_UPDATE_INTERVAL_SEC = 10; private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 10 * 20;
private int ticks = 0; private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
private int registryUpdateTicks = 20;
private int packetSendTicks = 20; private int packetSendTicks = 20;
@Override @Override
public void updateEntity() { public void updateEntity() {
// Update frequency on clients // Update frequency on clients (recovery mechanism, no need to go too fast)
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
packetSendTicks--; packetSendTicks--;
if (packetSendTicks == 0) { if (packetSendTicks <= 0) {
packetSendTicks = 20 * 5; packetSendTicks = PACKET_SEND_INTERVAL_TICKS;
sendFreqPacket(); sendFreqPacket();
} }
return; } else {
} registryUpdateTicks--;
if (registryUpdateTicks <= 0) {
ticks++; registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS;
if (ticks > 20 * REGISTRY_UPDATE_INTERVAL_SEC) { WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0);
ticks = 0; }
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0);
} }
} }
@ -57,8 +57,15 @@ public class TileEntityCamera extends TileEntity implements IPeripheral {
if (frequency != parFrequency) { if (frequency != parFrequency) {
frequency = parFrequency; frequency = parFrequency;
WarpDrive.debugPrint("" + this + " Frequency set to " + frequency); WarpDrive.debugPrint("" + this + " Frequency set to " + frequency);
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0);
sendFreqPacket();
} }
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0); }
@Override
public void invalidate() {
WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
super.invalidate();
} }
@Override @Override

View file

@ -33,8 +33,8 @@ public class TileEntityLaser extends WarpTE implements IPeripheral {
private int dx, dz, dy; private int dx, dz, dy;
public float yaw, pitch; // laser direction public float yaw, pitch; // laser direction
private int beamFrequency = -1; // beam frequency private int beamFrequency = -1;
private int cameraFrequency = -1; // camera frequency private int cameraFrequency = -1;
private float r, g, b; // beam color (corresponds to frequency) private float r, g, b; // beam color (corresponds to frequency)
public boolean isEmitting = false; public boolean isEmitting = false;
@ -54,22 +54,28 @@ public class TileEntityLaser extends WarpTE implements IPeripheral {
private MovingObjectPosition firstHit = null; private MovingObjectPosition firstHit = null;
private int camUpdateTicks = 20; private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 10 * 20;
private int registryUpdateTicks = 20 * 10; private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
private int registryUpdateTicks = 20;
private int packetSendTicks = 20;
@Override @Override
public void updateEntity() { public void updateEntity() {
if (isWithCamera()) { if (isWithCamera()) {
registryUpdateTicks--; // Update frequency on clients (recovery mechanism, no need to go too fast)
if (registryUpdateTicks == 0 && FMLCommonHandler.instance().getEffectiveSide().isClient()) { if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
registryUpdateTicks = 20 * 10; packetSendTicks--;
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), cameraFrequency, 1); if (packetSendTicks <= 0) {
} packetSendTicks = PACKET_SEND_INTERVAL_TICKS;
sendFreqPacket();
camUpdateTicks--; }
if (camUpdateTicks == 0) { } else {
camUpdateTicks = 20 * 5; // 5 seconds registryUpdateTicks--;
sendFreqPacket(); // send own cam frequency to clients if (registryUpdateTicks <= 0) {
registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS;
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), cameraFrequency, 1);
}
} }
} }
@ -438,6 +444,12 @@ public class TileEntityLaser extends WarpTE implements IPeripheral {
tag.setInteger("cameraFrequency", cameraFrequency); tag.setInteger("cameraFrequency", cameraFrequency);
} }
@Override
public void invalidate() {
WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
super.invalidate();
}
@Override @Override
public void onChunkUnload() { public void onChunkUnload() {
WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord)); WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));