Bugfixes / Pathfinding 'improvements'
This commit is contained in:
@@ -2,7 +2,7 @@ package io.anuke.mindustry.ai;
|
||||
|
||||
import io.anuke.arc.Events;
|
||||
import io.anuke.arc.collection.IntArray;
|
||||
import io.anuke.arc.collection.Queue;
|
||||
import io.anuke.arc.collection.IntQueue;
|
||||
import io.anuke.arc.math.geom.Geometry;
|
||||
import io.anuke.arc.math.geom.Point2;
|
||||
import io.anuke.arc.util.Structs;
|
||||
@@ -19,7 +19,7 @@ import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class Pathfinder{
|
||||
private long maxUpdate = Time.millisToNanos(4);
|
||||
private static final long maxUpdate = Time.millisToNanos(4);
|
||||
private PathData[] paths;
|
||||
private IntArray blocked = new IntArray();
|
||||
|
||||
@@ -39,10 +39,6 @@ public class Pathfinder{
|
||||
});
|
||||
}
|
||||
|
||||
public void activateTeamPath(Team team){
|
||||
createFor(team);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(Net.client() || paths == null) return;
|
||||
|
||||
@@ -110,7 +106,7 @@ public class Pathfinder{
|
||||
for(Tile other : world.indexer.getEnemy(team, BlockFlag.target)){
|
||||
path.weights[other.x][other.y] = 0;
|
||||
path.searches[other.x][other.y] = (short)path.search;
|
||||
path.frontier.addFirst(other);
|
||||
path.frontier.addFirst(other.pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +126,7 @@ public class Pathfinder{
|
||||
|
||||
if(state.teams.areEnemies(tile.getTeam(), team)
|
||||
&& tile.block().flags.contains(BlockFlag.target)){
|
||||
path.frontier.addFirst(tile);
|
||||
path.frontier.addFirst(tile.pos());
|
||||
path.weights[x][y] = 0;
|
||||
path.searches[x][y] = (short)path.search;
|
||||
}else{
|
||||
@@ -148,9 +144,15 @@ public class Pathfinder{
|
||||
long start = Time.nanos();
|
||||
|
||||
while(path.frontier.size > 0 && (nsToRun < 0 || Time.timeSinceNanos(start) <= nsToRun)){
|
||||
Tile tile = path.frontier.removeLast();
|
||||
Tile tile = world.tile(path.frontier.removeLast());
|
||||
float cost = path.weights[tile.x][tile.y];
|
||||
|
||||
//pathfinding overflowed for some reason, time to bail. the next block update will handle this, hopefully
|
||||
if(path.frontier.size >= world.width() * world.height()){
|
||||
path.frontier.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if(cost < Float.MAX_VALUE){
|
||||
for(Point2 point : Geometry.d4){
|
||||
|
||||
@@ -160,7 +162,7 @@ public class Pathfinder{
|
||||
if(other != null && (path.weights[dx][dy] > cost + other.cost || path.searches[dx][dy] < path.search)
|
||||
&& passable(other, team)){
|
||||
if(other.cost < 0) throw new IllegalArgumentException("Tile cost cannot be negative! " + other);
|
||||
path.frontier.addFirst(world.tile(dx, dy));
|
||||
path.frontier.addFirst(world.tile(dx, dy).pos());
|
||||
path.weights[dx][dy] = cost + other.cost;
|
||||
path.searches[dx][dy] = (short)path.search;
|
||||
}
|
||||
@@ -190,6 +192,6 @@ public class Pathfinder{
|
||||
short[][] searches;
|
||||
int search = 0;
|
||||
long lastSearchTime;
|
||||
Queue<Tile> frontier = new Queue<>();
|
||||
IntQueue frontier = new IntQueue();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user