X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FTraffic%2FTrafficMgr.cxx;h=9ebf78c1c7c063e80ba68352d1d4073131d4a3a8;hb=ed434d9967b0b23e4abb172d699ef956246f4bf9;hp=5e649472c09e77d3306050cfb1c3dae517f403a1;hpb=8112ff5842d24ac12dbeeaaa02b981d24ebbf339;p=flightgear.git diff --git a/src/Traffic/TrafficMgr.cxx b/src/Traffic/TrafficMgr.cxx index 5e649472c..9ebf78c1c 100644 --- a/src/Traffic/TrafficMgr.cxx +++ b/src/Traffic/TrafficMgr.cxx @@ -51,10 +51,9 @@ #include #include -#include - #include #include +#include #include #include #include @@ -76,7 +75,12 @@ using std::strcmp; /****************************************************************************** * TrafficManager *****************************************************************************/ -FGTrafficManager::FGTrafficManager() +FGTrafficManager::FGTrafficManager() : + inited(false), + enabled("/sim/traffic-manager/enabled"), + aiEnabled("/sim/ai/enabled"), + realWxEnabled("/environment/realwx/enabled"), + metarValid("/environment/metar/valid") { //score = 0; //runCount = 0; @@ -126,41 +130,26 @@ FGTrafficManager::~FGTrafficManager() void FGTrafficManager::init() { - ulDir *d, *d2; - ulDirEnt *dent, *dent2; - + if (!enabled || !aiEnabled) { + return; + } + heuristicsVector heuristics; HeuristicMap heurMap; if (string(fgGetString("/sim/traffic-manager/datafile")) == string("")) { - SGPath aircraftDir = globals->get_fg_root(); - SGPath path = aircraftDir; - - aircraftDir.append("AI/Traffic"); - if ((d = ulOpenDir(aircraftDir.c_str())) != NULL) { - while ((dent = ulReadDir(d)) != NULL) { - if (string(dent->d_name) != string(".") && - string(dent->d_name) != string("..") && dent->d_isdir) { - SGPath currACDir = aircraftDir; - currACDir.append(dent->d_name); - if ((d2 = ulOpenDir(currACDir.c_str())) == NULL) - return; - while ((dent2 = ulReadDir(d2)) != NULL) { - SGPath currFile = currACDir; - currFile.append(dent2->d_name); - if (currFile.extension() == string("xml")) { - SGPath currFile = currACDir; - currFile.append(dent2->d_name); - SG_LOG(SG_GENERAL, SG_DEBUG, - "Scanning " << currFile. - str() << " for traffic"); - readXML(currFile.str(), *this); - } - } - ulCloseDir(d2); - } - } - ulCloseDir(d); + simgear::Dir trafficDir(SGPath(globals->get_fg_root(), "AI/Traffic")); + simgear::PathList d = trafficDir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT); + + for (unsigned int i=0; i> h.registration >> h.runCount >> h.hits; if (data.eof()) break; + HeuristicMapIterator itr = heurMap.find(h.registration); + if (itr != heurMap.end()) { + SG_LOG(SG_GENERAL, SG_WARN,"Traffic Manager Warning: found duplicate tailnumber " << + h.registration << " for AI aircraft"); + } heurMap[h.registration] = h; heuristics.push_back(h); } @@ -233,13 +227,22 @@ void FGTrafficManager::init() compareSchedules); currAircraft = scheduledAircraft.begin(); currAircraftClosest = scheduledAircraft.begin(); + + inited = true; } void FGTrafficManager::update(double /*dt */ ) { - if (fgGetBool("/environment/metar/valid") == false) { + if (!enabled || !aiEnabled || (realWxEnabled && !metarValid)) { return; } + + if (!inited) { + // lazy-initialization, we've been enabled at run-time + SG_LOG(SG_GENERAL, SG_INFO, "doing lazy-init of TrafficManager"); + init(); + } + time_t now = time(NULL) + fgGetLong("/sim/time/warp"); if (scheduledAircraft.size() == 0) { return; @@ -255,6 +258,7 @@ void FGTrafficManager::update(double /*dt */ ) } //cerr << "Processing << " << (*currAircraft)->getRegistration() << " with score " << (*currAircraft)->getScore() << endl; if (!((*currAircraft)->update(now, userCart))) { + (*currAircraft)->taint(); // NOTE: With traffic manager II, this statement below is no longer true // after proper initialization, we shouldnt get here. // But let's make sure @@ -370,7 +374,7 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName) string arrTimeGen = tokens[6]; string repeat = "WEEK"; string requiredAircraft = tokens[9]; - + if (weekdays.size() != 7) { SG_LOG(SG_GENERAL, SG_ALERT, "Found misconfigured weekdays string" << weekdays); exit(1); @@ -606,7 +610,7 @@ void FGTrafficManager::endElement(const char *name) if (fgGetBool("/sim/traffic-manager/dumpdata") == true) { SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft << "," << acType << "," << livery << "," - << airline << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl); + << airline << "," << m_class << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl); } //scheduledAircraft.push_back(new FGAISchedule(mdl, // livery,