diff options
Diffstat (limited to 'scene/resources/navigation_mesh.cpp')
-rw-r--r-- | scene/resources/navigation_mesh.cpp | 92 |
1 files changed, 56 insertions, 36 deletions
diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 0a25bb2ed1..00cee9269b 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; } @@ -91,29 +91,31 @@ uint32_t NavigationMesh::get_collision_mask() const { return collision_mask; } -void NavigationMesh::set_collision_mask_bit(int p_bit, bool p_value) { - ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision mask bit must be between 0 and 31 inclusive."); +void NavigationMesh::set_collision_mask_value(int p_layer_number, bool p_value) { + ERR_FAIL_COND_MSG(p_layer_number < 1, "Collision layer number must be between 1 and 32 inclusive."); + ERR_FAIL_COND_MSG(p_layer_number > 32, "Collision layer number must be between 1 and 32 inclusive."); uint32_t mask = get_collision_mask(); if (p_value) { - mask |= 1 << p_bit; + mask |= 1 << (p_layer_number - 1); } else { - mask &= ~(1 << p_bit); + mask &= ~(1 << (p_layer_number - 1)); } set_collision_mask(mask); } -bool NavigationMesh::get_collision_mask_bit(int p_bit) const { - ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision mask bit must be between 0 and 31 inclusive."); - return get_collision_mask() & (1 << p_bit); +bool NavigationMesh::get_collision_mask_value(int p_layer_number) const { + ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive."); + ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive."); + return get_collision_mask() & (1 << (p_layer_number - 1)); } -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 +128,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 +137,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 +146,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 +155,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 +164,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 +173,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 +182,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 +191,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 +200,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 +209,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 +218,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 +227,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 +236,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; } @@ -329,9 +344,7 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { Vector3 *tw = tmeshfaces.ptrw(); int tidx = 0; - for (List<Face3>::Element *E = faces.front(); E; E = E->next()) { - const Face3 &f = E->get(); - + for (const Face3 &f : faces) { for (int j = 0; j < 3; j++) { tw[tidx++] = f.vertex[j]; _EdgeKey ek; @@ -366,8 +379,8 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { { Vector3 *w = varr.ptrw(); int idx = 0; - for (List<Vector3>::Element *E = lines.front(); E; E = E->next()) { - w[idx++] = E->get(); + for (const Vector3 &E : lines) { + w[idx++] = E; } } @@ -392,8 +405,8 @@ void NavigationMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &NavigationMesh::set_collision_mask); ClassDB::bind_method(D_METHOD("get_collision_mask"), &NavigationMesh::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &NavigationMesh::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &NavigationMesh::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_value", "layer_number", "value"), &NavigationMesh::set_collision_mask_value); + ClassDB::bind_method(D_METHOD("get_collision_mask_value", "layer_number"), &NavigationMesh::get_collision_mask_value); ClassDB::bind_method(D_METHOD("set_source_geometry_mode", "mask"), &NavigationMesh::set_source_geometry_mode); ClassDB::bind_method(D_METHOD("get_source_geometry_mode"), &NavigationMesh::get_source_geometry_mode); @@ -462,14 +475,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"); @@ -496,19 +501,34 @@ 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 { if (property.name == "geometry/collision_mask") { if (parsed_geometry_type == PARSED_GEOMETRY_MESH_INSTANCES) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; return; } } if (property.name == "geometry/source_group_name") { if (source_geometry_mode == SOURCE_GEOMETRY_NAVMESH_CHILDREN) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; return; } } |