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:
+120
-49
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
+93
-105
@@ -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(®ions[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(®ions[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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user