1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-25 13:11:37 +00:00

Initialize navigator max climb and max slope settings in makeSettingsFromSettingsManager

To avoid having multiple places to initialize them when they will be required
by multiple binaries.
This commit is contained in:
elsid 2021-07-03 04:09:55 +02:00
parent d6613d3677
commit 6986feb81b
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
8 changed files with 25 additions and 24 deletions

View file

@ -3,7 +3,6 @@
namespace MWPhysics namespace MWPhysics
{ {
static constexpr float sStepSizeUp = 34.0f;
static constexpr float sStepSizeDown = 62.0f; static constexpr float sStepSizeDown = 62.0f;
static constexpr float sMinStep = 10.0f; // hack to skip over tiny unwalkable slopes static constexpr float sMinStep = 10.0f; // hack to skip over tiny unwalkable slopes
@ -12,7 +11,6 @@ namespace MWPhysics
static constexpr bool sDoExtraStairHacks = true; static constexpr bool sDoExtraStairHacks = true;
static constexpr float sGroundOffset = 1.0f; static constexpr float sGroundOffset = 1.0f;
static constexpr float sMaxSlope = 46.0f;
// Arbitrary number. To prevent infinite loops. They shouldn't happen but it's good to be prepared. // Arbitrary number. To prevent infinite loops. They shouldn't happen but it's good to be prepared.
static constexpr int sMaxIterations = 8; static constexpr int sMaxIterations = 8;

View file

@ -230,7 +230,7 @@ namespace MWPhysics
float hitHeight = tracer.mHitPoint.z() - tracer.mEndPos.z() + actor.mHalfExtentsZ; float hitHeight = tracer.mHitPoint.z() - tracer.mEndPos.z() + actor.mHalfExtentsZ;
osg::Vec3f oldPosition = newPosition; osg::Vec3f oldPosition = newPosition;
bool usedStepLogic = false; bool usedStepLogic = false;
if (hitHeight < sStepSizeUp && !isActor(tracer.mHitObject)) if (hitHeight < Constants::sStepSizeUp && !isActor(tracer.mHitObject))
{ {
// Try to step up onto it. // Try to step up onto it.
// NOTE: this modifies newPosition and velocity on its own if successful // NOTE: this modifies newPosition and velocity on its own if successful

View file

@ -3,7 +3,8 @@
#include <osg/Vec3f> #include <osg/Vec3f>
#include "constants.hpp" #include <components/misc/constants.hpp>
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
class btCollisionWorld; class btCollisionWorld;
@ -30,7 +31,7 @@ namespace MWPhysics
template <class Vec3> template <class Vec3>
static bool isWalkableSlope(const Vec3 &normal) static bool isWalkableSlope(const Vec3 &normal)
{ {
static const float sMaxSlopeCos = std::cos(osg::DegreesToRadians(sMaxSlope)); static const float sMaxSlopeCos = std::cos(osg::DegreesToRadians(Constants::sMaxSlope));
return (normal.z() > sMaxSlopeCos); return (normal.z() > sMaxSlopeCos);
} }

View file

@ -3,6 +3,8 @@
#include <BulletCollision/CollisionDispatch/btCollisionObject.h> #include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h> #include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <components/misc/constants.hpp>
#include "collisiontype.hpp" #include "collisiontype.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "movementsolver.hpp" #include "movementsolver.hpp"
@ -13,7 +15,7 @@ namespace MWPhysics
{ {
if (!stepper.mHitObject) if (!stepper.mHitObject)
return false; return false;
static const float sMaxSlopeCos = std::cos(osg::DegreesToRadians(sMaxSlope)); static const float sMaxSlopeCos = std::cos(osg::DegreesToRadians(Constants::sMaxSlope));
if (stepper.mPlaneNormal.z() <= sMaxSlopeCos) if (stepper.mPlaneNormal.z() <= sMaxSlopeCos)
return false; return false;
@ -34,13 +36,13 @@ namespace MWPhysics
// Stairstepping algorithms work by moving up to avoid the step, moving forwards, then moving back down onto the ground. // Stairstepping algorithms work by moving up to avoid the step, moving forwards, then moving back down onto the ground.
// This algorithm has a couple of minor problems, but they don't cause problems for sane geometry, and just prevent stepping on insane geometry. // This algorithm has a couple of minor problems, but they don't cause problems for sane geometry, and just prevent stepping on insane geometry.
mUpStepper.doTrace(mColObj, position, position+osg::Vec3f(0.0f,0.0f,sStepSizeUp), mColWorld); mUpStepper.doTrace(mColObj, position, position + osg::Vec3f(0.0f, 0.0f, Constants::sStepSizeUp), mColWorld);
float upDistance = 0; float upDistance = 0;
if(!mUpStepper.mHitObject) if(!mUpStepper.mHitObject)
upDistance = sStepSizeUp; upDistance = Constants::sStepSizeUp;
else if(mUpStepper.mFraction*sStepSizeUp > sCollisionMargin) else if(mUpStepper.mFraction * Constants::sStepSizeUp > sCollisionMargin)
upDistance = mUpStepper.mFraction*sStepSizeUp - sCollisionMargin; upDistance = mUpStepper.mFraction * Constants::sStepSizeUp - sCollisionMargin;
else else
{ {
return false; return false;
@ -76,9 +78,9 @@ namespace MWPhysics
} }
else if(attempt == 3) else if(attempt == 3)
{ {
if(upDistance > sStepSizeUp) if(upDistance > Constants::sStepSizeUp)
{ {
upDistance = sStepSizeUp; upDistance = Constants::sStepSizeUp;
tracerPos = position + osg::Vec3f(0.0f, 0.0f, upDistance); tracerPos = position + osg::Vec3f(0.0f, 0.0f, upDistance);
} }
moveDistance = sMinStep2; moveDistance = sMinStep2;

View file

@ -173,13 +173,12 @@ namespace MWWorld
mPhysics.reset(new MWPhysics::PhysicsSystem(resourceSystem, rootNode)); mPhysics.reset(new MWPhysics::PhysicsSystem(resourceSystem, rootNode));
if (auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager()) if (Settings::Manager::getBool("enable", "Navigator"))
{ {
navigatorSettings->mMaxClimb = MWPhysics::sStepSizeUp; auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager();
navigatorSettings->mMaxSlope = MWPhysics::sMaxSlope; navigatorSettings.mSwimHeightScale = mSwimHeightScale;
navigatorSettings->mSwimHeightScale = mSwimHeightScale;
DetourNavigator::RecastGlobalAllocator::init(); DetourNavigator::RecastGlobalAllocator::init();
mNavigator.reset(new DetourNavigator::NavigatorImpl(*navigatorSettings)); mNavigator.reset(new DetourNavigator::NavigatorImpl(navigatorSettings));
} }
else else
{ {

View file

@ -1,14 +1,12 @@
#include "settings.hpp" #include "settings.hpp"
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
#include <components/misc/constants.hpp>
namespace DetourNavigator namespace DetourNavigator
{ {
std::optional<Settings> makeSettingsFromSettingsManager() Settings makeSettingsFromSettingsManager()
{ {
if (!::Settings::Manager::getBool("enable", "Navigator"))
return std::optional<Settings>();
Settings navigatorSettings; Settings navigatorSettings;
navigatorSettings.mBorderSize = ::Settings::Manager::getInt("border size", "Navigator"); navigatorSettings.mBorderSize = ::Settings::Manager::getInt("border size", "Navigator");
@ -16,9 +14,9 @@ namespace DetourNavigator
navigatorSettings.mCellSize = ::Settings::Manager::getFloat("cell size", "Navigator"); navigatorSettings.mCellSize = ::Settings::Manager::getFloat("cell size", "Navigator");
navigatorSettings.mDetailSampleDist = ::Settings::Manager::getFloat("detail sample dist", "Navigator"); navigatorSettings.mDetailSampleDist = ::Settings::Manager::getFloat("detail sample dist", "Navigator");
navigatorSettings.mDetailSampleMaxError = ::Settings::Manager::getFloat("detail sample max error", "Navigator"); navigatorSettings.mDetailSampleMaxError = ::Settings::Manager::getFloat("detail sample max error", "Navigator");
navigatorSettings.mMaxClimb = 0; navigatorSettings.mMaxClimb = Constants::sStepSizeUp;
navigatorSettings.mMaxSimplificationError = ::Settings::Manager::getFloat("max simplification error", "Navigator"); navigatorSettings.mMaxSimplificationError = ::Settings::Manager::getFloat("max simplification error", "Navigator");
navigatorSettings.mMaxSlope = 0; navigatorSettings.mMaxSlope = Constants::sMaxSlope;
navigatorSettings.mRecastScaleFactor = ::Settings::Manager::getFloat("recast scale factor", "Navigator"); navigatorSettings.mRecastScaleFactor = ::Settings::Manager::getFloat("recast scale factor", "Navigator");
navigatorSettings.mSwimHeightScale = 0; navigatorSettings.mSwimHeightScale = 0;
navigatorSettings.mMaxEdgeLen = ::Settings::Manager::getInt("max edge len", "Navigator"); navigatorSettings.mMaxEdgeLen = ::Settings::Manager::getInt("max edge len", "Navigator");

View file

@ -41,7 +41,7 @@ namespace DetourNavigator
std::chrono::milliseconds mMinUpdateInterval; std::chrono::milliseconds mMinUpdateInterval;
}; };
std::optional<Settings> makeSettingsFromSettingsManager(); Settings makeSettingsFromSettingsManager();
} }
#endif #endif

View file

@ -36,6 +36,9 @@ const std::string HerbalismLabel = "HerbalismSwitch";
// Percentage height at which projectiles are spawned from an actor // Percentage height at which projectiles are spawned from an actor
const float TorsoHeight = 0.75f; const float TorsoHeight = 0.75f;
static constexpr float sStepSizeUp = 34.0f;
static constexpr float sMaxSlope = 46.0f;
} }
#endif #endif