Performance improvements for the energygrid (#3051)
* Performance improvements for the energygrid Reworked the old recursive approach to a queue based loop. Extract will try to prefer the next grid with the hightest amount of stored energy. Inject will try to prefer the grid with the lowest percentage stored. Other operations are first come, first serve. * Added a local buffer storage to EnergyGrid This replaces the old not really working buffer with a special IAEPowerStorage acting as buffer/proxy for the local energy demand as well as temporary overflow should something provide more energy than requested. Currently it set to hold a maximum of 200 AE (+ optional overflow until consumed). It will only be used locally, no other grid can use it to avoid starving the neighbor grids before finding a energy cell. * Fixes IExternalPowerSink All implementations currently depend on the network demand being a valid source, which might not be true. Further it can cause the sink to iterate the network twice (demand and inject) and both again for simulate and modulate. Also it did not return the actual leftover amount instead of relying on the demand matching it. * Minor fixes related to removing nodes from a grid. The grid did remove IStackWatcherHost not IEnergyWatcherHost, this was fine for AE2 as only level emitters use it and they implement both. But not for potential addons. Also they would potentually not being removed as the are indexed by the gridnodes not the machine. Fixes #1004
This commit is contained in:
@@ -29,6 +29,7 @@ import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.events.MENetworkControllerChange;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
@@ -137,7 +138,9 @@ public class TileController extends AENetworkPowerTile
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getEnergy().getEnergyDemand( 8000 );
|
||||
final IEnergyGrid grid = this.getProxy().getEnergy();
|
||||
|
||||
return grid.getEnergyDemand( maxReceived );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
@@ -151,12 +154,10 @@ public class TileController extends AENetworkPowerTile
|
||||
{
|
||||
try
|
||||
{
|
||||
final double ret = this.getProxy().getEnergy().injectPower( power, mode );
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
final IEnergyGrid grid = this.getProxy().getEnergy();
|
||||
final double leftOver = grid.injectPower( power, mode );
|
||||
|
||||
return leftOver;
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
|
||||
@@ -69,6 +69,7 @@ public class TileEnergyAcceptor extends AENetworkPowerTile
|
||||
try
|
||||
{
|
||||
final IEnergyGrid grid = this.getProxy().getEnergy();
|
||||
|
||||
return grid.getEnergyDemand( maxRequired );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
@@ -84,11 +85,8 @@ public class TileEnergyAcceptor extends AENetworkPowerTile
|
||||
{
|
||||
final IEnergyGrid grid = this.getProxy().getEnergy();
|
||||
final double leftOver = grid.injectPower( power, mode );
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
return leftOver;
|
||||
}
|
||||
return 0.0;
|
||||
|
||||
return leftOver;
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user