1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-11 03:31:19 +03:00

Non-recursive door floodfill

This commit is contained in:
Anuken 2021-03-15 11:39:06 -04:00
parent 075ddf104b
commit 96607ef753
2 changed files with 14 additions and 12 deletions

View File

@ -20,6 +20,7 @@ import static mindustry.Vars.*;
public class Door extends Wall{
protected final static Rect rect = new Rect();
protected final static Queue<DoorBuild> doorQueue = new Queue<>();
public final int timerToggle = timers++;
public Effect openfx = Fx.dooropen;
@ -56,7 +57,7 @@ public class Door extends Wall{
public class DoorBuild extends Building{
public boolean open = false;
public ObjectSet<DoorBuild> chained = new ObjectSet<>();
public Seq<DoorBuild> chained = new Seq<>();
@Override
public void onProximityAdded(){
@ -103,18 +104,19 @@ public class Door extends Wall{
}
public void updateChained(){
chained = new ObjectSet<>();
flow(chained);
}
chained = new Seq<>();
doorQueue.clear();
doorQueue.add(this);
public void flow(ObjectSet<DoorBuild> set){
if(!set.add(this)) return;
while(!doorQueue.isEmpty()){
var next = doorQueue.removeLast();
chained.add(next);
this.chained = set;
for(Building b : proximity){
if(b instanceof DoorBuild d){
d.flow(set);
for(var b : next.proximity){
if(b instanceof DoorBuild d && d.chained != chained){
d.chained = chained;
doorQueue.addFirst(d);
}
}
}
}

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=10de4947bdfc5510ea35ed9f510ffe2a7107ee63
archash=50fe096a7d26e76abc9be1ee5b18172d18e1b930