From f2921db45c744503fc03aedee851bc675a0a7528 Mon Sep 17 00:00:00 2001 From: LemADEC Date: Sun, 10 Aug 2014 16:47:26 +0200 Subject: [PATCH] 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 --- src/cr0s/WarpDrive/WarpDrive.java | 2 +- .../WarpDrive/machines/BlockAirGenerator.java | 10 ----- src/cr0s/WarpDrive/machines/BlockCamera.java | 10 ++--- .../WarpDrive/machines/BlockCloakingCoil.java | 10 ----- .../machines/BlockCloakingDeviceCore.java | 2 - src/cr0s/WarpDrive/machines/BlockLift.java | 8 ---- src/cr0s/WarpDrive/machines/BlockMonitor.java | 1 - .../machines/BlockParticleBooster.java | 10 ----- src/cr0s/WarpDrive/machines/BlockRadar.java | 10 ----- src/cr0s/WarpDrive/machines/BlockReactor.java | 1 - .../WarpDrive/machines/BlockShipScanner.java | 8 ---- .../WarpDrive/machines/TileEntityCamera.java | 37 ++++++++++------- .../WarpDrive/machines/TileEntityLaser.java | 40 ++++++++++++------- 13 files changed, 54 insertions(+), 95 deletions(-) diff --git a/src/cr0s/WarpDrive/WarpDrive.java b/src/cr0s/WarpDrive/WarpDrive.java index c3592c94..c6b750b5 100644 --- a/src/cr0s/WarpDrive/WarpDrive.java +++ b/src/cr0s/WarpDrive/WarpDrive.java @@ -148,7 +148,7 @@ public class WarpDrive implements LoadingCallback { return; } if (WarpDriveConfig.debugMode) { - System.out.println(out); + System.out.println((FMLCommonHandler.instance().getEffectiveSide().isClient() ? "Client ":"Server ") + out); } } diff --git a/src/cr0s/WarpDrive/machines/BlockAirGenerator.java b/src/cr0s/WarpDrive/machines/BlockAirGenerator.java index 4098f102..57b80b47 100644 --- a/src/cr0s/WarpDrive/machines/BlockAirGenerator.java +++ b/src/cr0s/WarpDrive/machines/BlockAirGenerator.java @@ -97,14 +97,4 @@ public class BlockAirGenerator extends BlockContainer 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); - } } diff --git a/src/cr0s/WarpDrive/machines/BlockCamera.java b/src/cr0s/WarpDrive/machines/BlockCamera.java index 9035ef81..7db7e8bd 100644 --- a/src/cr0s/WarpDrive/machines/BlockCamera.java +++ b/src/cr0s/WarpDrive/machines/BlockCamera.java @@ -44,10 +44,10 @@ public class BlockCamera extends BlockContainer { } @Override - public TileEntity createNewTileEntity(World var1) { + public TileEntity createNewTileEntity(World parWorld) { return new TileEntityCamera(); } - + /** * Returns the quantity of items to drop on block destruction. */ @@ -55,12 +55,12 @@ public class BlockCamera extends BlockContainer { public int quantityDropped(Random par1Random) { return 1; } - + /** * Returns the ID of the items to drop on destruction. */ @Override - public int idDropped(int par1, Random par2Random, int par3) { + public int idDropped(int par1, Random par2Random, int par3) { return this.blockID; } @@ -75,7 +75,7 @@ public class BlockCamera extends BlockContainer { // Get camera frequency 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(); CamRegistryItem cam = WarpDrive.instance.cams.getCamByFrequency(par1World, frequency); diff --git a/src/cr0s/WarpDrive/machines/BlockCloakingCoil.java b/src/cr0s/WarpDrive/machines/BlockCloakingCoil.java index 1ed9beca..08d175e6 100644 --- a/src/cr0s/WarpDrive/machines/BlockCloakingCoil.java +++ b/src/cr0s/WarpDrive/machines/BlockCloakingCoil.java @@ -64,14 +64,4 @@ public class BlockCloakingCoil extends Block { public int idDropped(int par1, Random par2Random, int par3) { 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); - } } diff --git a/src/cr0s/WarpDrive/machines/BlockCloakingDeviceCore.java b/src/cr0s/WarpDrive/machines/BlockCloakingDeviceCore.java index df910706..e1feb898 100644 --- a/src/cr0s/WarpDrive/machines/BlockCloakingDeviceCore.java +++ b/src/cr0s/WarpDrive/machines/BlockCloakingDeviceCore.java @@ -91,8 +91,6 @@ public class BlockCloakingDeviceCore extends BlockContainer { if (te != null && te instanceof TileEntityCloakingDeviceCore) { ((TileEntityCloakingDeviceCore)te).isEnabled = false; ((TileEntityCloakingDeviceCore)te).disableCloakingField(); - - te.invalidate(); } super.breakBlock(par1World, par2, par3, par4, par5, par6); diff --git a/src/cr0s/WarpDrive/machines/BlockLift.java b/src/cr0s/WarpDrive/machines/BlockLift.java index abca2b73..2266dacc 100644 --- a/src/cr0s/WarpDrive/machines/BlockLift.java +++ b/src/cr0s/WarpDrive/machines/BlockLift.java @@ -96,12 +96,4 @@ public class BlockLift extends BlockContainer 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(); - } - } } \ No newline at end of file diff --git a/src/cr0s/WarpDrive/machines/BlockMonitor.java b/src/cr0s/WarpDrive/machines/BlockMonitor.java index 08a563e2..e59ce80c 100644 --- a/src/cr0s/WarpDrive/machines/BlockMonitor.java +++ b/src/cr0s/WarpDrive/machines/BlockMonitor.java @@ -75,7 +75,6 @@ public class BlockMonitor extends BlockContainer { if (te != null && te instanceof TileEntityMonitor && (par5EntityPlayer.getHeldItem() == null)) { int frequency = ((TileEntityMonitor)te).getFrequency(); - WarpDrive.instance.cams.removeDeadCams(par1World); CamRegistryItem cam = WarpDrive.instance.cams.getCamByFrequency(par1World, frequency); if (cam == null) { par5EntityPlayer.addChatMessage(getLocalizedName() + " Frequency '" + frequency + "' is invalid or camera is too far!"); diff --git a/src/cr0s/WarpDrive/machines/BlockParticleBooster.java b/src/cr0s/WarpDrive/machines/BlockParticleBooster.java index 0b9e7a2f..ce157acb 100644 --- a/src/cr0s/WarpDrive/machines/BlockParticleBooster.java +++ b/src/cr0s/WarpDrive/machines/BlockParticleBooster.java @@ -92,14 +92,4 @@ public class BlockParticleBooster extends BlockContainer { 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); - } } \ No newline at end of file diff --git a/src/cr0s/WarpDrive/machines/BlockRadar.java b/src/cr0s/WarpDrive/machines/BlockRadar.java index f9cd6d93..4f00dd2f 100644 --- a/src/cr0s/WarpDrive/machines/BlockRadar.java +++ b/src/cr0s/WarpDrive/machines/BlockRadar.java @@ -99,14 +99,4 @@ public class BlockRadar extends BlockContainer 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); - } } diff --git a/src/cr0s/WarpDrive/machines/BlockReactor.java b/src/cr0s/WarpDrive/machines/BlockReactor.java index a8936fe2..03b4ace8 100644 --- a/src/cr0s/WarpDrive/machines/BlockReactor.java +++ b/src/cr0s/WarpDrive/machines/BlockReactor.java @@ -104,7 +104,6 @@ public class BlockReactor extends BlockContainer { TileEntity te = par1World.getBlockTileEntity(par2, par3, par4); if (te != null && te instanceof TileEntityReactor) { WarpDrive.instance.warpCores.removeFromRegistry((TileEntityReactor)te); - te.invalidate(); } WarpDrive.instance.warpCores.removeDeadCores(); diff --git a/src/cr0s/WarpDrive/machines/BlockShipScanner.java b/src/cr0s/WarpDrive/machines/BlockShipScanner.java index d37d9737..f2b99b4b 100644 --- a/src/cr0s/WarpDrive/machines/BlockShipScanner.java +++ b/src/cr0s/WarpDrive/machines/BlockShipScanner.java @@ -85,12 +85,4 @@ public class BlockShipScanner extends BlockContainer { 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(); - } - } } \ No newline at end of file diff --git a/src/cr0s/WarpDrive/machines/TileEntityCamera.java b/src/cr0s/WarpDrive/machines/TileEntityCamera.java index 17572ce3..90b52404 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityCamera.java +++ b/src/cr0s/WarpDrive/machines/TileEntityCamera.java @@ -25,27 +25,27 @@ public class TileEntityCamera extends TileEntity implements IPeripheral { "freq" }; - private final int REGISTRY_UPDATE_INTERVAL_SEC = 10; - private int ticks = 0; + private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 10 * 20; + private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20; + private int registryUpdateTicks = 20; private int packetSendTicks = 20; @Override public void updateEntity() { - // Update frequency on clients + // Update frequency on clients (recovery mechanism, no need to go too fast) if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { packetSendTicks--; - if (packetSendTicks == 0) { - packetSendTicks = 20 * 5; + if (packetSendTicks <= 0) { + packetSendTicks = PACKET_SEND_INTERVAL_TICKS; sendFreqPacket(); } - return; - } - - ticks++; - if (ticks > 20 * REGISTRY_UPDATE_INTERVAL_SEC) { - ticks = 0; - WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0); + } else { + registryUpdateTicks--; + if (registryUpdateTicks <= 0) { + registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS; + WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0); + } } } @@ -57,16 +57,23 @@ public class TileEntityCamera extends TileEntity implements IPeripheral { if (frequency != parFrequency) { frequency = parFrequency; 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 public void onChunkUnload() { WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord)); super.onChunkUnload(); } - + @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); diff --git a/src/cr0s/WarpDrive/machines/TileEntityLaser.java b/src/cr0s/WarpDrive/machines/TileEntityLaser.java index 3459622b..29f8715f 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityLaser.java +++ b/src/cr0s/WarpDrive/machines/TileEntityLaser.java @@ -33,8 +33,8 @@ public class TileEntityLaser extends WarpTE implements IPeripheral { private int dx, dz, dy; public float yaw, pitch; // laser direction - private int beamFrequency = -1; // beam frequency - private int cameraFrequency = -1; // camera frequency + private int beamFrequency = -1; + private int cameraFrequency = -1; private float r, g, b; // beam color (corresponds to frequency) public boolean isEmitting = false; @@ -54,22 +54,28 @@ public class TileEntityLaser extends WarpTE implements IPeripheral { private MovingObjectPosition firstHit = null; - private int camUpdateTicks = 20; - private int registryUpdateTicks = 20 * 10; + private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 10 * 20; + private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20; + + private int registryUpdateTicks = 20; + private int packetSendTicks = 20; @Override public void updateEntity() { if (isWithCamera()) { - registryUpdateTicks--; - if (registryUpdateTicks == 0 && FMLCommonHandler.instance().getEffectiveSide().isClient()) { - registryUpdateTicks = 20 * 10; - WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), cameraFrequency, 1); - } - - camUpdateTicks--; - if (camUpdateTicks == 0) { - camUpdateTicks = 20 * 5; // 5 seconds - sendFreqPacket(); // send own cam frequency to clients + // Update frequency on clients (recovery mechanism, no need to go too fast) + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { + packetSendTicks--; + if (packetSendTicks <= 0) { + packetSendTicks = PACKET_SEND_INTERVAL_TICKS; + sendFreqPacket(); + } + } else { + registryUpdateTicks--; + if (registryUpdateTicks <= 0) { + registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS; + WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), cameraFrequency, 1); + } } } @@ -437,6 +443,12 @@ public class TileEntityLaser extends WarpTE implements IPeripheral { tag.setInteger("beamFrequency", beamFrequency); tag.setInteger("cameraFrequency", cameraFrequency); } + + @Override + public void invalidate() { + WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord)); + super.invalidate(); + } @Override public void onChunkUnload() {