From 7c80bb94116aee03a25b1b509befee59f096a040 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 22 Sep 2018 17:49:57 +0300 Subject: [PATCH] Support multiple threads for async nav mesh updater --- apps/openmw/mwworld/worldimp.cpp | 1 + apps/openmw_test_suite/detournavigator/navigator.cpp | 1 + components/detournavigator/asyncnavmeshupdater.cpp | 6 ++++-- components/detournavigator/asyncnavmeshupdater.hpp | 2 +- components/detournavigator/settings.hpp | 1 + files/settings-default.cfg | 3 +++ 6 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 6cfba1e26..83a238280 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -215,6 +215,7 @@ namespace MWWorld navigatorSettings.mRegionMergeSize = Settings::Manager::getInt("region merge size", "Navigator"); navigatorSettings.mRegionMinSize = Settings::Manager::getInt("region min size", "Navigator"); navigatorSettings.mTileSize = Settings::Manager::getInt("tile size", "Navigator"); + navigatorSettings.mAsyncNavMeshUpdaterThreads = static_cast(Settings::Manager::getInt("async nav mesh updater threads", "Navigator")); navigatorSettings.mMaxPolygonPathSize = static_cast(Settings::Manager::getInt("max polygon path size", "Navigator")); navigatorSettings.mMaxSmoothPathSize = static_cast(Settings::Manager::getInt("max smooth path size", "Navigator")); navigatorSettings.mTrianglesPerChunk = static_cast(Settings::Manager::getInt("triangles per chunk", "Navigator")); diff --git a/apps/openmw_test_suite/detournavigator/navigator.cpp b/apps/openmw_test_suite/detournavigator/navigator.cpp index 52e350572..7e188f8fd 100644 --- a/apps/openmw_test_suite/detournavigator/navigator.cpp +++ b/apps/openmw_test_suite/detournavigator/navigator.cpp @@ -55,6 +55,7 @@ namespace mSettings.mRegionMergeSize = 20; mSettings.mRegionMinSize = 8; mSettings.mTileSize = 64; + mSettings.mAsyncNavMeshUpdaterThreads = 1; mSettings.mMaxPolygonPathSize = 1024; mSettings.mMaxSmoothPathSize = 1024; mSettings.mTrianglesPerChunk = 256; diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index 168ec8f41..ba3de3583 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -52,8 +52,9 @@ namespace DetourNavigator , mRecastMeshManager(recastMeshManager) , mOffMeshConnectionsManager(offMeshConnectionsManager) , mShouldStop() - , mThread([&] { process(); }) { + for (std::size_t i = 0; i < mSettings.get().mAsyncNavMeshUpdaterThreads; ++i) + mThreads.emplace_back([&] { process(); }); } AsyncNavMeshUpdater::~AsyncNavMeshUpdater() @@ -63,7 +64,8 @@ namespace DetourNavigator mJobs = decltype(mJobs)(); mHasJob.notify_all(); lock.unlock(); - mThread.join(); + for (auto& thread : mThreads) + thread.join(); } void AsyncNavMeshUpdater::post(const osg::Vec3f& agentHalfExtents, diff --git a/components/detournavigator/asyncnavmeshupdater.hpp b/components/detournavigator/asyncnavmeshupdater.hpp index d2d72a290..8d3184887 100644 --- a/components/detournavigator/asyncnavmeshupdater.hpp +++ b/components/detournavigator/asyncnavmeshupdater.hpp @@ -71,7 +71,7 @@ namespace DetourNavigator TilePosition mPlayerTile; std::mutex mFirstStartMutex; boost::optional mFirstStart; - std::thread mThread; + std::vector mThreads; void process() throw(); diff --git a/components/detournavigator/settings.hpp b/components/detournavigator/settings.hpp index ccfece3da..9f6ca97be 100644 --- a/components/detournavigator/settings.hpp +++ b/components/detournavigator/settings.hpp @@ -27,6 +27,7 @@ namespace DetourNavigator int mRegionMergeSize; int mRegionMinSize; int mTileSize; + std::size_t mAsyncNavMeshUpdaterThreads; std::size_t mMaxPolygonPathSize; std::size_t mMaxSmoothPathSize; std::size_t mTrianglesPerChunk; diff --git a/files/settings-default.cfg b/files/settings-default.cfg index c046a19b3..29333682e 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -585,6 +585,9 @@ region merge size = 20 # The minimum number of cells allowed to form isolated island areas. (value >= 0) region min size = 8 +# Number of background threads to update nav mesh (value >= 1) +async nav mesh updater threads = 1 + # Maximum size of path over polygons (value > 0) max polygon path size = 1024