]> git.mxchange.org Git - flightgear.git/commitdiff
Avoid excessive load when no navaids are in range
authorThorstenB <brehmt@gmail.com>
Wed, 24 Aug 2011 21:17:05 +0000 (23:17 +0200)
committerThorstenB <brehmt@gmail.com>
Wed, 24 Aug 2011 21:17:05 +0000 (23:17 +0200)
When no navaid is found, '_ref_navaid_id_node->setStringValue("")' results
in a listener firing, which requests another navaid update when no navaid
is available.
=> Resulted in FGPositioned::findClosest being called in every update loop,
when no navaid was within range.

src/Instrumentation/gps.cxx

index f0ecf6f0486bfa960d18498d3bbc78cdfefbd2d7..667ff2c36b50daf7e9f63a773cab5da52d96e2ef 100644 (file)
@@ -611,12 +611,11 @@ void GPS::updateReferenceNavaid(double dt)
   if (!_ref_navaid_set) {
     _ref_navaid_elapsed += dt;
     if (_ref_navaid_elapsed > 5.0) {
-      _ref_navaid_elapsed = 0.0;
 
       FGPositioned::TypeFilter vorFilter(FGPositioned::VOR);
       FGPositionedRef nav = FGPositioned::findClosest(_indicated_pos, 400.0, &vorFilter);
       if (!nav) {
-        SG_LOG(SG_INSTR, SG_INFO, "GPS couldn't find a reference navid");
+        SG_LOG(SG_INSTR, SG_INFO, "GPS couldn't find a reference navaid");
         _ref_navaid_id_node->setStringValue("");
         _ref_navaid_name_node->setStringValue("");
         _ref_navaid_bearing_node->setDoubleValue(0.0);
@@ -636,6 +635,10 @@ void GPS::updateReferenceNavaid(double dt)
       }
       
       _ref_navaid = nav;
+      // reset elapsed time (do not do that before updating the properties above, since their
+      // listeners may request another update (_ref_navaid_elapsed = 9999), which results in
+      // excessive load (FGPositioned::findClosest called in every update loop...)
+      _ref_navaid_elapsed = 0.0; 
     }
   }