Path progress
This commit is contained in:
@@ -425,46 +425,48 @@ public class Pathfinder implements Runnable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface PathTarget{
|
/**
|
||||||
/** Gets targets to pathfind towards. This must run on the main thread. */
|
* Data for a flow field to some set of destinations.
|
||||||
IntSeq getPositions(Team team, IntSeq out);
|
* Concrete subclasses must specify a way to fetch costs and destinations.
|
||||||
|
* */
|
||||||
|
static abstract class Flowfield{
|
||||||
/** Refresh rate in milliseconds. Return any number <= 0 to disable. */
|
/** Refresh rate in milliseconds. Return any number <= 0 to disable. */
|
||||||
int refreshRate();
|
protected int refreshRate;
|
||||||
}
|
|
||||||
|
|
||||||
/** Data for a specific flow field to some set of destinations. */
|
|
||||||
static class Flowfield{
|
|
||||||
/** Team this path is for. */
|
/** Team this path is for. */
|
||||||
final Team team;
|
protected Team team;
|
||||||
/** Flag that is being targeted. */
|
|
||||||
final PathTarget target;
|
|
||||||
/** costs of getting to a specific tile */
|
/** costs of getting to a specific tile */
|
||||||
final int[][] weights;
|
int[][] weights;
|
||||||
/** search IDs of each position - the highest, most recent search is prioritized and overwritten */
|
/** search IDs of each position - the highest, most recent search is prioritized and overwritten */
|
||||||
final int[][] searches;
|
int[][] searches;
|
||||||
/** search frontier, these are Pos objects */
|
/** search frontier, these are Pos objects */
|
||||||
final IntQueue frontier = new IntQueue();
|
IntQueue frontier = new IntQueue();
|
||||||
/** all target positions; these positions have a cost of 0, and must be synchronized on! */
|
/** all target positions; these positions have a cost of 0, and must be synchronized on! */
|
||||||
final IntSeq targets = new IntSeq();
|
IntSeq targets = new IntSeq();
|
||||||
/** current search ID */
|
/** current search ID */
|
||||||
int search = 1;
|
int search = 1;
|
||||||
/** last updated time */
|
/** last updated time */
|
||||||
long lastUpdateTime;
|
long lastUpdateTime;
|
||||||
|
|
||||||
Flowfield(Team team, PathTarget target, int width, int height){
|
void setup(Team team, int width, int height){
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.target = target;
|
|
||||||
|
|
||||||
this.weights = new int[width][height];
|
this.weights = new int[width][height];
|
||||||
this.searches = new int[width][height];
|
this.searches = new int[width][height];
|
||||||
this.frontier.ensureCapacity((width + height) * 3);
|
this.frontier.ensureCapacity((width + height) * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets targets to pathfind towards. This must run on the main thread. */
|
||||||
|
protected abstract IntSeq getPositions(IntSeq out);
|
||||||
|
|
||||||
|
/** Gets the cost of a tile at a position. */
|
||||||
|
protected abstract int getCost(int pathTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Holds a copy of tile data for a specific tile position. */
|
/** Holds a copy of tile data for a specific tile position. */
|
||||||
@Struct
|
@Struct
|
||||||
class PathTileStruct{
|
class PathTileStruct{
|
||||||
//base traversal cost
|
//base traversal cost (could be a byte..)
|
||||||
short cost;
|
short cost;
|
||||||
//team of block, if applicable (0 by default)
|
//team of block, if applicable (0 by default)
|
||||||
byte team;
|
byte team;
|
||||||
|
|||||||
Reference in New Issue
Block a user