Skip to content

Commit 0646ac1

Browse files
committed
Landing zone map is now using async pathing
1 parent d6f1084 commit 0646ac1

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

Data/Base.rte/Activities/LandingZoneMap.lua

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -483,25 +483,31 @@ function LandingZoneMap.SearchForLZ(self, team, Destination, digStrenght)
483483
end
484484
end
485485

486-
coroutine.yield(); -- wait until next frame
486+
local pathRequestsCompleted = 0;
487+
local completedPathRequests = {};
487488

488489
-- measure the distance to the destination
489490
for k, LZ in pairs(GoodLZs) do
490-
if SceneMan.Scene:CalculatePath(Vector(LZ.X, LZ.Y), Destination, false, digStrenght, team) > -1 then
491-
local Path = {};
492-
for Wpt in SceneMan.Scene:GetScenePath() do
493-
table.insert(Path, Wpt);
494-
end
491+
SceneMan.Scene:CalculatePathAsync(
492+
function(pathRequest)
493+
pathRequestsCompleted = pathRequestsCompleted + 1;
494+
completedPathRequests[k] = pathRequest;
495+
end,
496+
Vector(LZ.X, LZ.Y), Destination, false, digStrenght, team);
497+
end
495498

496-
coroutine.yield(); -- wait until the next frame
499+
while pathRequestsCompleted ~= #GoodLZs do
500+
coroutine.yield(); -- wait until all paths are complete
501+
end
497502

503+
for k, LZ in pairs(GoodLZs) do
504+
pathRequest = completedPathRequests[k];
505+
if pathRequest.PathLength > -1 then
498506
local NextWpt, PrevWpt, deltaY;
499507
local height = 0;
500-
local pathLength = 0;
501508
local pathObstMaxHeight = 0;
502509

503-
for _, Wpt in pairs(Path) do
504-
pathLength = pathLength + 1;
510+
for Wpt in pathRequest.Path do
505511
NextWpt = SceneMan:MovePointToGround(Wpt, 20, 12);
506512

507513
if PrevWpt then
@@ -519,36 +525,27 @@ function LandingZoneMap.SearchForLZ(self, team, Destination, digStrenght)
519525
end
520526

521527
PrevWpt = NextWpt;
522-
if pathLength % 17 == 0 then
523-
coroutine.yield(); -- wait until the next frame
524-
end
525528
end
526529

527530
GoodLZs[k].terrainScore = LZ.score;
528-
GoodLZs[k].pathLength = pathLength;
531+
GoodLZs[k].pathLength = pathRequest.PathLength;
529532
GoodLZs[k].pathObstMaxHeight = pathObstMaxHeight;
530-
GoodLZs[k].score = LZ.score - (pathLength * 0.2 + math.floor(pathObstMaxHeight/15) * 12); -- recalculate the score so we can find a safe LZ that has an easy path to the destination
533+
GoodLZs[k].score = LZ.score - (pathRequest.PathLength * 0.2 + math.floor(pathObstMaxHeight/15) * 12); -- recalculate the score so we can find a safe LZ that has an easy path to the destination
531534
else
532535
-- unknown path
533536
GoodLZs[k].terrainScore = LZ.score;
534537
GoodLZs[k].pathLength = 200;
535538
GoodLZs[k].pathObstMaxHeight = 200;
536539
GoodLZs[k].score = LZ.score - 100;
537540
end
538-
539-
coroutine.yield(); -- wait until the next frame
540541
end
541542

542-
coroutine.yield(); -- wait until the next frame
543-
544543
table.sort(GoodLZs, function(A, B) return A.score > B.score end); -- the best LZ first
545544
local MobilityLZ, selected_index = self:SelectLZ(GoodLZs, 12);
546545
if selected_index then
547546
table.remove(GoodLZs, selected_index); -- don't select this LZ again
548547
end
549548

550-
coroutine.yield(); -- wait until the next frame
551-
552549
-- recalculate the score so we can find a safe LZ that is close to the destination
553550
for k, LZ in pairs(GoodLZs) do
554551
GoodLZs[k].score = LZ.terrainScore - (LZ.pathLength * 0.7 + math.floor(LZ.pathObstMaxHeight/20) * 8);

0 commit comments

Comments
 (0)