]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/apt_loader.cxx
Interim windows build fix
[flightgear.git] / src / Airports / apt_loader.cxx
index e41db5a590b4845dcedf2976df60fd1601bbb872..9e6a475884228a25fd99206f89c82afbac7b1493 100644 (file)
@@ -67,6 +67,8 @@ static FGPositioned::Type fptypeFromRobinType(int aType)
   }
 }
 
+// generated by 'wc -l' on the uncompressed file
+const unsigned int LINES_IN_APT_DAT = 2465648;
 
 namespace flightgear
 {
@@ -90,7 +92,7 @@ public:
 
     if ( !in.is_open() ) {
         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << aptdb_file );
-        exit(-1);
+        throw sg_io_exception("cannot open APT file", aptdb_file);
     }
 
     string line;
@@ -109,6 +111,12 @@ public:
         continue;
       }
 
+        if ((line_num % 100) == 0) {
+            // every 100 lines
+            unsigned int percent = (line_num * 100) / LINES_IN_APT_DAT;
+            cache->setRebuildPhaseProgress(NavDataCache::REBUILD_AIRPORTS, percent);
+        }
+
       if (line.size() >= 3) {
           char *p = (char *)memchr(tmp, ' ', 3);
           if ( p )
@@ -151,9 +159,7 @@ public:
         double lat = atof( token[1].c_str() );
         double lon = atof( token[2].c_str() );
         double elev = atof( token[3].c_str() );
-        tower = SGGeod::fromDegFt(lon, lat, elev + last_apt_elev);
-        got_tower = true;
-        
+        tower = SGGeod::fromDegFt(lon, lat, elev + last_apt_elev);        
         cache->insertTower(currentAirportID, tower);
       } else if ( line_id == 19 ) {
           // windsock entry (ignore)
@@ -186,7 +192,7 @@ public:
       } else {
           SG_LOG( SG_GENERAL, SG_ALERT, 
                   "Unknown line(#" << line_num << ") in apt.dat file: " << line );
-          exit( -1 );
+          throw sg_format_exception("malformed line in apt.dat:", line);
       }
     }
 
@@ -199,7 +205,6 @@ private:
   double rwy_lon_accum;
   double last_rwy_heading;
   int rwy_count;
-  bool got_tower;
   string last_apt_id;
   double last_apt_elev;
   SGGeod tower;
@@ -230,17 +235,6 @@ private:
     double lat = rwy_lat_accum / (double)rwy_count;
     double lon = rwy_lon_accum / (double)rwy_count;
 
-    if (!got_tower) {
-      // tower height hard coded for now...
-      const float tower_height = 50.0f;
-      // make a little off the heading for 1 runway airports...
-      float fudge_lon = fabs(sin(last_rwy_heading * SGD_DEGREES_TO_RADIANS)) * .003f;
-      float fudge_lat = .003f - fudge_lon;
-      tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, last_apt_elev + tower_height);
-      
-      cache->insertTower(currentAirportID, tower);
-    }
-
     SGGeod pos(SGGeod::fromDegFt(lon, lat, last_apt_elev));
     cache->updatePosition(currentAirportID, pos);
     
@@ -256,7 +250,6 @@ private:
     finishAirport();
             
     last_apt_elev = elev;
-    got_tower = false;
 
     string name;
     // build the name
@@ -366,7 +359,7 @@ private:
 
     const string& rwy_no_1(token[8]);
     const string& rwy_no_2(token[17]);
-    if ( rwy_no_1.size() == 0 || rwy_no_2.size() == 0 )
+    if ( rwy_no_1.empty() || rwy_no_2.empty() )
         return;
 
     double displ_thresh1 = atof( token[11].c_str() );
@@ -557,6 +550,7 @@ bool metarDataLoad(const SGPath& metar_file)
   }
   
   NavDataCache* cache = NavDataCache::instance();
+
   string ident;
   while ( metar_in ) {
     metar_in >> ident;