From 44d94ae3d38b36362e130a6f6f615b24c933580a Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:59 +0100 Subject: [PATCH] fix(editor): the answer Without terrain keeps to the scenery open, the settings stay as they were nmt_decline_offer() turned off terrain_while_laying and terrain_model().area in the settings of the editor and saved them, so one Without terrain for a scratch scenery left the terrain off for every scenery opened later. The answer now holds for the scenery open only (nmt_state::declined, read through nmt_area()); the checkbox of the terrain panel shows it and, ticked, turns the terrain on again and keeps it in the settings. The nmtquestion self-test no longer writes the tester's settings, and fails the run if the answer changed them. --- application/editormode.cpp | 4 +-- application/editormode.h | 9 +++++-- application/editormodenmt.cpp | 30 ++++++++++++++------- application/editormodeselftest.cpp | 2 +- application/editormodeselftestexpect.cpp | 2 +- application/editormodeselftestterrain.cpp | 21 +++++++++------ tests/editor/cases/fs_3_without_terrain.txt | 5 ++-- 7 files changed, 47 insertions(+), 26 deletions(-) diff --git a/application/editormode.cpp b/application/editormode.cpp index ad505486c..10e243242 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -617,7 +617,7 @@ void editor_mode::ground_sources(editor_orthophoto &Layer) return true; // asked for, the tile goes onto it once it comes; not where no terrain is to be made of the model, as after the answer without // terrain - if (m_nmt.placed() && (m_nmt_state.grow || EditorSettings.terrain_model().area)) + if (m_nmt.placed() && (m_nmt_state.grow || nmt_area())) m_nmt.request({X - 1.0, Z - 1.0}, {X + 1.0, Z + 1.0}); return false; }); @@ -6274,7 +6274,7 @@ void editor_mode::render_ground_warning(tutorial_lesson const &Lesson) // over a panel the pointer is over no ground, and in a scenery laid without terrain no ground is to be there if (Lesson.action != tutorial_lesson::trial::lay || ui()->mode() != nodebank_panel::TRACK || ImGui::GetIO().WantCaptureMouse || false == ImGui::IsMousePosValid()) return; - auto const expected{m_streamer.resident() > 0 || ((m_nmt_state.grow || EditorSettings.terrain_model().area) && m_nmt.placed())}; + auto const expected{m_streamer.resident() > 0 || ((m_nmt_state.grow || nmt_area()) && m_nmt.placed())}; if (expected && false == GfxRenderer->Mouse_Hit()) ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", STR_C("There is no ground under the mouse: the track will lie flat at height 0. Real ground: F5")); } diff --git a/application/editormode.h b/application/editormode.h index 986626f31..38df9b4bc 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -385,6 +385,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri double band{300.0}; // m from the tracks the chunks made along them reach bool shape{true}; // the formation and the slopes of the tracks as modifiers of the terrain bool grow{true}; // while a track is laid, the terrain is made around the cursor where there's none + // the answer Without terrain for the scenery open: nothing of the model is made around the camera by itself, whatever the + // settings, which stay as they were for the other sceneries + bool declined{false}; bool laying{false}; // the tracks committed are being laid: they leave the terrain as it is bool follow{true}; // a track with its formation edited takes it along, the formation led anew bool grown{false}; // the chunks waiting were all asked for by growing: the formations aren't made anew after them @@ -656,8 +659,10 @@ class editor_mode : public application_mode, private editor_track::observer, pri void nmt_place_scenery(glm::dvec2 const &Point); void nmt_accept_offer(); // the answer without terrain: the tracks lie on the plane, nothing of the terrain model is loaded by itself any more, under the - // tracks laid nor around the camera + // tracks laid nor around the camera, in the scenery open; the settings stay as they are for the other sceneries void nmt_decline_offer(); + // the terrain of the download area made around the camera by itself: as the settings have it, unless declined for this scenery + bool nmt_area() const; // the whole scenery: tracks, includes and models, moved up or down as one undo step std::size_t nmt_join_ends(); // the turntables as they lie, each with the ends of the tracks running up to it on its rim @@ -3208,7 +3213,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::string badge; // the mouse or the keys drawn over the view, for the clips of the tutorial glm::vec2 badge_at{0.0f}; // its bottom left corner, in the pixels of the window std::map marks; // the heights of the ends of tracks kept by mark, for expect lift - std::optional> terrain_kept; // the terrain made while laying and around the camera before nmtquestion + std::optional> terrain_kept; // the terrain made while laying, and the answer without it, before nmtquestion }; selftest m_selftest; using selftest_result = editor_selftest_result; diff --git a/application/editormodenmt.cpp b/application/editormodenmt.cpp index 56e450f3f..15a994301 100644 --- a/application/editormodenmt.cpp +++ b/application/editormodenmt.cpp @@ -1085,7 +1085,7 @@ void editor_mode::nmt_area_terrain() 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)) + if (false == area.run_only.value_or(nmt_area())) return held("turned off"); if (m_orthophoto.area().empty()) return held("no area"); @@ -1217,7 +1217,7 @@ void editor_mode::nmt_update() m_nmt_prefetched = wanted; // unless no terrain is made of the model by itself, as after the answer without terrain: what the terrain panel asks for then is // downloaded as it's asked for - if (state.grow || EditorSettings.terrain_model().area) + if (state.grow || nmt_area()) m_nmt.prefetch(wanted); // the terrain around the camera looked at again within the new area m_area_terrain.listed = false; @@ -2140,13 +2140,18 @@ void editor_mode::render_download_area_ui(editor_orthophoto::statistics const &S } } auto &model{EditorSettings.terrain_model()}; - if (ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &model.area)) + // as it is for the scenery open: off after the answer Without terrain, and ticked, on again and kept so in the settings + if (bool area{nmt_area()}; ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &area)) + { + m_nmt_state.declined = false; + model.area = 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) + if (nmt_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()); @@ -2599,9 +2604,10 @@ void editor_mode::nmt_accept_offer() state.offset = 0.0; nmt_make(nmt_keys_around()); state.prompt = false; - // the terrain goes on under the tracks as they're laid and around the camera, as the answer says, also after the other answer was - // given for a scenery before; the model of the download area is put into the cache again if that answer stopped it + // the terrain goes on under the tracks as they're laid and around the camera, as the answer says, also where the settings had it + // off; the model of the download area is put into the cache again if it was stopped state.grow = true; + state.declined = false; EditorSettings.terrain_while_laying(true); EditorSettings.terrain_model().area = true; EditorSettings.save(); @@ -2615,16 +2621,20 @@ void editor_mode::nmt_decline_offer() state.prompt = false; // nothing of the model loaded any more: not under the tracks as they're laid, as the checkbox of the layers turns it off, nor around // the camera within the download area, as the checkbox of the terrain panel does, nor the squares of the download area into the - // cache. Kept on, they went on being loaded, and where there's no network their requests failed in the log + // cache. Kept on, they went on being loaded, and where there's no network their requests failed in the log. For this scenery only: + // the settings stay as they were, for the sceneries opened later state.grow = false; - EditorSettings.terrain_while_laying(false); - EditorSettings.terrain_model().area = false; - EditorSettings.save(); + state.declined = true; m_nmt.prefetch({}); // nor the squares asked for meanwhile, as the aerial photos asked for them to lie on m_nmt.cancel(); } +bool editor_mode::nmt_area() const +{ + return false == m_nmt_state.declined && EditorSettings.terrain_model().area; +} + void editor_mode::render_nmt_prompt() { auto &state{m_nmt_state}; diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index c733f8980..0bcd3a572 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -194,7 +194,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // to it out along their lines from the rim, against the model there // nmtstate logs how far the tracks going onto the terrain model are // nmtquestion the question of the terrain of a new scenery opened, or answered without terrain as its card does; -// restore: the settings of the terrain made by itself put back as they were before that answer +// restore: the terrain made by itself as it was before that answer, which leaves the settings be // gradelines the grade line each track shares written to the file, for a map of them // fitreport to the file: the tracks off the terrain model, the switches off their plane, the rails on common timbers apart in height // gradeline the common grade line of the route open in the profile tool: its design lifted and applied, the route taken off it and back diff --git a/application/editormodeselftestexpect.cpp b/application/editormodeselftestexpect.cpp index 7f1b87c1a..4f16a1b2f 100644 --- a/application/editormodeselftestexpect.cpp +++ b/application/editormodeselftestexpect.cpp @@ -516,7 +516,7 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com expect_steps(what, words, static_cast(std::ranges::count_if(m_history, [](EditorSnapshot const &Step) { return false == Step.joined; }))); else if (false == expect_shown(kind, what, words, {m_switch.status, ui()->refusal_shown(), ui()->status_line(), m_lay.mouse, - {{"grow", m_nmt_state.grow}, {"area", EditorSettings.terrain_model().area}, {"prompt", m_nmt_state.prompt}}})) + {{"grow", m_nmt_state.grow}, {"area", nmt_area()}, {"prompt", m_nmt_state.prompt}}})) expectation(false, what, "no expectation " + kind, "cant, joint, records, shaped, speed, gauge, track, route, norms, findings, height, lift, includes, status, statuslacks, refusal, statusline, laycursor, terrain or steps"); return selftest_result::handled; diff --git a/application/editormodeselftestterrain.cpp b/application/editormodeselftestterrain.cpp index cdacd84e8..ed796d446 100644 --- a/application/editormodeselftestterrain.cpp +++ b/application/editormodeselftestterrain.cpp @@ -513,26 +513,31 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co if (command == "nmtquestion") { // the question of the terrain of a new scenery: open, as the first L in an empty scenery opens it, or answered without - // terrain, as its card does it; restore: the settings of the terrain made by itself as they were before the answer, which - // keeps them with the editor + // terrain, as its card does it; restore: the terrain made by itself as it was before the answer. The answer keeps to the + // scenery open, so the settings of the tester aren't written std::string answer; words >> answer; - auto &model{EditorSettings.terrain_model()}; + auto const &model{EditorSettings.terrain_model()}; if (answer == "open") m_nmt_state.prompt = true; else if (answer == "flat") { - m_selftest.terrain_kept = std::pair{m_nmt_state.grow, model.area}; + auto const kept{std::pair{EditorSettings.terrain_while_laying(), model.area}}; + m_selftest.terrain_kept = std::pair{m_nmt_state.grow, m_nmt_state.declined}; nmt_decline_offer(); + // the settings as they were: the answer is for this scenery alone + if (std::pair{EditorSettings.terrain_while_laying(), model.area} != kept) + { + editor_selftest::fail(); + WriteLog("SELFTEST FAIL nmtquestion flat: the settings of the terrain changed"); + } } else if (answer == "restore" && m_selftest.terrain_kept.has_value()) { m_nmt_state.grow = m_selftest.terrain_kept->first; - model.area = m_selftest.terrain_kept->second; - EditorSettings.terrain_while_laying(m_nmt_state.grow); - EditorSettings.save(); + m_nmt_state.declined = m_selftest.terrain_kept->second; } - WriteLog(format("SELFTEST nmtquestion %s: prompt %d, terrain while laying %d, around the camera %d", answer.c_str(), m_nmt_state.prompt ? 1 : 0, m_nmt_state.grow ? 1 : 0, model.area ? 1 : 0)); + WriteLog(format("SELFTEST nmtquestion %s: prompt %d, terrain while laying %d, around the camera %d", answer.c_str(), m_nmt_state.prompt ? 1 : 0, m_nmt_state.grow ? 1 : 0, nmt_area() ? 1 : 0)); return selftest_result::handled; } if (command == "nmtgrow") diff --git a/tests/editor/cases/fs_3_without_terrain.txt b/tests/editor/cases/fs_3_without_terrain.txt index a56bc93a4..b2b7c70d7 100644 --- a/tests/editor/cases/fs_3_without_terrain.txt +++ b/tests/editor/cases/fs_3_without_terrain.txt @@ -1,7 +1,8 @@ # First steps: the answer Without terrain to the question of the terrain of a new empty scenery turns off the terrain made of the # terrain model by itself: under the tracks as they're laid (the checkbox of the layers) and around the camera within the download -# area (the checkbox of the terrain panel), so nothing of the model is asked for. The question asked as the first L in an empty -# scenery asks it (the fixture has tracks, so it isn't asked by itself) +# area (the checkbox of the terrain panel), so nothing of the model is asked for. For this scenery only: the settings, kept for the +# sceneries opened later, stay as they were (nmtquestion flat fails the run if they changed). The question asked as the first L +# in an empty scenery asks it (the fixture has tracks, so it isn't asked by itself) wait 5 nmtsettings grow 1 wait 2