From b04c9584105781bb475c01aee5366421a544aa91 Mon Sep 17 00:00:00 2001 From: fredzio Date: Thu, 22 Jul 2021 00:08:44 +0200 Subject: [PATCH] Modify the way swimming is handled: - compute the swimming state instead of storing it, it changes as part of the simulation and was not updated, so it was wrong anyway. - store the swim level in ActorFrameData, it is constant per Actor so no need to compute it inside the simulation --- apps/openmw/mwphysics/movementsolver.cpp | 3 +-- apps/openmw/mwphysics/mtphysics.cpp | 9 +++++++-- apps/openmw/mwphysics/physicssystem.cpp | 3 ++- apps/openmw/mwphysics/physicssystem.hpp | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwphysics/movementsolver.cpp b/apps/openmw/mwphysics/movementsolver.cpp index fd72ea3220..ccb9105147 100644 --- a/apps/openmw/mwphysics/movementsolver.cpp +++ b/apps/openmw/mwphysics/movementsolver.cpp @@ -140,8 +140,7 @@ namespace MWPhysics osg::Vec3f halfExtents = physicActor->getHalfExtents(); actor.mPosition.z() += halfExtents.z(); // vanilla-accurate - static const float fSwimHeightScale = MWBase::Environment::get().getWorld()->getStore().get().find("fSwimHeightScale")->mValue.getFloat(); - float swimlevel = actor.mWaterlevel + halfExtents.z() - (physicActor->getRenderingHalfExtents().z() * 2 * fSwimHeightScale); + float swimlevel = actor.mSwimLevel + halfExtents.z(); ActorTracer tracer; diff --git a/apps/openmw/mwphysics/mtphysics.cpp b/apps/openmw/mwphysics/mtphysics.cpp index 68a69a5c6d..de390aee1f 100644 --- a/apps/openmw/mwphysics/mtphysics.cpp +++ b/apps/openmw/mwphysics/mtphysics.cpp @@ -49,13 +49,18 @@ namespace bool mCanBeSharedLock; }; + bool isUnderWater(const MWPhysics::ActorFrameData& actorData) + { + return actorData.mPosition.z() < actorData.mSwimLevel; + } + void handleFall(MWPhysics::ActorFrameData& actorData, bool simulationPerformed) { const float heightDiff = actorData.mPosition.z() - actorData.mOldHeight; const bool isStillOnGround = (simulationPerformed && actorData.mWasOnGround && actorData.mIsOnGround); - if (isStillOnGround || actorData.mFlying || actorData.mSwimming || actorData.mSlowFall < 1) + if (isStillOnGround || actorData.mFlying || isUnderWater(actorData) || actorData.mSlowFall < 1) actorData.mNeedLand = true; else if (heightDiff < 0) actorData.mFallHeight += heightDiff; @@ -67,7 +72,7 @@ namespace MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); if (actorData.mNeedLand) - stats.land(ptr == MWMechanics::getPlayer() && (actorData.mFlying || actorData.mSwimming)); + stats.land(ptr == MWMechanics::getPlayer() && (actorData.mFlying || isUnderWater(actorData))); else if (actorData.mFallHeight < 0) stats.addToFallHeight(-actorData.mFallHeight); } diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 7757b3eb65..f67e732751 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -1007,10 +1007,11 @@ namespace MWPhysics const MWBase::World *world = MWBase::Environment::get().getWorld(); const auto ptr = actor->getPtr(); mFlying = world->isFlying(ptr); - mSwimming = world->isSwimming(ptr); const auto& stats = ptr.getClass().getCreatureStats(ptr); const bool godmode = ptr == world->getPlayerConstPtr() && world->getGodModeState(); mInert = stats.isDead() || (!godmode && stats.getMagicEffects().get(ESM::MagicEffect::Paralyze).getModifier() > 0); + static const float fSwimHeightScale = MWBase::Environment::get().getWorld()->getStore().get().find("fSwimHeightScale")->mValue.getFloat(); + mSwimLevel = mWaterlevel - (actor->getRenderingHalfExtents().z() * 2 * fSwimHeightScale); } void ActorFrameData::updatePosition(btCollisionWorld* world) diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index e5e1aa0c06..e4c67ed188 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -84,7 +84,6 @@ namespace MWPhysics Actor* mActorRaw; MWWorld::Ptr mStandingOn; bool mFlying; - bool mSwimming; bool mWasOnGround; bool mIsOnGround; bool mIsOnSlope; @@ -94,6 +93,7 @@ namespace MWPhysics bool mWalkingOnWater; bool mSkipCollisionDetection; float mWaterlevel; + float mSwimLevel; float mSlowFall; float mOldHeight; float mFallHeight;