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