From 865fb56c5aab7a465b4ee726c8e8d360df80acd1 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 18 May 2001 20:31:23 +0000 Subject: [PATCH] Tile loading is interleaved now when not threaded. Threaded loader is throttled to one tile per frame maximum. --- src/Scenery/FGTileLoader.cxx | 26 ++++++++++++++++---------- src/Scenery/FGTileLoader.hxx | 8 ++++++-- src/Scenery/tileentry.cxx | 3 ++- src/Scenery/tilemgr.cxx | 24 ++++++++++-------------- src/Scenery/tilemgr.hxx | 8 ++++++-- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/Scenery/FGTileLoader.cxx b/src/Scenery/FGTileLoader.cxx index 17cc52fc3..a709b57f0 100644 --- a/src/Scenery/FGTileLoader.cxx +++ b/src/Scenery/FGTileLoader.cxx @@ -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 ); diff --git a/src/Scenery/FGTileLoader.hxx b/src/Scenery/FGTileLoader.hxx index 75b3a0c3d..16878e134 100644 --- a/src/Scenery/FGTileLoader.hxx +++ b/src/Scenery/FGTileLoader.hxx @@ -30,6 +30,8 @@ #ifdef ENABLE_THREADS # include # include +#else +# include #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 /** diff --git a/src/Scenery/tileentry.cxx b/src/Scenery/tileentry.cxx index a3c921188..020c32436 100644 --- a/src/Scenery/tileentry.cxx +++ b/src/Scenery/tileentry.cxx @@ -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() ); diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index b47e6246d..d949c6ab2 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -71,6 +71,8 @@ static inline Point3D operator + (const Point3D& a, const sgdVec3 b) #ifdef ENABLE_THREADS SGLockedQueue FGTileMgr::loaded_queue; +#else +queue 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; diff --git a/src/Scenery/tilemgr.hxx b/src/Scenery/tilemgr.hxx index 2503f50d7..9d3f74685 100644 --- a/src/Scenery/tilemgr.hxx +++ b/src/Scenery/tilemgr.hxx @@ -31,6 +31,8 @@ #include +#include + #include #include @@ -116,11 +118,14 @@ private: FGTileLoader loader; int counter_hack; -#ifdef ENABLE_THREADS /** * Tiles to add to scene graph. */ +#ifdef ENABLE_THREADS static SGLockedQueue loaded_queue; +#else + static queue 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: