Cancel running pathfinding jobs before scheduling a new one

This commit is contained in:
Manuel Vögele
2022-09-30 22:47:51 +02:00
parent ac00aac85b
commit 25fc6258e7
+12 -5
View File
@@ -110,19 +110,26 @@ export function extendRuler() {
if (d.x === this.destination.x && d.y === this.destination.y) return; if (d.x === this.destination.x && d.y === this.destination.y) return;
this.destination = d; this.destination = d;
// TODO Cancel running pathfinding operations
// TODO Check if we can reuse the old path // TODO Check if we can reuse the old path
this.dragRulerRemovePathfindingWaypoints(); this.dragRulerRemovePathfindingWaypoints();
if (this.pathfindingJob) {
routinglib.cancelPathfinding(this.pathfindingJob);
this.pathfindingJob = undefined;
}
if (isToken && isPathfindingEnabled.call(this)) { if (isToken && isPathfindingEnabled.call(this)) {
// TODO Show a busy indicator // TODO Show a busy indicator
const from = getGridPositionFromPixelsObj(this.waypoints[this.waypoints.length - 1]); const from = getGridPositionFromPixelsObj(this.waypoints[this.waypoints.length - 1]);
const to = getGridPositionFromPixelsObj(destination); const to = getGridPositionFromPixelsObj(destination);
return routinglib const pathfindingJob = routinglib.calculatePath(from, to, {token: this.draggedEntity});
.calculatePath(from, to, {token: this.draggedEntity}) this.pathfindingJob = pathfindingJob;
.then(result => this.addPathToWaypoints(result?.path)) return this.pathfindingJob.then(result => {
.then(() => this.performPostPathfindingActions(options)); if (pathfindingJob === this.pathfindingJob) {
this.addPathToWaypoints(result?.path);
return this.performPostPathfindingActions(options);
}
});
} }
return this.performPostPathfindingActions(options); return this.performPostPathfindingActions(options);