Merge pull request #92123 from timothyqiu/estimate-end

Change param name of AStar's `_estimate_cost` method
This commit is contained in:
Rémi Verschelde 2024-08-28 00:10:47 +02:00
commit 1e6b6eaf49
No known key found for this signature in database
GPG Key ID: C3336907360768E1
7 changed files with 24 additions and 24 deletions

View File

@ -391,9 +391,9 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) {
return found_route; return found_route;
} }
real_t AStar3D::_estimate_cost(int64_t p_from_id, int64_t p_to_id) { real_t AStar3D::_estimate_cost(int64_t p_from_id, int64_t p_end_id) {
real_t scost; real_t scost;
if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_to_id, scost)) { if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_end_id, scost)) {
return scost; return scost;
} }
@ -401,11 +401,11 @@ real_t AStar3D::_estimate_cost(int64_t p_from_id, int64_t p_to_id) {
bool from_exists = points.lookup(p_from_id, from_point); bool from_exists = points.lookup(p_from_id, from_point);
ERR_FAIL_COND_V_MSG(!from_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_from_id)); ERR_FAIL_COND_V_MSG(!from_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_from_id));
Point *to_point = nullptr; Point *end_point = nullptr;
bool to_exists = points.lookup(p_to_id, to_point); bool end_exists = points.lookup(p_end_id, end_point);
ERR_FAIL_COND_V_MSG(!to_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_to_id)); ERR_FAIL_COND_V_MSG(!end_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_end_id));
return from_point->pos.distance_to(to_point->pos); return from_point->pos.distance_to(end_point->pos);
} }
real_t AStar3D::_compute_cost(int64_t p_from_id, int64_t p_to_id) { real_t AStar3D::_compute_cost(int64_t p_from_id, int64_t p_to_id) {
@ -579,7 +579,7 @@ void AStar3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id", "allow_partial_path"), &AStar3D::get_point_path, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id", "allow_partial_path"), &AStar3D::get_point_path, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id", "allow_partial_path"), &AStar3D::get_id_path, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id", "allow_partial_path"), &AStar3D::get_id_path, DEFVAL(false));
GDVIRTUAL_BIND(_estimate_cost, "from_id", "to_id") GDVIRTUAL_BIND(_estimate_cost, "from_id", "end_id")
GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id") GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id")
} }
@ -675,9 +675,9 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const {
return Vector2(p.x, p.y); return Vector2(p.x, p.y);
} }
real_t AStar2D::_estimate_cost(int64_t p_from_id, int64_t p_to_id) { real_t AStar2D::_estimate_cost(int64_t p_from_id, int64_t p_end_id) {
real_t scost; real_t scost;
if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_to_id, scost)) { if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_end_id, scost)) {
return scost; return scost;
} }
@ -685,11 +685,11 @@ real_t AStar2D::_estimate_cost(int64_t p_from_id, int64_t p_to_id) {
bool from_exists = astar.points.lookup(p_from_id, from_point); bool from_exists = astar.points.lookup(p_from_id, from_point);
ERR_FAIL_COND_V_MSG(!from_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_from_id)); ERR_FAIL_COND_V_MSG(!from_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_from_id));
AStar3D::Point *to_point = nullptr; AStar3D::Point *end_point = nullptr;
bool to_exists = astar.points.lookup(p_to_id, to_point); bool to_exists = astar.points.lookup(p_end_id, end_point);
ERR_FAIL_COND_V_MSG(!to_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_to_id)); ERR_FAIL_COND_V_MSG(!to_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_end_id));
return from_point->pos.distance_to(to_point->pos); return from_point->pos.distance_to(end_point->pos);
} }
real_t AStar2D::_compute_cost(int64_t p_from_id, int64_t p_to_id) { real_t AStar2D::_compute_cost(int64_t p_from_id, int64_t p_to_id) {
@ -918,6 +918,6 @@ void AStar2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id", "allow_partial_path"), &AStar2D::get_point_path, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id", "allow_partial_path"), &AStar2D::get_point_path, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id", "allow_partial_path"), &AStar2D::get_id_path, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id", "allow_partial_path"), &AStar2D::get_id_path, DEFVAL(false));
GDVIRTUAL_BIND(_estimate_cost, "from_id", "to_id") GDVIRTUAL_BIND(_estimate_cost, "from_id", "end_id")
GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id") GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id")
} }

View File

