]> git.mxchange.org Git - flightgear.git/commitdiff
Don't try to open runway and parking files for every airport in the
authorandy <andy>
Fri, 27 May 2005 17:06:13 +0000 (17:06 +0000)
committerandy <andy>
Fri, 27 May 2005 17:06:13 +0000 (17:06 +0000)
database.  Works fine on Linux, but is a huge performance hit (1
minute) on cygwin.  Keep a cache of actual directories and check that
first.

src/Airports/simple.cxx
src/Airports/simple.hxx

index 5ea71ac06d2899356e1e69a9a88d9c8dda0729fa..a516036c8da896d43ef3d6505606bed790cad301 100644 (file)
@@ -1149,6 +1149,26 @@ void FGAirport::chooseRunwayFallback(string *runway)
  * FGAirportList
  *****************************************************************************/
 
+// Populates a list of subdirectories of $FG_ROOT/Airports/AI so that
+// the add() method doesn't have to try opening 2 XML files in each of
+// thousands of non-existent directories.  FIXME: should probably add
+// code to free this list after parsing of apt.dat is finished;
+// non-issue at the moment, however, as there are no AI subdirectories
+// in the base package.
+FGAirportList::FGAirportList()
+{
+    ulDir* d;
+    ulDirEnt* dent;
+    SGPath aid( globals->get_fg_root() );
+    aid.append( "/Airports/AI" );
+    if((d = ulOpenDir(aid.c_str())) == NULL)
+        return;
+    while((dent = ulReadDir(d)) != NULL) {
+        cerr << "Dent: " << dent->d_name; // DEBUG
+        ai_dirs.insert(dent->d_name);
+    }
+    ulCloseDir(d);
+}
 
 // add an entry to the list
 void FGAirportList::add( const string id, const double longitude,
@@ -1172,7 +1192,8 @@ void FGAirportList::add( const string id, const double longitude,
     rwyPrefPath.append( "/Airports/AI/" );
     rwyPrefPath.append(id);
     rwyPrefPath.append("rwyuse.xml");
-    if (parkpath.exists()) 
+    if (ai_dirs.find(parkpath.str()) != ai_dirs.end()
+        && parkpath.exists()) 
       {
        try {
          readXML(parkpath.str(),a);
@@ -1181,7 +1202,8 @@ void FGAirportList::add( const string id, const double longitude,
          //cerr << "unable to read " << parkpath.str() << endl;
        }
       }
-    if (rwyPrefPath.exists()) 
+    if (ai_dirs.find(rwyPrefPath.str()) != ai_dirs.end()
+        && rwyPrefPath.exists()) 
       {
        try {
          readXML(rwyPrefPath.str(), rwyPrefs);
index 40eed975830dfd708af512d3adbb6d4ea3b6e542..9fe38fdbe6af68d300cc90ccf155d5997983ae83 100644 (file)
 
 #include STL_STRING
 #include <map>
+#include <set>
 #include <vector>
 
 SG_USING_STD(string);
 SG_USING_STD(map);
+SG_USING_STD(set);
 SG_USING_STD(vector);
 
 typedef vector<string> stringVec;
@@ -306,11 +308,12 @@ private:
 
     airport_map airports_by_id;
     airport_list airports_array;
+    set < string > ai_dirs;
 
 public:
 
     // Constructor (new)
-    FGAirportList() {}
+    FGAirportList();
 
     // Destructor
     ~FGAirportList();