mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-22 20:48:33 +07:00
Fixed infinite graph traversal for power blocks
This commit is contained in:
parent
7a41fc8ec8
commit
8fd08a1574
@ -35,8 +35,6 @@ public class Blocks extends BlockList implements ContentList{
|
||||
blockpart = new BlockPart();
|
||||
|
||||
spawn = new Block("spawn"){
|
||||
{
|
||||
}
|
||||
|
||||
public void drawShadow(Tile tile){}
|
||||
|
||||
|
@ -162,7 +162,8 @@ public class Block extends BaseBlock {
|
||||
public Array<Tile> getPowerConnections(Tile tile, Array<Tile> out){
|
||||
out.clear();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@ -11,6 +12,7 @@ public class PowerGraph{
|
||||
private final static Queue<Tile> queue = new Queue<>();
|
||||
private final static Array<Tile> outArray1 = 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> consumers = new ObjectSet<>();
|
||||
@ -101,13 +103,15 @@ public class PowerGraph{
|
||||
public synchronized void reflow(Tile tile){
|
||||
queue.clear();
|
||||
queue.addLast(tile);
|
||||
closedSet.clear();
|
||||
while(queue.size > 0){
|
||||
Tile child = queue.removeFirst();
|
||||
child.entity.power.graph = this;
|
||||
add(child);
|
||||
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);
|
||||
closedSet.add(next.packedPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,6 +119,7 @@ public class PowerGraph{
|
||||
|
||||
public synchronized void remove(Tile tile){
|
||||
clear();
|
||||
closedSet.clear();
|
||||
|
||||
for(Tile other : tile.block().getPowerConnections(tile, outArray1)){
|
||||
if(other.entity.power == null || other.entity.power.graph != null) continue;
|
||||
@ -126,8 +131,9 @@ public class PowerGraph{
|
||||
child.entity.power.graph = graph;
|
||||
graph.add(child);
|
||||
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);
|
||||
closedSet.add(next.packedPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user