X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fdme.cxx;h=33ea69279d18b949484a93576a9325951f7ba267;hb=0e4aba11fa7a68ee671cccd86562c5fbe831651b;hp=bcea965d83b596c766f49a772f4d50406e6f428b;hpb=9022c6a58dea4f5414fff6432cd6e0556c80693f;p=flightgear.git diff --git a/src/Instrumentation/dme.cxx b/src/Instrumentation/dme.cxx index bcea965d8..33ea69279 100644 --- a/src/Instrumentation/dme.cxx +++ b/src/Instrumentation/dme.cxx @@ -11,6 +11,7 @@ #include #include #include +#include #include
#include @@ -40,6 +41,36 @@ adjust_range (double transmitter_elevation_ft, double aircraft_altitude_ft, return range_nm + (range_nm * rand * rand); } +namespace { + + class DMEFilter : public FGNavList::TypeFilter + { + public: + DMEFilter() : + TypeFilter(FGPositioned::DME), + _locEnabled(fgGetBool("/sim/realism/dme-fallback-to-loc", true)) + { + if (_locEnabled) { + _mintype = FGPositioned::ILS; + } + } + + virtual bool pass(FGPositioned* pos) const + { + switch (pos->type()) { + case FGPositioned::DME: return true; + case FGPositioned::ILS: + case FGPositioned::LOC: return _locEnabled; + default: return false; + } + } + + private: + const bool _locEnabled; + }; + +} // of anonymous namespace + DME::DME ( SGPropertyNode *node ) : _last_distance_nm(0), @@ -60,7 +91,7 @@ DME::~DME () void DME::init () { - string branch; + std::string branch; branch = "/instrumentation/" + _name; SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true ); @@ -88,6 +119,14 @@ DME::init () if( NULL == _audioIdent ) _audioIdent = new DMEAudioIdent( temp.str() ); _audioIdent->init(); + + reinit(); +} + +void +DME::reinit () +{ + _time_before_search_sec = 0; } void @@ -99,7 +138,7 @@ DME::update (double delta_time_sec) // Figure out the source const char * source = _source_node->getStringValue(); if (source[0] == '\0') { - string branch; + std::string branch; branch = "/instrumentation/" + _name + "/frequencies/selected-mhz"; _source_node->setStringValue(branch.c_str()); source = _source_node->getStringValue(); @@ -119,17 +158,9 @@ DME::update (double delta_time_sec) if (_time_before_search_sec < 0) { _time_before_search_sec = 1.0; - if( fgGetBool( "/sim/realism/dme-fallback-to-loc", true ) ) { - if( NULL == (_navrecord = globals->get_loclist()->findByFreq( frequency_mhz, - globals->get_aircraft_position())) ) { - - _navrecord = globals->get_dmelist()->findByFreq( frequency_mhz, - globals->get_aircraft_position()); - } - } else { - _navrecord = globals->get_dmelist()->findByFreq( frequency_mhz, - globals->get_aircraft_position()); - } + SGGeod pos(globals->get_aircraft_position()); + DMEFilter filter; + _navrecord = FGNavList::findByFreq(frequency_mhz, pos, &filter); } // If it's off, don't bother.