X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FScenery%2FFGTileLoader.cxx;h=3bbe26521f994e9a27932f5885287540ff890c84;hb=56592f3869c41e4f189e9ab44abb1a0898c90f4b;hp=6a787926fba57af17dd65a125091d6b39285e61a;hpb=4a609646b66215ed31d4fb11207b89d0c4b54d8d;p=flightgear.git diff --git a/src/Scenery/FGTileLoader.cxx b/src/Scenery/FGTileLoader.cxx index 6a787926f..3bbe26521 100644 --- a/src/Scenery/FGTileLoader.cxx +++ b/src/Scenery/FGTileLoader.cxx @@ -24,11 +24,16 @@ # include #endif +#include + #include
#include "FGTileLoader.hxx" #include "tileentry.hxx" #include "tilemgr.hxx" +extern ssgBranch *terrain; +extern ssgBranch *ground; + /** * */ @@ -61,6 +66,19 @@ FGTileLoader::~FGTileLoader() #endif // ENABLE_THREADS } + +#if 0 // we don't ever want to do this I don't think +/** + * + */ +void FGTileLoader::reinit() { + while ( !tile_load_queue.empty() ) { + tile_load_queue.pop(); + } +} +#endif + + /** * */ @@ -74,7 +92,7 @@ FGTileLoader::add( FGTileEntry* tile ) static bool beenhere = false; if (!beenhere) { - if ( globals->get_fg_scenery() != (string)"" ) { + if ( !globals->get_fg_scenery().empty() ) { tile_path.set( globals->get_fg_scenery() ); } else { tile_path.set( globals->get_fg_root() ); @@ -83,12 +101,19 @@ FGTileLoader::add( FGTileEntry* tile ) beenhere = true; } -#ifdef ENABLE_THREADS - tile_queue.push( tile ); -#else - tile->load( tile_path, true ); -#endif // ENABLE_THREADS + tile_load_queue.push( tile ); +} + +#ifdef WISH_PLIB_WAS_THREADED // but it isn't +/** + * + */ +void +FGTileLoader::remove( FGTileEntry* tile ) +{ + tile_free_queue.push( tile ); } +#endif /** * @@ -96,11 +121,38 @@ FGTileLoader::add( FGTileEntry* tile ) 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::ready_to_attach( tile ); + } + +#ifdef WISH_PLIB_WAS_THREADED // but it isn't + if ( !tile_free_queue.empty() ) { + // cout << "freeing next tile ..." << endl; + // free the next tile in the queue + FGTileEntry* tile = tile_free_queue.front(); + tile_free_queue.pop(); + tile->free_tile(); + delete tile; + } +#endif + #endif // ENABLE_THREADS + } @@ -114,18 +166,30 @@ 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 ); set_cancel( SGThread::CANCEL_DEFERRED ); - FGTileMgr::loaded( tile ); + FGTileMgr::ready_to_attach( tile ); + +#ifdef WISH_PLIB_WAS_THREADED // but it isn't + // Handle and pending removals + while ( !loader->tile_free_queue.empty() ) { + // cout << "freeing next tile ..." << endl; + // free the next tile in the queue + FGTileEntry* tile = loader->tile_free_queue.pop(); + tile->free_tile(); + delete tile; + } +#endif + } pthread_cleanup_pop(1); }