From d2ab3662336d805413b4a89e005c5fcefdc1040d Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 13 Oct 2024 22:49:26 +0200 Subject: [PATCH] Use normalized path in PhysicsSystem --- apps/openmw/mwclass/activator.cpp | 2 +- apps/openmw/mwclass/actor.cpp | 2 +- apps/openmw/mwclass/container.cpp | 2 +- apps/openmw/mwclass/door.cpp | 2 +- apps/openmw/mwclass/esm4base.cpp | 2 +- apps/openmw/mwclass/light.cpp | 2 +- apps/openmw/mwclass/static.cpp | 2 +- apps/openmw/mwphysics/physicssystem.cpp | 13 +++++++------ apps/openmw/mwphysics/physicssystem.hpp | 8 +++++--- apps/openmw/mwworld/worldimp.cpp | 3 ++- components/misc/resourcehelpers.cpp | 6 +++--- components/misc/resourcehelpers.hpp | 2 +- 12 files changed, 25 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index e0ee315bc1..6de211e557 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -59,7 +59,7 @@ namespace MWClass void Activator::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const { - physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World); + physics.addObject(ptr, VFS::Path::toNormalized(model), rotation, MWPhysics::CollisionType_World); } std::string_view Activator::getModel(const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/actor.cpp b/apps/openmw/mwclass/actor.cpp index 0a45a85a74..ea0b0d07b3 100644 --- a/apps/openmw/mwclass/actor.cpp +++ b/apps/openmw/mwclass/actor.cpp @@ -27,7 +27,7 @@ namespace MWClass void Actor::insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const { - physics.addActor(ptr, model); + physics.addActor(ptr, VFS::Path::toNormalized(model)); if (getCreatureStats(ptr).isDead() && getCreatureStats(ptr).isDeathAnimationFinished()) MWBase::Environment::get().getWorld()->enableActorCollision(ptr, false); } diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 5cf9bf919a..8327904ecd 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -124,7 +124,7 @@ namespace MWClass void Container::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const { - physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World); + physics.addObject(ptr, VFS::Path::toNormalized(model), rotation, MWPhysics::CollisionType_World); } std::string_view Container::getModel(const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index e31da8415d..9fe7e92ffa 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -82,7 +82,7 @@ namespace MWClass void Door::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const { - physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_Door); + physics.addObject(ptr, VFS::Path::toNormalized(model), rotation, MWPhysics::CollisionType_Door); } bool Door::isDoor() const diff --git a/apps/openmw/mwclass/esm4base.cpp b/apps/openmw/mwclass/esm4base.cpp index 77a5ad94a6..17af545348 100644 --- a/apps/openmw/mwclass/esm4base.cpp +++ b/apps/openmw/mwclass/esm4base.cpp @@ -29,7 +29,7 @@ namespace MWClass void ESM4Impl::insertObjectPhysics( const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) { - physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World); + physics.addObject(ptr, VFS::Path::toNormalized(model), rotation, MWPhysics::CollisionType_World); } MWGui::ToolTipInfo ESM4Impl::getToolTipInfo(std::string_view name, int count) diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 763ce86326..9aa5e2c67d 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -63,7 +63,7 @@ namespace MWClass { // TODO: add option somewhere to enable collision for placeable objects if ((ptr.get()->mBase->mData.mFlags & ESM::Light::Carry) == 0) - physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World); + physics.addObject(ptr, VFS::Path::toNormalized(model), rotation, MWPhysics::CollisionType_World); } bool Light::useAnim() const diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index 502a4fcb66..65fe58ea76 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -40,7 +40,7 @@ namespace MWClass void Static::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const { - physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World); + physics.addObject(ptr, VFS::Path::toNormalized(model), rotation, MWPhysics::CollisionType_World); } std::string_view Static::getModel(const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 5601b486d0..83ffb9d701 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -407,14 +407,15 @@ namespace MWPhysics } void PhysicsSystem::addObject( - const MWWorld::Ptr& ptr, const std::string& mesh, osg::Quat rotation, int collisionType) + const MWWorld::Ptr& ptr, VFS::Path::NormalizedView mesh, osg::Quat rotation, int collisionType) { if (ptr.mRef->mData.mPhysicsPostponed) return; const VFS::Path::Normalized animationMesh = ptr.getClass().useAnim() - ? Misc::ResourceHelpers::correctActorModelPath(mesh, mResourceSystem->getVFS()) - : mesh; + ? VFS::Path::toNormalized( + Misc::ResourceHelpers::correctActorModelPath(mesh.value(), mResourceSystem->getVFS())) + : VFS::Path::Normalized(mesh); osg::ref_ptr shapeInstance = mShapeManager->getInstance(animationMesh); if (!shapeInstance || !shapeInstance->mCollisionShape) return; @@ -560,10 +561,10 @@ namespace MWPhysics } } - void PhysicsSystem::addActor(const MWWorld::Ptr& ptr, const std::string& mesh) + void PhysicsSystem::addActor(const MWWorld::Ptr& ptr, VFS::Path::NormalizedView mesh) { const VFS::Path::Normalized animationMesh - = Misc::ResourceHelpers::correctActorModelPath(mesh, mResourceSystem->getVFS()); + = Misc::ResourceHelpers::correctActorModelPath(mesh.value(), mResourceSystem->getVFS()); osg::ref_ptr shape = mShapeManager->getShape(animationMesh); // Try to get shape from basic model as fallback for creatures @@ -589,7 +590,7 @@ namespace MWPhysics } int PhysicsSystem::addProjectile( - const MWWorld::Ptr& caster, const osg::Vec3f& position, const std::string& mesh, bool computeRadius) + const MWWorld::Ptr& caster, const osg::Vec3f& position, VFS::Path::NormalizedView mesh, bool computeRadius) { osg::ref_ptr shapeInstance = mShapeManager->getInstance(VFS::Path::toNormalized(mesh)); diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index d7f1933a79..546d72676e 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -16,6 +16,8 @@ #include #include +#include + #include "../mwworld/ptr.hpp" #include "collisiontype.hpp" @@ -159,12 +161,12 @@ namespace MWPhysics void setWaterHeight(float height); void disableWater(); - void addObject(const MWWorld::Ptr& ptr, const std::string& mesh, osg::Quat rotation, + void addObject(const MWWorld::Ptr& ptr, VFS::Path::NormalizedView mesh, osg::Quat rotation, int collisionType = CollisionType_World); - void addActor(const MWWorld::Ptr& ptr, const std::string& mesh); + void addActor(const MWWorld::Ptr& ptr, VFS::Path::NormalizedView mesh); int addProjectile( - const MWWorld::Ptr& caster, const osg::Vec3f& position, const std::string& mesh, bool computeRadius); + const MWWorld::Ptr& caster, const osg::Vec3f& position, VFS::Path::NormalizedView mesh, bool computeRadius); void setCaster(int projectileId, const MWWorld::Ptr& caster); void removeProjectile(const int projectileId); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 84f4a6de2c..658dee56c7 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2331,7 +2331,8 @@ namespace MWWorld MWBase::Environment::get().getWindowManager()->watchActor(getPlayerPtr()); mPhysics->remove(getPlayerPtr()); - mPhysics->addActor(getPlayerPtr(), getPlayerPtr().getClass().getCorrectedModel(getPlayerPtr())); + mPhysics->addActor( + getPlayerPtr(), VFS::Path::toNormalized(getPlayerPtr().getClass().getCorrectedModel(getPlayerPtr()))); applyLoopingParticles(player); diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index 1728e51c7a..eba3acdc7a 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -154,9 +154,9 @@ std::string Misc::ResourceHelpers::correctBookartPath( return image; } -std::string Misc::ResourceHelpers::correctActorModelPath(const std::string& resPath, const VFS::Manager* vfs) +std::string Misc::ResourceHelpers::correctActorModelPath(std::string_view resPath, const VFS::Manager* vfs) { - std::string mdlname = resPath; + std::string mdlname(resPath); std::string::size_type p = mdlname.find_last_of("/\\"); if (p != std::string::npos) mdlname.insert(mdlname.begin() + p + 1, 'x'); @@ -168,7 +168,7 @@ std::string Misc::ResourceHelpers::correctActorModelPath(const std::string& resP if (!vfs->exists(kfname)) { - return resPath; + return std::string(resPath); } return mdlname; } diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp index 069d921fa9..f97e865770 100644 --- a/components/misc/resourcehelpers.hpp +++ b/components/misc/resourcehelpers.hpp @@ -33,7 +33,7 @@ namespace Misc std::string correctBookartPath(std::string_view resPath, int width, int height, const VFS::Manager* vfs); /// Use "xfoo.nif" instead of "foo.nif" if "xfoo.kf" is available /// Note that if "xfoo.nif" is actually unavailable, we can't fall back to "foo.nif". :( - std::string correctActorModelPath(const std::string& resPath, const VFS::Manager* vfs); + std::string correctActorModelPath(std::string_view resPath, const VFS::Manager* vfs); std::string correctMaterialPath(std::string_view resPath, const VFS::Manager* vfs); // Adds "meshes\\".