1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-04-01 10:36:42 +00:00

Add NavMeshItem generation to fix update NavMesh for render

This commit is contained in:
elsid 2018-04-21 16:09:49 +03:00
parent f268ec5d34
commit dbb1d99bff
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
7 changed files with 16 additions and 9 deletions

View file

@ -10,6 +10,7 @@ namespace MWRender
NavMesh::NavMesh(const osg::ref_ptr<osg::Group>& root, bool enabled) NavMesh::NavMesh(const osg::ref_ptr<osg::Group>& root, bool enabled)
: mRootNode(root) : mRootNode(root)
, mEnabled(enabled) , mEnabled(enabled)
, mGeneration(0)
, mRevision(0) , mRevision(0)
{ {
} }
@ -30,12 +31,13 @@ namespace MWRender
return mEnabled; return mEnabled;
} }
void NavMesh::update(const DetourNavigator::SharedNavMesh& sharedNavMesh, std::size_t revision, void NavMesh::update(const DetourNavigator::SharedNavMesh& sharedNavMesh, std::size_t generation,
const DetourNavigator::Settings& settings) std::size_t revision, const DetourNavigator::Settings& settings)
{ {
if (!mEnabled || mRevision >= revision) if (!mEnabled || (mGeneration >= generation && mRevision >= revision))
return; return;
mGeneration = generation;
mRevision = revision; mRevision = revision;
if (mGroup) if (mGroup)
mRootNode->removeChild(mGroup); mRootNode->removeChild(mGroup);

View file

@ -21,7 +21,7 @@ namespace MWRender
bool toggle(); 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); const DetourNavigator::Settings& settings);
void enable(); void enable();
@ -31,6 +31,7 @@ namespace MWRender
private: private:
osg::ref_ptr<osg::Group> mRootNode; osg::ref_ptr<osg::Group> mRootNode;
bool mEnabled; bool mEnabled;
std::size_t mGeneration;
std::size_t mRevision; std::size_t mRevision;
osg::ref_ptr<osg::Group> mGroup; osg::ref_ptr<osg::Group> mGroup;
}; };

View file

@ -597,8 +597,8 @@ namespace MWRender
{ {
try try
{ {
mNavMesh->update(navMeshes.begin()->second->mValue, navMeshes.begin()->second->mNavMeshRevision, mNavMesh->update(navMeshes.begin()->second->mValue, navMeshes.begin()->second->mGeneration,
mNavigator.getSettings()); navMeshes.begin()->second->mNavMeshRevision, mNavigator.getSettings());
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {

View file

@ -119,6 +119,8 @@ namespace DetourNavigator
using FloatMs = std::chrono::duration<float, std::milli>; using FloatMs = std::chrono::duration<float, std::milli>;
log("cache updated for agent=", job.mAgentHalfExtents, " status=", status, log("cache updated for agent=", job.mAgentHalfExtents, " status=", status,
" generation=", job.mNavMeshCacheItem->mGeneration,
" revision=", job.mNavMeshCacheItem->mNavMeshRevision,
" time=", std::chrono::duration_cast<FloatMs>(finish - start).count(), "ms", " time=", std::chrono::duration_cast<FloatMs>(finish - start).count(), "ms",
" total_time=", std::chrono::duration_cast<FloatMs>(finish - getFirstStart()).count(), "ms"); " total_time=", std::chrono::duration_cast<FloatMs>(finish - getFirstStart()).count(), "ms");
} }

View file

@ -10,11 +10,12 @@ namespace DetourNavigator
struct NavMeshCacheItem struct NavMeshCacheItem
{ {
SharedNavMesh mValue; SharedNavMesh mValue;
std::size_t mGeneration;
std::size_t mRecastMeshRevision; std::size_t mRecastMeshRevision;
std::atomic_size_t mNavMeshRevision; std::atomic_size_t mNavMeshRevision;
NavMeshCacheItem(const NavMeshPtr& value, std::size_t revision) NavMeshCacheItem(const NavMeshPtr& value, std::size_t generation, std::size_t revision)
: mValue(value), mRecastMeshRevision(revision), mNavMeshRevision(0) {} : mValue(value), mGeneration(generation), mRecastMeshRevision(revision), mNavMeshRevision(0) {}
}; };
} }

View file

@ -45,7 +45,7 @@ namespace DetourNavigator
if (cached != mCache.end()) if (cached != mCache.end())
return; return;
mCache.insert(std::make_pair(agentHalfExtents, mCache.insert(std::make_pair(agentHalfExtents,
std::make_shared<NavMeshCacheItem>(makeEmptyNavMesh(mSettings), mRevision)) std::make_shared<NavMeshCacheItem>(makeEmptyNavMesh(mSettings), ++mGenerationCounter, mRevision))
); );
log("cache add for agent=", agentHalfExtents); log("cache add for agent=", agentHalfExtents);
} }

View file

@ -46,6 +46,7 @@ namespace DetourNavigator
std::map<osg::Vec3f, std::shared_ptr<NavMeshCacheItem>> mCache; std::map<osg::Vec3f, std::shared_ptr<NavMeshCacheItem>> mCache;
std::map<osg::Vec3f, std::set<TilePosition>> mChangedTiles; std::map<osg::Vec3f, std::set<TilePosition>> mChangedTiles;
AsyncNavMeshUpdater mAsyncNavMeshUpdater; AsyncNavMeshUpdater mAsyncNavMeshUpdater;
std::size_t mGenerationCounter = 0;
void addChangedTiles(const btCollisionShape& shape, const btTransform& transform); void addChangedTiles(const btCollisionShape& shape, const btTransform& transform);