summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2021-08-11 16:23:14 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2021-08-11 18:18:10 +0800
commit60298328caa445dee7c562fedbefec990b292f5a (patch)
tree1d21a462def85bd943cdcb4c6ff62fee324d939e /scene
parenta902f760634432adcb5f74b3b6cd27a7275a320f (diff)
Improve NavigationMesh typing, parameter validation and documentation
Diffstat (limited to 'scene')
-rw-r--r--scene/resources/navigation_mesh.cpp60
-rw-r--r--scene/resources/navigation_mesh.h16
2 files changed, 50 insertions, 26 deletions
diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp
index ddc50c0490..3c3c643367 100644
--- a/scene/resources/navigation_mesh.cpp
+++ b/scene/resources/navigation_mesh.cpp
@@ -64,22 +64,22 @@ void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) {
}
}
-void NavigationMesh::set_sample_partition_type(int p_value) {
- ERR_FAIL_COND(p_value >= SAMPLE_PARTITION_MAX);
- partition_type = static_cast<SamplePartitionType>(p_value);
+void NavigationMesh::set_sample_partition_type(SamplePartitionType p_value) {
+ ERR_FAIL_INDEX(p_value, SAMPLE_PARTITION_MAX);
+ partition_type = p_value;
}
-int NavigationMesh::get_sample_partition_type() const {
- return static_cast<int>(partition_type);
+NavigationMesh::SamplePartitionType NavigationMesh::get_sample_partition_type() const {
+ return partition_type;
}
-void NavigationMesh::set_parsed_geometry_type(int p_value) {
- ERR_FAIL_COND(p_value >= PARSED_GEOMETRY_MAX);
- parsed_geometry_type = static_cast<ParsedGeometryType>(p_value);
+void NavigationMesh::set_parsed_geometry_type(ParsedGeometryType p_value) {
+ ERR_FAIL_INDEX(p_value, PARSED_GEOMETRY_MAX);
+ parsed_geometry_type = p_value;
notify_property_list_changed();
}
-int NavigationMesh::get_parsed_geometry_type() const {
+NavigationMesh::ParsedGeometryType NavigationMesh::get_parsed_geometry_type() const {
return parsed_geometry_type;
}
@@ -107,13 +107,13 @@ bool NavigationMesh::get_collision_mask_bit(int p_bit) const {
return get_collision_mask() & (1 << p_bit);
}
-void NavigationMesh::set_source_geometry_mode(int p_geometry_mode) {
+void NavigationMesh::set_source_geometry_mode(SourceGeometryMode p_geometry_mode) {
ERR_FAIL_INDEX(p_geometry_mode, SOURCE_GEOMETRY_MAX);
- source_geometry_mode = static_cast<SourceGeometryMode>(p_geometry_mode);
+ source_geometry_mode = p_geometry_mode;
notify_property_list_changed();
}
-int NavigationMesh::get_source_geometry_mode() const {
+NavigationMesh::SourceGeometryMode NavigationMesh::get_source_geometry_mode() const {
return source_geometry_mode;
}
@@ -126,6 +126,7 @@ StringName NavigationMesh::get_source_group_name() const {
}
void NavigationMesh::set_cell_size(float p_value) {
+ ERR_FAIL_COND(p_value <= 0);
cell_size = p_value;
}
@@ -134,6 +135,7 @@ float NavigationMesh::get_cell_size() const {
}
void NavigationMesh::set_cell_height(float p_value) {
+ ERR_FAIL_COND(p_value <= 0);
cell_height = p_value;
}
@@ -142,6 +144,7 @@ float NavigationMesh::get_cell_height() const {
}
void NavigationMesh::set_agent_height(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
agent_height = p_value;
}
@@ -150,6 +153,7 @@ float NavigationMesh::get_agent_height() const {
}
void NavigationMesh::set_agent_radius(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
agent_radius = p_value;
}
@@ -158,6 +162,7 @@ float NavigationMesh::get_agent_radius() {
}
void NavigationMesh::set_agent_max_climb(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
agent_max_climb = p_value;
}
@@ -166,6 +171,7 @@ float NavigationMesh::get_agent_max_climb() const {
}
void NavigationMesh::set_agent_max_slope(float p_value) {
+ ERR_FAIL_COND(p_value < 0 || p_value > 90);
agent_max_slope = p_value;
}
@@ -174,6 +180,7 @@ float NavigationMesh::get_agent_max_slope() const {
}
void NavigationMesh::set_region_min_size(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
region_min_size = p_value;
}
@@ -182,6 +189,7 @@ float NavigationMesh::get_region_min_size() const {
}
void NavigationMesh::set_region_merge_size(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
region_merge_size = p_value;
}
@@ -190,6 +198,7 @@ float NavigationMesh::get_region_merge_size() const {
}
void NavigationMesh::set_edge_max_length(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
edge_max_length = p_value;
}
@@ -198,6 +207,7 @@ float NavigationMesh::get_edge_max_length() const {
}
void NavigationMesh::set_edge_max_error(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
edge_max_error = p_value;
}
@@ -206,6 +216,7 @@ float NavigationMesh::get_edge_max_error() const {
}
void NavigationMesh::set_verts_per_poly(float p_value) {
+ ERR_FAIL_COND(p_value < 3);
verts_per_poly = p_value;
}
@@ -214,6 +225,7 @@ float NavigationMesh::get_verts_per_poly() const {
}
void NavigationMesh::set_detail_sample_distance(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
detail_sample_distance = p_value;
}
@@ -222,6 +234,7 @@ float NavigationMesh::get_detail_sample_distance() const {
}
void NavigationMesh::set_detail_sample_max_error(float p_value) {
+ ERR_FAIL_COND(p_value < 0);
detail_sample_max_error = p_value;
}
@@ -460,14 +473,6 @@ void NavigationMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationMesh::_set_polygons);
ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationMesh::_get_polygons);
- BIND_CONSTANT(SAMPLE_PARTITION_WATERSHED);
- BIND_CONSTANT(SAMPLE_PARTITION_MONOTONE);
- BIND_CONSTANT(SAMPLE_PARTITION_LAYERS);
-
- BIND_CONSTANT(PARSED_GEOMETRY_MESH_INSTANCES);
- BIND_CONSTANT(PARSED_GEOMETRY_STATIC_COLLIDERS);
- BIND_CONSTANT(PARSED_GEOMETRY_BOTH);
-
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices", "get_vertices");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons");
@@ -494,6 +499,21 @@ void NavigationMesh::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/low_hanging_obstacles"), "set_filter_low_hanging_obstacles", "get_filter_low_hanging_obstacles");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/ledge_spans"), "set_filter_ledge_spans", "get_filter_ledge_spans");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/filter_walkable_low_height_spans"), "set_filter_walkable_low_height_spans", "get_filter_walkable_low_height_spans");
+
+ BIND_ENUM_CONSTANT(SAMPLE_PARTITION_WATERSHED);
+ BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MONOTONE);
+ BIND_ENUM_CONSTANT(SAMPLE_PARTITION_LAYERS);
+ BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MAX);
+
+ BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MESH_INSTANCES);
+ BIND_ENUM_CONSTANT(PARSED_GEOMETRY_STATIC_COLLIDERS);
+ BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH);
+ BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX);
+
+ BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_NAVMESH_CHILDREN);
+ BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN);
+ BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT);
+ BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX);
}
void NavigationMesh::_validate_property(PropertyInfo &property) const {
diff --git a/scene/resources/navigation_mesh.h b/scene/resources/navigation_mesh.h
index 966221c7c6..99b2b6ff58 100644
--- a/scene/resources/navigation_mesh.h
+++ b/scene/resources/navigation_mesh.h
@@ -109,11 +109,11 @@ protected:
public:
// Recast settings
- void set_sample_partition_type(int p_value);
- int get_sample_partition_type() const;
+ void set_sample_partition_type(SamplePartitionType p_value);
+ SamplePartitionType get_sample_partition_type() const;
- void set_parsed_geometry_type(int p_value);
- int get_parsed_geometry_type() const;
+ void set_parsed_geometry_type(ParsedGeometryType p_value);
+ ParsedGeometryType get_parsed_geometry_type() const;
void set_collision_mask(uint32_t p_mask);
uint32_t get_collision_mask() const;
@@ -121,8 +121,8 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
- void set_source_geometry_mode(int p_geometry_mode);
- int get_source_geometry_mode() const;
+ void set_source_geometry_mode(SourceGeometryMode p_geometry_mode);
+ SourceGeometryMode get_source_geometry_mode() const;
void set_source_group_name(StringName p_group_name);
StringName get_source_group_name() const;
@@ -190,4 +190,8 @@ public:
NavigationMesh();
};
+VARIANT_ENUM_CAST(NavigationMesh::SamplePartitionType);
+VARIANT_ENUM_CAST(NavigationMesh::ParsedGeometryType);
+VARIANT_ENUM_CAST(NavigationMesh::SourceGeometryMode);
+
#endif // NAVIGATION_MESH_H