1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00

Add option to disable DetourNavigator component to find paths

This commit is contained in:
elsid 2019-02-16 15:50:58 +03:00
parent 34c594f01e
commit 9626b6ec42
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40
5 changed files with 110 additions and 11 deletions

View File

@ -25,6 +25,7 @@
#include <components/detournavigator/debug.hpp>
#include <components/detournavigator/navigatorimpl.hpp>
#include <components/detournavigator/navigatorstub.hpp>
#include <components/detournavigator/recastglobalallocator.hpp>
#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<DetourNavigator::FileSink>(
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<DetourNavigator::FileSink>(
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()));

View File

@ -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<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const override
{
return std::map<osg::Vec3f, SharedNavMeshCacheItem>();
}
Settings getSettings() const override
{
return Settings {};
}
};
}
#endif

View File

@ -6,8 +6,11 @@
namespace DetourNavigator
{
Settings makeSettingsFromSettingsManager()
boost::optional<Settings> makeSettingsFromSettingsManager()
{
if (!::Settings::Manager::getBool("enable", "Navigator"))
return boost::optional<Settings>();
Settings navigatorSettings;
navigatorSettings.mBorderSize = ::Settings::Manager::getInt("border size", "Navigator");

View File

@ -1,6 +1,8 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H
#include <boost/optional.hpp>
#include <string>
namespace DetourNavigator
@ -37,7 +39,7 @@ namespace DetourNavigator
std::string mNavMeshPathPrefix;
};
Settings makeSettingsFromSettingsManager();
boost::optional<Settings> makeSettingsFromSettingsManager();
}
#endif

View File

@ -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: