Fixed #7292
This commit is contained in:
@@ -152,6 +152,13 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(){
|
||||||
|
if(power != null){
|
||||||
|
power.graph.checkAdd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Replace
|
@Replace
|
||||||
public int tileX(){
|
public int tileX(){
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
|||||||
//update power graph first, resolve everything
|
//update power graph first, resolve everything
|
||||||
for(Payload pay : payloads){
|
for(Payload pay : payloads){
|
||||||
if(pay instanceof BuildPayload pb && pb.build.power != null){
|
if(pay instanceof BuildPayload pb && pb.build.power != null){
|
||||||
if(payloadPower == null) payloadPower = new PowerGraph();
|
if(payloadPower == null) payloadPower = new PowerGraph(false);
|
||||||
|
|
||||||
//pb.build.team = team;
|
//pb.build.team = team;
|
||||||
pb.build.power.graph = null;
|
pb.build.power.graph = null;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class PowerGraph{
|
|||||||
public final Seq<Building> batteries = new Seq<>(false, 16, Building.class);
|
public final Seq<Building> batteries = new Seq<>(false, 16, Building.class);
|
||||||
public final Seq<Building> all = new Seq<>(false, 16, Building.class);
|
public final Seq<Building> all = new Seq<>(false, 16, Building.class);
|
||||||
|
|
||||||
private final PowerGraphUpdater entity;
|
private final @Nullable PowerGraphUpdater entity;
|
||||||
private final WindowedMean powerBalance = new WindowedMean(60);
|
private final WindowedMean powerBalance = new WindowedMean(60);
|
||||||
private float lastPowerProduced, lastPowerNeeded, lastPowerStored;
|
private float lastPowerProduced, lastPowerNeeded, lastPowerStored;
|
||||||
private float lastScaledPowerIn, lastScaledPowerOut, lastCapacity;
|
private float lastScaledPowerIn, lastScaledPowerOut, lastCapacity;
|
||||||
@@ -34,6 +34,11 @@ public class PowerGraph{
|
|||||||
graphID = lastGraphID++;
|
graphID = lastGraphID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PowerGraph(boolean noEntity){
|
||||||
|
entity = null;
|
||||||
|
graphID = lastGraphID++;
|
||||||
|
}
|
||||||
|
|
||||||
public int getID(){
|
public int getID(){
|
||||||
return graphID;
|
return graphID;
|
||||||
}
|
}
|
||||||
@@ -251,11 +256,12 @@ public class PowerGraph{
|
|||||||
public void addGraph(PowerGraph graph){
|
public void addGraph(PowerGraph graph){
|
||||||
if(graph == this) return;
|
if(graph == this) return;
|
||||||
//other entity should be removed as the graph was merged
|
//other entity should be removed as the graph was merged
|
||||||
graph.entity.remove();
|
if(graph.entity != null) graph.entity.remove();
|
||||||
|
|
||||||
for(Building tile : graph.all){
|
for(Building tile : graph.all){
|
||||||
add(tile);
|
add(tile);
|
||||||
}
|
}
|
||||||
|
checkAdd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Building build){
|
public void add(Building build){
|
||||||
@@ -264,14 +270,12 @@ public class PowerGraph{
|
|||||||
if(build.power.graph != this || !build.power.init){
|
if(build.power.graph != this || !build.power.init){
|
||||||
//any old graph that is added here MUST be invalid, remove it
|
//any old graph that is added here MUST be invalid, remove it
|
||||||
if(build.power.graph != null && build.power.graph != this){
|
if(build.power.graph != null && build.power.graph != this){
|
||||||
build.power.graph.entity.remove();
|
if( build.power.graph.entity != null) build.power.graph.entity.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
build.power.graph = this;
|
build.power.graph = this;
|
||||||
build.power.init = true;
|
build.power.init = true;
|
||||||
all.add(build);
|
all.add(build);
|
||||||
//there's something to update, add the entity
|
|
||||||
entity.add();
|
|
||||||
|
|
||||||
if(build.block.outputsPower && build.block.consumesPower && !build.block.consPower.buffered){
|
if(build.block.outputsPower && build.block.consumesPower && !build.block.consPower.buffered){
|
||||||
producers.add(build);
|
producers.add(build);
|
||||||
@@ -286,13 +290,17 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkAdd(){
|
||||||
|
if(entity != null) entity.add();
|
||||||
|
}
|
||||||
|
|
||||||
public void clear(){
|
public void clear(){
|
||||||
all.clear();
|
all.clear();
|
||||||
producers.clear();
|
producers.clear();
|
||||||
consumers.clear();
|
consumers.clear();
|
||||||
batteries.clear();
|
batteries.clear();
|
||||||
//nothing left
|
//nothing left
|
||||||
entity.remove();
|
if(entity != null) entity.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reflow(Building tile){
|
public void reflow(Building tile){
|
||||||
@@ -302,6 +310,7 @@ public class PowerGraph{
|
|||||||
while(queue.size > 0){
|
while(queue.size > 0){
|
||||||
Building child = queue.removeFirst();
|
Building child = queue.removeFirst();
|
||||||
add(child);
|
add(child);
|
||||||
|
checkAdd();
|
||||||
for(Building next : child.getPowerConnections(outArray2)){
|
for(Building next : child.getPowerConnections(outArray2)){
|
||||||
if(closedSet.add(next.pos())){
|
if(closedSet.add(next.pos())){
|
||||||
queue.addLast(next);
|
queue.addLast(next);
|
||||||
@@ -329,6 +338,7 @@ public class PowerGraph{
|
|||||||
|
|
||||||
//create graph for this branch
|
//create graph for this branch
|
||||||
PowerGraph graph = new PowerGraph();
|
PowerGraph graph = new PowerGraph();
|
||||||
|
graph.checkAdd();
|
||||||
graph.add(other);
|
graph.add(other);
|
||||||
//add to queue for BFS
|
//add to queue for BFS
|
||||||
queue.clear();
|
queue.clear();
|
||||||
@@ -353,7 +363,7 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//implied empty graph here
|
//implied empty graph here
|
||||||
entity.remove();
|
if(entity != null) entity.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
Reference in New Issue
Block a user