From 59deddda6b8b583a44a03068b932f4c9d6a104d9 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 21:08:10 +0100 Subject: [PATCH] fix(editor): Fields: a separate field is built after loading with the camera still; a cleared outline or another field chosen forgets the one to outline again; giving back a field keeps the holes of the others over it - waits_for_ground counts a chunk as still coming while its pack isn't read yet (right after opening the scenery none is), and as not coming only when the pack is missing or read without that chunk. Before, the first build after opening left a saved separate field a hole until the camera moved. - Clear the outline (Fields and the area fill) and choosing another field in the list forget the field put back by Outline it again, so the next cut is a new field and not the old one moved. - All holes of separate fields share one mark, so closing one closed it under an overlapping field too; the separate fields left over the closed outline are cut again after it (when a field is given back or outlined again). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ --- application/editormode.cpp | 3 +++ application/editormodefields.cpp | 27 +++++++++++++++++++++++++++ editor/editorTerrainStreamer.cpp | 9 ++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/application/editormode.cpp b/application/editormode.cpp index 21d0b037f..72007d629 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -2032,7 +2032,10 @@ void editor_mode::render_terrain_ui() ImGui::EndDisabled(); ImGui::SameLine(); if (ImGui::Button(STR_C("Clear the outline##fill"))) + { m_paint_outline.clear(); + m_patch_reoutline.clear(); + } // the same outline for the holes and the grass std::vector outline; for (auto const &point : m_paint_outline) diff --git a/application/editormodefields.cpp b/application/editormodefields.cpp index 515341f0a..fa9f275a3 100644 --- a/application/editormodefields.cpp +++ b/application/editormodefields.cpp @@ -49,6 +49,24 @@ void reach_of(heightmap::surface_patch const &Patch, glm::dvec2 &Low, glm::dvec2 Low -= glm::dvec2{margin}; High += glm::dvec2{margin}; } + +// every hole of a separate field has the same mark, so closing one field's hole closes it under another field over it as +// well: the separate fields left that overlap the closed outline are cut again (a cut leaves the holes there are as they are) +void recut_separate_over(terrain_streamer &Streamer, std::vector const &Patches, heightmap::surface_patch const &Closed) +{ + glm::dvec2 low, high; + Closed.bounds(low, high); + for (auto const &patch : Patches) + { + if (patch.paint || patch.outline.size() < 3) + continue; + glm::dvec2 otherlow, otherhigh; + patch.bounds(otherlow, otherhigh); + if (otherlow.x > high.x || otherhigh.x < low.x || otherlow.y > high.y || otherhigh.y < low.y) + continue; + Streamer.cut_field(patch.outline, true); + } +} } // namespace namespace @@ -141,7 +159,10 @@ void editor_mode::render_fields_ui() cut_out_field(); ImGui::EndDisabled(); if (ImGui::Button(STR_C("Clear the outline##fields"), ImVec2(-FLT_MIN, 0.0f))) + { m_paint_outline.clear(); + m_patch_reoutline.clear(); // the next cut is a new field + } render_patches_list(); ImGui::SeparatorText(STR_C("Natural slopes")); @@ -220,6 +241,7 @@ void editor_mode::cut_out_field() if (false == patch.paint) { m_streamer.cut_field(old.outline, false); + recut_separate_over(m_streamer, patches, old); // the others; this one already has its new outline in the list m_streamer.cut_field(patch.outline, true); m_streamer.patches(std::move(patches)); forget_ground(); @@ -791,7 +813,11 @@ void editor_mode::render_patches_list() ImGui::PushID(static_cast(i)); auto const material = patches[i].material.empty() ? std::string(STR_C("default material")) : patches[i].material; if (ImGui::Selectable(format(STR_C("%s, %zu points, %s"), patches[i].name.c_str(), patches[i].outline.size(), material.c_str()).c_str(), static_cast(i) == m_patch_selected)) + { + if (static_cast(i) != m_patch_selected) + m_patch_reoutline.clear(); // another field chosen: the outline put back no longer stands for the one before m_patch_selected = static_cast(i); + } // a texture dropped on an entry becomes the material of that surface std::string name; if (material_drop(name)) @@ -908,6 +934,7 @@ void editor_mode::render_patches_list() return; } m_streamer.cut_field(gone.outline, false); + recut_separate_over(m_streamer, all, gone); m_streamer.patches(std::move(all)); forget_ground(); m_terrain_status = STR_C("Surface removed, the hole under it closed"); diff --git a/editor/editorTerrainStreamer.cpp b/editor/editorTerrainStreamer.cpp index 7c24769a0..21ce6de79 100644 --- a/editor/editorTerrainStreamer.cpp +++ b/editor/editorTerrainStreamer.cpp @@ -921,7 +921,14 @@ bool terrain_streamer::waits_for_ground(heightmap::surface_patch const &Patch) c for (auto x{std::min(first.first, last.first)}; x <= std::max(first.first, last.first); ++x) { chunk_key const key{x, z}; - if (m_chunks.find(key) == m_chunks.end() && exists(key)) + if (m_chunks.count(key) > 0 || m_removed.count(key) > 0) + continue; + // still coming while its pack isn't read yet (just after opening the scenery none is); not coming only when + // the pack is missing, or read and without that chunk + auto const pack{m_packs.find(heightmap::pack_of(key))}; + if (pack == m_packs.end() || pack->second.status == pack_state::state::unknown || pack->second.status == pack_state::state::loading) + return true; + if (pack->second.status == pack_state::state::ready && pack->second.file->has(key)) return true; } return false;