Skip to content

Commit 88c02d0

Browse files
committed
WIP: Load DSO and Star catalogs in parallel
1 parent a082fb9 commit 88c02d0

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

src/celestia/celestiacore.cpp

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <cassert>
2525
#include <ctime>
2626
#include <fstream>
27+
#include <future>
2728
#include <iomanip>
2829
#include <iostream>
2930
#include <iterator>
@@ -2274,6 +2275,11 @@ Eigen::Vector3f CelestiaCore::getPickRay(float x, float y, const celestia::View
22742275
return renderer->getProjectionMode()->getPickRay(pickX, pickY, view->getObserver()->getZoom());
22752276
}
22762277

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+
}
22772283

22782284
bool CelestiaCore::initSimulation(const fs::path& configFileName,
22792285
const vector<fs::path>& extrasDirs,
@@ -2358,23 +2364,46 @@ bool CelestiaCore::initSimulation(const fs::path& configFileName,
23582364

23592365
StarDetails::SetStarTextures(config->starTextures);
23602366

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"));
23682368

2369-
/***** Load the deep sky catalogs *****/
2369+
auto *cfg = config.get();
23702370

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;)
23732380
{
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+
}
23762406
}
2377-
universe->setDSOCatalog(std::move(dsoCatalog));
23782407

23792408
/***** Load the solar system catalogs *****/
23802409

@@ -3237,14 +3266,14 @@ void CelestiaCore::setAudioNoPause(int channel, bool nopause)
32373266

32383267
void CelestiaCore::pauseAudioIfNeeded()
32393268
{
3240-
for (auto const &[_, value] : audioSessions)
3269+
for (const auto &[_, value] : audioSessions)
32413270
if (!value->nopause())
32423271
value->stop();
32433272
}
32443273

32453274
void CelestiaCore::resumeAudioIfNeeded()
32463275
{
3247-
for (auto const &[_, value] : audioSessions)
3276+
for (const auto &[_, value] : audioSessions)
32483277
if (!value->nopause())
32493278
value->play();
32503279
}

0 commit comments

Comments
 (0)