X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmodel%2FModelRegistry.hxx;h=8c8e7467386cd6c7bda347f6678cdb89147f9445;hb=32a6bd78d8bf143f40922f1a0bc7a88ea7706a7d;hp=909c9460247184d6b481d2ab86dbd06b25ee7cfe;hpb=9cbbe5559844317f44744788ddb308101a1e75e9;p=simgear.git diff --git a/simgear/scene/model/ModelRegistry.hxx b/simgear/scene/model/ModelRegistry.hxx index 909c9460..8c8e7467 100644 --- a/simgear/scene/model/ModelRegistry.hxx +++ b/simgear/scene/model/ModelRegistry.hxx @@ -19,8 +19,6 @@ #ifndef _SG_MODELREGISTRY_HXX #define _SG_MODELREGISTRY_HXX 1 -#include - #include #include #include @@ -29,7 +27,7 @@ #include #include -#include +#include #include #include @@ -61,18 +59,18 @@ namespace simgear // readNode function is specified as a template with a bunch of // pluggable (and predefined) policies. template + typename SubstitutePolicy, typename BVHPolicy> class ModelRegistryCallback : public osgDB::Registry::ReadFileCallback { public: ModelRegistryCallback(const std::string& extension) : _processPolicy(extension), _cachePolicy(extension), - _optimizePolicy(extension), _copyPolicy(extension), + _optimizePolicy(extension), _substitutePolicy(extension), _bvhPolicy(extension) { } virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options* opt) + const osgDB::Options* opt) { using namespace osg; using namespace osgDB; @@ -97,17 +95,16 @@ public: optimizedNode = _optimizePolicy.optimize(processedNode.get(), fileName, opt); } - _bvhPolicy.buildBVH(fileName, optimizedNode.get()); + if (opt->getPluginStringData("SimGear::BOUNDINGVOLUMES") != "OFF") + _bvhPolicy.buildBVH(fileName, optimizedNode.get()); _cachePolicy.addToCache(fileName, optimizedNode.get()); } - osg::ref_ptr copyNode; - copyNode = _copyPolicy.copy(optimizedNode.get(), fileName, opt); - return ReaderWriter::ReadResult(copyNode); + return ReaderWriter::ReadResult(optimizedNode.get()); } protected: static osgDB::ReaderWriter::ReadResult loadUsingReaderWriter(const std::string& fileName, - const osgDB::ReaderWriter::Options* opt) + const osgDB::Options* opt) { using namespace osgDB; ReaderWriter* rw = Registry::instance() @@ -120,7 +117,6 @@ protected: ProcessPolicy _processPolicy; CachePolicy _cachePolicy; OptimizePolicy _optimizePolicy; - CopyPolicy _copyPolicy; SubstitutePolicy _substitutePolicy; BVHPolicy _bvhPolicy; virtual ~ModelRegistryCallback() {} @@ -131,20 +127,20 @@ protected: struct DefaultProcessPolicy { DefaultProcessPolicy(const std::string& extension) {} osg::Node* process(osg::Node* node, const std::string& filename, - const osgDB::ReaderWriter::Options* opt); + const osgDB::Options* opt); }; struct DefaultCachePolicy { DefaultCachePolicy(const std::string& extension) {} osg::Node* find(const std::string& fileName, - const osgDB::ReaderWriter::Options* opt); + const osgDB::Options* opt); void addToCache(const std::string& filename, osg::Node* node); }; struct NoCachePolicy { NoCachePolicy(const std::string& extension) {} osg::Node* find(const std::string& fileName, - const osgDB::ReaderWriter::Options* opt) + const osgDB::Options* opt) { return 0; } @@ -155,7 +151,7 @@ class OptimizeModelPolicy { public: OptimizeModelPolicy(const std::string& extension); osg::Node* optimize(osg::Node* node, const std::string& fileName, - const osgDB::ReaderWriter::Options* opt); + const osgDB::Options* opt); protected: unsigned _osgOptions; }; @@ -163,22 +159,7 @@ protected: struct NoOptimizePolicy { NoOptimizePolicy(const std::string& extension) {} osg::Node* optimize(osg::Node* node, const std::string& fileName, - const osgDB::ReaderWriter::Options* opt) - { - return node; - } -}; - -struct DefaultCopyPolicy { - DefaultCopyPolicy(const std::string& extension) {} - osg::Node* copy(osg::Node* node, const std::string& fileName, - const osgDB::ReaderWriter::Options* opt); -}; - -struct NoCopyPolicy { - NoCopyPolicy(const std::string& extension) {} - osg::Node* copy(osg::Node* node, const std::string& fileName, - const osgDB::ReaderWriter::Options* opt) + const osgDB::Options* opt) { return node; } @@ -187,13 +168,13 @@ struct NoCopyPolicy { struct OSGSubstitutePolicy { OSGSubstitutePolicy(const std::string& extension) {} std::string substitute(const std::string& name, - const osgDB::ReaderWriter::Options* opt); + const osgDB::Options* opt); }; struct NoSubstitutePolicy { NoSubstitutePolicy(const std::string& extension) {} std::string substitute(const std::string& name, - const osgDB::ReaderWriter::Options* opt) + const osgDB::Options* opt) { return std::string(); } @@ -215,7 +196,7 @@ struct NoBuildBVHPolicy { }; typedef ModelRegistryCallback DefaultCallback; @@ -226,10 +207,10 @@ public: ModelRegistry(); virtual osgDB::ReaderWriter::ReadResult readImage(const std::string& fileName, - const osgDB::ReaderWriter::Options* opt); + const osgDB::Options* opt); virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options* opt); + const osgDB::Options* opt); void addImageCallbackForExtension(const std::string& extension, osgDB::Registry::ReadFileCallback* callback); @@ -243,15 +224,12 @@ protected: CallbackMap imageCallbackMap; CallbackMap nodeCallbackMap; osg::ref_ptr _defaultCallback; - // Protect against simultaneous calls from main thread (MP models) - // and pager thread. - OpenThreads::ReentrantMutex readerMutex; }; // Callback that only loads the file without any caching or // postprocessing. typedef ModelRegistryCallback LoadOnlyCallback;