From 6986feb81b3a5a0154fafe415b5fa68fa6cdd223 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 3 Jul 2021 04:09:55 +0200 Subject: [PATCH] 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. --- apps/openmw/mwphysics/constants.hpp | 2 -- apps/openmw/mwphysics/movementsolver.cpp | 2 +- apps/openmw/mwphysics/movementsolver.hpp | 5 +++-- apps/openmw/mwphysics/stepper.cpp | 16 +++++++++------- apps/openmw/mwworld/worldimp.cpp | 9 ++++----- components/detournavigator/settings.cpp | 10 ++++------ components/detournavigator/settings.hpp | 2 +- components/misc/constants.hpp | 3 +++ 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/apps/openmw/mwphysics/constants.hpp b/apps/openmw/mwphysics/constants.hpp index 2d7cd53d38..c275b63c7b 100644 --- a/apps/openmw/mwphysics/constants.hpp +++ b/apps/openmw/mwphysics/constants.hpp @@ -3,7 +3,6 @@ namespace MWPhysics { - static constexpr float sStepSizeUp = 34.0f; static constexpr float sStepSizeDown = 62.0f; 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 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. static constexpr int sMaxIterations = 8; diff --git a/apps/openmw/mwphysics/movementsolver.cpp b/apps/openmw/mwphysics/movementsolver.cpp index df9239dd83..44a5391f0d 100644 --- a/apps/openmw/mwphysics/movementsolver.cpp +++ b/apps/openmw/mwphysics/movementsolver.cpp @@ -230,7 +230,7 @@ namespace MWPhysics float hitHeight = tracer.mHitPoint.z() - tracer.mEndPos.z() + actor.mHalfExtentsZ; osg::Vec3f oldPosition = newPosition; bool usedStepLogic = false; - if (hitHeight < sStepSizeUp && !isActor(tracer.mHitObject)) + if (hitHeight < Constants::sStepSizeUp && !isActor(tracer.mHitObject)) { // Try to step up onto it. // NOTE: this modifies newPosition and velocity on its own if successful diff --git a/apps/openmw/mwphysics/movementsolver.hpp b/apps/openmw/mwphysics/movementsolver.hpp index 90b10c275e..30733eeec8 100644 --- a/apps/openmw/mwphysics/movementsolver.hpp +++ b/apps/openmw/mwphysics/movementsolver.hpp @@ -3,7 +3,8 @@ #include -#include "constants.hpp" +#include + #include "../mwworld/ptr.hpp" class btCollisionWorld; @@ -30,7 +31,7 @@ namespace MWPhysics template 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); } diff --git a/apps/openmw/mwphysics/stepper.cpp b/apps/openmw/mwphysics/stepper.cpp index 1f53c1ac51..af85658910 100644 --- a/apps/openmw/mwphysics/stepper.cpp +++ b/apps/openmw/mwphysics/stepper.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include "collisiontype.hpp" #include "constants.hpp" #include "movementsolver.hpp" @@ -13,7 +15,7 @@ namespace MWPhysics { if (!stepper.mHitObject) 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) 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. // 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; if(!mUpStepper.mHitObject) - upDistance = sStepSizeUp; - else if(mUpStepper.mFraction*sStepSizeUp > sCollisionMargin) - upDistance = mUpStepper.mFraction*sStepSizeUp - sCollisionMargin; + upDistance = Constants::sStepSizeUp; + else if(mUpStepper.mFraction * Constants::sStepSizeUp > sCollisionMargin) + upDistance = mUpStepper.mFraction * Constants::sStepSizeUp - sCollisionMargin; else { return false; @@ -76,9 +78,9 @@ namespace MWPhysics } 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); } moveDistance = sMinStep2; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 4fd9235586..57ad8fc149 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -173,13 +173,12 @@ namespace MWWorld mPhysics.reset(new MWPhysics::PhysicsSystem(resourceSystem, rootNode)); - if (auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager()) + if (Settings::Manager::getBool("enable", "Navigator")) { - navigatorSettings->mMaxClimb = MWPhysics::sStepSizeUp; - navigatorSettings->mMaxSlope = MWPhysics::sMaxSlope; - navigatorSettings->mSwimHeightScale = mSwimHeightScale; + auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager(); + navigatorSettings.mSwimHeightScale = mSwimHeightScale; DetourNavigator::RecastGlobalAllocator::init(); - mNavigator.reset(new DetourNavigator::NavigatorImpl(*navigatorSettings)); + mNavigator.reset(new DetourNavigator::NavigatorImpl(navigatorSettings)); } else { diff --git a/components/detournavigator/settings.cpp b/components/detournavigator/settings.cpp index ff99fae20c..e428f3695a 100644 --- a/components/detournavigator/settings.cpp +++ b/components/detournavigator/settings.cpp @@ -1,14 +1,12 @@ #include "settings.hpp" #include +#include namespace DetourNavigator { - std::optional makeSettingsFromSettingsManager() + Settings makeSettingsFromSettingsManager() { - if (!::Settings::Manager::getBool("enable", "Navigator")) - return std::optional(); - Settings navigatorSettings; navigatorSettings.mBorderSize = ::Settings::Manager::getInt("border size", "Navigator"); @@ -16,9 +14,9 @@ namespace DetourNavigator navigatorSettings.mCellSize = ::Settings::Manager::getFloat("cell size", "Navigator"); navigatorSettings.mDetailSampleDist = ::Settings::Manager::getFloat("detail sample dist", "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.mMaxSlope = 0; + navigatorSettings.mMaxSlope = Constants::sMaxSlope; navigatorSettings.mRecastScaleFactor = ::Settings::Manager::getFloat("recast scale factor", "Navigator"); navigatorSettings.mSwimHeightScale = 0; navigatorSettings.mMaxEdgeLen = ::Settings::Manager::getInt("max edge len", "Navigator"); diff --git a/components/detournavigator/settings.hpp b/components/detournavigator/settings.hpp index 39f5815b8e..800ad6b2bb 100644 --- a/components/detournavigator/settings.hpp +++ b/components/detournavigator/settings.hpp @@ -41,7 +41,7 @@ namespace DetourNavigator std::chrono::milliseconds mMinUpdateInterval; }; - std::optional makeSettingsFromSettingsManager(); + Settings makeSettingsFromSettingsManager(); } #endif diff --git a/components/misc/constants.hpp b/components/misc/constants.hpp index bfd3933fc7..01d783a4fc 100644 --- a/components/misc/constants.hpp +++ b/components/misc/constants.hpp @@ -36,6 +36,9 @@ const std::string HerbalismLabel = "HerbalismSwitch"; // Percentage height at which projectiles are spawned from an actor const float TorsoHeight = 0.75f; +static constexpr float sStepSizeUp = 34.0f; +static constexpr float sMaxSlope = 46.0f; + } #endif