Debian Codegraph @

debian/patches/0010-Some-quick-cleanup-in-RecastRasterization.cpp-655.patch

raw
1 From 6d9998e5b4fe96c607a04ed0fed318522165ab49 Mon Sep 17 00:00:00 2001
2 From: Graham Pentheny <[email protected]>
3 Date: Thu, 10 Aug 2023 16:39:36 -0400
4 Subject: [PATCH 10/36] Some quick cleanup in RecastRasterization.cpp (#655)
5
6 * Rename hf -> heightfield to be consistent
7 * Removed unused include
8 ---
9 Recast/Source/RecastRasterization.cpp | 81 +++++++++++++--------------
10 1 file changed, 40 insertions(+), 41 deletions(-)
11
12 diff --git a/Recast/Source/RecastRasterization.cpp b/Recast/Source/RecastRasterization.cpp
13 index 2a4f619..d54ae72 100644
14 --- a/Recast/Source/RecastRasterization.cpp
15 +++ b/Recast/Source/RecastRasterization.cpp
16 @@ -17,7 +17,6 @@
17 //
18
19 #include <math.h>
20 -#include <stdio.h>
21 #include "Recast.h"
22 #include "RecastAlloc.h"
23 #include "RecastAssert.h"
24 @@ -40,12 +39,12 @@ static bool overlapBounds(const float* aMin, const float* aMax, const float* bMi
25 /// Allocates a new span in the heightfield.
26 /// Use a memory pool and free list to minimize actual allocations.
27 ///
28 -/// @param[in] hf The heightfield
29 +/// @param[in] heightfield The heightfield
30 /// @returns A pointer to the allocated or re-used span memory.
31 -static rcSpan* allocSpan(rcHeightfield& hf)
32 +static rcSpan* allocSpan(rcHeightfield& heightfield)
33 {
34 // If necessary, allocate new page and update the freelist.
35 - if (hf.freelist == NULL || hf.freelist->next == NULL)
36 + if (heightfield.freelist == NULL || heightfield.freelist->next == NULL)
37 {
38 // Create new page.
39 // Allocate memory for the new pool.
40 @@ -56,11 +55,11 @@ static rcSpan* allocSpan(rcHeightfield& hf)
41 }
42
43 // Add the pool into the list of pools.
44 - spanPool->next = hf.pools;
45 - hf.pools = spanPool;
46 + spanPool->next = heightfield.pools;
47 + heightfield.pools = spanPool;
48
49 // Add new spans to the free list.
50 - rcSpan* freeList = hf.freelist;
51 + rcSpan* freeList = heightfield.freelist;
52 rcSpan* head = &spanPool->items[0];
53 rcSpan* it = &spanPool->items[RC_SPANS_PER_POOL];
54 do
55 @@ -70,46 +69,46 @@ static rcSpan* allocSpan(rcHeightfield& hf)
56 freeList = it;
57 }
58 while (it != head);
59 - hf.freelist = it;
60 + heightfield.freelist = it;
61 }
62
63 // Pop item from the front of the free list.
64 - rcSpan* newSpan = hf.freelist;
65 - hf.freelist = hf.freelist->next;
66 + rcSpan* newSpan = heightfield.freelist;
67 + heightfield.freelist = heightfield.freelist->next;
68 return newSpan;
69 }
70
71 /// Releases the memory used by the span back to the heightfield, so it can be re-used for new spans.
72 -/// @param[in] hf The heightfield.
73 +/// @param[in] heightfield The heightfield.
74 /// @param[in] span A pointer to the span to free
75 -static void freeSpan(rcHeightfield& hf, rcSpan* span)
76 +static void freeSpan(rcHeightfield& heightfield, rcSpan* span)
77 {
78 if (span == NULL)
79 {
80 return;
81 }
82 // Add the span to the front of the free list.
83 - span->next = hf.freelist;
84 - hf.freelist = span;
85 + span->next = heightfield.freelist;
86 + heightfield.freelist = span;
87 }
88
89 /// Adds a span to the heightfield. If the new span overlaps existing spans,
90 /// it will merge the new span with the existing ones.
91 ///
92 -/// @param[in] hf Heightfield to add spans to
93 +/// @param[in] heightfield Heightfield to add spans to
94 /// @param[in] x The new span's column cell x index
95 /// @param[in] z The new span's column cell z index
96 /// @param[in] min The new span's minimum cell index
97 /// @param[in] max The new span's maximum cell index
98 /// @param[in] areaID The new span's area type ID
99 /// @param[in] flagMergeThreshold How close two spans maximum extents need to be to merge area type IDs
100 -static bool addSpan(rcHeightfield& hf,
101 +static bool addSpan(rcHeightfield& heightfield,
102 const int x, const int z,
103 const unsigned short min, const unsigned short max,
104 const unsigned char areaID, const int flagMergeThreshold)
105 {
106 // Create the new span.
107 - rcSpan* newSpan = allocSpan(hf);
108 + rcSpan* newSpan = allocSpan(heightfield);
109 if (newSpan == NULL)
110 {
111 return false;
112 @@ -119,9 +118,9 @@ static bool addSpan(rcHeightfield& hf,
113 newSpan->area = areaID;
114 newSpan->next = NULL;
115
116 - const int columnIndex = x + z * hf.width;
117 + const int columnIndex = x + z * heightfield.width;
118 rcSpan* previousSpan = NULL;
119 - rcSpan* currentSpan = hf.spans[columnIndex];
120 + rcSpan* currentSpan = heightfield.spans[columnIndex];
121
122 // Insert the new span, possibly merging it with existing spans.
123 while (currentSpan != NULL)
124 @@ -160,14 +159,14 @@ static bool addSpan(rcHeightfield& hf,
125 // Remove the current span since it's now merged with newSpan.
126 // Keep going because there might be other overlapping spans that also need to be merged.
127 rcSpan* next = currentSpan->next;
128 - freeSpan(hf, currentSpan);
129 + freeSpan(heightfield, currentSpan);
130 if (previousSpan)
131 {
132 previousSpan->next = next;
133 }
134 else
135 {
136 - hf.spans[columnIndex] = next;
137 + heightfield.spans[columnIndex] = next;
138 }
139 currentSpan = next;
140 }
141 @@ -182,8 +181,8 @@ static bool addSpan(rcHeightfield& hf,
142 else
143 {
144 // This span should go before the others in the list
145 - newSpan->next = hf.spans[columnIndex];
146 - hf.spans[columnIndex] = newSpan;
147 + newSpan->next = heightfield.spans[columnIndex];
148 + heightfield.spans[columnIndex] = newSpan;
149 }
150
151 return true;
152 @@ -296,17 +295,17 @@ static void dividePoly(const float* inVerts, int inVertsCount,
153 /// @param[in] v1 Triangle vertex 1
154 /// @param[in] v2 Triangle vertex 2
155 /// @param[in] areaID The area ID to assign to the rasterized spans
156 -/// @param[in] hf Heightfield to rasterize into
157 -/// @param[in] hfBBMin The min extents of the heightfield bounding box
158 -/// @param[in] hfBBMax The max extents of the heightfield bounding box
159 +/// @param[in] heightfield Heightfield to rasterize into
160 +/// @param[in] heightfieldBBMin The min extents of the heightfield bounding box
161 +/// @param[in] heightfieldBBMax The max extents of the heightfield bounding box
162 /// @param[in] cellSize The x and z axis size of a voxel in the heightfield
163 /// @param[in] inverseCellSize 1 / cellSize
164 /// @param[in] inverseCellHeight 1 / cellHeight
165 /// @param[in] flagMergeThreshold The threshold in which area flags will be merged
166 /// @returns true if the operation completes successfully. false if there was an error adding spans to the heightfield.
167 static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
168 - const unsigned char areaID, rcHeightfield& hf,
169 - const float* hfBBMin, const float* hfBBMax,
170 + const unsigned char areaID, rcHeightfield& heightfield,
171 + const float* heightfieldBBMin, const float* heightfieldBBMax,
172 const float cellSize, const float inverseCellSize, const float inverseCellHeight,
173 const int flagMergeThreshold)
174 {
175 @@ -322,18 +321,18 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
176 rcVmax(triBBMax, v2);
177
178 // If the triangle does not touch the bounding box of the heightfield, skip the triangle.
179 - if (!overlapBounds(triBBMin, triBBMax, hfBBMin, hfBBMax))
180 + if (!overlapBounds(triBBMin, triBBMax, heightfieldBBMin, heightfieldBBMax))
181 {
182 return true;
183 }
184
185 - const int w = hf.width;
186 - const int h = hf.height;
187 - const float by = hfBBMax[1] - hfBBMin[1];
188 + const int w = heightfield.width;
189 + const int h = heightfield.height;
190 + const float by = heightfieldBBMax[1] - heightfieldBBMin[1];
191
192 // Calculate the footprint of the triangle on the grid's z-axis
193 - int z0 = (int)((triBBMin[2] - hfBBMin[2]) * inverseCellSize);
194 - int z1 = (int)((triBBMax[2] - hfBBMin[2]) * inverseCellSize);
195 + int z0 = (int)((triBBMin[2] - heightfieldBBMin[2]) * inverseCellSize);
196 + int z1 = (int)((triBBMax[2] - heightfieldBBMin[2]) * inverseCellSize);
197
198 // use -1 rather than 0 to cut the polygon properly at the start of the tile
199 z0 = rcClamp(z0, -1, h - 1);
200 @@ -355,7 +354,7 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
201 for (int z = z0; z <= z1; ++z)
202 {
203 // Clip polygon to row. Store the remaining polygon as well
204 - const float cellZ = hfBBMin[2] + (float)z * cellSize;
205 + const float cellZ = heightfieldBBMin[2] + (float)z * cellSize;
206 dividePoly(in, nvIn, inRow, &nvRow, p1, &nvIn, cellZ + cellSize, RC_AXIS_Z);
207 rcSwap(in, p1);
208
209 @@ -382,8 +381,8 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
210 maxX = inRow[vert * 3];
211 }
212 }
213 - int x0 = (int)((minX - hfBBMin[0]) * inverseCellSize);
214 - int x1 = (int)((maxX - hfBBMin[0]) * inverseCellSize);
215 + int x0 = (int)((minX - heightfieldBBMin[0]) * inverseCellSize);
216 + int x1 = (int)((maxX - heightfieldBBMin[0]) * inverseCellSize);
217 if (x1 < 0 || x0 >= w)
218 {
219 continue;
220 @@ -397,7 +396,7 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
221 for (int x = x0; x <= x1; ++x)
222 {
223 // Clip polygon to column. store the remaining polygon as well
224 - const float cx = hfBBMin[0] + (float)x * cellSize;
225 + const float cx = heightfieldBBMin[0] + (float)x * cellSize;
226 dividePoly(inRow, nv2, p1, &nv, p2, &nv2, cx + cellSize, RC_AXIS_X);
227 rcSwap(inRow, p2);
228
229 @@ -418,8 +417,8 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
230 spanMin = rcMin(spanMin, p1[vert * 3 + 1]);
231 spanMax = rcMax(spanMax, p1[vert * 3 + 1]);
232 }
233 - spanMin -= hfBBMin[1];
234 - spanMax -= hfBBMin[1];
235 + spanMin -= heightfieldBBMin[1];
236 + spanMax -= heightfieldBBMin[1];
237
238 // Skip the span if it's completely outside the heightfield bounding box
239 if (spanMax < 0.0f)
240 @@ -445,7 +444,7 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
241 unsigned short spanMinCellIndex = (unsigned short)rcClamp((int)floorf(spanMin * inverseCellHeight), 0, RC_SPAN_MAX_HEIGHT);
242 unsigned short spanMaxCellIndex = (unsigned short)rcClamp((int)ceilf(spanMax * inverseCellHeight), (int)spanMinCellIndex + 1, RC_SPAN_MAX_HEIGHT);
243
244 - if (!addSpan(hf, x, z, spanMinCellIndex, spanMaxCellIndex, areaID, flagMergeThreshold))
245 + if (!addSpan(heightfield, x, z, spanMinCellIndex, spanMaxCellIndex, areaID, flagMergeThreshold))
246 {
247 return false;
248 }
249 --
250 2.43.0
251