From 2a29fad1bb97db0036f681004053733c580afac8 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 8 Aug 2016 23:13:57 +0100 Subject: [PATCH] Async loading of NaturalEarth data for launcher. --- src/GUI/QtLauncher.cxx | 91 ++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 64f5b76fa..16a0a104d 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -47,6 +47,7 @@ #include #include #include +#include // Simgear #include @@ -257,6 +258,60 @@ private: }; }; +class NaturalEarthDataLoaderThread : public QThread +{ + Q_OBJECT +public: + + NaturalEarthDataLoaderThread() + { + connect(this, &QThread::finished, this, &NaturalEarthDataLoaderThread::onFinished); + } + +protected: + virtual void run() Q_DECL_OVERRIDE + { + SGTimeStamp st; + st.stamp(); + + loadNaturalEarthFile("ne_10m_coastline.shp", flightgear::PolyLine::COASTLINE, false); + loadNaturalEarthFile("ne_10m_rivers_lake_centerlines.shp", flightgear::PolyLine::RIVER, false); + loadNaturalEarthFile("ne_10m_lakes.shp", flightgear::PolyLine::LAKE, true); + + qDebug() << "load basic data took" << st.elapsedMSec(); + + st.stamp(); + loadNaturalEarthFile("ne_10m_urban_areas.shp", flightgear::PolyLine::URBAN, true); + + qDebug() << "loading urban areas took:" << st.elapsedMSec(); + + } + +private: + void onFinished() + { + flightgear::PolyLine::bulkAddToSpatialIndex(m_parsedLines); + qDebug() << "finished loading Natural Earth data"; + deleteLater(); // commit suicide + } + + void loadNaturalEarthFile(const std::string& aFileName, + flightgear::PolyLine::Type aType, + bool areClosed) + { + SGPath path(globals->get_fg_root()); + path.append( "Geodata" ); + path.append(aFileName); + if (!path.exists()) + return; // silently fail for now + + flightgear::PolyLineList lines; + flightgear::SHPParser::parsePolyLines(path, aType, m_parsedLines, areClosed); + } + + flightgear::PolyLineList m_parsedLines; +}; + } // of anonymous namespace class AircraftProxyModel : public QSortFilterProxyModel @@ -405,39 +460,6 @@ void initApp(int& argc, char** argv) } } -void loadNaturalEarthFile(const std::string& aFileName, - flightgear::PolyLine::Type aType, - bool areClosed) -{ - SGPath path(globals->get_fg_root()); - path.append( "Geodata" ); - path.append(aFileName); - if (!path.exists()) - return; // silently fail for now - - flightgear::PolyLineList lines; - flightgear::SHPParser::parsePolyLines(path, aType, lines, areClosed); - flightgear::PolyLine::bulkAddToSpatialIndex(lines); -} - -void loadNaturalEarthData() -{ - SGTimeStamp st; - st.stamp(); - - loadNaturalEarthFile("ne_10m_coastline.shp", flightgear::PolyLine::COASTLINE, false); - loadNaturalEarthFile("ne_10m_rivers_lake_centerlines.shp", flightgear::PolyLine::RIVER, false); - loadNaturalEarthFile("ne_10m_lakes.shp", flightgear::PolyLine::LAKE, true); - - qDebug() << "load basic data took" << st.elapsedMSec(); - - - st.stamp(); - loadNaturalEarthFile("ne_10m_urban_areas.shp", flightgear::PolyLine::URBAN, true); - - qDebug() << "loading urban areas took:" << st.elapsedMSec(); -} - bool runLauncherDialog() { // startup the nav-cache now. This pre-empts normal startup of @@ -460,7 +482,8 @@ bool runLauncherDialog() // will happen as normal http->init(); - loadNaturalEarthData(); + NaturalEarthDataLoaderThread* naturalEarthLoader = new NaturalEarthDataLoaderThread; + naturalEarthLoader->start(); // avoid double Apple menu and other weirdness if both Qt and OSG // try to initialise various Cocoa structures. -- 2.39.5