mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-20 17:24:53 +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:
@@ -137,31 +137,40 @@ std::string lower(std::string Text)
|
||||
void editor_mode::sweep_scan_models()
|
||||
{
|
||||
auto &tool{m_sweep};
|
||||
if (tool.scanned)
|
||||
EditorIncludes.start();
|
||||
auto changed{false};
|
||||
if (false == tool.scanned)
|
||||
{
|
||||
tool.scanned = true;
|
||||
changed = true;
|
||||
std::error_code error;
|
||||
for (auto const &entry : std::filesystem::recursive_directory_iterator("models", std::filesystem::directory_options::skip_permission_denied, error))
|
||||
{
|
||||
if (false == entry.is_regular_file(error))
|
||||
continue;
|
||||
auto const extension{lower(entry.path().extension().string())};
|
||||
if (extension != ".e3d" && extension != ".t3d")
|
||||
continue;
|
||||
auto name{std::filesystem::relative(entry.path(), "models", error).generic_string()};
|
||||
name.erase(name.size() - extension.size());
|
||||
tool.models.push_back(name);
|
||||
}
|
||||
}
|
||||
// the templates come from the include bank, which looks through the scenery directory in the background
|
||||
if (EditorIncludes.scanned() && tool.revision != EditorIncludes.revision())
|
||||
{
|
||||
tool.revision = EditorIncludes.revision();
|
||||
std::erase_if(tool.models, [](std::string const &Model) { return Model.ends_with(".inc"); });
|
||||
for (auto const &entry : EditorIncludes.entries())
|
||||
tool.models.push_back(entry.file);
|
||||
changed = true;
|
||||
}
|
||||
if (false == changed)
|
||||
return;
|
||||
tool.scanned = true;
|
||||
std::error_code error;
|
||||
std::set<std::string> found;
|
||||
for (auto const &entry : std::filesystem::recursive_directory_iterator("models", std::filesystem::directory_options::skip_permission_denied, error))
|
||||
{
|
||||
if (false == entry.is_regular_file(error))
|
||||
continue;
|
||||
auto const extension{lower(entry.path().extension().string())};
|
||||
if (extension != ".e3d" && extension != ".t3d")
|
||||
continue;
|
||||
auto name{std::filesystem::relative(entry.path(), "models", error).generic_string()};
|
||||
name.erase(name.size() - extension.size());
|
||||
found.insert(name);
|
||||
}
|
||||
for (auto const &entry : std::filesystem::recursive_directory_iterator("scenery", std::filesystem::directory_options::skip_permission_denied, error))
|
||||
{
|
||||
if (entry.is_regular_file(error) && lower(entry.path().extension().string()) == ".inc")
|
||||
found.insert(std::filesystem::relative(entry.path(), "scenery", error).generic_string());
|
||||
}
|
||||
tool.models.assign(found.begin(), found.end());
|
||||
std::sort(tool.models.begin(), tool.models.end());
|
||||
tool.models.erase(std::unique(tool.models.begin(), tool.models.end()), tool.models.end());
|
||||
}
|
||||
|
||||
|
||||
void editor_mode::sweep_curve()
|
||||
{
|
||||
auto &tool{m_sweep};
|
||||
|
||||
Reference in New Issue
Block a user