diff --git a/application/editormode.cpp b/application/editormode.cpp index 46c34c6b5..146ef0372 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -68,6 +68,7 @@ extern char **environ; #include "utilities/Logs.h" #include #include +#include #include #include #include @@ -3039,13 +3040,60 @@ void editor_mode::area_grow() } } +namespace +{ +// the failed tiles drawn, the first of them; those after aren't outlined +std::size_t constexpr orthophoto_failures_drawn = 400; +} // namespace + +void editor_mode::ground_orthophoto_failures(std::vector> const &Failed) const +{ + // the tiles no longer failing forgotten + std::set> failing; + for (auto const &tile : Failed) + failing.emplace(tile.first.x, tile.first.y); + std::erase_if(m_orthophoto_failure_ground, [&failing](auto const &Entry) { return false == failing.contains(Entry.first); }); + + // two tiles asked for a frame: those with a corner not found yet each second, those found all round each 30 s, as the ground + // under them may have come or changed since + double const now{ImGui::GetTime()}; + int asked{0}; + auto const count{std::min(Failed.size(), orthophoto_failures_drawn)}; + for (std::size_t index = 0; index < count && asked < 2; ++index) + { + auto const &[low, high]{Failed[index]}; + auto &entry{m_orthophoto_failure_ground[{low.x, low.y}]}; + auto const complete{std::ranges::all_of(entry.found, [](bool const Found) { return Found; })}; + if (now - entry.asked < (complete ? 30.0 : 1.0)) + continue; + entry.asked = now; + ++asked; + std::vector const above{{low.x, 10000.0, low.y}, {high.x, 10000.0, low.y}, {high.x, 10000.0, high.y}, {low.x, 10000.0, high.y}}; + std::vector found; + auto const ground{ground_heights(above, false, &found)}; + for (std::size_t corner = 0; corner < entry.heights.size(); ++corner) + { + if (found[corner] == 0) + continue; + entry.heights[corner] = ground[corner]; + entry.found[corner] = true; + } + } +} + void editor_mode::draw_orthophoto_failures() const { if (false == m_orthophoto.enabled()) + { + m_orthophoto_failure_ground.clear(); return; + } auto const failed{m_orthophoto.failed()}; if (failed.empty()) + { + m_orthophoto_failure_ground.clear(); return; + } // the tiles which failed outlined in red, with a cross over them: there's no photo there yet, it's tried again by itself screen_projection const projection; auto *drawlist{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())}; @@ -3054,22 +3102,18 @@ void editor_mode::draw_orthophoto_failures() const // where the terrain lies well above or below it. Seen from above the height doesn't matter auto const grounded{m_orthophoto.settings().drape && false == Global.EditorOrtho}; auto const colour{IM_COL32(240, 70, 60, 210)}; + if (grounded) + ground_orthophoto_failures(failed); std::size_t drawn{0}; for (auto const &[low, high] : failed) { - if (++drawn > 400) + if (++drawn > orthophoto_failures_drawn) break; - std::vector corners{{low.x, height, low.y}, {high.x, height, low.y}, {high.x, height, high.y}, {low.x, height, high.y}}; - if (grounded) + std::array corners{{{low.x, height, low.y}, {high.x, height, low.y}, {high.x, height, high.y}, {low.x, height, high.y}}}; + if (auto const entry{grounded ? m_orthophoto_failure_ground.find({low.x, low.y}) : m_orthophoto_failure_ground.end()}; entry != m_orthophoto_failure_ground.end()) { - std::vector above{corners}; - for (auto &corner : above) - corner.y = 10000.0; - std::vector found; - auto const ground{ground_heights(above, false, &found)}; for (std::size_t i = 0; i < corners.size(); ++i) - if (found[i] != 0) - corners[i].y = ground[i]; + corners[i].y = entry->second.found[i] ? entry->second.heights[i] : corners[i].y; } for (int i = 0; i < 4; ++i) projection.line(drawlist, corners[i], corners[(i + 1) % 4], colour, 2.0f); diff --git a/application/editormode.h b/application/editormode.h index b069b41d2..71f56d595 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -946,6 +946,17 @@ class editor_mode : public application_mode, private editor_track::observer, pri bool m_area_grow_limited{false}; // the tiles of the photo which failed: marked red in the view, counted in the status bar with the button trying them again void draw_orthophoto_failures() const; + // the heights of the ground under the corners of the tiles which failed, outlined on it in the 3D view. A few tiles are asked for + // each frame, and a tile whose corners were found only again once in a while, so that the outlines don't keep the tiles of the + // ground in use every frame and their cache growing past its limit + struct orthophoto_failure_ground + { + std::array heights{}; + std::array found{}; + double asked{-1.0e9}; + }; + void ground_orthophoto_failures(std::vector> const &Failed) const; + mutable std::map, orthophoto_failure_ground> m_orthophoto_failure_ground; void render_orthophoto_status(); // the terrain loaded in the background as the first track of a new scenery is laid, told in a line of the panel of the laying with // the button to go without it