1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 09:23:53 +00:00

Add cached flag to update navmesh status

This commit is contained in:
elsid 2020-10-08 00:04:51 +02:00
parent eb140ed15f
commit f637dc38bd
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
3 changed files with 26 additions and 1 deletions

View file

@ -38,6 +38,12 @@ namespace DetourNavigator
return stream << "failed"; return stream << "failed";
case UpdateNavMeshStatus::lost: case UpdateNavMeshStatus::lost:
return stream << "lost"; return stream << "lost";
case UpdateNavMeshStatus::cached:
return stream << "cached";
case UpdateNavMeshStatus::unchanged:
return stream << "unchanged";
case UpdateNavMeshStatus::restored:
return stream << "restored";
} }
return stream << "unknown(" << static_cast<unsigned>(value) << ")"; return stream << "unknown(" << static_cast<unsigned>(value) << ")";
} }

View file

@ -559,6 +559,7 @@ namespace DetourNavigator
} }
auto cachedNavMeshData = navMeshTilesCache.get(agentHalfExtents, changedTile, *recastMesh, offMeshConnections); auto cachedNavMeshData = navMeshTilesCache.get(agentHalfExtents, changedTile, *recastMesh, offMeshConnections);
bool cached = static_cast<bool>(cachedNavMeshData);
if (!cachedNavMeshData) if (!cachedNavMeshData)
{ {
@ -584,6 +585,7 @@ namespace DetourNavigator
{ {
cachedNavMeshData = navMeshTilesCache.get(agentHalfExtents, changedTile, *recastMesh, cachedNavMeshData = navMeshTilesCache.get(agentHalfExtents, changedTile, *recastMesh,
offMeshConnections); offMeshConnections);
cached = static_cast<bool>(cachedNavMeshData);
} }
if (!cachedNavMeshData) if (!cachedNavMeshData)
@ -593,6 +595,8 @@ namespace DetourNavigator
} }
} }
return navMeshCacheItem->lock()->updateTile(changedTile, std::move(cachedNavMeshData)); const auto updateStatus = navMeshCacheItem->lock()->updateTile(changedTile, std::move(cachedNavMeshData));
return UpdateNavMeshStatusBuilder(updateStatus).cached(cached).getResult();
} }
} }

View file

@ -22,6 +22,9 @@ namespace DetourNavigator
replaced = removed | added, replaced = removed | added,
failed = 1 << 2, failed = 1 << 2,
lost = removed | failed, lost = removed | failed,
cached = 1 << 3,
unchanged = replaced | cached,
restored = added | cached,
}; };
inline bool isSuccess(UpdateNavMeshStatus value) inline bool isSuccess(UpdateNavMeshStatus value)
@ -34,6 +37,9 @@ namespace DetourNavigator
public: public:
UpdateNavMeshStatusBuilder() = default; UpdateNavMeshStatusBuilder() = default;
explicit UpdateNavMeshStatusBuilder(UpdateNavMeshStatus value)
: mResult(value) {}
UpdateNavMeshStatusBuilder removed(bool value) UpdateNavMeshStatusBuilder removed(bool value)
{ {
if (value) if (value)
@ -61,6 +67,15 @@ namespace DetourNavigator
return *this; return *this;
} }
UpdateNavMeshStatusBuilder cached(bool value)
{
if (value)
set(UpdateNavMeshStatus::cached);
else
unset(UpdateNavMeshStatus::cached);
return *this;
}
UpdateNavMeshStatus getResult() const UpdateNavMeshStatus getResult() const
{ {
return mResult; return mResult;