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