fix(Core/Deps): Update recastnavigation to last version (#2189)

Note: you need to re-extract the client data files, or download them from: https://github.com/wowgaming/client-data/releases/tag/v7
This commit is contained in:
Francesco Borzì 2019-08-13 19:08:35 +02:00 committed by GitHub
parent 859eaed800
commit 10105cab01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 924 additions and 480 deletions

View File

@ -283,6 +283,28 @@ inline bool dtVequal(const float* p0, const float* p1)
return d < thr;
}
/// Checks that the specified vector's components are all finite.
/// @param[in] v A point. [(x, y, z)]
/// @return True if all of the point's components are finite, i.e. not NaN
/// or any of the infinities.
inline bool dtVisfinite(const float* v)
{
bool result =
dtMathIsfinite(v[0]) &&
dtMathIsfinite(v[1]) &&
dtMathIsfinite(v[2]);
return result;
}
/// Checks that the specified vector's 2D components are finite.
/// @param[in] v A point. [(x, y, z)]
inline bool dtVisfinite2D(const float* v)
{
bool result = dtMathIsfinite(v[0]) && dtMathIsfinite(v[2]);
return result;
}
/// Derives the dot product of two vectors on the xz-plane. (@p u . @p v)
/// @param[in] u A vector [(x, y, z)]
/// @param[in] v A vector [(x, y, z)]

View File

@ -8,6 +8,9 @@ Members in this module are wrappers around the standard math library
#define DETOURMATH_H
#include <math.h>
// This include is required because libstdc++ has problems with isfinite
// if cmath is included before math.h.
#include <cmath>
inline float dtMathFabsf(float x) { return fabsf(x); }
inline float dtMathSqrtf(float x) { return sqrtf(x); }
@ -16,5 +19,6 @@ inline float dtMathCeilf(float x) { return ceilf(x); }
inline float dtMathCosf(float x) { return cosf(x); }
inline float dtMathSinf(float x) { return sinf(x); }
inline float dtMathAtan2f(float y, float x) { return atan2f(y, x); }
inline bool dtMathIsfinite(float x) { return std::isfinite(x); }
#endif

View File

@ -142,6 +142,11 @@ enum dtRaycastOptions
DT_RAYCAST_USE_COSTS = 0x01, ///< Raycast should calculate movement cost along the ray and fill RaycastHit::cost
};
enum dtDetailTriEdgeFlags
{
DT_DETAIL_EDGE_BOUNDARY = 0x01, ///< Detail triangle edge is part of the poly boundary
};
/// Limit raycasting during any angle pahfinding
/// The limit is given as a multiple of the character radius
@ -299,7 +304,8 @@ struct dtMeshTile
/// The detail mesh's unique vertices. [(x, y, z) * dtMeshHeader::detailVertCount]
float* detailVerts;
/// The detail mesh's triangles. [(vertA, vertB, vertC) * dtMeshHeader::detailTriCount]
/// The detail mesh's triangles. [(vertA, vertB, vertC, triFlags) * dtMeshHeader::detailTriCount].
/// See dtDetailTriEdgeFlags and dtGetDetailTriEdgeFlags.
unsigned char* detailTris;
/// The tile bounding volume nodes. [Size: dtMeshHeader::bvNodeCount]
@ -317,6 +323,15 @@ private:
dtMeshTile& operator=(const dtMeshTile&);
};
/// Get flags for edge in detail triangle.
/// @param triFlags[in] The flags for the triangle (last component of detail vertices above).
/// @param edgeIndex[in] The index of the first vertex of the edge. For instance, if 0,
/// returns flags for edge AB.
inline int dtGetDetailTriEdgeFlags(unsigned char triFlags, int edgeIndex)
{
return (triFlags >> (edgeIndex * 2)) & 0x3;
}
/// Configuration parameters used to define multi-tile navigation meshes.
/// The values are used to allocate space during the initialization of a navigation mesh.
/// @see dtNavMesh::init()
@ -648,6 +663,8 @@ private:
/// Find nearest polygon within a tile.
dtPolyRef findNearestPolyInTile(const dtMeshTile* tile, const float* center,
const float* halfExtents, float* nearestPt) const;
/// Returns whether position is over the poly and the height at the position if so.
bool getPolyHeight(const dtMeshTile* tile, const dtPoly* poly, const float* pos, float* height) const;
/// Returns closest point on polygon.
void closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const;
@ -667,6 +684,8 @@ private:
unsigned int m_tileBits; ///< Number of tile bits in the tile ID.
unsigned int m_polyBits; ///< Number of poly bits in the tile ID.
#endif
friend class dtNavMeshQuery;
};
/// Allocates a navigation mesh object using the Detour allocator.

View File

@ -119,8 +119,6 @@ public:
};
/// Provides information about raycast hit
/// filled by dtNavMeshQuery::raycast
/// @ingroup detour

View File

@ -35,6 +35,7 @@ static const unsigned int DT_INVALID_PARAM = 1 << 3; // An input parameter was i
static const unsigned int DT_BUFFER_TOO_SMALL = 1 << 4; // Result buffer for the query was too small to store all results.
static const unsigned int DT_OUT_OF_NODES = 1 << 5; // Query ran out of nodes during search.
static const unsigned int DT_PARTIAL_RESULT = 1 << 6; // Query did not reach the end location, returning best guess.
static const unsigned int DT_ALREADY_OCCUPIED = 1 << 7; // A tile has already been assigned to the given x,y coordinate
// Returns true of status is success.

View File

@ -203,33 +203,32 @@ void dtCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const floa
bool dtClosestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h)
{
const float EPS = 1e-6f;
float v0[3], v1[3], v2[3];
dtVsub(v0, c,a);
dtVsub(v1, b,a);
dtVsub(v2, p,a);
const float dot00 = dtVdot2D(v0, v0);
const float dot01 = dtVdot2D(v0, v1);
const float dot02 = dtVdot2D(v0, v2);
const float dot11 = dtVdot2D(v1, v1);
const float dot12 = dtVdot2D(v1, v2);
// Compute barycentric coordinates
const float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01);
const float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
const float v = (dot00 * dot12 - dot01 * dot02) * invDenom;
// The (sloppy) epsilon is needed to allow to get height of points which
// are interpolated along the edges of the triangles.
static const float EPS = 1e-4f;
dtVsub(v0, c, a);
dtVsub(v1, b, a);
dtVsub(v2, p, a);
// Compute scaled barycentric coordinates
float denom = v0[0] * v1[2] - v0[2] * v1[0];
if (fabsf(denom) < EPS)
return false;
float u = v1[2] * v2[0] - v1[0] * v2[2];
float v = v0[0] * v2[2] - v0[2] * v2[0];
if (denom < 0) {
denom = -denom;
u = -u;
v = -v;
}
// If point lies inside the triangle, return interpolated ycoord.
if (u >= -EPS && v >= -EPS && (u+v) <= 1+EPS)
{
h = a[1] + v0[1]*u + v1[1]*v;
if (u >= 0.0f && v >= 0.0f && (u + v) <= denom) {
h = a[1] + (v0[1] * u + v1[1] * v) / denom;
return true;
}
return false;
}

View File

