Fixed infinite graph traversal for power blocks
This commit is contained in:
@@ -35,8 +35,6 @@ public class Blocks extends BlockList implements ContentList{
|
|||||||
blockpart = new BlockPart();
|
blockpart = new BlockPart();
|
||||||
|
|
||||||
spawn = new Block("spawn"){
|
spawn = new Block("spawn"){
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawShadow(Tile tile){}
|
public void drawShadow(Tile tile){}
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,8 @@ public class Block extends BaseBlock {
|
|||||||
public Array<Tile> getPowerConnections(Tile tile, Array<Tile> out){
|
public Array<Tile> getPowerConnections(Tile tile, Array<Tile> out){
|
||||||
out.clear();
|
out.clear();
|
||||||
for(Tile other : tile.entity.proximity()){
|
for(Tile other : tile.entity.proximity()){
|
||||||
if(other.entity.power != null && !(consumesPower && other.block().consumesPower && !outputsPower && !other.block().outputsPower)){
|
if(other.entity.power != null && !(consumesPower && other.block().consumesPower && !outputsPower && !other.block().outputsPower)
|
||||||
|
&& !tile.entity.power.links.contains(other.packedPosition())){
|
||||||
out.add(other);
|
out.add(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.anuke.mindustry.world.blocks.power;
|
package io.anuke.mindustry.world.blocks.power;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
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;
|
||||||
@@ -11,6 +12,7 @@ public class PowerGraph{
|
|||||||
private final static Queue<Tile> queue = new Queue<>();
|
private final static Queue<Tile> queue = new Queue<>();
|
||||||
private final static Array<Tile> outArray1 = new Array<>();
|
private final static Array<Tile> outArray1 = new Array<>();
|
||||||
private final static Array<Tile> outArray2 = new Array<>();
|
private final static Array<Tile> outArray2 = new Array<>();
|
||||||
|
private final static IntSet closedSet = new IntSet();
|
||||||
|
|
||||||
private final ObjectSet<Tile> producers = new ObjectSet<>();
|
private final ObjectSet<Tile> producers = new ObjectSet<>();
|
||||||
private final ObjectSet<Tile> consumers = new ObjectSet<>();
|
private final ObjectSet<Tile> consumers = new ObjectSet<>();
|
||||||
@@ -101,13 +103,15 @@ public class PowerGraph{
|
|||||||
public synchronized void reflow(Tile tile){
|
public synchronized void reflow(Tile tile){
|
||||||
queue.clear();
|
queue.clear();
|
||||||
queue.addLast(tile);
|
queue.addLast(tile);
|
||||||
|
closedSet.clear();
|
||||||
while(queue.size > 0){
|
while(queue.size > 0){
|
||||||
Tile child = queue.removeFirst();
|
Tile child = queue.removeFirst();
|
||||||
child.entity.power.graph = this;
|
child.entity.power.graph = this;
|
||||||
add(child);
|
add(child);
|
||||||
for(Tile next : child.block().getPowerConnections(child, outArray2)){
|
for(Tile next : child.block().getPowerConnections(child, outArray2)){
|
||||||
if(next.entity.power != null && next.entity.power.graph == null){
|
if(next.entity.power != null && next.entity.power.graph == null && !closedSet.contains(next.packedPosition())){
|
||||||
queue.addLast(next);
|
queue.addLast(next);
|
||||||
|
closedSet.add(next.packedPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,6 +119,7 @@ public class PowerGraph{
|
|||||||
|
|
||||||
public synchronized void remove(Tile tile){
|
public synchronized void remove(Tile tile){
|
||||||
clear();
|
clear();
|
||||||
|
closedSet.clear();
|
||||||
|
|
||||||
for(Tile other : tile.block().getPowerConnections(tile, outArray1)){
|
for(Tile other : tile.block().getPowerConnections(tile, outArray1)){
|
||||||
if(other.entity.power == null || other.entity.power.graph != null) continue;
|
if(other.entity.power == null || other.entity.power.graph != null) continue;
|
||||||
@@ -126,8 +131,9 @@ public class PowerGraph{
|
|||||||
child.entity.power.graph = graph;
|
child.entity.power.graph = graph;
|
||||||
graph.add(child);
|
graph.add(child);
|
||||||
for(Tile next : child.block().getPowerConnections(child, outArray2)){
|
for(Tile next : child.block().getPowerConnections(child, outArray2)){
|
||||||
if(next != tile && next.entity.power != null && next.entity.power.graph == null){
|
if(next != tile && next.entity.power != null && next.entity.power.graph == null && !closedSet.contains(next.packedPosition())){
|
||||||
queue.addLast(next);
|
queue.addLast(next);
|
||||||
|
closedSet.add(next.packedPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user