X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FTraffic%2FTrafficMgr.cxx;h=86be2196cb2e02e4da8b1a76152f65bda97089f3;hb=c1e29d09981dfcd47ff213069fbe8fd5c8ccaf0c;hp=e265372366193683cb6d549d5b70fcfbebab9624;hpb=33037b21394792559332b18d1451ae21a44d090a;p=flightgear.git diff --git a/src/Traffic/TrafficMgr.cxx b/src/Traffic/TrafficMgr.cxx index e26537236..86be2196c 100644 --- a/src/Traffic/TrafficMgr.cxx +++ b/src/Traffic/TrafficMgr.cxx @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -114,22 +115,75 @@ void FGTrafficManager::init() // } // Sort by points: Aircraft with frequent visits to the // startup airport will be processed first + ulDir* d, *d2; + ulDirEnt* dent, *dent2; + SGPath aircraftDir = globals->get_fg_root(); + + /* keep the following three lines (which mimicks the old "fixed path" behavior) + * until we have some AI models with traffic in the base package + */ + SGPath path = aircraftDir; + path.append("Traffic/fgtraffic.xml"); + if (path.exists()) + readXML(path.str(),*this); + + aircraftDir.append("AI/Aircraft"); + if (aircraftDir.exists()) + { + if((d = ulOpenDir(aircraftDir.c_str())) == NULL) + return; + while((dent = ulReadDir(d)) != NULL) { + //cerr << "Scanning : " << dent->d_name << endl; + 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")) + { + //cerr << "found " << dent2->d_name << " for parsing" << endl; + SGPath currFile = currACDir; + currFile.append(dent2->d_name); + SG_LOG(SG_GENERAL, SG_INFO, "Scanning " << currFile.str() << " for traffic"); + readXML(currFile.str(),*this); + } + } + ulCloseDir(d2); + } + } + ulCloseDir(d); + } + // Sort by points: Aircraft with frequent visits to the + // startup airport will be processed first sort(scheduledAircraft.begin(), scheduledAircraft.end(), compareSchedules); currAircraft = scheduledAircraft.begin(); currAircraftClosest = scheduledAircraft.begin(); //cerr << "Done initializing schedules" << endl; } -void FGTrafficManager::update(double something) +void FGTrafficManager::update(double /*dt*/) { + //SG_LOG( SG_GENERAL, SG_INFO, "Running TrafficManager::Update() "); + // Hack alert: Skip running for the first frames 1000 after + // initialization to allow proper initialization of wheather stuff + // and runway assignments if (runCount < 1000) { runCount++; return; } + //runCount = 0; time_t now = time(NULL) + fgGetLong("/sim/time/warp"); - if (scheduledAircraft.size() == 0) + if (scheduledAircraft.size() == 0) { + //SG_LOG( SG_GENERAL, SG_INFO, "Returned Running TrafficManager::Update() "); return; + } if(currAircraft == scheduledAircraft.end()) { //cerr << "resetting schedule " << endl; @@ -139,9 +193,10 @@ void FGTrafficManager::update(double something) { // after proper initialization, we shouldnt get here. // But let's make sure - cerr << "Failed to update aircraft schedule in traffic manager" << endl; + SG_LOG( SG_GENERAL, SG_ALERT, "Failed to update aircraft schedule in traffic manager"); } currAircraft++; + //SG_LOG( SG_GENERAL, SG_INFO, "Done Running TrafficManager::Update() "); } void FGTrafficManager::release(int id)