From 8d1c97d94b0bc4e8f7f84016c67391c7d6d07e0c Mon Sep 17 00:00:00 2001 From: timoore Date: Mon, 2 Jun 2008 21:10:13 +0000 Subject: [PATCH] Changes for new DatabasePager interface in OSG 2.5.1 --- src/Include/general.hxx | 7 ++--- src/Scenery/SceneryPager.cxx | 57 ++++++++++++++++++++++++++++-------- src/Scenery/SceneryPager.hxx | 53 +++++++++++++++++++++++---------- src/Scenery/tilemgr.cxx | 6 +++- 4 files changed, 89 insertions(+), 34 deletions(-) diff --git a/src/Include/general.hxx b/src/Include/general.hxx index 0001e232e..0db2b8829 100644 --- a/src/Include/general.hxx +++ b/src/Include/general.hxx @@ -31,11 +31,8 @@ # error This library requires C++ #endif -#include - -#define FG_OSG_VERSION \ - ((OPENSCENEGRAPH_MAJOR_VERSION*10000)\ - + (OPENSCENEGRAPH_MINOR_VERSION*1000) + OPENSCENEGRAPH_PATCH_VERSION) +#include +#define FG_OSG_VERSION SG_OSG_VERSION // #define FANCY_FRAME_COUNTER #ifdef FANCY_FRAME_COUNTER diff --git a/src/Scenery/SceneryPager.cxx b/src/Scenery/SceneryPager.cxx index 690cd9395..77aac61c3 100644 --- a/src/Scenery/SceneryPager.cxx +++ b/src/Scenery/SceneryPager.cxx @@ -21,9 +21,8 @@ #include #include +using namespace osg; using namespace flightgear; -using osg::ref_ptr; -using osg::Node; SceneryPager::SceneryPager() { @@ -41,22 +40,42 @@ SceneryPager::~SceneryPager() { } -void SceneryPager::requestNodeFile(const std::string& fileName,osg::Group* group, - float priority, const osg::FrameStamp* framestamp) +void SceneryPager::requestNodeFile(const std::string& fileName, Group* group, + float priority, + const FrameStamp* framestamp, +#ifdef FGOSGPAGER25 + ref_ptr& databaseRequest +#endif + ) { simgear::SGPagedLOD *sgplod = dynamic_cast(group); if(sgplod) - DatabasePager::requestNodeFile(fileName,group,priority,framestamp,sgplod->getReaderWriterOptions()); + DatabasePager::requestNodeFile(fileName, group, priority, framestamp, +#ifdef FGOSGPAGER25 + databaseRequest, +#endif + sgplod->getReaderWriterOptions()); else - DatabasePager::requestNodeFile(fileName,group,priority,framestamp); + DatabasePager::requestNodeFile(fileName, group, priority, framestamp, +#ifdef FGOSGPAGER25 + databaseRequest +#endif + ); } -void SceneryPager::queueRequest(const std::string& fileName, osg::Group* group, - float priority, osg::FrameStamp* frameStamp, +void SceneryPager::queueRequest(const std::string& fileName, Group* group, + float priority, FrameStamp* frameStamp, +#ifdef FGOSGPAGER25 + ref_ptr& databaseRequest, +#endif osgDB::ReaderWriter::Options* options) { _pagerRequests.push_back(PagerRequest(fileName, group, priority, - frameStamp, options)); + frameStamp, +#ifdef FGOSGPAGER25 + databaseRequest, +#endif + options)); } void SceneryPager::queueDeleteRequest(osg::ref_ptr& objptr) @@ -71,11 +90,18 @@ void SceneryPager::signalEndFrame() bool arePagerRequests = false; if (!_deleteRequests.empty()) { areDeleteRequests = true; +#ifdef FGOSGPAGER25 + OpenThreads::ScopedLock + lock(_fileRequestQueue->_childrenToDeleteListMutex); + ObjectList& deleteList = _fileRequestQueue->_childrenToDeleteList; +#else OpenThreads::ScopedLock lock(_childrenToDeleteListMutex); - _childrenToDeleteList.insert(_childrenToDeleteList.end(), - _deleteRequests.begin(), - _deleteRequests.end()); + ObjectList& deleteList = _childrenToDeleteList; +#endif + deleteList.insert(deleteList.end(), + _deleteRequests.begin(), + _deleteRequests.end()); _deleteRequests.clear(); } if (!_pagerRequests.empty()) { @@ -84,8 +110,13 @@ void SceneryPager::signalEndFrame() bind2nd(mem_fun_ref(&PagerRequest::doRequest), this)); _pagerRequests.clear(); } - if (areDeleteRequests && !arePagerRequests) + if (areDeleteRequests && !arePagerRequests) { +#ifdef FGOSGPAGER25 + _fileRequestQueue->updateBlock(); +#else updateDatabasePagerThreadBlock(); +#endif + } DatabasePager::signalEndFrame(); } diff --git a/src/Scenery/SceneryPager.hxx b/src/Scenery/SceneryPager.hxx index 5ec53372c..11bcda889 100644 --- a/src/Scenery/SceneryPager.hxx +++ b/src/Scenery/SceneryPager.hxx @@ -26,6 +26,13 @@ #include #include +#include + +// Pager request change in OpenSceneGraph 2.5.1 +#if SG_OSG_VERSION >= 25001 +#define FGOSGPAGER25 +#endif + namespace flightgear { class SceneryPager : public osgDB::DatabasePager @@ -33,20 +40,22 @@ class SceneryPager : public osgDB::DatabasePager public: SceneryPager(); SceneryPager(const SceneryPager& rhs); - + // Unhide DatabasePager::requestNodeFile + using osgDB::DatabasePager::requestNodeFile; // reimplement to add readerWriterOptions from SGPagedLOD - virtual void requestNodeFile(const std::string& fileName,osg::Group* group, - float priority, const osg::FrameStamp* framestamp); - - virtual void requestNodeFile(const std::string& fileName,osg::Group* group, - float priority, const osg::FrameStamp* framestamp, - osgDB::ReaderWriter::Options* options) { - osgDB::DatabasePager::requestNodeFile(fileName, group, priority, - framestamp, options); - } - + virtual void requestNodeFile(const std::string& fileName, osg::Group* group, + float priority, + const osg::FrameStamp* framestamp, +#ifdef FGOSGPAGER25 + osg::ref_ptr& + databaseRequest +#endif + ); void queueRequest(const std::string& fileName, osg::Group* node, float priority, osg::FrameStamp* frameStamp, +#ifdef FGOSGPAGER25 + osg::ref_ptr& databaseRequest, +#endif osgDB::ReaderWriter::Options* options); // This is passed a ref_ptr so that it can "take ownership" of the // node to delete and decrement its refcount while holding the @@ -57,23 +66,36 @@ protected: // Queue up file requests until the end of the frame struct PagerRequest { - PagerRequest() {} + PagerRequest() : _priority(0.0f), _databaseRequest(0) {} PagerRequest(const PagerRequest& rhs) : _fileName(rhs._fileName), _group(rhs._group), _priority(rhs._priority), _frameStamp(rhs._frameStamp), - _options(rhs._options) {} + _options(rhs._options), _databaseRequest(rhs._databaseRequest) {} PagerRequest(const std::string& fileName, osg::Group* group, float priority, osg::FrameStamp* frameStamp, +#ifdef FGOSGPAGER25 + osg::ref_ptr& databaseRequest, +#endif osgDB::ReaderWriter::Options* options): _fileName(fileName), _group(group), _priority(priority), - _frameStamp(frameStamp), _options(options) {} + _frameStamp(frameStamp), _options(options), +#ifdef FGOSGPAGER25 + _databaseRequest(&databaseRequest) +#else + _databaseRequest(0) +#endif + {} void doRequest(SceneryPager* pager) { if (_group->getNumChildren() == 0) pager->requestNodeFile(_fileName, _group.get(), _priority, - _frameStamp.get(), _options.get()); + _frameStamp.get(), +#ifdef FGOSGPAGER25 + *_databaseRequest, +#endif + _options.get()); } std::string _fileName; @@ -81,6 +103,7 @@ protected: float _priority; osg::ref_ptr _frameStamp; osg::ref_ptr _options; + osg::ref_ptr* _databaseRequest; }; typedef std::vector PagerRequestList; PagerRequestList _pagerRequests; diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index 033bf2d5b..c7965719a 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -279,7 +279,11 @@ public: _pager->queueRequest(entry->tileFileName, entry->getNode(), entry->get_inner_ring() ? 10.0f : 1.0f, - _framestamp, _options); + _framestamp, +#ifdef FGOSGPAGER25 + entry->getDatabaseRequest(), +#endif + _options); } } private: