mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-20 15:40:32 +00:00
Add NavMeshItem generation to fix update NavMesh for render
This commit is contained in:
parent
f268ec5d34
commit
dbb1d99bff
@ -10,6 +10,7 @@ namespace MWRender
|
||||
NavMesh::NavMesh(const osg::ref_ptr<osg::Group>& 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);
|
||||
|
@ -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<osg::Group> mRootNode;
|
||||
bool mEnabled;
|
||||
std::size_t mGeneration;
|
||||
std::size_t mRevision;
|
||||
osg::ref_ptr<osg::Group> mGroup;
|
||||
};
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -119,6 +119,8 @@ namespace DetourNavigator
|
||||
using FloatMs = std::chrono::duration<float, std::milli>;
|
||||
|
||||
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",
|
||||
" total_time=", std::chrono::duration_cast<FloatMs>(finish - getFirstStart()).count(), "ms");
|
||||
}
|
||||
|
@ -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) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace DetourNavigator
|
||||
if (cached != mCache.end())
|
||||
return;
|
||||
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);
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ namespace DetourNavigator
|
||||
std::map<osg::Vec3f, std::shared_ptr<NavMeshCacheItem>> mCache;
|
||||
std::map<osg::Vec3f, std::set<TilePosition>> mChangedTiles;
|
||||
AsyncNavMeshUpdater mAsyncNavMeshUpdater;
|
||||
std::size_t mGenerationCounter = 0;
|
||||
|
||||
void addChangedTiles(const btCollisionShape& shape, const btTransform& transform);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user