From df6badfdd5fb1a07679c738376dfe86005694624 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Tue, 15 Feb 2011 12:28:03 +0100 Subject: [PATCH] accomodate changes to osgDB::DatabasePager interface The change was introduced in OSG SVN revision 12080. Note: that revision has a bug that causes fgfs to crash. The bug is fixed in revision 12170. --- simgear/scene/model/CheckSceneryVisitor.cxx | 2 +- simgear/scene/model/SGPagedLOD.cxx | 39 ++++++++----------- simgear/scene/model/SGPagedLOD.hxx | 24 +++++++++--- .../scene/tgdb/SGReaderWriterBTGOptions.hxx | 1 + 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/simgear/scene/model/CheckSceneryVisitor.cxx b/simgear/scene/model/CheckSceneryVisitor.cxx index a21f103b..4a0625bc 100644 --- a/simgear/scene/model/CheckSceneryVisitor.cxx +++ b/simgear/scene/model/CheckSceneryVisitor.cxx @@ -54,7 +54,7 @@ void CheckSceneryVisitor::apply(osg::PagedLOD& node) // if the DatabasePager would load LODs while the splashscreen // is there, we could just wait for the models to be loaded // by only setting setLoaded(false) here - sgplod->forceLoad(_dbp,_framestamp); + sgplod->forceLoad(_dbp,_framestamp, getNodePath()); setLoaded(false); } } diff --git a/simgear/scene/model/SGPagedLOD.cxx b/simgear/scene/model/SGPagedLOD.cxx index 02b187ea..531b45b0 100644 --- a/simgear/scene/model/SGPagedLOD.cxx +++ b/simgear/scene/model/SGPagedLOD.cxx @@ -61,37 +61,30 @@ bool SGPagedLOD::addChild(osg::Node *child) return true; } -void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, osg::FrameStamp* framestamp) +// Work around interface change in osgDB::DatabasePager::requestNodeFile +struct NodePathProxy +{ + NodePathProxy(NodePath& nodePath) + : _nodePath(nodePath) + { + } + operator Group* () { return static_cast(_nodePath.back()); } + operator NodePath& () { return _nodePath; } + NodePath& _nodePath; +}; + +void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, FrameStamp* framestamp, + NodePath& path) { //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::forceLoad(" << //getFileName(getNumChildren()) << ")"); unsigned childNum = getNumChildren(); setTimeStamp(childNum, 0); double priority=1.0; -#if SG_OSG_MIN_VERSION_REQUIRED(2,9,11) - // osgDB::DatabasePager::requestNodeFile changed with OSG 2.9.11 - - #ifdef __GNUC__ - #warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - #warning !! Your version of OpenSceneGraph is currently unsupported. - #warning !! Use latest stable OSG (2.8.3) or a OSG developer release up to 2.9.10. - #warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - #else - // Alas! Why is MSVC different (again)? :) - #pragma WARNING( Your version of OpenSceneGraph is currently unsupported. ) - #pragma WARNING( Use latest stable OSG (2.8.3) or a OSG developer release up to 2.9.10. ) - #endif - - //TODO We need to adapt to OSG 2.9.11 (and future releases). This doesn't work yet... - dbp->requestNodeFile(getFileName(childNum),this,priority,framestamp, + dbp->requestNodeFile(getFileName(childNum), NodePathProxy(path), + priority, framestamp, getDatabaseRequest(childNum), _readerWriterOptions.get()); -#else - // OSG revisions up to 2.9.10 - dbp->requestNodeFile(getFileName(childNum),this,priority,framestamp, - getDatabaseRequest(childNum), - _readerWriterOptions.get()); -#endif } bool SGPagedLOD_writeLocalData(const Object& obj, osgDB::Output& fw) diff --git a/simgear/scene/model/SGPagedLOD.hxx b/simgear/scene/model/SGPagedLOD.hxx index fe256446..a9e55d96 100644 --- a/simgear/scene/model/SGPagedLOD.hxx +++ b/simgear/scene/model/SGPagedLOD.hxx @@ -18,10 +18,13 @@ #define SGPAGEDLOD_HXX 1 #include + +#define SG_PAGEDLOD_HAS_OPTIONS \ + (SG_OSG_VERSION >= 29005 \ + || (SG_OSG_VERSION < 29000 && SG_OSG_VERSION >= 28003)) + #include -#if SG_OSG_MIN_VERSION_REQUIRED(2,9,5) -#include -#endif +#include #include #include @@ -43,26 +46,35 @@ public: META_Node(simgear, SGPagedLOD); // virtual void traverse(osg::NodeVisitor& nv); - virtual void forceLoad(osgDB::DatabasePager* dbp, osg::FrameStamp* framestamp); + virtual void forceLoad(osgDB::DatabasePager* dbp, + osg::FrameStamp* framestamp, + osg::NodePath& path); // reimplemented to notify the loading through ModelData bool addChild(osg::Node *child); void setReaderWriterOptions(osgDB::ReaderWriter::Options *options) { - _readerWriterOptions = options; options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE); -#if SG_OSG_MIN_VERSION_REQUIRED(2,9,5) +#if SG_PAGEDLOD_HAS_OPTIONS setDatabaseOptions(options); +#else + _readerWriterOptions = options; #endif } osgDB::ReaderWriter::Options* getReaderWriterOptions() { +#if SG_PAGEDLOD_HAS_OPTIONS + return static_cast(getDatabaseOptions()); +#else return _readerWriterOptions.get(); +#endif } protected: virtual ~SGPagedLOD(); +#if SG_PAGEDLOD_HAS_OPTIONS osg::ref_ptr _readerWriterOptions; +#endif }; } #endif diff --git a/simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx b/simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx index b1d21b5d..097d3fcd 100644 --- a/simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx +++ b/simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx @@ -21,6 +21,7 @@ #include class SGReaderWriterBTGOptions : public osgDB::ReaderWriter::Options { public: + META_Object(simgear,SGReaderWriterBTGOptions); SGReaderWriterBTGOptions(const std::string& str = std::string()) : osgDB::ReaderWriter::Options(str), _matlib(0), _calcLights(true), -- 2.39.5