File: 0022-Code-cleanup-and-small-optimizations-in-RecastFilter.patch

package info (click to toggle)
recastnavigation 1.6.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,928 kB
  • sloc: cpp: 50,116; ansic: 2,674; xml: 182; makefile: 16
file content (89 lines) | stat: -rw-r--r-- 3,929 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
From 3e94c3b6fcb5361bc30e87cacfa0ff46bde37a2c Mon Sep 17 00:00:00 2001
From: Cupcake <1357715449@qq.com>
Date: Mon, 1 Jan 2024 03:27:07 +0800
Subject: [PATCH 22/36] Code cleanup and small optimizations in
 RecastFilter.cpp rcFilterLedgeSpans (#672)

* Code cleanup and minor refactor in RecastFilter.cpp rcFilterLedgeSpans

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.

* Code cleanup and minor refactor in RecastFilter.cpp rcFilterLedgeSpans

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.

* Update RecastFilter.cpp

Revise Comment
---
 Recast/Source/RecastFilter.cpp | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/Recast/Source/RecastFilter.cpp b/Recast/Source/RecastFilter.cpp
index b5adba4..8f3414b 100644
--- a/Recast/Source/RecastFilter.cpp
+++ b/Recast/Source/RecastFilter.cpp
@@ -96,42 +96,47 @@ void rcFilterLedgeSpans(rcContext* context, const int walkableHeight, const int
 				for (int direction = 0; direction < 4; ++direction)
 				{
 					int dx = x + rcGetDirOffsetX(direction);
-					int dy = z + rcGetDirOffsetY(direction);
+					int dz = z + rcGetDirOffsetY(direction);
 					// Skip neighbours which are out of bounds.
-					if (dx < 0 || dy < 0 || dx >= xSize || dy >= zSize)
+					if (dx < 0 || dz < 0 || dx >= xSize || dz >= zSize)
 					{
-						minNeighborHeight = rcMin(minNeighborHeight, -walkableClimb - bot);
-						continue;
+						minNeighborHeight = (-walkableClimb - 1) ;
+						break;
 					}
 
 					// From minus infinity to the first span.
-					const rcSpan* neighborSpan = heightfield.spans[dx + dy * xSize];
-					int neighborBot = -walkableClimb;
+					const rcSpan* neighborSpan = heightfield.spans[dx + dz * xSize];
 					int neighborTop = neighborSpan ? (int)neighborSpan->smin : MAX_HEIGHT;
 					
 					// Skip neighbour if the gap between the spans is too small.
-					if (rcMin(top, neighborTop) - rcMax(bot, neighborBot) > walkableHeight)
+					if (rcMin(top, neighborTop) - bot >= walkableHeight)
 					{
-						minNeighborHeight = rcMin(minNeighborHeight, neighborBot - bot);
+						minNeighborHeight = (-walkableClimb - 1);
+						break;
 					}
 
 					// Rest of the spans.
-					for (neighborSpan = heightfield.spans[dx + dy * xSize]; neighborSpan; neighborSpan = neighborSpan->next)
+					for (neighborSpan = heightfield.spans[dx + dz * xSize]; neighborSpan; neighborSpan = neighborSpan->next)
 					{
-						neighborBot = (int)neighborSpan->smax;
+						int neighborBot = (int)neighborSpan->smax;
 						neighborTop = neighborSpan->next ? (int)neighborSpan->next->smin : MAX_HEIGHT;
 						
 						// Skip neighbour if the gap between the spans is too small.
-						if (rcMin(top, neighborTop) - rcMax(bot, neighborBot) > walkableHeight)
+						if (rcMin(top, neighborTop) - rcMax(bot, neighborBot) >= walkableHeight)
 						{
-							minNeighborHeight = rcMin(minNeighborHeight, neighborBot - bot);
+							int accessibleNeighbourHeight = neighborBot - bot;
+							minNeighborHeight = rcMin(minNeighborHeight, accessibleNeighbourHeight);
 
 							// Find min/max accessible neighbour height. 
-							if (rcAbs(neighborBot - bot) <= walkableClimb)
+							if (rcAbs(accessibleNeighbourHeight) <= walkableClimb)
 							{
 								if (neighborBot < accessibleNeighborMinHeight) accessibleNeighborMinHeight = neighborBot;
 								if (neighborBot > accessibleNeighborMaxHeight) accessibleNeighborMaxHeight = neighborBot;
 							}
+							else if (accessibleNeighbourHeight < -walkableClimb)
+							{
+								break;
+							}
 
 						}
 					}
-- 
2.43.0