From 518e34b403bb907410579fd136106787b4b25597 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 10 Mar 2019 14:24:03 +0300 Subject: [PATCH 1/7] Remove useless variables --- apps/openmw/mwworld/scene.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 6655bef4be..8cccb2fc5a 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -338,7 +338,7 @@ namespace MWWorld { if (const auto object = mPhysics->getObject(ptr)) navigator->removeObject(DetourNavigator::ObjectId(object)); - else if (const auto actor = mPhysics->getActor(ptr)) + else if (mPhysics->getActor(ptr)) { navigator->removeAgent(world->getPathfindingHalfExtents(ptr)); mRendering.removeActorPath(ptr); @@ -809,7 +809,7 @@ namespace MWWorld const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr(); navigator->update(player.getRefData().getPosition().asVec3()); } - else if (const auto actor = mPhysics->getActor(ptr)) + else if (mPhysics->getActor(ptr)) { navigator->removeAgent(MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(ptr)); } From ce9aebcba14965ddca14801488e83810a89f3a0e Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 17 Feb 2019 00:52:20 +0300 Subject: [PATCH 2/7] Clear all changed tiles after post --- components/detournavigator/navmeshmanager.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index 03a8b055fd..c9af545932 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -172,10 +172,6 @@ namespace DetourNavigator else tileToPost->second = addChangeType(tileToPost->second, tile.second); } - for (const auto& tile : tilesToPost) - changedTiles->second.erase(tile.first); - if (changedTiles->second.empty()) - mChangedTiles.erase(changedTiles); } const auto maxTiles = std::min(mSettings.mMaxTilesNumber, navMesh.getParams()->maxTiles); mRecastMeshManager.forEachTilePosition([&] (const TilePosition& tile) @@ -191,6 +187,8 @@ namespace DetourNavigator }); } mAsyncNavMeshUpdater.post(agentHalfExtents, cached, playerTile, tilesToPost); + if (changedTiles != mChangedTiles.end()) + changedTiles->second.clear(); log("cache update posted for agent=", agentHalfExtents, " playerTile=", lastPlayerTile->second, " recastMeshManagerRevision=", lastRevision); From c05fc9e054dbf2cae27993aef421a03150ac0605 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 18 Feb 2019 01:29:11 +0300 Subject: [PATCH 3/7] Add missing cleanup --- components/detournavigator/navmeshmanager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index c9af545932..9723366f95 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -105,6 +105,9 @@ namespace DetourNavigator if (!resetIfUnique(it->second)) return false; mCache.erase(agentHalfExtents); + mChangedTiles.erase(agentHalfExtents); + mPlayerTile.erase(agentHalfExtents); + mLastRecastMeshManagerRevision.erase(agentHalfExtents); return true; } From ece111d05a238b4b49d810eef878298d6665156d Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 19 Feb 2019 03:05:15 +0300 Subject: [PATCH 4/7] Check for jobs using predicate --- components/detournavigator/asyncnavmeshupdater.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index e9172f041b..bb2605a5ba 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -162,9 +162,7 @@ namespace DetourNavigator boost::optional AsyncNavMeshUpdater::getNextJob() { std::unique_lock lock(mMutex); - if (mJobs.empty()) - mHasJob.wait_for(lock, std::chrono::milliseconds(10)); - if (mJobs.empty()) + if (!mHasJob.wait_for(lock, std::chrono::milliseconds(10), [&] { return !mJobs.empty(); })) { mFirstStart.lock()->reset(); mDone.notify_all(); From 8d2af94b75fb9c893270ef9df27f6a29ecf6e23b Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 19 Feb 2019 11:46:00 +0300 Subject: [PATCH 5/7] Use default objects for NavigatorStub methods result --- components/detournavigator/navigator.hpp | 2 +- components/detournavigator/navigatorimpl.cpp | 2 +- components/detournavigator/navigatorimpl.hpp | 2 +- components/detournavigator/navigatorstub.hpp | 13 +++++++++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/components/detournavigator/navigator.hpp b/components/detournavigator/navigator.hpp index cc62d61640..baf56145bb 100644 --- a/components/detournavigator/navigator.hpp +++ b/components/detournavigator/navigator.hpp @@ -191,7 +191,7 @@ namespace DetourNavigator */ virtual std::map getNavMeshes() const = 0; - virtual Settings getSettings() const = 0; + virtual const Settings& getSettings() const = 0; }; } diff --git a/components/detournavigator/navigatorimpl.cpp b/components/detournavigator/navigatorimpl.cpp index 2e16b6d04d..a62220e555 100644 --- a/components/detournavigator/navigatorimpl.cpp +++ b/components/detournavigator/navigatorimpl.cpp @@ -133,7 +133,7 @@ namespace DetourNavigator return mNavMeshManager.getNavMeshes(); } - Settings NavigatorImpl::getSettings() const + const Settings& NavigatorImpl::getSettings() const { return mSettings; } diff --git a/components/detournavigator/navigatorimpl.hpp b/components/detournavigator/navigatorimpl.hpp index 8156f6655e..d2ff8a57bd 100644 --- a/components/detournavigator/navigatorimpl.hpp +++ b/components/detournavigator/navigatorimpl.hpp @@ -46,7 +46,7 @@ namespace DetourNavigator std::map getNavMeshes() const override; - Settings getSettings() const override; + const Settings& getSettings() const override; private: Settings mSettings; diff --git a/components/detournavigator/navigatorstub.hpp b/components/detournavigator/navigatorstub.hpp index 5d82d2f59f..cab93b1052 100644 --- a/components/detournavigator/navigatorstub.hpp +++ b/components/detournavigator/navigatorstub.hpp @@ -5,8 +5,9 @@ namespace DetourNavigator { - struct NavigatorStub final : public Navigator + class NavigatorStub final : public Navigator { + public: NavigatorStub() = default; void addAgent(const osg::Vec3f& /*agentHalfExtents*/) override {} @@ -65,7 +66,7 @@ namespace DetourNavigator SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& /*agentHalfExtents*/) const override { - return SharedNavMeshCacheItem(); + return mEmptyNavMeshCacheItem; } std::map getNavMeshes() const override @@ -73,10 +74,14 @@ namespace DetourNavigator return std::map(); } - Settings getSettings() const override + const Settings& getSettings() const override { - return Settings {}; + return mDefaultSettings; } + + private: + Settings mDefaultSettings {}; + SharedNavMeshCacheItem mEmptyNavMeshCacheItem; }; } From 849f2078c134f670fce9a95318f508fe7bcc380e Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 22 Feb 2019 23:52:00 +0300 Subject: [PATCH 6/7] Swap outside critical section --- components/detournavigator/tilecachedrecastmeshmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/detournavigator/tilecachedrecastmeshmanager.cpp b/components/detournavigator/tilecachedrecastmeshmanager.cpp index b878c2d3e4..0cb1cfb807 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -61,8 +61,8 @@ namespace DetourNavigator for (const auto& tile : currentTiles) if (!newTiles.count(tile) && removeTile(id, tile, tiles.get())) changedTiles.push_back(tile); - std::swap(currentTiles, newTiles); } + std::swap(currentTiles, newTiles); if (!changedTiles.empty()) ++mRevision; return changedTiles; From 4395a92c354cf9ff2a1516df1ab4545588f78e12 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 10 Mar 2019 19:08:30 +0300 Subject: [PATCH 7/7] Use display list to render navmesh Slightly improves performance of massive navmesh rendering. --- components/sceneutil/detourdebugdraw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sceneutil/detourdebugdraw.cpp b/components/sceneutil/detourdebugdraw.cpp index a0ae67dc29..046bbb08cf 100644 --- a/components/sceneutil/detourdebugdraw.cpp +++ b/components/sceneutil/detourdebugdraw.cpp @@ -102,7 +102,7 @@ namespace SceneUtil osg::ref_ptr geometry(new osg::Geometry); geometry->setStateSet(stateSet); - geometry->setUseDisplayList(false); + geometry->setUseDisplayList(true); geometry->setVertexArray(mVertices); geometry->setColorArray(mColors, osg::Array::BIND_PER_VERTEX); geometry->addPrimitiveSet(new osg::DrawArrays(mMode, 0, static_cast(mVertices->size())));