Added DatabasePager::setUseFrameBlock(bool) method

This commit is contained in:
Robert Osfield
2004-01-07 12:37:44 +00:00
parent 72ac2f7eee
commit 2f918d62d7
2 changed files with 31 additions and 16 deletions

View File

@@ -84,6 +84,16 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
/** run does the database paging.*/
virtual void run();
/** Set the use of the frame block which, if enabled, blocks the DatabasePager
* from executing which the current frame is being drawn.
* When a single processor machine is being used it can be useful to block on
* frame to help prevent the database paging thread from slowing the cull and draw
* traversals which in turn can cause frame drops.*/
void setUseFrameBlock(bool useFrameBlock) { _useFrameBlock = useFrameBlock; }
/** Get the whether UseFrameBlock is on or off.*/
bool getUseFrameBlock() const { return _useFrameBlock; }
/** Signal the database thread that the update, cull and draw has begun for a new frame.
* Note, this is called by the application so that the database pager can go to sleep while the CPU is busy on the main rendering threads. */
@@ -196,6 +206,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
virtual ~DatabasePager();
bool _useFrameBlock;
osg::ref_ptr<Block> _frameBlock;
int _frameNumber;

View File

@@ -19,6 +19,7 @@ DatabasePager::DatabasePager()
{
//osg::notify(osg::INFO)<<"Constructing DatabasePager()"<<std::endl;
_useFrameBlock = false;
_frameNumber = 0;
_frameBlock = new Block;
_fileRequestListEmptyBlock = new Block;
@@ -45,8 +46,7 @@ DatabasePager::~DatabasePager()
}
}
std::cout<<"DatabasePager::~DatabasePager() stopped running"<<std::endl;
//std::cout<<"DatabasePager::~DatabasePager() stopped running"<<std::endl;
}
void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* group, float priority, const osg::FrameStamp* framestamp)
@@ -263,20 +263,18 @@ void DatabasePager::run()
// by keeping deleted texture objects around for 10 seconds after being deleted.
osg::Texture::getTextureObjectManager()->setExpiryDelay(10.0f);
bool firstTime = true;
do
{
//std::cout<<"In run loop"<<std::endl;
//osg::Timer_t t1 = osg::Timer::instance()->tick();
_fileRequestListEmptyBlock->block();
//osg::Timer_t t2 = osg::Timer::instance()->tick();
_frameBlock->block();
//osg::Timer_t t3 = osg::Timer::instance()->tick();
//std::cout<<"Time in _fileRequestListEmptyBlock block()"<<osg::Timer::instance()->delta_m(t1,t2)<<std::endl;
//std::cout<<"Time in _frameBlock block()"<<osg::Timer::instance()->delta_m(t2,t3)<<std::endl;
if (_useFrameBlock)
{
_frameBlock->block();
}
//
// delete any children if required.
//
@@ -316,7 +314,7 @@ void DatabasePager::run()
osg::notify(osg::INFO)<<"In DatabasePager thread readNodeFile("<<databaseRequest->_fileName<<")"<<std::endl;
osg::Timer_t before = osg::Timer::instance()->tick();
databaseRequest->_loadedModel = osgDB::readNodeFile(databaseRequest->_fileName);
osg::notify(osg::INFO)<<" node read"<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<std::endl;
osg::notify(osg::INFO)<<" node read in "<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<" ms"<<std::endl;
bool loadedObjectsNeedToBeCompiled = false;
@@ -350,7 +348,6 @@ void DatabasePager::run()
}
}
// move the databaseRequest from the front of the fileRequest to the end of
// dataLoad list.
_fileRequestListMutex.lock();
@@ -376,6 +373,7 @@ void DatabasePager::run()
if (_fileRequestList.empty()) _fileRequestListEmptyBlock->reset();
_fileRequestListMutex.unlock();
}
else
{
@@ -389,13 +387,19 @@ void DatabasePager::run()
if (_fileRequestList.empty()) _fileRequestListEmptyBlock->reset();
_fileRequestListMutex.unlock();
}
}
// go to sleep till our the next time our thread gets scheduled.
//YieldCurrentThread();
//std::cout<<"At end of loop"<<std::endl;
if (firstTime)
{
// do a yield to get round a peculiar thread hang when testCancel() is called
// in certain cirumstances - of which there is no particular pattern.
YieldCurrentThread();
firstTime = false;
}
} while (!testCancel());