| 1 |
From 3e94c3b6fcb5361bc30e87cacfa0ff46bde37a2c Mon Sep 17 00:00:00 2001 |
| 2 |
From: Cupcake <[email protected]> |
| 3 |
Date: Mon, 1 Jan 2024 03:27:07 +0800 |
| 4 |
Subject: [PATCH 22/36] Code cleanup and small optimizations in |
| 5 |
RecastFilter.cpp rcFilterLedgeSpans (#672) |
| 6 |
|
| 7 |
* Code cleanup and minor refactor in RecastFilter.cpp rcFilterLedgeSpans |
| 8 |
|
| 9 |
Because span.smax is always > 0, bot > 0 as well, and (-walkableClimb - bot) is always < -walkableClimb. Furthermore, as long as minNeighborHeight < -walkableClimb' at least once, there is no need to continue the traversal. |
| 10 |
|
| 11 |
* Code cleanup and minor refactor in RecastFilter.cpp rcFilterLedgeSpans |
| 12 |
|
| 13 |
Because span.smax is always > 0, bot > 0 as well, and (-walkableClimb - bot) is always < -walkableClimb. Furthermore, as long as minNeighborHeight < -walkableClimb' at least once, there is no need to continue the traversal. |
| 14 |
|
| 15 |
* Update RecastFilter.cpp |
| 16 |
|
| 17 |
Revise Comment |
| 18 |
--- |
| 19 |
Recast/Source/RecastFilter.cpp | 31 ++++++++++++++++++------------- |
| 20 |
1 file changed, 18 insertions(+), 13 deletions(-) |
| 21 |
|
| 22 |
diff --git a/Recast/Source/RecastFilter.cpp b/Recast/Source/RecastFilter.cpp |
| 23 |
index b5adba4..8f3414b 100644 |
| 24 |
--- a/Recast/Source/RecastFilter.cpp |
| 25 |
+++ b/Recast/Source/RecastFilter.cpp |
| 26 |
@@ -96,42 +96,47 @@ void rcFilterLedgeSpans(rcContext* context, const int walkableHeight, const int |
| 27 |
for (int direction = 0; direction < 4; ++direction) |
| 28 |
{ |
| 29 |
int dx = x + rcGetDirOffsetX(direction); |
| 30 |
- int dy = z + rcGetDirOffsetY(direction); |
| 31 |
+ int dz = z + rcGetDirOffsetY(direction); |
| 32 |
// Skip neighbours which are out of bounds. |
| 33 |
- if (dx < 0 || dy < 0 || dx >= xSize || dy >= zSize) |
| 34 |
+ if (dx < 0 || dz < 0 || dx >= xSize || dz >= zSize) |
| 35 |
{ |
| 36 |
- minNeighborHeight = rcMin(minNeighborHeight, -walkableClimb - bot); |
| 37 |
- continue; |
| 38 |
+ minNeighborHeight = (-walkableClimb - 1) ; |
| 39 |
+ break; |
| 40 |
} |
| 41 |
|
| 42 |
// From minus infinity to the first span. |
| 43 |
- const rcSpan* neighborSpan = heightfield.spans[dx + dy * xSize]; |
| 44 |
- int neighborBot = -walkableClimb; |
| 45 |
+ const rcSpan* neighborSpan = heightfield.spans[dx + dz * xSize]; |
| 46 |
int neighborTop = neighborSpan ? (int)neighborSpan->smin : MAX_HEIGHT; |
| 47 |
|
| 48 |
// Skip neighbour if the gap between the spans is too small. |
| 49 |
- if (rcMin(top, neighborTop) - rcMax(bot, neighborBot) > walkableHeight) |
| 50 |
+ if (rcMin(top, neighborTop) - bot >= walkableHeight) |
| 51 |
{ |
| 52 |
- minNeighborHeight = rcMin(minNeighborHeight, neighborBot - bot); |
| 53 |
+ minNeighborHeight = (-walkableClimb - 1); |
| 54 |
+ break; |
| 55 |
} |
| 56 |
|
| 57 |
// Rest of the spans. |
| 58 |
- for (neighborSpan = heightfield.spans[dx + dy * xSize]; neighborSpan; neighborSpan = neighborSpan->next) |
| 59 |
+ for (neighborSpan = heightfield.spans[dx + dz * xSize]; neighborSpan; neighborSpan = neighborSpan->next) |
| 60 |
{ |
| 61 |
- neighborBot = (int)neighborSpan->smax; |
| 62 |
+ int neighborBot = (int)neighborSpan->smax; |
| 63 |
neighborTop = neighborSpan->next ? (int)neighborSpan->next->smin : MAX_HEIGHT; |
| 64 |
|
| 65 |
// Skip neighbour if the gap between the spans is too small. |
| 66 |
- if (rcMin(top, neighborTop) - rcMax(bot, neighborBot) > walkableHeight) |
| 67 |
+ if (rcMin(top, neighborTop) - rcMax(bot, neighborBot) >= walkableHeight) |
| 68 |
{ |
| 69 |
- minNeighborHeight = rcMin(minNeighborHeight, neighborBot - bot); |
| 70 |
+ int accessibleNeighbourHeight = neighborBot - bot; |
| 71 |
+ minNeighborHeight = rcMin(minNeighborHeight, accessibleNeighbourHeight); |
| 72 |
|
| 73 |
// Find min/max accessible neighbour height. |
| 74 |
- if (rcAbs(neighborBot - bot) <= walkableClimb) |
| 75 |
+ if (rcAbs(accessibleNeighbourHeight) <= walkableClimb) |
| 76 |
{ |
| 77 |
if (neighborBot < accessibleNeighborMinHeight) accessibleNeighborMinHeight = neighborBot; |
| 78 |
if (neighborBot > accessibleNeighborMaxHeight) accessibleNeighborMaxHeight = neighborBot; |
| 79 |
} |
| 80 |
+ else if (accessibleNeighbourHeight < -walkableClimb) |
| 81 |
+ { |
| 82 |
+ break; |
| 83 |
+ } |
| 84 |
|
| 85 |
} |
| 86 |
} |
| 87 |
-- |
| 88 |
2.43.0 |
| 89 |
|