diff --git a/include/osgDB/Registry b/include/osgDB/Registry index 019745488..f07f58d2f 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -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; diff --git a/include/osgViewer/Scene b/include/osgViewer/Scene index e2c73a489..51ecf4c97 100644 --- a/include/osgViewer/Scene +++ b/include/osgViewer/Scene @@ -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.*/ diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 8672200a5..6f58822b9 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -908,14 +908,14 @@ DatabasePager::DatabasePager() if( (ptr = getenv("OSG_EXPIRY_DELAY")) != 0) { _expiryDelay = osg::asciiToDouble(ptr); - osg::notify(osg::NOTICE)<<"Expiry delay = "<<_expiryDelay< 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 lock(_objectCacheMutex); typedef std::vector ObjectsToRemove; diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index c52067c4c..5d3db92fd 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -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. diff --git a/src/osgViewer/Scene.cpp b/src/osgViewer/Scene.cpp index 7d6df49d0..d5ed8f6ce 100644 --- a/src/osgViewer/Scene.cpp +++ b/src/osgViewer/Scene.cpp @@ -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) { diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 1968a15b8..5a5cb1292 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -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.