@ -120,7 +120,7 @@ class AStar3D : public RefCounted {
protected: protected:
static void _bind_methods(); static void _bind_methods();
virtual real_t _estimate_cost(int64_t p_from_id, int64_t p_to_id); virtual real_t _estimate_cost(int64_t p_from_id, int64_t p_end_id);
virtual real_t _compute_cost(int64_t p_from_id, int64_t p_to_id); virtual real_t _compute_cost(int64_t p_from_id, int64_t p_to_id);
GDVIRTUAL2RC(real_t, _estimate_cost, int64_t, int64_t) GDVIRTUAL2RC(real_t, _estimate_cost, int64_t, int64_t)
@ -176,7 +176,7 @@ class AStar2D : public RefCounted {
protected: protected:
static void _bind_methods(); static void _bind_methods();
virtual real_t _estimate_cost(int64_t p_from_id, int64_t p_to_id); virtual real_t _estimate_cost(int64_t p_from_id, int64_t p_end_id);
virtual real_t _compute_cost(int64_t p_from_id, int64_t p_to_id); virtual real_t _compute_cost(int64_t p_from_id, int64_t p_to_id);
GDVIRTUAL2RC(real_t, _estimate_cost, int64_t, int64_t) GDVIRTUAL2RC(real_t, _estimate_cost, int64_t, int64_t)

View File

@ -535,12 +535,12 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) {
return found_route; return found_route;
} }
real_t AStarGrid2D::_estimate_cost(const Vector2i &p_from_id, const Vector2i &p_to_id) { real_t AStarGrid2D::_estimate_cost(const Vector2i &p_from_id, const Vector2i &p_end_id) {
real_t scost; real_t scost;
if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_to_id, scost)) { if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_end_id, scost)) {
return scost; return scost;
} }
return heuristics[default_estimate_heuristic](p_from_id, p_to_id); return heuristics[default_estimate_heuristic](p_from_id, p_end_id);
} }
real_t AStarGrid2D::_compute_cost(const Vector2i &p_from_id, const Vector2i &p_to_id) { real_t AStarGrid2D::_compute_cost(const Vector2i &p_from_id, const Vector2i &p_to_id) {
@ -729,7 +729,7 @@ void AStarGrid2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id", "allow_partial_path"), &AStarGrid2D::get_point_path, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id", "allow_partial_path"), &AStarGrid2D::get_point_path, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id", "allow_partial_path"), &AStarGrid2D::get_id_path, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id", "allow_partial_path"), &AStarGrid2D::get_id_path, DEFVAL(false));
GDVIRTUAL_BIND(_estimate_cost, "from_id", "to_id") GDVIRTUAL_BIND(_estimate_cost, "from_id", "end_id")
GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id") GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id")
ADD_PROPERTY(PropertyInfo(Variant::RECT2I, "region"), "set_region", "get_region"); ADD_PROPERTY(PropertyInfo(Variant::RECT2I, "region"), "set_region", "get_region");

View File

@ -151,7 +151,7 @@ private: // Internal routines.
protected: protected:
static void _bind_methods(); static void _bind_methods();
virtual real_t _estimate_cost(const Vector2i &p_from_id, const Vector2i &p_to_id); virtual real_t _estimate_cost(const Vector2i &p_from_id, const Vector2i &p_end_id);
virtual real_t _compute_cost(const Vector2i &p_from_id, const Vector2i &p_to_id); virtual real_t _compute_cost(const Vector2i &p_from_id, const Vector2i &p_to_id);
GDVIRTUAL2RC(real_t, _estimate_cost, Vector2i, Vector2i) GDVIRTUAL2RC(real_t, _estimate_cost, Vector2i, Vector2i)

View File

@ -22,7 +22,7 @@
<method name="_estimate_cost" qualifiers="virtual const"> <method name="_estimate_cost" qualifiers="virtual const">
<return type="float" /> <return type="float" />
<param index="0" name="from_id" type="int" /> <param index="0" name="from_id" type="int" />
<param index="1" name="to_id" type="int" /> <param index="1" name="end_id" type="int" />
<description> <description>
Called when estimating the cost between a point and the path's ending point. Called when estimating the cost between a point and the path's ending point.
Note that this function is hidden in the default [AStar2D] class. Note that this function is hidden in the default [AStar2D] class.

View File

@ -51,7 +51,7 @@
<method name="_estimate_cost" qualifiers="virtual const"> <method name="_estimate_cost" qualifiers="virtual const">
<return type="float" /> <return type="float" />
<param index="0" name="from_id" type="int" /> <param index="0" name="from_id" type="int" />
<param index="1" name="to_id" type="int" /> <param index="1" name="end_id" type="int" />
<description> <description>
Called when estimating the cost between a point and the path's ending point. Called when estimating the cost between a point and the path's ending point.
Note that this function is hidden in the default [AStar3D] class. Note that this function is hidden in the default [AStar3D] class.

View File

@ -41,7 +41,7 @@
<method name="_estimate_cost" qualifiers="virtual const"> <method name="_estimate_cost" qualifiers="virtual const">
<return type="float" /> <return type="float" />
<param index="0" name="from_id" type="Vector2i" /> <param index="0" name="from_id" type="Vector2i" />
<param index="1" name="to_id" type="Vector2i" /> <param index="1" name="end_id" type="Vector2i" />
<description> <description>
Called when estimating the cost between a point and the path's ending point. Called when estimating the cost between a point and the path's ending point.
Note that this function is hidden in the default [AStarGrid2D] class. Note that this function is hidden in the default [AStarGrid2D] class.