mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 01:45:38 +00:00
Use normalized path for NifFileManager::get
This commit is contained in:
parent
3ea3eeb613
commit
859d765921
6 changed files with 21 additions and 13 deletions
|
@ -110,7 +110,7 @@ namespace Resource
|
|||
|
||||
osg::ref_ptr<const BulletShape> BulletShapeManager::getShape(const std::string& name)
|
||||
{
|
||||
const std::string normalized = VFS::Path::normalizeFilename(name);
|
||||
const VFS::Path::Normalized normalized(name);
|
||||
|
||||
osg::ref_ptr<BulletShape> shape;
|
||||
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
|
||||
|
|
|
@ -41,14 +41,14 @@ namespace Resource
|
|||
|
||||
NifFileManager::~NifFileManager() = default;
|
||||
|
||||
Nif::NIFFilePtr NifFileManager::get(const std::string& name)
|
||||
Nif::NIFFilePtr NifFileManager::get(VFS::Path::NormalizedView name)
|
||||
{
|
||||
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(name);
|
||||
if (obj)
|
||||
return static_cast<NifFileHolder*>(obj.get())->mNifFile;
|
||||
else
|
||||
{
|
||||
auto file = std::make_shared<Nif::NIFFile>(name);
|
||||
auto file = std::make_shared<Nif::NIFFile>(name.value());
|
||||
Nif::Reader reader(*file, mEncoder);
|
||||
reader.parse(mVFS->get(name));
|
||||
obj = new NifFileHolder(file);
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Resource
|
|||
/// Retrieve a NIF file from the cache, or load it from the VFS if not cached yet.
|
||||
/// @note For performance reasons the NifFileManager does not handle case folding, needs
|
||||
/// to be done in advance by other managers accessing the NifFileManager.
|
||||
Nif::NIFFilePtr get(const std::string& name);
|
||||
Nif::NIFFilePtr get(VFS::Path::NormalizedView name);
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;
|
||||
};
|
||||
|
|
|
@ -545,9 +545,9 @@ namespace Resource
|
|||
namespace
|
||||
{
|
||||
osg::ref_ptr<osg::Node> loadNonNif(
|
||||
const std::string& normalizedFilename, std::istream& model, Resource::ImageManager* imageManager)
|
||||
VFS::Path::NormalizedView normalizedFilename, std::istream& model, Resource::ImageManager* imageManager)
|
||||
{
|
||||
auto ext = Misc::getFileExtension(normalizedFilename);
|
||||
const std::string_view ext = Misc::getFileExtension(normalizedFilename.value());
|
||||
osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension(std::string(ext));
|
||||
if (!reader)
|
||||
{
|
||||
|
@ -566,7 +566,7 @@ namespace Resource
|
|||
if (ext == "dae")
|
||||
options->setOptionString("daeUseSequencedTextureUnits");
|
||||
|
||||
const std::array<std::uint64_t, 2> fileHash = Files::getHash(normalizedFilename, model);
|
||||
const std::array<std::uint64_t, 2> fileHash = Files::getHash(normalizedFilename.value(), model);
|
||||
|
||||
osgDB::ReaderWriter::ReadResult result = reader->readNode(model, options);
|
||||
if (!result.success())
|
||||
|
@ -721,10 +721,10 @@ namespace Resource
|
|||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> load(const std::string& normalizedFilename, const VFS::Manager* vfs,
|
||||
osg::ref_ptr<osg::Node> load(VFS::Path::NormalizedView normalizedFilename, const VFS::Manager* vfs,
|
||||
Resource::ImageManager* imageManager, Resource::NifFileManager* nifFileManager)
|
||||
{
|
||||
auto ext = Misc::getFileExtension(normalizedFilename);
|
||||
const std::string_view ext = Misc::getFileExtension(normalizedFilename.value());
|
||||
if (ext == "nif")
|
||||
return NifOsg::Loader::load(*nifFileManager->get(normalizedFilename), imageManager);
|
||||
else if (ext == "spt")
|
||||
|
@ -843,11 +843,12 @@ namespace Resource
|
|||
{
|
||||
try
|
||||
{
|
||||
VFS::Path::Normalized path("meshes/marker_error.****");
|
||||
for (const auto meshType : { "nif", "osg", "osgt", "osgb", "osgx", "osg2", "dae" })
|
||||
{
|
||||
const std::string normalized = "meshes/marker_error." + std::string(meshType);
|
||||
if (mVFS->exists(normalized))
|
||||
return load(normalized, mVFS, mImageManager, mNifFileManager);
|
||||
path.changeExtension(meshType);
|
||||
if (mVFS->exists(path))
|
||||
return load(path, mVFS, mImageManager, mNifFileManager);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
@ -869,7 +870,7 @@ namespace Resource
|
|||
|
||||
osg::ref_ptr<const osg::Node> SceneManager::getTemplate(std::string_view name, bool compile)
|
||||
{
|
||||
std::string normalized = VFS::Path::normalizeFilename(name);
|
||||
const VFS::Path::Normalized normalized(name);
|
||||
|
||||
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
|
||||
if (obj)
|
||||
|
|
|
@ -43,6 +43,11 @@ namespace VFS
|
|||
return getNormalized(name);
|
||||
}
|
||||
|
||||
Files::IStreamPtr Manager::get(Path::NormalizedView name) const
|
||||
{
|
||||
return getNormalized(name.value());
|
||||
}
|
||||
|
||||
Files::IStreamPtr Manager::getNormalized(std::string_view normalizedName) const
|
||||
{
|
||||
assert(Path::isNormalized(normalizedName));
|
||||
|
|
|
@ -50,6 +50,8 @@ namespace VFS
|
|||
/// @note May be called from any thread once the index has been built.
|
||||
Files::IStreamPtr get(const Path::Normalized& name) const;
|
||||
|
||||
Files::IStreamPtr get(Path::NormalizedView name) const;
|
||||
|
||||
/// Retrieve a file by name (name is already normalized).
|
||||
/// @note Throws an exception if the file can not be found.
|
||||
/// @note May be called from any thread once the index has been built.
|
||||
|
|
Loading…
Reference in a new issue