v0.4.2: array managment optimizations to Pathfinder
This commit is contained in:
parent
7b16e75553
commit
3941aa3fe4
|
@ -27,6 +27,7 @@ import java.util.LinkedList;
|
|||
public class PathFinder {
|
||||
|
||||
public static int[] distance;
|
||||
private static int[] maxVal;
|
||||
|
||||
private static boolean[] goals;
|
||||
private static int[] queue;
|
||||
|
@ -49,13 +50,20 @@ public class PathFinder {
|
|||
goals = new boolean[size];
|
||||
queue = new int[size];
|
||||
|
||||
maxVal = new int[size];
|
||||
Arrays.fill(maxVal, Integer.MAX_VALUE);
|
||||
|
||||
dir = new int[]{-1, +1, -width, +width, -width-1, -width+1, +width-1, +width+1};
|
||||
|
||||
NEIGHBOURS4 = new int[]{-width, +1, +width, -1};
|
||||
NEIGHBOURS8 = new int[]{-width, +1-width, +1, +1+width, +width, -1+width, -1, -1-width};
|
||||
NEIGHBOURS9 = new int[]{0, -width, +1-width, +1, +1+width, +width, -1+width, -1, -1-width};
|
||||
}
|
||||
|
||||
|
||||
//TODO currently this isn't used, and all pathfinding is recomputed each step.
|
||||
// Computing each step is performance expensive, but pre-computing a path leads to incorrect
|
||||
// pathing in cases where passable changes. Need to look into a compromise, something that's
|
||||
// correct but is less costly
|
||||
public static Path find( int from, int to, boolean[] passable ) {
|
||||
|
||||
if (!buildDistanceMap( from, to, passable )) {
|
||||
|
@ -146,8 +154,8 @@ public class PathFinder {
|
|||
if (from == to) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Arrays.fill( distance, Integer.MAX_VALUE );
|
||||
|
||||
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
|
||||
|
||||
boolean pathFound = false;
|
||||
|
||||
|
@ -185,7 +193,7 @@ public class PathFinder {
|
|||
|
||||
public static void buildDistanceMap( int to, boolean[] passable, int limit ) {
|
||||
|
||||
Arrays.fill( distance, Integer.MAX_VALUE );
|
||||
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
|
||||
|
||||
int head = 0;
|
||||
int tail = 0;
|
||||
|
@ -223,7 +231,7 @@ public class PathFinder {
|
|||
return false;
|
||||
}
|
||||
|
||||
Arrays.fill( distance, Integer.MAX_VALUE );
|
||||
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
|
||||
|
||||
boolean pathFound = false;
|
||||
|
||||
|
@ -265,7 +273,7 @@ public class PathFinder {
|
|||
|
||||
private static int buildEscapeDistanceMap( int cur, int from, float factor, boolean[] passable ) {
|
||||
|
||||
Arrays.fill( distance, Integer.MAX_VALUE );
|
||||
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
|
||||
|
||||
int destDist = Integer.MAX_VALUE;
|
||||
|
||||
|
@ -312,7 +320,7 @@ public class PathFinder {
|
|||
@SuppressWarnings("unused")
|
||||
private static void buildDistanceMap( int to, boolean[] passable ) {
|
||||
|
||||
Arrays.fill( distance, Integer.MAX_VALUE );
|
||||
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
|
||||
|
||||
int head = 0;
|
||||
int tail = 0;
|
||||
|
|
Loading…
Reference in New Issue
Block a user