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 struct
(* functor for adding reachable platforms to queue *) (* functor for adding reachable platforms to queue *)
structure FindReachable = structure FindReachable =
MakeQuadFolder struct
(struct
open GameType open GameType
type env = type env =
@@ -237,7 +236,7 @@ struct
else else
(eVals, q) (eVals, q)
end end
end) end
fun filterMinDuplicates (q, eKeys) = fun filterMinDuplicates (q, eKeys) =
let let
@@ -271,6 +270,21 @@ struct
fun getPathList (pID, eID, eKeys, eVals) = fun getPathList (pID, eID, eKeys, eVals) =
helpGetPathList (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) = fun loop (pID, eID, platforms, platformTree, q, eKeys, eVals) =
let let
(* filtering duplicates because we have no decrease-key operation *) (* filtering duplicates because we have no decrease-key operation *)
@@ -318,8 +332,7 @@ struct
(* fold over quad tree, updating any distances (* fold over quad tree, updating any distances
* we find the shortest path for *) * we find the shortest path for *)
val (eVals, q) = FindReachable.foldRegion val (eVals, q) = addPlatforms (0, (eVals, q), env)
(0, 0, ww, 100, 0, 0, ww, wh, env, state, platformTree)
in in
loop (pID, eID, platforms, platformTree, q, eKeys, eVals) loop (pID, eID, platforms, platformTree, q, eKeys, eVals)
end end