Faster power graph reload / Fixed iOS editor margin

This commit is contained in:
Anuken
2020-12-27 12:59:49 -05:00
parent a04e7d5612
commit f174d1b2b4
7 changed files with 52 additions and 38 deletions

View File

@@ -243,14 +243,14 @@ public class MapView extends Element implements GestureListener{
image.setImageSize(editor.width(), editor.height());
if(!ScissorStack.push(rect.set(x, y, width, height))){
if(!ScissorStack.push(rect.set(x, y + Core.scene.marginBottom, width, height))){
return;
}
Draw.color(Pal.remove);
Lines.stroke(2f);
Lines.rect(centerx - sclwidth / 2 - 1, centery - sclheight / 2 - 1, sclwidth + 2, sclheight + 2);
editor.renderer.draw(centerx - sclwidth / 2, centery - sclheight / 2, sclwidth, sclheight);
editor.renderer.draw(centerx - sclwidth / 2, centery - sclheight / 2 + Core.scene.marginBottom, sclwidth, sclheight);
Draw.reset();
if(grid){

View File

@@ -84,8 +84,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
}else{
if(block.hasPower){
//reinit power graph
power.graph = new PowerGraph();
power.graph.add(self());
new PowerGraph().add(self());
}
}
this.rotation = rotation;

View File

@@ -44,6 +44,7 @@ public class LExecutor{
public LInstruction[] instructions = {};
public Var[] vars = {};
public int[] binds;
public LongSeq graphicsBuffer = new LongSeq();
public StringBuilder textBuffer = new StringBuilder();
@@ -182,9 +183,6 @@ public class LExecutor{
public static class UnitBindI implements LInstruction{
public int type;
//iteration index
private int index;
public UnitBindI(int type){
this.type = type;
}
@@ -195,17 +193,21 @@ public class LExecutor{
@Override
public void run(LExecutor exec){
if(exec.binds == null || exec.binds.length != content.units().size){
exec.binds = new int[content.units().size];
}
//binding to `null` was previously possible, but was too powerful and exploitable
if(exec.obj(type) instanceof UnitType type){
Seq<Unit> seq = exec.team.data().unitCache(type);
if(seq != null && seq.any()){
index %= seq.size;
if(index < seq.size){
exec.binds[type.id] %= seq.size;
if(exec.binds[type.id] < seq.size){
//bind to the next unit
exec.setconst(varUnit, seq.get(index));
exec.setconst(varUnit, seq.get(exec.binds[type.id]));
}
index++;
exec.binds[type.id] ++;
}else{
//no units of this type found
exec.setconst(varUnit, null);

View File

@@ -12,11 +12,22 @@ public class PowerGraph{
private static final Seq<Building> outArray1 = new Seq<>();
private static final Seq<Building> outArray2 = new Seq<>();
private static final IntSet closedSet = new IntSet();
private static final PowerGraph nullGraph = new PowerGraph(){
@Override
public void add(Building build){
throw new RuntimeException("cannot add to null graph");
}
private final ObjectSet<Building> producers = new ObjectSet<>();
private final ObjectSet<Building> consumers = new ObjectSet<>();
private final ObjectSet<Building> batteries = new ObjectSet<>();
private final ObjectSet<Building> all = new ObjectSet<>();
@Override
public void addGraph(PowerGraph graph){
throw new RuntimeException("cannot add to null graph");
}
};
private final Seq<Building> producers = new Seq<>(false);
private final Seq<Building> consumers = new Seq<>(false);
private final Seq<Building> batteries = new Seq<>(false);
private final Seq<Building> all = new Seq<>(false);
private final WindowedMean powerBalance = new WindowedMean(60);
private float lastPowerProduced, lastPowerNeeded, lastPowerStored;
@@ -209,7 +220,6 @@ public class PowerGraph{
float powerNeeded = getPowerNeeded();
float powerProduced = getPowerProduced();
float rawProduced = powerProduced;
lastPowerNeeded = powerNeeded;
lastPowerProduced = powerProduced;
@@ -244,20 +254,24 @@ public class PowerGraph{
}
}
public void add(Building tile){
if(tile == null || tile.power == null) return;
tile.power.graph = this;
all.add(tile);
public void add(Building build){
if(build == null || build.power == null) return;
if(tile.block.outputsPower && tile.block.consumesPower && !tile.block.consumes.getPower().buffered){
producers.add(tile);
consumers.add(tile);
}else if(tile.block.outputsPower && tile.block.consumesPower){
batteries.add(tile);
}else if(tile.block.outputsPower){
producers.add(tile);
}else if(tile.block.consumesPower){
consumers.add(tile);
if(build.power.graph != this || !build.power.init){
build.power.graph = this;
build.power.init = true;
all.add(build);
if(build.block.outputsPower && build.block.consumesPower && !build.block.consumes.getPower().buffered){
producers.add(build);
consumers.add(build);
}else if(build.block.outputsPower && build.block.consumesPower){
batteries.add(build);
}else if(build.block.outputsPower){
producers.add(build);
}else if(build.block.consumesPower){
consumers.add(build);
}
}
}
@@ -278,10 +292,10 @@ public class PowerGraph{
}
private void removeSingle(Building tile){
all.remove(tile);
producers.remove(tile);
consumers.remove(tile);
batteries.remove(tile);
all.remove(tile, true);
producers.remove(tile, true);
consumers.remove(tile, true);
batteries.remove(tile, true);
}
public void remove(Building tile){

View File

@@ -318,8 +318,7 @@ public class PowerNode extends PowerBlock{
public void dropped(){
power.links.clear();
//create new power graph to manually unlink (this may be redundant)
power.graph = new PowerGraph();
power.graph.add(this);
new PowerGraph().add(this);
}
@Override

View File

@@ -11,6 +11,7 @@ public class PowerModule extends BlockModule{
* In case of buffered consumers, this is the percentage of power stored in relation to the maximum capacity.
*/
public float status = 0.0f;
public boolean init;
public PowerGraph graph = new PowerGraph();
public IntSeq links = new IntSeq();