Moved the updating and expiry of the Registry object cache from DatabasePager into osgViewer::Viewer/CompositeViewer.
This commit is contained in:
parent
2f3dfc4349
commit
df9385ac19
@ -418,18 +418,21 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
* for that object in the cache to specified time.
|
||||
* This would typically be called once per frame by applications which are doing database paging,
|
||||
* and need to prune objects that are no longer required.
|
||||
* Time value is time in seconds.*/
|
||||
void updateTimeStampOfObjectsInCacheWithExternalReferences(double currentTime);
|
||||
* The time used is taken from the FrameStamp::getReferenceTime().*/
|
||||
void updateTimeStampOfObjectsInCacheWithExternalReferences(const osg::FrameStamp& frameStamp);
|
||||
|
||||
/** Removed object in the cache which have a time stamp at or before the specified expiry time.
|
||||
* This would typically be called once per frame by applications which are doing database paging,
|
||||
* and need to prune objects that are no longer required, and called after the a called
|
||||
* after the call to updateTimeStampOfObjectsInCacheWithExternalReferences(currentTime).
|
||||
* Note, the currentTime is not the expiryTime, one would typically set the expiry time
|
||||
* to a fixed amount of time before currentTime, such as expiryTime = currentTime-10.0.
|
||||
* Time value is time in seconds.*/
|
||||
void removeExpiredObjectsInCache(double expiryTime);
|
||||
|
||||
* after the call to updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp).*/
|
||||
void removeExpiredObjectsInCache(const osg::FrameStamp& frameStamp);
|
||||
|
||||
/** set hint to viewer code calling removeExpiredObjectsInCache to specify how long it should give before expiring objects in Registry cache,*/
|
||||
void setExpiryDelay(double expiryDelay) { _expiryDelay = expiryDelay; }
|
||||
|
||||
double getExpiryDelay() const { return _expiryDelay; }
|
||||
|
||||
|
||||
/** Remove all objects in the cache regardless of having external references or expiry times.*/
|
||||
void clearObjectCache();
|
||||
|
||||
@ -599,6 +602,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
FilePathList _dataFilePath;
|
||||
FilePathList _libraryFilePath;
|
||||
|
||||
double _expiryDelay;
|
||||
ObjectCache _objectCache;
|
||||
OpenThreads::Mutex _objectCacheMutex;
|
||||
|
||||
|
@ -39,11 +39,12 @@ class OSGVIEWER_EXPORT Scene : public osg::Referenced
|
||||
osgDB::DatabasePager* getDatabasePager() { return _databasePager.get(); }
|
||||
const osgDB::DatabasePager* getDatabasePager() const { return _databasePager.get(); }
|
||||
|
||||
|
||||
void setImagePager(osgDB::ImagePager* ip);
|
||||
osgDB::ImagePager* getImagePager() { return _imagePager.get(); }
|
||||
const osgDB::ImagePager* getImagePager() const { return _imagePager.get(); }
|
||||
|
||||
void updateSceneGraph(osg::NodeVisitor& updateVisitor);
|
||||
|
||||
|
||||
/** Get the Scene object that has the specified node assigned to it.
|
||||
* return 0 if no Scene has yet been assigned the specified node.*/
|
||||
|
@ -908,14 +908,14 @@ DatabasePager::DatabasePager()
|
||||
if( (ptr = getenv("OSG_EXPIRY_DELAY")) != 0)
|
||||
{
|
||||
_expiryDelay = osg::asciiToDouble(ptr);
|
||||
osg::notify(osg::NOTICE)<<"Expiry delay = "<<_expiryDelay<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"DatabasePager: Expiry delay = "<<_expiryDelay<<std::endl;
|
||||
}
|
||||
|
||||
_expiryFrames = 1; // Last frame will not be expired
|
||||
if( (ptr = getenv("OSG_EXPIRY_FRAMES")) != 0)
|
||||
{
|
||||
_expiryFrames = atoi(ptr);
|
||||
osg::notify(osg::NOTICE)<<"Expiry frames = "<<_expiryFrames<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"DatabasePager: Expiry frames = "<<_expiryFrames<<std::endl;
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_RELEASE_DELAY")) != 0)
|
||||
@ -929,7 +929,7 @@ DatabasePager::DatabasePager()
|
||||
setReleaseDelay(osg::asciiToDouble(ptr));
|
||||
}
|
||||
|
||||
osg::notify(osg::NOTICE)<<"Release delay = "<<_releaseDelay<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"DatabasePager: Release delay = "<<_releaseDelay<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1781,14 +1781,6 @@ void DatabasePager::capped_removeExpiredSubgraphs(const osg::FrameStamp& frameSt
|
||||
" A="<<time_a<<" avg="<<s_total_time_stage_a/s_total_iter_stage_a<<" max = "<<s_total_max_stage_a<<
|
||||
" B="<<time_b<<" avg="<<s_total_time_stage_b/s_total_iter_stage_b<<" max = "<<s_total_max_stage_b<<
|
||||
" C="<<time_c<<" avg="<<s_total_time_stage_c/s_total_iter_stage_c<<" max = "<<s_total_max_stage_c<<std::endl;
|
||||
|
||||
|
||||
if (osgDB::Registry::instance()->getSharedStateManager())
|
||||
osgDB::Registry::instance()->getSharedStateManager()->prune();
|
||||
|
||||
// update the Registry object cache.
|
||||
osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp.getReferenceTime());
|
||||
osgDB::Registry::instance()->removeExpiredObjectsInCache(expiryTime);
|
||||
}
|
||||
|
||||
void DatabasePager::expiry_removeExpiredSubgraphs(const osg::FrameStamp& frameStamp)
|
||||
@ -1883,16 +1875,6 @@ void DatabasePager::expiry_removeExpiredSubgraphs(const osg::FrameStamp& frameSt
|
||||
|
||||
osg::notify(osg::INFO)<<"_activePagedLODList.size()="<<_activePagedLODList.size()<<" overall = "<<time<<
|
||||
" avg="<<s_total_time/s_total_iter<<" max = "<<s_total_max<<std::endl;
|
||||
|
||||
|
||||
if (osgDB::Registry::instance()->getSharedStateManager())
|
||||
osgDB::Registry::instance()->getSharedStateManager()->prune();
|
||||
|
||||
// update the Registry object cache.
|
||||
osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp.getReferenceTime());
|
||||
osgDB::Registry::instance()->removeExpiredObjectsInCache(expiryTime);
|
||||
|
||||
|
||||
}
|
||||
|
||||
class DatabasePager::FindPagedLODsVisitor : public osg::NodeVisitor
|
||||
|
@ -187,6 +187,15 @@ Registry::Registry()
|
||||
else _buildKdTreesHint = Options::BUILD_KDTREES;
|
||||
}
|
||||
|
||||
const char* ptr=0;
|
||||
|
||||
_expiryDelay = 10.0;
|
||||
if( (ptr = getenv("OSG_EXPIRY_DELAY")) != 0)
|
||||
{
|
||||
_expiryDelay = osg::asciiToDouble(ptr);
|
||||
osg::notify(osg::INFO)<<"Registry : Expiry delay = "<<_expiryDelay<<std::endl;
|
||||
}
|
||||
|
||||
const char* fileCachePath = getenv("OSG_FILE_CACHE");
|
||||
if (fileCachePath)
|
||||
{
|
||||
@ -2104,7 +2113,7 @@ osg::Object* Registry::getFromObjectCache(const std::string& fileName)
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(double currentTime)
|
||||
void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(const osg::FrameStamp& frameStamp)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||
|
||||
@ -2117,13 +2126,15 @@ void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(double curr
|
||||
if (itr->second.first->referenceCount()>1)
|
||||
{
|
||||
// so update it time stamp.
|
||||
itr->second.second = currentTime;
|
||||
itr->second.second = frameStamp.getReferenceTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Registry::removeExpiredObjectsInCache(double expiryTime)
|
||||
void Registry::removeExpiredObjectsInCache(const osg::FrameStamp& frameStamp)
|
||||
{
|
||||
double expiryTime = frameStamp.getReferenceTime() - _expiryDelay;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||
|
||||
typedef std::vector<std::string> ObjectsToRemove;
|
||||
|
@ -1037,27 +1037,18 @@ void CompositeViewer::updateTraversal()
|
||||
++sitr)
|
||||
{
|
||||
Scene* scene = *sitr;
|
||||
if (scene->getSceneData())
|
||||
{
|
||||
_updateVisitor->setImageRequestHandler(scene->getImagePager());
|
||||
|
||||
scene->getSceneData()->accept(*_updateVisitor);
|
||||
}
|
||||
|
||||
if (scene->getDatabasePager())
|
||||
{
|
||||
// synchronize changes required by the DatabasePager thread to the scene graph
|
||||
scene->getDatabasePager()->updateSceneGraph(*_frameStamp);
|
||||
}
|
||||
|
||||
if (scene->getImagePager())
|
||||
{
|
||||
// synchronize changes required by the DatabasePager thread to the scene graph
|
||||
scene->getImagePager()->updateSceneGraph(*_frameStamp);
|
||||
}
|
||||
|
||||
scene->updateSceneGraph(*_updateVisitor);
|
||||
}
|
||||
|
||||
// if we have a shared state manager prune any unused entries
|
||||
if (osgDB::Registry::instance()->getSharedStateManager())
|
||||
osgDB::Registry::instance()->getSharedStateManager()->prune();
|
||||
|
||||
// update the Registry object cache.
|
||||
osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(*getFrameStamp());
|
||||
osgDB::Registry::instance()->removeExpiredObjectsInCache(*getFrameStamp());
|
||||
|
||||
|
||||
if (_incrementalCompileOperation.valid())
|
||||
{
|
||||
// merge subgraphs that have been compiled by the incremental compiler operation.
|
||||
|
@ -77,6 +77,31 @@ void Scene::setImagePager(osgDB::ImagePager* ip)
|
||||
_imagePager = ip;
|
||||
}
|
||||
|
||||
void Scene::updateSceneGraph(osg::NodeVisitor& updateVisitor)
|
||||
{
|
||||
if (!_sceneData) return;
|
||||
|
||||
if (getSceneData())
|
||||
{
|
||||
updateVisitor.setImageRequestHandler(getImagePager());
|
||||
getSceneData()->accept(updateVisitor);
|
||||
}
|
||||
|
||||
if (getDatabasePager())
|
||||
{
|
||||
// synchronize changes required by the DatabasePager thread to the scene graph
|
||||
getDatabasePager()->updateSceneGraph((*updateVisitor.getFrameStamp()));
|
||||
}
|
||||
|
||||
if (getImagePager())
|
||||
{
|
||||
// synchronize changes required by the DatabasePager thread to the scene graph
|
||||
getImagePager()->updateSceneGraph(*(updateVisitor.getFrameStamp()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Scene* Scene::getScene(osg::Node* node)
|
||||
{
|
||||
|
@ -924,29 +924,22 @@ void Viewer::updateTraversal()
|
||||
_updateVisitor->setFrameStamp(getFrameStamp());
|
||||
_updateVisitor->setTraversalNumber(getFrameStamp()->getFrameNumber());
|
||||
|
||||
if (getSceneData())
|
||||
{
|
||||
_updateVisitor->setImageRequestHandler(_scene->getImagePager());
|
||||
getSceneData()->accept(*_updateVisitor);
|
||||
}
|
||||
|
||||
if (_scene->getDatabasePager())
|
||||
{
|
||||
// synchronize changes required by the DatabasePager thread to the scene graph
|
||||
_scene->getDatabasePager()->updateSceneGraph(*_frameStamp);
|
||||
}
|
||||
_scene->updateSceneGraph(*_updateVisitor);
|
||||
|
||||
// if we have a shared state manager prune any unused entries
|
||||
if (osgDB::Registry::instance()->getSharedStateManager())
|
||||
osgDB::Registry::instance()->getSharedStateManager()->prune();
|
||||
|
||||
// update the Registry object cache.
|
||||
osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(*getFrameStamp());
|
||||
osgDB::Registry::instance()->removeExpiredObjectsInCache(*getFrameStamp());
|
||||
|
||||
if (_scene->getImagePager())
|
||||
{
|
||||
// synchronize changes required by the DatabasePager thread to the scene graph
|
||||
_scene->getImagePager()->updateSceneGraph(*_frameStamp);
|
||||
}
|
||||
|
||||
if (_updateOperations.valid())
|
||||
{
|
||||
_updateOperations->runOperations(this);
|
||||
}
|
||||
|
||||
|
||||
if (_incrementalCompileOperation.valid())
|
||||
{
|
||||
// merge subgraphs that have been compiled by the incremental compiler operation.
|
||||
|
Loading…
Reference in New Issue
Block a user