18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 06:14:58 +01:00

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ
This commit is contained in:
Claude
2026-11-12 21:08:10 +01:00
parent db8ea9081f
commit 59deddda6b
3 changed files with 38 additions and 1 deletions

View File

@@ -2032,7 +2032,10 @@ void editor_mode::render_terrain_ui()
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(STR_C("Clear the outline##fill"))) if (ImGui::Button(STR_C("Clear the outline##fill")))
{
m_paint_outline.clear(); m_paint_outline.clear();
m_patch_reoutline.clear();
}
// the same outline for the holes and the grass // the same outline for the holes and the grass
std::vector<glm::dvec2> outline; std::vector<glm::dvec2> outline;
for (auto const &point : m_paint_outline) for (auto const &point : m_paint_outline)

View File

@@ -49,6 +49,24 @@ void reach_of(heightmap::surface_patch const &Patch, glm::dvec2 &Low, glm::dvec2
Low -= glm::dvec2{margin}; Low -= glm::dvec2{margin};
High += 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<heightmap::surface_patch> 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
namespace namespace
@@ -141,7 +159,10 @@ void editor_mode::render_fields_ui()
cut_out_field(); cut_out_field();
ImGui::EndDisabled(); ImGui::EndDisabled();
if (ImGui::Button(STR_C("Clear the outline##fields"), ImVec2(-FLT_MIN, 0.0f))) if (ImGui::Button(STR_C("Clear the outline##fields"), ImVec2(-FLT_MIN, 0.0f)))
{
m_paint_outline.clear(); m_paint_outline.clear();
m_patch_reoutline.clear(); // the next cut is a new field
}
render_patches_list(); render_patches_list();
ImGui::SeparatorText(STR_C("Natural slopes")); ImGui::SeparatorText(STR_C("Natural slopes"));
@@ -220,6 +241,7 @@ void editor_mode::cut_out_field()
if (false == patch.paint) if (false == patch.paint)
{ {
m_streamer.cut_field(old.outline, false); 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.cut_field(patch.outline, true);
m_streamer.patches(std::move(patches)); m_streamer.patches(std::move(patches));
forget_ground(); forget_ground();
@@ -791,7 +813,11 @@ void editor_mode::render_patches_list()
ImGui::PushID(static_cast<int>(i)); ImGui::PushID(static_cast<int>(i));
auto const material = patches[i].material.empty() ? std::string(STR_C("default material")) : patches[i].material; 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<int>(i) == m_patch_selected)) 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<int>(i) == m_patch_selected))
{
if (static_cast<int>(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<int>(i); m_patch_selected = static_cast<int>(i);
}
// a texture dropped on an entry becomes the material of that surface // a texture dropped on an entry becomes the material of that surface
std::string name; std::string name;
if (material_drop(name)) if (material_drop(name))
@@ -908,6 +934,7 @@ void editor_mode::render_patches_list()
return; return;
} }
m_streamer.cut_field(gone.outline, false); m_streamer.cut_field(gone.outline, false);
recut_separate_over(m_streamer, all, gone);
m_streamer.patches(std::move(all)); m_streamer.patches(std::move(all));
forget_ground(); forget_ground();
m_terrain_status = STR_C("Surface removed, the hole under it closed"); m_terrain_status = STR_C("Surface removed, the hole under it closed");

View File

@@ -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) for (auto x{std::min(first.first, last.first)}; x <= std::max(first.first, last.first); ++x)
{ {
chunk_key const key{x, z}; 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 true;
} }
return false; return false;