Fixed doors not updating pathfinder
This commit is contained in:
@@ -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));
|
||||||
@@ -534,7 +538,7 @@ public class ControlPathfinder implements Runnable{
|
|||||||
|
|
||||||
void updateInnerEdges(int team, PathCost cost, int cx, int cy, Cluster cluster){
|
void updateInnerEdges(int team, PathCost cost, int cx, int cy, Cluster cluster){
|
||||||
int minX = cx * clusterSize, minY = cy * clusterSize, maxX = Math.min(minX + clusterSize - 1, wwidth - 1), maxY = Math.min(minY + clusterSize - 1, wheight - 1);
|
int minX = cx * clusterSize, minY = cy * clusterSize, maxX = Math.min(minX + clusterSize - 1, wwidth - 1), maxY = Math.min(minY + clusterSize - 1, wheight - 1);
|
||||||
|
|
||||||
usedEdges.clear();
|
usedEdges.clear();
|
||||||
|
|
||||||
//clear all connections, since portals changed, they need to be recomputed.
|
//clear all connections, since portals changed, they need to be recomputed.
|
||||||
@@ -548,7 +552,7 @@ public class ControlPathfinder implements Runnable{
|
|||||||
|
|
||||||
for(int i = 0; i < portals.size; i++){
|
for(int i = 0; i < portals.size; i++){
|
||||||
usedEdges.add(Point2.pack(direction, i));
|
usedEdges.add(Point2.pack(direction, i));
|
||||||
|
|
||||||
int
|
int
|
||||||
portal = portals.items[i],
|
portal = portals.items[i],
|
||||||
from = Point2.x(portal), to = Point2.y(portal),
|
from = Point2.x(portal), to = Point2.y(portal),
|
||||||
|
|||||||
@@ -243,6 +243,8 @@ public class Pathfinder implements Runnable{
|
|||||||
data.dirty = true;
|
data.dirty = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
controlPath.updateTile(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Thread implementation. */
|
/** Thread implementation. */
|
||||||
|
|||||||
Reference in New Issue
Block a user