Kill path finding jobs upon interruption, for #1873.

This commit is contained in:
SpaceToad 2014-06-22 17:57:10 +02:00
parent eeb637d59f
commit e4ab3b0fa0
4 changed files with 31 additions and 1 deletions

View file

@ -95,4 +95,11 @@ public class AIRobotMoveToBlock extends AIRobotMove {
prevDistance = Double.MAX_VALUE;
}
}
@Override
public void end() {
if (pathSearchJob != null) {
pathSearchJob.terminate();
}
}
}

View file

@ -74,4 +74,10 @@ public class AIRobotGoToRandomDirt extends AIRobot {
}
}
@Override
public void end() {
if (pathFindingJob != null) {
pathFindingJob.terminate();
}
}
}

View file

@ -55,4 +55,11 @@ public class AIRobotSearchBlock extends AIRobot {
terminate();
}
}
@Override
public void end() {
if (blockScannerJob != null) {
blockScannerJob.terminate();
}
}
}

View file

@ -12,6 +12,8 @@ public class PathFindingJob extends Thread {
private PathFinding pathFinding;
private boolean stop = false;
public PathFindingJob(PathFinding iPathFinding) {
super("Path Finding");
pathFinding = iPathFinding;
@ -19,9 +21,17 @@ public class PathFindingJob extends Thread {
@Override
public void run() {
while (!pathFinding.isDone()) {
while (!isTerminated() && !pathFinding.isDone()) {
pathFinding.iterate();
}
}
public synchronized void terminate() {
stop = true;
}
public synchronized boolean isTerminated() {
return stop;
}
}