]> git.mxchange.org Git - flightgear.git/commitdiff
Improve the terrasync strategy
authorfredb <fredb>
Sun, 1 Feb 2009 19:57:56 +0000 (19:57 +0000)
committerTim Moore <timoore@redhat.com>
Sun, 1 Feb 2009 23:58:01 +0000 (00:58 +0100)
utils/TerraSync/terrasync.cxx

index e0f867ebf0485942613a5a92aacf11a6e2bb2df3..6d10f2b1052ef6259f6683fd40e83a1b50a413f6 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <iostream>
 #include <string>
+#include <queue>
 
 #include <plib/netSocket.h>
 #include <plib/ul.h>
@@ -87,6 +88,8 @@ static void usage( const string& prog ) {
 #endif
 }
 
+std::queue<std::string> waitingTiles;
+
 #ifdef HAVE_SVN_CLIENT_H
 
 // Things we need for doing subversion checkout - often
@@ -328,18 +331,13 @@ static void sync_area( int lat, int lon ) {
         baselon = (int)(lon / 10) * 10;
         EW = 'e';
     }
-    
-    const char* terrainobjects[3] = { "Terrain", "Objects", 0 };
-    const char** tree;
+
     char dir[512];
-  
-    for (tree = &terrainobjects[0]; *tree; tree++) {
-        snprintf( dir, 512, "%s/%c%03d%c%02d/%c%03d%c%02d",
-          *tree,
-              EW, abs(baselon), NS, abs(baselat),
-              EW, abs(lon), NS, abs(lat) );
-        sync_tree(dir);
-    }
+    snprintf( dir, 512, "%c%03d%c%02d/%c%03d%c%02d",
+            EW, abs(baselon), NS, abs(baselat),
+            EW, abs(lon), NS, abs(lat) );
+
+    waitingTiles.push( dir );
 }
 
 
@@ -440,7 +438,7 @@ int main( int argc, char **argv ) {
     int last_lat = nowhere;
     int last_lon = nowhere;
     bool recv_msg = false;
-    int synced_other = 0;
+    char synced_other = 'K';
 
     while ( true ) {
         recv_msg = false;
@@ -449,11 +447,12 @@ int main( int argc, char **argv ) {
             recv_msg = true;
 
             parse_message( msg, &lat, &lon );
-            cout << "pos in msg = " << lat << "," << lon << endl;
         }
 
         if ( recv_msg ) {
             if ( lat != last_lat || lon != last_lon ) {
+               cout << "pos in msg = " << lat << "," << lon << endl;
+               waitingTiles.c.clear();
                 int lat_dir, lon_dir, dist;
                 if ( last_lat == nowhere || last_lon == nowhere ) {
                     lat_dir = lon_dir = 0;
@@ -477,18 +476,23 @@ int main( int argc, char **argv ) {
                 sync_areas( lat, lon, lat_dir, lon_dir );
             } else if ( last_lat == nowhere || last_lon == nowhere ) {
                cout << "Waiting for FGFS to finish startup" << endl;
-           } else {
-               switch (synced_other++) {
-               case 0:
-                   sync_tree((char*) "Airports/K");
-                   break;
-               case 1:
-                   sync_tree((char*) "Airports");
-                   break;
-               default:
-                   cout << "Done non-tile syncs" << endl;
-                   break;
+           } else if ( !waitingTiles.empty() ) {
+               const char* terrainobjects[3] = { "Terrain", "Objects", 0 };
+               const char** tree;
+               char dir[512];
+              
+               for (tree = &terrainobjects[0]; *tree; tree++) {
+                   snprintf( dir, 512, "%s/%s", *tree, waitingTiles.front().c_str() );
+                   sync_tree(dir);
                }
+               waitingTiles.pop();
+           } else {
+               char c;
+               while ( !isdigit( c = synced_other++ ) && !isupper( c ) );
+
+               char dir[512];
+               snprintf( dir, 512, "Airports/%c", c );
+               sync_tree( dir );
            }
 
             last_lat = lat;
@@ -500,4 +504,3 @@ int main( int argc, char **argv ) {
         
     return 0;
 }
-