Report navmesh change for not posted tiles

Corresponding recast mesh tiles can be updated but navmesh tiles may never
appear for them. Report back zero navmesh version to allow oscillating recast
objects detection to work. This version is always less than any generated
navmesh tile version so any report for generated navmesh will override it.
If zero navmesh version is reported after recast mesh tile got report about
generated navmesh tile it is a no-op since generated version is always greater
than zero.
pull/593/head
elsid 4 years ago
parent 4c4218f70d
commit d122e184cc
No known key found for this signature in database
GPG Key ID: D27B8E8D10A2896B

@ -54,7 +54,7 @@ namespace
{
TileCachedRecastMeshManager manager(mSettings);
std::size_t calls = 0;
manager.forEachTilePosition([&] (const TilePosition&) { ++calls; });
manager.forEachTile([&] (const TilePosition&, const CachedRecastMeshManager&) { ++calls; });
EXPECT_EQ(calls, 0);
}

@ -66,4 +66,9 @@ namespace DetourNavigator
{
mImpl.reportNavMeshChange(recastMeshVersion, navMeshVersion);
}
Version CachedRecastMeshManager::getVersion() const
{
return mImpl.getVersion();
}
}

@ -28,6 +28,8 @@ namespace DetourNavigator
void reportNavMeshChange(Version recastMeshVersion, Version navMeshVersion);
Version getVersion() const;
private:
RecastMeshManager mImpl;
std::shared_ptr<RecastMesh> mCached;

@ -171,7 +171,7 @@ namespace DetourNavigator
}
}
const auto maxTiles = std::min(mSettings.mMaxTilesNumber, navMesh.getParams()->maxTiles);
mRecastMeshManager.forEachTilePosition([&] (const TilePosition& tile)
mRecastMeshManager.forEachTile([&] (const TilePosition& tile, CachedRecastMeshManager& recastMeshManager)
{
if (tilesToPost.count(tile))
return;
@ -181,6 +181,8 @@ namespace DetourNavigator
tilesToPost.insert(std::make_pair(tile, ChangeType::add));
else if (!shouldAdd && presentInNavMesh)
tilesToPost.insert(std::make_pair(tile, ChangeType::mixed));
else
recastMeshManager.reportNavMeshChange(recastMeshManager.getVersion(), Version {0, 0});
});
}
mAsyncNavMeshUpdater.post(agentHalfExtents, cached, playerTile, tilesToPost);
@ -214,8 +216,8 @@ namespace DetourNavigator
RecastMeshTiles NavMeshManager::getRecastMeshTiles()
{
std::vector<TilePosition> tiles;
mRecastMeshManager.forEachTilePosition(
[&tiles] (const TilePosition& tile) { tiles.push_back(tile); });
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)); });

@ -95,6 +95,11 @@ namespace DetourNavigator
mLastNavMeshReportedChange = mLastNavMeshReport;
}
Version RecastMeshManager::getVersion() const
{
return Version {mGeneration, mRevision};
}
void RecastMeshManager::rebuild()
{
mMeshBuilder.reset();

@ -53,6 +53,8 @@ namespace DetourNavigator
void reportNavMeshChange(Version recastMeshVersion, Version navMeshVersion);
Version getVersion() const;
private:
struct Report
{

@ -81,10 +81,10 @@ namespace DetourNavigator
bool hasTile(const TilePosition& tilePosition);
template <class Function>
void forEachTilePosition(Function&& function)
void forEachTile(Function&& function)
{
for (const auto& tile : *mTiles.lock())
function(tile.first);
for (auto& [tilePosition, recastMeshManager] : *mTiles.lock())
function(tilePosition, recastMeshManager);
}
std::size_t getRevision() const;

Loading…
Cancel
Save