From cc020fe9df98e7218b34dd970a92d432ef733343 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Wed, 24 Aug 2011 23:17:05 +0200 Subject: [PATCH] Avoid excessive load when no navaids are in range 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Instrumentation/gps.cxx b/src/Instrumentation/gps.cxx index f0ecf6f04..667ff2c36 100644 --- a/src/Instrumentation/gps.cxx +++ b/src/Instrumentation/gps.cxx @@ -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; } } -- 2.39.5