]> git.mxchange.org Git - flightgear.git/commitdiff
Async loading of NaturalEarth data for launcher.
authorJames Turner <zakalawe@mac.com>
Mon, 8 Aug 2016 22:13:57 +0000 (23:13 +0100)
committerRoland Haeder <roland@mxchange.org>
Thu, 22 Sep 2016 21:27:48 +0000 (23:27 +0200)
src/GUI/QtLauncher.cxx

index 64f5b76faeddd833ec5286ac19e009c4fefd9bbe..16a0a104d2c3bf8b984000c6c0418f0c70ee267d 100644 (file)
@@ -47,6 +47,7 @@
 #include <QSpinBox>
 #include <QDoubleSpinBox>
 #include <QProcess>
+#include <QThread>
 
 // Simgear
 #include <simgear/timing/timestamp.hxx>
@@ -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.