|
24 | 24 | #include <cassert> |
25 | 25 | #include <ctime> |
26 | 26 | #include <fstream> |
| 27 | +#include <future> |
27 | 28 | #include <iomanip> |
28 | 29 | #include <iostream> |
29 | 30 | #include <iterator> |
@@ -2274,6 +2275,11 @@ Eigen::Vector3f CelestiaCore::getPickRay(float x, float y, const celestia::View |
2274 | 2275 | return renderer->getProjectionMode()->getPickRay(pickX, pickY, view->getObserver()->getZoom()); |
2275 | 2276 | } |
2276 | 2277 |
|
| 2278 | +template<typename T> |
| 2279 | +bool ready(const std::future<T> &future) |
| 2280 | +{ |
| 2281 | + return future.wait_for(std::chrono::seconds(1)) == std::future_status::ready; |
| 2282 | +} |
2277 | 2283 |
|
2278 | 2284 | bool CelestiaCore::initSimulation(const fs::path& configFileName, |
2279 | 2285 | const vector<fs::path>& extrasDirs, |
@@ -2358,23 +2364,46 @@ bool CelestiaCore::initSimulation(const fs::path& configFileName, |
2358 | 2364 |
|
2359 | 2365 | StarDetails::SetStarTextures(config->starTextures); |
2360 | 2366 |
|
2361 | | - std::unique_ptr<StarDatabase> starCatalog = loadStars(*config, progressNotifier); |
2362 | | - if (starCatalog == nullptr) |
2363 | | - { |
2364 | | - fatalError(_("Cannot read star database."), false); |
2365 | | - return false; |
2366 | | - } |
2367 | | - universe->setStarCatalog(std::move(starCatalog)); |
| 2367 | + progressNotifier->update(_("Deep Space Objects and Star catalogs")); |
2368 | 2368 |
|
2369 | | - /***** Load the deep sky catalogs *****/ |
| 2369 | + auto *cfg = config.get(); |
2370 | 2370 |
|
2371 | | - std::unique_ptr<DSODatabase> dsoCatalog = loadDSO(*config, progressNotifier); |
2372 | | - if (dsoCatalog == nullptr) |
| 2371 | + std::future<std::unique_ptr<StarDatabase>> starsLoader = std::async(std::launch::async, [cfg]() { |
| 2372 | + return loadStars(*cfg, nullptr); |
| 2373 | + }); |
| 2374 | + |
| 2375 | + std::future<std::unique_ptr<DSODatabase>> dsoLoader = std::async(std::launch::async, [cfg]() { |
| 2376 | + return loadDSO(*cfg, nullptr); |
| 2377 | + }); |
| 2378 | + |
| 2379 | + for (bool starsReady = false, dsoReady = false; !starsReady || !dsoReady;) |
2373 | 2380 | { |
2374 | | - fatalError(_("Cannot read DSO database."), false); |
2375 | | - return false; |
| 2381 | + if (!starsReady && ready(starsLoader)) |
| 2382 | + { |
| 2383 | + starsReady = true; |
| 2384 | + |
| 2385 | + std::unique_ptr<StarDatabase> starCatalog = starsLoader.get(); |
| 2386 | + if (starCatalog == nullptr) |
| 2387 | + { |
| 2388 | + fatalError(_("Cannot read star database."), false); |
| 2389 | + return false; |
| 2390 | + } |
| 2391 | + universe->setStarCatalog(std::move(starCatalog)); |
| 2392 | + } |
| 2393 | + |
| 2394 | + if (!dsoReady && ready(dsoLoader)) |
| 2395 | + { |
| 2396 | + dsoReady = true; |
| 2397 | + |
| 2398 | + std::unique_ptr<DSODatabase> dsoCatalog = dsoLoader.get(); |
| 2399 | + if (dsoCatalog == nullptr) |
| 2400 | + { |
| 2401 | + fatalError(_("Cannot read DSO database."), false); |
| 2402 | + return false; |
| 2403 | + } |
| 2404 | + universe->setDSOCatalog(std::move(dsoCatalog)); |
| 2405 | + } |
2376 | 2406 | } |
2377 | | - universe->setDSOCatalog(std::move(dsoCatalog)); |
2378 | 2407 |
|
2379 | 2408 | /***** Load the solar system catalogs *****/ |
2380 | 2409 |
|
@@ -3237,14 +3266,14 @@ void CelestiaCore::setAudioNoPause(int channel, bool nopause) |
3237 | 3266 |
|
3238 | 3267 | void CelestiaCore::pauseAudioIfNeeded() |
3239 | 3268 | { |
3240 | | - for (auto const &[_, value] : audioSessions) |
| 3269 | + for (const auto &[_, value] : audioSessions) |
3241 | 3270 | if (!value->nopause()) |
3242 | 3271 | value->stop(); |
3243 | 3272 | } |
3244 | 3273 |
|
3245 | 3274 | void CelestiaCore::resumeAudioIfNeeded() |
3246 | 3275 | { |
3247 | | - for (auto const &[_, value] : audioSessions) |
| 3276 | + for (const auto &[_, value] : audioSessions) |
3248 | 3277 | if (!value->nopause()) |
3249 | 3278 | value->play(); |
3250 | 3279 | } |
|
0 commit comments