From f295669e6e58fd4792a1ae3683d720b6cf93fd84 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Wed, 5 Feb 2014 22:36:10 -0600 Subject: [PATCH] TESR should use less CPU when no-op. onInventoryChange for FZ. Networks without batteries can store up to 1000 AE. Fixed a bug that cause energy to spiral out of control and go infinite. Fixed a crash with storage buses and fluids. --- client/render/TESRWrapper.java | 52 ++++++++++--------- .../ContainerMEMonitorable.java | 3 -- integration/modules/FZ.java | 8 ++- me/cache/EnergyGridCache.java | 27 +++++----- parts/AEBasePart.java | 6 +++ parts/CableBusContainer.java | 17 +++++- parts/automation/PartLevelEmitter.java | 9 +++- parts/misc/PartCableAnchor.java | 6 +++ parts/misc/PartStorageBus.java | 11 ++-- parts/reporting/PartStorageMonitor.java | 6 +++ tile/AEBaseTile.java | 5 ++ tile/grindstone/TileCrank.java | 9 +++- tile/misc/TileCharger.java | 6 +++ tile/networking/TileCableBus.java | 7 +++ 14 files changed, 121 insertions(+), 51 deletions(-) diff --git a/client/render/TESRWrapper.java b/client/render/TESRWrapper.java index 085c83161..13a2e077c 100644 --- a/client/render/TESRWrapper.java +++ b/client/render/TESRWrapper.java @@ -28,39 +28,43 @@ public class TESRWrapper extends TileEntitySpecialRenderer @Override final public void renderTileEntityAt(TileEntity te, double x, double y, double z, float f) { - if ( Math.abs( x ) > MAX_DISTANCE || Math.abs( y ) > MAX_DISTANCE || Math.abs( z ) > MAX_DISTANCE ) - return; - - try + if ( te instanceof AEBaseTile ) { Block b = te.getBlockType(); - Tessellator tess = Tessellator.instance; - if ( tess.isDrawing ) - return; - if ( b instanceof AEBaseBlock && te instanceof AEBaseTile ) + if ( b instanceof AEBaseBlock && ((AEBaseTile) te).requiresTESR() ) { + if ( Math.abs( x ) > MAX_DISTANCE || Math.abs( y ) > MAX_DISTANCE || Math.abs( z ) > MAX_DISTANCE ) + return; - GL11.glPushMatrix(); - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - - rbinstance.blockAccess = te.worldObj; - blkRender.renderTile( (AEBaseBlock) b, (AEBaseTile) te, tess, x, y, z, f, rbinstance ); + Tessellator tess = Tessellator.instance; if ( tess.isDrawing ) - throw new RuntimeException( "Error durring rendering." ); + return; + + try + { + GL11.glPushMatrix(); + GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + + rbinstance.blockAccess = te.worldObj; + blkRender.renderTile( (AEBaseBlock) b, (AEBaseTile) te, tess, x, y, z, f, rbinstance ); + + if ( tess.isDrawing ) + throw new RuntimeException( "Error durring rendering." ); + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } + catch (Throwable t) + { + FMLLog.severe( "Hi, Looks like there was a crash while rendering something..." ); + t.printStackTrace(); + FMLLog.severe( "MC will now crash ( probobly )!" ); + throw new RuntimeException( t ); + } - GL11.glPopAttrib(); - GL11.glPopMatrix(); } } - catch (Throwable t) - { - FMLLog.severe( "Hi, Looks like there was a crash while rendering something..." ); - t.printStackTrace(); - FMLLog.severe( "MC will now crash ( probobly )!" ); - throw new RuntimeException( t ); - } - } } diff --git a/container/implementations/ContainerMEMonitorable.java b/container/implementations/ContainerMEMonitorable.java index dfd91fa1e..347672d6f 100644 --- a/container/implementations/ContainerMEMonitorable.java +++ b/container/implementations/ContainerMEMonitorable.java @@ -134,18 +134,15 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate(); IItemList monitorCache = monitor.getStorageList(); - int items = 0; for (IAEItemStack send : monitorCache) { if ( piu.getLength() > 20000 ) { - items = 0; Packet p = piu.getPacket(); PacketDispatcher.sendPacketToPlayer( p, (Player) c ); piu = new PacketMEInventoryUpdate(); } - items++; piu.appendItem( send ); } diff --git a/integration/modules/FZ.java b/integration/modules/FZ.java index 0625cdeed..61ef0fa6c 100644 --- a/integration/modules/FZ.java +++ b/integration/modules/FZ.java @@ -64,7 +64,6 @@ public class FZ implements IFZ, IIntegrationModule { try { - if ( day_BarrelClass.isInstance( te ) ) return (Integer) day_getMaxSize.invoke( te ); else @@ -87,7 +86,6 @@ public class FZ implements IFZ, IIntegrationModule { try { - if ( day_BarrelClass.isInstance( te ) ) return (Integer) day_getItemCount.invoke( te ); else @@ -110,11 +108,12 @@ public class FZ implements IFZ, IIntegrationModule { try { - if ( day_BarrelClass.isInstance( te ) ) day_item.set( te, input == null ? null : input.copy() ); else item.set( te, input == null ? null : input.copy() ); + + te.onInventoryChanged(); } catch (IllegalArgumentException e) { @@ -129,13 +128,12 @@ public class FZ implements IFZ, IIntegrationModule { try { - if ( day_BarrelClass.isInstance( te ) ) day_setItemCount.invoke( te, max ); else setItemCount.invoke( te, max ); - te.worldObj.markBlockForUpdate( te.xCoord, te.yCoord, te.zCoord ); + te.onInventoryChanged(); } catch (IllegalAccessException e) { diff --git a/me/cache/EnergyGridCache.java b/me/cache/EnergyGridCache.java index bc9dd1f8e..8f4e3436e 100644 --- a/me/cache/EnergyGridCache.java +++ b/me/cache/EnergyGridCache.java @@ -68,6 +68,11 @@ public class EnergyGridCache implements IEnergyGrid IAEPowerStorage lastRequestor; Set requesters = new LinkedHashSet(); + private double buffer() + { + return providers.isEmpty() ? 1000.0 : 0.0; + } + private IAEPowerStorage getFirstRequestor() { if ( lastRequestor == null ) @@ -183,7 +188,7 @@ public class EnergyGridCache implements IEnergyGrid extra = i; } - return i; + return Math.max( 0.0, i - buffer() ); } Set seen = new HashSet(); @@ -299,8 +304,8 @@ public class EnergyGridCache implements IEnergyGrid publicPowerState( false, myGrid ); availableTicksSinceUpdate++; - if ( extra > 32 ) - injectPower( 0.0, Actionable.MODULATE ); + // if ( extra > 32 ) + // injectPower( 0.0, Actionable.MODULATE ); } private void publicPowerState(boolean newState, IGrid grid) @@ -354,7 +359,10 @@ public class EnergyGridCache implements IEnergyGrid return extractedPower; } else - extractedPower += doExtract( extractedPower, amt ); + { + extra = 0; + extractedPower = doExtract( extractedPower, amt ); + } // got more then we wanted? if ( extractedPower > amt ) @@ -379,8 +387,6 @@ public class EnergyGridCache implements IEnergyGrid private double doExtract(double extractedPower, double amt) { - extra = 0; - while (extractedPower < amt && !providers.isEmpty()) { IAEPowerStorage node = getFirstProvider(); @@ -435,8 +441,7 @@ public class EnergyGridCache implements IEnergyGrid return avgDrainPerTick;/* * double out = 0; * - * for (double x : totalDrainPastTicks) out += - * x; + * for (double x : totalDrainPastTicks) out += x; * * return out / totalDrainPastTicks.length; */ @@ -448,11 +453,9 @@ public class EnergyGridCache implements IEnergyGrid return avgInjectionPerTick;/* * double out = 0; * - * for (double x : totalInjectionPastTicks) - * out += x; + * for (double x : totalInjectionPastTicks) out += x; * - * return out / - * totalInjectionPastTicks.length; + * return out / totalInjectionPastTicks.length; */ } diff --git a/parts/AEBasePart.java b/parts/AEBasePart.java index 6689d0118..39c0dffb6 100644 --- a/parts/AEBasePart.java +++ b/parts/AEBasePart.java @@ -324,4 +324,10 @@ public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradea { host.markForSave(); } + + @Override + public boolean requireDynamicRender() + { + return false; + } } \ No newline at end of file diff --git a/parts/CableBusContainer.java b/parts/CableBusContainer.java index cb139ba6d..5eb5525b9 100644 --- a/parts/CableBusContainer.java +++ b/parts/CableBusContainer.java @@ -57,6 +57,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer public IPartHost tcb; boolean inWorld = false; + public boolean requiresDynamicRender = false; public void setHost(IPartHost host) { @@ -76,6 +77,17 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer return sides[side.ordinal()]; } + public void updateDynamicRender() + { + requiresDynamicRender = false; + for (ForgeDirection s : ForgeDirection.VALID_DIRECTIONS) + { + IPart p = getPart( s ); + if ( p != null ) + requiresDynamicRender = requiresDynamicRender || p.requireDynamicRender(); + } + } + @Override public void removePart(ForgeDirection side, boolean supressUpdate) { @@ -94,6 +106,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer if ( !supressUpdate ) { + updateDynamicRender(); updateConnections(); markForUpdate(); PartChanged(); @@ -262,6 +275,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer } } + updateDynamicRender(); updateConnections(); markForUpdate(); PartChanged(); @@ -543,7 +557,8 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer if ( part != null ) { setSide( s ); - BusCollisionHelper bch = new BusCollisionHelper( boxes, BusRenderHelper.instance.ax, BusRenderHelper.instance.ay, BusRenderHelper.instance.az, null, true ); + BusCollisionHelper bch = new BusCollisionHelper( boxes, BusRenderHelper.instance.ax, BusRenderHelper.instance.ay, + BusRenderHelper.instance.az, null, true ); part.getBoxes( bch ); } } diff --git a/parts/automation/PartLevelEmitter.java b/parts/automation/PartLevelEmitter.java index d327633fe..e6c1cd995 100644 --- a/parts/automation/PartLevelEmitter.java +++ b/parts/automation/PartLevelEmitter.java @@ -223,7 +223,14 @@ public class PartLevelEmitter extends PartUpgradeable implements IStackWatcherHo @Override public boolean isValid(Object effectiveGrid) { - return getGridNode().getGrid() == effectiveGrid; + try + { + return proxy.getGrid() == effectiveGrid; + } + catch (GridAccessException e) + { + return false; + } } @Override diff --git a/parts/misc/PartCableAnchor.java b/parts/misc/PartCableAnchor.java index f66f7e6ff..931e4bfdb 100644 --- a/parts/misc/PartCableAnchor.java +++ b/parts/misc/PartCableAnchor.java @@ -72,6 +72,12 @@ public class PartCableAnchor implements IPart return is; } + @Override + public boolean requireDynamicRender() + { + return false; + } + @Override public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer) { diff --git a/parts/misc/PartStorageBus.java b/parts/misc/PartStorageBus.java index a5ac7f893..2492d9fb4 100644 --- a/parts/misc/PartStorageBus.java +++ b/parts/misc/PartStorageBus.java @@ -353,10 +353,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC @Override public List getCellArray(StorageChannel channel) { - IMEInventoryHandler out = proxy.isActive() ? getHandler() : null; - if ( out == null ) - return Arrays.asList( new IMEInventoryHandler[] {} ); - return Arrays.asList( new IMEInventoryHandler[] { out } ); + if ( channel == StorageChannel.ITEMS ) + { + IMEInventoryHandler out = proxy.isActive() ? getHandler() : null; + if ( out != null ) + return Arrays.asList( new IMEInventoryHandler[] { out } ); + } + return Arrays.asList( new IMEInventoryHandler[] {} ); } @Override diff --git a/parts/reporting/PartStorageMonitor.java b/parts/reporting/PartStorageMonitor.java index 2cb0fdc0a..484aa7a25 100644 --- a/parts/reporting/PartStorageMonitor.java +++ b/parts/reporting/PartStorageMonitor.java @@ -162,6 +162,12 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit frontSolid = CableBusTextures.PartStorageMonitor_Solid; } + @Override + public boolean requireDynamicRender() + { + return true; + } + @Override public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer) { diff --git a/tile/AEBaseTile.java b/tile/AEBaseTile.java index 13d45081e..081b50658 100644 --- a/tile/AEBaseTile.java +++ b/tile/AEBaseTile.java @@ -346,4 +346,9 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile super.onInventoryChanged(); } + public boolean requiresTESR() + { + return false; + } + } diff --git a/tile/grindstone/TileCrank.java b/tile/grindstone/TileCrank.java index bad5cc62b..22800dc64 100644 --- a/tile/grindstone/TileCrank.java +++ b/tile/grindstone/TileCrank.java @@ -116,7 +116,8 @@ public class TileCrank extends AEBaseTile implements ICustomCollision double xOff = -0.15 * getUp().offsetX; double yOff = -0.15 * getUp().offsetY; double zOff = -0.15 * getUp().offsetZ; - return Arrays.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85 ) } ); + return Arrays + .asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85 ) } ); } @Override @@ -128,4 +129,10 @@ public class TileCrank extends AEBaseTile implements ICustomCollision out.add( AxisAlignedBB.getAABBPool().getAABB( xOff + (double) 0.15, yOff + (double) 0.15, zOff + (double) 0.15,// ahh xOff + (double) 0.85, yOff + (double) 0.85, zOff + (double) 0.85 ) ); } + + @Override + public boolean requiresTESR() + { + return true; + } } diff --git a/tile/misc/TileCharger.java b/tile/misc/TileCharger.java index d19b9a86c..bfcb7d37f 100644 --- a/tile/misc/TileCharger.java +++ b/tile/misc/TileCharger.java @@ -247,4 +247,10 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable } } + @Override + public boolean requiresTESR() + { + return true; + } + } diff --git a/tile/networking/TileCableBus.java b/tile/networking/TileCableBus.java index 5594ab2e9..05c886f47 100644 --- a/tile/networking/TileCableBus.java +++ b/tile/networking/TileCableBus.java @@ -298,4 +298,11 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl { return cb.isEmpty(); } + + @Override + public boolean requiresTESR() + { + return cb.requiresDynamicRender; + } + }