cancel calculation in progress

This commit is contained in:
Leijurv
2018-08-28 11:17:11 -07:00
parent df73e07923
commit c0fb57825c
3 changed files with 14 additions and 2 deletions

View File

@@ -52,6 +52,8 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
private volatile boolean isFinished;
protected boolean cancelRequested;
/**
* This is really complicated and hard to explain. I wrote a comment in the old version of MineBot but it was so
* long it was easier as a Google Doc (because I could insert charts).
@@ -70,10 +72,15 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
this.map = new HashMap<>();
}
public void cancel() {
cancelRequested = true;
}
public synchronized Optional<IPath> calculate() {
if (isFinished) {
throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!");
}
this.cancelRequested = false;
Optional<IPath> path = calculate0();
isFinished = true;
return path;