17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-22 22:31:09 +02:00

fix(editor): the templates looked for in the background from the start, the panels don't wait for them

The include bank read every .inc of the scenery directory on the first use, on the main thread: opening the
switch panel or selecting a switch stopped the editor until all of them were read, which on a large scenery
directory under Windows takes long. The bank now starts looking as the editor starts, in the background,
and the main thread only reads the descriptions once the files are read.

- the switch drives, turntables and signals are read again from the bank when it changes; the panels show
  "Looking for the templates..." meanwhile, only the edits which need the templates wait for them
- the sweep tool takes the templates from the bank instead of looking through the scenery directory again
- a folder linked into one of its own subfolders no longer leads the walk in circles
- the log tells how many templates were found and how long it took
This commit is contained in:
maj00r
2026-10-19 16:21:55 +02:00
parent ff1710d9ea
commit 949965009b
12 changed files with 275 additions and 94 deletions

View File

@@ -214,13 +214,15 @@ void draw_signal_icon(ImDrawList *Draw, ImVec2 const Origin, ImVec2 const Size,
} // namespace
void editor_mode::signal_scan()
bool editor_mode::signal_scan(bool const Wait)
{
auto &tool{m_signal};
if (false == EditorIncludes.scanned())
EditorIncludes.scan();
if (tool.revision == EditorIncludes.revision())
return;
if (Wait)
EditorIncludes.wait();
else
EditorIncludes.start();
if (false == EditorIncludes.scanned() || tool.revision == EditorIncludes.revision())
return false;
tool.revision = EditorIncludes.revision();
std::string chosen[kKindCount];
for (int i = 0; i < kKindCount; ++i)
@@ -280,6 +282,7 @@ void editor_mode::signal_scan()
}
tool.chosen[i] = best;
}
return true;
}
editor_mode::signal_template const *editor_mode::signal_armed() const
@@ -346,9 +349,9 @@ std::string editor_mode::signal_intent_label(signal_template const &Template, si
void editor_mode::signal_refresh(bool const Force)
{
auto &tool{m_signal};
signal_scan();
auto const scanned{signal_scan(false)};
auto const now{ImGui::GetTime()};
if (false == Force && tool.standing_history == m_history.size() && tool.standing_redo == g_redo.size() && now - tool.standing_time < kRefreshPeriod)
if (false == Force && false == scanned && tool.standing_history == m_history.size() && tool.standing_redo == g_redo.size() && now - tool.standing_time < kRefreshPeriod)
return;
tool.standing_history = m_history.size();
tool.standing_redo = g_redo.size();
@@ -893,7 +896,12 @@ void editor_mode::render_signal_selected()
void editor_mode::render_signal_ui()
{
auto &tool{m_signal};
signal_scan();
signal_scan(false);
if (tool.templates.empty() && EditorIncludes.searching())
{
ImGui::TextDisabled("%s", STR_C("Looking for the templates..."));
return;
}
if (tool.templates.empty())
{
ImGui::TextWrapped("%s", STR_C("No signal templates: no template of the scenery directory is described with category: signal. tools/editor/signal_headers.py writes the descriptions into the signal templates."));