Skip to content

Commit 20f77ec

Browse files
committed
Merge branch 'vfs_normalized_path_19' into 'master'
Use normalized path for correctActorModelPath (#8138) See merge request OpenMW/openmw!4443
2 parents 6f9e84b + afa7694 commit 20f77ec

File tree

10 files changed

+41
-48
lines changed

10 files changed

+41
-48
lines changed

apps/navmeshtool/worldspacedata.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ namespace NavMeshTool
121121

122122
for (CellRef& cellRef : cellRefs)
123123
{
124-
std::string model(getModel(esmData, cellRef.mRefId, cellRef.mType));
124+
VFS::Path::Normalized model(getModel(esmData, cellRef.mRefId, cellRef.mType));
125125
if (model.empty())
126126
continue;
127127

apps/opencs/view/render/actor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace CSVRender
4747
mBaseNode->removeChildren(0, mBaseNode->getNumChildren());
4848

4949
// Load skeleton
50-
std::string skeletonModel = mActorData->getSkeleton();
50+
VFS::Path::Normalized skeletonModel = mActorData->getSkeleton();
5151
skeletonModel
5252
= Misc::ResourceHelpers::correctActorModelPath(skeletonModel, mData.getResourceSystem()->getVFS());
5353
loadSkeleton(skeletonModel);

apps/openmw/mwphysics/physicssystem.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ namespace MWPhysics
413413
return;
414414

415415
const VFS::Path::Normalized animationMesh = ptr.getClass().useAnim()
416-
? VFS::Path::toNormalized(
417-
Misc::ResourceHelpers::correctActorModelPath(mesh.value(), mResourceSystem->getVFS()))
416+
? Misc::ResourceHelpers::correctActorModelPath(mesh, mResourceSystem->getVFS())
418417
: VFS::Path::Normalized(mesh);
419418
osg::ref_ptr<Resource::BulletShapeInstance> shapeInstance = mShapeManager->getInstance(animationMesh);
420419
if (!shapeInstance || !shapeInstance->mCollisionShape)
@@ -564,7 +563,7 @@ namespace MWPhysics
564563
void PhysicsSystem::addActor(const MWWorld::Ptr& ptr, VFS::Path::NormalizedView mesh)
565564
{
566565
const VFS::Path::Normalized animationMesh
567-
= Misc::ResourceHelpers::correctActorModelPath(mesh.value(), mResourceSystem->getVFS());
566+
= Misc::ResourceHelpers::correctActorModelPath(mesh, mResourceSystem->getVFS());
568567
osg::ref_ptr<const Resource::BulletShape> shape = mShapeManager->getShape(animationMesh);
569568

570569
// Try to get shape from basic model as fallback for creatures

apps/openmw/mwrender/animation.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,8 @@ namespace MWRender
16251625
const bool werewolf = false;
16261626

16271627
defaultSkeleton = Misc::ResourceHelpers::correctActorModelPath(
1628-
getActorSkeleton(firstPerson, isFemale, isBeast, werewolf), mResourceSystem->getVFS());
1628+
VFS::Path::toNormalized(getActorSkeleton(firstPerson, isFemale, isBeast, werewolf)),
1629+
mResourceSystem->getVFS());
16291630
}
16301631
}
16311632
}

apps/openmw/mwrender/npcanimation.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,14 @@ namespace MWRender
494494
}
495495

496496
const std::string defaultSkeleton = Misc::ResourceHelpers::correctActorModelPath(
497-
getActorSkeleton(is1stPerson, isFemale, isBeast, isWerewolf), mResourceSystem->getVFS());
497+
VFS::Path::toNormalized(getActorSkeleton(is1stPerson, isFemale, isBeast, isWerewolf)),
498+
mResourceSystem->getVFS());
498499

499500
std::string smodel = defaultSkeleton;
500501
bool isCustomModel = false;
501502
if (!is1stPerson && !isWerewolf && !mNpc->mModel.empty())
502503
{
503-
std::string model = Misc::ResourceHelpers::correctMeshPath(mNpc->mModel);
504+
VFS::Path::Normalized model = Misc::ResourceHelpers::correctMeshPath(mNpc->mModel);
504505
isCustomModel = !isDefaultActorSkeleton(model);
505506
smodel = Misc::ResourceHelpers::correctActorModelPath(model, mResourceSystem->getVFS());
506507
}

apps/openmw/mwrender/objects.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ namespace MWRender
7979
std::string animationMesh = mesh;
8080
if (animated && !mesh.empty())
8181
{
82-
animationMesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mResourceSystem->getVFS());
82+
animationMesh = Misc::ResourceHelpers::correctActorModelPath(
83+
VFS::Path::toNormalized(mesh), mResourceSystem->getVFS());
8384
if (animationMesh == mesh && Misc::StringUtils::ciEndsWith(animationMesh, ".nif"))
8485
animated = false;
8586
}
@@ -96,7 +97,8 @@ namespace MWRender
9697
ptr.getRefData().getBaseNode()->setNodeMask(Mask_Actor);
9798

9899
bool animated = true;
99-
std::string animationMesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mResourceSystem->getVFS());
100+
std::string animationMesh
101+
= Misc::ResourceHelpers::correctActorModelPath(VFS::Path::toNormalized(mesh), mResourceSystem->getVFS());
100102
if (animationMesh == mesh && Misc::StringUtils::ciEndsWith(animationMesh, ".nif"))
101103
animated = false;
102104

