Minor power graph optimizations

This commit is contained in:
Anuken
2021-01-28 12:07:50 -05:00
parent 9a5a6e1ce2
commit 7cdf7a21fe

View File

@@ -249,6 +249,8 @@ public class PowerGraph{
}
public void addGraph(PowerGraph graph){
if(graph == this) return;
for(Building tile : graph.all){
add(tile);
}
@@ -283,9 +285,8 @@ public class PowerGraph{
Building child = queue.removeFirst();
add(child);
for(Building next : child.getPowerConnections(outArray2)){
if(!closedSet.contains(next.pos())){
if(closedSet.add(next.pos())){
queue.addLast(next);
closedSet.add(next.pos());
}
}
}
@@ -293,9 +294,6 @@ public class PowerGraph{
public void remove(Building tile){
//begin by clearing the closed set
closedSet.clear();
//go through all the connections of this tile
for(Building other : tile.getPowerConnections(outArray1)){
//a graph has already been assigned to this tile from a previous call, skip it
@@ -316,9 +314,9 @@ public class PowerGraph{
for(Building next : child.getPowerConnections(outArray2)){
//make sure it hasn't looped back, and that the new graph being assigned hasn't already been assigned
//also skip closed tiles
if(next != tile && next.power.graph != graph && !closedSet.contains(next.pos())){
if(next != tile && next.power.graph != graph){
graph.add(next);
queue.addLast(next);
closedSet.add(next.pos());
}
}
}