diff --git a/build/rtsgame/map.core b/build/rtsgame/map.core index f371d95..601e351 100644 --- a/build/rtsgame/map.core +++ b/build/rtsgame/map.core @@ -138,7 +138,6 @@ MAP_RecomputeHistory :: (s: *MAP_Actor) Reset(&s.history) it := GetLast(&s.close_paths) Add(&s.history, *it) - Pop(&s.history) for i := 0,,i += 1 if it.p.x == s.p.x && it.p.y == s.p.y ;; break if i > 512 @@ -172,7 +171,9 @@ MAP_PathFindUpdate :: (map: *MAP_Map) Reset(&s.history) break -MAP_PathFindStep :: (s: *MAP_Actor) + MAP_PathFind(s) + +MAP_PathFindStep :: (s: *MAP_Actor, compute_history: bool = true): bool if s.open_paths.len == 0 // Reset if we didnt find solution if s.close_paths.len != 0 @@ -189,7 +190,7 @@ MAP_PathFindStep :: (s: *MAP_Actor) last := GetLast(&s.close_paths) reached_target := last.p.x == s.target_p.x && last.p.y == s.target_p.y if reached_target - return + return true it := Pop(&s.open_paths) Add(&s.close_paths, it) @@ -204,4 +205,11 @@ MAP_PathFindStep :: (s: *MAP_Actor) p := V2I{it.p.x + x, it.p.y + y} MAP_InsertOpenPath(s, p, it.p) + if compute_history ;; MAP_RecomputeHistory(s) + return false + +MAP_PathFind :: (s: *MAP_Actor) + for i := 0, i < 128, i += 1 + done := MAP_PathFindStep(s, false) + if done ;; break MAP_RecomputeHistory(s)