Return count from insert_center_points

This commit is contained in:
Kp 2015-02-14 22:48:28 +00:00
parent c6bb4206e6
commit 223f11bb70

View file

@ -94,14 +94,13 @@ static void create_random_xlate(array<uint8_t, MAX_SIDES_PER_SEGMENT> &xt)
// Insert the point at the center of the side connecting two segments between the two points.
// This is messy because we must insert into the list. The simplest (and not too slow) way to do this is to start
// at the end of the list and go backwards.
static void insert_center_points(point_seg *psegs, int *num_points)
static uint_fast32_t insert_center_points(point_seg *psegs, uint_fast32_t count)
{
int i, last_point;
int count=*num_points;
last_point = *num_points-1;
for (i=last_point; i>0; i--) {
if (count < 2)
return count;
uint_fast32_t last_point = count - 1;
for (uint_fast32_t i = last_point; i; --i)
{
psegs[2*i] = psegs[i];
auto connect_side = find_connect_side(&Segments[psegs[i].segnum], &Segments[psegs[i-1].segnum]);
Assert(connect_side != -1); // Impossible! These two segments must be connected, they were created by create_path_points (which was created by mk!)
@ -125,13 +124,12 @@ static void insert_center_points(point_seg *psegs, int *num_points)
count++;
}
#if defined(DXX_BUILD_DESCENT_I)
*num_points = count;
#elif defined(DXX_BUILD_DESCENT_II)
#if defined(DXX_BUILD_DESCENT_II)
// Now, remove unnecessary center points.
// A center point is unnecessary if it is close to the line between the two adjacent points.
// MK, OPTIMIZE! Can get away with about half the math since every vector gets computed twice.
for (i=1; i<count-1; i+=2) {
for (uint_fast32_t i = 1; i < count - 1; i += 2)
{
vms_vector temp1, temp2;
fix dot;
@ -144,8 +142,9 @@ static void insert_center_points(point_seg *psegs, int *num_points)
// Now, scan for points with segnum == -1
auto predicate = [](const point_seg &p) { return p.segnum == segment_none; };
*num_points = std::distance(psegs, std::remove_if(psegs, psegs + count, predicate));
count = std::distance(psegs, std::remove_if(psegs, psegs + count, predicate));
#endif
return count;
}
#if defined(DXX_BUILD_DESCENT_II)
@ -472,7 +471,7 @@ cpp_done1: ;
*num_points = l_num_points;
return -1;
} else {
insert_center_points(original_psegs, &l_num_points);
l_num_points = insert_center_points(original_psegs, l_num_points);
}
}