From c7b9a07758c570ecf184cfa5b1810c65ec40d152 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 10 May 2007 08:20:33 +0000 Subject: [PATCH] Added checks against Options to osga plugin to ensure archives are only cached when requested, cleaned up the Registry::openArchiveImplementation function. --- src/osgDB/Registry.cpp | 22 ++++++++-------------- src/osgPlugins/osga/ReaderWriterOSGA.cpp | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 2541debbd..9732cb782 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -1537,25 +1537,19 @@ ReaderWriter::ReadResult Registry::readImplementation(const ReadFunctor& readFun ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const ReaderWriter::Options* options) { + osgDB::Archive* archive = getFromArchiveCache(fileName); + if (archive) return archive; + + ReaderWriter::ReadResult result = readImplementation(ReadArchiveFunctor(fileName, status, indexBlockSizeHint, options),false); // default to using chaching archive if no options structure provided, but if options are provided use archives // only if supplied. - if (!options || (options && (options->getObjectCacheHint() & ReaderWriter::Options::CACHE_ARCHIVES))) + if (result.validArchive() && + (!options || (options->getObjectCacheHint() & ReaderWriter::Options::CACHE_ARCHIVES)) ) { - osgDB::Archive* archive = getFromArchiveCache(fileName); - if (archive) return archive; - - ReaderWriter::ReadResult result = readImplementation(ReadArchiveFunctor(fileName, status, indexBlockSizeHint, options),false); - if (result.validArchive()) - { - addToArchiveCache(fileName,result.getArchive()); - } - return result; - } - else - { - return readImplementation(ReadArchiveFunctor(fileName, status, indexBlockSizeHint, _options.get()),false); + addToArchiveCache(fileName,result.getArchive()); } + return result; } diff --git a/src/osgPlugins/osga/ReaderWriterOSGA.cpp b/src/osgPlugins/osga/ReaderWriterOSGA.cpp index cf1b623d9..c23440c91 100644 --- a/src/osgPlugins/osga/ReaderWriterOSGA.cpp +++ b/src/osgPlugins/osga/ReaderWriterOSGA.cpp @@ -51,7 +51,7 @@ public: return archive.get(); } - virtual ReadResult readImage(const std::string& file,const Options*) const + virtual ReadResult readImage(const std::string& file,const Options* options) const { ReadResult result = openArchive(file,osgDB::Archive::READ); @@ -64,14 +64,16 @@ public: ReadResult result_2 = result.getArchive()->readImage(result.getArchive()->getMasterFileName(),local_options.get()); - // register the archive so that it is cached for future use. - osgDB::Registry::instance()->addToArchiveCache(file, result.getArchive()); - + if (!options || (options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_ARCHIVES)) + { + // register the archive so that it is cached for future use. + osgDB::Registry::instance()->addToArchiveCache(file, result.getArchive()); + } return result_2; } - virtual ReadResult readNode(const std::string& file,const Options*) const + virtual ReadResult readNode(const std::string& file,const Options* options) const { ReadResult result = openArchive(file,osgDB::Archive::READ); @@ -84,9 +86,11 @@ public: ReadResult result_2 = result.getArchive()->readNode(result.getArchive()->getMasterFileName(),local_options.get()); - // register the archive so that it is cached for future use. - osgDB::Registry::instance()->addToArchiveCache(file, result.getArchive()); - + if (!options || (options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_ARCHIVES)) + { + // register the archive so that it is cached for future use. + osgDB::Registry::instance()->addToArchiveCache(file, result.getArchive()); + } return result_2; }