Skip to content

Commit

Permalink
Merge branch 'vfs_normalized_path_11' into 'master'
Browse files Browse the repository at this point in the history
Use normalized path in SceneManager (#8138)

See merge request OpenMW/openmw!4370
  • Loading branch information
psi29a committed Sep 14, 2024
2 parents b32f68f + d8189a5 commit 04fe036
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 68 deletions.
4 changes: 2 additions & 2 deletions apps/opencs/view/render/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace CSVRender
{
auto sceneMgr = mData.getResourceSystem()->getSceneManager();

osg::ref_ptr<osg::Node> temp = sceneMgr->getInstance(model);
osg::ref_ptr<osg::Node> temp = sceneMgr->getInstance(VFS::Path::toNormalized(model));
mSkeleton = dynamic_cast<SceneUtil::Skeleton*>(temp.get());
if (!mSkeleton)
{
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion apps/opencs/view/render/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions apps/openmw/mwrender/actoranimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ namespace MWRender
if (!parent)
return nullptr;

osg::ref_ptr<osg::Node> instance = mResourceSystem->getSceneManager()->getInstance(model, parent);
osg::ref_ptr<osg::Node> instance
= mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(model), parent);

const NodeMap& nodeMap = getNodeMap();
NodeMap::const_iterator found = nodeMap.find(bonename);
Expand All @@ -89,7 +90,8 @@ namespace MWRender
osg::ref_ptr<osg::Node> ActorAnimation::attach(
const std::string& model, std::string_view bonename, std::string_view bonefilter, bool isLight)
{
osg::ref_ptr<const osg::Node> templateNode = mResourceSystem->getSceneManager()->getTemplate(model);
osg::ref_ptr<const osg::Node> templateNode
= mResourceSystem->getSceneManager()->getTemplate(VFS::Path::toNormalized(model));

const NodeMap& nodeMap = getNodeMap();
auto found = nodeMap.find(bonename);
Expand Down Expand Up @@ -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<osg::Node> shieldTemplate = mResourceSystem->getSceneManager()->getInstance(holsteredName);
Expand Down Expand Up @@ -243,7 +245,8 @@ namespace MWRender
// file.
if (shieldNode && !shieldNode->getNumChildren())
{
osg::ref_ptr<osg::Node> fallbackNode = mResourceSystem->getSceneManager()->getInstance(mesh, shieldNode);
osg::ref_ptr<osg::Node> fallbackNode
= mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(mesh), shieldNode);
if (isEnchanted)
SceneUtil::addEnchantedGlow(shieldNode, mResourceSystem, glowColor);
}
Expand Down Expand Up @@ -381,7 +384,7 @@ namespace MWRender
if (!weaponNode->getNumChildren())
{
osg::ref_ptr<osg::Node> fallbackNode
= mResourceSystem->getSceneManager()->getInstance(mesh, weaponNode);
= mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(mesh), weaponNode);
resetControllers(fallbackNode);
}

Expand Down Expand Up @@ -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<osg::Group> arrowNode = ammoNode->getChild(i)->asGroup();
Expand Down
11 changes: 6 additions & 5 deletions apps/openmw/mwrender/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ namespace MWRender
}