@ -616,63 +616,84 @@ void dtNavMesh::baseOffMeshLinks(dtMeshTile* tile)
}
}
void dtNavMesh::closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const
namespace
{
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
getTileAndPolyByRefUnsafe(ref, &tile, &poly);
// Off-mesh connections don't have detail polygons.
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
template<bool onlyBoundary>
void closestPointOnDetailEdges(const dtMeshTile* tile, const dtPoly* poly, const float* pos, float* closest)
{
const float* v0 = &tile->verts[poly->verts[0]*3];
const float* v1 = &tile->verts[poly->verts[1]*3];
const float d0 = dtVdist(pos, v0);
const float d1 = dtVdist(pos, v1);
const float u = d0 / (d0+d1);
dtVlerp(closest, v0, v1, u);
if (posOverPoly)
*posOverPoly = false;
return;
const unsigned int ip = (unsigned int)(poly - tile->polys);
const dtPolyDetail* pd = &tile->detailMeshes[ip];
float dmin = FLT_MAX;
float tmin = 0;
const float* pmin = 0;
const float* pmax = 0;
for (int i = 0; i < pd->triCount; i++)
{
const unsigned char* tris = &tile->detailTris[(pd->triBase + i) * 4];
const int ANY_BOUNDARY_EDGE =
(DT_DETAIL_EDGE_BOUNDARY << 0) |
(DT_DETAIL_EDGE_BOUNDARY << 2) |
(DT_DETAIL_EDGE_BOUNDARY << 4);
if (onlyBoundary && (tris[3] & ANY_BOUNDARY_EDGE) == 0)
continue;
const float* v[3];
for (int j = 0; j < 3; ++j)
{
if (tris[j] < poly->vertCount)
v[j] = &tile->verts[poly->verts[tris[j]] * 3];
else
v[j] = &tile->detailVerts[(pd->vertBase + (tris[j] - poly->vertCount)) * 3];
}
for (int k = 0, j = 2; k < 3; j = k++)
{
if ((dtGetDetailTriEdgeFlags(tris[3], j) & DT_DETAIL_EDGE_BOUNDARY) == 0 &&
(onlyBoundary || tris[j] < tris[k]))
{
// Only looking at boundary edges and this is internal, or
// this is an inner edge that we will see again or have already seen.
continue;
}
float t;
float d = dtDistancePtSegSqr2D(pos, v[j], v[k], t);
if (d < dmin)
{
dmin = d;
tmin = t;
pmin = v[j];
pmax = v[k];
}
}
}
dtVlerp(closest, pmin, pmax, tmin);
}
}
bool dtNavMesh::getPolyHeight(const dtMeshTile* tile, const dtPoly* poly, const float* pos, float* height) const
{
// Off-mesh connections do not have detail polys and getting height
// over them does not make sense.
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
return false;
const unsigned int ip = (unsigned int)(poly - tile->polys);
const dtPolyDetail* pd = &tile->detailMeshes[ip];
// Clamp point to be inside the polygon.
float verts[DT_VERTS_PER_POLYGON*3];
float edged[DT_VERTS_PER_POLYGON];
float edget[DT_VERTS_PER_POLYGON];
const int nv = poly->vertCount;
for (int i = 0; i < nv; ++i)
dtVcopy(&verts[i*3], &tile->verts[poly->verts[i]*3]);
dtVcopy(closest, pos);
if (!dtDistancePtPolyEdgesSqr(pos, verts, nv, edged, edget))
{
// Point is outside the polygon, dtClamp to nearest edge.
float dmin = edged[0];
int imin = 0;
for (int i = 1; i < nv; ++i)
{
if (edged[i] < dmin)
{
dmin = edged[i];
imin = i;
}
}
const float* va = &verts[imin*3];
const float* vb = &verts[((imin+1)%nv)*3];
dtVlerp(closest, va, vb, edget[imin]);
if (posOverPoly)
*posOverPoly = false;
}
else
{
if (posOverPoly)
*posOverPoly = true;
}
if (!dtPointInPolygon(pos, verts, nv))
return false;
if (!height)
return true;
// Find height at the location.
for (int j = 0; j < pd->triCount; ++j)
@ -687,12 +708,53 @@ void dtNavMesh::closestPointOnPoly(dtPolyRef ref, const float* pos, float* close
v[k] = &tile->detailVerts[(pd->vertBase+(t[k]-poly->vertCount))*3];
}
float h;
if (dtClosestHeightPointTriangle(closest, v[0], v[1], v[2], h))
if (dtClosestHeightPointTriangle(pos, v[0], v[1], v[2], h))
{
closest[1] = h;
break;
*height = h;
return true;
}
}
// If all triangle checks failed above (can happen with degenerate triangles
// or larger floating point values) the point is on an edge, so just select
// closest. This should almost never happen so the extra iteration here is
// ok.
float closest[3];
closestPointOnDetailEdges<false>(tile, poly, pos, closest);
*height = closest[1];
return true;
}
void dtNavMesh::closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const
{
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
getTileAndPolyByRefUnsafe(ref, &tile, &poly);
dtVcopy(closest, pos);
if (getPolyHeight(tile, poly, pos, &closest[1]))
{
if (posOverPoly)
*posOverPoly = true;
return;
}
if (posOverPoly)
*posOverPoly = false;
// Off-mesh connections don't have detail polygons.
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
{
const float* v0 = &tile->verts[poly->verts[0]*3];
const float* v1 = &tile->verts[poly->verts[1]*3];
float t;
dtDistancePtSegSqr2D(pos, v0, v1, t);
dtVlerp(closest, v0, v1, t);
return;
}
// Outside poly that is not an offmesh connection.
closestPointOnDetailEdges<true>(tile, poly, pos, closest);
}
dtPolyRef dtNavMesh::findNearestPolyInTile(const dtMeshTile* tile,
@ -855,7 +917,7 @@ dtStatus dtNavMesh::addTile(unsigned char* data, int dataSize, int flags,
// Make sure the location is free.
if (getTileAt(header->x, header->y, header->layer))
return DT_FAILURE;
return DT_FAILURE | DT_ALREADY_OCCUPIED;
// Allocate a tile.
dtMeshTile* tile = 0;

View File

@ -100,7 +100,7 @@ inline float dtQueryFilter::getCost(const float* pa, const float* pb,
}
#endif
static const float H_SCALE = 2.0f; // Search heuristic scale.
static const float H_SCALE = 0.999f; // Search heuristic scale.
dtNavMeshQuery* dtAllocNavMeshQuery()
@ -222,7 +222,10 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr
dtPolyRef* randomRef, float* randomPt) const
{
dtAssert(m_nav);
if (!filter || !frand || !randomRef || !randomPt)
return DT_FAILURE | DT_INVALID_PARAM;
// Randomly pick one tile. Assume that all tiles cover roughly the same area.
const dtMeshTile* tile = 0;
float tsum = 0.0f;
@ -319,8 +322,13 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
dtAssert(m_openList);
// Validate input
if (!startRef || !m_nav->isValidPolyRef(startRef))
if (!m_nav->isValidPolyRef(startRef) ||
!centerPos || !dtVisfinite(centerPos) ||
maxRadius < 0 || !dtMathIsfinite(maxRadius) ||
!filter || !frand || !randomRef || !randomPt)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
const dtMeshTile* startTile = 0;
const dtPoly* startPoly = 0;
@ -506,85 +514,14 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
dtStatus dtNavMeshQuery::closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const
{
dtAssert(m_nav);
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
if (!m_nav->isValidPolyRef(ref) ||
!pos || !dtVisfinite(pos) ||
!closest)
{
return DT_FAILURE | DT_INVALID_PARAM;
if (!tile)
return DT_FAILURE | DT_INVALID_PARAM;
// Off-mesh connections don't have detail polygons.
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
{
const float* v0 = &tile->verts[poly->verts[0]*3];
const float* v1 = &tile->verts[poly->verts[1]*3];
const float d0 = dtVdist(pos, v0);
const float d1 = dtVdist(pos, v1);
const float u = d0 / (d0+d1);
dtVlerp(closest, v0, v1, u);
if (posOverPoly)
*posOverPoly = false;
return DT_SUCCESS;
}
const unsigned int ip = (unsigned int)(poly - tile->polys);
const dtPolyDetail* pd = &tile->detailMeshes[ip];
// Clamp point to be inside the polygon.
float verts[DT_VERTS_PER_POLYGON*3];
float edged[DT_VERTS_PER_POLYGON];
float edget[DT_VERTS_PER_POLYGON];
const int nv = poly->vertCount;
for (int i = 0; i < nv; ++i)
dtVcopy(&verts[i*3], &tile->verts[poly->verts[i]*3]);
dtVcopy(closest, pos);
if (!dtDistancePtPolyEdgesSqr(pos, verts, nv, edged, edget))
{
// Point is outside the polygon, dtClamp to nearest edge.
float dmin = edged[0];
int imin = 0;
for (int i = 1; i < nv; ++i)
{
if (edged[i] < dmin)
{
dmin = edged[i];
imin = i;
}
}
const float* va = &verts[imin*3];
const float* vb = &verts[((imin+1)%nv)*3];
dtVlerp(closest, va, vb, edget[imin]);
if (posOverPoly)
*posOverPoly = false;
}
else
{
if (posOverPoly)
*posOverPoly = true;
}
// Find height at the location.
for (int j = 0; j < pd->triCount; ++j)
{
const unsigned char* t = &tile->detailTris[(pd->triBase+j)*4];
const float* v[3];
for (int k = 0; k < 3; ++k)
{
if (t[k] < poly->vertCount)
v[k] = &tile->verts[poly->verts[t[k]]*3];
else
v[k] = &tile->detailVerts[(pd->vertBase+(t[k]-poly->vertCount))*3];
}
float h;
if (dtClosestHeightPointTriangle(closest, v[0], v[1], v[2], h))
{
closest[1] = h;
break;
}
}
m_nav->closestPointOnPoly(ref, pos, closest, posOverPoly);
return DT_SUCCESS;
}
@ -607,6 +544,9 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float*
const dtPoly* poly = 0;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
return DT_FAILURE | DT_INVALID_PARAM;
if (!pos || !dtVisfinite(pos) || !closest)
return DT_FAILURE | DT_INVALID_PARAM;
// Collect vertices.
float verts[DT_VERTS_PER_POLYGON*3];
@ -648,7 +588,7 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float*
/// @par
///
/// Will return #DT_FAILURE if the provided position is outside the xz-bounds
/// Will return #DT_FAILURE | DT_INVALID_PARAM if the provided position is outside the xz-bounds
/// of the polygon.
///
dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* height) const
@ -659,44 +599,28 @@ dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* h
const dtPoly* poly = 0;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
return DT_FAILURE | DT_INVALID_PARAM;
if (!pos || !dtVisfinite2D(pos))
return DT_FAILURE | DT_INVALID_PARAM;
// We used to return success for offmesh connections, but the
// getPolyHeight in DetourNavMesh does not do this, so special
// case it here.
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
{
const float* v0 = &tile->verts[poly->verts[0]*3];
const float* v1 = &tile->verts[poly->verts[1]*3];
const float d0 = dtVdist2D(pos, v0);
const float d1 = dtVdist2D(pos, v1);
const float u = d0 / (d0+d1);
float t;
dtDistancePtSegSqr2D(pos, v0, v1, t);
if (height)
*height = v0[1] + (v1[1] - v0[1]) * u;
*height = v0[1] + (v1[1] - v0[1])*t;
return DT_SUCCESS;
}
else
{
const unsigned int ip = (unsigned int)(poly - tile->polys);
const dtPolyDetail* pd = &tile->detailMeshes[ip];
for (int j = 0; j < pd->triCount; ++j)
{
const unsigned char* t = &tile->detailTris[(pd->triBase+j)*4];
const float* v[3];
for (int k = 0; k < 3; ++k)
{
if (t[k] < poly->vertCount)
v[k] = &tile->verts[poly->verts[t[k]]*3];
else
v[k] = &tile->detailVerts[(pd->vertBase+(t[k]-poly->vertCount))*3];
}
float h;
if (dtClosestHeightPointTriangle(pos, v[0], v[1], v[2], h))
{
if (height)
*height = h;
return DT_SUCCESS;
}
}
}
return DT_FAILURE | DT_INVALID_PARAM;
return m_nav->getPolyHeight(tile, poly, pos, height)
? DT_SUCCESS
: DT_FAILURE | DT_INVALID_PARAM;
}
class dtFindNearestPolyQuery : public dtPolyQuery
@ -767,6 +691,8 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* halfE
if (!nearestRef)
return DT_FAILURE | DT_INVALID_PARAM;
// queryPolygons below will check rest of params
dtFindNearestPolyQuery query(this, center);
@ -972,8 +898,12 @@ dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* halfExt
{
dtAssert(m_nav);
if (!center || !halfExtents || !filter || !query)
if (!center || !dtVisfinite(center) ||
!halfExtents || !dtVisfinite(halfExtents) ||
!filter || !query)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
float bmin[3], bmax[3];
dtVsub(bmin, center, halfExtents);
@ -1021,14 +951,20 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
dtAssert(m_nav);
dtAssert(m_nodePool);
dtAssert(m_openList);
if (pathCount)
*pathCount = 0;
if (!pathCount)
return DT_FAILURE | DT_INVALID_PARAM;
*pathCount = 0;
// Validate input
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef) ||
!startPos || !endPos || !filter || maxPath <= 0 || !path || !pathCount)
!startPos || !dtVisfinite(startPos) ||
!endPos || !dtVisfinite(endPos) ||
!filter || !path || maxPath <= 0)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
if (startRef == endRef)
{
@ -1263,18 +1199,21 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef
m_query.status = DT_FAILURE;
m_query.startRef = startRef;
m_query.endRef = endRef;
dtVcopy(m_query.startPos, startPos);
dtVcopy(m_query.endPos, endPos);
if (startPos)
dtVcopy(m_query.startPos, startPos);
if (endPos)
dtVcopy(m_query.endPos, endPos);
m_query.filter = filter;
m_query.options = options;
m_query.raycastLimitSqr = FLT_MAX;
if (!startRef || !endRef)
return DT_FAILURE | DT_INVALID_PARAM;
// Validate input
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef))
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef) ||
!startPos || !dtVisfinite(startPos) ||
!endPos || !dtVisfinite(endPos) || !filter)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
// trade quality with performance?
if (options & DT_FINDPATH_ANY_ANGLE)
@ -1530,7 +1469,13 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters)
dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, const int maxPath)
{
if (!pathCount)
return DT_FAILURE | DT_INVALID_PARAM;
*pathCount = 0;
if (!path || maxPath <= 0)
return DT_FAILURE | DT_INVALID_PARAM;
if (dtStatusFailed(m_query.status))
{
@ -1615,12 +1560,13 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount,
dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing, const int existingSize,
dtPolyRef* path, int* pathCount, const int maxPath)
{
if (!pathCount)
return DT_FAILURE | DT_INVALID_PARAM;
*pathCount = 0;
if (existingSize == 0)
{
return DT_FAILURE;
}
if (!existing || existingSize <= 0 || !path || !pathCount || maxPath <= 0)
return DT_FAILURE | DT_INVALID_PARAM;
if (dtStatusFailed(m_query.status))
{
@ -1823,14 +1769,19 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
int* straightPathCount, const int maxStraightPath, const int options) const
{
dtAssert(m_nav);
if (!straightPathCount)
return DT_FAILURE | DT_INVALID_PARAM;
*straightPathCount = 0;
if (!maxStraightPath)
return DT_FAILURE | DT_INVALID_PARAM;
if (!path[0])
if (!startPos || !dtVisfinite(startPos) ||
!endPos || !dtVisfinite(endPos) ||
!path || pathSize <= 0 || !path[0] ||
maxStraightPath <= 0)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
dtStatus stat = 0;
@ -2070,13 +2021,19 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
dtAssert(m_nav);
dtAssert(m_tinyNodePool);
if (!visitedCount)
return DT_FAILURE | DT_INVALID_PARAM;
*visitedCount = 0;
// Validate input
if (!startRef)
return DT_FAILURE | DT_INVALID_PARAM;
if (!m_nav->isValidPolyRef(startRef))
if (!m_nav->isValidPolyRef(startRef) ||
!startPos || !dtVisfinite(startPos) ||
!endPos || !dtVisfinite(endPos) ||
!filter || !resultPos || !visited ||
maxVisitedSize <= 0)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
dtStatus status = DT_SUCCESS;
@ -2484,16 +2441,23 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
dtRaycastHit* hit, dtPolyRef prevRef) const
{
dtAssert(m_nav);
if (!hit)
return DT_FAILURE | DT_INVALID_PARAM;
hit->t = 0;
hit->pathCount = 0;
hit->pathCost = 0;
// Validate input
if (!startRef || !m_nav->isValidPolyRef(startRef))
return DT_FAILURE | DT_INVALID_PARAM;
if (prevRef && !m_nav->isValidPolyRef(prevRef))
if (!m_nav->isValidPolyRef(startRef) ||
!startPos || !dtVisfinite(startPos) ||
!endPos || !dtVisfinite(endPos) ||
!filter ||
(prevRef && !m_nav->isValidPolyRef(prevRef)))
{
return DT_FAILURE | DT_INVALID_PARAM;
}
float dir[3], curPos[3], lastPos[3];
float verts[DT_VERTS_PER_POLYGON*3+3];
@ -2735,11 +2699,18 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
dtAssert(m_nodePool);
dtAssert(m_openList);
*resultCount = 0;
// Validate input
if (!startRef || !m_nav->isValidPolyRef(startRef))
if (!resultCount)
return DT_FAILURE | DT_INVALID_PARAM;
*resultCount = 0;
if (!m_nav->isValidPolyRef(startRef) ||
!centerPos || !dtVisfinite(centerPos) ||
radius < 0 || !dtMathIsfinite(radius) ||
!filter || maxResult < 0)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
m_nodePool->clear();
m_openList->clear();
@ -2901,8 +2872,18 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
dtAssert(m_nav);
dtAssert(m_nodePool);
dtAssert(m_openList);
if (!resultCount)
return DT_FAILURE | DT_INVALID_PARAM;
*resultCount = 0;
if (!m_nav->isValidPolyRef(startRef) ||
!verts || nverts < 3 ||
!filter || maxResult < 0)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
// Validate input
if (!startRef || !m_nav->isValidPolyRef(startRef))
@ -3088,13 +3069,20 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
{
dtAssert(m_nav);
dtAssert(m_tinyNodePool);
if (!resultCount)
return DT_FAILURE | DT_INVALID_PARAM;
*resultCount = 0;
// Validate input
if (!startRef || !m_nav->isValidPolyRef(startRef))
if (!m_nav->isValidPolyRef(startRef) ||
!centerPos || !dtVisfinite(centerPos) ||
radius < 0 || !dtMathIsfinite(radius) ||
!filter || maxResult < 0)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
static const int MAX_STACK = 48;
dtNode* stack[MAX_STACK];
int nstack = 0;
@ -3301,13 +3289,19 @@ dtStatus dtNavMeshQuery::getPolyWallSegments(dtPolyRef ref, const dtQueryFilter*
const int maxSegments) const
{
dtAssert(m_nav);
if (!segmentCount)
return DT_FAILURE | DT_INVALID_PARAM;
*segmentCount = 0;
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
return DT_FAILURE | DT_INVALID_PARAM;
if (!filter || !segmentVerts || maxSegments < 0)
return DT_FAILURE | DT_INVALID_PARAM;
int n = 0;
static const int MAX_INTERVAL = 16;
@ -3455,8 +3449,13 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
dtAssert(m_openList);
// Validate input
if (!startRef || !m_nav->isValidPolyRef(startRef))
if (!m_nav->isValidPolyRef(startRef) ||
!centerPos || !dtVisfinite(centerPos) ||
maxRadius < 0 || !dtMathIsfinite(maxRadius) ||
!filter || !hitDist || !hitPos || !hitNormal)
{
return DT_FAILURE | DT_INVALID_PARAM;
}
m_nodePool->clear();
m_openList->clear();

View File

@ -332,6 +332,8 @@ struct rcCompactSpan
/// @ingroup recast
struct rcCompactHeightfield
{
rcCompactHeightfield();
~rcCompactHeightfield();
int width; ///< The width of the heightfield. (Along the x-axis in cell units.)
int height; ///< The height of the heightfield. (Along the z-axis in cell units.)
int spanCount; ///< The number of spans in the heightfield.
@ -376,6 +378,8 @@ struct rcHeightfieldLayer
/// @see rcAllocHeightfieldLayerSet, rcFreeHeightfieldLayerSet
struct rcHeightfieldLayerSet
{
rcHeightfieldLayerSet();
~rcHeightfieldLayerSet();
rcHeightfieldLayer* layers; ///< The layers in the set. [Size: #nlayers]
int nlayers; ///< The number of layers in the set.
};
@ -395,6 +399,8 @@ struct rcContour
/// @ingroup recast
struct rcContourSet
{
rcContourSet();
~rcContourSet();
rcContour* conts; ///< An array of the contours in the set. [Size: #nconts]
int nconts; ///< The number of contours in the set.
float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]
@ -411,6 +417,8 @@ struct rcContourSet
/// @ingroup recast
struct rcPolyMesh
{
rcPolyMesh();
~rcPolyMesh();
unsigned short* verts; ///< The mesh vertices. [Form: (x, y, z) * #nverts]
unsigned short* polys; ///< Polygon and neighbor data. [Length: #maxpolys * 2 * #nvp]
unsigned short* regs; ///< The region id assigned to each polygon. [Length: #maxpolys]

View File

@ -20,6 +20,9 @@
#define RECASTALLOC_H
#include <stddef.h>
#include <stdint.h>
#include <RecastAssert.h>
/// Provides hint values to the memory allocator on how long the
/// memory is expected to be used.
@ -58,64 +61,257 @@ void* rcAlloc(size_t size, rcAllocHint hint);
/// @see rcAlloc
void rcFree(void* ptr);
/// An implementation of operator new usable for placement new. The default one is part of STL (which we don't use).
/// rcNewTag is a dummy type used to differentiate our operator from the STL one, in case users import both Recast
/// and STL.
struct rcNewTag {};
inline void* operator new(size_t, const rcNewTag&, void* p) { return p; }
inline void operator delete(void*, const rcNewTag&, void*) {}
/// A simple dynamic array of integers.
/// Signed to avoid warnnings when comparing to int loop indexes, and common error with comparing to zero.
/// MSVC2010 has a bug where ssize_t is unsigned (!!!).
typedef intptr_t rcSizeType;
#define RC_SIZE_MAX INTPTR_MAX
/// Macros to hint to the compiler about the likeliest branch. Please add a benchmark that demonstrates a performance
/// improvement before introducing use cases.
#if defined(__GNUC__) || defined(__clang__)
#define rcLikely(x) __builtin_expect((x), true)
#define rcUnlikely(x) __builtin_expect((x), false)
#else
#define rcLikely(x) (x)
#define rcUnlikely(x) (x)
#endif
/// Variable-sized storage type. Mimics the interface of std::vector<T> with some notable differences:
/// * Uses rcAlloc()/rcFree() to handle storage.
/// * No support for a custom allocator.
/// * Uses signed size instead of size_t to avoid warnings in for loops: "for (int i = 0; i < foo.size(); i++)"
/// * Omits methods of limited utility: insert/erase, (bad performance), at (we don't use exceptions), operator=.
/// * assign() and the pre-sizing constructor follow C++11 semantics -- they don't construct a temporary if no value is provided.
/// * push_back() and resize() support adding values from the current vector. Range-based constructors and assign(begin, end) do not.
/// * No specialization for bool.
template <typename T, rcAllocHint H>
class rcVectorBase {
rcSizeType m_size;
rcSizeType m_cap;
T* m_data;
// Constructs a T at the give address with either the copy constructor or the default.
static void construct(T* p, const T& v) { ::new(rcNewTag(), (void*)p) T(v); }
static void construct(T* p) { ::new(rcNewTag(), (void*)p) T; }
static void construct_range(T* begin, T* end);
static void construct_range(T* begin, T* end, const T& value);
static void copy_range(T* dst, const T* begin, const T* end);
void destroy_range(rcSizeType begin, rcSizeType end);
// Creates an array of the given size, copies all of this vector's data into it, and returns it.
T* allocate_and_copy(rcSizeType size);
void resize_impl(rcSizeType size, const T* value);
public:
typedef rcSizeType size_type;
typedef T value_type;
rcVectorBase() : m_size(0), m_cap(0), m_data(0) {};
rcVectorBase(const rcVectorBase<T, H>& other) : m_size(0), m_cap(0), m_data(0) { assign(other.begin(), other.end()); }
explicit rcVectorBase(rcSizeType count) : m_size(0), m_cap(0), m_data(0) { resize(count); }
rcVectorBase(rcSizeType count, const T& value) : m_size(0), m_cap(0), m_data(0) { resize(count, value); }
rcVectorBase(const T* begin, const T* end) : m_size(0), m_cap(0), m_data(0) { assign(begin, end); }
~rcVectorBase() { destroy_range(0, m_size); rcFree(m_data); }
// Unlike in std::vector, we return a bool to indicate whether the alloc was successful.
bool reserve(rcSizeType size);
void assign(rcSizeType count, const T& value) { clear(); resize(count, value); }
void assign(const T* begin, const T* end);
void resize(rcSizeType size) { resize_impl(size, NULL); }
void resize(rcSizeType size, const T& value) { resize_impl(size, &value); }
// Not implemented as resize(0) because resize requires T to be default-constructible.
void clear() { destroy_range(0, m_size); m_size = 0; }
void push_back(const T& value);
void pop_back() { rcAssert(m_size > 0); back().~T(); m_size--; }
rcSizeType size() const { return m_size; }
rcSizeType capacity() const { return m_cap; }
bool empty() const { return size() == 0; }
const T& operator[](rcSizeType i) const { rcAssert(i >= 0 && i < m_size); return m_data[i]; }
T& operator[](rcSizeType i) { rcAssert(i >= 0 && i < m_size); return m_data[i]; }
const T& front() const { rcAssert(m_size); return m_data[0]; }
T& front() { rcAssert(m_size); return m_data[0]; }
const T& back() const { rcAssert(m_size); return m_data[m_size - 1]; };
T& back() { rcAssert(m_size); return m_data[m_size - 1]; };
const T* data() const { return m_data; }
T* data() { return m_data; }
T* begin() { return m_data; }
T* end() { return m_data + m_size; }
const T* begin() const { return m_data; }
const T* end() const { return m_data + m_size; }
void swap(rcVectorBase<T, H>& other);
// Explicitly deleted.
rcVectorBase& operator=(const rcVectorBase<T, H>& other);
};
template<typename T, rcAllocHint H>
bool rcVectorBase<T, H>::reserve(rcSizeType count) {
if (count <= m_cap) {
return true;
}
T* new_data = allocate_and_copy(count);
if (!new_data) {
return false;
}
destroy_range(0, m_size);
rcFree(m_data);
m_data = new_data;
m_cap = count;
return true;
}
template <typename T, rcAllocHint H>
T* rcVectorBase<T, H>::allocate_and_copy(rcSizeType size) {
rcAssert(RC_SIZE_MAX / static_cast<rcSizeType>(sizeof(T)) >= size);
T* new_data = static_cast<T*>(rcAlloc(sizeof(T) * size, H));
if (new_data) {
copy_range(new_data, m_data, m_data + m_size);
}
return new_data;
}
template <typename T, rcAllocHint H>
void rcVectorBase<T, H>::assign(const T* begin, const T* end) {
clear();
reserve(end - begin);
m_size = end - begin;
copy_range(m_data, begin, end);
}
template <typename T, rcAllocHint H>
void rcVectorBase<T, H>::push_back(const T& value) {
// rcLikely increases performance by ~50% on BM_rcVector_PushPreallocated,
// and by ~2-5% on BM_rcVector_Push.
if (rcLikely(m_size < m_cap)) {
construct(m_data + m_size++, value);
return;
}
rcAssert(RC_SIZE_MAX / 2 >= m_size);
rcSizeType new_cap = m_size ? 2*m_size : 1;
T* data = allocate_and_copy(new_cap);
// construct between allocate and destroy+free in case value is
// in this vector.
construct(data + m_size, value);
destroy_range(0, m_size);
m_size++;
m_cap = new_cap;
rcFree(m_data);
m_data = data;
}
template <typename T, rcAllocHint H>
void rcVectorBase<T, H>::resize_impl(rcSizeType size, const T* value) {
if (size < m_size) {
destroy_range(size, m_size);
m_size = size;
} else if (size > m_size) {
T* new_data = allocate_and_copy(size);
// We defer deconstructing/freeing old data until after constructing
// new elements in case "value" is there.
if (value) {
construct_range(new_data + m_size, new_data + size, *value);
} else {
construct_range(new_data + m_size, new_data + size);
}
destroy_range(0, m_size);
rcFree(m_data);
m_data = new_data;
m_cap = size;
m_size = size;
}
}
template <typename T, rcAllocHint H>
void rcVectorBase<T, H>::swap(rcVectorBase<T, H>& other) {
// TODO: Reorganize headers so we can use rcSwap here.
rcSizeType tmp_cap = other.m_cap;
rcSizeType tmp_size = other.m_size;
T* tmp_data = other.m_data;
other.m_cap = m_cap;
other.m_size = m_size;
other.m_data = m_data;
m_cap = tmp_cap;
m_size = tmp_size;
m_data = tmp_data;
}
// static
template <typename T, rcAllocHint H>
void rcVectorBase<T, H>::construct_range(T* begin, T* end) {
for (T* p = begin; p < end; p++) {
construct(p);
}
}
// static
template <typename T, rcAllocHint H>
void rcVectorBase<T, H>::construct_range(T* begin, T* end, const T& value) {
for (T* p = begin; p < end; p++) {
construct(p, value);
}
}
// static
template <typename T, rcAllocHint H>
void rcVectorBase<T, H>::copy_range(T* dst, const T* begin, const T* end) {
for (rcSizeType i = 0 ; i < end - begin; i++) {
construct(dst + i, begin[i]);
}
}
template <typename T, rcAllocHint H>
void rcVectorBase<T, H>::destroy_range(rcSizeType begin, rcSizeType end) {
for (rcSizeType i = begin; i < end; i++) {
m_data[i].~T();
}
}
template <typename T>
class rcTempVector : public rcVectorBase<T, RC_ALLOC_TEMP> {
typedef rcVectorBase<T, RC_ALLOC_TEMP> Base;
public:
rcTempVector() : Base() {}
explicit rcTempVector(rcSizeType size) : Base(size) {}
rcTempVector(rcSizeType size, const T& value) : Base(size, value) {}
rcTempVector(const rcTempVector<T>& other) : Base(other) {}
rcTempVector(const T* begin, const T* end) : Base(begin, end) {}
};
template <typename T>
class rcPermVector : public rcVectorBase<T, RC_ALLOC_PERM> {
typedef rcVectorBase<T, RC_ALLOC_PERM> Base;
public:
rcPermVector() : Base() {}
explicit rcPermVector(rcSizeType size) : Base(size) {}
rcPermVector(rcSizeType size, const T& value) : Base(size, value) {}
rcPermVector(const rcPermVector<T>& other) : Base(other) {}
rcPermVector(const T* begin, const T* end) : Base(begin, end) {}
};
/// Legacy class. Prefer rcVector<int>.
class rcIntArray
{
int* m_data;
int m_size, m_cap;
void doResize(int n);
// Explicitly disabled copy constructor and copy assignment operator.
rcIntArray(const rcIntArray&);
rcIntArray& operator=(const rcIntArray&);
rcTempVector<int> m_impl;
public:
/// Constructs an instance with an initial array size of zero.
rcIntArray() : m_data(0), m_size(0), m_cap(0) {}
/// Constructs an instance initialized to the specified size.
/// @param[in] n The initial size of the integer array.
rcIntArray(int n) : m_data(0), m_size(0), m_cap(0) { resize(n); }
~rcIntArray() { rcFree(m_data); }
/// Specifies the new size of the integer array.
/// @param[in] n The new size of the integer array.
void resize(int n)
{
if (n > m_cap)
doResize(n);
m_size = n;
}
/// Push the specified integer onto the end of the array and increases the size by one.
/// @param[in] item The new value.
void push(int item) { resize(m_size+1); m_data[m_size-1] = item; }
/// Returns the value at the end of the array and reduces the size by one.
/// @return The value at the end of the array.
rcIntArray() {}
rcIntArray(int n) : m_impl(n, 0) {}
void push(int item) { m_impl.push_back(item); }
void resize(int size) { m_impl.resize(size); }
int pop()
{
if (m_size > 0)
m_size--;
return m_data[m_size];
int v = m_impl.back();
m_impl.pop_back();
return v;
}
/// The value at the specified array index.
/// @warning Does not provide overflow protection.
/// @param[in] i The index of the value.
const int& operator[](int i) const { return m_data[i]; }
/// The value at the specified array index.
/// @warning Does not provide overflow protection.
/// @param[in] i The index of the value.
int& operator[](int i) { return m_data[i]; }
/// The current size of the integer array.
int size() const { return m_size; }
int size() const { return static_cast<int>(m_impl.size()); }
int& operator[](int index) { return m_impl[index]; }
int operator[](int index) const { return m_impl[index]; }
};
/// A simple helper class used to delete an array when it goes out of scope.

View File

@ -23,11 +23,34 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <new>
#include "Recast.h"
#include "RecastAlloc.h"
#include "RecastAssert.h"
namespace
{
/// Allocates and constructs an object of the given type, returning a pointer.
/// TODO: Support constructor args.
/// @param[in] hint Hint to the allocator.
template <typename T>
T* rcNew(rcAllocHint hint) {
T* ptr = (T*)rcAlloc(sizeof(T), hint);
::new(rcNewTag(), (void*)ptr) T();
return ptr;
}
/// Destroys and frees an object allocated with rcNew.
/// @param[in] ptr The object pointer to delete.
template <typename T>
void rcDelete(T* ptr) {
if (ptr) {
ptr->~T();
rcFree((void*)ptr);
}
}
} // namespace
float rcSqrt(float x)
{
return sqrtf(x);
@ -73,9 +96,8 @@ void rcContext::log(const rcLogCategory category, const char* format, ...)
rcHeightfield* rcAllocHeightfield()
{
return new (rcAlloc(sizeof(rcHeightfield), RC_ALLOC_PERM)) rcHeightfield;
return rcNew<rcHeightfield>(RC_ALLOC_PERM);
}
rcHeightfield::rcHeightfield()
: width()
, height()
@ -104,84 +126,133 @@ rcHeightfield::~rcHeightfield()
void rcFreeHeightField(rcHeightfield* hf)
{
if (!hf) return;
hf->~rcHeightfield();
rcFree(hf);
rcDelete(hf);
}
rcCompactHeightfield* rcAllocCompactHeightfield()
{
rcCompactHeightfield* chf = (rcCompactHeightfield*)rcAlloc(sizeof(rcCompactHeightfield), RC_ALLOC_PERM);
memset(chf, 0, sizeof(rcCompactHeightfield));
return chf;
return rcNew<rcCompactHeightfield>(RC_ALLOC_PERM);
}
void rcFreeCompactHeightfield(rcCompactHeightfield* chf)
{
if (!chf) return;
rcFree(chf->cells);
rcFree(chf->spans);
rcFree(chf->dist);
rcFree(chf->areas);
rcFree(chf);
rcDelete(chf);
}
rcCompactHeightfield::rcCompactHeightfield()
: width(),
height(),
spanCount(),
walkableHeight(),
walkableClimb(),
borderSize(),
maxDistance(),
maxRegions(),
bmin(),
bmax(),
cs(),
ch(),
cells(),
spans(),
dist(),
areas()
{
}
rcCompactHeightfield::~rcCompactHeightfield()
{
rcFree(cells);
rcFree(spans);
rcFree(dist);
rcFree(areas);
}
rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet()
{
rcHeightfieldLayerSet* lset = (rcHeightfieldLayerSet*)rcAlloc(sizeof(rcHeightfieldLayerSet), RC_ALLOC_PERM);
memset(lset, 0, sizeof(rcHeightfieldLayerSet));
return lset;
return rcNew<rcHeightfieldLayerSet>(RC_ALLOC_PERM);
}
void rcFreeHeightfieldLayerSet(rcHeightfieldLayerSet* lset)
{
if (!lset) return;
for (int i = 0; i < lset->nlayers; ++i)
rcDelete(lset);
}
rcHeightfieldLayerSet::rcHeightfieldLayerSet()
: layers(), nlayers() {}
rcHeightfieldLayerSet::~rcHeightfieldLayerSet()
{
for (int i = 0; i < nlayers; ++i)
{
rcFree(lset->layers[i].heights);
rcFree(lset->layers[i].areas);
rcFree(lset->layers[i].cons);
rcFree(layers[i].heights);
rcFree(layers[i].areas);
rcFree(layers[i].cons);
}
rcFree(lset->layers);
rcFree(lset);
rcFree(layers);
}
rcContourSet* rcAllocContourSet()
{
rcContourSet* cset = (rcContourSet*)rcAlloc(sizeof(rcContourSet), RC_ALLOC_PERM);
memset(cset, 0, sizeof(rcContourSet));
return cset;
return rcNew<rcContourSet>(RC_ALLOC_PERM);
}
void rcFreeContourSet(rcContourSet* cset)
{
if (!cset) return;
for (int i = 0; i < cset->nconts; ++i)
{
rcFree(cset->conts[i].verts);
rcFree(cset->conts[i].rverts);
}
rcFree(cset->conts);
rcFree(cset);
rcDelete(cset);
}
rcContourSet::rcContourSet()
: conts(),
nconts(),
bmin(),
bmax(),
cs(),
ch(),
width(),
height(),
borderSize(),
maxError() {}
rcContourSet::~rcContourSet()
{
for (int i = 0; i < nconts; ++i)
{
rcFree(conts[i].verts);
rcFree(conts[i].rverts);
}
rcFree(conts);
}
rcPolyMesh* rcAllocPolyMesh()
{
rcPolyMesh* pmesh = (rcPolyMesh*)rcAlloc(sizeof(rcPolyMesh), RC_ALLOC_PERM);
memset(pmesh, 0, sizeof(rcPolyMesh));
return pmesh;
return rcNew<rcPolyMesh>(RC_ALLOC_PERM);
}
void rcFreePolyMesh(rcPolyMesh* pmesh)
{
if (!pmesh) return;
rcFree(pmesh->verts);
rcFree(pmesh->polys);
rcFree(pmesh->regs);
rcFree(pmesh->flags);
rcFree(pmesh->areas);
rcFree(pmesh);
rcDelete(pmesh);
}
rcPolyMesh::rcPolyMesh()
: verts(),
polys(),
regs(),
flags(),
areas(),
nverts(),
npolys(),
maxpolys(),
nvp(),
bmin(),
bmax(),
cs(),
ch(),
borderSize(),
maxEdgeError() {}
rcPolyMesh::~rcPolyMesh()
{
rcFree(verts);
rcFree(polys);
rcFree(regs);
rcFree(flags);
rcFree(areas);
}
rcPolyMeshDetail* rcAllocPolyMeshDetail()

View File

@ -58,29 +58,3 @@ void rcFree(void* ptr)
if (ptr)
sRecastFreeFunc(ptr);
}
/// @class rcIntArray
///
/// While it is possible to pre-allocate a specific array size during
/// construction or by using the #resize method, certain methods will
/// automatically resize the array as needed.
///
/// @warning The array memory is not initialized to zero when the size is
/// manually set during construction or when using #resize.
/// @par
///
/// Using this method ensures the array is at least large enough to hold
/// the specified number of elements. This can improve performance by
/// avoiding auto-resizing during use.
void rcIntArray::doResize(int n)
{
if (!m_cap) m_cap = n;
while (m_cap < n) m_cap *= 2;
int* newData = (int*)rcAlloc(m_cap*sizeof(int), RC_ALLOC_TEMP);
rcAssert(newData);
if (m_size && newData) memcpy(newData, m_data, m_size*sizeof(int));
rcFree(m_data);
m_data = newData;
}

View File

@ -557,15 +557,16 @@ static float polyMinExtent(const float* verts, const int nverts)
inline int prev(int i, int n) { return i-1 >= 0 ? i-1 : n-1; }
inline int next(int i, int n) { return i+1 < n ? i+1 : 0; }
static void triangulateHull(const int /*nverts*/, const float* verts, const int nhull, const int* hull, rcIntArray& tris)
static void triangulateHull(const int /*nverts*/, const float* verts, const int nhull, const int* hull, const int nin, rcIntArray& tris)
{
int start = 0, left = 1, right = nhull-1;
// Start from an ear with shortest perimeter.
// This tends to favor well formed triangles as starting point.
float dmin = 0;
float dmin = FLT_MAX;
for (int i = 0; i < nhull; i++)
{
if (hull[i] >= nin) continue; // Ears are triangles with original vertices as middle vertex while others are actually line segments on edges
int pi = prev(i, nhull);
int ni = next(i, nhull);
const float* pv = &verts[hull[pi]*3];
@ -770,7 +771,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
// If the polygon minimum extent is small (sliver or small triangle), do not try to add internal points.
if (minExtent < sampleDist*2)
{
triangulateHull(nverts, verts, nhull, hull, tris);
triangulateHull(nverts, verts, nhull, hull, nin, tris);
return true;
}
@ -778,7 +779,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
// We're using the triangulateHull instead of delaunayHull as it tends to
// create a bit better triangulation for long thin triangles when there
// are no internal points.
triangulateHull(nverts, verts, nhull, hull, tris);
triangulateHull(nverts, verts, nhull, hull, nin, tris);
if (tris.size() == 0)
{
@ -1140,7 +1141,8 @@ static void getHeightData(rcContext* ctx, const rcCompactHeightfield& chf,
static unsigned char getEdgeFlags(const float* va, const float* vb,
const float* vpoly, const int npoly)
{
// Return true if edge (va,vb) is part of the polygon.
// The flag returned by this function matches dtDetailTriEdgeFlags in Detour.
// Figure out if edge (va,vb) is part of the polygon boundary.
static const float thrSqr = rcSqr(0.001f);
for (int i = 0, j = npoly-1; i < npoly; j=i++)
{

View File

@ -25,8 +25,17 @@
#include "Recast.h"
#include "RecastAlloc.h"
#include "RecastAssert.h"
#include <new>
namespace
{
struct LevelStackEntry
{
LevelStackEntry(int x_, int y_, int index_) : x(x_), y(y_), index(index_) {}
int x;
int y;
int index;
};
} // namespace
static void calculateDistanceField(rcCompactHeightfield& chf, unsigned short* src, unsigned short& maxDist)
{
@ -245,17 +254,15 @@ static bool floodRegion(int x, int y, int i,
unsigned short level, unsigned short r,
rcCompactHeightfield& chf,
unsigned short* srcReg, unsigned short* srcDist,
rcIntArray& stack)
rcTempVector<LevelStackEntry>& stack)
{
const int w = chf.width;
const unsigned char area = chf.areas[i];
// Flood fill mark region.
stack.resize(0);
stack.push((int)x);
stack.push((int)y);
stack.push((int)i);
stack.clear();
stack.push_back(LevelStackEntry(x, y, i));
srcReg[i] = r;
srcDist[i] = 0;
@ -264,9 +271,11 @@ static bool floodRegion(int x, int y, int i,
while (stack.size() > 0)
{
int ci = stack.pop();
int cy = stack.pop();
int cx = stack.pop();
LevelStackEntry& back = stack.back();
int cx = back.x;
int cy = back.y;
int ci = back.index;
stack.pop_back();
const rcCompactSpan& cs = chf.spans[ci];
@ -332,9 +341,7 @@ static bool floodRegion(int x, int y, int i,
{
srcReg[ai] = r;
srcDist[ai] = 0;
stack.push(ax);
stack.push(ay);
stack.push(ai);
stack.push_back(LevelStackEntry(ax, ay, ai));
}
}
}
@ -343,12 +350,20 @@ static bool floodRegion(int x, int y, int i,
return count > 0;
}
static unsigned short* expandRegions(int maxIter, unsigned short level,
rcCompactHeightfield& chf,
unsigned short* srcReg, unsigned short* srcDist,
unsigned short* dstReg, unsigned short* dstDist,
rcIntArray& stack,
bool fillStack)
// Struct to keep track of entries in the region table that have been changed.
struct DirtyEntry
{
DirtyEntry(int index_, unsigned short region_, unsigned short distance2_)
: index(index_), region(region_), distance2(distance2_) {}
int index;
unsigned short region;
unsigned short distance2;
};
static void expandRegions(int maxIter, unsigned short level,
rcCompactHeightfield& chf,
unsigned short* srcReg, unsigned short* srcDist,
rcTempVector<LevelStackEntry>& stack,
bool fillStack)
{
const int w = chf.width;
const int h = chf.height;
@ -356,7 +371,7 @@ static unsigned short* expandRegions(int maxIter, unsigned short level,
if (fillStack)
{
// Find cells revealed by the raised level.
stack.resize(0);
stack.clear();
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
@ -366,9 +381,7 @@ static unsigned short* expandRegions(int maxIter, unsigned short level,
{
if (chf.dist[i] >= level && srcReg[i] == 0 && chf.areas[i] != RC_NULL_AREA)
{
stack.push(x);
stack.push(y);
stack.push(i);
stack.push_back(LevelStackEntry(x, y, i));
}
}
}
@ -377,27 +390,26 @@ static unsigned short* expandRegions(int maxIter, unsigned short level,
else // use cells in the input stack
{
// mark all cells which already have a region
for (int j=0; j<stack.size(); j+=3)
for (int j=0; j<stack.size(); j++)
{
int i = stack[j+2];
int i = stack[j].index;
if (srcReg[i] != 0)
stack[j+2] = -1;
stack[j].index = -1;
}
}
rcTempVector<DirtyEntry> dirtyEntries;
int iter = 0;
while (stack.size() > 0)
{
int failed = 0;
dirtyEntries.clear();
memcpy(dstReg, srcReg, sizeof(unsigned short)*chf.spanCount);
memcpy(dstDist, srcDist, sizeof(unsigned short)*chf.spanCount);
for (int j = 0; j < stack.size(); j += 3)
for (int j = 0; j < stack.size(); j++)
{
int x = stack[j+0];
int y = stack[j+1];
int i = stack[j+2];
int x = stack[j].x;
int y = stack[j].y;
int i = stack[j].index;
if (i < 0)
{
failed++;
@ -426,9 +438,8 @@ static unsigned short* expandRegions(int maxIter, unsigned short level,
}
if (r)
{
stack[j+2] = -1; // mark as used
dstReg[i] = r;
dstDist[i] = d2;
stack[j].index = -1; // mark as used
dirtyEntries.push_back(DirtyEntry(i, r, d2));
}
else
{
@ -436,11 +447,14 @@ static unsigned short* expandRegions(int maxIter, unsigned short level,
}
}
// rcSwap source and dest.
rcSwap(srcReg, dstReg);
rcSwap(srcDist, dstDist);
// Copy entries that differ between src and dst to keep them in sync.
for (int i = 0; i < dirtyEntries.size(); i++) {
int idx = dirtyEntries[i].index;
srcReg[idx] = dirtyEntries[i].region;
srcDist[idx] = dirtyEntries[i].distance2;
}
if (failed*3 == stack.size())
if (failed == stack.size())
break;
if (level > 0)
@ -450,16 +464,14 @@ static unsigned short* expandRegions(int maxIter, unsigned short level,
break;
}
}
return srcReg;
}
static void sortCellsByLevel(unsigned short startLevel,
rcCompactHeightfield& chf,
unsigned short* srcReg,
unsigned int nbStacks, rcIntArray* stacks,
const unsigned short* srcReg,
unsigned int nbStacks, rcTempVector<LevelStackEntry>* stacks,
unsigned short loglevelsPerStack) // the levels per stack (2 in our case) as a bit shift
{
const int w = chf.width;
@ -467,7 +479,7 @@ static void sortCellsByLevel(unsigned short startLevel,
startLevel = startLevel >> loglevelsPerStack;
for (unsigned int j=0; j<nbStacks; ++j)
stacks[j].resize(0);
stacks[j].clear();
// put all cells in the level range into the appropriate stacks
for (int y = 0; y < h; ++y)
@ -487,26 +499,23 @@ static void sortCellsByLevel(unsigned short startLevel,
if (sId < 0)
sId = 0;
stacks[sId].push(x);
stacks[sId].push(y);
stacks[sId].push(i);
stacks[sId].push_back(LevelStackEntry(x, y, i));
}
}
}
}
static void appendStacks(rcIntArray& srcStack, rcIntArray& dstStack,
unsigned short* srcReg)
static void appendStacks(const rcTempVector<LevelStackEntry>& srcStack,
rcTempVector<LevelStackEntry>& dstStack,
const unsigned short* srcReg)
{
for (int j=0; j<srcStack.size(); j+=3)
for (int j=0; j<srcStack.size(); j++)
{
int i = srcStack[j+2];
int i = srcStack[j].index;
if ((i < 0) || (srcReg[i] != 0))
continue;
dstStack.push(srcStack[j]);
dstStack.push(srcStack[j+1]);
dstStack.push(srcStack[j+2]);
dstStack.push_back(srcStack[j]);
}
}
@ -671,7 +680,7 @@ static bool isRegionConnectedToBorder(const rcRegion& reg)
return false;
}
static bool isSolidEdge(rcCompactHeightfield& chf, unsigned short* srcReg,
static bool isSolidEdge(rcCompactHeightfield& chf, const unsigned short* srcReg,
int x, int y, int i, int dir)
{
const rcCompactSpan& s = chf.spans[i];
@ -690,7 +699,7 @@ static bool isSolidEdge(rcCompactHeightfield& chf, unsigned short* srcReg,
static void walkContour(int x, int y, int i, int dir,
rcCompactHeightfield& chf,
unsigned short* srcReg,
const unsigned short* srcReg,
rcIntArray& cont)
{
int startDir = dir;
@ -786,16 +795,15 @@ static bool mergeAndFilterRegions(rcContext* ctx, int minRegionArea, int mergeRe
const int h = chf.height;
const int nreg = maxRegionId+1;
rcRegion* regions = (rcRegion*)rcAlloc(sizeof(rcRegion)*nreg, RC_ALLOC_TEMP);
if (!regions)
{
rcTempVector<rcRegion> regions;
if (!regions.reserve(nreg)) {
ctx->log(RC_LOG_ERROR, "mergeAndFilterRegions: Out of memory 'regions' (%d).", nreg);
return false;
}
// Construct regions
for (int i = 0; i < nreg; ++i)
new(&regions[i]) rcRegion((unsigned short)i);
regions.push_back(rcRegion((unsigned short) i));
// Find edge of a region and find connections around the contour.
for (int y = 0; y < h; ++y)
@ -1021,11 +1029,6 @@ static bool mergeAndFilterRegions(rcContext* ctx, int minRegionArea, int mergeRe
if (regions[i].overlap)
overlaps.push(regions[i].id);
for (int i = 0; i < nreg; ++i)
regions[i].~rcRegion();
rcFree(regions);
return true;
}
@ -1041,22 +1044,21 @@ static void addUniqueConnection(rcRegion& reg, int n)
static bool mergeAndFilterLayerRegions(rcContext* ctx, int minRegionArea,
unsigned short& maxRegionId,
rcCompactHeightfield& chf,
unsigned short* srcReg, rcIntArray& /*overlaps*/)
unsigned short* srcReg)
{
const int w = chf.width;
const int h = chf.height;
const int nreg = maxRegionId+1;
rcRegion* regions = (rcRegion*)rcAlloc(sizeof(rcRegion)*nreg, RC_ALLOC_TEMP);
if (!regions)
{
rcTempVector<rcRegion> regions;
// Construct regions
if (!regions.reserve(nreg)) {
ctx->log(RC_LOG_ERROR, "mergeAndFilterLayerRegions: Out of memory 'regions' (%d).", nreg);
return false;
}
// Construct regions
for (int i = 0; i < nreg; ++i)
new(&regions[i]) rcRegion((unsigned short)i);
regions.push_back(rcRegion((unsigned short) i));
// Find region neighbours and overlapping regions.
rcIntArray lregs(32);
@ -1234,10 +1236,6 @@ static bool mergeAndFilterLayerRegions(rcContext* ctx, int minRegionArea,
srcReg[i] = regions[srcReg[i]].id;
}
for (int i = 0; i < nreg; ++i)
regions[i].~rcRegion();
rcFree(regions);
return true;
}
@ -1391,9 +1389,9 @@ bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf,
paintRectRegion(w-bw, w, 0, h, id|RC_BORDER_REG, chf, srcReg); id++;
paintRectRegion(0, w, 0, bh, id|RC_BORDER_REG, chf, srcReg); id++;
paintRectRegion(0, w, h-bh, h, id|RC_BORDER_REG, chf, srcReg); id++;
chf.borderSize = borderSize;
}
chf.borderSize = borderSize;
rcIntArray prev(256);
@ -1535,7 +1533,7 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
const int w = chf.width;
const int h = chf.height;
rcScopedDelete<unsigned short> buf((unsigned short*)rcAlloc(sizeof(unsigned short)*chf.spanCount*4, RC_ALLOC_TEMP));
rcScopedDelete<unsigned short> buf((unsigned short*)rcAlloc(sizeof(unsigned short)*chf.spanCount*2, RC_ALLOC_TEMP));
if (!buf)
{
ctx->log(RC_LOG_ERROR, "rcBuildRegions: Out of memory 'tmp' (%d).", chf.spanCount*4);
@ -1546,17 +1544,15 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
const int LOG_NB_STACKS = 3;
const int NB_STACKS = 1 << LOG_NB_STACKS;
rcIntArray lvlStacks[NB_STACKS];
rcTempVector<LevelStackEntry> lvlStacks[NB_STACKS];
for (int i=0; i<NB_STACKS; ++i)
lvlStacks[i].resize(1024);
lvlStacks[i].reserve(256);
rcIntArray stack(1024);
rcIntArray visited(1024);
rcTempVector<LevelStackEntry> stack;
stack.reserve(256);
unsigned short* srcReg = buf;
unsigned short* srcDist = buf+chf.spanCount;
unsigned short* dstReg = buf+chf.spanCount*2;
unsigned short* dstDist = buf+chf.spanCount*3;
memset(srcReg, 0, sizeof(unsigned short)*chf.spanCount);
memset(srcDist, 0, sizeof(unsigned short)*chf.spanCount);
@ -1581,9 +1577,9 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
paintRectRegion(w-bw, w, 0, h, regionId|RC_BORDER_REG, chf, srcReg); regionId++;
paintRectRegion(0, w, 0, bh, regionId|RC_BORDER_REG, chf, srcReg); regionId++;
paintRectRegion(0, w, h-bh, h, regionId|RC_BORDER_REG, chf, srcReg); regionId++;
chf.borderSize = borderSize;
}
chf.borderSize = borderSize;
int sId = -1;
while (level > 0)
@ -1604,22 +1600,19 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
rcScopedTimer timerExpand(ctx, RC_TIMER_BUILD_REGIONS_EXPAND);
// Expand current regions until no empty connected cells found.
if (expandRegions(expandIters, level, chf, srcReg, srcDist, dstReg, dstDist, lvlStacks[sId], false) != srcReg)
{
rcSwap(srcReg, dstReg);
rcSwap(srcDist, dstDist);
}
expandRegions(expandIters, level, chf, srcReg, srcDist, lvlStacks[sId], false);
}
{
rcScopedTimer timerFloor(ctx, RC_TIMER_BUILD_REGIONS_FLOOD);
// Mark new regions with IDs.
for (int j = 0; j<lvlStacks[sId].size(); j += 3)
for (int j = 0; j<lvlStacks[sId].size(); j++)
{
int x = lvlStacks[sId][j];
int y = lvlStacks[sId][j+1];
int i = lvlStacks[sId][j+2];
LevelStackEntry current = lvlStacks[sId][j];
int x = current.x;
int y = current.y;
int i = current.index;
if (i >= 0 && srcReg[i] == 0)
{
if (floodRegion(x, y, i, level, regionId, chf, srcReg, srcDist, stack))
@ -1638,11 +1631,7 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
}
// Expand current regions until no empty connected cells found.
if (expandRegions(expandIters*8, 0, chf, srcReg, srcDist, dstReg, dstDist, stack, true) != srcReg)
{
rcSwap(srcReg, dstReg);
rcSwap(srcDist, dstDist);
}
expandRegions(expandIters*8, 0, chf, srcReg, srcDist, stack, true);
ctx->stopTimer(RC_TIMER_BUILD_REGIONS_WATERSHED);
@ -1709,9 +1698,9 @@ bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf,
paintRectRegion(w-bw, w, 0, h, id|RC_BORDER_REG, chf, srcReg); id++;
paintRectRegion(0, w, 0, bh, id|RC_BORDER_REG, chf, srcReg); id++;
paintRectRegion(0, w, h-bh, h, id|RC_BORDER_REG, chf, srcReg); id++;
chf.borderSize = borderSize;
}
chf.borderSize = borderSize;
rcIntArray prev(256);
@ -1809,9 +1798,8 @@ bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf,
rcScopedTimer timerFilter(ctx, RC_TIMER_BUILD_REGIONS_FILTER);
// Merge monotone regions to layers and remove small regions.
rcIntArray overlaps;
chf.maxRegions = id;
if (!mergeAndFilterLayerRegions(ctx, minRegionArea, chf.maxRegions, chf, srcReg, overlaps))
if (!mergeAndFilterLayerRegions(ctx, minRegionArea, chf.maxRegions, chf, srcReg))
return false;
}

View File

@ -0,0 +1,104 @@
From 3790dbcc9cd4bdebbd3257ac8f3f9f28a0cf0485 Mon Sep 17 00:00:00 2001
From: jackpoz <giacomopoz@gmail.com>
Date: Fri, 20 Jun 2014 23:15:04 +0200
Subject: [PATCH] Add custom trinitycore changes
---
Detour/Include/DetourNavMesh.h | 24 ++++++++++++++++++------
Detour/Source/DetourNavMeshQuery.cpp | 4 ++--
Recast/Include/Recast.h | 4 ++--
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/Detour/Include/DetourNavMesh.h b/Detour/Include/DetourNavMesh.h
index 8ecd57e..f50f705 100644
--- a/Detour/Include/DetourNavMesh.h
+++ b/Detour/Include/DetourNavMesh.h
@@ -25,13 +25,25 @@
// Undefine (or define in a build cofnig) the following line to use 64bit polyref.
// Generally not needed, useful for very large worlds.
// Note: tiles build using 32bit refs are not compatible with 64bit refs!
-//#define DT_POLYREF64 1
+#define DT_POLYREF64 1
#ifdef DT_POLYREF64
// TODO: figure out a multiplatform version of uint64_t
// - maybe: https://code.google.com/p/msinttypes/
// - or: http://www.azillionmonkeys.com/qed/pstdint.h
+#if defined(WIN32) && !defined(__MINGW32__)
+/// Do not rename back to uint64. Otherwise mac complains about typedef redefinition
+typedef unsigned __int64 uint64_d;
+#else
#include <stdint.h>
+#ifndef uint64_t
+#ifdef __linux__
+#include <linux/types.h>
+#endif
+#endif
+/// Do not rename back to uint64. Otherwise mac complains about typedef redefinition
+typedef uint64_t uint64_d;
+#endif
#endif
// Note: If you want to use 64-bit refs, change the types of both dtPolyRef & dtTileRef.
@@ -40,10 +52,10 @@
/// A handle to a polygon within a navigation mesh tile.
/// @ingroup detour
#ifdef DT_POLYREF64
-static const unsigned int DT_SALT_BITS = 16;
-static const unsigned int DT_TILE_BITS = 28;
-static const unsigned int DT_POLY_BITS = 20;
-typedef uint64_t dtPolyRef;
+static const unsigned int DT_SALT_BITS = 12;
+static const unsigned int DT_TILE_BITS = 21;
+static const unsigned int DT_POLY_BITS = 31;
+typedef uint64_d dtPolyRef;
#else
typedef unsigned int dtPolyRef;
#endif
@@ -51,7 +63,7 @@ typedef unsigned int dtPolyRef;
/// A handle to a tile within a navigation mesh.
/// @ingroup detour
#ifdef DT_POLYREF64
-typedef uint64_t dtTileRef;
+typedef uint64_d dtTileRef;
#else
typedef unsigned int dtTileRef;
#endif
diff --git a/Detour/Source/DetourNavMeshQuery.cpp b/Detour/Source/DetourNavMeshQuery.cpp
index 75af102..a263106 100644
--- a/Detour/Source/DetourNavMeshQuery.cpp
+++ b/Detour/Source/DetourNavMeshQuery.cpp
@@ -3623,7 +3623,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
dtVsub(hitNormal, centerPos, hitPos);
dtVnormalize(hitNormal);
- *hitDist = dtMathSqrtf(radiusSqr);
+ *hitDist = sqrtf(radiusSqr);
return status;
}
diff --git a/Recast/Include/Recast.h b/Recast/Include/Recast.h
index e85c0d2..79d77e4 100644
--- a/Recast/Include/Recast.h
+++ b/Recast/Include/Recast.h
@@ -263,7 +263,7 @@ struct rcConfig
};
/// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax.
-static const int RC_SPAN_HEIGHT_BITS = 13;
+static const int RC_SPAN_HEIGHT_BITS = 16;
/// Defines the maximum value for rcSpan::smin and rcSpan::smax.
static const int RC_SPAN_MAX_HEIGHT = (1 << RC_SPAN_HEIGHT_BITS) - 1;
@@ -277,7 +277,7 @@ struct rcSpan
{
unsigned int smin : RC_SPAN_HEIGHT_BITS; ///< The lower limit of the span. [Limit: < #smax]
unsigned int smax : RC_SPAN_HEIGHT_BITS; ///< The upper limit of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT]
- unsigned int area : 6; ///< The area id assigned to the span.
+ unsigned char area; ///< The area id assigned to the span.
rcSpan* next; ///< The next span higher up in column.
};
--
2.9.0.windows.1

View File

@ -12,8 +12,8 @@
namespace VMAP
{
const char VMAP_MAGIC[] = "VMAP_4.3";
const char RAW_VMAP_MAGIC[] = "VMAP043"; // used in extracted vmap files with raw data
const char VMAP_MAGIC[] = "VMAP_4.4";
const char RAW_VMAP_MAGIC[] = "VMAP044"; // used in extracted vmap files with raw data
const char GAMEOBJECT_MODELS[] = "GameObjectModels.dtree";
// defined in TileAssembler.cpp currently...

View File

@ -3520,7 +3520,7 @@ enum PartyResult
};
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 9
#define MMAP_VERSION 10
struct MmapTileHeader
{

View File

@ -25,7 +25,7 @@ const float Constants::UnitSize = Constants::ChunkSize / 8.0f;
const float Constants::Origin[] = { -Constants::MaxXY, 0.0f, -Constants::MaxXY };
const float Constants::PI = 3.1415926f;
const float Constants::MaxStandableHeight = 1.5f;
const char* Constants::VMAPMagic = "VMAP042";
const char* Constants::VMAPMagic = "VMAP044";
bool Constants::ToWoWCoords = false;
bool Constants::Debug = false;
const float Constants::BaseUnitDim = 0.533333f;

View File

@ -340,7 +340,7 @@ public:
};
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 9
#define MMAP_VERSION 10
struct MmapTileHeader
{

View File

@ -4,18 +4,16 @@
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/
#include "PathCommon.h"
#include "MapBuilder.h"
#include "MapTree.h"
#include "ModelInstance.h"
#include "PathCommon.h"
#include "DetourNavMeshBuilder.h"
#include "DetourNavMesh.h"
#include "DetourCommon.h"
#include <DetourCommon.h>
#include <DetourNavMesh.h>
#include <DetourNavMeshBuilder.h>
#include "DisableMgr.h"
#include <ace/OS_NS_unistd.h>
namespace DisableMgr
{
@ -23,7 +21,7 @@ namespace DisableMgr
}
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 9
#define MMAP_VERSION 10
struct MmapTileHeader
{
@ -388,6 +386,8 @@ namespace MMAP
printf("[Map %03i] We have %u tiles. \n", mapID, (unsigned int)tiles->size());
for (std::set<uint32>::iterator it = tiles->begin(); it != tiles->end(); ++it)
{
// percentageDone - increment tiles built
m_totalTilesBuilt++;
uint32 tileX, tileY;
// unpack tile coords
@ -443,9 +443,6 @@ namespace MMAP
// build navmesh tile
buildMoveMapTile(mapID, tileX, tileY, meshData, bmin, bmax, navMesh);
// percentageDone - increment tiles built
m_totalTilesBuilt++;
}
/**************************************************************************/

View File

@ -64,7 +64,7 @@ bool preciseVectorData = false;
//static const char * szWorkDirMaps = ".\\Maps";
const char* szWorkDirWmo = "./Buildings";
const char* szRawVMAPMagic = "VMAP043";
const char* szRawVMAPMagic = "VMAP044";
// Local testing functions