diff --git a/application/editormode.cpp b/application/editormode.cpp index ce95988ff..e08e1f0e7 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -2556,17 +2556,60 @@ void editor_mode::render_orthophoto_ui() if (ImGui::TreeNode(STR_C("More settings"))) { - if (ImGui::Checkbox(STR_C("Fit to terrain"), &config.drape)) + // one choice of three, what it means under it: drawn over the view (laid on the ground, where there's none at the height), a + // surface of the scene on the ground, or a flat sheet in the scene; flat over the view says nothing more than on the ground + enum class look { - changed = true; - persist = true; + overlay, + ground, + sheet + }; + auto const current{false == config.in_scene ? look::overlay : config.drape ? look::ground : look::sheet}; + auto const choice = [&](char const *Label, look const Look) { + // the Better Renderer doesn't pick up geometry added in the editor: in the scene the photos wouldn't show at all + auto const disabled{Global.NvRenderer && Look != look::overlay && current != Look}; + begin_disabled(disabled); + if (ImGui::RadioButton(Label, current == Look) && current != Look) + { + config.in_scene = Look != look::overlay; + config.drape = Look != look::sheet; + changed = true; + persist = true; + } + end_disabled(disabled); + }; + auto const explain = [](char const *Text) { + ImGui::Indent(); + ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + 360.0f); + ImGui::TextDisabled("%s", Text); + ImGui::PopTextWrapPos(); + ImGui::Unindent(); + }; + + ImGui::TextUnformatted(STR_C("Show the photos")); + choice(STR_C("Over the view"), look::overlay); + choice(STR_C("On the terrain, in the scene"), look::ground); + choice(STR_C("A flat sheet in the scene"), look::sheet); + switch (current) + { + case look::overlay: + explain(STR_C("The photos are drawn over the whole view, over the tracks and models as well: lower the opacity to see " + "what's under them. The quickest way to compare the scenery with the map.")); + break; + case look::ground: + explain(STR_C("The photos lie on the terrain as its surface: tracks and models standing on them cover them, the scene lights " + "them, and fully opaque the mouse places objects on them as on the ground.")); + break; + case look::sheet: + explain(STR_C("One flat sheet at the height below, in the scene: for a scenery with no terrain yet. Where there is " + "terrain, it cuts through the sheet.")); + break; } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(STR_C("Lays the imagery onto the ground geometry (terrain shapes, terrain tile models, heightmap terrain).\n" - "Places without any ground use the height below.")); + if (Global.NvRenderer && current != look::overlay) + ImGui::TextColored(ImVec4(1.0f, 0.75f, 0.2f, 1.0f), "%s", STR_C("The Better Renderer doesn't show them in the scene: pick \"Over the view\"")); + if (config.drape) { - ImGui::SameLine(); if (ImGui::Button(STR_C("Refit"))) { // the ground was edited: what's kept of it has to go as well @@ -2577,34 +2620,22 @@ void editor_mode::render_orthophoto_ui() layer->refit(); } if (ImGui::IsItemHovered()) - ImGui::SetTooltip(STR_C("Samples the ground again, after it was edited")); + ImGui::SetTooltip("%s", STR_C("Samples the ground again, after it was edited")); + // the lift only matters where the scene can cover the photos + if (config.in_scene) + { + ImGui::SetNextItemWidth(160.0f); + changed |= ImGui::DragFloat(STR_C("Lift above ground (m)"), &config.lift, 0.01f, 0.0f, 50.0f, "%.2f"); + persist |= ImGui::IsItemDeactivatedAfterEdit(); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("%s", STR_C("Raises the photos above the ground.\n" + "Whatever is lower than this, the rails and the sleepers too, ends up under them: keep it small.")); + } } - - begin_disabled(!config.drape); ImGui::SetNextItemWidth(160.0f); - changed |= ImGui::DragFloat(STR_C("Lift above ground (m)"), &config.lift, 0.01f, 0.0f, 50.0f, "%.2f"); + changed |= ImGui::DragFloat(config.drape ? STR_C("Height where there's no ground (m)") : STR_C("Height (m)"), &config.height, 0.1f, -1000.0f, 3000.0f, "%.2f"); persist |= ImGui::IsItemDeactivatedAfterEdit(); - end_disabled(!config.drape); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(STR_C("Raises the fitted imagery above the ground. Keep it below the objects you want to see:\n" - "in the scene everything lower than this ends up under the imagery.")); - - begin_disabled(config.drape); - ImGui::SetNextItemWidth(160.0f); - changed |= ImGui::DragFloat(STR_C("Height (m)"), &config.height, 0.1f, -1000.0f, 3000.0f, "%.2f"); - persist |= ImGui::IsItemDeactivatedAfterEdit(); - end_disabled(config.drape); - - if (ImGui::Checkbox(STR_C("Covered by objects and terrain"), &config.in_scene)) - { - changed = true; - persist = true; - } - if (ImGui::IsItemHovered()) - ImGui::SetTooltip(STR_C("Draws the imagery as part of the scene, so tracks, models and terrain in front of it hide it.\n" - "It is lit like the scene. Fully opaque, mouse placement lands on it as on any surface;\n" - "translucent, it doesn't catch the mouse.\n" - "Not available with the Better Renderer, which doesn't pick up geometry added in the editor.")); + ImGui::Spacing(); ImGui::SetNextItemWidth(160.0f); changed |= ImGui::SliderFloat(STR_C("Opacity"), &config.opacity, 0.0f, 1.0f, "%.2f"); diff --git a/application/editormode.h b/application/editormode.h index 2abcae13e..bcf22592c 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -535,6 +535,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::optional nmt_terrain_offset(std::vector const &Points, bool &Foreign) const; // the same along the edges the chunk shares with the chunks beside it in memory std::optional nmt_seam_offset(heightmap::chunk_key const &Key, bool &Foreign) const; + // the offset a chunk made from the model where there's no terrain gets: of the terrain made from the model beside it, empty + // (the offset of the scenery) beside terrain made by hand or none + std::optional nmt_chunk_offset(heightmap::chunk_key const &Key) const; // the terrain beside the formation of the track is the one made from the model; Waiting: its squares of the model aren't in yet // the tracks changed by hand are told to the terrain: their formations laid anew, of the tracks removed taken away, a // track laid onto the terrain of the model given its own, once the mouse lets go; in the step of the history of the change @@ -552,6 +555,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri // of the modifiers laid std::size_t nmt_shape_tracks(std::vector const *Only = nullptr); void nmt_update(); + // the terrain of the scenery made from the model around the camera within the download area, a chunk at a time while nothing + // else is done with the model and the frames are quick: edited chunks wait in memory to be saved, so not the whole area at once + void nmt_area_terrain(); void nmt_grow(); void render_nmt_ui(); // where the scenery lies: the map to click on, the place typed; true once it's placed @@ -919,6 +925,25 @@ class editor_mode : public application_mode, private editor_track::observer, pri } m_area_drawing; std::vector m_nmt_prefetched; // the download area the terrain model was given bool m_area_paused{false}; // the download of the area held by the button; out of the editor it's held anyway + // the terrain made around the camera within the area: the chunks there, nearest first, the next one looked at, when the next one + // may be made, those made (or left: the model has no data there, or the chunk is outside the region) since the scenery opened + struct area_terrain + { + std::vector keys; + std::size_t next{0}; + heightmap::chunk_key centre{0, 0}; + bool listed{false}; + double resume{0.0}; + std::size_t made{0}; + std::size_t square_made{0}; // of them, in the square around the camera now + bool refit{false}; // chunks made since the photos were last laid onto the ground + double waiting{-1.0}; // since when the next chunk waits for its model; -1: it doesn't + std::string held{"-"}; // what held it last, as logged; empty: nothing + double took{0.0}; // s the chunks of the square around the camera took, all and the longest + double took_most{0.0}; + std::set empty; + std::optional run_only; // the selftest turned it on or off for its run, the setting left as it is + } m_area_terrain; int m_area_square{0}; // km, the side of the square around the camera waiting for its yes in place of the area there is bool m_outside_area_closed{false}; // the note of the camera outside the area closed; open again once it's back inside int m_empty_hint_frame{-10}; // the frame the panel of the empty scenery was last drawn in diff --git a/application/editormodenmt.cpp b/application/editormodenmt.cpp index 9476dc5cf..13465a006 100644 --- a/application/editormodenmt.cpp +++ b/application/editormodenmt.cpp @@ -746,6 +746,20 @@ std::optional editor_mode::nmt_terrain_offset(std::vector co return median; } +std::optional editor_mode::nmt_chunk_offset(heightmap::chunk_key const &Key) const +{ + // the one rule for every chunk made from the model where there's no terrain, under the track laid, around the camera in the area or + // by the buttons: beside terrain made from the model it goes on at its height over the model, so no step is left at the seam; + // otherwise, beside terrain made by hand or none, at the offset of the scenery. no chunk is left out for what lies beside it + // the terrain drawn to the tracks place by place (under the tracks) keeps to their heights near it: the height of the chunk beside + // would carry one offset on along a run of chunks, metres off the tracks + if (auto const &state{m_nmt_state}; state.under && false == state.anchors.empty()) + return std::nullopt; + bool foreign{false}; + auto const offset{nmt_seam_offset(Key, foreign)}; + return foreign ? std::nullopt : offset; +} + std::optional editor_mode::nmt_seam_offset(heightmap::chunk_key const &Key, bool &Foreign) const { auto const low{heightmap::chunk_corner(Key)}; @@ -1058,17 +1072,158 @@ std::size_t editor_mode::nmt_shape_tracks(std::vector const *Only) return count; } +void editor_mode::nmt_area_terrain() +{ + auto &area{m_area_terrain}; + auto const &config{m_orthophoto.settings()}; + auto const &state{m_nmt_state}; + // what holds it, logged as it changes: nothing was made and nothing told why + auto const held = [&](char const *Reason) { + if (area.held != Reason) + { + area.held = Reason; + WriteLog(std::string{"Editor: NMT - the terrain of the download area "} + (*Reason != '\0' ? std::string{"held: "} + Reason : std::string{"goes on"}), logtype::generic); + } + }; + if (false == area.run_only.value_or(EditorSettings.terrain_model().area)) + return held("turned off"); + if (m_orthophoto.area().empty()) + return held("no area"); + if (m_area_paused) + return held("the area paused"); + if (config.north == 0.0 && config.east == 0.0) + return held("no origin of the scenery"); + // after the work with the model the user asked for + if (state.stage != nmt_state::automatic::idle || state.fitting || false == state.pending.empty()) + return held("other work with the model"); + // a stroke of the terrain brush keeps its step of the history open to its end: closed around a chunk, its undo would lose the + // part brushed before + if (terrain_brush() && mouseHold) + return held("a stroke of the terrain brush"); + held(""); + // light: the time after a chunk set by how long it took. not held by slow frames: a large scenery has them all the time, and + // nothing was made there + auto const now{ImGui::GetTime()}; + if (now < area.resume) + return; + // the chunks of the area in the square around the camera, the nearest first + int constexpr reach{4}; + auto const centre{heightmap::chunk_at(Camera.Pos.x, Camera.Pos.z)}; + if (false == area.listed || centre != area.centre) + { + area.keys.clear(); + area.next = 0; + area.centre = centre; + area.listed = true; + area.waiting = -1.0; + area.square_made = 0; + area.took = 0.0; + area.took_most = 0.0; + for (int dz = -reach; dz <= reach; ++dz) + for (int dx = -reach; dx <= reach; ++dx) + { + heightmap::chunk_key const key{centre.first + dx, centre.second + dz}; + if (auto const low{heightmap::chunk_corner(key)}; false == area.empty.contains(key) && in_download_area(low, low + glm::dvec2{heightmap::chunk_size})) + area.keys.push_back(key); + } + std::stable_sort(area.keys.begin(), area.keys.end(), [&](heightmap::chunk_key const &Left, heightmap::chunk_key const &Right) { + auto const distance = [&](heightmap::chunk_key const &Key) { return sq(Key.first - centre.first) + sq(Key.second - centre.second); }; + return distance(Left) < distance(Right); + }); + auto const missing{std::count_if(area.keys.begin(), area.keys.end(), [&](heightmap::chunk_key const &Key) { return false == m_streamer.active() || false == m_streamer.exists(Key); })}; + // told only where there's terrain to make: the camera crosses a chunk every few seconds + if (missing > 0) + WriteLog(format("Editor: NMT - the download area around the camera (chunk %d,%d): %zu chunks in it, %zu with no terrain yet", centre.first, centre.second, area.keys.size(), + static_cast(missing)), + logtype::generic); + } + // those there already cost a lookup only, a few of them a frame; the terrain made by hand is left as it is + for (int looked = 0; looked < 8 && area.next < area.keys.size(); ++looked) + { + auto const key{area.keys[area.next]}; + if (m_streamer.active() && m_streamer.exists(key)) + { + ++area.next; + continue; + } + if (false == ensure_terrain()) + return; + nmt_locate(); + auto const low{heightmap::chunk_corner(key)}; + auto const high{low + glm::dvec2{heightmap::chunk_size}}; + // the model under it and a little around, for the heights along the terrain beside: read from the cache or downloaded + // meanwhile; one that doesn't come is left for the camera's next move + if (false == nmt_ready(low - glm::dvec2{2.0}, high + glm::dvec2{2.0})) + { + if (area.waiting < 0.0) + area.waiting = now; + else if (now - area.waiting > 5.0) + { + area.waiting = -1.0; + ++area.next; + } + return; + } + area.waiting = -1.0; + ++area.next; + auto const started{std::chrono::steady_clock::now()}; + // the editor keeps a step of the history of the terrain open all the time: the chunk isn't a step of it, as the terrain grown + // under the track laid; the step there is closed before, and a new one opened after + auto const recording{m_streamer.recording()}; + if (recording) + { + terrain_history_step(); + m_streamer.end_change(); + } + auto const chunk{add_chunk_from_nmt(key, nmt_chunk_offset(key))}; + if (recording) + m_streamer.begin_change(); + auto const took{std::chrono::duration(std::chrono::steady_clock::now() - started).count()}; + // a chunk at most every 0.1 s, and the editor left at least three times as long for itself as the chunk took + area.resume = now + std::max(0.1, 3.0 * took); + area.took += took; + area.took_most = std::max(area.took_most, took); + // one outside the region of the scenery isn't added either + if (chunk == nmt_chunk::made && m_streamer.exists(key)) + { + ++area.made; + ++area.square_made; + area.refit = true; + forget_ground_in(low, high); + } + else + area.empty.insert(key); + return; + } + // the square done: the photos laid onto the new ground once, not after each chunk + if (area.next >= area.keys.size() && std::exchange(area.refit, false)) + { + m_orthophoto.refit(); + for (auto &layer : m_wms) + layer->refit(); + WriteLog(format("Editor: NMT - the download area: %zu chunks made around the camera in %.0f ms, the longest %.1f ms, %zu in all", area.square_made, area.took * 1000.0, + area.took_most * 1000.0, area.made), + logtype::generic); + } +} + void editor_mode::nmt_update() { auto &state{m_nmt_state}; - // the squares of the model in the download area to the disk cache, where the scenery is placed and its terrain is there - if (auto const wanted{m_nmt.placed() && m_streamer.active() ? m_orthophoto.area() : std::vector{}}; wanted != m_nmt_prefetched) + // the squares of the model in the download area to the disk cache, as the area promises the model with the photos: the area is in + // PUWG 1992 already, so it needs neither the model placed (its panel opened) nor the terrain of the scenery begun + if (auto const &wanted{m_orthophoto.area()}; wanted != m_nmt_prefetched) { m_nmt_prefetched = wanted; m_nmt.prefetch(wanted); + // the terrain around the camera looked at again within the new area + m_area_terrain.listed = false; + m_area_terrain.empty.clear(); } nmt_offer(); nmt_follow_tracks(); + // the terrain of the download area, when nothing else is done with the model: it tells what holds it + nmt_area_terrain(); if (state.stage != nmt_state::automatic::idle) { nmt_auto_step(); @@ -1091,6 +1246,14 @@ void editor_mode::nmt_update() return; } state.camera_check = true; + // the terrain of the scenery opened, or begun, for the chunks grown under the track laid as well: they don't need terrain there before + if (false == ensure_terrain()) + { + state.pending.clear(); + state.refill.clear(); + state.status = STR("The heightmap terrain can't be opened"); + return; + } // a few chunks a frame, those whose model is in. the terrain made ahead of the track laid isn't a step of the history: // Ctrl+Z takes back the track, not the ground under it auto const unrecorded{state.grown && m_streamer.recording()}; @@ -1100,7 +1263,6 @@ void editor_mode::nmt_update() m_streamer.end_change(); } int made{0}; - std::size_t apart{0}; std::vector changed; for (auto it{state.pending.begin()}; it != state.pending.end() && made < 4;) { @@ -1110,34 +1272,22 @@ void editor_mode::nmt_update() it = state.pending.erase(it); continue; } - // ahead of the track the terrain goes on from the one there is, at its height over the model - std::optional offset; - if (state.grown && false == refilled) + // the model under it and a little around first: the height along the terrain beside is read from it + if (auto const low{heightmap::chunk_corner(*it)}; false == nmt_ready(low - glm::dvec2{2.0}, low + glm::dvec2{heightmap::chunk_size + 2.0})) { - bool foreign{false}; - offset = nmt_seam_offset(*it, foreign); - if (foreign) - { - state.given_up.insert(*it); - it = state.pending.erase(it); - ++state.foreign; - ++made; - continue; - } - if (false == offset.has_value()) - { - ++apart; - ++it; - continue; - } + ++it; + continue; } + // a new chunk at the height nmt_chunk_offset() gives it; one of flat ground refilled keeps to the offset of the scenery + auto const offset{refilled ? std::nullopt : nmt_chunk_offset(*it)}; auto const chunk{add_chunk_from_nmt(*it, offset)}; if (chunk == nmt_chunk::waiting) { ++it; continue; } - if (offset.has_value() && chunk == nmt_chunk::made) + // the height the track laid goes on at, over the model: from the terrain grown under it only, not from the buttons' chunks + if (state.grown && offset.has_value() && chunk == nmt_chunk::made) state.ahead = offset; if (chunk == nmt_chunk::made) changed.push_back(*it); @@ -1149,15 +1299,6 @@ void editor_mode::nmt_update() else ++state.empty; } - // the chunks ahead which no terrain made from the model touches any more are given up - if (made == 0 && apart > 0 && apart == state.pending.size()) - { - state.foreign += apart; - state.given_up.insert(state.pending.begin(), state.pending.end()); - state.pending.clear(); - state.refill.clear(); - made = 1; - } // the last ones may have got here as chunks the streamer has read in meanwhile, nothing made: all waited for is there all the same, // the formations of the tracks led into it if (made > 0 || state.pending.empty()) @@ -1199,13 +1340,18 @@ void editor_mode::nmt_grow() { auto &state{m_nmt_state}; auto const now{ImGui::GetTime()}; - if (false == state.grow || now - state.grow_time < 0.5 || false == m_nmt.placed()) + if (false == state.grow || now - state.grow_time < 0.5) return; state.grow_time = now; // around the cursor of the tool laying the tracks, the terrain under them once they're laid: from the first point placed, or as a // track is dragged from a free end; not around the camera, nor with the tool merely chosen if (false == m_lay.active && false == m_extend.active) return; + // the model placed where the origin of the orthophoto puts the scenery: it was only once the terrain panel had been open, and + // nothing grew under the track laid before that + nmt_locate(); + if (false == m_nmt.placed()) + return; auto const at{m_extend.active ? m_extend.mouse : m_lay.mouse}; // nothing asked for outside the download area if (false == in_download_area({at.x - 100.0, at.z - 100.0}, {at.x + 100.0, at.z + 100.0})) @@ -1213,7 +1359,9 @@ void editor_mode::nmt_grow() // the model under it meanwhile, for the height of the first point laid where there's no terrain yet, as over the base map m_nmt.request({at.x - 100.0, at.z - 100.0}, {at.x + 100.0, at.z + 100.0}); auto const laying{m_extend.active || false == m_lay.points.empty()}; - if (false == laying || m_streamer.resident() == 0) + // also in a scenery with no terrain yet, and far from the terrain there is: the chunks are made where the track goes. a scenery + // with no name yet can't have its terrain: nothing asked for, or it would be asked again and dropped every half a second + if (false == laying || (false == m_streamer.active() && m_orthophoto_scenery.empty())) return; glm::dvec2 const cursor{at.x, at.z}; double constexpr grow_reach{400.0}; // m around the cursor @@ -1836,11 +1984,11 @@ void editor_mode::draw_download_area() const return; screen_projection const projection; auto *drawlist{ImGui::GetBackgroundDrawList()}; - // the tiles of the area as they are: in the disk cache, failed; the ones waiting left clear + // the tiles of the area which failed: those in the cache or waiting left clear, the green over all the cached ones got in the way if (false == drawing.active && orthophoto_settings_open()) for (auto const &square : m_orthophoto.area_squares()) { - if (square.state == 0) + if (square.state != 2) continue; std::array corners; auto seen{true}; @@ -1848,7 +1996,7 @@ void editor_mode::draw_download_area() const for (int i = 0; i < 4 && seen; ++i) seen = projection.project(area_point(at[i]), corners[i]); if (seen) - drawlist->AddQuadFilled(corners[0], corners[1], corners[2], corners[3], square.state == 1 ? IM_COL32(90, 220, 120, 45) : IM_COL32(240, 80, 70, 80)); + drawlist->AddQuadFilled(corners[0], corners[1], corners[2], corners[3], IM_COL32(240, 80, 70, 80)); } auto const edge{IM_COL32(80, 220, 255, 230)}; auto const closing{IM_COL32(80, 220, 255, drawing.active ? 110 : 230)}; @@ -1988,6 +2136,18 @@ void editor_mode::render_download_area_ui(editor_orthophoto::statistics const &S m_nmt.prefetch(m_nmt_prefetched); } } + auto &model{EditorSettings.terrain_model()}; + if (ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &model.area)) + EditorSettings.save(); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("%s", STR_C("Makes the terrain from the terrain model within the area, around the camera wherever it goes,\n" + "a chunk at a time while the editor is idle. The terrain there is already isn't touched.\n" + "The chunks made wait in memory until the scenery is saved (Ctrl+S).")); + if (model.area && m_area_terrain.made > 0) + { + ImGui::SameLine(); + ImGui::TextDisabled("%s", format(STR_P("%zu chunk made", "%zu chunks made", m_area_terrain.made), m_area_terrain.made).c_str()); + } } void editor_mode::render_nmt_banner() diff --git a/application/editormodeselftestterrain.cpp b/application/editormodeselftestterrain.cpp index a2483f3b8..f50bd438a 100644 --- a/application/editormodeselftestterrain.cpp +++ b/application/editormodeselftestterrain.cpp @@ -175,6 +175,8 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co EditorSettings.terrain_while_laying(state.grow); EditorSettings.save(); } + else if (key == "area") + m_area_terrain.run_only = value != 0.0; // for the run only: the setting isn't touched, so no save keeps it } WriteLog(format("SELFTEST nmtsettings band %.0f around %d shape %d follow %d grow %d offset %+.2f fitted %d", state.band, m_terrain_add_count, state.shape ? 1 : 0, state.follow ? 1 : 0, state.grow ? 1 : 0, state.offset, state.fitted ? 1 : 0)); diff --git a/editor/editorNmt.cpp b/editor/editorNmt.cpp index 59e266192..3fd10b0fd 100644 --- a/editor/editorNmt.cpp +++ b/editor/editorNmt.cpp @@ -255,6 +255,7 @@ void editor_nmt::prefetch(std::vector const &Polygon) std::lock_guard lock{m_mutex}; m_prefetch = std::move(keys); m_prefetch_next = 0; + m_prefetch_again.clear(); m_prefetch_cached.clear(); m_prefetch_failed.clear(); ++m_prefetch_generation; @@ -350,7 +351,7 @@ void editor_nmt::work() std::uint32_t generation{0}; { std::unique_lock lock{m_mutex}; - auto const prefetchable = [this]() { return false == m_prefetch_paused && m_prefetch_next < m_prefetch.size(); }; + auto const prefetchable = [this]() { return false == m_prefetch_paused && (false == m_prefetch_again.empty() || m_prefetch_next < m_prefetch.size()); }; m_wake.wait(lock, [&]() { return m_stop || false == m_queue.empty() || prefetchable(); }); if (m_stop) return; @@ -361,8 +362,14 @@ void editor_nmt::work() } else { - // a square of the download area, while none is asked for - square = m_prefetch[m_prefetch_next++]; + // a square of the download area, while none is asked for; one broken off before first + if (false == m_prefetch_again.empty()) + { + square = m_prefetch_again.front(); + m_prefetch_again.pop_front(); + } + else + square = m_prefetch[m_prefetch_next++]; prefetching = true; generation = m_prefetch_generation; } @@ -372,9 +379,14 @@ void editor_nmt::work() // put into the disk cache only, the file there not read std::error_code fault; std::string error; - auto const ok{fs::exists(file_of(square), fault) || false == fetch(square, error)->failed}; + bool yielded{false}; + auto const ok{fs::exists(file_of(square), fault) || false == fetch(square, error, &yielded)->failed}; std::lock_guard lock{m_mutex}; - if (generation == m_prefetch_generation) + if (generation != m_prefetch_generation) + continue; + if (yielded) + m_prefetch_again.push_back(square); + else (ok ? m_prefetch_cached : m_prefetch_failed).insert(square); continue; } @@ -390,7 +402,7 @@ void editor_nmt::work() } } -std::shared_ptr editor_nmt::fetch(key const &Key, std::string &Error) +std::shared_ptr editor_nmt::fetch(key const &Key, std::string &Error, bool *Yielded) { auto result{std::make_shared()}; std::error_code fault; @@ -429,9 +441,18 @@ std::shared_ptr editor_nmt::fetch(key const &Key, std: return result; } editor_http::client client; - auto const stop = [this]() { + // the download of the area gives way to the squares asked for: the terrain under the track laid isn't kept waiting for it + auto const yield = [this, Yielded]() { std::lock_guard lock{m_mutex}; - return m_stop; + return Yielded != nullptr && false == m_queue.empty(); + }; + auto const stop = [this, &yield]() { + { + std::lock_guard lock{m_mutex}; + if (m_stop) + return true; + } + return yield(); }; std::string coverage; { @@ -481,6 +502,13 @@ std::shared_ptr editor_nmt::fetch(key const &Key, std: if (Error.empty()) Error = STRN("The service gave no terrain model"); } + if (Yielded != nullptr && yield()) + { + // broken off, not failed: downloaded again later + *Yielded = true; + result->failed = true; + return result; + } WriteLog("Editor: NMT square " + std::to_string(Key.first) + "," + std::to_string(Key.second) + " not fetched: " + Error, logtype::generic); result->failed = true; result->error = Error; diff --git a/editor/editorNmt.hpp b/editor/editorNmt.hpp index 9c55ec1c2..01baefe46 100644 --- a/editor/editorNmt.hpp +++ b/editor/editorNmt.hpp @@ -94,7 +94,9 @@ class editor_nmt key key_of(double const East, double const North) const; void work(); - std::shared_ptr fetch(key const &Key, std::string &Error); + // Yielded given: a square of the download area, its download broken off as soon as a square is asked for (the terrain under the + // track laid), and true then + std::shared_ptr fetch(key const &Key, std::string &Error, bool *Yielded = nullptr); mutable std::mutex m_mutex; std::condition_variable m_wake; @@ -109,6 +111,7 @@ class editor_nmt // the squares of the download area for the disk cache std::vector m_prefetch; std::size_t m_prefetch_next{0}; + std::deque m_prefetch_again; // broken off for a square asked for, taken up before the next ones std::set m_prefetch_cached; std::set m_prefetch_failed; std::uint32_t m_prefetch_generation{0}; diff --git a/editor/editorOrthophoto.cpp b/editor/editorOrthophoto.cpp index f2864fb2d..f663dd012 100644 --- a/editor/editorOrthophoto.cpp +++ b/editor/editorOrthophoto.cpp @@ -1501,6 +1501,8 @@ void editor_orthophoto::build_shape(tile_key const &Key, tile &Tile) bounds[1].position = glm::dvec3(corner.x, yhi, corner.y); scene::shape_node shape; shape.make_terrain(Tile.slot.material, std::move(bounds), origin); + // laid on the ground it's a copy of the ground's own triangles: the lift alone loses to the depth buffer further away + shape.decal(draped); shape.geometry(Tile.geometry); // extend the bounds of the containers so the tile isn't culled at its edges double const reach = glm::length(glm::dvec3(tile_size * 0.5, (yhi - ylo) * 0.5, tile_size * 0.5)); diff --git a/editor/editorSettings.cpp b/editor/editorSettings.cpp index f186197ef..c7e162c46 100644 --- a/editor/editorSettings.cpp +++ b/editor/editorSettings.cpp @@ -161,6 +161,8 @@ bool editorSettings::load() m_terrain_model.shape = (value == "1"); else if (key == "nmt_follow") m_terrain_model.follow = (value == "1"); + else if (key == "nmt_area") + m_terrain_model.area = (value == "1"); else if (key == "top_ballast") m_top_tracks = value == "1" ? 0 : 1; else if (key == "top_tracks") @@ -261,6 +263,7 @@ bool editorSettings::save() stream << "nmt_around " << m_terrain_model.around << "\n"; stream << "nmt_shape " << (m_terrain_model.shape ? 1 : 0) << "\n"; stream << "nmt_follow " << (m_terrain_model.follow ? 1 : 0) << "\n"; + stream << "nmt_area " << (m_terrain_model.area ? 1 : 0) << "\n"; stream << "top_tracks " << m_top_tracks << "\n"; stream << "top_rails " << std::hex << (m_top_rails & 0xffffffu) << std::dec << "\n"; stream << "laying_heights " << (m_heights == lay_heights::points ? "points" : m_heights == lay_heights::level ? "level" : "fitted") << "\n"; diff --git a/editor/editorSettings.hpp b/editor/editorSettings.hpp index f60553265..548f12b61 100644 --- a/editor/editorSettings.hpp +++ b/editor/editorSettings.hpp @@ -88,13 +88,15 @@ public: bool terrain_while_laying() const { return m_terrain_while_laying; } void terrain_while_laying(bool const Make) { m_terrain_while_laying = Make; } // the terrain model in the terrain panel: the band along the tracks it's loaded in, m; the chunks along a side of the square - // made around the camera; the formation and the slopes made along the tracks; the terrain following the tracks edited + // made around the camera; the formation and the slopes made along the tracks; the terrain following the tracks edited; the + // terrain made from the model around the camera within the download area, in the background struct terrain_model_settings { double band{300.0}; int around{4}; bool shape{true}; bool follow{true}; + bool area{true}; }; terrain_model_settings &terrain_model() { return m_terrain_model; } // the height offset of the terrain model to the tracks of the scenery, and whether it was fitted to them; false when none was stored diff --git a/lang/editor_pl.po b/lang/editor_pl.po index 9c6a8c908..668792f28 100644 --- a/lang/editor_pl.po +++ b/lang/editor_pl.po @@ -3195,12 +3195,6 @@ msgstr "Kamera w X %.1f Y %.1f" msgid "Distance (tiles)" msgstr "Zasięg (kafle)" -msgid "Fit to terrain" -msgstr "Dopasuj do terenu" - -msgid "Lays the imagery onto the ground geometry (terrain shapes, terrain tile models, editor terrain).\nPlaces without any ground use the height below." -msgstr "Kładzie zdjęcia na geometrii gruntu (kształty terenu, modele kafli terenu, teren edytora).\nMiejsca bez gruntu dostają wysokość podaną niżej." - msgid "Refit" msgstr "Dopasuj ponownie" @@ -3210,17 +3204,38 @@ msgstr "Dopasowuje zdjęcia od nowa, po zmianach terenu" msgid "Lift above ground (m)" msgstr "Uniesienie nad grunt (m)" -msgid "Raises the fitted imagery above the ground. Keep it below the objects you want to see:\nin the scene everything lower than this ends up under the imagery." -msgstr "Unosi dopasowane zdjęcia nad grunt. Trzymaj je poniżej obiektów, które chcesz widzieć:\nw scenie wszystko, co jest niżej, znajdzie się pod zdjęciami." - msgid "Height (m)" msgstr "Wysokość (m)" -msgid "Covered by objects and terrain" -msgstr "Chowaj za obiektami i terenem" +msgid "Show the photos" +msgstr "Pokaż zdjęcia" -msgid "Draws the imagery as part of the scene, so tracks, models and terrain in front of it hide it.\nIt is lit like the scene. Fully opaque, mouse placement lands on it as on any surface;\ntranslucent, it doesn't catch the mouse.\nNot available with the Better Renderer, which doesn't pick up geometry added in the editor." -msgstr "Rysuje zdjęcia jako część sceny, więc tory, modele i teren przed nimi je zasłaniają.\nJest oświetlone jak scena. W pełni kryjące łapie mysz przy wstawianiu jak każda powierzchnia;\nprzezroczyste nie łapie myszy.\nNiedostępne z Better Renderer, który nie widzi geometrii dodanej w edytorze." +msgid "Over the view" +msgstr "Na wierzchu widoku" + +msgid "On the terrain, in the scene" +msgstr "Na terenie, w scenie" + +msgid "A flat sheet in the scene" +msgstr "Płaska plansza w scenie" + +msgid "The photos lie on the terrain as its surface: tracks and models standing on them cover them, the scene lights them, and fully opaque the mouse places objects on them as on the ground." +msgstr "Zdjęcia leżą na terenie jak jego powierzchnia: tory i modele, które na nich stoją, zasłaniają je, scena je oświetla, a przy pełnym kryciu mysz stawia na nich obiekty jak na gruncie." + +msgid "One flat sheet at the height below, in the scene: for a scenery with no terrain yet. Where there is terrain, it cuts through the sheet." +msgstr "Jedna płaska plansza na wysokości podanej niżej, w scenie: dla scenerii, która nie ma jeszcze terenu. Tam, gdzie teren jest, przecina planszę." + +msgid "Raises the photos above the ground.\nWhatever is lower than this, the rails and the sleepers too, ends up under them: keep it small." +msgstr "Unosi zdjęcia nad grunt.\nWszystko, co jest niżej, także szyny i podkłady, znajdzie się pod nimi: trzymaj je małe." + +msgid "The Better Renderer doesn't show them in the scene: pick \"Over the view\"" +msgstr "Better Renderer nie pokazuje ich w scenie: wybierz „Na wierzchu widoku”" + +msgid "The photos are drawn over the whole view, over the tracks and models as well: lower the opacity to see what's under them. The quickest way to compare the scenery with the map." +msgstr "Zdjęcia są rysowane na całym widoku, także na torach i modelach: zmniejsz krycie, żeby widzieć, co pod nimi. Najszybszy sposób, by porównać scenerię z mapą." + +msgid "Height where there's no ground (m)" +msgstr "Wysokość tam, gdzie nie ma gruntu (m)" msgid "Opacity" msgstr "Krycie" @@ -12267,6 +12282,18 @@ msgstr "Wstrzymaj" msgid "Terrain model: %d of %d squares in the cache, %d failed" msgstr "Model terenu: %d z %d kwadratów w pamięci podręcznej, nieudanych %d" +msgid "The terrain of the scenery around the camera" +msgstr "Teren scenerii wokół kamery" + +msgid "Makes the terrain from the terrain model within the area, around the camera wherever it goes,\na chunk at a time while the editor is idle. The terrain there is already isn't touched.\nThe chunks made wait in memory until the scenery is saved (Ctrl+S)." +msgstr "Robi teren z NMT w obszarze, wokół kamery, gdziekolwiek pojedzie,\npo jednym kaflu, kiedy edytor nic nie robi. Teren, który już jest, zostaje nietknięty.\nZrobione kafle czekają w pamięci na zapis scenerii (Ctrl+S)." + +msgid "%zu chunk made" +msgid_plural "%zu chunks made" +msgstr[0] "%zu kafel zrobiony" +msgstr[1] "%zu kafle zrobione" +msgstr[2] "%zu kafli zrobionych" + msgid "Tab while laying: an arc, then a straight" msgstr "Tab przy kładzeniu: łuk, potem prosta" diff --git a/rendering/opengl33renderer.cpp b/rendering/opengl33renderer.cpp index a7262214b..5eb98222b 100644 --- a/rendering/opengl33renderer.cpp +++ b/rendering/opengl33renderer.cpp @@ -3140,8 +3140,16 @@ void opengl33_renderer::Render(scene::shape_node const &Shape, bool const Ignore break; } // render - + // a decal comes nearer the camera: the depth is reversed (GL_GEQUAL), so a positive offset. not in the shadows, it casts none + auto const decal{data.decal && m_renderpass.draw_mode != rendermode::shadows}; + if (decal) + { + ::glEnable(GL_POLYGON_OFFSET_FILL); + ::glPolygonOffset(2.f, 8.f); + } draw(data.geometry); + if (decal) + ::glDisable(GL_POLYGON_OFFSET_FILL); // debug data ++m_renderpass.draw_stats.shapes; ++m_renderpass.draw_stats.drawcalls; diff --git a/scene/scenenode.h b/scene/scenenode.h index 11032882f..237056669 100644 --- a/scene/scenenode.h +++ b/scene/scenenode.h @@ -101,6 +101,9 @@ public: gfx::userdata_array userdata; // terrain file the shape comes from, see scene::terrain_file::reference_of(); 0: none, or not known (only the editor asks) std::uint16_t terrainfile { 0 }; + // drawn pulled towards the camera in the depth buffer, over the surface it lies on: the photos of the editor laid on the + // terrain. not kept by serialize() + bool decal { false }; // methods: // sends content of the struct to provided stream void @@ -127,6 +130,9 @@ public: // relative to Origin. used by the editor's terrain to own editable geometry it can re-upload. shape_node & make_terrain( material_handle const Material, std::vector Vertices, glm::dvec3 const Origin ); + // see shapenode_data::decal + void + decal( bool const Decal ) { m_data.decal = Decal; } // adds content of provided node to already enclosed geometry. returns: true if merge could be performed bool merge( shape_node &Shape );