Faster power graph reload / Fixed iOS editor margin
This commit is contained in:
@@ -243,14 +243,14 @@ public class MapView extends Element implements GestureListener{
|
|||||||
|
|
||||||
image.setImageSize(editor.width(), editor.height());
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.color(Pal.remove);
|
Draw.color(Pal.remove);
|
||||||
Lines.stroke(2f);
|
Lines.stroke(2f);
|
||||||
Lines.rect(centerx - sclwidth / 2 - 1, centery - sclheight / 2 - 1, sclwidth + 2, sclheight + 2);
|
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();
|
Draw.reset();
|
||||||
|
|
||||||
if(grid){
|
if(grid){
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
}else{
|
}else{
|
||||||
if(block.hasPower){
|
if(block.hasPower){
|
||||||
//reinit power graph
|
//reinit power graph
|
||||||
power.graph = new PowerGraph();
|
new PowerGraph().add(self());
|
||||||
power.graph.add(self());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class LExecutor{
|
|||||||
|
|
||||||
public LInstruction[] instructions = {};
|
public LInstruction[] instructions = {};
|
||||||
public Var[] vars = {};
|
public Var[] vars = {};
|
||||||
|
public int[] binds;
|
||||||
|
|
||||||
public LongSeq graphicsBuffer = new LongSeq();
|
public LongSeq graphicsBuffer = new LongSeq();
|
||||||
public StringBuilder textBuffer = new StringBuilder();
|
public StringBuilder textBuffer = new StringBuilder();
|
||||||
@@ -182,9 +183,6 @@ public class LExecutor{
|
|||||||
public static class UnitBindI implements LInstruction{
|
public static class UnitBindI implements LInstruction{
|
||||||
public int type;
|
public int type;
|
||||||
|
|
||||||
//iteration index
|
|
||||||
private int index;
|
|
||||||
|
|
||||||
public UnitBindI(int type){
|
public UnitBindI(int type){
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
@@ -195,17 +193,21 @@ public class LExecutor{
|
|||||||
@Override
|
@Override
|
||||||
public void run(LExecutor exec){
|
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
|
//binding to `null` was previously possible, but was too powerful and exploitable
|
||||||
if(exec.obj(type) instanceof UnitType type){
|
if(exec.obj(type) instanceof UnitType type){
|
||||||
Seq<Unit> seq = exec.team.data().unitCache(type);
|
Seq<Unit> seq = exec.team.data().unitCache(type);
|
||||||
|
|
||||||
if(seq != null && seq.any()){
|
if(seq != null && seq.any()){
|
||||||
index %= seq.size;
|
exec.binds[type.id] %= seq.size;
|
||||||
if(index < seq.size){
|
if(exec.binds[type.id] < seq.size){
|
||||||
//bind to the next unit
|
//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{
|
}else{
|
||||||
//no units of this type found
|
//no units of this type found
|
||||||
exec.setconst(varUnit, null);
|
exec.setconst(varUnit, null);
|
||||||
|
|||||||
@@ -12,11 +12,22 @@ public class PowerGraph{
|
|||||||
private static final Seq<Building> outArray1 = new Seq<>();
|
private static final Seq<Building> outArray1 = new Seq<>();
|
||||||
private static final Seq<Building> outArray2 = new Seq<>();
|
private static final Seq<Building> outArray2 = new Seq<>();
|
||||||
private static final IntSet closedSet = new IntSet();
|
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<>();
|
@Override
|
||||||
private final ObjectSet<Building> consumers = new ObjectSet<>();
|
public void addGraph(PowerGraph graph){
|
||||||
private final ObjectSet<Building> batteries = new ObjectSet<>();
|
throw new RuntimeException("cannot add to null graph");
|
||||||
private final ObjectSet<Building> all = new ObjectSet<>();
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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 final WindowedMean powerBalance = new WindowedMean(60);
|
||||||
private float lastPowerProduced, lastPowerNeeded, lastPowerStored;
|
private float lastPowerProduced, lastPowerNeeded, lastPowerStored;
|
||||||
@@ -209,7 +220,6 @@ public class PowerGraph{
|
|||||||
|
|
||||||
float powerNeeded = getPowerNeeded();
|
float powerNeeded = getPowerNeeded();
|
||||||
float powerProduced = getPowerProduced();
|
float powerProduced = getPowerProduced();
|
||||||
float rawProduced = powerProduced;
|
|
||||||
|
|
||||||
lastPowerNeeded = powerNeeded;
|
lastPowerNeeded = powerNeeded;
|
||||||
lastPowerProduced = powerProduced;
|
lastPowerProduced = powerProduced;
|
||||||
@@ -244,20 +254,24 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Building tile){
|
public void add(Building build){
|
||||||
if(tile == null || tile.power == null) return;
|
if(build == null || build.power == null) return;
|
||||||
tile.power.graph = this;
|
|
||||||
all.add(tile);
|
|
||||||
|
|
||||||
if(tile.block.outputsPower && tile.block.consumesPower && !tile.block.consumes.getPower().buffered){
|
if(build.power.graph != this || !build.power.init){
|
||||||
producers.add(tile);
|
build.power.graph = this;
|
||||||
consumers.add(tile);
|
build.power.init = true;
|
||||||
}else if(tile.block.outputsPower && tile.block.consumesPower){
|
all.add(build);
|
||||||
batteries.add(tile);
|
|
||||||
}else if(tile.block.outputsPower){
|
if(build.block.outputsPower && build.block.consumesPower && !build.block.consumes.getPower().buffered){
|
||||||
producers.add(tile);
|
producers.add(build);
|
||||||
}else if(tile.block.consumesPower){
|
consumers.add(build);
|
||||||
consumers.add(tile);
|
}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){
|
private void removeSingle(Building tile){
|
||||||
all.remove(tile);
|
all.remove(tile, true);
|
||||||
producers.remove(tile);
|
producers.remove(tile, true);
|
||||||
consumers.remove(tile);
|
consumers.remove(tile, true);
|
||||||
batteries.remove(tile);
|
batteries.remove(tile, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Building tile){
|
public void remove(Building tile){
|
||||||
|
|||||||
@@ -318,8 +318,7 @@ public class PowerNode extends PowerBlock{
|
|||||||
public void dropped(){
|
public void dropped(){
|
||||||
power.links.clear();
|
power.links.clear();
|
||||||
//create new power graph to manually unlink (this may be redundant)
|
//create new power graph to manually unlink (this may be redundant)
|
||||||
power.graph = new PowerGraph();
|
new PowerGraph().add(this);
|
||||||
power.graph.add(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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.
|
* In case of buffered consumers, this is the percentage of power stored in relation to the maximum capacity.
|
||||||
*/
|
*/
|
||||||
public float status = 0.0f;
|
public float status = 0.0f;
|
||||||
|
public boolean init;
|
||||||
public PowerGraph graph = new PowerGraph();
|
public PowerGraph graph = new PowerGraph();
|
||||||
public IntSeq links = new IntSeq();
|
public IntSeq links = new IntSeq();
|
||||||
|
|
||||||
|
|||||||
@@ -95,14 +95,13 @@ public class PowerTestFixture{
|
|||||||
// Simulate the "changed" method. Calling it through reflections would require half the game to be initialized.
|
// Simulate the "changed" method. Calling it through reflections would require half the game to be initialized.
|
||||||
tile.build = block.newBuilding().init(tile, Team.sharded, false, 0);
|
tile.build = block.newBuilding().init(tile, Team.sharded, false, 0);
|
||||||
if(block.hasPower){
|
if(block.hasPower){
|
||||||
tile.build.power.graph = new PowerGraph(){
|
new PowerGraph(){
|
||||||
//assume there's always something consuming power
|
//assume there's always something consuming power
|
||||||
@Override
|
@Override
|
||||||
public float getUsageFraction(){
|
public float getUsageFraction(){
|
||||||
return 1f;
|
return 1f;
|
||||||
}
|
}
|
||||||
};
|
}.add(tile.build);
|
||||||
tile.build.power.graph.add(tile.build);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign incredibly high health so the block does not get destroyed on e.g. burning Blast Compound
|
// Assign incredibly high health so the block does not get destroyed on e.g. burning Blast Compound
|
||||||
|
|||||||
Reference in New Issue
Block a user