Cleanup & enemy follow commands

This commit is contained in:
Anuken
2022-02-09 17:21:15 -05:00
parent fa79c5e93a
commit 44b37cfe55
3 changed files with 15 additions and 19 deletions

View File

@@ -45,9 +45,7 @@ public class ControlPathfinder implements Runnable{
//static access probably faster than object access
static int wwidth, wheight;
//MAIN THREAD DATA
//increments each tile change
static volatile int worldUpdateId;
/** Current pathfinding thread */
@@ -56,9 +54,10 @@ public class ControlPathfinder implements Runnable{
int lastTargetId = 1;
/** handles task scheduling on the update thread. */
TaskQueue queue = new TaskQueue();
/** requests per-unit */
ObjectMap<Unit, PathRequest> requests = new ObjectMap<>();
//PATHFINDING THREAD DATA
/** pathfinding thread access only! */
Seq<PathRequest> threadRequests = new Seq<>();
public ControlPathfinder(){
@@ -149,7 +148,7 @@ public class ControlPathfinder implements Runnable{
var req = new PathRequest();
req.unit = unit;
req.pathType = pathType;
req.destination = destination;
req.destination.set(destination);
req.curId = pathId;
req.lastUpdateId = state.updateId;
req.lastWorldUpdate = worldUpdateId;
@@ -168,7 +167,7 @@ public class ControlPathfinder implements Runnable{
req.foundEnd = false;
}
req.destination = destination;
req.destination.set(destination);
req.curId = pathId;
if(req.done){
@@ -366,11 +365,12 @@ public class ControlPathfinder implements Runnable{
volatile boolean done = false;
volatile boolean foundEnd = false;
final Vec2 destination = new Vec2();
final Vec2 lastDestination = new Vec2();
volatile Unit unit;
volatile int pathType;
volatile Vec2 destination;
volatile int lastWorldUpdate;
volatile float stuckTime;
//TODO only access on main thread??
int pathIndex;
@@ -400,7 +400,7 @@ public class ControlPathfinder implements Runnable{
lastId = curId;
//re-do everything when world updates
if(Time.timeSinceMillis(lastTime) > 1000 * 1 && worldUpdateId != lastWorldUpdate){
if(Time.timeSinceMillis(lastTime) > 1000 * 2 && (worldUpdateId != lastWorldUpdate || !destination.epsilonEquals(lastDestination, 2f))){
lastTime = Time.millis();
lastWorldUpdate = worldUpdateId;
pathIndex = 0;
@@ -496,7 +496,7 @@ public class ControlPathfinder implements Runnable{
void clear(){
done = false;
//TODO horribly expensive
//TODO could be less expensive?
frontier = new PathfindQueue(20);
cameFrom.clear();
costs.clear();
@@ -511,9 +511,7 @@ public class ControlPathfinder implements Runnable{
foundEnd = false;
result.clear();
//closed = new GridBits(world.width(), world.height());
//queue = new PathfindQueue(16);
lastDestination.set(destination);
}
}
}

View File

@@ -215,9 +215,7 @@ public class Pathfinder implements Runnable{
return;
}
}catch(Throwable e){
//TODO remove in production!
Threads.throwAppException(e);
//e.printStackTrace();
e.printStackTrace();
}
}
}
@@ -403,7 +401,7 @@ public class Pathfinder implements Runnable{
}
}
//every 100 iterations, check the time spent - this prevents extra calls to nano time, which itself is slow
//every N iterations, check the time spent - this prevents extra calls to nano time, which itself is slow
if(nsToRun >= 0 && (counter++) >= 200){
counter = 0;
if(Time.timeSinceNanos(start) >= nsToRun){

View File

@@ -2782,7 +2782,7 @@ public class UnitTypes{
speed = 1.1f;
hitSize = 44f;
health = 18000;
armor = 8f;
armor = 9f;
rotateSpeed = 1.6f;
lockLegBase = true;
legContinuousMove = true;
@@ -2849,7 +2849,7 @@ public class UnitTypes{
}});
}
bullet = new BasicBulletType(9f, 75){{
bullet = new BasicBulletType(9f, 85){{
pierceCap = 2;
pierceBuilding = true;