]> git.mxchange.org Git - flightgear.git/commitdiff
Melchior FRANZ:
authorehofman <ehofman>
Tue, 8 Jun 2004 15:32:09 +0000 (15:32 +0000)
committerehofman <ehofman>
Tue, 8 Jun 2004 15:32:09 +0000 (15:32 +0000)
Wouldn't it be better to prepare the whole list of paths (or two
separate ones for Terrain/Objects if necessary) in FGGlobals::set_fg_scenery,
and to pass the vector<string>s to FGTileEntry::load? It doesn't seem to make
a lot of sense to split the path up, modify it, mount it together to one string
again, and then let FGTileEntry::load split it up again.

Here we go:

Main/globals.cxx
================
As fg_scenery is now a string_list, we don't need initialization. Furthermore,
this list is cleared with every set_fg_scenery() call.

ctor: create default dir from fg_root if necessary. Otherwise check all paths
of --fg-scenery/FG_SCENERY: If the path doesn't exist, ignore it. If it contains
a dir Terrain and/or Objects, then only add that to the list. If it contains
neither, then use the path as is.

Scenery/tileentry.cxx
=====================
Trivial: don't split a "base path", but use the given path_list as is.
(I considered a variable name "path_list" better suited than "search".)

Scenery/FGTileLoader.cxx
========================
No more fiddling with sub-paths. This has to be delivered by get_fg_scenery
already.

src/Main/globals.cxx
src/Main/globals.hxx
src/Scenery/FGTileLoader.cxx
src/Scenery/FGTileLoader.hxx
src/Scenery/tileentry.cxx
src/Scenery/tileentry.hxx

index 8681a5e4a4ad0508db401a0e00ae5740c67647a3..aa9f37aa2d870e4b725d0d220a2b822a0f552573 100644 (file)
@@ -46,7 +46,6 @@ FGGlobals::FGGlobals() :
     event_mgr( new SGEventMgr ),
     sim_time_sec( 0.0 ),
     fg_root( "" ),
-    fg_scenery( "" ),
 #if defined(FX) && defined(XMESA)
     fullscreen( true ),
 #endif
