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
+11 -13
View File
@@ -45,9 +45,7 @@ public class ControlPathfinder implements Runnable{
//static access probably faster than object access //static access probably faster than object access
static int wwidth, wheight; static int wwidth, wheight;
//increments each tile change
//MAIN THREAD DATA
static volatile int worldUpdateId; static volatile int worldUpdateId;
/** Current pathfinding thread */ /** Current pathfinding thread */
@@ -56,9 +54,10 @@ public class ControlPathfinder implements Runnable{
int lastTargetId = 1; int lastTargetId = 1;
/** handles task scheduling on the update thread. */ /** handles task scheduling on the update thread. */
TaskQueue queue = new TaskQueue(); TaskQueue queue = new TaskQueue();
/** requests per-unit */
ObjectMap<Unit, PathRequest> requests = new ObjectMap<>(); ObjectMap<Unit, PathRequest> requests = new ObjectMap<>();
//PATHFINDING THREAD DATA /** pathfinding thread access only! */
Seq<PathRequest> threadRequests = new Seq<>(); Seq<PathRequest> threadRequests = new Seq<>();
public ControlPathfinder(){ public ControlPathfinder(){
@@ -149,7 +148,7 @@ public class ControlPathfinder implements Runnable{
var req = new PathRequest(); var req = new PathRequest();
req.unit = unit; req.unit = unit;
req.pathType = pathType; req.pathType = pathType;
req.destination = destination; req.destination.set(destination);
req.curId = pathId; req.curId = pathId;
req.lastUpdateId = state.updateId; req.lastUpdateId = state.updateId;
req.lastWorldUpdate = worldUpdateId; req.lastWorldUpdate = worldUpdateId;
@@ -168,7 +167,7 @@ public class ControlPathfinder implements Runnable{
req.foundEnd = false; req.foundEnd = false;
} }
req.destination = destination; req.destination.set(destination);
req.curId = pathId; req.curId = pathId;
if(req.done){ if(req.done){
@@ -366,11 +365,12 @@ public class ControlPathfinder implements Runnable{
volatile boolean done = false; volatile boolean done = false;
volatile boolean foundEnd = false; volatile boolean foundEnd = false;
final Vec2 destination = new Vec2();
final Vec2 lastDestination = new Vec2();
volatile Unit unit; volatile Unit unit;
volatile int pathType; volatile int pathType;
volatile Vec2 destination;
volatile int lastWorldUpdate; volatile int lastWorldUpdate;
volatile float stuckTime;
//TODO only access on main thread?? //TODO only access on main thread??
int pathIndex; int pathIndex;
@@ -400,7 +400,7 @@ public class ControlPathfinder implements Runnable{
lastId = curId; lastId = curId;
//re-do everything when world updates //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(); lastTime = Time.millis();
lastWorldUpdate = worldUpdateId; lastWorldUpdate = worldUpdateId;
pathIndex = 0; pathIndex = 0;
@@ -496,7 +496,7 @@ public class ControlPathfinder implements Runnable{
void clear(){ void clear(){
done = false; done = false;
//TODO horribly expensive //TODO could be less expensive?
frontier = new PathfindQueue(20); frontier = new PathfindQueue(20);
cameFrom.clear(); cameFrom.clear();
costs.clear(); costs.clear();
@@ -511,9 +511,7 @@ public class ControlPathfinder implements Runnable{
foundEnd = false; foundEnd = false;
result.clear(); result.clear();
lastDestination.set(destination);
//closed = new GridBits(world.width(), world.height());
//queue = new PathfindQueue(16);
} }
} }
} }
+2 -4
View File
@@ -215,9 +215,7 @@ public class Pathfinder implements Runnable{
return; return;
} }
}catch(Throwable e){ }catch(Throwable e){
//TODO remove in production! e.printStackTrace();
Threads.throwAppException(e);
//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){ if(nsToRun >= 0 && (counter++) >= 200){
counter = 0; counter = 0;
if(Time.timeSinceNanos(start) >= nsToRun){ if(Time.timeSinceNanos(start) >= nsToRun){
+2 -2
View File
@@ -2782,7 +2782,7 @@ public class UnitTypes{
speed = 1.1f; speed = 1.1f;
hitSize = 44f; hitSize = 44f;
health = 18000; health = 18000;
armor = 8f; armor = 9f;
rotateSpeed = 1.6f; rotateSpeed = 1.6f;
lockLegBase = true; lockLegBase = true;
legContinuousMove = true; legContinuousMove = true;
@@ -2849,7 +2849,7 @@ public class UnitTypes{
}}); }});
} }
bullet = new BasicBulletType(9f, 75){{ bullet = new BasicBulletType(9f, 85){{
pierceCap = 2; pierceCap = 2;
pierceBuilding = true; pierceBuilding = true;