|
28 | 28 | #include <shellapi.h> |
29 | 29 | #pragma comment(lib, "shell32.lib") |
30 | 30 |
|
| 31 | +#include <tbb/parallel_for_each.h> |
| 32 | + |
31 | 33 | #include "Common/object_broker.h" |
32 | 34 |
|
33 | 35 | #include "account_manager.h" |
@@ -150,16 +152,43 @@ CMainMenu::~CMainMenu() |
150 | 152 | void CMainMenu::ReadTextureInfo() |
151 | 153 | { |
152 | 154 | string_path buf; |
153 | | - FS_FileSet fset; |
154 | | - FS.file_list(fset, "$game_config$", FS_ListFiles, strconcat(sizeof(buf), buf, UI_PATH, "\\", "textures_descr\\*.xml")); |
155 | | - for (const auto& file : fset) |
| 155 | + FS_FileSet files; |
| 156 | + |
| 157 | + const auto UpdateFileSet = [&](pcstr path) |
156 | 158 | { |
157 | | - string_path fn1, fn2, fn3; |
158 | | - _splitpath(file.name.c_str(), fn1, fn2, fn3, 0); |
159 | | - xr_strcat(fn3, ".xml"); |
| 159 | + FS.file_list(files, "$game_config$", FS_ListFiles, |
| 160 | + strconcat(sizeof(buf), buf, path, "\\", "textures_descr\\*.xml") |
| 161 | + ); |
| 162 | + }; |
160 | 163 |
|
161 | | - CUITextureMaster::ParseShTexInfo(fn3); |
162 | | - } |
| 164 | + const auto ParseFileSet = [&]() |
| 165 | + { |
| 166 | + /* |
| 167 | + * Original CoP textures_descr |
| 168 | + * loading time: |
| 169 | + * Single-threaded ~80 ms |
| 170 | + * Multi-threaded ~40 ms |
| 171 | + * Just a bit of speedup |
| 172 | + */ |
| 173 | + tbb::parallel_for_each(files, [](const FS_File& file) |
| 174 | + { |
| 175 | + string_path path, name; |
| 176 | + _splitpath(file.name.c_str(), nullptr, path, name, nullptr); |
| 177 | + xr_strcat(name, ".xml"); |
| 178 | + path[xr_strlen(path) - 1] = '\0'; // cut the latest '\\' |
| 179 | + |
| 180 | + CUITextureMaster::ParseShTexInfo(path, name); |
| 181 | + }); |
| 182 | + }; |
| 183 | + |
| 184 | + UpdateFileSet(UI_PATH_DEFAULT); |
| 185 | + ParseFileSet(); |
| 186 | + |
| 187 | + if (0 == xr_strcmp(UI_PATH, UI_PATH_DEFAULT)) |
| 188 | + return; |
| 189 | + |
| 190 | + UpdateFileSet(UI_PATH); |
| 191 | + ParseFileSet(); |
163 | 192 | } |
164 | 193 |
|
165 | 194 | void CMainMenu::Activate(bool bActivate) |
|
0 commit comments