diff options
Diffstat (limited to 'core/math/a_star.cpp')
-rw-r--r-- | core/math/a_star.cpp | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index a85a0e9db9..45c4a207c3 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -154,8 +154,9 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) { } Segment s(p_id, p_with_id); - if (bidirectional) + if (bidirectional) { s.direction = Segment::BIDIRECTIONAL; + } Set<Segment>::Element *element = segments.find(s); if (element != nullptr) { @@ -197,15 +198,17 @@ void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) { b->unlinked_neighbours.remove(a->id); } } else { - if (s.direction == Segment::NONE) + if (s.direction == Segment::NONE) { b->unlinked_neighbours.remove(a->id); - else + } else { a->unlinked_neighbours.set(b->id, b); + } } segments.erase(element); - if (s.direction != Segment::NONE) + if (s.direction != Segment::NONE) { segments.insert(s); + } } } @@ -273,8 +276,9 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co real_t closest_dist = 1e20; for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) { - if (!p_include_disabled && !(*it.value)->enabled) + if (!p_include_disabled && !(*it.value)->enabled) { continue; // Disabled points should not be considered. + } real_t d = p_point.distance_squared_to((*it.value)->pos); if (closest_id < 0 || d < closest_dist) { @@ -320,8 +324,9 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const { bool AStar::_solve(Point *begin_point, Point *end_point) { pass++; - if (!end_point->enabled) + if (!end_point->enabled) { return false; + } bool found_route = false; @@ -379,8 +384,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { } real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) + if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) { return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); + } Point *from_point; bool from_exists = points.lookup(p_from_id, from_point); @@ -394,8 +400,9 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) + if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) { return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); + } Point *from_point; bool from_exists = points.lookup(p_from_id, from_point); @@ -427,8 +434,9 @@ Vector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { Point *end_point = b; bool found_route = _solve(begin_point, end_point); - if (!found_route) + if (!found_route) { return Vector<Vector3>(); + } Point *p = end_point; int pc = 1; // Begin point @@ -475,8 +483,9 @@ Vector<int> AStar::get_id_path(int p_from_id, int p_to_id) { Point *end_point = b; bool found_route = _solve(begin_point, end_point); - if (!found_route) + if (!found_route) { return Vector<int>(); + } Point *p = end_point; int pc = 1; // Begin point @@ -647,8 +656,9 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const { } real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) + if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) { return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); + } AStar::Point *from_point; bool from_exists = astar.points.lookup(p_from_id, from_point); @@ -662,8 +672,9 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) + if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) { return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); + } AStar::Point *from_point; bool from_exists = astar.points.lookup(p_from_id, from_point); @@ -695,8 +706,9 @@ Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) { AStar::Point *end_point = b; bool found_route = _solve(begin_point, end_point); - if (!found_route) + if (!found_route) { return Vector<Vector2>(); + } AStar::Point *p = end_point; int pc = 1; // Begin point @@ -743,8 +755,9 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) { AStar::Point *end_point = b; bool found_route = _solve(begin_point, end_point); - if (!found_route) + if (!found_route) { return Vector<int>(); + } AStar::Point *p = end_point; int pc = 1; // Begin point @@ -775,8 +788,9 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) { bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { astar.pass++; - if (!end_point->enabled) + if (!end_point->enabled) { return false; + } bool found_route = false; |