instead of folding through quad tree to find reachable platforms, fold through platforms instead

This commit is contained in:
2025-01-21 21:20:57 +00:00
parent f948d060ea
commit 72924ae084

View File

@@ -2,8 +2,7 @@ structure PathFinding =
struct
(* functor for adding reachable platforms to queue *)
structure FindReachable =
MakeQuadFolder
(struct
struct
open GameType
type env =
@@ -237,7 +236,7 @@ struct
else
(eVals, q)
end
end)
end
fun filterMinDuplicates (q, eKeys) =
let
@@ -271,6 +270,21 @@ struct
fun getPathList (pID, eID, eKeys, eVals) =
helpGetPathList (pID, eID, eKeys, eVals, [])
fun addPlatforms (pos, (eVals, q), env) =
let
val {platforms, ...} = env
in
if pos = Vector.length platforms then (eVals, q)
else
let
val foldPlat = Vector.sub (platforms, pos)
val foldPlatID = #id foldPlat
val (eVals, q) = FindReachable.fState ((eVals, q), env, foldPlatID)
in
addPlatforms (pos + 1, (eVals, q), env)
end
end
fun loop (pID, eID, platforms, platformTree, q, eKeys, eVals) =
let
(* filtering duplicates because we have no decrease-key operation *)
@@ -318,8 +332,7 @@ struct
(* fold over quad tree, updating any distances
* we find the shortest path for *)
val (eVals, q) = FindReachable.foldRegion
(0, 0, ww, 100, 0, 0, ww, wh, env, state, platformTree)
val (eVals, q) = addPlatforms (0, (eVals, q), env)
in
loop (pID, eID, platforms, platformTree, q, eKeys, eVals)
end