Changeset 10520

Show
Ignore:
Timestamp:
08/05/09 13:06:53 (5 years ago)
Author:
robert
Message:

Moved the updating and expiry of the Registry object cache from DatabasePager? into osgViewer::Viewer/CompositeViewer.

Location:
OpenSceneGraph/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgDB/Registry

    r10227 r10520  
    419419          * This would typically be called once per frame by applications which are doing database paging, 
    420420          * and need to prune objects that are no longer required. 
    421           * Time value is time in seconds.*/ 
    422         void updateTimeStampOfObjectsInCacheWithExternalReferences(double currentTime); 
     421          * The time used is taken from the FrameStamp::getReferenceTime().*/ 
     422        void updateTimeStampOfObjectsInCacheWithExternalReferences(const osg::FrameStamp& frameStamp); 
    423423 
    424424        /** Removed object in the cache which have a time stamp at or before the specified expiry time. 
    425425          * This would typically be called once per frame by applications which are doing database paging, 
    426426          * and need to prune objects that are no longer required, and called after the a called 
    427           * after the call to updateTimeStampOfObjectsInCacheWithExternalReferences(currentTime).  
    428           * Note, the currentTime is not the expiryTime, one would typically set the expiry time 
    429           * to a fixed amount of time before currentTime, such as expiryTime = currentTime-10.0. 
    430           * Time value is time in seconds.*/ 
    431         void removeExpiredObjectsInCache(double expiryTime); 
    432          
     427          * after the call to updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp).*/ 
     428        void removeExpiredObjectsInCache(const osg::FrameStamp& frameStamp); 
     429 
     430        /** set hint to viewer code calling removeExpiredObjectsInCache to specify how long it should give before expiring objects in Registry cache,*/ 
     431        void setExpiryDelay(double expiryDelay) { _expiryDelay = expiryDelay; } 
     432 
     433        double getExpiryDelay() const { return _expiryDelay; } 
     434 
     435 
    433436        /** Remove all objects in the cache regardless of having external references or expiry times.*/  
    434437        void clearObjectCache(); 
     
    600603        FilePathList                            _libraryFilePath; 
    601604 
     605        double                                  _expiryDelay; 
    602606        ObjectCache                             _objectCache; 
    603607        OpenThreads::Mutex                      _objectCacheMutex; 
  • OpenSceneGraph/trunk/include/osgViewer/Scene

    r8633 r10520  
    4040        const osgDB::DatabasePager* getDatabasePager() const { return _databasePager.get(); } 
    4141 
    42  
    4342        void setImagePager(osgDB::ImagePager* ip); 
    4443        osgDB::ImagePager* getImagePager() { return _imagePager.get(); } 
    4544        const osgDB::ImagePager* getImagePager() const { return _imagePager.get(); } 
     45 
     46        void updateSceneGraph(osg::NodeVisitor& updateVisitor); 
    4647 
    4748 
  • OpenSceneGraph/trunk/src/osgDB/DatabasePager.cpp

    r10473 r10520  
    909909    { 
    910910        _expiryDelay = osg::asciiToDouble(ptr); 
    911         osg::notify(osg::NOTICE)<<"Expiry delay = "<<_expiryDelay<<std::endl; 
     911        osg::notify(osg::NOTICE)<<"DatabasePager: Expiry delay = "<<_expiryDelay<<std::endl; 
    912912    } 
    913913 
     
    916916    { 
    917917        _expiryFrames = atoi(ptr); 
    918         osg::notify(osg::NOTICE)<<"Expiry frames = "<<_expiryFrames<<std::endl; 
     918        osg::notify(osg::NOTICE)<<"DatabasePager: Expiry frames = "<<_expiryFrames<<std::endl; 
    919919    } 
    920920 
     
    930930        } 
    931931             
    932         osg::notify(osg::NOTICE)<<"Release delay = "<<_releaseDelay<<std::endl; 
     932        osg::notify(osg::NOTICE)<<"DatabasePager: Release delay = "<<_releaseDelay<<std::endl; 
    933933    } 
    934934    else 
     
    17821782                              " B="<<time_b<<" avg="<<s_total_time_stage_b/s_total_iter_stage_b<<" max = "<<s_total_max_stage_b<< 
    17831783                              " C="<<time_c<<" avg="<<s_total_time_stage_c/s_total_iter_stage_c<<" max = "<<s_total_max_stage_c<<std::endl; 
    1784  
    1785      
    1786     if (osgDB::Registry::instance()->getSharedStateManager())  
    1787         osgDB::Registry::instance()->getSharedStateManager()->prune(); 
    1788  
    1789     // update the Registry object cache. 
    1790     osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp.getReferenceTime()); 
    1791     osgDB::Registry::instance()->removeExpiredObjectsInCache(expiryTime); 
    17921784} 
    17931785 
     
    18841876    osg::notify(osg::INFO)<<"_activePagedLODList.size()="<<_activePagedLODList.size()<<" overall = "<<time<< 
    18851877                              " avg="<<s_total_time/s_total_iter<<" max = "<<s_total_max<<std::endl; 
    1886       
    1887     
    1888     if (osgDB::Registry::instance()->getSharedStateManager())  
    1889         osgDB::Registry::instance()->getSharedStateManager()->prune(); 
    1890  
    1891     // update the Registry object cache. 
    1892     osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp.getReferenceTime()); 
    1893     osgDB::Registry::instance()->removeExpiredObjectsInCache(expiryTime); 
    1894  
    1895  
    18961878} 
    18971879 
  • OpenSceneGraph/trunk/src/osgDB/Registry.cpp

    r10356 r10520  
    186186        if (switchOff) _buildKdTreesHint = Options::DO_NOT_BUILD_KDTREES; 
    187187        else _buildKdTreesHint = Options::BUILD_KDTREES; 
     188    } 
     189 
     190    const char* ptr=0; 
     191 
     192    _expiryDelay = 10.0; 
     193    if( (ptr = getenv("OSG_EXPIRY_DELAY")) != 0) 
     194    { 
     195        _expiryDelay = osg::asciiToDouble(ptr); 
     196        osg::notify(osg::INFO)<<"Registry : Expiry delay = "<<_expiryDelay<<std::endl; 
    188197    } 
    189198 
     
    21052114} 
    21062115 
    2107 void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(double currentTime) 
     2116void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(const osg::FrameStamp& frameStamp) 
    21082117{ 
    21092118    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); 
     
    21182127        { 
    21192128            // so update it time stamp. 
    2120             itr->second.second = currentTime; 
    2121         } 
    2122     } 
    2123 } 
    2124  
    2125 void Registry::removeExpiredObjectsInCache(double expiryTime) 
    2126 { 
     2129            itr->second.second = frameStamp.getReferenceTime(); 
     2130        } 
     2131    } 
     2132} 
     2133 
     2134void Registry::removeExpiredObjectsInCache(const osg::FrameStamp& frameStamp) 
     2135{ 
     2136    double expiryTime = frameStamp.getReferenceTime() - _expiryDelay; 
     2137 
    21272138    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); 
    21282139 
  • OpenSceneGraph/trunk/src/osgViewer/CompositeViewer.cpp

    r10365 r10520  
    10381038    { 
    10391039        Scene* scene = *sitr; 
    1040         if (scene->getSceneData()) 
    1041         { 
    1042             _updateVisitor->setImageRequestHandler(scene->getImagePager()); 
    1043              
    1044             scene->getSceneData()->accept(*_updateVisitor); 
    1045         } 
    1046  
    1047         if (scene->getDatabasePager()) 
    1048         {     
    1049             // synchronize changes required by the DatabasePager thread to the scene graph 
    1050             scene->getDatabasePager()->updateSceneGraph(*_frameStamp); 
    1051         } 
    1052  
    1053         if (scene->getImagePager()) 
    1054         {     
    1055             // synchronize changes required by the DatabasePager thread to the scene graph 
    1056             scene->getImagePager()->updateSceneGraph(*_frameStamp); 
    1057         } 
    1058  
    1059     } 
     1040        scene->updateSceneGraph(*_updateVisitor); 
     1041    } 
     1042 
     1043    // if we have a shared state manager prune any unused entries 
     1044    if (osgDB::Registry::instance()->getSharedStateManager()) 
     1045        osgDB::Registry::instance()->getSharedStateManager()->prune(); 
     1046 
     1047    // update the Registry object cache. 
     1048    osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(*getFrameStamp()); 
     1049    osgDB::Registry::instance()->removeExpiredObjectsInCache(*getFrameStamp()); 
     1050 
    10601051 
    10611052    if (_incrementalCompileOperation.valid()) 
  • OpenSceneGraph/trunk/src/osgViewer/Scene.cpp

    r8633 r10520  
    7878} 
    7979 
     80void Scene::updateSceneGraph(osg::NodeVisitor& updateVisitor) 
     81{ 
     82    if (!_sceneData) return; 
     83 
     84    if (getSceneData()) 
     85    { 
     86        updateVisitor.setImageRequestHandler(getImagePager()); 
     87        getSceneData()->accept(updateVisitor); 
     88    } 
     89 
     90    if (getDatabasePager()) 
     91    { 
     92        // synchronize changes required by the DatabasePager thread to the scene graph 
     93        getDatabasePager()->updateSceneGraph((*updateVisitor.getFrameStamp())); 
     94    } 
     95 
     96    if (getImagePager()) 
     97    { 
     98        // synchronize changes required by the DatabasePager thread to the scene graph 
     99        getImagePager()->updateSceneGraph(*(updateVisitor.getFrameStamp())); 
     100    } 
     101 
     102 
     103} 
     104 
    80105 
    81106Scene* Scene::getScene(osg::Node* node) 
  • OpenSceneGraph/trunk/src/osgViewer/Viewer.cpp

    r10365 r10520  
    925925    _updateVisitor->setTraversalNumber(getFrameStamp()->getFrameNumber()); 
    926926 
    927     if (getSceneData()) 
    928     { 
    929         _updateVisitor->setImageRequestHandler(_scene->getImagePager()); 
    930         getSceneData()->accept(*_updateVisitor); 
    931     } 
    932      
    933     if (_scene->getDatabasePager()) 
    934     {     
    935         // synchronize changes required by the DatabasePager thread to the scene graph 
    936         _scene->getDatabasePager()->updateSceneGraph(*_frameStamp); 
    937     } 
    938  
    939     if (_scene->getImagePager()) 
    940     {     
    941         // synchronize changes required by the DatabasePager thread to the scene graph 
    942         _scene->getImagePager()->updateSceneGraph(*_frameStamp); 
    943     } 
     927    _scene->updateSceneGraph(*_updateVisitor); 
     928 
     929    // if we have a shared state manager prune any unused entries 
     930    if (osgDB::Registry::instance()->getSharedStateManager()) 
     931        osgDB::Registry::instance()->getSharedStateManager()->prune(); 
     932 
     933    // update the Registry object cache. 
     934    osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(*getFrameStamp()); 
     935    osgDB::Registry::instance()->removeExpiredObjectsInCache(*getFrameStamp()); 
     936 
    944937 
    945938    if (_updateOperations.valid()) 
     
    947940        _updateOperations->runOperations(this); 
    948941    } 
    949      
     942 
    950943    if (_incrementalCompileOperation.valid()) 
    951944    {