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.
This commit is contained in:
AlgorithmX2 2014-02-05 22:36:10 -06:00
parent e79e866417
commit f295669e6e
14 changed files with 121 additions and 51 deletions

View file

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

View file

@ -134,18 +134,15 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito
PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
IItemList<IAEItemStack> 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 );
}

View file

@ -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)
{

View file

@ -68,6 +68,11 @@ public class EnergyGridCache implements IEnergyGrid
IAEPowerStorage lastRequestor;
Set<IAEPowerStorage> 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<IEnergyGrid> 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;
*/
}

View file

@ -324,4 +324,10 @@ public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradea
{
host.markForSave();
}
@Override
public boolean requireDynamicRender()
{
return false;
}
}

View file

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

View file

@ -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

View file

@ -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)
{

View file

@ -353,10 +353,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
@Override
public List<IMEInventoryHandler> 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

View file

@ -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)
{

View file

@ -346,4 +346,9 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile
super.onInventoryChanged();
}
public boolean requiresTESR()
{
return false;
}
}

View file

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

View file

@ -247,4 +247,10 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
}
}
@Override
public boolean requiresTESR()
{
return true;
}
}

View file

@ -298,4 +298,11 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl
{
return cb.isEmpty();
}
@Override
public boolean requiresTESR()
{
return cb.requiresDynamicRender;
}
}