From fdb265cd6e069f2f85dcde9f0a94fdf478173851 Mon Sep 17 00:00:00 2001 From: timoore Date: Thu, 29 Nov 2007 23:56:49 +0000 Subject: [PATCH] Change the main ModelRegistry callback function to stash the substituted file in the cache. --- simgear/scene/model/ModelRegistry.hxx | 54 +++++++++++++++++---------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/simgear/scene/model/ModelRegistry.hxx b/simgear/scene/model/ModelRegistry.hxx index e65c78b8..2c010297 100644 --- a/simgear/scene/model/ModelRegistry.hxx +++ b/simgear/scene/model/ModelRegistry.hxx @@ -75,30 +75,44 @@ public: using namespace osgDB; using osgDB::ReaderWriter; Registry* registry = Registry::instance(); - std::string usedFileName = _substitutePolicy.substitute(fileName, opt); - if (usedFileName.empty()) - usedFileName = fileName; - ref_ptr loadedNode = _cachePolicy.find(usedFileName, opt); - if (!loadedNode.valid()) { - ReaderWriter* rw = registry ->getReaderWriterForExtension(osgDB::getFileExtension(usedFileName)); - if (!rw) - return ReaderWriter::ReadResult(); // FILE_NOT_HANDLED - ReaderWriter::ReadResult res = rw->readNode(usedFileName, opt); - if (!res.validNode()) - return res; - ref_ptr processedNode - = _processPolicy.process(res.getNode(), usedFileName, opt); - ref_ptr optimizedNode - = _optimizePolicy.optimize(processedNode.get(), usedFileName, - opt); - _cachePolicy.addToCache(usedFileName, optimizedNode.get()); - loadedNode = optimizedNode; + ref_ptr optimizedNode = _cachePolicy.find(fileName, opt); + if (!optimizedNode.valid()) { + std::string otherFileName = _substitutePolicy.substitute(fileName, + opt); + ReaderWriter::ReadResult res; + if (!otherFileName.empty()) { + res = loadUsingReaderWriter(otherFileName, opt); + if (res.validNode()) + optimizedNode = res.getNode(); + } + if (!optimizedNode.valid()) { + res = loadUsingReaderWriter(fileName, opt); + if (!res.validNode()) + return res; + ref_ptr processedNode + = _processPolicy.process(res.getNode(), fileName, opt); + optimizedNode = _optimizePolicy.optimize(processedNode.get(), + fileName, opt); + } + _cachePolicy.addToCache(fileName, optimizedNode.get()); } - return ReaderWriter::ReadResult(_copyPolicy.copy(loadedNode.get(), - usedFileName, + return ReaderWriter::ReadResult(_copyPolicy.copy(optimizedNode.get(), + fileName, opt)); } protected: + static osgDB::ReaderWriter::ReadResult + loadUsingReaderWriter(const std::string& fileName, + const osgDB::ReaderWriter::Options* opt) + { + using namespace osgDB; + ReaderWriter* rw = Registry::instance() + ->getReaderWriterForExtension(osgDB::getFileExtension(fileName)); + if (!rw) + return ReaderWriter::ReadResult(); // FILE_NOT_HANDLED + return rw->readNode(fileName, opt); + } + ProcessPolicy _processPolicy; CachePolicy _cachePolicy; OptimizePolicy _optimizePolicy; -- 2.39.5