@@ -118,34 +117,42 @@ void FGGlobals::set_fg_root (const string &root) {
 }
 
 void FGGlobals::set_fg_scenery (const string &scenery) {
-    if (scenery.empty())
-        return;
-
-    // TODO: Split the scenery path up into separate
-    // paths (taking into account the search path separator
-    // and test them individually.
-    // -EMH-
-    SGPath pt( scenery ), po( scenery );
-    pt.append("Terrain");
-    po.append("Objects");
-
-    ulDir *td = ulOpenDir(pt.c_str());
-    ulDir *od = ulOpenDir(po.c_str());
-
-    if (td == NULL) {
-        if (od == NULL) {
-            fg_scenery = scenery;
-        } else {
-            fg_scenery = po.str();
-            ulCloseDir(od);
-        }
-    } else {
-        if (od != NULL) {
-            pt.add(po.str());
-            ulCloseDir(od);
+    SGPath s;
+    if (scenery.empty()) {
+        s.set( fg_root );
+        s.append( "Scenery" );
+    } else
+        s.set( scenery );
+
+    string_list path_list = sgPathSplit( s.str() );
+    fg_scenery.clear();
+
+    for (unsigned i = 0; i < path_list.size(); i++) {
+
+        ulDir *d = ulOpenDir( path_list[0].c_str() );
+        if (d == NULL)
+            continue;
+        ulCloseDir( d );
+
+        SGPath pt( path_list[i] ), po( path_list[i] );
+        pt.append("Terrain");
+        po.append("Objects");
+
+        ulDir *td = ulOpenDir( pt.c_str() );
+        ulDir *od = ulOpenDir( po.c_str() );
+
+        if (td == NULL && od == NULL)
+            fg_scenery.push_back( path_list[i] );
+        else {
+            if (td != NULL) {
+                fg_scenery.push_back( pt.str() );
+                ulCloseDir( td );
+            }
+            if (od != NULL) {
+                fg_scenery.push_back( po.str() );
+                ulCloseDir( od );
+            }
         }
-        fg_scenery = pt.str();
-        ulCloseDir(td);
     }
 }
 
index 52ee7deb6720cd6e73413b2d81ea69156bb41069..1446e0921f50cb95a0814851b430dd3323cb3b79 100644 (file)
@@ -106,8 +106,8 @@ private:
     // Root of FlightGear data tree
     string fg_root;
 
-    // Root of FlightGear scenery tree
-    string fg_scenery;
+    // Roots of FlightGear scenery tree
+    string_list fg_scenery;
 
     // Fullscreen mode for old 3DFX cards.
 #if defined(FX) && defined(XMESA)
@@ -236,7 +236,7 @@ public:
     inline const string &get_fg_root () const { return fg_root; }
     void set_fg_root (const string &root);
 
-    inline const string &get_fg_scenery () const { return fg_scenery; }
+    inline const string_list &get_fg_scenery () const { return fg_scenery; }
     void set_fg_scenery (const string &scenery);
 
 #if defined(FX) && defined(XMESA)
index 6d247cb920a6851c434d538c5c537e7861646ae3..255e76b85bb117ee7314999ebb235b406fa35476 100644 (file)
@@ -88,22 +88,12 @@ FGTileLoader::add( FGTileEntry* tile )
 {
     /**
      * Initialise tile_path here and not in ctor to avoid problems
-     * with the initialastion order of global objects.
+     * with the initialisation order of global objects.
      */
     static bool beenhere = false;
-    if (!beenhere)
-    {
-       if ( !globals->get_fg_scenery().empty() ) {
-            tile_path = globals->get_fg_scenery();
-       } else {
-            SGPath tmp;
-           tmp.set( globals->get_fg_root() );
-            tmp.append( "Scenery/Terrain" );
-            tmp.add(globals->get_fg_root() );
-            tmp.append( "Scenery/Objects" );
-            tile_path = tmp.str();
-       }
-       beenhere = true;
+    if (!beenhere) {
+        tile_path = globals->get_fg_scenery();
+        beenhere = true;
     }
 
     tile_load_queue.push( tile );
index 54e8be927e5f2ecd4be743f9981a7f0254cd7ec1..3d912fa753ce73715a4bafd50534c3dba442371c 100644 (file)
@@ -109,9 +109,9 @@ private:
 #endif
 
     /**
-     * Base name of directory containing tile data file.
+     * Base names of directories containing tile data files.
      */
-    string tile_path;
+    string_list tile_path;
 
 #if defined(ENABLE_THREADS) && ENABLE_THREADS
     /**
index 3076b32defafb3ea333b9d21ff1a9412d21b7db8..6b132e7ee62e2e1a69c43d41f6aea98724354d19 100644 (file)
@@ -662,29 +662,24 @@ bool FGTileEntry::obj_load( const string& path,
 
 
 void
-FGTileEntry::load( const string &base_path, bool is_base )
+FGTileEntry::load( const string_list &path_list, bool is_base )
 {
-    SG_LOG( SG_TERRAIN, SG_INFO, "load() base search path = "
-            << base_path );
-
     bool found_tile_base = false;
 
-    string_list search = sgPathSplit( base_path );
-
     // obj_load() will generate ground lighting for us ...
     ssgVertexArray *light_pts = new ssgVertexArray( 100 );
 
     ssgBranch* new_tile = new ssgBranch;
 
     unsigned int i = 0;
-    while ( i < search.size() ) {
+    while ( i < path_list.size() ) {
 
         bool has_base = false;
 
         // Generate names for later use
         string index_str = tile_bucket.gen_index_str();
 
-        SGPath tile_path = search[i];
+        SGPath tile_path = path_list[i];
         tile_path.append( tile_bucket.gen_base_path() );
 
         SGPath basename = tile_path;
@@ -918,7 +913,7 @@ FGTileEntry::load( const string &base_path, bool is_base )
         ssgBranch *geometry = new ssgBranch;
         Point3D c;
         double br;
-        if ( sgGenTile( search[0], tile_bucket, &c, &br,
+        if ( sgGenTile( path_list[0], tile_bucket, &c, &br,
                         globals->get_matlib(), geometry ) )
         {
             center = c;
index 2bf8130b90aac0fac6769ac8d6028982e98c155c..dfb16965a1680e673ff231e41de83ce4dd3dc398 100644 (file)
@@ -227,7 +227,7 @@ public:
      * @param base name of directory containing tile data file.
      * @param is_base is this a base terrain object for which we should generate
      *        random ground light points */
-    void load( const string &base_path, bool is_base );
+    void load( const string_list &base_path, bool is_base );
 
     /**
      * Return true if the tile entry is loaded, otherwise return false