diff options
Diffstat (limited to 'dep/recastnavigation/Recast/Source/RecastMesh.cpp')
| -rw-r--r-- | dep/recastnavigation/Recast/Source/RecastMesh.cpp | 72 | 
1 files changed, 40 insertions, 32 deletions
| diff --git a/dep/recastnavigation/Recast/Source/RecastMesh.cpp b/dep/recastnavigation/Recast/Source/RecastMesh.cpp index c8853444019..9b6f04e3092 100644 --- a/dep/recastnavigation/Recast/Source/RecastMesh.cpp +++ b/dep/recastnavigation/Recast/Source/RecastMesh.cpp @@ -528,8 +528,8 @@ static int getPolyMergeValue(unsigned short* pa, unsigned short* pb,  	return dx*dx + dy*dy;  } -static void mergePolys(unsigned short* pa, unsigned short* pb, int ea, int eb, -					   unsigned short* tmp, const int nvp) +static void mergePolyVerts(unsigned short* pa, unsigned short* pb, int ea, int eb, +						   unsigned short* tmp, const int nvp)  {  	const int na = countPolyVerts(pa, nvp);  	const int nb = countPolyVerts(pb, nvp); @@ -601,7 +601,7 @@ static bool canRemoveVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned sho  	// Find edges which share the removed vertex.  	const int maxEdges = numTouchedVerts*2;  	int nedges = 0; -	rcScopedDelete<int> edges = (int*)rcAlloc(sizeof(int)*maxEdges*3, RC_ALLOC_TEMP); +	rcScopedDelete<int> edges((int*)rcAlloc(sizeof(int)*maxEdges*3, RC_ALLOC_TEMP));  	if (!edges)  	{  		ctx->log(RC_LOG_WARNING, "canRemoveVertex: Out of memory 'edges' (%d).", maxEdges*3); @@ -681,7 +681,7 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short  	}  	int nedges = 0; -	rcScopedDelete<int> edges = (int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp*4, RC_ALLOC_TEMP); +	rcScopedDelete<int> edges((int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp*4, RC_ALLOC_TEMP));  	if (!edges)  	{  		ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'edges' (%d).", numRemovedVerts*nvp*4); @@ -689,15 +689,15 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short  	}  	int nhole = 0; -	rcScopedDelete<int> hole = (int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP); +	rcScopedDelete<int> hole((int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP));  	if (!hole)  	{  		ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'hole' (%d).", numRemovedVerts*nvp);  		return false;  	} -	 +  	int nhreg = 0; -	rcScopedDelete<int> hreg = (int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP); +	rcScopedDelete<int> hreg((int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP));  	if (!hreg)  	{  		ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'hreg' (%d).", numRemovedVerts*nvp); @@ -705,7 +705,7 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short  	}  	int nharea = 0; -	rcScopedDelete<int> harea = (int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP); +	rcScopedDelete<int> harea((int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP));  	if (!harea)  	{  		ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'harea' (%d).", numRemovedVerts*nvp); @@ -822,21 +822,21 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short  			break;  	} -	rcScopedDelete<int> tris = (int*)rcAlloc(sizeof(int)*nhole*3, RC_ALLOC_TEMP); +	rcScopedDelete<int> tris((int*)rcAlloc(sizeof(int)*nhole*3, RC_ALLOC_TEMP));  	if (!tris)  	{  		ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'tris' (%d).", nhole*3);  		return false;  	} -	rcScopedDelete<int> tverts = (int*)rcAlloc(sizeof(int)*nhole*4, RC_ALLOC_TEMP); +	rcScopedDelete<int> tverts((int*)rcAlloc(sizeof(int)*nhole*4, RC_ALLOC_TEMP));  	if (!tverts)  	{  		ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'tverts' (%d).", nhole*4);  		return false;  	} -	rcScopedDelete<int> thole = (int*)rcAlloc(sizeof(int)*nhole, RC_ALLOC_TEMP); +	rcScopedDelete<int> thole((int*)rcAlloc(sizeof(int)*nhole, RC_ALLOC_TEMP));  	if (!thole)  	{  		ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'thole' (%d).", nhole); @@ -863,19 +863,19 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short  	}  	// Merge the hole triangles back to polygons. -	rcScopedDelete<unsigned short> polys = (unsigned short*)rcAlloc(sizeof(unsigned short)*(ntris+1)*nvp, RC_ALLOC_TEMP); +	rcScopedDelete<unsigned short> polys((unsigned short*)rcAlloc(sizeof(unsigned short)*(ntris+1)*nvp, RC_ALLOC_TEMP));  	if (!polys)  	{  		ctx->log(RC_LOG_ERROR, "removeVertex: Out of memory 'polys' (%d).", (ntris+1)*nvp);  		return false;  	} -	rcScopedDelete<unsigned short> pregs = (unsigned short*)rcAlloc(sizeof(unsigned short)*ntris, RC_ALLOC_TEMP); +	rcScopedDelete<unsigned short> pregs((unsigned short*)rcAlloc(sizeof(unsigned short)*ntris, RC_ALLOC_TEMP));  	if (!pregs)  	{  		ctx->log(RC_LOG_ERROR, "removeVertex: Out of memory 'pregs' (%d).", ntris);  		return false;  	} -	rcScopedDelete<unsigned char> pareas = (unsigned char*)rcAlloc(sizeof(unsigned char)*ntris, RC_ALLOC_TEMP); +	rcScopedDelete<unsigned char> pareas((unsigned char*)rcAlloc(sizeof(unsigned char)*ntris, RC_ALLOC_TEMP));  	if (!pareas)  	{  		ctx->log(RC_LOG_ERROR, "removeVertex: Out of memory 'pareas' (%d).", ntris); @@ -895,7 +895,14 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short  			polys[npolys*nvp+0] = (unsigned short)hole[t[0]];  			polys[npolys*nvp+1] = (unsigned short)hole[t[1]];  			polys[npolys*nvp+2] = (unsigned short)hole[t[2]]; -			pregs[npolys] = (unsigned short)hreg[t[0]]; + +			// If this polygon covers multiple region types then +			// mark it as such +			if (hreg[t[0]] != hreg[t[1]] || hreg[t[1]] != hreg[t[2]]) +				pregs[npolys] = RC_MULTIPLE_REGS; +			else +				pregs[npolys] = (unsigned short)hreg[t[0]]; +  			pareas[npolys] = (unsigned char)harea[t[0]];  			npolys++;  		} @@ -936,7 +943,10 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short  				// Found best, merge.  				unsigned short* pa = &polys[bestPa*nvp];  				unsigned short* pb = &polys[bestPb*nvp]; -				mergePolys(pa, pb, bestEa, bestEb, tmpPoly, nvp); +				mergePolyVerts(pa, pb, bestEa, bestEb, tmpPoly, nvp); +				if (pregs[bestPa] != pregs[bestPb]) +					pregs[bestPa] = RC_MULTIPLE_REGS; +  				unsigned short* last = &polys[(npolys-1)*nvp];  				if (pb != last)  					memcpy(pb, last, sizeof(unsigned short)*nvp); @@ -983,13 +993,14 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe  {  	rcAssert(ctx); -	ctx->startTimer(RC_TIMER_BUILD_POLYMESH); +	rcScopedTimer timer(ctx, RC_TIMER_BUILD_POLYMESH);  	rcVcopy(mesh.bmin, cset.bmin);  	rcVcopy(mesh.bmax, cset.bmax);  	mesh.cs = cset.cs;  	mesh.ch = cset.ch;  	mesh.borderSize = cset.borderSize; +	mesh.maxEdgeError = cset.maxError;  	int maxVertices = 0;  	int maxTris = 0; @@ -1009,7 +1020,7 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe  		return false;  	} -	rcScopedDelete<unsigned char> vflags = (unsigned char*)rcAlloc(sizeof(unsigned char)*maxVertices, RC_ALLOC_TEMP); +	rcScopedDelete<unsigned char> vflags((unsigned char*)rcAlloc(sizeof(unsigned char)*maxVertices, RC_ALLOC_TEMP));  	if (!vflags)  	{  		ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'vflags' (%d).", maxVertices); @@ -1052,7 +1063,7 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe  	memset(mesh.regs, 0, sizeof(unsigned short)*maxTris);  	memset(mesh.areas, 0, sizeof(unsigned char)*maxTris); -	rcScopedDelete<int> nextVert = (int*)rcAlloc(sizeof(int)*maxVertices, RC_ALLOC_TEMP); +	rcScopedDelete<int> nextVert((int*)rcAlloc(sizeof(int)*maxVertices, RC_ALLOC_TEMP));  	if (!nextVert)  	{  		ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'nextVert' (%d).", maxVertices); @@ -1060,7 +1071,7 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe  	}  	memset(nextVert, 0, sizeof(int)*maxVertices); -	rcScopedDelete<int> firstVert = (int*)rcAlloc(sizeof(int)*VERTEX_BUCKET_COUNT, RC_ALLOC_TEMP); +	rcScopedDelete<int> firstVert((int*)rcAlloc(sizeof(int)*VERTEX_BUCKET_COUNT, RC_ALLOC_TEMP));  	if (!firstVert)  	{  		ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'firstVert' (%d).", VERTEX_BUCKET_COUNT); @@ -1069,19 +1080,19 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe  	for (int i = 0; i < VERTEX_BUCKET_COUNT; ++i)  		firstVert[i] = -1; -	rcScopedDelete<int> indices = (int*)rcAlloc(sizeof(int)*maxVertsPerCont, RC_ALLOC_TEMP); +	rcScopedDelete<int> indices((int*)rcAlloc(sizeof(int)*maxVertsPerCont, RC_ALLOC_TEMP));  	if (!indices)  	{  		ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'indices' (%d).", maxVertsPerCont);  		return false;  	} -	rcScopedDelete<int> tris = (int*)rcAlloc(sizeof(int)*maxVertsPerCont*3, RC_ALLOC_TEMP); +	rcScopedDelete<int> tris((int*)rcAlloc(sizeof(int)*maxVertsPerCont*3, RC_ALLOC_TEMP));  	if (!tris)  	{  		ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'tris' (%d).", maxVertsPerCont*3);  		return false;  	} -	rcScopedDelete<unsigned short> polys = (unsigned short*)rcAlloc(sizeof(unsigned short)*(maxVertsPerCont+1)*nvp, RC_ALLOC_TEMP); +	rcScopedDelete<unsigned short> polys((unsigned short*)rcAlloc(sizeof(unsigned short)*(maxVertsPerCont+1)*nvp, RC_ALLOC_TEMP));  	if (!polys)  	{  		ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'polys' (%d).", maxVertsPerCont*nvp); @@ -1182,7 +1193,7 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe  					// Found best, merge.  					unsigned short* pa = &polys[bestPa*nvp];  					unsigned short* pb = &polys[bestPb*nvp]; -					mergePolys(pa, pb, bestEa, bestEb, tmpPoly, nvp); +					mergePolyVerts(pa, pb, bestEa, bestEb, tmpPoly, nvp);  					unsigned short* lastPoly = &polys[(npolys-1)*nvp];  					if (pb != lastPoly)  						memcpy(pb, lastPoly, sizeof(unsigned short)*nvp); @@ -1293,8 +1304,6 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe  		ctx->log(RC_LOG_ERROR, "rcBuildPolyMesh: The resulting mesh has too many polygons %d (max %d). Data can be corrupted.", mesh.npolys, 0xffff);  	} -	ctx->stopTimer(RC_TIMER_BUILD_POLYMESH); -	  	return true;  } @@ -1306,7 +1315,7 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r  	if (!nmeshes || !meshes)  		return true; -	ctx->startTimer(RC_TIMER_MERGE_POLYMESH); +	rcScopedTimer timer(ctx, RC_TIMER_MERGE_POLYMESH);  	mesh.nvp = meshes[0]->nvp;  	mesh.cs = meshes[0]->cs; @@ -1367,7 +1376,7 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r  	}  	memset(mesh.flags, 0, sizeof(unsigned short)*maxPolys); -	rcScopedDelete<int> nextVert = (int*)rcAlloc(sizeof(int)*maxVerts, RC_ALLOC_TEMP); +	rcScopedDelete<int> nextVert((int*)rcAlloc(sizeof(int)*maxVerts, RC_ALLOC_TEMP));  	if (!nextVert)  	{  		ctx->log(RC_LOG_ERROR, "rcMergePolyMeshes: Out of memory 'nextVert' (%d).", maxVerts); @@ -1375,7 +1384,7 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r  	}  	memset(nextVert, 0, sizeof(int)*maxVerts); -	rcScopedDelete<int> firstVert = (int*)rcAlloc(sizeof(int)*VERTEX_BUCKET_COUNT, RC_ALLOC_TEMP); +	rcScopedDelete<int> firstVert((int*)rcAlloc(sizeof(int)*VERTEX_BUCKET_COUNT, RC_ALLOC_TEMP));  	if (!firstVert)  	{  		ctx->log(RC_LOG_ERROR, "rcMergePolyMeshes: Out of memory 'firstVert' (%d).", VERTEX_BUCKET_COUNT); @@ -1384,7 +1393,7 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r  	for (int i = 0; i < VERTEX_BUCKET_COUNT; ++i)  		firstVert[i] = -1; -	rcScopedDelete<unsigned short> vremap = (unsigned short*)rcAlloc(sizeof(unsigned short)*maxVertsPerMesh, RC_ALLOC_PERM); +	rcScopedDelete<unsigned short> vremap((unsigned short*)rcAlloc(sizeof(unsigned short)*maxVertsPerMesh, RC_ALLOC_PERM));  	if (!vremap)  	{  		ctx->log(RC_LOG_ERROR, "rcMergePolyMeshes: Out of memory 'vremap' (%d).", maxVertsPerMesh); @@ -1474,8 +1483,6 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r  		ctx->log(RC_LOG_ERROR, "rcMergePolyMeshes: The resulting mesh has too many polygons %d (max %d). Data can be corrupted.", mesh.npolys, 0xffff);  	} -	ctx->stopTimer(RC_TIMER_MERGE_POLYMESH); -	  	return true;  } @@ -1499,6 +1506,7 @@ bool rcCopyPolyMesh(rcContext* ctx, const rcPolyMesh& src, rcPolyMesh& dst)  	dst.cs = src.cs;  	dst.ch = src.ch;  	dst.borderSize = src.borderSize; +	dst.maxEdgeError = src.maxEdgeError;  	dst.verts = (unsigned short*)rcAlloc(sizeof(unsigned short)*src.nverts*3, RC_ALLOC_PERM);  	if (!dst.verts) | 
