Tile loading is interleaved now when not threaded. Threaded loader is
throttled to one tile per frame maximum.
This commit is contained in:
parent
f85df36eaa
commit
865fb56c5a
5 changed files with 40 additions and 29 deletions
|
@ -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 );
|
||||
|
|
|
@ -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
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() );
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in a new issue