mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 09:45:36 +00:00
Log update NavMesh status
This commit is contained in:
parent
6f3028b8f9
commit
c26773bd29
4 changed files with 52 additions and 9 deletions
|
@ -24,6 +24,22 @@ namespace
|
|||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
static std::ostream& operator <<(std::ostream& stream, UpdateNavMeshStatus value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case UpdateNavMeshStatus::ignore:
|
||||
return stream << "ignore";
|
||||
case UpdateNavMeshStatus::removed:
|
||||
return stream << "removed";
|
||||
case UpdateNavMeshStatus::add:
|
||||
return stream << "add";
|
||||
case UpdateNavMeshStatus::replaced:
|
||||
return stream << "replaced";
|
||||
}
|
||||
return stream << "unknown";
|
||||
}
|
||||
|
||||
AsyncNavMeshUpdater::AsyncNavMeshUpdater(const Settings& settings)
|
||||
: mSettings(std::cref(settings))
|
||||
, mShouldStop()
|
||||
|
@ -91,7 +107,8 @@ namespace DetourNavigator
|
|||
|
||||
const auto recastMesh = getRecastMesh();
|
||||
|
||||
updateNavMesh(job.mAgentHalfExtents, *recastMesh, job.mChangedTile, mSettings, *job.mNavMeshCacheItem);
|
||||
const auto status = updateNavMesh(job.mAgentHalfExtents, *recastMesh, job.mChangedTile, mSettings,
|
||||
*job.mNavMeshCacheItem);
|
||||
|
||||
const auto finish = std::chrono::steady_clock::now();
|
||||
|
||||
|
@ -99,7 +116,7 @@ namespace DetourNavigator
|
|||
|
||||
using FloatMs = std::chrono::duration<float, std::milli>;
|
||||
|
||||
log("cache updated for agent=", job.mAgentHalfExtents,
|
||||
log("cache updated for agent=", job.mAgentHalfExtents, " status=", status,
|
||||
" time=", std::chrono::duration_cast<FloatMs>(finish - start).count(), "ms");
|
||||
}
|
||||
|
||||
|
|
|
@ -231,6 +231,18 @@ namespace
|
|||
++mNavMeshRevision;
|
||||
}
|
||||
};
|
||||
|
||||
UpdateNavMeshStatus makeUpdateNavMeshStatus(bool removed, bool add)
|
||||
{
|
||||
if (removed && add)
|
||||
return UpdateNavMeshStatus::replaced;
|
||||
else if (removed)
|
||||
return UpdateNavMeshStatus::removed;
|
||||
else if (add)
|
||||
return UpdateNavMeshStatus::add;
|
||||
else
|
||||
return UpdateNavMeshStatus::ignore;
|
||||
}
|
||||
}
|
||||
|
||||
namespace DetourNavigator
|
||||
|
@ -257,7 +269,7 @@ namespace DetourNavigator
|
|||
return navMesh;
|
||||
}
|
||||
|
||||
void updateNavMesh(const osg::Vec3f& agentHalfExtents, const RecastMesh& recastMesh,
|
||||
UpdateNavMeshStatus updateNavMesh(const osg::Vec3f& agentHalfExtents, const RecastMesh& recastMesh,
|
||||
const TilePosition& changedTile, const Settings& settings, NavMeshCacheItem& navMeshCacheItem)
|
||||
{
|
||||
log("update NavMesh with mutiple tiles:",
|
||||
|
@ -277,20 +289,22 @@ namespace DetourNavigator
|
|||
const auto y = changedTile.y();
|
||||
|
||||
AutoIncrementRevision incRev(navMeshCacheItem.mNavMeshRevision);
|
||||
bool removed = false;
|
||||
|
||||
{
|
||||
const auto locked = navMesh.lock();
|
||||
incRev.mNavMeshChanged = dtStatusSucceed(locked->removeTile(locked->getTileRefAt(x, y, 0),
|
||||
nullptr, nullptr));
|
||||
removed = dtStatusSucceed(locked->removeTile(locked->getTileRefAt(x, y, 0), nullptr, nullptr));
|
||||
}
|
||||
|
||||
incRev.mNavMeshChanged = removed;
|
||||
|
||||
const auto& boundsMin = recastMesh.getBoundsMin();
|
||||
const auto& boundsMax = recastMesh.getBoundsMax();
|
||||
|
||||
if (boundsMin == boundsMax)
|
||||
{
|
||||
log("ignore add tile: recastMesh is empty");
|
||||
return;
|
||||
return makeUpdateNavMeshStatus(removed, false);
|
||||
}
|
||||
|
||||
const auto tileBounds = makeTileBounds(settings, changedTile);
|
||||
|
@ -303,7 +317,7 @@ namespace DetourNavigator
|
|||
if (!navMeshData.mValue)
|
||||
{
|
||||
log("ignore add tile: NavMeshData is null");
|
||||
return;
|
||||
return makeUpdateNavMeshStatus(removed, false);
|
||||
}
|
||||
|
||||
const auto status = navMesh.lock()->addTile(navMeshData.mValue.get(), navMeshData.mSize,
|
||||
|
@ -313,5 +327,7 @@ namespace DetourNavigator
|
|||
else
|
||||
log("failed to add tile with status=", WriteDtStatus {status});
|
||||
navMeshData.mValue.release();
|
||||
}
|
||||
|
||||
return makeUpdateNavMeshStatus(removed, dtStatusSucceed(status));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,17 @@ namespace DetourNavigator
|
|||
|
||||
using NavMeshPtr = std::shared_ptr<dtNavMesh>;
|
||||
|
||||
enum class UpdateNavMeshStatus
|
||||
{
|
||||
ignore,
|
||||
removed,
|
||||
add,
|
||||
replaced
|
||||
};
|
||||
|
||||
NavMeshPtr makeEmptyNavMesh(const Settings& settings);
|
||||
|
||||
void updateNavMesh(const osg::Vec3f& agentHalfExtents, const RecastMesh& recastMesh,
|
||||
UpdateNavMeshStatus updateNavMesh(const osg::Vec3f& agentHalfExtents, const RecastMesh& recastMesh,
|
||||
const TilePosition& changedTile, const Settings& settings, NavMeshCacheItem& navMeshCacheItem);
|
||||
}
|
||||
|
||||
|
|
|
@ -614,4 +614,6 @@ recast mesh path prefix =
|
|||
|
||||
# Write nav mesh file at path with this prefix
|
||||
nav mesh path prefix =
|
||||
|
||||
# Render nav mesh (true, false)
|
||||
enable render = false
|
||||
|
|
Loading…
Reference in a new issue