perf(autohunt): avoid discarded A-star searches for attack sight lines

This commit is contained in:
shen
2026-10-16 23:14:48 -07:00
parent b9f5d737cb
commit ae0fc25a81
4 changed files with 25 additions and 8 deletions
+4 -1
View File
@@ -35,12 +35,15 @@ inline Point Toward(Point p, Point goal, float body) {
}
// Empty means unreachable within the loaded data/search budget, never permission to walk straight.
inline std::vector<Point> FindPath(Point start, Point goal, float arrival, const Walkable& walkable,
int budget=3500, float body=0.f) {
int budget=3500, float body=0.f, bool directOnly=false) {
if (!std::isfinite(start.x) || !std::isfinite(start.y) || !std::isfinite(goal.x) ||
!std::isfinite(goal.y) || arrival < 0 || body < 0 || budget <= 0 || Distance(start,goal)>40000.f) return {};
auto reaches=[&](Point p) { return Segment(p,Toward(p,goal,body),walkable); };
if (Distance(start,goal) <= arrival && reaches(start)) return {start};
if (reaches(start)) return {Toward(start,goal,body)};
// Attack/skill line checks reject a detour anyway. Do not run a 3500-node
// A* search for each monster in a crowded room just to discard that route.
if (directOnly) return {};
constexpr float cell=100.f;
// Grid is relative to the exact starting position, so the first step cannot cross an unchecked edge.
const int extent = int(std::ceil(Distance(start,goal)/cell))+25;