Skip to content

Commit

Permalink
Fixed cirular reference in DatabaseRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed May 30, 2008
1 parent f07d106 commit 0cc3810
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion include/osg/PagedLOD
Expand Up @@ -121,7 +121,7 @@ class OSG_EXPORT PagedLOD : public LOD

protected :

virtual ~PagedLOD() {}
virtual ~PagedLOD();

void expandPerRangeDataTo(unsigned int pos);

Expand Down
22 changes: 11 additions & 11 deletions include/osgDB/DatabasePager
Expand Up @@ -324,17 +324,17 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
_numOfRequests(0)
{}

std::string _fileName;
int _frameNumberFirstRequest;
double _timestampFirstRequest;
float _priorityFirstRequest;
int _frameNumberLastRequest;
double _timestampLastRequest;
float _priorityLastRequest;
unsigned int _numOfRequests;
osg::ref_ptr<osg::Group> _groupForAddingLoadedSubgraph;
osg::ref_ptr<osg::Node> _loadedModel;
DataToCompileMap _dataToCompileMap;
std::string _fileName;
int _frameNumberFirstRequest;
double _timestampFirstRequest;
float _priorityFirstRequest;
int _frameNumberLastRequest;
double _timestampLastRequest;
float _priorityLastRequest;
unsigned int _numOfRequests;
osg::observer_ptr<osg::Group> _groupForAddingLoadedSubgraph;
osg::ref_ptr<osg::Node> _loadedModel;
DataToCompileMap _dataToCompileMap;
osg::ref_ptr<ReaderWriter::Options> _loadOptions;

bool isRequestCurrent (int frameNumber) const
Expand Down
4 changes: 4 additions & 0 deletions src/osg/PagedLOD.cpp
Expand Up @@ -59,6 +59,10 @@ PagedLOD::PagedLOD(const PagedLOD& plod,const CopyOp& copyop):
{
}

PagedLOD::~PagedLOD()
{
}

void PagedLOD::setDatabasePath(const std::string& path)
{
_databasePath = path;
Expand Down
70 changes: 41 additions & 29 deletions src/osgDB/DatabasePager.cpp
Expand Up @@ -397,7 +397,7 @@ void DatabasePager::DatabaseThread::run()
//
// delete any children if required.
//
if (_pager->_deleteRemovedSubgraphsInDatabaseThread)
if (_pager->_deleteRemovedSubgraphsInDatabaseThread && !(read_queue->_childrenToDeleteList.empty()))
{
ObjectList deleteList;

Expand Down Expand Up @@ -557,12 +557,22 @@ void DatabasePager::DatabaseThread::run()
osg::notify(osg::INFO)<<_name<<": Warning DatabaseRquest no longer required."<<std::endl;
databaseRequest->_loadedModel = 0;
}

osg::ref_ptr<osg::Group> groupForAddingLoadedSubgraph = databaseRequest->_groupForAddingLoadedSubgraph.get();

if (!groupForAddingLoadedSubgraph)
{
osg::notify(osg::INFO)<<_name<<": Warning parent of loaded subgraph, deleted."<<std::endl;
databaseRequest->_loadedModel = 0;
}

//osg::notify(osg::NOTICE)<<" node read in "<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<" ms"<<std::endl;

bool loadedObjectsNeedToBeCompiled = false;

if (_pager->_doPreCompile && databaseRequest->_loadedModel.valid() && !_pager->_activeGraphicsContexts.empty())
if (_pager->_doPreCompile &&
databaseRequest->_loadedModel.valid() &&
!_pager->_activeGraphicsContexts.empty())
{
// 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.
Expand All @@ -582,7 +592,7 @@ void DatabasePager::DatabaseThread::run()

// push the soon to be parent on the nodepath of the NodeVisitor so that
// during traversal one can test for where it'll be in the overall scene graph
osg::NodePathList nodePathList = databaseRequest->_groupForAddingLoadedSubgraph->getParentalNodePaths();
osg::NodePathList nodePathList = groupForAddingLoadedSubgraph->getParentalNodePaths();
if (!nodePathList.empty())
{
osg::NodePath& nodePath = nodePathList.front();
Expand All @@ -594,7 +604,7 @@ void DatabasePager::DatabaseThread::run()
}
}

frov.pushOntoNodePath(databaseRequest->_groupForAddingLoadedSubgraph.get());
frov.pushOntoNodePath(groupForAddingLoadedSubgraph.get());

databaseRequest->_loadedModel->accept(frov);

Expand Down Expand Up @@ -1182,35 +1192,37 @@ void DatabasePager::addLoadedDataToSceneGraph(double timeStamp)

registerPagedLODs(databaseRequest->_loadedModel.get());

osg::Group* group = databaseRequest->_groupForAddingLoadedSubgraph.get();

osg::PagedLOD* plod = dynamic_cast<osg::PagedLOD*>(group);
if (plod)
osg::ref_ptr<osg::Group> group = databaseRequest->_groupForAddingLoadedSubgraph.get();
if (group.valid())
{
plod->setTimeStamp(plod->getNumChildren(),timeStamp);
plod->getDatabaseRequest(plod->getNumChildren()) = 0;
}
else
{
osg::ProxyNode* proxyNode = dynamic_cast<osg::ProxyNode*>(group);
if (proxyNode)
osg::PagedLOD* plod = dynamic_cast<osg::PagedLOD*>(group.get());
if (plod)
{
proxyNode->getDatabaseRequest(proxyNode->getNumChildren()) = 0;
}
}

group->addChild(databaseRequest->_loadedModel.get());
plod->setTimeStamp(plod->getNumChildren(),timeStamp);
plod->getDatabaseRequest(plod->getNumChildren()) = 0;
}
else
{
osg::ProxyNode* proxyNode = dynamic_cast<osg::ProxyNode*>(group.get());
if (proxyNode)
{
proxyNode->getDatabaseRequest(proxyNode->getNumChildren()) = 0;
}
}

osg::notify(osg::INFO)<<"merged subgraph"<<databaseRequest->_fileName<<" after "<<databaseRequest->_numOfRequests<<" requests and time="<<(timeStamp-databaseRequest->_timestampFirstRequest)*1000.0<<std::endl;

double timeToMerge = timeStamp-databaseRequest->_timestampFirstRequest;
group->addChild(databaseRequest->_loadedModel.get());

if (timeToMerge<_minimumTimeToMergeTile) _minimumTimeToMergeTile = timeToMerge;
if (timeToMerge>_maximumTimeToMergeTile) _maximumTimeToMergeTile = timeToMerge;

_totalTimeToMergeTiles += timeToMerge;
++_numTilesMerges;

osg::notify(osg::INFO)<<"merged subgraph"<<databaseRequest->_fileName<<" after "<<databaseRequest->_numOfRequests<<" requests and time="<<(timeStamp-databaseRequest->_timestampFirstRequest)*1000.0<<std::endl;

double timeToMerge = timeStamp-databaseRequest->_timestampFirstRequest;

if (timeToMerge<_minimumTimeToMergeTile) _minimumTimeToMergeTile = timeToMerge;
if (timeToMerge>_maximumTimeToMergeTile) _maximumTimeToMergeTile = timeToMerge;

_totalTimeToMergeTiles += timeToMerge;
++_numTilesMerges;
}

// reset the loadedModel pointer
databaseRequest->_loadedModel = 0;

Expand Down

0 comments on commit 0cc3810

Please sign in to comment.