From f2e47d640d15dc5b1e96f34dd1ca18245ad8d0b0 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 22 Feb 2019 01:22:10 +0300 Subject: [PATCH] Add option to limit max number of navmesh tiles --- .../detournavigator/navigator.cpp | 1 + components/detournavigator/makenavmesh.cpp | 2 +- components/detournavigator/navmeshmanager.cpp | 2 +- components/detournavigator/settings.cpp | 1 + components/detournavigator/settings.hpp | 1 + .../reference/modding/settings/navigator.rst | 24 +++++++++++++++++++ files/settings-default.cfg | 3 +++ 7 files changed, 32 insertions(+), 2 deletions(-) diff --git a/apps/openmw_test_suite/detournavigator/navigator.cpp b/apps/openmw_test_suite/detournavigator/navigator.cpp index 42b69d7f9..9daef6f64 100644 --- a/apps/openmw_test_suite/detournavigator/navigator.cpp +++ b/apps/openmw_test_suite/detournavigator/navigator.cpp @@ -61,6 +61,7 @@ namespace mSettings.mMaxSmoothPathSize = 1024; mSettings.mTrianglesPerChunk = 256; mSettings.mMaxPolys = 4096; + mSettings.mMaxTilesNumber = 512; mNavigator.reset(new NavigatorImpl(mSettings)); } }; diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index e62509940..5ac28127e 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -628,7 +628,7 @@ namespace DetourNavigator return removeTile(); } - if (!shouldAddTile(changedTile, playerTile, params.maxTiles)) + if (!shouldAddTile(changedTile, playerTile, std::min(settings.mMaxTilesNumber, params.maxTiles))) { log("ignore add tile: too far from player"); return removeTile(); diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index 2a29d1dd4..217c17e41 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -157,7 +157,7 @@ namespace DetourNavigator if (changedTiles->second.empty()) mChangedTiles.erase(changedTiles); } - const auto maxTiles = navMesh.getParams()->maxTiles; + const auto maxTiles = std::min(mSettings.mMaxTilesNumber, navMesh.getParams()->maxTiles); mRecastMeshManager.forEachTilePosition([&] (const TilePosition& tile) { if (tilesToPost.count(tile)) diff --git a/components/detournavigator/settings.cpp b/components/detournavigator/settings.cpp index ddffd0d1f..735194dba 100644 --- a/components/detournavigator/settings.cpp +++ b/components/detournavigator/settings.cpp @@ -24,6 +24,7 @@ namespace DetourNavigator navigatorSettings.mMaxEdgeLen = ::Settings::Manager::getInt("max edge len", "Navigator"); navigatorSettings.mMaxNavMeshQueryNodes = ::Settings::Manager::getInt("max nav mesh query nodes", "Navigator"); navigatorSettings.mMaxPolys = ::Settings::Manager::getInt("max polygons per tile", "Navigator"); + navigatorSettings.mMaxTilesNumber = ::Settings::Manager::getInt("max tiles number", "Navigator"); navigatorSettings.mMaxVertsPerPoly = ::Settings::Manager::getInt("max verts per poly", "Navigator"); navigatorSettings.mRegionMergeSize = ::Settings::Manager::getInt("region merge size", "Navigator"); navigatorSettings.mRegionMinSize = ::Settings::Manager::getInt("region min size", "Navigator"); diff --git a/components/detournavigator/settings.hpp b/components/detournavigator/settings.hpp index 0316092a0..dc0e5dc5a 100644 --- a/components/detournavigator/settings.hpp +++ b/components/detournavigator/settings.hpp @@ -26,6 +26,7 @@ namespace DetourNavigator int mMaxEdgeLen = 0; int mMaxNavMeshQueryNodes = 0; int mMaxPolys = 0; + int mMaxTilesNumber = 0; int mMaxVertsPerPoly = 0; int mRegionMergeSize = 0; int mRegionMinSize = 0; diff --git a/docs/source/reference/modding/settings/navigator.rst b/docs/source/reference/modding/settings/navigator.rst index 1b65c35a8..d9ddf5381 100644 --- a/docs/source/reference/modding/settings/navigator.rst +++ b/docs/source/reference/modding/settings/navigator.rst @@ -24,6 +24,24 @@ Moving across external world, entering/exiting location produce nav mesh update. NPC and creatures may not be able to find path before nav mesh is built around them. Try to disable this if you want to have old fashioned AI which doesn't know where to go when you stand behind that stone and casting a firebolt. +max tiles number +---------------- + +:Type: integer +:Range: >= 0 +:Default: 512 + +Number of tiles at nav mesh. +Nav mesh covers circle area around player. +This option allows to set an explicit limit for nav mesh size, how many tiles should fit into circle. +If actor is inside this area it able to find path over nav mesh. +Increasing this value may decrease performance. + +.. note:: + Don't expect infinite nav mesh size increasing. + This condition is always true: ``max tiles number * max polygons per tile <= 4194304``. + It's a limitation of `Recastnavigation `_ library. + Advanced settings ***************** @@ -322,6 +340,12 @@ Maximum number of polygons per nav mesh tile. Maximum number of nav mesh tiles d this value. 22 bits is a limit to store both tile identifier and polygon identifier (tiles = 2^(22 - log2(polygons))). See `recastnavigation `_ for more details. +.. Warning:: + Lower value may lead to ignored world geometry on nav mesh. + Greater value will reduce number of nav mesh tiles. + This condition is always true: ``max tiles number * max polygons per tile <= 4194304``. + It's a limitation of `Recastnavigation `_ library. + max verts per poly ------------------ diff --git a/files/settings-default.cfg b/files/settings-default.cfg index e3920a4bf..e95646602 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -670,6 +670,9 @@ enable nav mesh render = false # Render agents paths (true, false) enable agents paths render = false +# Max number of navmesh tiles (value >= 0) +max tiles number = 512 + [Shadows] # Enable or disable shadows. Bear in mind that this will force OpenMW to use shaders as if "[Shaders]/force shaders" was set to true.