Re-added hacky power graph fix
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.ObjectSet;
|
||||||
import com.badlogic.gdx.utils.Queue;
|
import com.badlogic.gdx.utils.Queue;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Timers;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.threads;
|
import static io.anuke.mindustry.Vars.threads;
|
||||||
|
|
||||||
@@ -38,38 +37,63 @@ public class PowerGraph{
|
|||||||
|
|
||||||
lastFrameUpdated = threads.getFrameID();
|
lastFrameUpdated = threads.getFrameID();
|
||||||
|
|
||||||
float totalInput = 0f;
|
boolean charge = false;
|
||||||
|
|
||||||
|
float totalInput = 0f;
|
||||||
|
float bufferInput = 0f;
|
||||||
for(Tile producer : producers){
|
for(Tile producer : producers){
|
||||||
totalInput += producer.entity.power.amount;
|
if(producer.block().consumesPower){
|
||||||
|
bufferInput += producer.entity.power.amount;
|
||||||
|
}else{
|
||||||
|
totalInput += producer.entity.power.amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Tile producer : producers){
|
float maxOutput = 0f;
|
||||||
float accumulator = producer.entity.power.amount;
|
float bufferOutput = 0f;
|
||||||
|
for(Tile consumer : consumers){
|
||||||
if(accumulator <= 0.0001f) continue;
|
if(consumer.block().outputsPower){
|
||||||
|
bufferOutput += consumer.block().powerCapacity - consumer.entity.power.amount;
|
||||||
float toEach = accumulator / consumers.size;
|
}else{
|
||||||
float outputs = 0f;
|
maxOutput += consumer.block().powerCapacity - consumer.entity.power.amount;
|
||||||
|
|
||||||
for(Tile tile : consumers){
|
|
||||||
outputs += Math.min(tile.block().powerCapacity - tile.entity.power.amount, toEach) / toEach;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float finalEach = toEach / outputs * Timers.delta();
|
if(maxOutput < totalInput){
|
||||||
float buffer = 0f;
|
charge = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(Float.isNaN(finalEach) || Float.isInfinite(finalEach)){
|
if(totalInput + bufferInput <= 0.0001f || maxOutput + bufferOutput <= 0.0001f){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float bufferUsed;
|
||||||
|
if(charge){
|
||||||
|
bufferUsed = Math.min((totalInput - maxOutput) / bufferOutput, 1f);
|
||||||
|
}else{
|
||||||
|
bufferUsed = Math.min((maxOutput - totalInput) / bufferInput, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
float inputUsed = charge ? Math.min((maxOutput + bufferOutput) / totalInput, 1f) : 1f;
|
||||||
|
for(Tile producer : producers){
|
||||||
|
if(producer.block().consumesPower){
|
||||||
|
if(!charge){
|
||||||
|
producer.entity.power.amount -= producer.entity.power.amount * bufferUsed;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
producer.entity.power.amount -= producer.entity.power.amount * inputUsed;
|
||||||
|
}
|
||||||
|
|
||||||
for(Tile tile : consumers){
|
float outputSatisfied = charge ? 1f : Math.min((totalInput + bufferInput) / maxOutput, 1f);
|
||||||
float used = Math.min(tile.block().powerCapacity - tile.entity.power.amount, finalEach) * accumulator / totalInput;
|
for(Tile consumer : consumers){
|
||||||
buffer += used;
|
if(consumer.block().outputsPower){
|
||||||
tile.entity.power.amount += used;
|
if(charge){
|
||||||
|
consumer.entity.power.amount += (consumer.block().powerCapacity - consumer.entity.power.amount) * bufferUsed;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
consumer.entity.power.amount += (consumer.block().powerCapacity - consumer.entity.power.amount) * outputSatisfied;
|
||||||
producer.entity.power.amount -= buffer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user