Reduce power flickering by increasing energy polling rate

in testing 84 dense cells could sustain MAX Integer on a FE p2p pair
This commit is contained in:
Salomão
2021-06-27 23:17:26 -03:00
parent 3582582e3f
commit f9c274fb48
2 changed files with 21 additions and 39 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ aechannel=stable
aebuild=7 aebuild=7
aegroup=appeng aegroup=appeng
aebasename=appliedenergistics2 aebasename=appliedenergistics2
trousers=omni-fixes-v43d trousers=omni-fixes-v43h
######################################################### #########################################################
# Versions # # Versions #
+20 -38
View File
@@ -202,23 +202,6 @@ public class EnergyGridCache implements IEnergyGrid
@Override @Override
public void onUpdateTick() public void onUpdateTick()
{ {
if (!providerToRemove.isEmpty() && !ongoingExtractOperation) {
this.providers.removeIf( p -> providerToRemove.contains( p ) );
providerToRemove.clear();
}
if (!requesterToRemove.isEmpty() && !ongoingInjectOperation) {
this.requesters.removeIf( r -> providerToRemove.contains( r ) );
requesterToRemove.clear();
}
if (!providersToAdd.isEmpty() && !ongoingExtractOperation) {
this.providers.addAll(providersToAdd);
providersToAdd.clear();
}
if( !requesterToAdd.isEmpty() && !ongoingInjectOperation){
this.requesters.addAll(requesterToAdd);
requesterToAdd.clear();
}
if( !this.interests.isEmpty() ) if( !this.interests.isEmpty() )
{ {
final double oldPower = this.lastStoredPower; final double oldPower = this.lastStoredPower;
@@ -248,7 +231,7 @@ public class EnergyGridCache implements IEnergyGrid
if( this.drainPerTick > 0.0001 ) if( this.drainPerTick > 0.0001 )
{ {
final double drained = this.extractAEPower( this.getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG ); final double drained = this.extractAEPower( this.getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG );
currentlyHasPower = drained >= this.drainPerTick - 0.001; currentlyHasPower = drained >= this.drainPerTick - 0.001 && this.getStoredPower() > 0;
} }
else else
{ {
@@ -352,6 +335,9 @@ public class EnergyGridCache implements IEnergyGrid
{ {
double extractedPower = 0; double extractedPower = 0;
this.providers.addAll( providersToAdd );
providersToAdd.clear();
final Iterator<IAEPowerStorage> it = this.providers.iterator(); final Iterator<IAEPowerStorage> it = this.providers.iterator();
ongoingExtractOperation = true; ongoingExtractOperation = true;
@@ -361,12 +347,6 @@ public class EnergyGridCache implements IEnergyGrid
{ {
final IAEPowerStorage node = it.next(); final IAEPowerStorage node = it.next();
if ( providerToRemove.contains( node )) {
it.remove();
providerToRemove.remove( node );
continue;
}
final double req = amt - extractedPower; final double req = amt - extractedPower;
final double newPower = node.extractAEPower( req, mode, PowerMultiplier.ONE ); final double newPower = node.extractAEPower( req, mode, PowerMultiplier.ONE );
extractedPower += newPower; extractedPower += newPower;
@@ -376,7 +356,10 @@ public class EnergyGridCache implements IEnergyGrid
it.remove(); it.remove();
} }
} }
} finally { } finally
{
providers.removeIf( p -> providerToRemove.contains( p ) );
this.providerToRemove.clear();
ongoingExtractOperation = false; ongoingExtractOperation = false;
} }
@@ -401,6 +384,9 @@ public class EnergyGridCache implements IEnergyGrid
{ {
final double originalAmount = amt; final double originalAmount = amt;
this.requesters.addAll( requesterToAdd );
requesterToAdd.clear();
final Iterator<IAEPowerStorage> it = this.requesters.iterator(); final Iterator<IAEPowerStorage> it = this.requesters.iterator();
ongoingInjectOperation = true; ongoingInjectOperation = true;
@@ -410,12 +396,6 @@ public class EnergyGridCache implements IEnergyGrid
{ {
final IAEPowerStorage node = it.next(); final IAEPowerStorage node = it.next();
if ( requesterToRemove.contains( node )) {
it.remove();
requesterToRemove.remove( node );
continue;
}
amt = node.injectAEPower( amt, mode ); amt = node.injectAEPower( amt, mode );
if( amt > 0 && mode == Actionable.MODULATE ) if( amt > 0 && mode == Actionable.MODULATE )
@@ -425,6 +405,8 @@ public class EnergyGridCache implements IEnergyGrid
} }
} finally } finally
{ {
requesters.removeIf( r -> requesterToRemove.contains( r ) );
this.requesterToRemove.clear();
ongoingInjectOperation = false; ongoingInjectOperation = false;
} }
@@ -505,11 +487,7 @@ public class EnergyGridCache implements IEnergyGrid
@Override @Override
public double getStoredPower() public double getStoredPower()
{ {
if( this.availableTicksSinceUpdate > 2 ) this.refreshPower();
{
this.refreshPower();
}
return Math.max( 0.0, this.globalAvailablePower ); return Math.max( 0.0, this.globalAvailablePower );
} }
@@ -810,8 +788,12 @@ public class EnergyGridCache implements IEnergyGrid
if( this.stored < 0.01 ) if( this.stored < 0.01 )
{ {
EnergyGridCache.this.ticksSinceHasPowerChange = 0; refreshPower();
EnergyGridCache.this.publicPowerState( false, EnergyGridCache.this.myGrid ); if (globalAvailablePower < MAX_BUFFER_STORAGE - 0.001)
{
EnergyGridCache.this.ticksSinceHasPowerChange = 0;
EnergyGridCache.this.publicPowerState( false, EnergyGridCache.this.myGrid );
}
} }
} }
} }