|
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> |
@@ -2307,6 +2308,11 @@ void CelestiaCore::updateFOV(float newFOV, std::optional<Eigen::Vector2f> focus, |
2307 | 2308 | } |
2308 | 2309 | } |
2309 | 2310 |
|
| 2311 | +template<typename T> |
| 2312 | +bool ready(const std::future<T> &future) |
| 2313 | +{ |
| 2314 | + return future.wait_for(std::chrono::seconds(1)) == std::future_status::ready; |
| 2315 | +} |
2310 | 2316 |
|
2311 | 2317 | bool CelestiaCore::initSimulation(const fs::path& configFileName, |
2312 | 2318 | const vector<fs::path>& extrasDirs, |
@@ -2391,23 +2397,46 @@ bool CelestiaCore::initSimulation(const fs::path& configFileName, |
2391 | 2397 |
|
2392 | 2398 | StarDetails::SetStarTextures(config->starTextures); |
2393 | 2399 |
|
2394 | | - std::unique_ptr<StarDatabase> starCatalog = loadStars(*config, progressNotifier); |
2395 | | - if (starCatalog == nullptr) |
2396 | | - { |
2397 | | - fatalError(_("Cannot read star database."), false); |
2398 | | - return false; |
2399 | | - } |
2400 | | - universe->setStarCatalog(std::move(starCatalog)); |
| 2400 | + progressNotifier->update(_("Deep Space Objects and Star catalogs")); |
2401 | 2401 |
|
2402 | | - /***** Load the deep sky catalogs *****/ |
| 2402 | + auto *cfg = config.get(); |
2403 | 2403 |
|
2404 | | - std::unique_ptr<DSODatabase> dsoCatalog = loadDSO(*config, progressNotifier); |
2405 | | - if (dsoCatalog == nullptr) |
| 2404 | + std::future<std::unique_ptr<StarDatabase>> starsLoader = std::async(std::launch::async, [cfg]() { |
| 2405 | + return loadStars(*cfg, nullptr); |
| 2406 | + }); |
| 2407 | + |
| 2408 | + std::future<std::unique_ptr<DSODatabase>> dsoLoader = std::async(std::launch::async, [cfg]() { |
| 2409 | + return loadDSO(*cfg, nullptr); |
| 2410 | + }); |
| 2411 | + |
| 2412 | + for (bool starsReady = false, dsoReady = false; !starsReady || !dsoReady;) |
2406 | 2413 | { |
2407 | | - fatalError(_("Cannot read DSO database."), false); |
2408 | | - return false; |
| 2414 | + if (!starsReady && ready(starsLoader)) |
| 2415 | + { |
| 2416 | + starsReady = true; |
| 2417 | + |
| 2418 | + std::unique_ptr<StarDatabase> starCatalog = starsLoader.get(); |
| 2419 | + if (starCatalog == nullptr) |
| 2420 | + { |
| 2421 | + fatalError(_("Cannot read star database."), false); |
| 2422 | + return false; |
| 2423 | + } |
| 2424 | + universe->setStarCatalog(std::move(starCatalog)); |
| 2425 | + } |
| 2426 | + |
| 2427 | + if (!dsoReady && ready(dsoLoader)) |
| 2428 | + { |
| 2429 | + dsoReady = true; |
| 2430 | + |
| 2431 | + std::unique_ptr<DSODatabase> dsoCatalog = dsoLoader.get(); |
| 2432 | + if (dsoCatalog == nullptr) |
| 2433 | + { |
| 2434 | + fatalError(_("Cannot read DSO database."), false); |
| 2435 | + return false; |
| 2436 | + } |
| 2437 | + universe->setDSOCatalog(std::move(dsoCatalog)); |
| 2438 | + } |
2409 | 2439 | } |
2410 | | - universe->setDSOCatalog(std::move(dsoCatalog)); |
2411 | 2440 |
|
2412 | 2441 | /***** Load the solar system catalogs *****/ |
2413 | 2442 |
|
@@ -3270,14 +3299,14 @@ void CelestiaCore::setAudioNoPause(int channel, bool nopause) |
3270 | 3299 |
|
3271 | 3300 | void CelestiaCore::pauseAudioIfNeeded() |
3272 | 3301 | { |
3273 | | - for (auto const &[_, value] : audioSessions) |
| 3302 | + for (const auto &[_, value] : audioSessions) |
3274 | 3303 | if (!value->nopause()) |
3275 | 3304 | value->stop(); |
3276 | 3305 | } |
3277 | 3306 |
|
3278 | 3307 | void CelestiaCore::resumeAudioIfNeeded() |
3279 | 3308 | { |
3280 | | - for (auto const &[_, value] : audioSessions) |
| 3309 | + for (const auto &[_, value] : audioSessions) |
3281 | 3310 | if (!value->nopause()) |
3282 | 3311 | value->play(); |
3283 | 3312 | } |
|
0 commit comments