From: James Turner Date: Mon, 8 Aug 2016 22:13:57 +0000 (+0100) Subject: Async loading of NaturalEarth data for launcher. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2a29fad1bb97db0036f681004053733c580afac8;p=flightgear.git Async loading of NaturalEarth data for launcher. --- 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.