2004-09-22 01:26:08 +08:00
# include <osgDB/DatabasePager>
2003-07-21 18:39:07 +08:00
# include <osgDB/ReadFile>
2004-05-20 18:15:48 +08:00
2003-07-21 18:39:07 +08:00
# include <osg/Geode>
# include <osg/Timer>
# include <osg/Texture>
2003-09-01 05:13:50 +08:00
# include <osg/Notify>
2003-07-21 18:39:07 +08:00
2003-10-09 17:48:36 +08:00
# include <OpenThreads/ScopedLock>
2003-07-21 18:39:07 +08:00
# ifdef WIN32
# include <windows.h>
# else
# include <unistd.h>
# endif
using namespace osgDB ;
2004-09-20 04:09:54 +08:00
using namespace OpenThreads ;
2003-07-21 18:39:07 +08:00
DatabasePager : : DatabasePager ( )
{
2003-10-09 05:29:45 +08:00
//osg::notify(osg::INFO)<<"Constructing DatabasePager()"<<std::endl;
2003-07-21 18:39:07 +08:00
2004-09-22 05:33:52 +08:00
_startThreadCalled = false ;
2004-09-20 04:09:54 +08:00
_done = false ;
_acceptNewRequests = true ;
_databasePagerThreadPaused = false ;
2004-01-22 18:42:32 +08:00
_useFrameBlock = false ;
2004-09-28 16:39:46 +08:00
_numFramesActive = 0 ;
2003-10-12 20:13:58 +08:00
_frameNumber = 0 ;
2003-10-12 22:51:54 +08:00
_frameBlock = new Block ;
2004-09-19 03:28:45 +08:00
_databasePagerThreadBlock = new Block ;
2003-10-12 20:13:58 +08:00
2004-01-22 18:42:32 +08:00
_threadPriorityDuringFrame = PRIORITY_MIN ;
2004-01-29 04:17:10 +08:00
_threadPriorityOutwithFrame = PRIORITY_MIN ;
2004-01-22 18:42:32 +08:00
2004-07-22 03:16:49 +08:00
_changeAutoUnRef = true ;
_valueAutoUnRef = true ;
2004-07-20 13:37:59 +08:00
_changeAnisotropy = false ;
_valueAnisotropy = 1.0f ;
2004-01-27 22:49:59 +08:00
# if 1
_deleteRemovedSubgraphsInDatabaseThread = true ;
# else
_deleteRemovedSubgraphsInDatabaseThread = false ;
# endif
2003-07-21 18:39:07 +08:00
2004-09-24 02:50:38 +08:00
_expiryDelay = 10 ;
2004-01-11 01:13:20 +08:00
// make sure a SharedStateManager exists.
//osgDB::Registry::instance()->getOrCreateSharedStateManager();
//if (osgDB::Registry::instance()->getSharedStateManager())
//osgDB::Registry::instance()->setUseObjectCacheHint(true);
2003-07-21 18:39:07 +08:00
}
2003-08-20 20:52:33 +08:00
DatabasePager : : ~ DatabasePager ( )
{
2004-09-20 04:09:54 +08:00
cancel ( ) ;
}
2004-01-11 01:13:20 +08:00
2004-09-20 04:09:54 +08:00
int DatabasePager : : cancel ( )
{
int result = 0 ;
2003-08-20 20:52:33 +08:00
if ( isRunning ( ) )
{
2004-09-20 04:09:54 +08:00
_done = true ;
2004-01-11 01:13:20 +08:00
2003-08-20 20:52:33 +08:00
// cancel the thread..
2004-09-20 04:09:54 +08:00
result = Thread : : cancel ( ) ;
2003-08-20 20:52:33 +08:00
//join();
2004-09-19 03:28:45 +08:00
// release the frameBlock and _databasePagerThreadBlock incase its holding up thread cancelation.
2004-03-14 00:29:29 +08:00
_frameBlock - > release ( ) ;
2004-09-19 03:28:45 +08:00
_databasePagerThreadBlock - > release ( ) ;
2004-03-14 00:29:29 +08:00
2003-08-20 20:52:33 +08:00
// then wait for the the thread to stop running.
while ( isRunning ( ) )
{
2003-09-01 05:13:50 +08:00
osg : : notify ( osg : : DEBUG_INFO ) < < " Waiting for DatabasePager to cancel " < < std : : endl ;
2003-08-21 17:52:12 +08:00
OpenThreads : : Thread : : YieldCurrentThread ( ) ;
2003-08-20 20:52:33 +08:00
}
2004-09-22 05:33:52 +08:00
_startThreadCalled = false ;
2003-08-20 20:52:33 +08:00
}
2004-01-07 20:37:44 +08:00
//std::cout<<"DatabasePager::~DatabasePager() stopped running"<<std::endl;
2004-09-20 04:09:54 +08:00
return result ;
}
void DatabasePager : : clear ( )
{
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _fileRequestListMutex ) ;
_fileRequestList . clear ( ) ;
}
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToCompileListMutex ) ;
_dataToCompileList . clear ( ) ;
}
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _childrenToDeleteListMutex ) ;
_childrenToDeleteList . clear ( ) ;
}
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToMergeListMutex ) ;
_dataToMergeList . clear ( ) ;
}
// no mutex??
2004-09-22 01:26:08 +08:00
_activePagedLODList . clear ( ) ;
_inactivePagedLODList . clear ( ) ;
2004-09-20 04:09:54 +08:00
// ??
// _activeGraphicsContexts
2003-08-20 20:52:33 +08:00
}
2003-10-11 03:25:14 +08:00
void DatabasePager : : requestNodeFile ( const std : : string & fileName , osg : : Group * group , float priority , const osg : : FrameStamp * framestamp )
2003-07-21 18:39:07 +08:00
{
2004-09-20 04:09:54 +08:00
if ( ! _acceptNewRequests ) return ;
2003-07-21 18:39:07 +08:00
2003-10-11 03:25:14 +08:00
double timestamp = framestamp ? framestamp - > getReferenceTime ( ) : 0.0 ;
2003-10-12 20:13:58 +08:00
int frameNumber = framestamp ? framestamp - > getFrameNumber ( ) : _frameNumber ;
2003-10-11 03:25:14 +08:00
2003-07-21 18:39:07 +08:00
// search to see if filename already exist in the file loaded list.
bool foundEntry = false ;
2004-09-20 04:09:54 +08:00
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToCompileListMutex ) ;
2003-07-21 18:39:07 +08:00
for ( DatabaseRequestList : : iterator litr = _dataToCompileList . begin ( ) ;
litr ! = _dataToCompileList . end ( ) & & ! foundEntry ;
+ + litr )
{
if ( ( * litr ) - > _fileName = = fileName )
{
foundEntry = true ;
2003-10-12 20:13:58 +08:00
( * litr ) - > _frameNumberLastRequest = frameNumber ;
2003-10-11 03:25:14 +08:00
( * litr ) - > _timestampLastRequest = timestamp ;
( * litr ) - > _priorityLastRequest = priority ;
2003-07-21 18:39:07 +08:00
+ + ( ( * litr ) - > _numOfRequests ) ;
}
}
2004-09-20 04:09:54 +08:00
}
2003-07-21 18:39:07 +08:00
if ( ! foundEntry )
{
2004-09-20 04:09:54 +08:00
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToMergeListMutex ) ;
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
for ( DatabaseRequestList : : iterator litr = _dataToMergeList . begin ( ) ;
litr ! = _dataToMergeList . end ( ) & & ! foundEntry ;
+ + litr )
{
if ( ( * litr ) - > _fileName = = fileName )
2003-07-21 18:39:07 +08:00
{
2004-09-20 04:09:54 +08:00
foundEntry = true ;
( * litr ) - > _frameNumberLastRequest = frameNumber ;
( * litr ) - > _timestampLastRequest = timestamp ;
( * litr ) - > _priorityLastRequest = priority ;
+ + ( ( * litr ) - > _numOfRequests ) ;
}
}
2003-07-21 18:39:07 +08:00
}
if ( ! foundEntry )
{
2004-09-20 04:09:54 +08:00
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _fileRequestListMutex ) ;
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
// search to see if entry already in file request list.
bool foundEntry = false ;
for ( DatabaseRequestList : : iterator ritr = _fileRequestList . begin ( ) ;
ritr ! = _fileRequestList . end ( ) & & ! foundEntry ;
+ + ritr )
{
if ( ( * ritr ) - > _fileName = = fileName )
2003-07-21 18:39:07 +08:00
{
2004-09-20 04:09:54 +08:00
foundEntry = true ;
( * ritr ) - > _timestampLastRequest = timestamp ;
( * ritr ) - > _priorityLastRequest = priority ;
( * ritr ) - > _frameNumberLastRequest = frameNumber ;
+ + ( ( * ritr ) - > _numOfRequests ) ;
}
}
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
if ( ! foundEntry )
{
osg : : notify ( osg : : INFO ) < < " In DatabasePager::fileRquest( " < < fileName < < " ) " < < std : : endl ;
2003-10-12 20:13:58 +08:00
2004-09-20 04:09:54 +08:00
osg : : ref_ptr < DatabaseRequest > databaseRequest = new DatabaseRequest ;
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
databaseRequest - > _fileName = fileName ;
databaseRequest - > _frameNumberFirstRequest = frameNumber ;
databaseRequest - > _timestampFirstRequest = timestamp ;
databaseRequest - > _priorityFirstRequest = priority ;
databaseRequest - > _frameNumberLastRequest = frameNumber ;
databaseRequest - > _timestampLastRequest = timestamp ;
databaseRequest - > _priorityLastRequest = priority ;
databaseRequest - > _groupForAddingLoadedSubgraph = group ;
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
_fileRequestList . push_back ( databaseRequest ) ;
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
updateDatabasePagerThreadBlock ( ) ;
}
2003-07-21 18:39:07 +08:00
}
if ( ! isRunning ( ) )
{
2004-09-22 05:33:52 +08:00
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _run_mutex ) ;
2003-10-09 17:48:36 +08:00
2004-09-22 05:33:52 +08:00
if ( ! _startThreadCalled )
2003-10-09 17:48:36 +08:00
{
2004-09-22 05:33:52 +08:00
_startThreadCalled = true ;
2004-09-20 04:09:54 +08:00
_done = false ;
2003-10-09 17:48:36 +08:00
osg : : notify ( osg : : DEBUG_INFO ) < < " DatabasePager::startThread() " < < std : : endl ;
2004-01-22 18:42:32 +08:00
setSchedulePriority ( _threadPriorityDuringFrame ) ;
2003-10-09 17:48:36 +08:00
startThread ( ) ;
}
2003-07-21 18:39:07 +08:00
}
}
2003-10-12 20:13:58 +08:00
void DatabasePager : : signalBeginFrame ( const osg : : FrameStamp * framestamp )
{
2004-09-23 20:27:56 +08:00
2003-10-12 20:13:58 +08:00
if ( framestamp )
{
2003-10-30 00:45:17 +08:00
//osg::notify(osg::INFO) << "signalBeginFrame "<<framestamp->getFrameNumber()<<">>>>>>>>>>>>>>>>"<<std::endl;
2003-10-12 20:13:58 +08:00
_frameNumber = framestamp - > getFrameNumber ( ) ;
2004-09-23 20:27:56 +08:00
2003-10-30 00:45:17 +08:00
} //else osg::notify(osg::INFO) << "signalBeginFrame >>>>>>>>>>>>>>>>"<<std::endl;
2003-10-12 20:13:58 +08:00
2004-09-28 16:39:46 +08:00
updateFrameBlock ( 1 ) ;
2004-09-23 20:27:56 +08:00
2004-09-28 16:39:46 +08:00
if ( _numFramesActive > 0 & & _threadPriorityDuringFrame ! = getSchedulePriority ( ) )
2004-01-22 18:42:32 +08:00
setSchedulePriority ( _threadPriorityDuringFrame ) ;
2003-10-12 20:13:58 +08:00
}
void DatabasePager : : signalEndFrame ( )
{
2003-10-30 00:45:17 +08:00
//osg::notify(osg::INFO) << "signalEndFrame <<<<<<<<<<<<<<<<<<<< "<<std::endl;
2004-09-28 16:39:46 +08:00
updateFrameBlock ( - 1 ) ;
2004-01-22 18:42:32 +08:00
2004-09-28 16:39:46 +08:00
if ( _numFramesActive < = 0 & & _threadPriorityOutwithFrame ! = getSchedulePriority ( ) )
2004-01-22 18:42:32 +08:00
setSchedulePriority ( _threadPriorityOutwithFrame ) ;
2003-10-12 20:13:58 +08:00
}
2004-01-07 05:18:36 +08:00
class FindCompileableGLObjectsVisitor : public osg : : NodeVisitor
2003-07-21 18:39:07 +08:00
{
public :
2004-07-20 13:37:59 +08:00
FindCompileableGLObjectsVisitor ( DatabasePager : : DataToCompile & dataToCompile ,
bool changeAutoUnRef , bool valueAutoUnRef ,
bool changeAnisotropy , float valueAnisotropy ) :
osg : : NodeVisitor ( osg : : NodeVisitor : : TRAVERSE_ALL_CHILDREN ) ,
_dataToCompile ( dataToCompile ) ,
_changeAutoUnRef ( changeAutoUnRef ) , _valueAutoUnRef ( valueAutoUnRef ) ,
_changeAnisotropy ( changeAnisotropy ) , _valueAnisotropy ( valueAnisotropy )
2003-07-21 18:39:07 +08:00
{
}
virtual void apply ( osg : : Node & node )
{
apply ( node . getStateSet ( ) ) ;
traverse ( node ) ;
}
virtual void apply ( osg : : Geode & geode )
{
apply ( geode . getStateSet ( ) ) ;
for ( unsigned int i = 0 ; i < geode . getNumDrawables ( ) ; + + i )
{
apply ( geode . getDrawable ( i ) ) ;
}
traverse ( geode ) ;
}
inline void apply ( osg : : StateSet * stateset )
{
if ( stateset )
{
// search for the existance of any texture object attributes
bool foundTextureState = false ;
2004-07-12 21:20:18 +08:00
for ( unsigned int i = 0 ; i < stateset - > getTextureAttributeList ( ) . size ( ) ; + + i )
2003-07-21 18:39:07 +08:00
{
2004-07-12 21:20:18 +08:00
osg : : Texture * texture = dynamic_cast < osg : : Texture * > ( stateset - > getTextureAttribute ( i , osg : : StateAttribute : : TEXTURE ) ) ;
if ( texture )
2004-07-12 18:23:15 +08:00
{
2004-07-20 13:37:59 +08:00
if ( _changeAutoUnRef ) texture - > setUnRefImageDataAfterApply ( _valueAutoUnRef ) ;
if ( _changeAnisotropy ) texture - > setMaxAnisotropy ( _valueAnisotropy ) ;
2004-07-12 18:23:15 +08:00
foundTextureState = true ;
}
2003-07-21 18:39:07 +08:00
}
// if texture object attributes exist add the state to the list for later compilation.
if ( foundTextureState )
{
2003-09-01 05:13:50 +08:00
//osg::notify(osg::DEBUG_INFO)<<"Found compilable texture state"<<std::endl;
2004-09-24 02:50:38 +08:00
_dataToCompile . first . insert ( stateset ) ;
2003-07-21 18:39:07 +08:00
}
}
}
inline void apply ( osg : : Drawable * drawable )
{
apply ( drawable - > getStateSet ( ) ) ;
2004-09-22 01:26:08 +08:00
// drawable->setUseDisplayList(false);
// drawable->setUseVertexBufferObjects(true);
2003-07-21 18:39:07 +08:00
if ( drawable - > getUseDisplayList ( ) | | drawable - > getUseVertexBufferObjects ( ) )
{
2003-10-09 05:29:45 +08:00
//osg::notify(osg::INFO)<<"Found compilable drawable"<<std::endl;
2003-07-21 18:39:07 +08:00
_dataToCompile . second . push_back ( drawable ) ;
}
}
2004-07-12 18:23:15 +08:00
DatabasePager : : DataToCompile & _dataToCompile ;
2004-07-20 13:37:59 +08:00
bool _changeAutoUnRef ;
bool _valueAutoUnRef ;
bool _changeAnisotropy ;
float _valueAnisotropy ;
2003-07-21 18:39:07 +08:00
} ;
2003-10-11 03:25:14 +08:00
struct SortFileRequestFunctor
{
bool operator ( ) ( const osg : : ref_ptr < DatabasePager : : DatabaseRequest > & lhs , const osg : : ref_ptr < DatabasePager : : DatabaseRequest > & rhs ) const
{
if ( lhs - > _timestampLastRequest > rhs - > _timestampLastRequest ) return true ;
else if ( lhs - > _timestampLastRequest < rhs - > _timestampLastRequest ) return false ;
else return ( lhs - > _priorityLastRequest > rhs - > _priorityLastRequest ) ;
}
} ;
2004-09-20 04:09:54 +08:00
void DatabasePager : : setDatabasePagerThreadPause ( bool pause )
{
_databasePagerThreadPaused = pause ;
updateDatabasePagerThreadBlock ( ) ;
}
2003-07-21 18:39:07 +08:00
void DatabasePager : : run ( )
{
2004-08-11 02:31:43 +08:00
osg : : notify ( osg : : INFO ) < < " DatabasePager::run() " < < std : : endl ;
2003-07-23 23:52:05 +08:00
// need to set the texture object manager to be able to reuse textures
2004-09-22 05:33:52 +08:00
osg : : Texture : : setMinimumNumberOfTextureObjectsToRetainInCache ( 100 ) ;
2003-07-21 18:39:07 +08:00
2004-09-22 05:33:52 +08:00
// need to set the texture object manager to be able to reuse textures
2004-09-23 20:27:56 +08:00
osg : : Drawable : : setMinimumNumberOfDisplayListsToRetainInCache ( 500 ) ;
2004-09-22 05:33:52 +08:00
2004-01-07 20:37:44 +08:00
bool firstTime = true ;
2003-09-05 03:45:55 +08:00
do
2003-07-21 18:39:07 +08:00
{
2003-10-12 20:13:58 +08:00
2004-09-19 03:28:45 +08:00
_databasePagerThreadBlock - > block ( ) ;
2004-01-07 20:37:44 +08:00
if ( _useFrameBlock )
{
_frameBlock - > block ( ) ;
}
2003-07-21 18:39:07 +08:00
//
// delete any children if required.
//
if ( _deleteRemovedSubgraphsInDatabaseThread )
{
2004-09-19 03:28:45 +08:00
osg : : ref_ptr < osg : : Object > obj = 0 ;
2004-09-20 04:09:54 +08:00
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _childrenToDeleteListMutex ) ;
2003-07-21 18:39:07 +08:00
if ( ! _childrenToDeleteList . empty ( ) )
{
2004-09-19 03:28:45 +08:00
//osg::notify(osg::NOTICE)<<"In DatabasePager thread deleting "<<_childrenToDeleteList.size()<<" objects"<<std::endl;
//osg::Timer_t before = osg::Timer::instance()->tick();
obj = _childrenToDeleteList . back ( ) ;
_childrenToDeleteList . pop_back ( ) ;
//osg::notify(osg::NOTICE)<<"Done DatabasePager thread deleted in "<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<" ms"<<" objects"<<std::endl;
updateDatabasePagerThreadBlock ( ) ;
}
2004-09-20 04:09:54 +08:00
}
2003-07-21 18:39:07 +08:00
}
//
// load any subgraphs that are required.
//
osg : : ref_ptr < DatabaseRequest > databaseRequest ;
// get the front of the file request list.
2004-09-20 04:09:54 +08:00
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _fileRequestListMutex ) ;
2003-10-11 03:25:14 +08:00
if ( ! _fileRequestList . empty ( ) )
{
std : : sort ( _fileRequestList . begin ( ) , _fileRequestList . end ( ) , SortFileRequestFunctor ( ) ) ;
databaseRequest = _fileRequestList . front ( ) ;
}
2004-09-20 04:09:54 +08:00
}
2003-07-21 18:39:07 +08:00
if ( databaseRequest . valid ( ) )
{
2003-10-12 20:13:58 +08:00
// check if databaseRequest is still relevant
if ( _frameNumber - databaseRequest - > _frameNumberLastRequest < = 1 )
{
2004-01-11 01:13:20 +08:00
2003-10-12 20:13:58 +08:00
// load the data, note safe to write to the databaseRequest since once
// it is created this thread is the only one to write to the _loadedModel pointer.
2004-09-19 03:28:45 +08:00
// osg::notify(osg::NOTICE)<<"In DatabasePager thread readNodeFile("<<databaseRequest->_fileName<<")"<<std::endl;
//osg::Timer_t before = osg::Timer::instance()->tick();
2004-09-22 05:33:52 +08:00
bool serialize_readNodeFile = true ;
if ( serialize_readNodeFile )
{
// do *not* assume that we only have one DatabasePager, or that reaNodeFile is thread safe...
static OpenThreads : : Mutex s_serialize_readNodeFile_mutex ;
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( s_serialize_readNodeFile_mutex ) ;
databaseRequest - > _loadedModel = osgDB : : readNodeFile ( databaseRequest - > _fileName ) ;
}
else
{
// assume that we only have one DatabasePager, or that reaNodeFile is thread safe...
databaseRequest - > _loadedModel = osgDB : : readNodeFile ( databaseRequest - > _fileName ) ;
}
2004-09-19 03:28:45 +08:00
//osg::notify(osg::NOTICE)<<" node read in "<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<" ms"<<std::endl;
2004-01-11 01:13:20 +08:00
2003-10-12 20:13:58 +08:00
bool loadedObjectsNeedToBeCompiled = false ;
2003-07-21 18:39:07 +08:00
2003-10-12 20:13:58 +08:00
if ( databaseRequest - > _loadedModel . valid ( ) & & ! _activeGraphicsContexts . empty ( ) )
2003-07-21 18:39:07 +08:00
{
2003-10-12 20:13:58 +08:00
// force a compute of the loaded model's bounding volume, so that when the subgraph
// merged with the main scene graph and large computeBound() isn't incurred.
databaseRequest - > _loadedModel - > getBound ( ) ;
2003-07-21 18:39:07 +08:00
2003-10-12 20:13:58 +08:00
ActiveGraphicsContexts : : iterator itr = _activeGraphicsContexts . begin ( ) ;
2003-07-21 18:39:07 +08:00
2003-10-12 20:13:58 +08:00
DataToCompile & dtc = databaseRequest - > _dataToCompileMap [ * itr ] ;
+ + itr ;
// find all the compileable rendering objects
2004-07-20 13:37:59 +08:00
FindCompileableGLObjectsVisitor frov ( dtc ,
_changeAutoUnRef , _valueAutoUnRef ,
_changeAnisotropy , _valueAnisotropy ) ;
2003-10-12 20:13:58 +08:00
databaseRequest - > _loadedModel - > accept ( frov ) ;
if ( ! dtc . first . empty ( ) | | ! dtc . second . empty ( ) )
2003-07-21 18:39:07 +08:00
{
2003-10-12 20:13:58 +08:00
loadedObjectsNeedToBeCompiled = true ;
2004-09-19 03:28:45 +08:00
// copy the objects from the compile list to the other graphics context list.
2003-10-12 20:13:58 +08:00
for ( ;
itr ! = _activeGraphicsContexts . end ( ) ;
+ + itr )
{
databaseRequest - > _dataToCompileMap [ * itr ] = dtc ;
}
2003-07-21 18:39:07 +08:00
}
2003-10-12 20:13:58 +08:00
}
2003-07-21 18:39:07 +08:00
2003-10-12 20:13:58 +08:00
// move the databaseRequest from the front of the fileRequest to the end of
// dataLoad list.
2004-09-20 04:09:54 +08:00
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _fileRequestListMutex ) ;
2003-10-12 20:13:58 +08:00
2004-09-20 04:09:54 +08:00
if ( databaseRequest - > _loadedModel . valid ( ) )
{
if ( loadedObjectsNeedToBeCompiled )
2003-10-12 20:13:58 +08:00
{
2004-09-20 04:09:54 +08:00
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToCompileListMutex ) ;
_dataToCompileList . push_back ( databaseRequest ) ;
}
else
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToMergeListMutex ) ;
_dataToMergeList . push_back ( databaseRequest ) ;
}
}
2003-10-12 20:13:58 +08:00
2004-09-20 04:09:54 +08:00
if ( ! _fileRequestList . empty ( ) ) _fileRequestList . erase ( _fileRequestList . begin ( ) ) ;
2003-10-12 20:13:58 +08:00
2004-09-20 04:09:54 +08:00
updateDatabasePagerThreadBlock ( ) ;
2004-01-07 20:37:44 +08:00
2003-10-12 20:13:58 +08:00
}
else
{
//std::cout<<"frame number delta for "<<databaseRequest->_fileName<<" "<<_frameNumber-databaseRequest->_frameNumberLastRequest<<std::endl;
// remove the databaseRequest from the front of the fileRequest to the end of
// dataLoad list as its is no longer relevant
2004-09-20 04:09:54 +08:00
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _fileRequestListMutex ) ;
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
if ( ! _fileRequestList . empty ( ) ) _fileRequestList . erase ( _fileRequestList . begin ( ) ) ;
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
updateDatabasePagerThreadBlock ( ) ;
2004-01-07 20:37:44 +08:00
2003-10-12 20:13:58 +08:00
}
2003-07-21 18:39:07 +08:00
}
2003-07-23 05:03:59 +08:00
// go to sleep till our the next time our thread gets scheduled.
2003-10-12 20:13:58 +08:00
2004-01-07 20:37:44 +08:00
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 ;
}
2003-07-21 23:51:43 +08:00
2004-09-22 01:26:08 +08:00
} while ( ! testCancel ( ) & & ! _done ) ;
2004-08-27 20:04:29 +08:00
2003-07-21 18:39:07 +08:00
}
2004-09-24 02:50:38 +08:00
bool DatabasePager : : requiresUpdateSceneGraph ( ) const
{
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToMergeListMutex ) ;
if ( ! _dataToMergeList . empty ( ) ) return true ;
}
return false ;
}
2003-07-21 18:39:07 +08:00
void DatabasePager : : addLoadedDataToSceneGraph ( double timeStamp )
{
2004-09-22 01:26:08 +08:00
// osg::Timer_t before = osg::Timer::instance()->tick();
2003-07-21 18:39:07 +08:00
DatabaseRequestList localFileLoadedList ;
// get the dat for the _dataToCompileList, leaving it empty via a std::vector<>.swap.
2004-09-20 04:09:54 +08:00
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToMergeListMutex ) ;
2003-07-21 18:39:07 +08:00
localFileLoadedList . swap ( _dataToMergeList ) ;
2004-09-20 04:09:54 +08:00
}
2003-07-21 18:39:07 +08:00
// add the loaded data into the scene graph.
for ( DatabaseRequestList : : iterator itr = localFileLoadedList . begin ( ) ;
itr ! = localFileLoadedList . end ( ) ;
+ + itr )
{
DatabaseRequest * databaseRequest = itr - > get ( ) ;
2004-01-11 01:13:20 +08:00
2004-09-19 03:28:45 +08:00
// osg::notify(osg::NOTICE)<<"Merging "<<_frameNumber-(*itr)->_frameNumberLastRequest<<std::endl;
2004-01-11 01:13:20 +08:00
if ( osgDB : : Registry : : instance ( ) - > getSharedStateManager ( ) )
osgDB : : Registry : : instance ( ) - > getSharedStateManager ( ) - > share ( databaseRequest - > _loadedModel . get ( ) ) ;
2003-07-21 18:39:07 +08:00
registerPagedLODs ( databaseRequest - > _loadedModel . get ( ) ) ;
osg : : Group * group = databaseRequest - > _groupForAddingLoadedSubgraph . get ( ) ;
osg : : PagedLOD * plod = dynamic_cast < osg : : PagedLOD * > ( group ) ;
if ( plod )
{
plod - > setTimeStamp ( plod - > getNumChildren ( ) , timeStamp ) ;
}
group - > addChild ( databaseRequest - > _loadedModel . get ( ) ) ;
2003-10-09 05:29:45 +08:00
osg : : notify ( osg : : INFO ) < < " merged subgraph " < < databaseRequest - > _fileName < < " after " < < databaseRequest - > _numOfRequests < < " requests. " < < std : : endl ;
2003-07-21 18:39:07 +08:00
}
2004-01-27 22:49:59 +08:00
2004-09-22 01:26:08 +08:00
// osg::notify(osg::NOTICE)<<"Done DatabasePager::addLoadedDataToSceneGraph"<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<" ms objects"<<localFileLoadedList.size()<<std::endl;
2004-09-19 03:28:45 +08:00
2004-09-22 01:26:08 +08:00
}
2003-07-21 18:39:07 +08:00
2004-09-24 02:50:38 +08:00
2003-07-21 18:39:07 +08:00
void DatabasePager : : removeExpiredSubgraphs ( double currentFrameTime )
{
2004-09-22 01:26:08 +08:00
//osg::notify(osg::NOTICE)<<"DatabasePager::removeExpiredSubgraphs()"<<std::endl;
// osg::Timer_t before = osg::Timer::instance()->tick();
2004-09-19 03:28:45 +08:00
2003-07-21 18:39:07 +08:00
double expiryTime = currentFrameTime - _expiryDelay ;
osg : : NodeList childrenRemoved ;
2004-09-22 01:26:08 +08:00
2003-07-21 18:39:07 +08:00
2004-09-22 01:26:08 +08:00
for ( PagedLODList : : iterator active_itr = _activePagedLODList . begin ( ) ;
active_itr ! = _activePagedLODList . end ( ) ;
)
2003-07-21 18:39:07 +08:00
{
2004-09-22 01:26:08 +08:00
const osg : : PagedLOD * plod = active_itr - > get ( ) ;
bool remove_plod = false ;
if ( plod - > referenceCount ( ) < = 1 )
{
// prune PageLOD's that are no longer externally referenced
childrenRemoved . push_back ( const_cast < osg : : PagedLOD * > ( plod ) ) ;
//osg::notify(osg::NOTICE)<<"_activePagedLODList : pruning no longer externally referenced"<<std::endl;
remove_plod = true ;
}
else if ( plod - > getFrameNumberOfLastTraversal ( ) < _frameNumber )
{
// osg::notify(osg::NOTICE)<<"_activePagedLODList : moving PageLOD to inactive list"<<std::endl;
_inactivePagedLODList . push_back ( * active_itr ) ;
remove_plod = true ;
}
if ( remove_plod )
{
PagedLODList : : iterator itr_to_erase = active_itr ;
+ + active_itr ;
_activePagedLODList . erase ( itr_to_erase ) ;
}
else
{
+ + active_itr ;
}
2003-07-21 18:39:07 +08:00
}
2004-09-22 01:26:08 +08:00
unsigned int i = 0 ;
2004-09-22 05:33:52 +08:00
// unsigned int numberOfPagedLODToTest = _inactivePagedLODList.size();
2004-09-23 20:27:56 +08:00
unsigned int targetNumOfInActivePagedLODs = 100 ;
2004-09-22 01:26:08 +08:00
unsigned int targetNumOfRemovedChildPagedLODs = 0 ;
if ( _inactivePagedLODList . size ( ) > targetNumOfInActivePagedLODs ) targetNumOfRemovedChildPagedLODs = _inactivePagedLODList . size ( ) - targetNumOfInActivePagedLODs ;
if ( targetNumOfRemovedChildPagedLODs > 1 ) targetNumOfRemovedChildPagedLODs = 1 ;
// filter out singly referenced PagedLOD and move reactivated PagedLOD into the active list
for ( PagedLODList : : iterator inactive_itr = _inactivePagedLODList . begin ( ) ;
inactive_itr ! = _inactivePagedLODList . end ( ) ;
)
{
const osg : : PagedLOD * plod = inactive_itr - > get ( ) ;
bool remove_plod = false ;
if ( plod - > referenceCount ( ) < = 1 )
{
// prune PageLOD's that are no longer externally referenced
childrenRemoved . push_back ( const_cast < osg : : PagedLOD * > ( plod ) ) ;
//osg::notify(osg::NOTICE)<<"_activePagedLODList : pruning no longer externally referenced"<<std::endl;
remove_plod = true ;
}
else if ( plod - > getFrameNumberOfLastTraversal ( ) > = _frameNumber )
{
// osg::notify(osg::NOTICE)<<"_inactivePagedLODList : moving PageLOD to active list"<<std::endl;
// found a reactivated pagedLOD's need to put it back in the active list.
_activePagedLODList . push_back ( * inactive_itr ) ;
remove_plod = true ;
}
if ( remove_plod )
2004-09-19 03:28:45 +08:00
{
2004-09-22 01:26:08 +08:00
PagedLODList : : iterator itr_to_erase = inactive_itr ;
+ + inactive_itr ;
_inactivePagedLODList . erase ( itr_to_erase ) ;
}
else
{
// if (i<numberOfPagedLODToTest)
if ( childrenRemoved . size ( ) < targetNumOfRemovedChildPagedLODs )
{
// check for removing expired children.
2004-09-24 02:50:38 +08:00
if ( const_cast < osg : : PagedLOD * > ( plod ) - > removeExpiredChildren ( expiryTime , childrenRemoved ) )
2004-09-22 01:26:08 +08:00
{
//osg::notify(osg::NOTICE)<<"Some children removed from PLod"<<std::endl;
}
else
{
// osg::notify(osg::NOTICE)<<"no children removed from PLod"<<std::endl;
}
}
+ + inactive_itr ;
+ + i ;
2004-09-19 03:28:45 +08:00
}
2004-09-22 01:26:08 +08:00
}
//osg::notify(osg::NOTICE)<<"_activePagedLODList.size()="<<_activePagedLODList.size()<<"\t_inactivePagedLODList.size()="<<_inactivePagedLODList.size()<<std::endl;
// osg::notify(osg::NOTICE)<<" number stale "<<numberStale<<" number active "<<_pagedLODList.size()-numberStale<<std::endl;
2004-01-26 22:51:01 +08:00
2004-09-22 01:26:08 +08:00
//double t = osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick());
//osg::notify(osg::NOTICE)<<" time 1 "<<t<<" ms "<<_pagedLODList.size()<<" pagedLOD's"<<std::endl;
//osg::notify(osg::NOTICE)<<" average time = "<<t/(double)_pagedLODList.size()<<" ms/per PagedLOD"<<std::endl;
if ( ! childrenRemoved . empty ( ) )
{
2004-09-19 03:28:45 +08:00
// pass the objects across to the database pager delete list
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _childrenToDeleteListMutex ) ;
for ( osg : : NodeList : : iterator critr = childrenRemoved . begin ( ) ;
critr ! = childrenRemoved . end ( ) ;
+ + critr )
{
_childrenToDeleteList . push_back ( critr - > get ( ) ) ;
}
updateDatabasePagerThreadBlock ( ) ;
}
childrenRemoved . clear ( ) ;
}
2004-01-26 22:51:01 +08:00
2004-09-22 01:26:08 +08:00
// osg::notify(osg::NOTICE)<<" time 2 "<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<" ms "<<std::endl;
2004-01-27 22:49:59 +08:00
2004-09-19 03:28:45 +08:00
if ( osgDB : : Registry : : instance ( ) - > getSharedStateManager ( ) )
osgDB : : Registry : : instance ( ) - > getSharedStateManager ( ) - > prune ( ) ;
2004-01-06 22:09:12 +08:00
// update the Registry object cache.
osgDB : : Registry : : instance ( ) - > updateTimeStampOfObjectsInCacheWithExtenalReferences ( currentFrameTime ) ;
osgDB : : Registry : : instance ( ) - > removeExpiredObjectsInCache ( expiryTime ) ;
2004-09-22 01:26:08 +08:00
// osg::notify(osg::NOTICE)<<"Done DatabasePager::removeExpiredSubgraphs() "<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<" ms "<<std::endl;
2003-07-21 18:39:07 +08:00
}
class FindPagedLODsVisitor : public osg : : NodeVisitor
{
public :
FindPagedLODsVisitor ( DatabasePager : : PagedLODList & pagedLODList ) :
osg : : NodeVisitor ( osg : : NodeVisitor : : TRAVERSE_ALL_CHILDREN ) ,
_pagedLODList ( pagedLODList )
{
}
virtual void apply ( osg : : PagedLOD & plod )
{
2004-09-22 01:26:08 +08:00
_pagedLODList . push_back ( & plod ) ;
2003-07-21 18:39:07 +08:00
traverse ( plod ) ;
}
DatabasePager : : PagedLODList & _pagedLODList ;
} ;
void DatabasePager : : registerPagedLODs ( osg : : Node * subgraph )
{
2004-09-22 01:26:08 +08:00
FindPagedLODsVisitor fplv ( _activePagedLODList ) ;
2003-07-21 18:39:07 +08:00
if ( subgraph ) subgraph - > accept ( fplv ) ;
}
2004-09-24 02:50:38 +08:00
bool DatabasePager : : requiresCompileGLObjects ( ) const
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToCompileListMutex ) ;
return ! _dataToCompileList . empty ( ) ;
}
2004-09-22 05:33:52 +08:00
void DatabasePager : : setCompileGLObjectsForContextID ( unsigned int contextID , bool on )
2003-07-21 18:39:07 +08:00
{
if ( on )
{
_activeGraphicsContexts . insert ( contextID ) ;
}
else
{
_activeGraphicsContexts . erase ( contextID ) ;
}
}
2004-09-22 05:33:52 +08:00
bool DatabasePager : : getCompileGLObjectsForContextID ( unsigned int contextID )
2003-07-21 18:39:07 +08:00
{
return _activeGraphicsContexts . count ( contextID ) ! = 0 ;
}
2004-01-07 05:18:36 +08:00
void DatabasePager : : compileGLObjects ( osg : : State & state , double & availableTime )
2003-07-21 18:39:07 +08:00
{
2004-09-22 01:26:08 +08:00
// osg::notify(osg::NOTICE)<<"DatabasePager::compileGLObjects "<<_frameNumber<<std::endl;
2003-07-21 18:39:07 +08:00
2004-09-24 02:50:38 +08:00
if ( availableTime > 0.0 )
2004-09-20 04:09:54 +08:00
{
2004-09-19 03:28:45 +08:00
2004-09-23 20:27:56 +08:00
const osg : : Timer & timer = * osg : : Timer : : instance ( ) ;
osg : : Timer_t start_tick = timer . tick ( ) ;
double elapsedTime = 0.0 ;
2004-09-24 02:50:38 +08:00
double estimatedTextureDuration = 0.0001 ;
double estimatedDrawableDuration = 0.0001 ;
2004-09-23 20:27:56 +08:00
osg : : ref_ptr < DatabaseRequest > databaseRequest ;
// get the first compileable entry.
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToCompileListMutex ) ;
if ( ! _dataToCompileList . empty ( ) )
2004-09-19 03:28:45 +08:00
{
2004-09-23 20:27:56 +08:00
std : : sort ( _dataToCompileList . begin ( ) , _dataToCompileList . end ( ) , SortFileRequestFunctor ( ) ) ;
DatabaseRequestList : : iterator litr ;
int i = 0 ;
for ( litr = _dataToCompileList . begin ( ) ;
2004-09-27 18:42:14 +08:00
( litr ! = _dataToCompileList . end ( ) ) & & ( _frameNumber - ( * litr ) - > _frameNumberLastRequest ) < = 1 ;
2004-09-23 20:27:56 +08:00
+ + litr , i + + )
2004-09-22 01:26:08 +08:00
{
2004-09-23 20:27:56 +08:00
//osg::notify(osg::NOTICE)<<"Compile "<<_frameNumber-(*litr)->_frameNumberLastRequest<<std::endl;
}
if ( litr ! = _dataToCompileList . end ( ) )
{
if ( _deleteRemovedSubgraphsInDatabaseThread )
2004-09-22 01:26:08 +08:00
{
2004-09-23 20:27:56 +08:00
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _childrenToDeleteListMutex ) ;
for ( DatabaseRequestList : : iterator ditr = litr ;
ditr ! = _dataToCompileList . end ( ) ;
+ + ditr )
{
_childrenToDeleteList . push_back ( ( * ditr ) - > _loadedModel . get ( ) ) ;
}
2004-09-22 01:26:08 +08:00
}
2004-09-23 20:27:56 +08:00
//osg::notify(osg::NOTICE)<<"Pruning "<<_dataToCompileList.size()-i<<std::endl;
_dataToCompileList . erase ( litr , _dataToCompileList . end ( ) ) ;
2004-09-22 01:26:08 +08:00
}
2004-09-19 03:28:45 +08:00
2004-09-23 20:27:56 +08:00
databaseRequest = _dataToCompileList . front ( ) ;
}
} ;
2003-07-21 18:39:07 +08:00
2004-09-23 20:27:56 +08:00
unsigned int numObjectsCompiled = 0 ;
unsigned int maxNumObjectsToCompile = 4 ;
2004-09-22 01:26:08 +08:00
2004-09-23 20:27:56 +08:00
// while there are valid databaseRequest's in the to compile list and there is
// sufficient time left compile each databaseRequest's stateset and drawables.
while ( databaseRequest . valid ( ) & & elapsedTime < availableTime & & numObjectsCompiled < maxNumObjectsToCompile )
2003-07-21 18:39:07 +08:00
{
2004-09-23 20:27:56 +08:00
DataToCompileMap & dcm = databaseRequest - > _dataToCompileMap ;
DataToCompile & dtc = dcm [ state . getContextID ( ) ] ;
if ( ! dtc . first . empty ( ) & & ( elapsedTime + estimatedTextureDuration ) < availableTime & & numObjectsCompiled < maxNumObjectsToCompile )
2003-07-21 18:39:07 +08:00
{
2004-09-19 03:28:45 +08:00
2004-09-23 20:27:56 +08:00
glTexParameterf ( GL_TEXTURE_2D , GL_TEXTURE_PRIORITY , 1.0 ) ;
2004-09-19 03:28:45 +08:00
2004-09-23 20:27:56 +08:00
// we have StateSet's to compile
StateSetList & sslist = dtc . first ;
//osg::notify(osg::INFO)<<"Compiling statesets"<<std::endl;
StateSetList : : iterator itr = sslist . begin ( ) ;
for ( ;
itr ! = sslist . end ( ) & & ( elapsedTime + estimatedTextureDuration ) < availableTime & & numObjectsCompiled < maxNumObjectsToCompile ;
+ + itr )
{
//osg::notify(osg::INFO)<<" Compiling stateset "<<(*itr).get()<<std::endl;
2004-09-19 03:28:45 +08:00
2004-09-23 20:27:56 +08:00
double startCompileTime = timer . delta_s ( start_tick , timer . tick ( ) ) ;
2004-09-19 03:28:45 +08:00
2004-09-23 20:27:56 +08:00
( * itr ) - > compileGLObjects ( state ) ;
2004-09-19 03:28:45 +08:00
2004-09-23 20:27:56 +08:00
GLint p ;
glGetTexParameteriv ( GL_TEXTURE_2D , GL_TEXTURE_RESIDENT , & p ) ;
elapsedTime = timer . delta_s ( start_tick , timer . tick ( ) ) ;
// estimate the duration of the compile based on current compile duration.
estimatedTextureDuration = ( elapsedTime - startCompileTime ) ;
+ + numObjectsCompiled ;
}
// remove the compiled stateset from the list.
sslist . erase ( sslist . begin ( ) , itr ) ;
2003-07-21 18:39:07 +08:00
}
2004-09-23 20:27:56 +08:00
if ( ! dtc . second . empty ( ) & & ( elapsedTime + estimatedDrawableDuration ) < availableTime & & numObjectsCompiled < maxNumObjectsToCompile )
2003-07-21 18:39:07 +08:00
{
2004-09-23 20:27:56 +08:00
// we have Drawable's to compile
//osg::notify(osg::INFO)<<"Compiling drawables"<<std::endl;
DrawableList & dwlist = dtc . second ;
DrawableList : : iterator itr = dwlist . begin ( ) ;
for ( ;
itr ! = dwlist . end ( ) & & ( elapsedTime + estimatedDrawableDuration ) < availableTime & & numObjectsCompiled < maxNumObjectsToCompile ;
+ + itr )
{
//osg::notify(osg::INFO)<<" Compiling drawable "<<(*itr).get()<<std::endl;
double startCompileTime = timer . delta_s ( start_tick , timer . tick ( ) ) ;
( * itr ) - > compileGLObjects ( state ) ;
elapsedTime = timer . delta_s ( start_tick , timer . tick ( ) ) ;
// estimate the duration of the compile based on current compile duration.
estimatedDrawableDuration = ( elapsedTime - startCompileTime ) ;
2004-09-19 03:28:45 +08:00
2004-09-23 20:27:56 +08:00
+ + numObjectsCompiled ;
2004-09-22 01:26:08 +08:00
2004-09-23 20:27:56 +08:00
}
// remove the compiled drawables from the list.
dwlist . erase ( dwlist . begin ( ) , itr ) ;
2003-07-21 18:39:07 +08:00
}
2004-09-23 20:27:56 +08:00
//osg::notify(osg::INFO)<<"Checking if compiled"<<std::endl;
// now check the to compile entries for all active graphics contexts
// to make sure that all have been compiled.
bool allCompiled = true ;
for ( DataToCompileMap : : iterator itr = dcm . begin ( ) ;
itr ! = dcm . end ( ) & & allCompiled ;
+ + itr )
2004-09-20 04:09:54 +08:00
{
2004-09-23 20:27:56 +08:00
if ( ! ( itr - > second . first . empty ( ) ) ) allCompiled = false ;
if ( ! ( itr - > second . second . empty ( ) ) ) allCompiled = false ;
2004-09-20 04:09:54 +08:00
}
2003-07-21 18:39:07 +08:00
2004-09-20 04:09:54 +08:00
2004-09-23 20:27:56 +08:00
if ( allCompiled )
2004-09-20 04:09:54 +08:00
{
2004-09-23 20:27:56 +08:00
// we've compile all of the current databaseRequest so we can now pop it off the
// to compile list and place it on the merge list.
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToCompileListMutex ) ;
{
OpenThreads : : ScopedLock < OpenThreads : : Mutex > lock ( _dataToMergeListMutex ) ;
_dataToMergeList . push_back ( databaseRequest ) ;
}
if ( ! _dataToCompileList . empty ( ) ) _dataToCompileList . erase ( _dataToCompileList . begin ( ) ) ;
if ( ! _dataToCompileList . empty ( ) )
{
std : : sort ( _dataToCompileList . begin ( ) , _dataToCompileList . end ( ) , SortFileRequestFunctor ( ) ) ;
databaseRequest = _dataToCompileList . front ( ) ;
}
else databaseRequest = 0 ;
}
else
{
//osg::notify(osg::INFO)<<"Not all compiled"<<std::endl;
databaseRequest = 0 ;
2004-09-20 04:09:54 +08:00
}
2003-07-21 18:39:07 +08:00
2004-09-23 20:27:56 +08:00
elapsedTime = timer . delta_s ( start_tick , timer . tick ( ) ) ;
2003-07-21 18:39:07 +08:00
}
2004-09-23 20:27:56 +08:00
2004-09-24 02:50:38 +08:00
availableTime - = elapsedTime ;
2004-09-23 20:27:56 +08:00
2004-09-24 02:50:38 +08:00
//osg::notify(osg::NOTICE)<<"elapsedTime="<<elapsedTime<<"\ttime remaining ="<<availableTime<<"\tnumObjectsCompiled = "<<numObjectsCompiled<<std::endl;
2004-09-23 20:27:56 +08:00
//osg::notify(osg::NOTICE)<<"estimatedTextureDuration="<<estimatedTextureDuration;
//osg::notify(osg::NOTICE)<<"\testimatedDrawableDuration="<<estimatedDrawableDuration<<std::endl;
}
else
{
availableTime = 0.0f ;
2003-07-21 18:39:07 +08:00
}
}