From 2aa70cb4976fb8e62f3723fe0466be3108f61151 Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Sun, 21 Nov 2010 14:52:55 +0000 Subject: [PATCH] Fix for issue 144. Treat region borders as empty in floodRegions() to allow 1 width regions to grow next to tile border. Made area marking code not to override RC_NULL_AREA. --- Recast/Source/RecastArea.cpp | 5 ++++- Recast/Source/RecastRegion.cpp | 19 ++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Recast/Source/RecastArea.cpp b/Recast/Source/RecastArea.cpp index e89caee..c18277b 100644 --- a/Recast/Source/RecastArea.cpp +++ b/Recast/Source/RecastArea.cpp @@ -322,7 +322,8 @@ void rcMarkBoxArea(rcContext* ctx, const float* bmin, const float* bmax, unsigne rcCompactSpan& s = chf.spans[i]; if ((int)s.y >= miny && (int)s.y <= maxy) { - chf.areas[i] = areaId; + if (chf.areas[i] != RC_NULL_AREA) + chf.areas[i] = areaId; } } } @@ -393,6 +394,8 @@ void rcMarkConvexPolyArea(rcContext* ctx, const float* verts, const int nverts, for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i) { rcCompactSpan& s = chf.spans[i]; + if (chf.areas[i] == RC_NULL_AREA) + continue; if ((int)s.y >= miny && (int)s.y <= maxy) { float p[3]; diff --git a/Recast/Source/RecastRegion.cpp b/Recast/Source/RecastRegion.cpp index 6ad9fa5..131a5b8 100644 --- a/Recast/Source/RecastRegion.cpp +++ b/Recast/Source/RecastRegion.cpp @@ -283,6 +283,8 @@ static bool floodRegion(int x, int y, int i, if (chf.areas[ai] != area) continue; unsigned short nr = srcReg[ai]; + if (nr & RC_BORDER_REG) // Do not take borders into account. + continue; if (nr != 0 && nr != r) ar = nr; @@ -319,16 +321,13 @@ static bool floodRegion(int x, int y, int i, const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(cs, dir); if (chf.areas[ai] != area) continue; - if (chf.dist[ai] >= lev) + if (chf.dist[ai] >= lev && srcReg[ai] == 0) { - if (srcReg[ai] == 0) - { - srcReg[ai] = r; - srcDist[ai] = 0; - stack.push(ax); - stack.push(ay); - stack.push(ai); - } + srcReg[ai] = r; + srcDist[ai] = 0; + stack.push(ax); + stack.push(ay); + stack.push(ai); } } } @@ -1242,7 +1241,6 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf, { if (chf.dist[i] < level || srcReg[i] != 0 || chf.areas[i] == RC_NULL_AREA) continue; - if (floodRegion(x, y, i, level, regionId, chf, srcReg, srcDist, stack)) regionId++; } @@ -1250,7 +1248,6 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf, } ctx->stopTimer(RC_TIMER_BUILD_REGIONS_FLOOD); - } // Expand current regions until no empty connected cells found.