Simplified power logic (#261)
* Simplified power logic * Made the requested changes
This commit is contained in:
@@ -5,7 +5,6 @@ import com.badlogic.gdx.utils.IntSet;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
import static io.anuke.mindustry.Vars.threads;
|
||||
|
||||
@@ -39,37 +38,27 @@ public class PowerGraph{
|
||||
lastFrameUpdated = threads.getFrameID();
|
||||
|
||||
float totalInput = 0f;
|
||||
|
||||
for(Tile producer : producers){
|
||||
totalInput += producer.entity.power.amount;
|
||||
}
|
||||
|
||||
float maxOutput = 0f;
|
||||
for(Tile consumer : consumers){
|
||||
maxOutput += consumer.block().powerCapacity - consumer.entity.power.amount;
|
||||
}
|
||||
|
||||
if (totalInput <= 0.0001f || maxOutput <= 0.0001f) {
|
||||
return;
|
||||
}
|
||||
|
||||
float inputUsed = Math.min(maxOutput / totalInput, 1f);
|
||||
for(Tile producer : producers){
|
||||
float accumulator = producer.entity.power.amount;
|
||||
producer.entity.power.amount -= producer.entity.power.amount * inputUsed;
|
||||
}
|
||||
|
||||
if(accumulator <= 0.0001f) continue;
|
||||
|
||||
float toEach = accumulator / consumers.size;
|
||||
float outputs = 0f;
|
||||
|
||||
for(Tile tile : consumers){
|
||||
outputs += Math.min(tile.block().powerCapacity - tile.entity.power.amount, toEach) / toEach;
|
||||
}
|
||||
|
||||
float finalEach = toEach / outputs * Timers.delta();
|
||||
float buffer = 0f;
|
||||
|
||||
if(Float.isNaN(finalEach) || Float.isInfinite(finalEach)){
|
||||
continue;
|
||||
}
|
||||
|
||||
for(Tile tile : consumers){
|
||||
float used = Math.min(tile.block().powerCapacity - tile.entity.power.amount, finalEach) * accumulator / totalInput;
|
||||
buffer += used;
|
||||
tile.entity.power.amount += used;
|
||||
}
|
||||
|
||||
producer.entity.power.amount -= buffer;
|
||||
float outputSatisfied = Math.min(totalInput / maxOutput, 1f);
|
||||
for(Tile consumer : consumers){
|
||||
consumer.entity.power.amount += (consumer.block().powerCapacity - consumer.entity.power.amount) * outputSatisfied;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user