This commit is contained in:
theashtronaut 2024-10-22 22:13:44 +02:00 committed by GitHub
commit 20a1275059
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 44 additions and 0 deletions

View File

@ -549,6 +549,14 @@ bool AStar3D::is_point_disabled(int64_t p_id) const {
return !p->enabled;
}
real_t AStar3D::get_last_cost() const {
if (last_closest_point == nullptr) {
return -1;
}
return last_closest_point->g_score;
}
void AStar3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar3D::get_available_point_id);
ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar3D::add_point, DEFVAL(1.0));
@ -560,6 +568,7 @@ void AStar3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar3D::has_point);
ClassDB::bind_method(D_METHOD("get_point_connections", "id"), &AStar3D::get_point_connections);
ClassDB::bind_method(D_METHOD("get_point_ids"), &AStar3D::get_point_ids);
ClassDB::bind_method(D_METHOD("get_last_cost"), &AStar3D::get_last_cost);
ClassDB::bind_method(D_METHOD("set_point_disabled", "id", "disabled"), &AStar3D::set_point_disabled, DEFVAL(true));
ClassDB::bind_method(D_METHOD("is_point_disabled", "id"), &AStar3D::is_point_disabled);
@ -888,6 +897,10 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point, boo
return found_route;
}
real_t AStar2D::get_last_cost() const {
return astar.get_last_cost();
}
void AStar2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar2D::get_available_point_id);
ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar2D::add_point, DEFVAL(1.0));
@ -899,6 +912,7 @@ void AStar2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar2D::has_point);
ClassDB::bind_method(D_METHOD("get_point_connections", "id"), &AStar2D::get_point_connections);
ClassDB::bind_method(D_METHOD("get_point_ids"), &AStar2D::get_point_ids);
ClassDB::bind_method(D_METHOD("get_last_cost"), &AStar2D::get_last_cost);
ClassDB::bind_method(D_METHOD("set_point_disabled", "id", "disabled"), &AStar2D::set_point_disabled, DEFVAL(true));
ClassDB::bind_method(D_METHOD("is_point_disabled", "id"), &AStar2D::is_point_disabled);

View File

@ -144,6 +144,7 @@ public:
bool has_point(int64_t p_id) const;
Vector<int64_t> get_point_connections(int64_t p_id);
PackedInt64Array get_point_ids();
real_t get_last_cost() const;
void set_point_disabled(int64_t p_id, bool p_disabled = true);
bool is_point_disabled(int64_t p_id) const;
@ -200,6 +201,7 @@ public:
bool has_point(int64_t p_id) const;
Vector<int64_t> get_point_connections(int64_t p_id);
PackedInt64Array get_point_ids();
real_t get_last_cost() const;
void set_point_disabled(int64_t p_id, bool p_disabled = true);
bool is_point_disabled(int64_t p_id) const;

View File

@ -734,6 +734,14 @@ TypedArray<Vector2i> AStarGrid2D::get_id_path(const Vector2i &p_from_id, const V
return path;
}
real_t AStarGrid2D::get_last_cost() const {
if (last_closest_point == nullptr) {
return -1;
}
return last_closest_point->g_score;
}
void AStarGrid2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_region", "region"), &AStarGrid2D::set_region);
ClassDB::bind_method(D_METHOD("get_region"), &AStarGrid2D::get_region);
@ -769,6 +777,7 @@ void AStarGrid2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_point_data_in_region", "region"), &AStarGrid2D::get_point_data_in_region);
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_last_cost"), &AStarGrid2D::get_last_cost);
GDVIRTUAL_BIND(_estimate_cost, "from_id", "end_id")
GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id")

View File

@ -226,6 +226,7 @@ public:
TypedArray<Dictionary> get_point_data_in_region(const Rect2i &p_region) const;
Vector<Vector2> get_point_path(const Vector2i &p_from, const Vector2i &p_to, bool p_allow_partial_path = false);
TypedArray<Vector2i> get_id_path(const Vector2i &p_from, const Vector2i &p_to, bool p_allow_partial_path = false);
real_t get_last_cost() const;
};
VARIANT_ENUM_CAST(AStarGrid2D::DiagonalMode);

View File

@ -176,6 +176,12 @@
If you change the 2nd point's weight to 3, then the result will be [code][1, 4, 3][/code] instead, because now even though the distance is longer, it's "easier" to get through point 4 than through point 2.
</description>
</method>
<method name="get_last_cost" qualifiers="const">
<return type="float" />
<description>
Returns the total cost of the last path found through [method get_id_path] or [method get_point_path]. Returns -1 if there was no last path calculated.
</description>
</method>
<method name="get_point_capacity" qualifiers="const">
<return type="int" />
<description>

View File

@ -204,6 +204,12 @@
If you change the 2nd point's weight to 3, then the result will be [code][1, 4, 3][/code] instead, because now even though the distance is longer, it's "easier" to get through point 4 than through point 2.
</description>
</method>
<method name="get_last_cost" qualifiers="const">
<return type="float" />
<description>
Returns the total cost of the last path found through [method get_id_path] or [method get_point_path]. Returns -1 if there was no last path calculated.
</description>
</method>
<method name="get_point_capacity" qualifiers="const">
<return type="int" />
<description>

View File

@ -82,6 +82,12 @@
[b]Note:[/b] When [param allow_partial_path] is [code]true[/code] and [param to_id] is solid the search may take an unusually long time to finish.
</description>
</method>
<method name="get_last_cost" qualifiers="const">
<return type="float" />
<description>
Returns the total cost of the last path found through [method get_id_path] or [method get_point_path]. Returns -1 if there was no last path calculated.
</description>
</method>
<method name="get_point_data_in_region" qualifiers="const">
<return type="Dictionary[]" />
<param index="0" name="region" type="Rect2i" />