perf(autohunt): avoid discarded A-star searches for attack sight lines
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user