Merge branch 'navigator_cleanup' into 'master'

Navigator cleanup

See merge request OpenMW/openmw!612
pull/3047/head
psi29a 3 years ago
commit de28a89a43

@ -20,16 +20,7 @@ namespace DetourNavigator
dtQueryFilter queryFilter;
queryFilter.setIncludeFlags(includeFlags);
dtPolyRef startRef = 0;
osg::Vec3f startPolygonPosition;
for (int i = 0; i < 3; ++i)
{
const auto status = navMeshQuery.findNearestPoly(start.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
&startRef, startPolygonPosition.ptr());
if (!dtStatusFailed(status) && startRef != 0)
break;
}
dtPolyRef startRef = findNearestPolyExpanding(navMeshQuery, queryFilter, start, halfExtents);
if (startRef == 0)
return std::optional<osg::Vec3f>();

@ -108,13 +108,13 @@ namespace DetourNavigator
{
// Find steer target.
SteerTarget result;
const int MAX_STEER_POINTS = 3;
std::array<float, MAX_STEER_POINTS * 3> steerPath;
std::array<unsigned char, MAX_STEER_POINTS> steerPathFlags;
std::array<dtPolyRef, MAX_STEER_POINTS> steerPathPolys;
constexpr int maxSteerPoints = 3;
std::array<float, maxSteerPoints * 3> steerPath;
std::array<unsigned char, maxSteerPoints> steerPathFlags;
std::array<dtPolyRef, maxSteerPoints> steerPathPolys;
int nsteerPath = 0;
navQuery.findStraightPath(startPos.ptr(), endPos.ptr(), path.data(), int(path.size()), steerPath.data(),
steerPathFlags.data(), steerPathPolys.data(), &nsteerPath, MAX_STEER_POINTS);
steerPathFlags.data(), steerPathPolys.data(), &nsteerPath, maxSteerPoints);
assert(nsteerPath >= 0);
if (!nsteerPath)
return std::nullopt;
@ -140,4 +140,17 @@ namespace DetourNavigator
return result;
}
dtPolyRef findNearestPolyExpanding(const dtNavMeshQuery& query, const dtQueryFilter& filter,
const osg::Vec3f& center, const osg::Vec3f& halfExtents)
{
dtPolyRef ref = 0;
for (int i = 0; i < 3; ++i)
{
const dtStatus status = query.findNearestPoly(center.ptr(), (halfExtents * (1 << i)).ptr(), &filter, &ref, nullptr);
if (!dtStatusFailed(status) && ref != 0)
break;
}
return ref;
}
}

@ -103,6 +103,9 @@ namespace DetourNavigator
return dtStatusSucceed(status);
}
dtPolyRef findNearestPolyExpanding(const dtNavMeshQuery& query, const dtQueryFilter& filter,
const osg::Vec3f& center, const osg::Vec3f& halfExtents);
struct MoveAlongSurfaceResult
{
osg::Vec3f mResultPos;
@ -163,7 +166,7 @@ namespace DetourNavigator
osg::Vec3f targetPos;
navMeshQuery.closestPointOnPoly(polygonPath.back(), end.ptr(), targetPos.ptr(), nullptr);
const float SLOP = 0.01f;
constexpr float slop = 0.01f;
*out++ = iterPos;
@ -174,7 +177,7 @@ namespace DetourNavigator
while (!polygonPath.empty() && smoothPathSize < maxSmoothPathSize)
{
// Find location to steer towards.
const auto steerTarget = getSteerTarget(navMeshQuery, iterPos, targetPos, SLOP, polygonPath);
const auto steerTarget = getSteerTarget(navMeshQuery, iterPos, targetPos, slop, polygonPath);
if (!steerTarget)
break;
@ -206,7 +209,7 @@ namespace DetourNavigator
iterPos.y() = h;
// Handle end of path and off-mesh links when close enough.
if (endOfPath && inRange(iterPos, steerTarget->steerPos, SLOP, 1.0f))
if (endOfPath && inRange(iterPos, steerTarget->steerPos, slop, 1.0f))
{
// Reached end of path.
iterPos = targetPos;
@ -214,7 +217,7 @@ namespace DetourNavigator
++smoothPathSize;
break;
}
else if (offMeshConnection && inRange(iterPos, steerTarget->steerPos, SLOP, 1.0f))
else if (offMeshConnection && inRange(iterPos, steerTarget->steerPos, slop, 1.0f))
{
// Advance the path up to and over the off-mesh connection.
dtPolyRef prevRef = 0;
@ -282,29 +285,11 @@ namespace DetourNavigator
queryFilter.setAreaCost(AreaType_pathgrid, areaCosts.mPathgrid);
queryFilter.setAreaCost(AreaType_ground, areaCosts.mGround);
dtPolyRef startRef = 0;
osg::Vec3f startPolygonPosition;
for (int i = 0; i < 3; ++i)
{
const auto status = navMeshQuery.findNearestPoly(start.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
&startRef, startPolygonPosition.ptr());
if (!dtStatusFailed(status) && startRef != 0)
break;
}
dtPolyRef startRef = findNearestPolyExpanding(navMeshQuery, queryFilter, start, halfExtents);
if (startRef == 0)
return Status::StartPolygonNotFound;
dtPolyRef endRef = 0;
osg::Vec3f endPolygonPosition;
for (int i = 0; i < 3; ++i)
{
const auto status = navMeshQuery.findNearestPoly(end.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
&endRef, endPolygonPosition.ptr());
if (!dtStatusFailed(status) && endRef != 0)
break;
}
dtPolyRef endRef = findNearestPolyExpanding(navMeshQuery, queryFilter, end, halfExtents);
if (endRef == 0)
return Status::EndPolygonNotFound;

@ -66,7 +66,7 @@ namespace DetourNavigator
void update(const osg::Vec3f& /*playerPosition*/) override {}
void setUpdatesEnabled(bool enabled) override {}
void setUpdatesEnabled(bool /*enabled*/) override {}
void wait() override {}

@ -3,6 +3,8 @@
#include "recasttempallocator.hpp"
#include <cstdlib>
namespace DetourNavigator
{
class RecastGlobalAllocator
@ -32,7 +34,7 @@ namespace DetourNavigator
else
{
assert(BufferType_perm == getDataPtrBufferType(ptr));
::free(getPermDataPtrHeapPtr(ptr));
std::free(getPermDataPtrHeapPtr(ptr));
}
}
@ -56,7 +58,7 @@ namespace DetourNavigator
static void* allocPerm(size_t size)
{
const auto ptr = ::malloc(size + sizeof(std::size_t));
const auto ptr = std::malloc(size + sizeof(std::size_t));
if (rcUnlikely(!ptr))
return ptr;
setPermPtrBufferType(ptr, BufferType_perm);

@ -52,7 +52,7 @@ namespace DetourNavigator
inline float getTileSize(const Settings& settings)
{
return settings.mTileSize * settings.mCellSize;
return static_cast<float>(settings.mTileSize) * settings.mCellSize;
}
inline TilePosition getTilePosition(const Settings& settings, const osg::Vec3f& position)
@ -73,7 +73,7 @@ namespace DetourNavigator
inline float getBorderSize(const Settings& settings)
{
return settings.mBorderSize * settings.mCellSize;
return static_cast<float>(settings.mBorderSize) * settings.mCellSize;
}
inline float getSwimLevel(const Settings& settings, const float agentHalfExtentsZ)

Loading…
Cancel
Save