Bläddra i källkod

Avoid overestimating the cost in AStar heuristics.

This is a necessary condition for finding optimal solutions.
This is achieved by simply requiring/ensuring that no weights are smaller than 1.

Fixes #8584.

(cherry picked from commit e4eb093c62044cdce05ada0e0a42011c7e6628cf)
Ferenc Arn 8 år sedan
förälder
incheckning
89703435a1
2 ändrade filer med 2 tillägg och 1 borttagningar
  1. 1 1
      core/math/a_star.cpp
  2. 1 0
      doc/base/classes.xml

+ 1 - 1
core/math/a_star.cpp

@@ -43,6 +43,7 @@ int AStar::get_available_point_id() const {
 
 void AStar::add_point(int p_id, const Vector3 &p_pos, float p_weight_scale) {
 	ERR_FAIL_COND(p_id < 0);
+	ERR_FAIL_COND(p_weight_scale < 1);
 	if (!points.has(p_id)) {
 		Point *pt = memnew(Point);
 		pt->id = p_id;
@@ -221,7 +222,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
 
 			float cost = p->distance;
 			cost += _estimate_cost(p->id, end_point->id);
-			cost *= p->weight_scale;
 
 			if (cost < least_cost) {
 

+ 1 - 0
doc/base/classes.xml

@@ -2181,6 +2181,7 @@
 			<argument index="1" name="pos" type="Vector3">
 			</argument>
 			<argument index="2" name="weight_scale" type="float" default="1">
+				Weight scale has to be 1 or larger.
 			</argument>
 			<description>
 			</description>