diff --git a/src/terrain_3d.cpp b/src/terrain_3d.cpp index bbc82e84..b99fcf43 100644 --- a/src/terrain_3d.cpp +++ b/src/terrain_3d.cpp @@ -414,22 +414,22 @@ void Terrain3D::_update_collision() { Ref map, map_x, map_z, map_xz; Ref cmap, cmap_x, cmap_z, cmap_xz; - map = _storage->get_map_region(Terrain3DStorage::TYPE_HEIGHT, i); - cmap = _storage->get_map_region(Terrain3DStorage::TYPE_CONTROL, i); + map = _storage->get_map_region(TYPE_HEIGHT, i); + cmap = _storage->get_map_region(TYPE_CONTROL, i); int region_id = _storage->get_region_id(Vector3(global_pos.x + region_size, 0.f, global_pos.z) * _mesh_vertex_spacing); if (region_id >= 0) { - map_x = _storage->get_map_region(Terrain3DStorage::TYPE_HEIGHT, region_id); - cmap_x = _storage->get_map_region(Terrain3DStorage::TYPE_CONTROL, region_id); + map_x = _storage->get_map_region(TYPE_HEIGHT, region_id); + cmap_x = _storage->get_map_region(TYPE_CONTROL, region_id); } region_id = _storage->get_region_id(Vector3(global_pos.x, 0.f, global_pos.z + region_size) * _mesh_vertex_spacing); if (region_id >= 0) { - map_z = _storage->get_map_region(Terrain3DStorage::TYPE_HEIGHT, region_id); - cmap_z = _storage->get_map_region(Terrain3DStorage::TYPE_CONTROL, region_id); + map_z = _storage->get_map_region(TYPE_HEIGHT, region_id); + cmap_z = _storage->get_map_region(TYPE_CONTROL, region_id); } region_id = _storage->get_region_id(Vector3(global_pos.x + region_size, 0.f, global_pos.z + region_size) * _mesh_vertex_spacing); if (region_id >= 0) { - map_xz = _storage->get_map_region(Terrain3DStorage::TYPE_HEIGHT, region_id); - cmap_xz = _storage->get_map_region(Terrain3DStorage::TYPE_CONTROL, region_id); + map_xz = _storage->get_map_region(TYPE_HEIGHT, region_id); + cmap_xz = _storage->get_map_region(TYPE_CONTROL, region_id); } for (int z = 0; z < shape_size; z++) { diff --git a/src/terrain_3d_editor.cpp b/src/terrain_3d_editor.cpp index 14b5a465..bcd7fac0 100644 --- a/src/terrain_3d_editor.cpp +++ b/src/terrain_3d_editor.cpp @@ -38,7 +38,7 @@ void Terrain3DEditor::_operate_region(const Vector3 &p_global_position) { } else { if (has_region) { int region_id = _terrain->get_storage()->get_region_id(p_global_position); - Ref height_map = _terrain->get_storage()->get_map_region(Terrain3DStorage::TYPE_HEIGHT, region_id); + Ref height_map = _terrain->get_storage()->get_map_region(TYPE_HEIGHT, region_id); height_range = Util::get_min_max(height_map); _terrain->get_storage()->remove_region(p_global_position); @@ -76,11 +76,11 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ } } - Terrain3DStorage::MapType map_type; + MapType map_type; switch (_tool) { case HEIGHT: case INSTANCER: - map_type = Terrain3DStorage::TYPE_HEIGHT; + map_type = TYPE_HEIGHT; break; case TEXTURE: case AUTOSHADER: @@ -88,11 +88,11 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ case NAVIGATION: case ANGLE: case SCALE: - map_type = Terrain3DStorage::TYPE_CONTROL; + map_type = TYPE_CONTROL; break; case COLOR: case ROUGHNESS: - map_type = Terrain3DStorage::TYPE_COLOR; + map_type = TYPE_COLOR; break; default: LOG(ERROR, "Invalid tool selected"); @@ -193,7 +193,7 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ Color src = map->get_pixelv(map_pixel_position); Color dest = src; - if (map_type == Terrain3DStorage::TYPE_HEIGHT) { + if (map_type == TYPE_HEIGHT) { real_t srcf = src.r; real_t destf = dest.r; @@ -280,7 +280,7 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ edited_position.y = destf; edited_area = edited_area.expand(edited_position); - } else if (map_type == Terrain3DStorage::TYPE_CONTROL) { + } else if (map_type == TYPE_CONTROL) { // Get bit field from pixel uint32_t base_id = get_base(src.r); uint32_t overlay_id = get_overlay(src.r); @@ -404,7 +404,7 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ // Write back to pixel in FORMAT_RF. Must be a 32-bit float dest = Color(as_float(bits), 0.f, 0.f, 1.f); - } else if (map_type == Terrain3DStorage::TYPE_COLOR) { + } else if (map_type == TYPE_COLOR) { switch (_tool) { case COLOR: dest = src.lerp((_operation == ADD) ? color : COLOR_WHITE, brush_alpha * strength); @@ -473,9 +473,9 @@ Dictionary Terrain3DEditor::_get_undo_data() const { LOG(DEBUG, "Storing region locations"); data["region_locations"] = _terrain->get_storage()->get_region_locations().duplicate(); if (_operation == SUBTRACT) { - data["height_map"] = _terrain->get_storage()->get_maps_copy(Terrain3DStorage::TYPE_HEIGHT); - data["control_map"] = _terrain->get_storage()->get_maps_copy(Terrain3DStorage::TYPE_CONTROL); - data["color_map"] = _terrain->get_storage()->get_maps_copy(Terrain3DStorage::TYPE_COLOR); + data["height_map"] = _terrain->get_storage()->get_maps_copy(TYPE_HEIGHT); + data["control_map"] = _terrain->get_storage()->get_maps_copy(TYPE_CONTROL); + data["color_map"] = _terrain->get_storage()->get_maps_copy(TYPE_COLOR); data["height_range"] = _terrain->get_storage()->get_height_range(); data["edited_area"] = _terrain->get_storage()->get_edited_area(); } @@ -484,7 +484,7 @@ Dictionary Terrain3DEditor::_get_undo_data() const { case HEIGHT: LOG(DEBUG, "Storing height maps and range"); data["region_locations"] = _terrain->get_storage()->get_region_locations().duplicate(); - data["height_map"] = _terrain->get_storage()->get_maps_copy(Terrain3DStorage::TYPE_HEIGHT); + data["height_map"] = _terrain->get_storage()->get_maps_copy(TYPE_HEIGHT); data["height_range"] = _terrain->get_storage()->get_height_range(); data["edited_area"] = _terrain->get_storage()->get_edited_area(); break; @@ -497,13 +497,13 @@ Dictionary Terrain3DEditor::_get_undo_data() const { case AUTOSHADER: case NAVIGATION: LOG(DEBUG, "Storing control maps"); - data["control_map"] = _terrain->get_storage()->get_maps_copy(Terrain3DStorage::TYPE_CONTROL); + data["control_map"] = _terrain->get_storage()->get_maps_copy(TYPE_CONTROL); break; case COLOR: case ROUGHNESS: LOG(DEBUG, "Storing color maps"); - data["color_map"] = _terrain->get_storage()->get_maps_copy(Terrain3DStorage::TYPE_COLOR); + data["color_map"] = _terrain->get_storage()->get_maps_copy(TYPE_COLOR); break; case INSTANCER: @@ -558,11 +558,11 @@ void Terrain3DEditor::_apply_undo(const Dictionary &p_set) { if (key == "region_offsets") { _terrain->get_storage()->set_region_locations(p_set[key]); } else if (key == "height_map") { - _terrain->get_storage()->set_maps(Terrain3DStorage::TYPE_HEIGHT, p_set[key]); + _terrain->get_storage()->set_maps(TYPE_HEIGHT, p_set[key]); } else if (key == "control_map") { - _terrain->get_storage()->set_maps(Terrain3DStorage::TYPE_CONTROL, p_set[key]); + _terrain->get_storage()->set_maps(TYPE_CONTROL, p_set[key]); } else if (key == "color_map") { - _terrain->get_storage()->set_maps(Terrain3DStorage::TYPE_COLOR, p_set[key]); + _terrain->get_storage()->set_maps(TYPE_COLOR, p_set[key]); } else if (key == "height_range") { _terrain->get_storage()->set_height_range(p_set[key]); } else if (key == "edited_area") { diff --git a/src/terrain_3d_storage.cpp b/src/terrain_3d_storage.cpp index fc9c9c75..d1323d23 100644 --- a/src/terrain_3d_storage.cpp +++ b/src/terrain_3d_storage.cpp @@ -686,7 +686,7 @@ void Terrain3DStorage::save() { if (_save_16_bit) { LOG(DEBUG, "16-bit save requested, converting heightmaps"); TypedArray original_maps; - original_maps = get_maps_copy(Terrain3DStorage::MapType::TYPE_HEIGHT); + original_maps = get_maps_copy(TYPE_HEIGHT); for (int i = 0; i < _height_maps.size(); i++) { Ref img = _height_maps[i]; img->convert(Image::FORMAT_RH); diff --git a/src/terrain_3d_storage.h b/src/terrain_3d_storage.h index b1fb42bb..b28c89f8 100644 --- a/src/terrain_3d_storage.h +++ b/src/terrain_3d_storage.h @@ -197,7 +197,12 @@ class Terrain3DStorage : public Resource { static void _bind_methods(); }; +typedef Terrain3DStorage::MapType MapType; VARIANT_ENUM_CAST(Terrain3DStorage::MapType); +constexpr Terrain3DStorage::MapType TYPE_HEIGHT = Terrain3DStorage::MapType::TYPE_HEIGHT; +constexpr Terrain3DStorage::MapType TYPE_CONTROL = Terrain3DStorage::MapType::TYPE_CONTROL; +constexpr Terrain3DStorage::MapType TYPE_COLOR = Terrain3DStorage::MapType::TYPE_COLOR; +constexpr Terrain3DStorage::MapType TYPE_MAX = Terrain3DStorage::MapType::TYPE_MAX; VARIANT_ENUM_CAST(Terrain3DStorage::RegionSize); VARIANT_ENUM_CAST(Terrain3DStorage::HeightFilter); diff --git a/src/terrain_3d_util.cpp b/src/terrain_3d_util.cpp index 620b3fad..85d5599a 100644 --- a/src/terrain_3d_util.cpp +++ b/src/terrain_3d_util.cpp @@ -233,7 +233,7 @@ Ref Terrain3DUtil::load_image(const String &p_file_name, const int p_cach LOG(DEBUG, "Total file size is: ", fsize, " calculated width: ", fwidth, " dimensions: ", r16_size); file->seek(0); } - img = Image::create(r16_size.x, r16_size.y, false, Terrain3DStorage::FORMAT[Terrain3DStorage::TYPE_HEIGHT]); + img = Image::create(r16_size.x, r16_size.y, false, Terrain3DStorage::FORMAT[TYPE_HEIGHT]); for (int y = 0; y < r16_size.y; y++) { for (int x = 0; x < r16_size.x; x++) { real_t h = real_t(file->get_16()) / 65535.0f;