From dbb1d99bffe88aaece0f0079ce1470d6e1c8e18b Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 21 Apr 2018 16:09:49 +0300 Subject: [PATCH] Add NavMeshItem generation to fix update NavMesh for render --- apps/openmw/mwrender/navmesh.cpp | 8 +++++--- apps/openmw/mwrender/navmesh.hpp | 3 ++- apps/openmw/mwrender/renderingmanager.cpp | 4 ++-- components/detournavigator/asyncnavmeshupdater.cpp | 2 ++ components/detournavigator/navmeshcacheitem.hpp | 5 +++-- components/detournavigator/navmeshmanager.cpp | 2 +- components/detournavigator/navmeshmanager.hpp | 1 + 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwrender/navmesh.cpp b/apps/openmw/mwrender/navmesh.cpp index 79ee33b973..787e332e92 100644 --- a/apps/openmw/mwrender/navmesh.cpp +++ b/apps/openmw/mwrender/navmesh.cpp @@ -10,6 +10,7 @@ namespace MWRender NavMesh::NavMesh(const osg::ref_ptr& root, bool enabled) : mRootNode(root) , mEnabled(enabled) + , mGeneration(0) , mRevision(0) { } @@ -30,12 +31,13 @@ namespace MWRender return mEnabled; } - void NavMesh::update(const DetourNavigator::SharedNavMesh& sharedNavMesh, std::size_t revision, - const DetourNavigator::Settings& settings) + void NavMesh::update(const DetourNavigator::SharedNavMesh& sharedNavMesh, std::size_t generation, + std::size_t revision, const DetourNavigator::Settings& settings) { - if (!mEnabled || mRevision >= revision) + if (!mEnabled || (mGeneration >= generation && mRevision >= revision)) return; + mGeneration = generation; mRevision = revision; if (mGroup) mRootNode->removeChild(mGroup); diff --git a/apps/openmw/mwrender/navmesh.hpp b/apps/openmw/mwrender/navmesh.hpp index a6c1f086ea..0bed616f9c 100644 --- a/apps/openmw/mwrender/navmesh.hpp +++ b/apps/openmw/mwrender/navmesh.hpp @@ -21,7 +21,7 @@ namespace MWRender bool toggle(); - void update(const DetourNavigator::SharedNavMesh& sharedNavMesh, std::size_t revision, + void update(const DetourNavigator::SharedNavMesh& sharedNavMesh, std::size_t generation, std::size_t revision, const DetourNavigator::Settings& settings); void enable(); @@ -31,6 +31,7 @@ namespace MWRender private: osg::ref_ptr mRootNode; bool mEnabled; + std::size_t mGeneration; std::size_t mRevision; osg::ref_ptr mGroup; }; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 400a2d05ce..fbe8ba3459 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -597,8 +597,8 @@ namespace MWRender { try { - mNavMesh->update(navMeshes.begin()->second->mValue, navMeshes.begin()->second->mNavMeshRevision, - mNavigator.getSettings()); + mNavMesh->update(navMeshes.begin()->second->mValue, navMeshes.begin()->second->mGeneration, + navMeshes.begin()->second->mNavMeshRevision, mNavigator.getSettings()); } catch (const std::exception& e) { diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index c9fca3c92f..b809fc27c9 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -119,6 +119,8 @@ namespace DetourNavigator using FloatMs = std::chrono::duration; log("cache updated for agent=", job.mAgentHalfExtents, " status=", status, + " generation=", job.mNavMeshCacheItem->mGeneration, + " revision=", job.mNavMeshCacheItem->mNavMeshRevision, " time=", std::chrono::duration_cast(finish - start).count(), "ms", " total_time=", std::chrono::duration_cast(finish - getFirstStart()).count(), "ms"); } diff --git a/components/detournavigator/navmeshcacheitem.hpp b/components/detournavigator/navmeshcacheitem.hpp index 4c73fd05d1..ffea1fbddc 100644 --- a/components/detournavigator/navmeshcacheitem.hpp +++ b/components/detournavigator/navmeshcacheitem.hpp @@ -10,11 +10,12 @@ namespace DetourNavigator struct NavMeshCacheItem { SharedNavMesh mValue; + std::size_t mGeneration; std::size_t mRecastMeshRevision; std::atomic_size_t mNavMeshRevision; - NavMeshCacheItem(const NavMeshPtr& value, std::size_t revision) - : mValue(value), mRecastMeshRevision(revision), mNavMeshRevision(0) {} + NavMeshCacheItem(const NavMeshPtr& value, std::size_t generation, std::size_t revision) + : mValue(value), mGeneration(generation), mRecastMeshRevision(revision), mNavMeshRevision(0) {} }; } diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index eeaae309d3..ad9a3a5e70 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -45,7 +45,7 @@ namespace DetourNavigator if (cached != mCache.end()) return; mCache.insert(std::make_pair(agentHalfExtents, - std::make_shared(makeEmptyNavMesh(mSettings), mRevision)) + std::make_shared(makeEmptyNavMesh(mSettings), ++mGenerationCounter, mRevision)) ); log("cache add for agent=", agentHalfExtents); } diff --git a/components/detournavigator/navmeshmanager.hpp b/components/detournavigator/navmeshmanager.hpp index 4f7d9d24dd..63733cf018 100644 --- a/components/detournavigator/navmeshmanager.hpp +++ b/components/detournavigator/navmeshmanager.hpp @@ -46,6 +46,7 @@ namespace DetourNavigator std::map> mCache; std::map> mChangedTiles; AsyncNavMeshUpdater mAsyncNavMeshUpdater; + std::size_t mGenerationCounter = 0; void addChangedTiles(const btCollisionShape& shape, const btTransform& transform);