Minor power graph optimization
This commit is contained in:
@@ -87,6 +87,8 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
transient float optionalEfficiency;
|
transient float optionalEfficiency;
|
||||||
/** The efficiency this block *would* have if shouldConsume() returned true. */
|
/** The efficiency this block *would* have if shouldConsume() returned true. */
|
||||||
transient float potentialEfficiency;
|
transient float potentialEfficiency;
|
||||||
|
/** Whether there are any consumers (aside from power) that have efficiency > 0. */
|
||||||
|
transient boolean shouldConsumePower;
|
||||||
|
|
||||||
transient float healSuppressionTime = -1f;
|
transient float healSuppressionTime = -1f;
|
||||||
transient float lastHealTime = -120f * 10f;
|
transient float lastHealTime = -120f * 10f;
|
||||||
@@ -1773,6 +1775,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
if(!block.hasConsumers || cheating()){
|
if(!block.hasConsumers || cheating()){
|
||||||
potentialEfficiency = enabled && productionValid() ? 1f : 0f;
|
potentialEfficiency = enabled && productionValid() ? 1f : 0f;
|
||||||
efficiency = optionalEfficiency = shouldConsume() ? potentialEfficiency : 0f;
|
efficiency = optionalEfficiency = shouldConsume() ? potentialEfficiency : 0f;
|
||||||
|
shouldConsumePower = true;
|
||||||
updateEfficiencyMultiplier();
|
updateEfficiencyMultiplier();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1780,6 +1783,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
//disabled -> nothing works
|
//disabled -> nothing works
|
||||||
if(!enabled){
|
if(!enabled){
|
||||||
potentialEfficiency = efficiency = optionalEfficiency = 0f;
|
potentialEfficiency = efficiency = optionalEfficiency = 0f;
|
||||||
|
shouldConsumePower = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1789,10 +1793,17 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
|
|
||||||
//assume efficiency is 1 for the calculations below
|
//assume efficiency is 1 for the calculations below
|
||||||
efficiency = optionalEfficiency = 1f;
|
efficiency = optionalEfficiency = 1f;
|
||||||
|
shouldConsumePower = true;
|
||||||
|
|
||||||
//first pass: get the minimum efficiency of any consumer
|
//first pass: get the minimum efficiency of any consumer
|
||||||
for(var cons : block.nonOptionalConsumers){
|
for(var cons : block.nonOptionalConsumers){
|
||||||
minEfficiency = Math.min(minEfficiency, cons.efficiency(self()));
|
float result = cons.efficiency(self());
|
||||||
|
|
||||||
|
if(cons != block.consPower && result <= 0.0000001f){
|
||||||
|
shouldConsumePower = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
minEfficiency = Math.min(minEfficiency, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
//same for optionals
|
//same for optionals
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import arc.math.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.world.consumers.*;
|
|
||||||
|
|
||||||
public class PowerGraph{
|
public class PowerGraph{
|
||||||
private static final Queue<Building> queue = new Queue<>();
|
private static final Queue<Building> queue = new Queue<>();
|
||||||
@@ -109,7 +108,7 @@ public class PowerGraph{
|
|||||||
for(int i = 0; i < consumers.size; i++){
|
for(int i = 0; i < consumers.size; i++){
|
||||||
var consumer = items[i];
|
var consumer = items[i];
|
||||||
var consumePower = consumer.block.consPower;
|
var consumePower = consumer.block.consPower;
|
||||||
if(otherConsumersAreValid(consumer, consumePower)){
|
if(consumer.shouldConsumePower){
|
||||||
powerNeeded += consumePower.requestedPower(consumer) * consumer.delta();
|
powerNeeded += consumePower.requestedPower(consumer) * consumer.delta();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,7 +200,7 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//valid consumers get power as usual
|
//valid consumers get power as usual
|
||||||
if(otherConsumersAreValid(consumer, cons)){
|
if(consumer.shouldConsumePower){
|
||||||
consumer.power.status = coverage;
|
consumer.power.status = coverage;
|
||||||
}else{ //invalid consumers get an estimate, if they were to activate
|
}else{ //invalid consumers get an estimate, if they were to activate
|
||||||
consumer.power.status = Math.min(1, produced / (needed + cons.usage * consumer.delta()));
|
consumer.power.status = Math.min(1, produced / (needed + cons.usage * consumer.delta()));
|
||||||
@@ -381,24 +380,6 @@ public class PowerGraph{
|
|||||||
return graphID;
|
return graphID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private boolean otherConsumersAreValid(Building build, Consume consumePower){
|
|
||||||
if(!build.enabled) return false;
|
|
||||||
|
|
||||||
float f = build.efficiency;
|
|
||||||
//hack so liquids output positive efficiency values
|
|
||||||
build.efficiency = 1f;
|
|
||||||
for(Consume cons : build.block.nonOptionalConsumers){
|
|
||||||
//TODO fix this properly
|
|
||||||
if(cons != consumePower && cons.efficiency(build) <= 0.0000001f){
|
|
||||||
build.efficiency = f;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
build.efficiency = f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "PowerGraph{" +
|
return "PowerGraph{" +
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ org.gradle.caching=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
archash=7a6694c636
|
archash=7d6e89dffd
|
||||||
|
|||||||
Reference in New Issue
Block a user