diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 65d629384..d7963fae1 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include "../mwbase/environment.hpp" @@ -198,15 +199,21 @@ namespace MWWorld mPhysics.reset(new MWPhysics::PhysicsSystem(resourceSystem, rootNode)); - auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager(); - navigatorSettings.mMaxClimb = MWPhysics::sStepSizeUp; - navigatorSettings.mMaxSlope = MWPhysics::sMaxSlope; - navigatorSettings.mSwimHeightScale = mSwimHeightScale; - if (Settings::Manager::getBool("enable log", "Navigator")) - DetourNavigator::Log::instance().setSink(std::unique_ptr( - new DetourNavigator::FileSink(Settings::Manager::getString("log path", "Navigator")))); - DetourNavigator::RecastGlobalAllocator::init(); - mNavigator.reset(new DetourNavigator::NavigatorImpl(navigatorSettings)); + if (auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager()) + { + navigatorSettings->mMaxClimb = MWPhysics::sStepSizeUp; + navigatorSettings->mMaxSlope = MWPhysics::sMaxSlope; + navigatorSettings->mSwimHeightScale = mSwimHeightScale; + if (Settings::Manager::getBool("enable log", "Navigator")) + DetourNavigator::Log::instance().setSink(std::unique_ptr( + new DetourNavigator::FileSink(Settings::Manager::getString("log path", "Navigator")))); + DetourNavigator::RecastGlobalAllocator::init(); + mNavigator.reset(new DetourNavigator::NavigatorImpl(*navigatorSettings)); + } + else + { + mNavigator.reset(new DetourNavigator::NavigatorStub()); + } mRendering.reset(new MWRender::RenderingManager(viewer, rootNode, resourceSystem, workQueue, &mFallback, resourcePath, *mNavigator)); mProjectileManager.reset(new ProjectileManager(mRendering->getLightRoot(), resourceSystem, mRendering.get(), mPhysics.get())); diff --git a/components/detournavigator/navigatorstub.hpp b/components/detournavigator/navigatorstub.hpp new file mode 100644 index 000000000..5d82d2f59 --- /dev/null +++ b/components/detournavigator/navigatorstub.hpp @@ -0,0 +1,83 @@ +#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVIGATORSTUB_H +#define OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVIGATORSTUB_H + +#include "navigator.hpp" + +namespace DetourNavigator +{ + struct NavigatorStub final : public Navigator + { + NavigatorStub() = default; + + void addAgent(const osg::Vec3f& /*agentHalfExtents*/) override {} + + void removeAgent(const osg::Vec3f& /*agentHalfExtents*/) override {} + + bool addObject(const ObjectId /*id*/, const btCollisionShape& /*shape*/, const btTransform& /*transform*/) override + { + return false; + } + + bool addObject(const ObjectId /*id*/, const ObjectShapes& /*shapes*/, const btTransform& /*transform*/) override + { + return false; + } + + bool addObject(const ObjectId /*id*/, const DoorShapes& /*shapes*/, const btTransform& /*transform*/) override + { + return false; + } + + bool updateObject(const ObjectId /*id*/, const btCollisionShape& /*shape*/, const btTransform& /*transform*/) override + { + return false; + } + + bool updateObject(const ObjectId /*id*/, const ObjectShapes& /*shapes*/, const btTransform& /*transform*/) override + { + return false; + } + + bool updateObject(const ObjectId /*id*/, const DoorShapes& /*shapes*/, const btTransform& /*transform*/) override + { + return false; + } + + bool removeObject(const ObjectId /*id*/) override + { + return false; + } + + bool addWater(const osg::Vec2i& /*cellPosition*/, const int /*cellSize*/, const btScalar /*level*/, + const btTransform& /*transform*/) override + { + return false; + } + + bool removeWater(const osg::Vec2i& /*cellPosition*/) override + { + return false; + } + + void update(const osg::Vec3f& /*playerPosition*/) override {} + + void wait() override {} + + SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& /*agentHalfExtents*/) const override + { + return SharedNavMeshCacheItem(); + } + + std::map getNavMeshes() const override + { + return std::map(); + } + + Settings getSettings() const override + { + return Settings {}; + } + }; +} + +#endif diff --git a/components/detournavigator/settings.cpp b/components/detournavigator/settings.cpp index 0b9210a90..f584e48f9 100644 --- a/components/detournavigator/settings.cpp +++ b/components/detournavigator/settings.cpp @@ -6,8 +6,11 @@ namespace DetourNavigator { - Settings makeSettingsFromSettingsManager() + boost::optional makeSettingsFromSettingsManager() { + if (!::Settings::Manager::getBool("enable", "Navigator")) + return boost::optional(); + Settings navigatorSettings; navigatorSettings.mBorderSize = ::Settings::Manager::getInt("border size", "Navigator"); diff --git a/components/detournavigator/settings.hpp b/components/detournavigator/settings.hpp index dda193fff..0316092a0 100644 --- a/components/detournavigator/settings.hpp +++ b/components/detournavigator/settings.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H +#include + #include namespace DetourNavigator @@ -37,7 +39,7 @@ namespace DetourNavigator std::string mNavMeshPathPrefix; }; - Settings makeSettingsFromSettingsManager(); + boost::optional makeSettingsFromSettingsManager(); } #endif diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 71a93d1a2..81df700cc 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -542,6 +542,10 @@ companion h = 0.63 [Navigator] +# Enable navigator (true, false). When enabled background threads are started to build navmesh for world geometry. +# Pathfinding system uses navmesh to build paths. When disabled only pathgrid is used to build paths. +enable = true + # Scale of NavMesh coordinates to world coordinates (value > 0.0). Recastnavigation builds voxels for world geometry. # Basically voxel size is 1 / "cell size". To reduce amount of voxels we apply scale factor, to make voxel size # "recast scale factor" / "cell size". Default value calculates by this equation: