mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 07:15:36 +00:00
Store guarded navmesh cache item in shared_ptr
Remove useless SharedGuarded type.
This commit is contained in:
parent
0479ebf5ae
commit
ccc709a316
7 changed files with 11 additions and 42 deletions
|
@ -1446,7 +1446,7 @@ namespace MWRender
|
|||
{
|
||||
try
|
||||
{
|
||||
const auto locked = it->second.lockConst();
|
||||
const auto locked = it->second->lockConst();
|
||||
mNavMesh->update(locked->getValue(), mNavMeshNumber, locked->getGeneration(),
|
||||
locked->getNavMeshRevision(), mNavigator.getSettings());
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ namespace DetourNavigator
|
|||
using FloatMs = std::chrono::duration<float, std::milli>;
|
||||
|
||||
{
|
||||
const auto locked = job.mNavMeshCacheItem.lockConst();
|
||||
const auto locked = job.mNavMeshCacheItem->lockConst();
|
||||
log("cache updated for agent=", job.mAgentHalfExtents, " status=", status,
|
||||
" generation=", locked->getGeneration(),
|
||||
" revision=", locked->getNavMeshRevision(),
|
||||
|
@ -194,7 +194,7 @@ namespace DetourNavigator
|
|||
writeToFile(*recastMesh, mSettings.get().mRecastMeshPathPrefix + std::to_string(job.mChangedTile.x())
|
||||
+ "_" + std::to_string(job.mChangedTile.y()) + "_", recastMeshRevision);
|
||||
if (mSettings.get().mEnableWriteNavMeshToFile)
|
||||
writeToFile(job.mNavMeshCacheItem.lockConst()->getValue(), mSettings.get().mNavMeshPathPrefix, navMeshRevision);
|
||||
writeToFile(job.mNavMeshCacheItem->lockConst()->getValue(), mSettings.get().mNavMeshPathPrefix, navMeshRevision);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point AsyncNavMeshUpdater::setFirstStart(const std::chrono::steady_clock::time_point& value)
|
||||
|
|
|
@ -521,7 +521,7 @@ namespace
|
|||
UpdateNavMeshStatus replaceTile(const SharedNavMeshCacheItem& navMeshCacheItem,
|
||||
const TilePosition& changedTile, T&& navMeshData)
|
||||
{
|
||||
const auto locked = navMeshCacheItem.lock();
|
||||
const auto locked = navMeshCacheItem->lock();
|
||||
auto& navMesh = locked->getValue();
|
||||
const int layer = 0;
|
||||
const auto tileRef = navMesh.getTileRefAt(changedTile.x(), changedTile.y(), layer);
|
||||
|
@ -591,14 +591,14 @@ namespace DetourNavigator
|
|||
" playerTile=", playerTile,
|
||||
" changedTileDistance=", getDistance(changedTile, playerTile));
|
||||
|
||||
const auto params = *navMeshCacheItem.lockConst()->getValue().getParams();
|
||||
const auto params = *navMeshCacheItem->lockConst()->getValue().getParams();
|
||||
const osg::Vec3f origin(params.orig[0], params.orig[1], params.orig[2]);
|
||||
|
||||
const auto x = changedTile.x();
|
||||
const auto y = changedTile.y();
|
||||
|
||||
const auto removeTile = [&] {
|
||||
const auto locked = navMeshCacheItem.lock();
|
||||
const auto locked = navMeshCacheItem->lock();
|
||||
auto& navMesh = locked->getValue();
|
||||
const auto tileRef = navMesh.getTileRefAt(x, y, 0);
|
||||
const auto removed = dtStatusSucceed(navMesh.removeTile(tileRef, nullptr, nullptr));
|
||||
|
|
|
@ -174,7 +174,7 @@ namespace DetourNavigator
|
|||
if (!navMesh)
|
||||
return out;
|
||||
const auto settings = getSettings();
|
||||
return findSmoothPath(navMesh.lock()->getValue(), toNavMeshCoordinates(settings, agentHalfExtents),
|
||||
return findSmoothPath(navMesh->lockConst()->getValue(), toNavMeshCoordinates(settings, agentHalfExtents),
|
||||
toNavMeshCoordinates(settings, stepSize), toNavMeshCoordinates(settings, start),
|
||||
toNavMeshCoordinates(settings, end), includeFlags, settings, out);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ namespace DetourNavigator
|
|||
std::map<TilePosition, std::pair<NavMeshTilesCache::Value, NavMeshData>> mUsedTiles;
|
||||
};
|
||||
|
||||
using SharedNavMeshCacheItem = Misc::SharedGuarded<NavMeshCacheItem>;
|
||||
using GuardedNavMeshCacheItem = Misc::ScopeGuarded<NavMeshCacheItem>;
|
||||
using SharedNavMeshCacheItem = std::shared_ptr<GuardedNavMeshCacheItem>;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -93,7 +93,7 @@ namespace DetourNavigator
|
|||
if (cached != mCache.end())
|
||||
return;
|
||||
mCache.insert(std::make_pair(agentHalfExtents,
|
||||
std::make_shared<NavMeshCacheItem>(makeEmptyNavMesh(mSettings), ++mGenerationCounter)));
|
||||
std::make_shared<GuardedNavMeshCacheItem>(makeEmptyNavMesh(mSettings), ++mGenerationCounter)));
|
||||
log("cache add for agent=", agentHalfExtents);
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ namespace DetourNavigator
|
|||
}
|
||||
const auto changedTiles = mChangedTiles.find(agentHalfExtents);
|
||||
{
|
||||
const auto locked = cached.lock();
|
||||
const auto locked = cached->lockConst();
|
||||
const auto& navMesh = locked->getValue();
|
||||
if (changedTiles != mChangedTiles.end())
|
||||
{
|
||||
|
|
|
@ -83,38 +83,6 @@ namespace Misc
|
|||
std::mutex mMutex;
|
||||
T mValue;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class SharedGuarded
|
||||
{
|
||||
public:
|
||||
SharedGuarded()
|
||||
: mMutex(std::make_shared<std::mutex>()), mValue()
|
||||
{}
|
||||
|
||||
SharedGuarded(std::shared_ptr<T> value)
|
||||
: mMutex(std::make_shared<std::mutex>()), mValue(std::move(value))
|
||||
{}
|
||||
|
||||
Locked<T> lock() const
|
||||
{
|
||||
return Locked<T>(*mMutex, *mValue);
|
||||
}
|
||||
|
||||
Locked<const T> lockConst() const
|
||||
{
|
||||
return Locked<const T>(*mMutex, *mValue);
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return static_cast<bool>(mValue);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mutex> mMutex;
|
||||
std::shared_ptr<T> mValue;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue