regular path finding is using a separate thread, #1873

This commit is contained in:
SpaceToad 2014-06-11 18:50:17 +02:00
parent ce0c26f31d
commit 1d642f052c
3 changed files with 12 additions and 12 deletions

View file

@ -12,14 +12,15 @@ import java.util.LinkedList;
import buildcraft.core.BlockIndex;
import buildcraft.core.utils.PathFinding;
import buildcraft.core.utils.PathFindingJob;
import buildcraft.robots.EntityRobotBase;
public class AIRobotMoveToBlock extends AIRobotMove {
private PathFinding pathSearch;
private PathFindingJob pathSearchJob;
private LinkedList<BlockIndex> path;
private double prevDistance = Double.MAX_VALUE;
private float finalX, finalY, finalZ;
public AIRobotMoveToBlock(EntityRobotBase robot, int x, int y, int z) {
@ -46,6 +47,9 @@ public class AIRobotMoveToBlock extends AIRobotMove {
pathSearch = new PathFinding(robot.worldObj, new BlockIndex((int) Math.floor(robot.posX),
(int) Math.floor(robot.posY), (int) Math.floor(robot.posZ)), new BlockIndex(
(int) Math.floor(finalX), (int) Math.floor(finalY), (int) Math.floor(finalZ)));
pathSearchJob = new PathFindingJob(pathSearch);
pathSearchJob.start();
}
}
@ -64,11 +68,11 @@ public class AIRobotMoveToBlock extends AIRobotMove {
prevDistance = robot.getDistance(nextX, nextY, nextZ);
}
} else {
pathSearch.iterate(PathFinding.PATH_ITERATIONS);
if (pathSearch.isDone()) {
path = pathSearch.getResult();
setNextInPath();
if (!pathSearchJob.isAlive()) {
if (pathSearch.isDone()) {
path = pathSearch.getResult();
setNextInPath();
}
}
}

View file

@ -52,11 +52,7 @@ public class BoardRobotLumberjack extends RedstoneBoardRobot {
public static boolean isFreeWoodTarget(BlockIndex index) {
synchronized (woodTargets) {
if (!woodTargets.contains(index)) {
return true;
} else {
return false;
}
return !woodTargets.contains(index);
}
}

View file

@ -39,7 +39,7 @@ public class PathFinding {
private LinkedList<BlockIndex> result;
public boolean endReached = false;
private boolean endReached = false;
public PathFinding(World iWorld, BlockIndex iStart, BlockIndex iEnd) {
world = iWorld;