Introduce osgDB::FileCache, and updated osgfilecache and DatabasePager to use it.

This commit is contained in:
Robert Osfield
2008-10-20 16:24:57 +00:00
parent 10186190f6
commit 24eb2f6c43
9 changed files with 252 additions and 115 deletions

View File

@@ -105,8 +105,6 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
virtual void run();
osg::ref_ptr<osg::Node> dpReadRefNodeFile(const std::string& fileName,const ReaderWriter::Options* options);
protected:
virtual ~DatabaseThread();

49
include/osgDB/FileCache Normal file
View File

@@ -0,0 +1,49 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGDB_FILECACHE
#define OSGDB_FILECACHE 1
#include <osg/Node>
#include <osgDB/ReaderWriter>
namespace osgDB {
class OSGDB_EXPORT FileCache : public osg::Referenced
{
public:
FileCache(const std::string& path);
const std::string& getFileCachePath() const { return _fileCachePath; }
virtual std::string createCacheFileName(const std::string& originalFileName) const;
virtual bool existsInCache(const std::string& originalFileName) const;
virtual ReaderWriter::ReadResult readNode(const std::string& originalFileName, const osgDB::ReaderWriter::Options* options, bool buildKdTreeIfRequired=true) const;
virtual ReaderWriter::WriteResult writeNode(const osg::Node& node, const std::string& originalFileName, const osgDB::ReaderWriter::Options* options) const;
protected:
virtual ~FileCache();
std::string _fileCachePath;
};
}
#endif

View File

@@ -24,6 +24,7 @@
#include <osgDB/ReaderWriter>
#include <osgDB/DotOsgWrapper>
#include <osgDB/DatabasePager>
#include <osgDB/FileCache>
#include <vector>
#include <map>
@@ -203,13 +204,13 @@ class OSGDB_EXPORT Registry : public osg::Referenced
}
ReaderWriter::ReadResult openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const ReaderWriter::Options* options);
ReaderWriter::ReadResult readObject(const std::string& fileName,const ReaderWriter::Options* options)
ReaderWriter::ReadResult readObject(const std::string& fileName,const ReaderWriter::Options* options, bool buildKdTreeIfRequired=true)
{
ReaderWriter::ReadResult result = _readFileCallback.valid() ?
_readFileCallback->readObject(fileName,options) :
readObjectImplementation(fileName,options);
buildKdTreeIfRequired(result, options);
if (buildKdTreeIfRequired) _buildKdTreeIfRequired(result, options);
return result;
}
@@ -229,13 +230,13 @@ class OSGDB_EXPORT Registry : public osg::Referenced
}
ReaderWriter::ReadResult readHeightFieldImplementation(const std::string& fileName,const ReaderWriter::Options* options);
ReaderWriter::ReadResult readNode(const std::string& fileName,const ReaderWriter::Options* options)
ReaderWriter::ReadResult readNode(const std::string& fileName,const ReaderWriter::Options* options, bool buildKdTreeIfRequired=true)
{
ReaderWriter::ReadResult result = _readFileCallback.valid() ?
_readFileCallback->readNode(fileName,options) :
readNodeImplementation(fileName,options);
buildKdTreeIfRequired(result, options);
if (buildKdTreeIfRequired) _buildKdTreeIfRequired(result, options);
return result;
}
@@ -329,7 +330,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
ReaderWriter::WriteResult writeShaderImplementation(const osg::Shader& obj, const std::string& fileName,const ReaderWriter::Options* options);
inline void buildKdTreeIfRequired(ReaderWriter::ReadResult& result, const ReaderWriter::Options* options)
inline void _buildKdTreeIfRequired(ReaderWriter::ReadResult& result, const ReaderWriter::Options* options)
{
bool doKdTreeBuilder = (options && options->getBuildKdTreesHint()!=ReaderWriter::Options::NO_PREFERENCE) ?
options->getBuildKdTreesHint() == ReaderWriter::Options::BUILD_KDTREES :
@@ -355,6 +356,15 @@ class OSGDB_EXPORT Registry : public osg::Referenced
/** Get the KdTreeBuilder visitor that is used to build KdTree on loaded models.*/
osg::KdTreeBuilder* getKdTreeBuilder() { return _kdTreeBuilder.get(); }
/** Set the FileCache that is used to manage local storage of files downloaded from the internet.*/
void setFileCache(FileCache* fileCache) { _fileCache = fileCache; }
/** Get the FileCache that is used to manage local storage of files downloaded from the internet.*/
FileCache* getFileCache() { return _fileCache.get(); }
/** Get the const FileCache that is used to manage local storage of files downloaded from the internet.*/
const FileCache* getFileCache() const { return _fileCache.get(); }
/** Set the password map to be used by plugins when access files from secure locations.*/
void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; }
@@ -503,6 +513,8 @@ class OSGDB_EXPORT Registry : public osg::Referenced
ReaderWriter::Options::BuildKdTreesHint _buildKdTreesHint;
osg::ref_ptr<osg::KdTreeBuilder> _kdTreeBuilder;
osg::ref_ptr<FileCache> _fileCache;
osg::ref_ptr<AuthenticationMap> _authenticationMap;
bool _createNodeFromImage;