apps/openmw/mwscript/miscextensions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1437,8 +1437,8 @@ namespace MWScript
14371437
osg::Vec3f pos(ptr.getRefData().getPosition().asVec3());
14381438
msg << "Coordinates: " << pos.x() << " " << pos.y() << " " << pos.z() << std::endl;
14391439
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
1440-
const VFS::Path::Normalized model(
1441-
::Misc::ResourceHelpers::correctActorModelPath(ptr.getClass().getCorrectedModel(ptr), vfs));
1440+
const VFS::Path::Normalized model = ::Misc::ResourceHelpers::correctActorModelPath(
1441+
VFS::Path::toNormalized(ptr.getClass().getCorrectedModel(ptr)), vfs);
14421442
msg << "Model: " << model.value() << std::endl;
14431443
if (!model.empty())
14441444
{

apps/openmw/mwworld/scene.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,9 @@ namespace MWWorld
11261126
void Scene::preload(const std::string& mesh, bool useAnim)
11271127
{
11281128
const VFS::Path::Normalized meshPath = useAnim
1129-
? Misc::ResourceHelpers::correctActorModelPath(mesh, mRendering.getResourceSystem()->getVFS())
1130-
: mesh;
1129+
? Misc::ResourceHelpers::correctActorModelPath(
1130+
VFS::Path::toNormalized(mesh), mRendering.getResourceSystem()->getVFS())
1131+
: VFS::Path::toNormalized(mesh);
11311132

11321133
if (mRendering.getResourceSystem()->getSceneManager()->checkLoaded(meshPath, mRendering.getReferenceTime()))
11331134
return;

components/misc/resourcehelpers.cpp

+22-33
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,16 @@
1616

1717
namespace
1818
{
19-
20-
struct MatchPathSeparator
21-
{
22-
bool operator()(char ch) const { return ch == '\\' || ch == '/'; }
23-
};
24-
25-
std::string getBasename(std::string const& pathname)
26-
{
27-
return std::string(
28-
std::find_if(pathname.rbegin(), pathname.rend(), MatchPathSeparator()).base(), pathname.end());
29-
}
30-
31-
}
32-
33-
bool changeExtension(std::string& path, std::string_view ext)
34-
{
35-
std::string::size_type pos = path.rfind('.');
36-
if (pos != std::string::npos && path.compare(pos, path.length() - pos, ext) != 0)
19+
bool changeExtension(std::string& path, std::string_view ext)
3720
{
38-
path.replace(pos, path.length(), ext);
39-
return true;
21+
std::string::size_type pos = path.rfind('.');
22+
if (pos != std::string::npos && path.compare(pos, path.length() - pos, ext) != 0)
23+
{
24+
path.replace(pos, path.length(), ext);
25+
return true;
26+
}
27+
return false;
4028
}
41-
return false;
4229
}
4330

4431
bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path)
@@ -106,15 +93,16 @@ std::string Misc::ResourceHelpers::correctResourcePath(
10693
// fall back to a resource in the top level directory if it exists
10794
std::string fallback{ topLevelDirectories.front() };
10895
fallback += '\\';
109-
fallback += getBasename(correctedPath);
96+
fallback += Misc::getFileName(correctedPath);
97+
11098
if (vfs->exists(fallback))
11199
return fallback;
112100

113101
if (changedToDds)
114102
{
115103
fallback = topLevelDirectories.front();
116104
fallback += '\\';
117-
fallback += getBasename(origExt);
105+
fallback += Misc::getFileName(origExt);
118106
if (vfs->exists(fallback))
119107
return fallback;
120108
}
@@ -154,22 +142,23 @@ std::string Misc::ResourceHelpers::correctBookartPath(
154142
return image;
155143
}
156144

157-
std::string Misc::ResourceHelpers::correctActorModelPath(std::string_view resPath, const VFS::Manager* vfs)
145+
VFS::Path::Normalized Misc::ResourceHelpers::correctActorModelPath(
146+
VFS::Path::NormalizedView resPath, const VFS::Manager* vfs)
158147
{
159-
std::string mdlname(resPath);
160-
std::string::size_type p = mdlname.find_last_of("/\\");
148+
std::string mdlname(resPath.value());
149+
std::string::size_type p = mdlname.find_last_of('/');
161150
if (p != std::string::npos)
162-
mdlname.insert(mdlname.begin() + p + 1, 'x');
151+
mdlname.insert(mdlname.begin() + static_cast<std::string::difference_type>(p) + 1, 'x');
163152
else
164153
mdlname.insert(mdlname.begin(), 'x');
165-
std::string kfname = mdlname;
166-
if (Misc::StringUtils::ciEndsWith(kfname, ".nif"))
167-
kfname.replace(kfname.size() - 4, 4, ".kf");
154+
155+
VFS::Path::Normalized kfname(mdlname);
156+
if (Misc::getFileExtension(mdlname) == "nif")
157+
kfname.changeExtension("kf");
168158

169159
if (!vfs->exists(kfname))
170-
{
171-
return std::string(resPath);
172-
}
160+
return VFS::Path::Normalized(resPath);
161+
173162
return mdlname;
174163
}
175164

components/misc/resourcehelpers.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Misc
3333
std::string correctBookartPath(std::string_view resPath, int width, int height, const VFS::Manager* vfs);
3434
/// Use "xfoo.nif" instead of "foo.nif" if "xfoo.kf" is available
3535
/// Note that if "xfoo.nif" is actually unavailable, we can't fall back to "foo.nif". :(
36-
std::string correctActorModelPath(std::string_view resPath, const VFS::Manager* vfs);
36+
VFS::Path::Normalized correctActorModelPath(VFS::Path::NormalizedView resPath, const VFS::Manager* vfs);
3737
std::string correctMaterialPath(std::string_view resPath, const VFS::Manager* vfs);
3838

3939
// Adds "meshes\\".

0 commit comments

Comments
 (0)