Fixed doors not updating pathfinder

This commit is contained in:
Anuken
2024-09-11 14:17:35 -04:00
parent aca84bbeff
commit 6b95a4b70e
2 changed files with 26 additions and 20 deletions

View File

@@ -232,24 +232,7 @@ public class ControlPathfinder implements Runnable{
Events.on(TileChangeEvent.class, e -> { Events.on(TileChangeEvent.class, e -> {
e.tile.getLinkedTiles(t -> { updateTile(e.tile);
int x = t.x, y = t.y, mx = x % clusterSize, my = y % clusterSize, cx = x / clusterSize, cy = y / clusterSize, cluster = cx + cy * cwidth;
//is at the edge of a cluster; this means the portals may have changed.
if(mx == 0 || my == 0 || mx == clusterSize - 1 || my == clusterSize - 1){
if(mx == 0) queueClusterUpdate(cx - 1, cy); //left
if(my == 0) queueClusterUpdate(cx, cy - 1); //bottom
if(mx == clusterSize - 1) queueClusterUpdate(cx + 1, cy); //right
if(my == clusterSize - 1) queueClusterUpdate(cx, cy + 1); //top
queueClusterUpdate(cx, cy);
//TODO: recompute edge clusters too.
}else{
//there is no need to recompute portals for block updates that are not on the edge.
queue.post(() -> clustersToInnerUpdate.add(cluster));
}
});
//TODO: recalculate affected flow fields? or just all of them? how to reflow? //TODO: recalculate affected flow fields? or just all of them? how to reflow?
}); });
@@ -358,6 +341,27 @@ public class ControlPathfinder implements Runnable{
} }
} }
public void updateTile(Tile tile){
tile.getLinkedTiles(t -> {
int x = t.x, y = t.y, mx = x % clusterSize, my = y % clusterSize, cx = x / clusterSize, cy = y / clusterSize, cluster = cx + cy * cwidth;
//is at the edge of a cluster; this means the portals may have changed.
if(mx == 0 || my == 0 || mx == clusterSize - 1 || my == clusterSize - 1){
if(mx == 0) queueClusterUpdate(cx - 1, cy); //left
if(my == 0) queueClusterUpdate(cx, cy - 1); //bottom
if(mx == clusterSize - 1) queueClusterUpdate(cx + 1, cy); //right
if(my == clusterSize - 1) queueClusterUpdate(cx, cy + 1); //top
queueClusterUpdate(cx, cy);
//TODO: recompute edge clusters too.
}else{
//there is no need to recompute portals for block updates that are not on the edge.
queue.post(() -> clustersToInnerUpdate.add(cluster));
}
});
}
void queueClusterUpdate(int cx, int cy){ void queueClusterUpdate(int cx, int cy){
if(cx >= 0 && cy >= 0 && cx < cwidth && cy < cheight){ if(cx >= 0 && cy >= 0 && cx < cwidth && cy < cheight){
queue.post(() -> clustersToUpdate.add(cx + cy * cwidth)); queue.post(() -> clustersToUpdate.add(cx + cy * cwidth));

View File

@@ -243,6 +243,8 @@ public class Pathfinder implements Runnable{
data.dirty = true; data.dirty = true;
} }
}); });
controlPath.updateTile(tile);
} }
/** Thread implementation. */ /** Thread implementation. */