Add navigation path query parameter limits

Adds navigation path query parameter limits.
This commit is contained in:
smix8
2025-02-08 22:08:04 +01:00
parent 591e70ff78
commit cbd446ac29
23 changed files with 698 additions and 0 deletions

View File

@@ -95,6 +95,20 @@ void NavigationAgent2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_simplify_epsilon", "epsilon"), &NavigationAgent2D::set_simplify_epsilon);
ClassDB::bind_method(D_METHOD("get_simplify_epsilon"), &NavigationAgent2D::get_simplify_epsilon);
ClassDB::bind_method(D_METHOD("set_path_return_max_length", "length"), &NavigationAgent2D::set_path_return_max_length);
ClassDB::bind_method(D_METHOD("get_path_return_max_length"), &NavigationAgent2D::get_path_return_max_length);
ClassDB::bind_method(D_METHOD("set_path_return_max_radius", "radius"), &NavigationAgent2D::set_path_return_max_radius);
ClassDB::bind_method(D_METHOD("get_path_return_max_radius"), &NavigationAgent2D::get_path_return_max_radius);
ClassDB::bind_method(D_METHOD("set_path_search_max_polygons", "max_polygons"), &NavigationAgent2D::set_path_search_max_polygons);
ClassDB::bind_method(D_METHOD("get_path_search_max_polygons"), &NavigationAgent2D::get_path_search_max_polygons);
ClassDB::bind_method(D_METHOD("set_path_search_max_distance", "distance"), &NavigationAgent2D::set_path_search_max_distance);
ClassDB::bind_method(D_METHOD("get_path_search_max_distance"), &NavigationAgent2D::get_path_search_max_distance);
ClassDB::bind_method(D_METHOD("get_path_length"), &NavigationAgent2D::get_path_length);
ClassDB::bind_method(D_METHOD("get_next_path_position"), &NavigationAgent2D::get_next_path_position);
ClassDB::bind_method(D_METHOD("set_velocity_forced", "velocity"), &NavigationAgent2D::set_velocity_forced);
@@ -137,6 +151,10 @@ void NavigationAgent2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "path_metadata_flags", PROPERTY_HINT_FLAGS, "Include Types,Include RIDs,Include Owners"), "set_path_metadata_flags", "get_path_metadata_flags");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "simplify_path"), "set_simplify_path", "get_simplify_path");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "simplify_epsilon", PROPERTY_HINT_RANGE, "0.0,10.0,0.001,or_greater,suffix:px"), "set_simplify_epsilon", "get_simplify_epsilon");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_return_max_length", PROPERTY_HINT_RANGE, "0.0,10240.0,0.001,or_greater,suffix:px"), "set_path_return_max_length", "get_path_return_max_length");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_return_max_radius", PROPERTY_HINT_RANGE, "0.0,10240.0,0.001,or_greater,suffix:px"), "set_path_return_max_radius", "get_path_return_max_radius");
ADD_PROPERTY(PropertyInfo(Variant::INT, "path_search_max_polygons", PROPERTY_HINT_RANGE, "0,4096,1,or_greater"), "set_path_search_max_polygons", "get_path_search_max_polygons");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_search_max_distance"), "set_path_search_max_distance", "get_path_search_max_distance");
ADD_GROUP("Avoidance", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "avoidance_enabled"), "set_avoidance_enabled", "get_avoidance_enabled");
@@ -461,6 +479,46 @@ real_t NavigationAgent2D::get_simplify_epsilon() const {
return simplify_epsilon;
}
void NavigationAgent2D::set_path_return_max_length(float p_length) {
path_return_max_length = MAX(0.0, p_length);
navigation_query->set_path_return_max_length(path_return_max_length);
}
float NavigationAgent2D::get_path_return_max_length() const {
return path_return_max_length;
}
void NavigationAgent2D::set_path_return_max_radius(float p_radius) {
path_return_max_radius = MAX(0.0, p_radius);
navigation_query->set_path_return_max_radius(path_return_max_radius);
}
float NavigationAgent2D::get_path_return_max_radius() const {
return path_return_max_radius;
}
void NavigationAgent2D::set_path_search_max_polygons(int p_max_polygons) {
path_search_max_polygons = p_max_polygons;
navigation_query->set_path_search_max_polygons(path_search_max_polygons);
}
int NavigationAgent2D::get_path_search_max_polygons() const {
return path_search_max_polygons;
}
void NavigationAgent2D::set_path_search_max_distance(float p_distance) {
path_search_max_distance = MAX(0.0, p_distance);
navigation_query->set_path_search_max_distance(path_search_max_distance);
}
float NavigationAgent2D::get_path_search_max_distance() const {
return path_search_max_distance;
}
float NavigationAgent2D::get_path_length() const {
return navigation_result->get_path_length();
}
void NavigationAgent2D::set_path_metadata_flags(BitField<NavigationPathQueryParameters2D::PathMetadataFlags> p_path_metadata_flags) {
if (path_metadata_flags == p_path_metadata_flags) {
return;

View File

@@ -65,6 +65,10 @@ class NavigationAgent2D : public Node {
real_t path_max_distance = 100.0;
bool simplify_path = false;
real_t simplify_epsilon = 0.0;
float path_return_max_length = 0.0;
float path_return_max_radius = 0.0;
int path_search_max_polygons = NavigationDefaults2D::path_search_max_polygons;
float path_search_max_distance = 0.0;
Vector2 target_position;
@@ -185,6 +189,20 @@ public:
void set_simplify_epsilon(real_t p_epsilon);
real_t get_simplify_epsilon() const;
void set_path_return_max_length(float p_length);
float get_path_return_max_length() const;
void set_path_return_max_radius(float p_radius);
float get_path_return_max_radius() const;
void set_path_search_max_polygons(int p_max_polygons);
int get_path_search_max_polygons() const;
void set_path_search_max_distance(float p_distance);
float get_path_search_max_distance() const;
float get_path_length() const;
Vector2 get_next_path_position();
Ref<NavigationPathQueryResult2D> get_current_navigation_result() const { return navigation_result; }