]> git.mxchange.org Git - flightgear.git/commitdiff
Tile loading is interleaved now when not threaded. Threaded loader is
authorcurt <curt>
Fri, 18 May 2001 20:31:23 +0000 (20:31 +0000)
committercurt <curt>
Fri, 18 May 2001 20:31:23 +0000 (20:31 +0000)
throttled to one tile per frame maximum.

src/Scenery/FGTileLoader.cxx
src/Scenery/FGTileLoader.hxx
src/Scenery/tileentry.cxx
src/Scenery/tilemgr.cxx
src/Scenery/tilemgr.hxx

index 17cc52fc3b39c7cc9ba29c7bab946c9300ff39a9..a709b57f0fdb1b5b7ccaaa0393c93a2b04bef3ef 100644 (file)
@@ -86,12 +86,7 @@ FGTileLoader::add( FGTileEntry* tile )
        beenhere = true;
     }
 
-#ifdef ENABLE_THREADS
-    tile_queue.push( tile );
-#else
-    tile->load( tile_path, true );
-    tile->add_ssg_nodes( terrain, ground );
-#endif // ENABLE_THREADS
+    tile_load_queue.push( tile );
 }
 
 /**
@@ -101,9 +96,20 @@ void
 FGTileLoader::update()
 {
 #ifdef ENABLE_THREADS
+    // send a signal to the pager thread that it is allowed to load
+    // another tile
     mutex.lock();
     frame_cond.signal();
     mutex.unlock();
+#else
+    if ( !tile_load_queue.empty() ) {
+        cout << "loading next tile ..." << endl;
+        // load the next tile in the queue
+        FGTileEntry* tile = tile_load_queue.front();
+        tile_load_queue.pop();
+        tile->load( tile_path, true );
+        FGTileMgr::loaded( tile );
+    }
 #endif // ENABLE_THREADS
 }
 
@@ -118,12 +124,12 @@ FGTileLoader::LoaderThread::run()
     pthread_cleanup_push( cleanup_handler, loader );
     while ( true ) {
        // Wait for a load request to be placed in the queue.
-       FGTileEntry* tile = loader->tile_queue.pop();
+       FGTileEntry* tile = loader->tile_load_queue.pop();
 
         // Wait for the next frame signal before we load a tile from the queue
-        // loader->mutex.lock();
-        // loader->frame_cond.wait( loader->mutex );
-        // loader->mutex.unlock();
+        loader->mutex.lock();
+        loader->frame_cond.wait( loader->mutex );
+        loader->mutex.unlock();
 
        set_cancel( SGThread::CANCEL_DISABLE );
        tile->load( loader->tile_path, true );
index 75b3a0c3d9370989c5039579a52c5b7136b86b1b..16878e134c07e24b113c7c84b3f354cca3bddc6d 100644 (file)
@@ -30,6 +30,8 @@
 #ifdef ENABLE_THREADS
 #  include <simgear/threads/SGThread.hxx>
 #  include <simgear/threads/SGQueue.hxx>
+#else
+#  include <queue>
 #endif
 
 // Forward reference.
@@ -71,7 +73,7 @@ public:
      * Returns whether the load queue is empty (contains no elements).
      * @return true if load queue is empty otherwise returns false.
      */
-    // bool empty() const { return tile_queue.empty(); }
+    // bool empty() const { return tile_load_queue.empty(); }
 
 private:
 
@@ -81,7 +83,9 @@ private:
     /**
      * FIFO queue of tiles to load from data files.
      */
-    SGBlockingQueue< FGTileEntry* > tile_queue;
+    SGBlockingQueue< FGTileEntry* > tile_load_queue;
+#else
+    queue< FGTileEntry* > tile_load_queue;
 #endif
 
     /**
index a3c921188a3c589b06f73e4cdda4addd513a4855..020c324369abd299a826600c6fe2e1fae7aec168 100644 (file)
@@ -351,7 +351,7 @@ FGTileEntry::load( const SGPath& base, bool is_base )
     }
 
     // load custom objects
-    SG_LOG( SG_TERRAIN, SG_DEBUG, "CUSTOM OBJECTS" );
+    SG_LOG( SG_TERRAIN, SG_DEBUG, "Checking for custom objects ..." );
 
     SGPath index_path = tile_path;
     index_path.append( index_str );
@@ -391,6 +391,7 @@ FGTileEntry::load( const SGPath& base, bool is_base )
 
                // load the object itself
                SGPath custom_path = tile_path;
+                ssgTexturePath( (char *)custom_path.c_str() );
                custom_path.append( name );
                ssgEntity *obj_model = ssgLoad( (char *)custom_path.c_str() );
 
index b47e6246d60cd8ef61d61177ceb36ae7f26fdf64..d949c6ab225b90edbece8c302414507e80b4ac03 100644 (file)
@@ -71,6 +71,8 @@ static inline Point3D operator + (const Point3D& a, const sgdVec3 b)
 
 #ifdef ENABLE_THREADS
 SGLockedQueue<FGTileEntry*> FGTileMgr::loaded_queue;
+#else
+queue<FGTileEntry*> FGTileMgr::loaded_queue;
 #endif // ENABLE_THREADS
 
 // Constructor
@@ -358,17 +360,9 @@ int FGTileMgr::update( double lon, double lat ) {
        state = Running;
     }
 
-    // now handled by threaded tile pager
-#if 0
-    if ( load_queue.size() ) {
-       SG_LOG( SG_TERRAIN, SG_INFO, "Load queue size = " << load_queue.size()
-               << " loading a tile" );
-
-       SGBucket pending = load_queue.front();
-       load_queue.pop_front();
-       load_tile( pending );
-    }
-#endif
+    // load the next tile in the load queue (or authorize the next
+    // load in the case of the threaded tile pager)
+    loader.update();
 
     if ( scenery.center == Point3D(0.0) ) {
        // initializing
@@ -418,15 +412,17 @@ int FGTileMgr::update( double lon, double lat ) {
         // Notify the tile loader that it can load another tile
         // loader.update();
 
+       if ( !loaded_queue.empty() ) {
 #ifdef ENABLE_THREADS
-       if (!loaded_queue.empty())
-       {
            FGTileEntry* e = loaded_queue.pop();
+#else
+           FGTileEntry* e = loaded_queue.front();
+            loaded_queue.pop();
+#endif
            e->add_ssg_nodes( terrain, ground );
            //std::cout << "Adding ssg nodes for "
            //<< e->get_tile_bucket() << "\n";
        }
-#endif // ENABLE_THREADS
     }
 
     return 1;
index 2503f50d78cb8b0562ababd9e802db215d0213ca..9d3f746853469685d50d1594ba30bee3e2b0380c 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <simgear/compiler.h>
 
+#include <queue>
+
 #include <plib/ssg.h>
 
 #include <simgear/bucket/newbucket.hxx>
@@ -116,11 +118,14 @@ private:
     FGTileLoader loader;
     int counter_hack;
 
-#ifdef ENABLE_THREADS
     /**
      * Tiles to add to scene graph.
      */
+#ifdef ENABLE_THREADS
     static SGLockedQueue<FGTileEntry*> loaded_queue;
+#else
+    static queue<FGTileEntry*> loaded_queue;
+#endif // ENABLE_THREADS
 
 public:
 
@@ -128,7 +133,6 @@ public:
      * Add a loaded tile to the scene graph queue.
      */
     static void loaded( FGTileEntry* t ) { loaded_queue.push(t); }
-#endif // ENABLE_THREADS
 
 public: