mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-27 18:41:05 +00:00
Render only cached recast mesh
To avoid waiting while recast mesh is generating. Remove redundant continue.
This commit is contained in:
parent
daff7aba01
commit
0c8a811ad5
@ -60,7 +60,6 @@ namespace MWRender
|
||||
it->second.mValue = group;
|
||||
it->second.mGeneration = tile->second->getGeneration();
|
||||
it->second.mRevision = tile->second->getRevision();
|
||||
continue;
|
||||
}
|
||||
|
||||
++it;
|
||||
|
@ -13,7 +13,7 @@ namespace DetourNavigator
|
||||
{
|
||||
if (!mImpl.addObject(id, shape, transform, areaType))
|
||||
return false;
|
||||
mCached.lock()->reset();
|
||||
mOutdatedCache = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ namespace DetourNavigator
|
||||
{
|
||||
if (!mImpl.updateObject(id, transform, areaType))
|
||||
return false;
|
||||
mCached.lock()->reset();
|
||||
mOutdatedCache = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ namespace DetourNavigator
|
||||
{
|
||||
auto object = mImpl.removeObject(id);
|
||||
if (object)
|
||||
mCached.lock()->reset();
|
||||
mOutdatedCache = true;
|
||||
return object;
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ namespace DetourNavigator
|
||||
{
|
||||
if (!mImpl.addWater(cellPosition, cellSize, shift))
|
||||
return false;
|
||||
mCached.lock()->reset();
|
||||
mOutdatedCache = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace DetourNavigator
|
||||
{
|
||||
const auto water = mImpl.removeWater(cellPosition);
|
||||
if (water)
|
||||
mCached.lock()->reset();
|
||||
mOutdatedCache = true;
|
||||
return water;
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ namespace DetourNavigator
|
||||
{
|
||||
if (!mImpl.addHeightfield(cellPosition, cellSize, shift, shape))
|
||||
return false;
|
||||
mCached.lock()->reset();
|
||||
mOutdatedCache = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -63,18 +63,27 @@ namespace DetourNavigator
|
||||
{
|
||||
const auto cell = mImpl.removeHeightfield(cellPosition);
|
||||
if (cell)
|
||||
mCached.lock()->reset();
|
||||
mOutdatedCache = true;
|
||||
return cell;
|
||||
}
|
||||
|
||||
std::shared_ptr<RecastMesh> CachedRecastMeshManager::getMesh()
|
||||
{
|
||||
std::shared_ptr<RecastMesh> cached = *mCached.lock();
|
||||
if (cached != nullptr)
|
||||
return cached;
|
||||
cached = mImpl.getMesh();
|
||||
*mCached.lock() = cached;
|
||||
return cached;
|
||||
bool outdated = true;
|
||||
if (!mOutdatedCache.compare_exchange_strong(outdated, false))
|
||||
{
|
||||
std::shared_ptr<RecastMesh> cached = getCachedMesh();
|
||||
if (cached != nullptr)
|
||||
return cached;
|
||||
}
|
||||
std::shared_ptr<RecastMesh> mesh = mImpl.getMesh();
|
||||
*mCached.lock() = mesh;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
std::shared_ptr<RecastMesh> CachedRecastMeshManager::getCachedMesh() const
|
||||
{
|
||||
return *mCached.lockConst();
|
||||
}
|
||||
|
||||
bool CachedRecastMeshManager::isEmpty() const
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include <components/misc/guarded.hpp>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
class CachedRecastMeshManager
|
||||
@ -32,6 +34,8 @@ namespace DetourNavigator
|
||||
|
||||
std::shared_ptr<RecastMesh> getMesh();
|
||||
|
||||
std::shared_ptr<RecastMesh> getCachedMesh() const;
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
void reportNavMeshChange(const Version& recastMeshVersion, const Version& navMeshVersion);
|
||||
@ -41,6 +45,7 @@ namespace DetourNavigator
|
||||
private:
|
||||
RecastMeshManager mImpl;
|
||||
Misc::ScopeGuarded<std::shared_ptr<RecastMesh>> mCached;
|
||||
std::atomic_bool mOutdatedCache {true};
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ namespace DetourNavigator
|
||||
std::optional<osg::Vec3f> raycast(const osg::Vec3f& agentHalfExtents, const osg::Vec3f& start,
|
||||
const osg::Vec3f& end, const Flags includeFlags) const;
|
||||
|
||||
virtual RecastMeshTiles getRecastMeshTiles() = 0;
|
||||
virtual RecastMeshTiles getRecastMeshTiles() const = 0;
|
||||
|
||||
virtual float getMaxNavmeshAreaRealRadius() const = 0;
|
||||
};
|
||||
|
@ -187,7 +187,7 @@ namespace DetourNavigator
|
||||
mNavMeshManager.reportStats(frameNumber, stats);
|
||||
}
|
||||
|
||||
RecastMeshTiles NavigatorImpl::getRecastMeshTiles()
|
||||
RecastMeshTiles NavigatorImpl::getRecastMeshTiles() const
|
||||
{
|
||||
return mNavMeshManager.getRecastMeshTiles();
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ namespace DetourNavigator
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats& stats) const override;
|
||||
|
||||
RecastMeshTiles getRecastMeshTiles() override;
|
||||
RecastMeshTiles getRecastMeshTiles() const override;
|
||||
|
||||
float getMaxNavmeshAreaRealRadius() const override;
|
||||
|
||||
|
@ -94,7 +94,7 @@ namespace DetourNavigator
|
||||
|
||||
void reportStats(unsigned int /*frameNumber*/, osg::Stats& /*stats*/) const override {}
|
||||
|
||||
RecastMeshTiles getRecastMeshTiles() override
|
||||
RecastMeshTiles getRecastMeshTiles() const override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
@ -232,14 +232,15 @@ namespace DetourNavigator
|
||||
mAsyncNavMeshUpdater.reportStats(frameNumber, stats);
|
||||
}
|
||||
|
||||
RecastMeshTiles NavMeshManager::getRecastMeshTiles()
|
||||
RecastMeshTiles NavMeshManager::getRecastMeshTiles() const
|
||||
{
|
||||
std::vector<TilePosition> tiles;
|
||||
mRecastMeshManager.forEachTile(
|
||||
[&tiles] (const TilePosition& tile, const CachedRecastMeshManager&) { tiles.push_back(tile); });
|
||||
RecastMeshTiles result;
|
||||
std::transform(tiles.begin(), tiles.end(), std::inserter(result, result.end()),
|
||||
[this] (const TilePosition& tile) { return std::make_pair(tile, mRecastMeshManager.getMesh(tile)); });
|
||||
for (const TilePosition& tile : tiles)
|
||||
if (auto mesh = mRecastMeshManager.getCachedMesh(tile))
|
||||
result.emplace(tile, std::move(mesh));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ namespace DetourNavigator
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
|
||||
|
||||
RecastMeshTiles getRecastMeshTiles();
|
||||
RecastMeshTiles getRecastMeshTiles() const;
|
||||
|
||||
private:
|
||||
const Settings& mSettings;
|
||||
|
@ -192,17 +192,16 @@ namespace DetourNavigator
|
||||
|
||||
std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getMesh(const TilePosition& tilePosition) const
|
||||
{
|
||||
const auto manager = [&] () -> std::shared_ptr<CachedRecastMeshManager>
|
||||
{
|
||||
const auto tiles = mTiles.lockConst();
|
||||
const auto it = tiles->find(tilePosition);
|
||||
if (it == tiles->end())
|
||||
return nullptr;
|
||||
return it->second;
|
||||
} ();
|
||||
if (manager == nullptr)
|
||||
return nullptr;
|
||||
return manager->getMesh();
|
||||
if (const auto manager = getManager(tilePosition))
|
||||
return manager->getMesh();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getCachedMesh(const TilePosition& tilePosition) const
|
||||
{
|
||||
if (const auto manager = getManager(tilePosition))
|
||||
return manager->getCachedMesh();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::size_t TileCachedRecastMeshManager::getRevision() const
|
||||
@ -256,4 +255,13 @@ namespace DetourNavigator
|
||||
}
|
||||
return tileResult;
|
||||
}
|
||||
|
||||
std::shared_ptr<CachedRecastMeshManager> TileCachedRecastMeshManager::getManager(const TilePosition& tilePosition) const
|
||||
{
|
||||
const auto tiles = mTiles.lockConst();
|
||||
const auto it = tiles->find(tilePosition);
|
||||
if (it == tiles->end())
|
||||
return nullptr;
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
@ -88,6 +88,8 @@ namespace DetourNavigator
|
||||
|
||||
std::shared_ptr<RecastMesh> getMesh(const TilePosition& tilePosition) const;
|
||||
|
||||
std::shared_ptr<RecastMesh> getCachedMesh(const TilePosition& tilePosition) const;
|
||||
|
||||
template <class Function>
|
||||
void forEachTile(Function&& function) const
|
||||
{
|
||||
@ -118,6 +120,8 @@ namespace DetourNavigator
|
||||
|
||||
std::optional<RemovedRecastMeshObject> removeTile(const ObjectId id, const TilePosition& tilePosition,
|
||||
TilesMap& tiles);
|
||||
|
||||
inline std::shared_ptr<CachedRecastMeshManager> getManager(const TilePosition& tilePosition) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user