mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 17:49:41 +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
|
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)
|
AsyncNavMeshUpdater::AsyncNavMeshUpdater(const Settings& settings)
|
||||||
: mSettings(std::cref(settings))
|
: mSettings(std::cref(settings))
|
||||||
, mShouldStop()
|
, mShouldStop()
|
||||||
|
@ -91,7 +107,8 @@ namespace DetourNavigator
|
||||||
|
|
||||||
const auto recastMesh = getRecastMesh();
|
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();
|
const auto finish = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
@ -99,7 +116,7 @@ namespace DetourNavigator
|
||||||
|
|
||||||
using FloatMs = std::chrono::duration<float, std::milli>;
|
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");
|
" time=", std::chrono::duration_cast<FloatMs>(finish - start).count(), "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,18 @@ namespace
|
||||||
++mNavMeshRevision;
|
++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
|
namespace DetourNavigator
|
||||||
|
@ -257,7 +269,7 @@ namespace DetourNavigator
|
||||||
return navMesh;
|
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)
|
const TilePosition& changedTile, const Settings& settings, NavMeshCacheItem& navMeshCacheItem)
|
||||||
{
|
{
|
||||||
log("update NavMesh with mutiple tiles:",
|
log("update NavMesh with mutiple tiles:",
|
||||||
|
@ -277,20 +289,22 @@ namespace DetourNavigator
|
||||||
const auto y = changedTile.y();
|
const auto y = changedTile.y();
|
||||||
|
|
||||||
AutoIncrementRevision incRev(navMeshCacheItem.mNavMeshRevision);
|
AutoIncrementRevision incRev(navMeshCacheItem.mNavMeshRevision);
|
||||||
|
bool removed = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto locked = navMesh.lock();
|
const auto locked = navMesh.lock();
|
||||||
incRev.mNavMeshChanged = dtStatusSucceed(locked->removeTile(locked->getTileRefAt(x, y, 0),
|
removed = dtStatusSucceed(locked->removeTile(locked->getTileRefAt(x, y, 0), nullptr, nullptr));
|
||||||
nullptr, nullptr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
incRev.mNavMeshChanged = removed;
|
||||||
|
|
||||||
const auto& boundsMin = recastMesh.getBoundsMin();
|
const auto& boundsMin = recastMesh.getBoundsMin();
|
||||||
const auto& boundsMax = recastMesh.getBoundsMax();
|
const auto& boundsMax = recastMesh.getBoundsMax();
|
||||||
|
|
||||||
if (boundsMin == boundsMax)
|
if (boundsMin == boundsMax)
|
||||||
{
|
{
|
||||||
log("ignore add tile: recastMesh is empty");
|
log("ignore add tile: recastMesh is empty");
|
||||||
return;
|
return makeUpdateNavMeshStatus(removed, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto tileBounds = makeTileBounds(settings, changedTile);
|
const auto tileBounds = makeTileBounds(settings, changedTile);
|
||||||
|
@ -303,7 +317,7 @@ namespace DetourNavigator
|
||||||
if (!navMeshData.mValue)
|
if (!navMeshData.mValue)
|
||||||
{
|
{
|
||||||
log("ignore add tile: NavMeshData is null");
|
log("ignore add tile: NavMeshData is null");
|
||||||
return;
|
return makeUpdateNavMeshStatus(removed, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto status = navMesh.lock()->addTile(navMeshData.mValue.get(), navMeshData.mSize,
|
const auto status = navMesh.lock()->addTile(navMeshData.mValue.get(), navMeshData.mSize,
|
||||||
|
@ -313,5 +327,7 @@ namespace DetourNavigator
|
||||||
else
|
else
|
||||||
log("failed to add tile with status=", WriteDtStatus {status});
|
log("failed to add tile with status=", WriteDtStatus {status});
|
||||||
navMeshData.mValue.release();
|
navMeshData.mValue.release();
|
||||||
}
|
|
||||||
|
return makeUpdateNavMeshStatus(removed, dtStatusSucceed(status));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,17 @@ namespace DetourNavigator
|
||||||
|
|
||||||
using NavMeshPtr = std::shared_ptr<dtNavMesh>;
|
using NavMeshPtr = std::shared_ptr<dtNavMesh>;
|
||||||
|
|
||||||
|
enum class UpdateNavMeshStatus
|
||||||
|
{
|
||||||
|
ignore,
|
||||||
|
removed,
|
||||||
|
add,
|
||||||
|
replaced
|
||||||
|
};
|
||||||
|
|
||||||
NavMeshPtr makeEmptyNavMesh(const Settings& settings);
|
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);
|
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
|
# Write nav mesh file at path with this prefix
|
||||||
nav mesh path prefix =
|
nav mesh path prefix =
|
||||||
|
|
||||||
|
# Render nav mesh (true, false)
|
||||||
enable render = false
|
enable render = false
|
||||||
|
|
Loading…
Reference in a new issue