void loadBonesFromFile(
osg::ref_ptr<osg::Node>& baseNode, const std::string& model, Resource::ResourceSystem* resourceSystem)
osg::ref_ptr<osg::Node>& baseNode, VFS::Path::NormalizedView model, Resource::ResourceSystem* resourceSystem)
{
const osg::Node* node = resourceSystem->getSceneManager()->getTemplate(model).get();
osg::ref_ptr<osg::Node> sheathSkeleton(
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -1526,7 +1526,7 @@ namespace MWRender
Cache::iterator found = cache.find(model);
if (found == cache.end())
{
osg::ref_ptr<osg::Node> created = sceneMgr->getInstance(model);
osg::ref_ptr<osg::Node> created = sceneMgr->getInstance(VFS::Path::toNormalized(model));

if (inject)
{
Expand All @@ -1547,7 +1547,7 @@ namespace MWRender
}
else
{
osg::ref_ptr<osg::Node> created = sceneMgr->getInstance(model);
osg::ref_ptr<osg::Node> created = sceneMgr->getInstance(VFS::Path::toNormalized(model));

if (inject)
{
Expand Down Expand Up @@ -1762,7 +1762,8 @@ namespace MWRender
}
parentNode->addChild(trans);

osg::ref_ptr<osg::Node> node = mResourceSystem->getSceneManager()->getInstance(model, trans);
osg::ref_ptr<osg::Node> 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(
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/effectmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<osg::Node> node = mResourceSystem->getSceneManager()->getInstance(model);
Expand Down
7 changes: 4 additions & 3 deletions apps/openmw/mwrender/effectmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define OPENMW_MWRENDER_EFFECTMANAGER_H

#include <memory>
#include <string>
#include <vector>

#include <osg/ref_ptr>

#include <components/vfs/pathutil.hpp>

namespace osg
{
class Group;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/esm4npcanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class Record>
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/groundcover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<osg::Node> node = static_cast<osg::Node*>(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));
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/npcanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<osg::Node> shieldTemplate = mResourceSystem->getSceneManager()->getInstance(holsteredName);
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/objectpaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ namespace MWRender
->second;
}

osg::ref_ptr<const osg::Node> cnode = mSceneManager->getTemplate(model, false);
osg::ref_ptr<const osg::Node> cnode = mSceneManager->getTemplate(VFS::Path::toNormalized(model), false);

if (activeGrid)
{
Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwrender/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {};
Expand Down
16 changes: 8 additions & 8 deletions apps/openmw/mwrender/renderingmanager.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#ifndef OPENMW_MWRENDER_RENDERINGMANAGER_H
#define OPENMW_MWRENDER_RENDERINGMANAGER_H

#include <span>
#include "objects.hpp"
#include "renderinginterface.hpp"
#include "rendermode.hpp"

#include <components/settings/settings.hpp>
#include <components/vfs/pathutil.hpp>

#include <osg/Light>
#include <osg/ref_ptr>

#include <components/settings/settings.hpp>

#include <osgUtil/IncrementalCompileOperation>

#include "objects.hpp"
#include "renderinginterface.hpp"
#include "rendermode.hpp"

#include <deque>
#include <memory>
#include <span>
#include <unordered_map>

namespace osg
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/sky.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace MWRender
osg::Vec4f mSkyColour;
osg::Vec4f mFogColour;

std::string mCurrentParticleEffect;
VFS::Path::Normalized mCurrentParticleEffect;

float mRemainingTransitionTime;

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/weaponanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<osg::Node> arrow = getResourceSystem()->getSceneManager()->getInstance(model, parent);

Expand Down
8 changes: 4 additions & 4 deletions apps/openmw/mwscript/miscextensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1714,7 +1714,7 @@ namespace MWScript
for (const T& record : store.get<T>())
{
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);
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwworld/cellpreloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions apps/openmw/mwworld/projectilemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ namespace MWWorld
attachTo = rotateNode;
}

osg::ref_ptr<osg::Node> projectile = mResourceSystem->getSceneManager()->getInstance(model, attachTo);
osg::ref_ptr<osg::Node> projectile
= mResourceSystem->getSceneManager()->getInstance(VFS::Path::toNormalized(model), attachTo);

if (state.mIdMagic.size() > 1)
{
Expand All @@ -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);
}
}

Expand Down
15 changes: 8 additions & 7 deletions apps/openmw/mwworld/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/settings/values.hpp>
#include <components/vfs/pathutil.hpp>

#include "../mwbase/environment.hpp"
#include "../mwbase/luamanager.hpp"
Expand Down Expand Up @@ -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)
{
Expand All @@ -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<PreloadMeshItem> item(
new PreloadMeshItem(mesh_, mRendering.getResourceSystem()->getSceneManager()));
osg::ref_ptr<PreloadMeshItem> item(new PreloadMeshItem(
VFS::Path::toNormalized(meshPath), mRendering.getResourceSystem()->getSceneManager()));
mRendering.getWorkQueue()->addWorkItem(item);
const auto isDone = [](const osg::ref_ptr<SceneUtil::WorkItem>& v) { return v->isDone(); };
mWorkItems.erase(std::remove_if(mWorkItems.begin(), mWorkItems.end(), isDone), mWorkItems.end());
Expand Down
Loading

0 comments on commit 04fe036

Please sign in to comment.