From d8189a5aa16059223517f63936515822006d975e Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 18 Aug 2024 20:23:11 +0200 Subject: [PATCH] Use normalized path in SceneManager --- apps/opencs/view/render/actor.cpp | 4 ++-- apps/opencs/view/render/object.cpp | 4 +++- apps/openmw/mwrender/actoranimation.cpp | 15 +++++++++------ apps/openmw/mwrender/animation.cpp | 11 ++++++----- apps/openmw/mwrender/effectmanager.cpp | 2 +- apps/openmw/mwrender/effectmanager.hpp | 7 ++++--- apps/openmw/mwrender/esm4npcanimation.cpp | 2 +- apps/openmw/mwrender/groundcover.cpp | 2 +- apps/openmw/mwrender/npcanimation.cpp | 2 +- apps/openmw/mwrender/objectpaging.cpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 6 +++--- apps/openmw/mwrender/renderingmanager.hpp | 16 ++++++++-------- apps/openmw/mwrender/sky.hpp | 2 +- apps/openmw/mwrender/weaponanimation.cpp | 2 +- apps/openmw/mwscript/miscextensions.cpp | 8 ++++---- apps/openmw/mwworld/cellpreloader.cpp | 2 +- apps/openmw/mwworld/projectilemanager.cpp | 6 ++++-- apps/openmw/mwworld/scene.cpp | 15 ++++++++------- apps/openmw/mwworld/worldimp.cpp | 6 +++--- components/resource/scenemanager.cpp | 23 ++++++++++------------- components/resource/scenemanager.hpp | 6 +++--- components/vfs/pathutil.hpp | 11 +++++++++++ 22 files changed, 86 insertions(+), 68 deletions(-) diff --git a/apps/opencs/view/render/actor.cpp b/apps/opencs/view/render/actor.cpp index 8aa08e443e..1b1e4dfcaa 100644 --- a/apps/opencs/view/render/actor.cpp +++ b/apps/opencs/view/render/actor.cpp @@ -90,7 +90,7 @@ namespace CSVRender { auto sceneMgr = mData.getResourceSystem()->getSceneManager(); - osg::ref_ptr temp = sceneMgr->getInstance(model); + osg::ref_ptr temp = sceneMgr->getInstance(VFS::Path::toNormalized(model)); mSkeleton = dynamic_cast(temp.get()); if (!mSkeleton) { @@ -123,7 +123,7 @@ namespace CSVRender auto node = mNodeMap.find(boneName); if (!mesh.empty() && node != mNodeMap.end()) { - auto instance = sceneMgr->getInstance(mesh); + auto instance = sceneMgr->getInstance(VFS::Path::toNormalized(mesh)); SceneUtil::attach(instance, mSkeleton, boneName, node->second, sceneMgr); } } diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index 370c2ef59e..fe4b6e9b7f 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -151,7 +151,9 @@ void CSVRender::Object::update() } else if (!model.empty()) { - std::string path = "meshes\\" + model; + constexpr VFS::Path::NormalizedView meshes("meshes"); + VFS::Path::Normalized path(meshes); + path /= model; mResourceSystem->getSceneManager()->getInstance(path, mBaseNode); } else diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index 6e18fb51a1..35ff81a9ca 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -73,7 +73,8 @@ namespace MWRender if (!parent) return nullptr; - osg::ref_ptr instance = mResourceSystem->getSceneManager()->getInstance(model, parent); + osg::ref_ptr instance + = mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(model), parent); const NodeMap& nodeMap = getNodeMap(); NodeMap::const_iterator found = nodeMap.find(bonename); @@ -89,7 +90,8 @@ namespace MWRender osg::ref_ptr ActorAnimation::attach( const std::string& model, std::string_view bonename, std::string_view bonefilter, bool isLight) { - osg::ref_ptr templateNode = mResourceSystem->getSceneManager()->getTemplate(model); + osg::ref_ptr templateNode + = mResourceSystem->getSceneManager()->getTemplate(VFS::Path::toNormalized(model)); const NodeMap& nodeMap = getNodeMap(); auto found = nodeMap.find(bonename); @@ -145,7 +147,7 @@ namespace MWRender if (mesh.empty()) return mesh; - const std::string holsteredName = addSuffixBeforeExtension(mesh, "_sh"); + const VFS::Path::Normalized holsteredName(addSuffixBeforeExtension(mesh, "_sh")); if (mResourceSystem->getVFS()->exists(holsteredName)) { osg::ref_ptr shieldTemplate = mResourceSystem->getSceneManager()->getInstance(holsteredName); @@ -243,7 +245,8 @@ namespace MWRender // file. if (shieldNode && !shieldNode->getNumChildren()) { - osg::ref_ptr fallbackNode = mResourceSystem->getSceneManager()->getInstance(mesh, shieldNode); + osg::ref_ptr fallbackNode + = mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(mesh), shieldNode); if (isEnchanted) SceneUtil::addEnchantedGlow(shieldNode, mResourceSystem, glowColor); } @@ -381,7 +384,7 @@ namespace MWRender if (!weaponNode->getNumChildren()) { osg::ref_ptr fallbackNode - = mResourceSystem->getSceneManager()->getInstance(mesh, weaponNode); + = mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(mesh), weaponNode); resetControllers(fallbackNode); } @@ -463,7 +466,7 @@ namespace MWRender // Add new ones osg::Vec4f glowColor = ammo->getClass().getEnchantmentColor(*ammo); - std::string model = ammo->getClass().getCorrectedModel(*ammo); + const VFS::Path::Normalized model(ammo->getClass().getCorrectedModel(*ammo)); for (unsigned int i = 0; i < ammoCount; ++i) { osg::ref_ptr arrowNode = ammoNode->getChild(i)->asGroup(); diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 89adc26d08..5b7d1db78a 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1473,7 +1473,7 @@ namespace MWRender } void loadBonesFromFile( - osg::ref_ptr& baseNode, const std::string& model, Resource::ResourceSystem* resourceSystem) + osg::ref_ptr& baseNode, VFS::Path::NormalizedView model, Resource::ResourceSystem* resourceSystem) { const osg::Node* node = resourceSystem->getSceneManager()->getTemplate(model).get(); osg::ref_ptr sheathSkeleton( @@ -1511,7 +1511,7 @@ namespace MWRender for (const auto& name : resourceSystem->getVFS()->getRecursiveDirectoryIterator(animationPath)) { if (Misc::getFileExtension(name) == "nif") - loadBonesFromFile(node, name, resourceSystem); + loadBonesFromFile(node, VFS::Path::toNormalized(name), resourceSystem); } } @@ -1526,7 +1526,7 @@ namespace MWRender Cache::iterator found = cache.find(model); if (found == cache.end()) { - osg::ref_ptr created = sceneMgr->getInstance(model); + osg::ref_ptr created = sceneMgr->getInstance(VFS::Path::toNormalized(model)); if (inject) { @@ -1547,7 +1547,7 @@ namespace MWRender } else { - osg::ref_ptr created = sceneMgr->getInstance(model); + osg::ref_ptr created = sceneMgr->getInstance(VFS::Path::toNormalized(model)); if (inject) { @@ -1762,7 +1762,8 @@ namespace MWRender } parentNode->addChild(trans); - osg::ref_ptr node = mResourceSystem->getSceneManager()->getInstance(model, trans); + osg::ref_ptr node + = mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(model), trans); // Morrowind has a white ambient light attached to the root VFX node of the scenegraph node->getOrCreateStateSet()->setAttributeAndModes( diff --git a/apps/openmw/mwrender/effectmanager.cpp b/apps/openmw/mwrender/effectmanager.cpp index 83a4091402..0ac509742c 100644 --- a/apps/openmw/mwrender/effectmanager.cpp +++ b/apps/openmw/mwrender/effectmanager.cpp @@ -27,7 +27,7 @@ namespace MWRender clear(); } - void EffectManager::addEffect(const std::string& model, std::string_view textureOverride, + void EffectManager::addEffect(VFS::Path::NormalizedView model, std::string_view textureOverride, const osg::Vec3f& worldPosition, float scale, bool isMagicVFX) { osg::ref_ptr node = mResourceSystem->getSceneManager()->getInstance(model); diff --git a/apps/openmw/mwrender/effectmanager.hpp b/apps/openmw/mwrender/effectmanager.hpp index 2477344fd0..671c441a59 100644 --- a/apps/openmw/mwrender/effectmanager.hpp +++ b/apps/openmw/mwrender/effectmanager.hpp @@ -2,11 +2,12 @@ #define OPENMW_MWRENDER_EFFECTMANAGER_H #include -#include #include #include +#include + namespace osg { class Group; @@ -33,8 +34,8 @@ namespace MWRender ~EffectManager(); /// Add an effect. When it's finished playing, it will be removed automatically. - void addEffect(const std::string& model, std::string_view textureOverride, const osg::Vec3f& worldPosition, - float scale, bool isMagicVFX = true); + void addEffect(VFS::Path::NormalizedView model, std::string_view textureOverride, + const osg::Vec3f& worldPosition, float scale, bool isMagicVFX = true); void update(float dt); diff --git a/apps/openmw/mwrender/esm4npcanimation.cpp b/apps/openmw/mwrender/esm4npcanimation.cpp index 4193fb60b4..3bff588343 100644 --- a/apps/openmw/mwrender/esm4npcanimation.cpp +++ b/apps/openmw/mwrender/esm4npcanimation.cpp @@ -53,7 +53,7 @@ namespace MWRender if (model.empty()) return; mResourceSystem->getSceneManager()->getInstance( - Misc::ResourceHelpers::correctMeshPath(model), mObjectRoot.get()); + VFS::Path::toNormalized(Misc::ResourceHelpers::correctMeshPath(model)), mObjectRoot.get()); } template diff --git a/apps/openmw/mwrender/groundcover.cpp b/apps/openmw/mwrender/groundcover.cpp index 7a29f1bb07..44608ca3c3 100644 --- a/apps/openmw/mwrender/groundcover.cpp +++ b/apps/openmw/mwrender/groundcover.cpp @@ -428,7 +428,7 @@ namespace MWRender osg::Vec3f worldCenter = osg::Vec3f(center.x(), center.y(), 0) * ESM::Land::REAL_SIZE; for (auto& pair : instances) { - const osg::Node* temp = mSceneManager->getTemplate(pair.first); + const osg::Node* temp = mSceneManager->getTemplate(VFS::Path::toNormalized(pair.first)); osg::ref_ptr node = static_cast(temp->clone(osg::CopyOp::DEEP_COPY_NODES | osg::CopyOp::DEEP_COPY_DRAWABLES | osg::CopyOp::DEEP_COPY_USERDATA | osg::CopyOp::DEEP_COPY_ARRAYS | osg::CopyOp::DEEP_COPY_PRIMITIVES)); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 8e8f10a362..08dfcb667c 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -541,7 +541,7 @@ namespace MWRender if (mesh.empty()) return std::string(); - const std::string holsteredName = addSuffixBeforeExtension(mesh, "_sh"); + const VFS::Path::Normalized holsteredName(addSuffixBeforeExtension(mesh, "_sh")); if (mResourceSystem->getVFS()->exists(holsteredName)) { osg::ref_ptr shieldTemplate = mResourceSystem->getSceneManager()->getInstance(holsteredName); diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp index 6799b2358b..6e39d99404 100644 --- a/apps/openmw/mwrender/objectpaging.cpp +++ b/apps/openmw/mwrender/objectpaging.cpp @@ -671,7 +671,7 @@ namespace MWRender ->second; } - osg::ref_ptr cnode = mSceneManager->getTemplate(model, false); + osg::ref_ptr cnode = mSceneManager->getTemplate(VFS::Path::toNormalized(model), false); if (activeGrid) { diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index af3d0a7567..44e05d6115 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1263,7 +1263,7 @@ namespace MWRender mActorsPaths->updatePtr(old, updated); } - void RenderingManager::spawnEffect(const std::string& model, std::string_view texture, + void RenderingManager::spawnEffect(VFS::Path::NormalizedView model, std::string_view texture, const osg::Vec3f& worldPosition, float scale, bool isMagicVFX) { mEffectManager->addEffect(model, texture, worldPosition, scale, isMagicVFX); @@ -1649,7 +1649,7 @@ namespace MWRender osg::Vec3f RenderingManager::getHalfExtents(const MWWorld::ConstPtr& object) const { osg::Vec3f halfExtents(0, 0, 0); - std::string modelName = object.getClass().getCorrectedModel(object); + VFS::Path::Normalized modelName(object.getClass().getCorrectedModel(object)); if (modelName.empty()) return halfExtents; @@ -1680,7 +1680,7 @@ namespace MWRender MWWorld::Scene* worldScene = MWBase::Environment::get().getWorldScene(); if (!rootNode || worldScene->isPagedRef(ptr)) { - const std::string model = ptr.getClass().getCorrectedModel(ptr); + const VFS::Path::Normalized model(ptr.getClass().getCorrectedModel(ptr)); if (model.empty()) return {}; diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 2c68c060b3..86f248491a 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -1,21 +1,21 @@ #ifndef OPENMW_MWRENDER_RENDERINGMANAGER_H #define OPENMW_MWRENDER_RENDERINGMANAGER_H -#include +#include "objects.hpp" +#include "renderinginterface.hpp" +#include "rendermode.hpp" + +#include +#include #include #include -#include - #include -#include "objects.hpp" -#include "renderinginterface.hpp" -#include "rendermode.hpp" - #include #include +#include #include namespace osg @@ -196,7 +196,7 @@ namespace MWRender SkyManager* getSkyManager(); - void spawnEffect(const std::string& model, std::string_view texture, const osg::Vec3f& worldPosition, + void spawnEffect(VFS::Path::NormalizedView model, std::string_view texture, const osg::Vec3f& worldPosition, float scale = 1.f, bool isMagicVFX = true); /// Clear all savegame-specific data diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index 716f49a4c7..4ec357056e 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -188,7 +188,7 @@ namespace MWRender osg::Vec4f mSkyColour; osg::Vec4f mFogColour; - std::string mCurrentParticleEffect; + VFS::Path::Normalized mCurrentParticleEffect; float mRemainingTransitionTime; diff --git a/apps/openmw/mwrender/weaponanimation.cpp b/apps/openmw/mwrender/weaponanimation.cpp index 5db2a5e196..b9c8fd1d28 100644 --- a/apps/openmw/mwrender/weaponanimation.cpp +++ b/apps/openmw/mwrender/weaponanimation.cpp @@ -86,7 +86,7 @@ namespace MWRender MWWorld::ConstContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition); if (ammo == inv.end()) return; - std::string model = ammo->getClass().getCorrectedModel(*ammo); + VFS::Path::Normalized model(ammo->getClass().getCorrectedModel(*ammo)); osg::ref_ptr arrow = getResourceSystem()->getSceneManager()->getInstance(model, parent); diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 7fb901f31b..c808cc2518 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -1437,9 +1437,9 @@ namespace MWScript osg::Vec3f pos(ptr.getRefData().getPosition().asVec3()); msg << "Coordinates: " << pos.x() << " " << pos.y() << " " << pos.z() << std::endl; auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); - std::string model - = ::Misc::ResourceHelpers::correctActorModelPath(ptr.getClass().getCorrectedModel(ptr), vfs); - msg << "Model: " << model << std::endl; + const VFS::Path::Normalized model( + ::Misc::ResourceHelpers::correctActorModelPath(ptr.getClass().getCorrectedModel(ptr), vfs)); + msg << "Model: " << model.value() << std::endl; if (!model.empty()) { const std::string archive = vfs->getArchive(model); @@ -1714,7 +1714,7 @@ namespace MWScript for (const T& record : store.get()) { MWWorld::ManualRef ref(store, record.mId); - std::string model = ref.getPtr().getClass().getCorrectedModel(ref.getPtr()); + VFS::Path::Normalized model(ref.getPtr().getClass().getCorrectedModel(ref.getPtr())); if (!model.empty()) { sceneManager->getTemplate(model); diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 0bf3360bce..05d6efc494 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -133,7 +133,7 @@ namespace MWWorld mPreloadedObjects.insert(mKeyframeManager->get(kfname)); } } - mPreloadedObjects.insert(mSceneManager->getTemplate(mesh)); + mPreloadedObjects.insert(mSceneManager->getTemplate(VFS::Path::toNormalized(mesh))); if (mPreloadInstances) mPreloadedObjects.insert(mBulletShapeManager->cacheInstance(mesh)); else diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index dc675d956a..2c398db07d 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -207,7 +207,8 @@ namespace MWWorld attachTo = rotateNode; } - osg::ref_ptr projectile = mResourceSystem->getSceneManager()->getInstance(model, attachTo); + osg::ref_ptr projectile + = mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(model), attachTo); if (state.mIdMagic.size() > 1) { @@ -222,7 +223,8 @@ namespace MWWorld attachTo->accept(findVisitor); if (findVisitor.mFoundNode) mResourceSystem->getSceneManager()->getInstance( - Misc::ResourceHelpers::correctMeshPath(weapon->mModel), findVisitor.mFoundNode); + VFS::Path::toNormalized(Misc::ResourceHelpers::correctMeshPath(weapon->mModel)), + findVisitor.mFoundNode); } } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 52917e92e3..66aa027a89 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/luamanager.hpp" @@ -1094,7 +1095,7 @@ namespace MWWorld class PreloadMeshItem : public SceneUtil::WorkItem { public: - PreloadMeshItem(const std::string& mesh, Resource::SceneManager* sceneManager) + explicit PreloadMeshItem(VFS::Path::NormalizedView mesh, Resource::SceneManager* sceneManager) : mMesh(mesh) , mSceneManager(sceneManager) { @@ -1118,21 +1119,21 @@ namespace MWWorld void abort() override { mAborted = true; } private: - std::string mMesh; + VFS::Path::Normalized mMesh; Resource::SceneManager* mSceneManager; std::atomic_bool mAborted{ false }; }; void Scene::preload(const std::string& mesh, bool useAnim) { - std::string mesh_ = mesh; + std::string meshPath = mesh; if (useAnim) - mesh_ = Misc::ResourceHelpers::correctActorModelPath(mesh_, mRendering.getResourceSystem()->getVFS()); + meshPath = Misc::ResourceHelpers::correctActorModelPath(meshPath, mRendering.getResourceSystem()->getVFS()); - if (!mRendering.getResourceSystem()->getSceneManager()->checkLoaded(mesh_, mRendering.getReferenceTime())) + if (!mRendering.getResourceSystem()->getSceneManager()->checkLoaded(meshPath, mRendering.getReferenceTime())) { - osg::ref_ptr item( - new PreloadMeshItem(mesh_, mRendering.getResourceSystem()->getSceneManager())); + osg::ref_ptr item(new PreloadMeshItem( + VFS::Path::toNormalized(meshPath), mRendering.getResourceSystem()->getSceneManager())); mRendering.getWorkQueue()->addWorkItem(item); const auto isDone = [](const osg::ref_ptr& v) { return v->isDone(); }; mWorkItems.erase(std::remove_if(mWorkItems.begin(), mWorkItems.end(), isDone), mWorkItems.end()); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index bbf15312d3..b52d59d5e7 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -3638,8 +3638,8 @@ namespace MWWorld if (texture.empty()) texture = Fallback::Map::getString("Blood_Texture_0"); - std::string model = Misc::ResourceHelpers::correctMeshPath(std::string{ - Fallback::Map::getString("Blood_Model_" + std::to_string(Misc::Rng::rollDice(3))) } /*[0, 2]*/); + VFS::Path::Normalized model(Misc::ResourceHelpers::correctMeshPath(std::string{ + Fallback::Map::getString("Blood_Model_" + std::to_string(Misc::Rng::rollDice(3))) } /*[0, 2]*/)); mRendering->spawnEffect(model, texture, worldPosition, 1.0f, false); } @@ -3647,7 +3647,7 @@ namespace MWWorld void World::spawnEffect(const std::string& model, const std::string& textureOverride, const osg::Vec3f& worldPos, float scale, bool isMagicVFX) { - mRendering->spawnEffect(model, textureOverride, worldPos, scale, isMagicVFX); + mRendering->spawnEffect(VFS::Path::toNormalized(model), textureOverride, worldPos, scale, isMagicVFX); } struct ResetActorsVisitor diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index d1f48e533f..281a21d860 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -978,11 +978,9 @@ namespace Resource return static_cast(mErrorMarker->clone(osg::CopyOp::DEEP_COPY_ALL)); } - osg::ref_ptr SceneManager::getTemplate(std::string_view name, bool compile) + osg::ref_ptr SceneManager::getTemplate(VFS::Path::NormalizedView path, bool compile) { - const VFS::Path::Normalized normalized(name); - - osg::ref_ptr obj = mCache->getRefFromObjectCache(normalized); + osg::ref_ptr obj = mCache->getRefFromObjectCache(path); if (obj) return osg::ref_ptr(static_cast(obj.get())); else @@ -990,14 +988,14 @@ namespace Resource osg::ref_ptr loaded; try { - loaded = load(normalized, mVFS, mImageManager, mNifFileManager, mBgsmFileManager); + loaded = load(path, mVFS, mImageManager, mNifFileManager, mBgsmFileManager); SceneUtil::ProcessExtraDataVisitor extraDataVisitor(this); loaded->accept(extraDataVisitor); } catch (const std::exception& e) { - Log(Debug::Error) << "Failed to load '" << name << "': " << e.what() << ", using marker_error instead"; + Log(Debug::Error) << "Failed to load '" << path << "': " << e.what() << ", using marker_error instead"; loaded = cloneErrorMarker(); } @@ -1014,7 +1012,7 @@ namespace Resource osg::ref_ptr shaderVisitor(createShaderVisitor()); loaded->accept(*shaderVisitor); - if (canOptimize(normalized)) + if (canOptimize(path.value())) { SceneUtil::Optimizer optimizer; optimizer.setSharedStateManager(mSharedStateManager, &mSharedStateMutex); @@ -1033,15 +1031,14 @@ namespace Resource else loaded->getBound(); - mCache->addEntryToObjectCache(normalized, loaded); + mCache->addEntryToObjectCache(path.value(), loaded); return loaded; } } - osg::ref_ptr SceneManager::getInstance(std::string_view name) + osg::ref_ptr SceneManager::getInstance(VFS::Path::NormalizedView path) { - osg::ref_ptr scene = getTemplate(name); - return getInstance(scene); + return getInstance(getTemplate(path)); } osg::ref_ptr SceneManager::cloneNode(const osg::Node* base) @@ -1079,9 +1076,9 @@ namespace Resource return cloned; } - osg::ref_ptr SceneManager::getInstance(std::string_view name, osg::Group* parentNode) + osg::ref_ptr SceneManager::getInstance(VFS::Path::NormalizedView path, osg::Group* parentNode) { - osg::ref_ptr cloned = getInstance(name); + osg::ref_ptr cloned = getInstance(path); attachTo(cloned, parentNode); return cloned; } diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index 31ad51694c..6ea94233e7 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -158,7 +158,7 @@ namespace Resource /// @note If the given filename does not exist or fails to load, an error marker mesh will be used instead. /// If even the error marker mesh can not be found, an exception is thrown. /// @note Thread safe. - osg::ref_ptr getTemplate(std::string_view name, bool compile = true); + osg::ref_ptr getTemplate(VFS::Path::NormalizedView path, bool compile = true); /// Clone osg::Node safely. /// @note Thread safe. @@ -173,12 +173,12 @@ namespace Resource /// Instance the given scene template. /// @see getTemplate /// @note Thread safe. - osg::ref_ptr getInstance(std::string_view name); + osg::ref_ptr getInstance(VFS::Path::NormalizedView path); /// Instance the given scene template and immediately attach it to a parent node /// @see getTemplate /// @note Not thread safe, unless parentNode is not part of the main scene graph yet. - osg::ref_ptr getInstance(std::string_view name, osg::Group* parentNode); + osg::ref_ptr getInstance(VFS::Path::NormalizedView path, osg::Group* parentNode); /// Attach the given scene instance to the given parent node /// @note You should have the parentNode in its intended position before calling this method, diff --git a/components/vfs/pathutil.hpp b/components/vfs/pathutil.hpp index c836acb032..72c475fae0 100644 --- a/components/vfs/pathutil.hpp +++ b/components/vfs/pathutil.hpp @@ -166,6 +166,8 @@ namespace VFS::Path std::string_view view() const { return mValue; } + bool empty() const { return mValue.empty(); } + operator std::string_view() const { return mValue; } operator const std::string&() const { return mValue; } @@ -183,6 +185,8 @@ namespace VFS::Path return true; } + void clear() { mValue.clear(); } + Normalized& operator=(NormalizedView value) { mValue = value.value(); @@ -284,6 +288,13 @@ namespace VFS::Path return std::hash{}(s.value()); } }; + + // A special function to be removed once conversion to VFS::Path::Normalized* is complete + template + Normalized toNormalized(T&& value) + { + return Normalized(std::forward(value)); + } } #endif