]> git.mxchange.org Git - flightgear.git/commitdiff
New traffic manager initialization. Search for all files
authordurk <durk>
Wed, 27 Dec 2006 11:53:54 +0000 (11:53 +0000)
committerdurk <durk>
Wed, 27 Dec 2006 11:53:54 +0000 (11:53 +0000)
data/AI/Aircraft/*/*.xml and read traffic information from these files.
Current code still mimicks old behavior by reading data/Traffic/fgtraffic.xml
The latter functionality will be disabled once we have some traffic containing
files in data/AI/Aircraft.

src/Traffic/Schedule.cxx
src/Traffic/TrafficMgr.cxx

index 6692c8cc89d42dc0784ba67b84d0d325591a363a..cc117304a0d22b43a305ccb39b235a8206661734 100644 (file)
@@ -235,6 +235,7 @@ bool FGAISchedule::update(time_t now)
   if (!deptime)
     deptime = (*flights.begin())->getDepartureTime();
   FGScheduledFlightVecIterator i = flights.begin();
+  SG_LOG (SG_GENERAL, SG_INFO,"Processing registration " << registration << " with callsign " << (*i)->getCallSign())
   if (AIManagerRef)
     {
       // Check if this aircraft has been released. 
@@ -263,7 +264,6 @@ bool FGAISchedule::update(time_t now)
       // object for it. 
       //if ((i->getDepartureTime() < now) && (i->getArrivalTime() > now))
       
-
       // Part of this flight is in the future.
       if ((*i)->getArrivalTime() > now)
        {
index e265372366193683cb6d549d5b70fcfbebab9624..dd42d52f381a56f16bad648f6f37cb7015cda618 100644 (file)
@@ -49,6 +49,7 @@
 #include <algorithm>
 
 #include <plib/sg.h>
+#include <plib/ul.h>
 
 #include <simgear/compiler.h>
 #include <simgear/math/polar3d.hxx>
@@ -114,6 +115,51 @@ 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");
+  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();
@@ -122,14 +168,17 @@ void FGTrafficManager::init()
 
 void FGTrafficManager::update(double something)
 {
+  //SG_LOG( SG_GENERAL, SG_INFO, "Running TrafficManager::Update() ");
   if (runCount < 1000)
     {
       runCount++;
       return;
     }
   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;
@@ -142,6 +191,7 @@ void FGTrafficManager::update(double something)
       cerr << "Failed to update aircraft schedule in traffic manager" << endl;
     }
   currAircraft++;
+  //SG_LOG( SG_GENERAL, SG_INFO, "Done Running TrafficManager::Update() ");
 }
 
 void FGTrafficManager::release(int id)