]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/environment_ctrl.cxx
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[flightgear.git] / src / Environment / environment_ctrl.cxx
index 8fb0ad8fea53b57073ee4b8bc483dc547e720ae8..cf9c6505faefd68dff5f2cdfabb23f86666f19d2 100644 (file)
 
 using std::sort;
 
-class AirportWithMetar : public FGPositioned::Filter
+class AirportWithMetar : public FGAirport::AirportFilter
 {
 public:
-  virtual bool pass(FGPositioned* aPos) const
+  virtual bool passAirport(FGAirport* aApt) const
   {
-    if ((aPos->type() < FGPositioned::AIRPORT) || (aPos->type() > FGPositioned::SEAPORT)) {
-      return false;
-    }
-    
-    FGAirport* apt = static_cast<FGAirport*>(aPos);
-    return apt->getMetar();
+    return aApt->getMetar();
   }
 };
 \f
@@ -443,15 +438,19 @@ FGMetarEnvironmentCtrl::update_env_config ()
         // factor by the maximum wind change.
         double x = fabs(current[0] - metar[0]);
         double y = fabs(current[1] - metar[1]);
-        double dx = x / (x + y);
-        double dy = 1 - dx;
 
-        double maxdx = dx * MaxWindChangeKtsSec;
-        double maxdy = dy * MaxWindChangeKtsSec;
+        // only interpolate if we have a difference
+        if (x + y > 0) {
+            double dx = x / (x + y);
+            double dy = 1 - dx;
 
-        // Interpolate each component separately.
-        current[0] = interpolate_val(current[0], metar[0], maxdx);
-        current[1] = interpolate_val(current[1], metar[1], maxdy);
+            double maxdx = dx * MaxWindChangeKtsSec;
+            double maxdy = dy * MaxWindChangeKtsSec;
+
+            // Interpolate each component separately.
+            current[0] = interpolate_val(current[0], metar[0], maxdx);
+            current[1] = interpolate_val(current[1], metar[1], maxdy);
+        }
 
         // Now convert back to polar coordinates.
         if ((current[0] == 0.0) && (current[1] == 0.0)) {
@@ -964,7 +963,7 @@ FGMetarEnvironmentCtrl::update_metar_properties( const FGMetar *m )
 void
 FGMetarEnvironmentCtrl::thread_stop()
 {
-    request_queue.push( string() );    // ask thread to terminate
+    request_queue.push(NULL);  // ask thread to terminate
     thread->join();
 }
 
@@ -973,11 +972,11 @@ FGMetarEnvironmentCtrl::MetarThread::run()
 {
     while ( true )
     {
-        string icao = fetcher->request_queue.pop();
-        if (icao.empty())
+        FGAirport* apt = fetcher->request_queue.pop();
+        if (!apt)
             return;
-        SG_LOG( SG_GENERAL, SG_INFO, "Thread: fetch metar data = " << icao );
-        FGMetarResult result = fetcher->fetch_data( icao );
+        SG_LOG( SG_GENERAL, SG_INFO, "Thread: fetch metar data = " << apt->ident() );
+        FGMetarResult result = fetcher->fetch_data( apt );
         fetcher->result_queue.push( result );
     }
 }