diff --git a/tools/quake3/common/polylib.cpp b/tools/quake3/common/polylib.cpp index 2d509a0e..fdbbf4f1 100644 --- a/tools/quake3/common/polylib.cpp +++ b/tools/quake3/common/polylib.cpp @@ -29,10 +29,9 @@ #define BOGUS_RANGE WORLD_SIZE -void pw( winding_t *w ){ - int i; - for ( i = 0 ; i < w->numpoints ; i++ ) - Sys_Printf( "(%5.1f, %5.1f, %5.1f)\n",w->p[i][0], w->p[i][1],w->p[i][2] ); +void pw( const winding_t& w ){ + for ( const Vector3& p : w ) + Sys_Printf( "(%5.1f, %5.1f, %5.1f)\n", p[0], p[1], p[2] ); } @@ -45,7 +44,9 @@ winding_t *AllocWinding( int points ){ if ( points >= MAX_POINTS_ON_WINDING ) { Error( "AllocWinding failed: MAX_POINTS_ON_WINDING exceeded" ); } - return safe_calloc( offsetof_array( winding_t, p, points ) ); + winding_t *w = new winding_t; + w->reserve( points ); + return w; } /* @@ -57,13 +58,7 @@ void FreeWinding( winding_t *w ){ if ( !w ) { Error( "FreeWinding: winding is NULL" ); } - - if ( *(unsigned *)w == 0xdeaddead ) { - Error( "FreeWinding: freed a freed winding" ); - } - *(unsigned *)w = 0xdeaddead; - - free( w ); + delete w; } /* @@ -71,28 +66,22 @@ void FreeWinding( winding_t *w ){ RemoveColinearPoints ============ */ -void RemoveColinearPoints( winding_t *w ){ - int i, j, k; - int nump; - Vector3 p[MAX_POINTS_ON_WINDING]; +void RemoveColinearPoints( winding_t& w ){ + winding_t p; + p.reserve( w.size() ); - nump = 0; - for ( i = 0 ; i < w->numpoints ; i++ ) + for ( size_t i = 0 ; i < w.size() ; i++ ) { - j = ( i + 1 ) % w->numpoints; - k = ( i + w->numpoints - 1 ) % w->numpoints; - if ( vector3_dot( VectorNormalized( w->p[j] - w->p[i] ), VectorNormalized( w->p[j] - w->p[k] ) ) < 0.999 ) { - p[nump] = w->p[i]; - nump++; + const size_t j = ( i + 1 ) % w.size(); + const size_t k = ( i + w.size() - 1 ) % w.size(); + if ( vector3_dot( VectorNormalized( w[j] - w[i] ), VectorNormalized( w[j] - w[k] ) ) < 0.999 ) { + p.push_back( w[i] ); } } - if ( nump == w->numpoints ) { - return; + if ( p.size() != w.size() ) { + w.swap( p ); } - - w->numpoints = nump; - memcpy( w->p, p, nump * sizeof( p[0] ) ); } /* @@ -100,9 +89,9 @@ void RemoveColinearPoints( winding_t *w ){ WindingPlane ============ */ -Plane3f WindingPlane( const winding_t *w ){ +Plane3f WindingPlane( const winding_t& w ){ Plane3f plane; - PlaneFromPoints( plane, w->p[0], w->p[1], w->p[2] ); + PlaneFromPoints( plane, w.data() ); return plane; } @@ -111,20 +100,20 @@ Plane3f WindingPlane( const winding_t *w ){ WindingArea ============= */ -float WindingArea( const winding_t *w ){ +float WindingArea( const winding_t& w ){ float total = 0; - for ( int i = 2 ; i < w->numpoints ; i++ ) + for ( size_t i = 2; i < w.size(); i++ ) { - total += 0.5 * vector3_length( vector3_cross( w->p[i - 1] - w->p[0], w->p[i] - w->p[0] ) ); + total += 0.5 * vector3_length( vector3_cross( w[i - 1] - w[0], w[i] - w[0] ) ); } return total; } -void WindingExtendBounds( const winding_t *w, MinMax& minmax ){ - for ( int i = 0 ; i < w->numpoints ; ++i ) +void WindingExtendBounds( const winding_t& w, MinMax& minmax ){ + for ( const Vector3& p : w ) { - minmax.extend( w->p[i] ); + minmax.extend( p ); } } @@ -133,13 +122,13 @@ void WindingExtendBounds( const winding_t *w, MinMax& minmax ){ WindingCenter ============= */ -Vector3 WindingCenter( const winding_t *w ){ +Vector3 WindingCenter( const winding_t& w ){ Vector3 center( 0 ); - for ( int i = 0 ; i < w->numpoints ; i++ ) - center += w->p[i]; + for ( const Vector3& p : w ) + center += p; - return center / w->numpoints; + return center / w.size(); } /* @@ -261,7 +250,6 @@ winding_t *BaseWindingForPlane( const Plane3f& plane ){ int i, x; float max, v; Vector3 org, vright, vup; - winding_t *w; // find the major axis @@ -305,16 +293,12 @@ winding_t *BaseWindingForPlane( const Plane3f& plane ){ vright *= MAX_WORLD_COORD * 2; // project a really big axis aligned box onto the plane - w = AllocWinding( 4 ); - - w->p[0] = org - vright + vup; - w->p[1] = org + vright + vup; - w->p[2] = org + vright - vup; - w->p[3] = org - vright - vup; - - w->numpoints = 4; - - return w; + return new winding_t{ + org - vright + vup, + org + vright + vup, + org + vright - vup, + org - vright - vup + }; } /* @@ -326,7 +310,7 @@ winding_t *CopyWinding( const winding_t *w ){ if ( !w ) { Error( "CopyWinding: winding is NULL" ); } - return void_ptr( memcpy( AllocWinding( w->numpoints ), w, offsetof_array( winding_t, p, w->numpoints ) ) ); + return new winding_t( *w ); } /* @@ -335,13 +319,7 @@ winding_t *CopyWinding( const winding_t *w ){ ================== */ winding_t *CopyWindingAccuToRegular( const winding_accu_t& w ){ - winding_t *c = AllocWinding( w.size() ); - c->numpoints = w.size(); - for ( int i = 0; i < c->numpoints; i++ ) - { - c->p[i] = w[i]; - } - return c; + return new winding_t( w.begin(), w.end() ); } /* @@ -349,17 +327,8 @@ winding_t *CopyWindingAccuToRegular( const winding_accu_t& w ){ ReverseWinding ================== */ -winding_t *ReverseWinding( const winding_t *w ){ - int i; - winding_t *c; - - c = AllocWinding( w->numpoints ); - for ( i = 0 ; i < w->numpoints ; i++ ) - { - c->p[i] = w->p[w->numpoints - 1 - i]; - } - c->numpoints = w->numpoints; - return c; +winding_t *ReverseWinding( const winding_t& w ){ + return new winding_t( w.crbegin(), w.crend() ); } @@ -368,22 +337,18 @@ winding_t *ReverseWinding( const winding_t *w ){ ClipWindingEpsilon ============= */ -void ClipWindingEpsilonStrict( winding_t *in, const Plane3f& plane, - float epsilon, winding_t **front, winding_t **back ){ +void ClipWindingEpsilonStrict( const winding_t& in, const Plane3f& plane, + float epsilon, winding_t *&front, winding_t *&back ){ float dists[MAX_POINTS_ON_WINDING + 4]; EPlaneSide sides[MAX_POINTS_ON_WINDING + 4]; - int counts[3]; - int i, j; - winding_t *f, *b; - int maxpts; - - counts[0] = counts[1] = counts[2] = 0; + int counts[3] = { 0 }; + size_t i, j; // determine sides for each point - for ( i = 0 ; i < in->numpoints ; i++ ) + for ( i = 0; i < in.size(); i++ ) { - dists[i] = plane3_distance_to_point( plane, in->p[i] ); + dists[i] = plane3_distance_to_point( plane, in[i] ); if ( dists[i] > epsilon ) { sides[i] = eSideFront; } @@ -399,45 +364,41 @@ void ClipWindingEpsilonStrict( winding_t *in, const Plane3f& plane, sides[i] = sides[0]; dists[i] = dists[0]; - *front = *back = NULL; + front = back = NULL; - if ( !counts[0] && !counts[1] ) { + if ( !counts[eSideFront] && !counts[eSideBack] ) { return; } - if ( !counts[0] ) { - *back = CopyWinding( in ); + if ( !counts[eSideFront] ) { + back = CopyWinding( &in ); return; } - if ( !counts[1] ) { - *front = CopyWinding( in ); + if ( !counts[eSideBack] ) { + front = CopyWinding( &in ); return; } - maxpts = in->numpoints + 4; // cant use counts[0]+2 because + const size_t maxpts = in.size() + 4; // cant use counts[0]+2 because // of fp grouping errors - *front = f = AllocWinding( maxpts ); - *back = b = AllocWinding( maxpts ); + front = AllocWinding( maxpts ); + back = AllocWinding( maxpts ); - for ( i = 0 ; i < in->numpoints ; i++ ) + for ( i = 0 ; i < in.size() ; i++ ) { - const Vector3& p1 = in->p[i]; + const Vector3& p1 = in[i]; if ( sides[i] == eSideOn ) { - f->p[f->numpoints] = p1; - f->numpoints++; - b->p[b->numpoints] = p1; - b->numpoints++; + front->push_back( p1 ); + back->push_back( p1 ); continue; } if ( sides[i] == eSideFront ) { - f->p[f->numpoints] = p1; - f->numpoints++; + front->push_back( p1 ); } if ( sides[i] == eSideBack ) { - b->p[b->numpoints] = p1; - b->numpoints++; + back->push_back( p1 ); } if ( sides[i + 1] == eSideOn || sides[i + 1] == sides[i] ) { @@ -445,10 +406,10 @@ void ClipWindingEpsilonStrict( winding_t *in, const Plane3f& plane, } // generate a split point - const Vector3& p2 = in->p[( i + 1 ) % in->numpoints]; + const Vector3& p2 = in[( i + 1 ) % in.size()]; const double dot = dists[i] / ( dists[i] - dists[i + 1] ); Vector3 mid; - for ( j = 0 ; j < 3 ; j++ ) + for ( j = 0; j < 3; j++ ) { // avoid round off error when possible if ( plane.normal()[j] == 1 ) { mid[j] = plane.dist(); @@ -461,26 +422,21 @@ void ClipWindingEpsilonStrict( winding_t *in, const Plane3f& plane, } } - f->p[f->numpoints] = mid; - f->numpoints++; - b->p[b->numpoints] = mid; - b->numpoints++; + front->push_back( mid ); + back->push_back( mid ); } - if ( f->numpoints > maxpts || b->numpoints > maxpts ) { - Error( "ClipWinding: points exceeded estimate" ); - } - if ( f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING ) { + if ( front->size() > MAX_POINTS_ON_WINDING || back->size() > MAX_POINTS_ON_WINDING ) { Error( "ClipWinding: MAX_POINTS_ON_WINDING" ); } } -void ClipWindingEpsilon( winding_t *in, const Plane3f& plane, - float epsilon, winding_t **front, winding_t **back ){ +void ClipWindingEpsilon( const winding_t& in, const Plane3f& plane, + float epsilon, winding_t *&front, winding_t *&back ){ ClipWindingEpsilonStrict( in, plane, epsilon, front, back ); /* apparently most code expects that in the winding-on-plane case, the back winding is the original winding */ - if ( !*front && !*back ) { - *back = CopyWinding( in ); + if ( !front && !back ) { + back = CopyWinding( &in ); } } @@ -622,22 +578,17 @@ void ChopWindingInPlaceAccu( winding_accu_t& inout, const Plane3& plane, float c ChopWindingInPlace ============= */ -void ChopWindingInPlace( winding_t **inout, const Plane3f& plane, float epsilon ){ - winding_t *in; +void ChopWindingInPlace( winding_t *&inout, const Plane3f& plane, float epsilon ){ + winding_t& in = *inout; float dists[MAX_POINTS_ON_WINDING + 4]; EPlaneSide sides[MAX_POINTS_ON_WINDING + 4]; - int counts[3]; - int i, j; - winding_t *f; - int maxpts; - - in = *inout; - counts[0] = counts[1] = counts[2] = 0; + int counts[3] = { 0 }; + size_t i, j; // determine sides for each point - for ( i = 0 ; i < in->numpoints ; i++ ) + for ( i = 0; i < in.size(); i++ ) { - dists[i] = plane3_distance_to_point( plane, in->p[i] ); + dists[i] = plane3_distance_to_point( plane, in[i] ); if ( dists[i] > epsilon ) { sides[i] = eSideFront; } @@ -653,33 +604,30 @@ void ChopWindingInPlace( winding_t **inout, const Plane3f& plane, float epsilon sides[i] = sides[0]; dists[i] = dists[0]; - if ( !counts[0] ) { - FreeWinding( in ); - *inout = NULL; + if ( !counts[eSideFront] ) { + FreeWinding( inout ); + inout = NULL; return; } - if ( !counts[1] ) { + if ( !counts[eSideBack] ) { return; // inout stays the same } - maxpts = in->numpoints + 4; // cant use counts[0]+2 because - // of fp grouping errors - f = AllocWinding( maxpts ); + winding_t f; + f.reserve( in.size() + 4 ); // cant use counts[0]+2 because of fp grouping errors - for ( i = 0 ; i < in->numpoints ; i++ ) + for ( i = 0; i < in.size(); i++ ) { - const Vector3& p1 = in->p[i]; + const Vector3& p1 = in[i]; if ( sides[i] == eSideOn ) { - f->p[f->numpoints] = p1; - f->numpoints++; + f.push_back( p1 ); continue; } if ( sides[i] == eSideFront ) { - f->p[f->numpoints] = p1; - f->numpoints++; + f.push_back( p1 ); } if ( sides[i + 1] == eSideOn || sides[i + 1] == sides[i] ) { @@ -687,11 +635,11 @@ void ChopWindingInPlace( winding_t **inout, const Plane3f& plane, float epsilon } // generate a split point - const Vector3& p2 = in->p[( i + 1 ) % in->numpoints]; + const Vector3& p2 = in[( i + 1 ) % in.size()]; const double dot = dists[i] / ( dists[i] - dists[i + 1] ); Vector3 mid; - for ( j = 0 ; j < 3 ; j++ ) + for ( j = 0; j < 3; j++ ) { // avoid round off error when possible if ( plane.normal()[j] == 1 ) { mid[j] = plane.dist(); @@ -704,19 +652,14 @@ void ChopWindingInPlace( winding_t **inout, const Plane3f& plane, float epsilon } } - f->p[f->numpoints] = mid; - f->numpoints++; + f.push_back( mid ); } - if ( f->numpoints > maxpts ) { - Error( "ClipWinding: points exceeded estimate" ); - } - if ( f->numpoints > MAX_POINTS_ON_WINDING ) { + if ( f.size() > MAX_POINTS_ON_WINDING ) { Error( "ClipWinding: MAX_POINTS_ON_WINDING" ); } - FreeWinding( in ); - *inout = f; + inout->swap( f ); } @@ -731,7 +674,7 @@ void ChopWindingInPlace( winding_t **inout, const Plane3f& plane, float epsilon winding_t *ChopWinding( winding_t *in, const Plane3f& plane ){ winding_t *f, *b; - ClipWindingEpsilon( in, plane, ON_EPSILON, &f, &b ); + ClipWindingEpsilon( *in, plane, ON_EPSILON, f, b ); FreeWinding( in ); if ( b ) { FreeWinding( b ); @@ -747,56 +690,49 @@ inline const MinMax c_worldMinmax( Vector3( MIN_WORLD_COORD ), Vector3( MAX_WORL ================= */ -void CheckWinding( winding_t *w ){ - int i, j; - float edgedist; - Vector3 dir, edgenormal; - float area; - - if ( w->numpoints < 3 ) { - Error( "CheckWinding: %i points",w->numpoints ); +void CheckWinding( const winding_t& w ){ + if ( w.size() < 3 ) { + Error( "CheckWinding: %zu points",w.size() ); } - area = WindingArea( w ); + const float area = WindingArea( w ); if ( area < 1 ) { Error( "CheckWinding: %f area", area ); } const Plane3f faceplane = WindingPlane( w ); - for ( i = 0 ; i < w->numpoints ; i++ ) + for ( size_t i = 0 ; i < w.size() ; i++ ) { - const Vector3& p1 = w->p[i]; + const Vector3& p1 = w[i]; if ( !c_worldMinmax.test( p1 ) ) { Error( "CheckFace: MAX_WORLD_COORD exceeded: ( %f %f %f )", p1[0], p1[1], p1[2] ); } - j = ( i + 1 == w->numpoints )? 0 : i + 1; - // check the point is on the face plane if ( fabs( plane3_distance_to_point( faceplane, p1 ) ) > ON_EPSILON ) { Error( "CheckWinding: point off plane" ); } // check the edge isnt degenerate - const Vector3& p2 = w->p[j]; - dir = p2 - p1; + const Vector3& p2 = w[( i + 1 == w.size() )? 0 : i + 1]; + const Vector3 dir = p2 - p1; if ( vector3_length( dir ) < ON_EPSILON ) { Error( "CheckWinding: degenerate edge" ); } - edgenormal = VectorNormalized( vector3_cross( faceplane.normal(), dir ) ); - edgedist = vector3_dot( p1, edgenormal ) + ON_EPSILON; + const Vector3 edgenormal = VectorNormalized( vector3_cross( faceplane.normal(), dir ) ); + const float edgedist = vector3_dot( p1, edgenormal ) + ON_EPSILON; // all other points must be on front side - for ( j = 0 ; j < w->numpoints ; j++ ) + for ( size_t j = 0 ; j < w.size() ; j++ ) { if ( j == i ) { continue; } - if ( vector3_dot( w->p[j], edgenormal ) > edgedist ) { + if ( vector3_dot( w[j], edgenormal ) > edgedist ) { Error( "CheckWinding: non-convex" ); } } @@ -809,12 +745,12 @@ void CheckWinding( winding_t *w ){ WindingOnPlaneSide ============ */ -EPlaneSide WindingOnPlaneSide( const winding_t *w, const Plane3f& plane ){ +EPlaneSide WindingOnPlaneSide( const winding_t& w, const Plane3f& plane ){ bool front = false; bool back = false; - for ( int i = 0 ; i < w->numpoints ; i++ ) + for ( const Vector3& p : w ) { - const double d = plane3_distance_to_point( plane, w->p[i] ); + const double d = plane3_distance_to_point( plane, p ); if ( d < -ON_EPSILON ) { if ( front ) { return eSideCross; @@ -849,8 +785,8 @@ EPlaneSide WindingOnPlaneSide( const winding_t *w, const Plane3f& plane ){ ================= */ #define MAX_HULL_POINTS 128 -void AddWindingToConvexHull( winding_t *w, winding_t **hull, const Vector3& normal ) { - int i, j, k; +void AddWindingToConvexHull( const winding_t& w, winding_t *&hull, const Vector3& normal ) { + int j, k; int numHullPoints, numNew; Vector3 hullPoints[MAX_HULL_POINTS]; Vector3 newHullPoints[MAX_HULL_POINTS]; @@ -858,26 +794,24 @@ void AddWindingToConvexHull( winding_t *w, winding_t **hull, const Vector3& n bool hullSide[MAX_HULL_POINTS]; bool outside; - if ( *hull == nullptr ) { - *hull = CopyWinding( w ); + if ( hull == nullptr ) { + hull = CopyWinding( &w ); return; } - numHullPoints = ( *hull )->numpoints; - memcpy( hullPoints, ( *hull )->p, numHullPoints * sizeof( Vector3 ) ); - - for ( i = 0 ; i < w->numpoints ; i++ ) { - const Vector3 &p = w->p[i]; + numHullPoints = hull->size(); + memcpy( hullPoints, hull->data(), numHullPoints * sizeof( Vector3 ) ); + for ( const Vector3 &p : w ) { // calculate hull side vectors - for ( j = 0 ; j < numHullPoints ; j++ ) { + for ( j = 0; j < numHullPoints; j++ ) { k = ( j + 1 ) % numHullPoints; hullDirs[j] = vector3_cross( normal, VectorNormalized( hullPoints[k] - hullPoints[j] ) ); } outside = false; - for ( j = 0 ; j < numHullPoints ; j++ ) { + for ( j = 0; j < numHullPoints; j++ ) { const double d = vector3_dot( p - hullPoints[j], hullDirs[j] ); if ( d >= ON_EPSILON ) { outside = true; @@ -891,7 +825,7 @@ void AddWindingToConvexHull( winding_t *w, winding_t **hull, const Vector3& n } // find the back side to front side transition - for ( j = 0 ; j < numHullPoints ; j++ ) { + for ( j = 0; j < numHullPoints; j++ ) { if ( !hullSide[ j % numHullPoints ] && hullSide[ ( j + 1 ) % numHullPoints ] ) { break; } @@ -906,7 +840,7 @@ void AddWindingToConvexHull( winding_t *w, winding_t **hull, const Vector3& n // copy over all points that aren't double fronts j = ( j + 1 ) % numHullPoints; - for ( k = 0 ; k < numHullPoints ; k++ ) { + for ( k = 0; k < numHullPoints; k++ ) { if ( hullSide[ ( j + k ) % numHullPoints ] && hullSide[ ( j + k + 1 ) % numHullPoints ] ) { continue; } @@ -918,9 +852,5 @@ void AddWindingToConvexHull( winding_t *w, winding_t **hull, const Vector3& n memcpy( hullPoints, newHullPoints, numHullPoints * sizeof( Vector3 ) ); } - FreeWinding( *hull ); - w = AllocWinding( numHullPoints ); - w->numpoints = numHullPoints; - *hull = w; - memcpy( w->p, hullPoints, numHullPoints * sizeof( Vector3 ) ); + *hull = winding_t( hullPoints, hullPoints + numHullPoints ); } diff --git a/tools/quake3/common/polylib.h b/tools/quake3/common/polylib.h index 28093abd..30615fd9 100644 --- a/tools/quake3/common/polylib.h +++ b/tools/quake3/common/polylib.h @@ -23,11 +23,7 @@ #include "qmath.h" -struct winding_t -{ - int numpoints; - Vector3 p[]; -}; +using winding_t = std::vector; #define MAX_POINTS_ON_WINDING 512 @@ -45,29 +41,29 @@ enum EPlaneSide }; winding_t *AllocWinding( int points ); -float WindingArea( const winding_t *w ); -Vector3 WindingCenter( const winding_t *w ); -void ClipWindingEpsilon( winding_t *in, const Plane3f& plane, - float epsilon, winding_t **front, winding_t **back ); -void ClipWindingEpsilonStrict( winding_t *in, const Plane3f& plane, - float epsilon, winding_t **front, winding_t **back ); +float WindingArea( const winding_t& w ); +Vector3 WindingCenter( const winding_t& w ); +void ClipWindingEpsilon( const winding_t& in, const Plane3f& plane, + float epsilon, winding_t *&front, winding_t *&back ); +void ClipWindingEpsilonStrict( const winding_t& in, const Plane3f& plane, + float epsilon, winding_t *&front, winding_t *&back ); winding_t *ChopWinding( winding_t *in, const Plane3f& plane ); winding_t *CopyWinding( const winding_t *w ); -winding_t *ReverseWinding( const winding_t *w ); +winding_t *ReverseWinding( const winding_t& w ); winding_t *BaseWindingForPlane( const Plane3f& plane ); -void CheckWinding( winding_t *w ); -Plane3f WindingPlane( const winding_t *w ); -void RemoveColinearPoints( winding_t *w ); -EPlaneSide WindingOnPlaneSide( const winding_t *w, const Plane3f& plane ); +void CheckWinding( const winding_t& w ); +Plane3f WindingPlane( const winding_t& w ); +void RemoveColinearPoints( winding_t& w ); +EPlaneSide WindingOnPlaneSide( const winding_t& w, const Plane3f& plane ); void FreeWinding( winding_t *w ); -void WindingExtendBounds( const winding_t *w, MinMax& minmax ); +void WindingExtendBounds( const winding_t& w, MinMax& minmax ); -void AddWindingToConvexHull( winding_t *w, winding_t **hull, const Vector3& normal ); +void AddWindingToConvexHull( const winding_t& w, winding_t *&hull, const Vector3& normal ); -void ChopWindingInPlace( winding_t **w, const Plane3f& plane, float epsilon ); +void ChopWindingInPlace( winding_t *&w, const Plane3f& plane, float epsilon ); // frees the original if clipped -void pw( winding_t *w ); +void pw( const winding_t& w ); /////////////////////////////////////////////////////////////////////////////////////// diff --git a/tools/quake3/q3map2/brush.cpp b/tools/quake3/q3map2/brush.cpp index 5793625b..8169cb62 100644 --- a/tools/quake3/q3map2/brush.cpp +++ b/tools/quake3/q3map2/brush.cpp @@ -180,7 +180,7 @@ bool BoundBrush( brush_t *brush ){ { const winding_t *w = brush->sides[ i ].winding; if ( w != NULL ) { - WindingExtendBounds( w, brush->minmax ); + WindingExtendBounds( *w, brush->minmax ); } } @@ -198,17 +198,15 @@ bool BoundBrush( brush_t *brush ){ #define SNAP_EPSILON 0.01 -void SnapWeldVector( const Vector3& a, const Vector3& b, Vector3& out ){ - int i; - float ai, bi, outi; - +Vector3 SnapWeldVector( const Vector3& a, const Vector3& b ){ + Vector3 out; /* do each element */ - for ( i = 0; i < 3; i++ ) + for ( int i = 0; i < 3; i++ ) { /* round to integer */ - ai = std::rint( a[ i ] ); - bi = std::rint( b[ i ] ); + const float ai = std::rint( a[ i ] ); + const float bi = std::rint( b[ i ] ); /* prefer exact integer */ if ( ai == a[ i ] ) { @@ -227,11 +225,13 @@ void SnapWeldVector( const Vector3& a, const Vector3& b, Vector3& out ){ } /* snap */ - outi = std::rint( out[ i ] ); + const float outi = std::rint( out[ i ] ); if ( fabs( outi - out[ i ] ) <= SNAP_EPSILON ) { out[ i ] = outi; } } + + return out; } /* @@ -292,9 +292,6 @@ DoubleVector3 SnapWeldVectorAccu( const DoubleVector3& a, const DoubleVector3& b bool FixWinding( winding_t *w ){ bool valid = true; - int i, j, k; - Vector3 vec; - /* dummy check */ if ( !w ) { @@ -302,38 +299,30 @@ bool FixWinding( winding_t *w ){ } /* check all verts */ - for ( i = 0; i < w->numpoints; i++ ) + for ( winding_t::iterator i = w->end() - 1, j = w->begin(); j != w->end(); i = j, ++j ) { /* don't remove points if winding is a triangle */ - if ( w->numpoints == 3 ) { + if ( w->size() == 3 ) { return valid; } - /* get second point index */ - j = ( i + 1 ) % w->numpoints; - /* degenerate edge? */ - if ( vector3_length( w->p[ i ] - w->p[ j ] ) < DEGENERATE_EPSILON ) { + if ( vector3_length( *i - *j ) < DEGENERATE_EPSILON ) { valid = false; //Sys_FPrintf( SYS_WRN | SYS_VRBflag, "WARNING: Degenerate winding edge found, fixing...\n" ); /* create an average point (ydnar 2002-01-26: using nearest-integer weld preference) */ - SnapWeldVector( w->p[ i ], w->p[ j ], vec ); - w->p[ i ] = vec; + *i = SnapWeldVector( *i, *j ); //VectorAdd( w->p[ i ], w->p[ j ], vec ); //VectorScale( vec, 0.5, w->p[ i ] ); /* move the remaining verts */ - for ( k = i + 2; k < w->numpoints; k++ ) - { - w->p[ k - 1 ] = w->p[ k ]; - } - w->numpoints--; + w->erase( j ); } } /* one last check and return */ - if ( w->numpoints < 3 ) { + if ( w->size() < 3 ) { valid = false; } return valid; @@ -426,7 +415,7 @@ bool CreateBrushWindings( brush_t *brush ){ #if Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES ChopWindingInPlaceAccu( w, ( cside.plane.normal() != g_vector3_identity )? plane3_flipped( cside.plane ) : Plane3( cplane.plane ), 0 ); #else - ChopWindingInPlace( &w, cplane.plane, 0 ); // CLIP_EPSILON ); + ChopWindingInPlace( w, cplane.plane, 0 ); // CLIP_EPSILON ); #endif /* ydnar: fix broken windings that would generate trifans */ @@ -513,7 +502,7 @@ float BrushVolume( brush_t *brush ){ if ( !w ) { return 0; } - corner = w->p[0]; + corner = ( *w )[0]; // make tetrahedrons to all other faces @@ -524,7 +513,7 @@ float BrushVolume( brush_t *brush ){ if ( !w ) { continue; } - volume += -plane3_distance_to_point( mapplanes[brush->sides[i].planenum].plane, corner ) * WindingArea( w ); + volume += -plane3_distance_to_point( mapplanes[brush->sides[i].planenum].plane, corner ) * WindingArea( *w ); } volume /= 3; @@ -541,8 +530,6 @@ float BrushVolume( brush_t *brush ){ void WriteBSPBrushMap( const char *name, brush_t *list ){ side_t *s; int i; - winding_t *w; - /* note it */ Sys_Printf( "Writing %s\n", name ); @@ -552,18 +539,19 @@ void WriteBSPBrushMap( const char *name, brush_t *list ){ fprintf( f, "{\n\"classname\" \"worldspawn\"\n" ); - for ( ; list ; list = list->next ) + for ( ; list; list = list->next ) { fprintf( f, "{\n" ); - for ( i = 0,s = list->sides ; i < list->numsides ; i++,s++ ) + for ( i = 0, s = list->sides; i < list->numsides; i++, s++ ) { // TODO: See if we can use a smaller winding to prevent resolution loss. // Is WriteBSPBrushMap() used only to decompile maps? - w = BaseWindingForPlane( mapplanes[s->planenum].plane ); + winding_t *w = BaseWindingForPlane( mapplanes[s->planenum].plane ); + const winding_t& wr = *w; - fprintf( f, "( %i %i %i ) ", (int)w->p[0][0], (int)w->p[0][1], (int)w->p[0][2] ); - fprintf( f, "( %i %i %i ) ", (int)w->p[1][0], (int)w->p[1][1], (int)w->p[1][2] ); - fprintf( f, "( %i %i %i ) ", (int)w->p[2][0], (int)w->p[2][1], (int)w->p[2][2] ); + fprintf( f, "( %i %i %i ) ", (int)wr[0][0], (int)wr[0][1], (int)wr[0][2] ); + fprintf( f, "( %i %i %i ) ", (int)wr[1][0], (int)wr[1][1], (int)wr[1][2] ); + fprintf( f, "( %i %i %i ) ", (int)wr[2][0], (int)wr[2][1], (int)wr[2][2] ); fprintf( f, "notexture 0 0 0 1 1\n" ); FreeWinding( w ); @@ -746,19 +734,17 @@ node_t *AllocNode( void ){ ================ */ #define EDGE_LENGTH 0.2 -bool WindingIsTiny( winding_t *w ){ +bool WindingIsTiny( const winding_t& w ){ /* if (WindingArea (w) < 1) return true; return false; */ - int i, j; int edges = 0; - for ( i = 0 ; i < w->numpoints ; i++ ) + for ( size_t i = w.size() - 1, j = 0; j < w.size(); i = j, ++j ) { - j = ( i == w->numpoints - 1 )? 0 : i + 1; - if ( vector3_length( w->p[j] - w->p[i] ) > EDGE_LENGTH ) { + if ( vector3_length( w[j] - w[i] ) > EDGE_LENGTH ) { if ( ++edges == 3 ) { return false; } @@ -775,9 +761,9 @@ bool WindingIsTiny( winding_t *w ){ from basewinding for plane ================ */ -bool WindingIsHuge( winding_t *w ){ - for ( int i = 0; i < w->numpoints; i++ ) - if ( !c_worldMinmax.test( w->p[i] ) ) +bool WindingIsHuge( const winding_t& w ){ + for ( const Vector3& p : w ) + if ( !c_worldMinmax.test( p ) ) return true; return false; } @@ -791,29 +777,23 @@ bool WindingIsHuge( winding_t *w ){ ================== */ int BrushMostlyOnSide( brush_t *brush, plane_t *plane ){ - int i, j; - winding_t *w; - float max; - int side; - - max = 0; - side = PSIDE_FRONT; - for ( i = 0 ; i < brush->numsides ; i++ ) + float max = 0; + int side = PSIDE_FRONT; + for ( int i = 0 ; i < brush->numsides ; i++ ) { - w = brush->sides[i].winding; - if ( !w ) { - continue; - } - for ( j = 0 ; j < w->numpoints ; j++ ) - { - const double d = plane3_distance_to_point( plane->plane, w->p[j] ); - if ( d > max ) { - max = d; - side = PSIDE_FRONT; - } - if ( -d > max ) { - max = -d; - side = PSIDE_BACK; + winding_t *w = brush->sides[i].winding; + if ( w ) { + for ( const Vector3& p : *w ) + { + const double d = plane3_distance_to_point( plane->plane, p ); + if ( d > max ) { + max = d; + side = PSIDE_FRONT; + } + if ( -d > max ) { + max = -d; + side = PSIDE_BACK; + } } } } @@ -848,9 +828,9 @@ void SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back ) if ( !w ) { continue; } - for ( j = 0 ; j < w->numpoints ; j++ ) + for ( const Vector3& p : *w ) { - const float d = plane3_distance_to_point( plane->plane, w->p[j] ); + const float d = plane3_distance_to_point( plane->plane, p ); if ( d > 0 ) { value_maximize( d_front, d ); } @@ -877,10 +857,10 @@ void SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back ) for ( i = 0 ; i < brush->numsides && w ; i++ ) { plane2 = &mapplanes[brush->sides[i].planenum ^ 1]; - ChopWindingInPlace( &w, plane2->plane, 0 ); // PLANESIDE_EPSILON); + ChopWindingInPlace( w, plane2->plane, 0 ); // PLANESIDE_EPSILON); } - if ( !w || WindingIsTiny( w ) ) { // the brush isn't really split + if ( !w || WindingIsTiny( *w ) ) { // the brush isn't really split int side; side = BrushMostlyOnSide( brush, plane ); @@ -893,7 +873,7 @@ void SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back ) return; } - if ( WindingIsHuge( w ) ) { + if ( WindingIsHuge( *w ) ) { Sys_FPrintf( SYS_WRN | SYS_VRBflag, "WARNING: huge winding\n" ); } @@ -919,8 +899,8 @@ void SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back ) if ( !w ) { continue; } - ClipWindingEpsilonStrict( w, plane->plane, - 0 /*PLANESIDE_EPSILON*/, &cw[0], &cw[1] ); /* strict, in parallel case we get the face back because it also is the midwinding */ + ClipWindingEpsilonStrict( *w, plane->plane, + 0 /*PLANESIDE_EPSILON*/, cw[0], cw[1] ); /* strict, in parallel case we get the face back because it also is the midwinding */ for ( j = 0 ; j < 2 ; j++ ) { if ( !cw[j] ) { diff --git a/tools/quake3/q3map2/convert_bsp.cpp b/tools/quake3/q3map2/convert_bsp.cpp index c0fd5334..b1283834 100644 --- a/tools/quake3/q3map2/convert_bsp.cpp +++ b/tools/quake3/q3map2/convert_bsp.cpp @@ -788,7 +788,7 @@ void PseudoCompileBSP( bool need_tree ){ continue; } /* save this winding as a visible surface */ - DrawSurfaceForSide( entity, brush, side, side->winding ); + DrawSurfaceForSide( entity, brush, side, *side->winding ); } } diff --git a/tools/quake3/q3map2/convert_map.cpp b/tools/quake3/q3map2/convert_map.cpp index 531fb4db..c0b62a58 100644 --- a/tools/quake3/q3map2/convert_map.cpp +++ b/tools/quake3/q3map2/convert_map.cpp @@ -54,7 +54,6 @@ void GetBestSurfaceTriangleMatchForBrushside( side_t *buildSide, bspDrawVert_t * float best = 0; float thisarea; bspDrawVert_t *vert[3]; - winding_t *polygon; const plane_t& buildPlane = mapplanes[buildSide->planenum]; int matches = 0; @@ -99,7 +98,7 @@ void GetBestSurfaceTriangleMatchForBrushside( side_t *buildSide, bspDrawVert_t * continue; } // Okay. Correct surface type, correct shader, correct plane. Let's start with the business... - polygon = CopyWinding( buildSide->winding ); + winding_t *polygon = CopyWinding( buildSide->winding ); for ( i = 0; i < 3; ++i ) { // 0: 1, 2 @@ -110,12 +109,12 @@ void GetBestSurfaceTriangleMatchForBrushside( side_t *buildSide, bspDrawVert_t * // we now need to generate the plane spanned by normal and (v2 - v1). Plane3f plane( vector3_cross( v2 - v1, buildPlane.normal() ), 0 ); plane.dist() = vector3_dot( v1, plane.normal() ); - ChopWindingInPlace( &polygon, plane, distanceEpsilon ); + ChopWindingInPlace( polygon, plane, distanceEpsilon ); if ( !polygon ) { goto exwinding; } } - thisarea = WindingArea( polygon ); + thisarea = WindingArea( *polygon ); if ( thisarea > 0 ) { ++matches; } @@ -465,12 +464,9 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or /* recheck and fix winding points, fails occur somehow */ int match = 0; - for ( j = 0; j < buildSide->winding->numpoints; j++ ){ - if ( fabs( plane3_distance_to_point( buildPlane.plane, buildSide->winding->p[ j ] ) ) >= distanceEpsilon ) { - continue; - } - else{ - pts[ match ] = buildSide->winding->p[ j ]; + for ( const Vector3& p : ( *buildSide->winding ) ){ + if ( fabs( plane3_distance_to_point( buildPlane.plane, p ) ) < distanceEpsilon ) { + pts[ match ] = p; match++; /* got 3 fine points? */ if( match > 2 ) diff --git a/tools/quake3/q3map2/decals.cpp b/tools/quake3/q3map2/decals.cpp index 90631f94..0417a0e2 100644 --- a/tools/quake3/q3map2/decals.cpp +++ b/tools/quake3/q3map2/decals.cpp @@ -502,17 +502,17 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds, /* dummy check */ - if ( w->numpoints < 3 ) { + if ( w->size() < 3 ) { FreeWinding( w ); return; } /* offset by entity origin */ - for ( i = 0; i < w->numpoints; i++ ) - w->p[ i ] += entityOrigin; + for ( Vector3& p : *w ) + p += entityOrigin; /* make a plane from the winding */ - if ( !PlaneFromPoints( plane, w->p[ 0 ], w->p[ 1 ], w->p[ 2 ] ) ) { + if ( !PlaneFromPoints( plane, w->data() ) ) { FreeWinding( w ); return; } @@ -527,7 +527,7 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds, for ( i = 0; i < dp->numPlanes; i++ ) { /* chop winding by the plane */ - ClipWindingEpsilonStrict( w, dp->planes[ i ], 0.0625f, &front, &back ); /* strict, if identical plane we don't want to keep it */ + ClipWindingEpsilonStrict( *w, dp->planes[ i ], 0.0625f, front, back ); /* strict, if identical plane we don't want to keep it */ FreeWinding( w ); /* lose the front fragment */ @@ -545,7 +545,7 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds, } /* nothing left? */ - if ( w == NULL || w->numpoints < 3 ) { + if ( w == NULL || w->size() < 3 ) { return; } @@ -563,7 +563,7 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds, ds2->fogNum = ds->fogNum; /* why was this -1? */ ds2->lightmapScale = ds->lightmapScale; ds2->shadeAngleDegrees = ds->shadeAngleDegrees; - ds2->numVerts = w->numpoints; + ds2->numVerts = w->size(); ds2->verts = safe_calloc( ds2->numVerts * sizeof( *ds2->verts ) ); /* set vertexes */ @@ -573,12 +573,12 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds, dv = &ds2->verts[ i ]; /* set alpha */ - const float d = plane3_distance_to_point( dp->planes[ 0 ], w->p[ i ] ); - const float d2 = plane3_distance_to_point( dp->planes[ 1 ], w->p[ i ] ); + const float d = plane3_distance_to_point( dp->planes[ 0 ], ( *w )[ i ] ); + const float d2 = plane3_distance_to_point( dp->planes[ 1 ], ( *w )[ i ] ); const float alpha = 255.0f * d2 / ( d + d2 ); /* set misc */ - dv->xyz = w->p[ i ] - entityOrigin; + dv->xyz = ( *w )[ i ] - entityOrigin; dv->normal = plane.normal(); dv->st[ 0 ] = vector3_dot( dv->xyz, dp->texMat[ 0 ].vec3() ) + dp->texMat[ 0 ][ 3 ]; dv->st[ 1 ] = vector3_dot( dv->xyz, dp->texMat[ 1 ].vec3() ) + dp->texMat[ 1 ][ 3 ]; @@ -669,18 +669,16 @@ static void ProjectDecalOntoPatch( decalProjector_t *dp, mapDrawSurface_t *ds ){ /* generate decal for first triangle */ w = AllocWinding( 3 ); - w->numpoints = 3; - w->p[ 0 ] = mesh->verts[ pw[ r + 0 ] ].xyz; - w->p[ 1 ] = mesh->verts[ pw[ r + 1 ] ].xyz; - w->p[ 2 ] = mesh->verts[ pw[ r + 2 ] ].xyz; + w->push_back( mesh->verts[ pw[ r + 0 ] ].xyz ); + w->push_back( mesh->verts[ pw[ r + 1 ] ].xyz ); + w->push_back( mesh->verts[ pw[ r + 2 ] ].xyz ); ProjectDecalOntoWinding( dp, ds, w ); /* generate decal for second triangle */ w = AllocWinding( 3 ); - w->numpoints = 3; - w->p[ 0 ] = mesh->verts[ pw[ r + 0 ] ].xyz; - w->p[ 1 ] = mesh->verts[ pw[ r + 2 ] ].xyz; - w->p[ 2 ] = mesh->verts[ pw[ r + 3 ] ].xyz; + w->push_back( mesh->verts[ pw[ r + 0 ] ].xyz ); + w->push_back( mesh->verts[ pw[ r + 2 ] ].xyz ); + w->push_back( mesh->verts[ pw[ r + 3 ] ].xyz ); ProjectDecalOntoWinding( dp, ds, w ); } } @@ -717,10 +715,9 @@ static void ProjectDecalOntoTriangles( decalProjector_t *dp, mapDrawSurface_t *d { /* generate decal */ winding_t *w = AllocWinding( 3 ); - w->numpoints = 3; - w->p[ 0 ] = ds->verts[ ds->indexes[ i ] ].xyz; - w->p[ 1 ] = ds->verts[ ds->indexes[ i + 1 ] ].xyz; - w->p[ 2 ] = ds->verts[ ds->indexes[ i + 2 ] ].xyz; + w->push_back( ds->verts[ ds->indexes[ i ] ].xyz ); + w->push_back( ds->verts[ ds->indexes[ i + 1 ] ].xyz ); + w->push_back( ds->verts[ ds->indexes[ i + 2 ] ].xyz ); ProjectDecalOntoWinding( dp, ds, w ); } } diff --git a/tools/quake3/q3map2/facebsp.cpp b/tools/quake3/q3map2/facebsp.cpp index d39f9431..12473551 100644 --- a/tools/quake3/q3map2/facebsp.cpp +++ b/tools/quake3/q3map2/facebsp.cpp @@ -126,7 +126,7 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum, //check->checked = true; // won't need to test this plane again continue; } - const EPlaneSide side = WindingOnPlaneSide( check->w, plane.plane ); + const EPlaneSide side = WindingOnPlaneSide( *check->w, plane.plane ); if ( side == eSideCross ) { splits++; } @@ -142,7 +142,7 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum, // from 27 //Bigger is better - sizeBias = WindingArea( split->w ); + sizeBias = WindingArea( *split->w ); //Base score = 20000 perfectly balanced value = 20000 - ( abs( front - back ) ); @@ -276,12 +276,12 @@ void BuildFaceTree_r( node_t *node, face_t *list ){ #endif /* determine which side the face falls on */ - const EPlaneSide side = WindingOnPlaneSide( split->w, plane.plane ); + const EPlaneSide side = WindingOnPlaneSide( *split->w, plane.plane ); /* switch on side */ if ( side == eSideCross ) { - ClipWindingEpsilonStrict( split->w, plane.plane, CLIP_EPSILON * 2, - &frontWinding, &backWinding ); /* strict; if no winding is left, we have a "virtually identical" plane and don't want to split by it */ + ClipWindingEpsilonStrict( *split->w, plane.plane, CLIP_EPSILON * 2, + frontWinding, backWinding ); /* strict; if no winding is left, we have a "virtually identical" plane and don't want to split by it */ if ( frontWinding ) { newFace = AllocBspFace(); newFace->w = frontWinding; @@ -370,7 +370,7 @@ tree_t *FaceBSP( face_t *list ) { int count = 0; for ( const face_t *face = list; face != NULL; face = face->next ) { - WindingExtendBounds( face->w, tree->minmax ); + WindingExtendBounds( *face->w, tree->minmax ); count++; } Sys_FPrintf( SYS_VRB, "%9d faces\n", count ); diff --git a/tools/quake3/q3map2/fog.cpp b/tools/quake3/q3map2/fog.cpp index d29a4129..9e4b0f94 100644 --- a/tools/quake3/q3map2/fog.cpp +++ b/tools/quake3/q3map2/fog.cpp @@ -349,9 +349,8 @@ winding_t *WindingFromDrawSurf( mapDrawSurface_t *ds ){ } w = AllocWinding( ds->numVerts ); - w->numpoints = ds->numVerts; - for ( i = 0 ; i < ds->numVerts ; i++ ) { - w->p[i] = ds->verts[i].xyz; + for ( i = 0; i < ds->numVerts; i++ ) { + w->push_back( ds->verts[i].xyz ); } return w; } @@ -400,7 +399,7 @@ bool ChopFaceSurfaceByBrush( entity_t *e, mapDrawSurface_t *ds, brush_t *b ){ } /* general case */ - ClipWindingEpsilonStrict( w, plane.plane, ON_EPSILON, &front, &back ); /* strict; if plane is "almost identical" to face, both ways to continue can be wrong, so we better not fog it */ + ClipWindingEpsilonStrict( *w, plane.plane, ON_EPSILON, front, back ); /* strict; if plane is "almost identical" to face, both ways to continue can be wrong, so we better not fog it */ FreeWinding( w ); if ( back == NULL ) { @@ -428,7 +427,7 @@ bool ChopFaceSurfaceByBrush( entity_t *e, mapDrawSurface_t *ds, brush_t *b ){ s = ds->sideRef->side; for ( i = 0; i < numOutside; i++ ) { - newds = DrawSurfaceForSide( e, ds->mapBrush, s, outside[ i ] ); + newds = DrawSurfaceForSide( e, ds->mapBrush, s, *outside[ i ] ); newds->fogNum = ds->fogNum; FreeWinding( outside[ i ] ); } @@ -438,7 +437,7 @@ bool ChopFaceSurfaceByBrush( entity_t *e, mapDrawSurface_t *ds, brush_t *b ){ the right thing and uses the original surface's brush side */ /* build a drawsurf for it */ - newds = DrawSurfaceForSide( e, ds->mapBrush, s, w ); + newds = DrawSurfaceForSide( e, ds->mapBrush, s, *w ); if ( newds == NULL ) { return false; } diff --git a/tools/quake3/q3map2/leakfile.cpp b/tools/quake3/q3map2/leakfile.cpp index 5d4ffdf0..a2d18a03 100644 --- a/tools/quake3/q3map2/leakfile.cpp +++ b/tools/quake3/q3map2/leakfile.cpp @@ -97,7 +97,7 @@ xmlNodePtr LeakFile( tree_t *tree ){ } } node = nextnode; - mid = WindingCenter( nextportal->winding ); + mid = WindingCenter( *nextportal->winding ); fprintf( linefile, "%f %f %f\n", mid[0], mid[1], mid[2] ); point = xml_NodeForVec( mid ); xmlAddChild( xml_node, point ); diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp index a755e3be..130cde23 100644 --- a/tools/quake3/q3map2/light.cpp +++ b/tools/quake3/q3map2/light.cpp @@ -637,17 +637,17 @@ void SetEntityOrigins( void ){ #define ONE_OVER_2PI 0.159154942f //% (1.0f / (2.0f * 3.141592657f)) -float PointToPolygonFormFactor( const Vector3& point, const Vector3& normal, const winding_t *w ){ - int i, j; +float PointToPolygonFormFactor( const Vector3& point, const Vector3& normal, const winding_t& w ){ Vector3 dirs[ MAX_POINTS_ON_WINDING ]; float total; float angle, facing; /* this is expensive */ - for ( i = 0; i < w->numpoints; i++ ) + size_t i; + for ( i = 0; i < w.size(); i++ ) { - dirs[ i ] = w->p[ i ] - point; + dirs[ i ] = w[ i ] - point; VectorFastNormalize( dirs[ i ] ); } @@ -656,10 +656,10 @@ float PointToPolygonFormFactor( const Vector3& point, const Vector3& normal, con /* calculcate relative area */ total = 0.0f; - for ( i = 0; i < w->numpoints; i++ ) + for ( i = 0; i < w.size(); i++ ) { /* get a triangle */ - j = i + 1; + const size_t j = i + 1; /* get the angle */ /* roundoff can cause slight creep, which gives an IND from acos, thus clamp */ @@ -811,7 +811,7 @@ int LightContributionToSample( trace_t *trace ){ else { /* calculate the contribution */ - factor = PointToPolygonFormFactor( pushedOrigin, trace->normal, light->w ); + factor = PointToPolygonFormFactor( pushedOrigin, trace->normal, *light->w ); if ( factor == 0.0f ) { return 0; } @@ -1258,7 +1258,7 @@ bool LightContributionToPoint( trace_t *trace ){ } /* calculate the contribution (ydnar 2002-10-21: [bug 642] bad normal calc) */ - factor = PointToPolygonFormFactor( pushedOrigin, trace->direction, light->w ); + factor = PointToPolygonFormFactor( pushedOrigin, trace->direction, *light->w ); if ( factor == 0.0f ) { return false; } diff --git a/tools/quake3/q3map2/light_bounce.cpp b/tools/quake3/q3map2/light_bounce.cpp index 1999a606..d143258a 100644 --- a/tools/quake3/q3map2/light_bounce.cpp +++ b/tools/quake3/q3map2/light_bounce.cpp @@ -389,7 +389,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw float dist, area, value; Vector3 normal, color, gradient; light_t *light, *splash; - winding_t *w, *splash_w; + winding_t *w; /* dummy check */ @@ -447,11 +447,10 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw /* create a regular winding and an average normal */ w = AllocWinding( rw->numVerts ); - w->numpoints = rw->numVerts; normal.set( 0 ); for ( i = 0; i < rw->numVerts; i++ ) { - w->p[ i ] = rw->verts[ i ].xyz; + w->push_back( rw->verts[ i ].xyz ); normal += rw->verts[ i ].normal; } normal /= rw->numVerts; @@ -582,11 +581,9 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw } /* create a regular winding */ - splash_w = AllocWinding( rw->numVerts ); - splash_w->numpoints = rw->numVerts; + splash->w = AllocWinding( rw->numVerts ); for ( i = 0; i < rw->numVerts; i++ ) - splash_w->p[ i ] = rw->verts[rw->numVerts - 1 - i].xyz + normal * si->backsplashDistance; - splash->w = splash_w; + splash->w->push_back( rw->verts[rw->numVerts - 1 - i].xyz + normal * si->backsplashDistance ); splash->origin = normal * si->backsplashDistance + light->origin; splash->normal = -normal; @@ -610,7 +607,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw } /* set origin */ - light->origin = WindingCenter( w ); + light->origin = WindingCenter( *w ); /* nudge it off the plane a bit */ light->normal = normal; diff --git a/tools/quake3/q3map2/light_ydnar.cpp b/tools/quake3/q3map2/light_ydnar.cpp index 9bdf36dc..a5cec9c1 100644 --- a/tools/quake3/q3map2/light_ydnar.cpp +++ b/tools/quake3/q3map2/light_ydnar.cpp @@ -3433,7 +3433,7 @@ void SetupEnvelopes( bool forGrid, bool fastFlag ){ for ( radius = 100.0f; radius < MAX_WORLD_COORD * 8.0f; radius += 10.0f ) { const Vector3 origin = light->origin + light->normal * radius; - const float factor = std::abs( PointToPolygonFormFactor( origin, dir, light->w ) ); + const float factor = std::abs( PointToPolygonFormFactor( origin, dir, *light->w ) ); if ( ( factor * light->add ) <= light->falloffTolerance ) { light->envelope = radius; break; diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index 05daa89b..967e3c07 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -651,8 +651,8 @@ void AddBrushBevels( void ){ if ( !w ) { continue; } - for ( k = 0; k < w->numpoints; k++ ) { - if ( fabs( plane.dist() - w->p[k][axis] ) < .1f ) { + for ( const Vector3& po : *w ) { + if ( fabs( plane.dist() - po[axis] ) < .1f ) { s->surfaceFlags |= ( s2->surfaceFlags & surfaceFlagsMask ); break; } @@ -686,9 +686,9 @@ void AddBrushBevels( void ){ if ( !w ) { continue; } - for ( j = 0; j < w->numpoints; j++ ) { - k = ( j + 1 ) % w->numpoints; - vec = w->p[j] - w->p[k]; + for ( j = 0; j < w->size(); j++ ) { + k = ( j + 1 ) % w->size(); + vec = ( *w )[j] - ( *w )[k]; if ( VectorNormalize( vec ) < 0.5f ) { continue; } @@ -715,7 +715,7 @@ void AddBrushBevels( void ){ if ( VectorNormalize( plane.normal() ) < 0.5f ) { continue; } - plane.dist() = vector3_dot( w->p[j], plane.normal() ); + plane.dist() = vector3_dot( ( *w )[j], plane.normal() ); // if all the points on all the sides are // behind this plane, it is a proper edge bevel @@ -734,15 +734,15 @@ void AddBrushBevels( void ){ continue; } minBack = 0.0f; - for ( l = 0; l < w2->numpoints; l++ ) { - d = plane3_distance_to_point( plane, w2->p[l] ); + for ( l = 0; l < w2->size(); l++ ) { + d = plane3_distance_to_point( plane, ( *w2 )[l] ); if ( d > 0.1f ) { break; // point in front } value_minimize( minBack, d ); } // if some point was at the front - if ( l != w2->numpoints ) { + if ( l != w2->size() ) { break; } @@ -768,7 +768,7 @@ void AddBrushBevels( void ){ buildBrush->numsides++; memset( s2, 0, sizeof( *s2 ) ); - s2->planenum = FindFloatPlane( plane, 1, &w->p[ j ] ); + s2->planenum = FindFloatPlane( plane, 1, &( *w )[ j ] ); s2->contentFlags = buildBrush->sides[0].contentFlags; s2->surfaceFlags = ( s->surfaceFlags & surfaceFlagsMask ); /* handle bevel surfaceflags */ s2->bevel = true; diff --git a/tools/quake3/q3map2/portals.cpp b/tools/quake3/q3map2/portals.cpp index a9ab8cf9..1940487d 100644 --- a/tools/quake3/q3map2/portals.cpp +++ b/tools/quake3/q3map2/portals.cpp @@ -156,14 +156,9 @@ void RemovePortalFromNode( portal_t *portal, node_t *l ){ //============================================================================ -void PrintPortal( portal_t *p ){ - int i; - winding_t *w; - - w = p->winding; - for ( i = 0 ; i < w->numpoints ; i++ ) - Sys_Printf( "(%5.0f,%5.0f,%5.0f)\n", w->p[i][0] - , w->p[i][1], w->p[i][2] ); +void PrintPortal( const portal_t *p ){ + for ( const Vector3& point : ( *p->winding ) ) + Sys_Printf( "(%5.0f,%5.0f,%5.0f)\n", point[0], point[1], point[2] ); } /* @@ -226,7 +221,7 @@ void MakeHeadnodePortals( tree_t *tree ){ if ( j == i ) { continue; } - ChopWindingInPlace( &portals[i]->winding, bplanes[j].plane, ON_EPSILON ); + ChopWindingInPlace( portals[i]->winding, bplanes[j].plane, ON_EPSILON ); } } } @@ -254,11 +249,11 @@ winding_t *BaseWindingForNode( node_t *node ){ const plane_t& plane = mapplanes[n->planenum]; if ( n->children[0] == node ) { // take front - ChopWindingInPlace( &w, plane.plane, BASE_WINDING_EPSILON ); + ChopWindingInPlace( w, plane.plane, BASE_WINDING_EPSILON ); } else { // take back - ChopWindingInPlace( &w, plane3_flipped( plane.plane ), BASE_WINDING_EPSILON ); + ChopWindingInPlace( w, plane3_flipped( plane.plane ), BASE_WINDING_EPSILON ); } node = n; n = n->parent; @@ -289,11 +284,11 @@ void MakeNodePortal( node_t *node ){ { if ( p->nodes[0] == node ) { side = 0; - ChopWindingInPlace( &w, p->plane.plane, CLIP_EPSILON ); + ChopWindingInPlace( w, p->plane.plane, CLIP_EPSILON ); } else if ( p->nodes[1] == node ) { side = 1; - ChopWindingInPlace( &w, plane3_flipped( p->plane.plane ), CLIP_EPSILON ); + ChopWindingInPlace( w, plane3_flipped( p->plane.plane ), CLIP_EPSILON ); } else{ Error( "CutNodePortals_r: mislinked portal" ); @@ -315,7 +310,7 @@ void MakeNodePortal( node_t *node ){ } #endif - if ( WindingIsTiny( w ) ) { + if ( WindingIsTiny( *w ) ) { c_tinyportals++; FreeWinding( w ); return; @@ -368,16 +363,16 @@ void SplitNodePortals( node_t *node ){ // // cut the portal into two portals, one on each side of the cut plane // - ClipWindingEpsilon( p->winding, plane.plane, - SPLIT_WINDING_EPSILON, &frontwinding, &backwinding ); /* not strict, we want to always keep one of them even if coplanar */ + ClipWindingEpsilon( *p->winding, plane.plane, + SPLIT_WINDING_EPSILON, frontwinding, backwinding ); /* not strict, we want to always keep one of them even if coplanar */ - if ( frontwinding && WindingIsTiny( frontwinding ) ) { + if ( frontwinding && WindingIsTiny( *frontwinding ) ) { if ( !f->tinyportals ) { - f->referencepoint = frontwinding->p[0]; + f->referencepoint = ( *frontwinding )[0]; } f->tinyportals++; if ( !other_node->tinyportals ) { - other_node->referencepoint = frontwinding->p[0]; + other_node->referencepoint = ( *frontwinding )[0]; } other_node->tinyportals++; @@ -386,13 +381,13 @@ void SplitNodePortals( node_t *node ){ c_tinyportals++; } - if ( backwinding && WindingIsTiny( backwinding ) ) { + if ( backwinding && WindingIsTiny( *backwinding ) ) { if ( !b->tinyportals ) { - b->referencepoint = backwinding->p[0]; + b->referencepoint = ( *backwinding )[0]; } b->tinyportals++; if ( !other_node->tinyportals ) { - other_node->referencepoint = backwinding->p[0]; + other_node->referencepoint = ( *backwinding )[0]; } other_node->tinyportals++; @@ -462,7 +457,7 @@ void CalcNodeBounds( node_t *node ){ for ( p = node->portals ; p ; p = p->next[s] ) { s = ( p->nodes[1] == node ); - WindingExtendBounds( p->winding, node->minmax ); + WindingExtendBounds( *p->winding, node->minmax ); } } @@ -485,7 +480,7 @@ void MakeTreePortals_r( node_t *node ){ if ( !c_worldMinmax.surrounds( node->minmax ) ) { if ( node->portals && node->portals->winding ) { - xml_Winding( "WARNING: Node With Unbounded Volume", node->portals->winding->p, node->portals->winding->numpoints, false ); + xml_Winding( "WARNING: Node With Unbounded Volume", node->portals->winding->data(), node->portals->winding->size(), false ); } } if ( node->planenum == PLANENUM_LEAF ) { diff --git a/tools/quake3/q3map2/prtfile.cpp b/tools/quake3/q3map2/prtfile.cpp index dba58d23..7bdce995 100644 --- a/tools/quake3/q3map2/prtfile.cpp +++ b/tools/quake3/q3map2/prtfile.cpp @@ -97,7 +97,7 @@ void CountVisportals_r( node_t *node ){ ================= */ void WritePortalFile_r( node_t *node ){ - int i, s, flags; + int s, flags; portal_t *p; winding_t *w; @@ -130,11 +130,11 @@ void WritePortalFile_r( node_t *node ){ // the changeover point between different axis. interpret the // plane the same way vis will, and flip the side orders if needed // FIXME: is this still relevant? - if ( vector3_dot( p->plane.normal(), WindingPlane( w ).normal() ) < 0.99 ) { // backwards... - fprintf( pf, "%i %i %i ", w->numpoints, p->nodes[1]->cluster, p->nodes[0]->cluster ); + if ( vector3_dot( p->plane.normal(), WindingPlane( *w ).normal() ) < 0.99 ) { // backwards... + fprintf( pf, "%zu %i %i ", w->size(), p->nodes[1]->cluster, p->nodes[0]->cluster ); } else{ - fprintf( pf, "%i %i %i ", w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster ); + fprintf( pf, "%zu %i %i ", w->size(), p->nodes[0]->cluster, p->nodes[1]->cluster ); } flags = 0; @@ -152,12 +152,12 @@ void WritePortalFile_r( node_t *node ){ fprintf( pf, "%d ", flags ); /* write the winding */ - for ( i = 0 ; i < w->numpoints ; i++ ) + for ( const Vector3 point : *w ) { fprintf( pf, "(" ); - WriteFloat( pf, w->p[i][0] ); - WriteFloat( pf, w->p[i][1] ); - WriteFloat( pf, w->p[i][2] ); + WriteFloat( pf, point.x() ); + WriteFloat( pf, point.y() ); + WriteFloat( pf, point.z() ); fprintf( pf, ") " ); } fprintf( pf, "\n" ); @@ -206,7 +206,7 @@ void CountSolidFaces_r( node_t *node ){ ================= */ void WriteFaceFile_r( node_t *node ){ - int i, s; + int s; portal_t *p; winding_t *w; @@ -235,26 +235,26 @@ void WriteFaceFile_r( node_t *node ){ // write out to the file if ( p->nodes[0] == node ) { - fprintf( pf, "%i %i ", w->numpoints, p->nodes[0]->cluster ); - for ( i = 0 ; i < w->numpoints ; i++ ) + fprintf( pf, "%zu %i ", w->size(), p->nodes[0]->cluster ); + for ( const Vector3& point : *w ) { fprintf( pf, "(" ); - WriteFloat( pf, w->p[i][0] ); - WriteFloat( pf, w->p[i][1] ); - WriteFloat( pf, w->p[i][2] ); + WriteFloat( pf, point.x() ); + WriteFloat( pf, point.y() ); + WriteFloat( pf, point.z() ); fprintf( pf, ") " ); } fprintf( pf, "\n" ); } else { - fprintf( pf, "%i %i ", w->numpoints, p->nodes[1]->cluster ); - for ( i = w->numpoints - 1; i >= 0; i-- ) + fprintf( pf, "%zu %i ", w->size(), p->nodes[1]->cluster ); + for ( winding_t::const_reverse_iterator point = w->crbegin(); point != w->crend(); ++point ) { fprintf( pf, "(" ); - WriteFloat( pf, w->p[i][0] ); - WriteFloat( pf, w->p[i][1] ); - WriteFloat( pf, w->p[i][2] ); + WriteFloat( pf, point->x() ); + WriteFloat( pf, point->y() ); + WriteFloat( pf, point->z() ); fprintf( pf, ") " ); } fprintf( pf, "\n" ); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 8d0f0d8c..41833330 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1559,7 +1559,7 @@ void FreeBrush( brush_t *brushes ); void FreeBrushList( brush_t *brushes ); brush_t *CopyBrush( const brush_t *brush ); bool BoundBrush( brush_t *brush ); -void SnapWeldVector( const Vector3& a, const Vector3& b, Vector3& out ); +Vector3 SnapWeldVector( const Vector3& a, const Vector3& b ); bool CreateBrushWindings( brush_t *brush ); brush_t *BrushFromBounds( const Vector3& mins, const Vector3& maxs ); float BrushVolume( brush_t *brush ); @@ -1568,7 +1568,7 @@ void WriteBSPBrushMap( const char *name, brush_t *list ); void FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree ); void FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree ); -bool WindingIsTiny( winding_t *w ); +bool WindingIsTiny( const winding_t& w ); void SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back ); @@ -1703,7 +1703,7 @@ mapDrawSurface_t *MakeCelSurface( mapDrawSurface_t *src, shaderInfo_t bool IsTriangleDegenerate( bspDrawVert_t *points, int a, int b, int c ); void ClearSurface( mapDrawSurface_t *ds ); void AddEntitySurfaceModels( entity_t *e ); -mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w ); +mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, const winding_t& w ); mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh ); mapDrawSurface_t *DrawSurfaceForFlare( int entNum, const Vector3& origin, const Vector3& normal, const Vector3& color, const char *flareShader, int lightStyle ); mapDrawSurface_t *DrawSurfaceForShader( const char *shader ); @@ -1779,7 +1779,7 @@ void PassagePortalFlow( int portalnum ); /* light.c */ -float PointToPolygonFormFactor( const Vector3& point, const Vector3& normal, const winding_t *w ); +float PointToPolygonFormFactor( const Vector3& point, const Vector3& normal, const winding_t& w ); int LightContributionToSample( trace_t *trace ); void LightingAtSample( trace_t * trace, byte styles[ MAX_LIGHTMAPS ], Vector3 (&colors)[ MAX_LIGHTMAPS ] ); bool LightContributionToPoint( trace_t *trace ); diff --git a/tools/quake3/q3map2/surface.cpp b/tools/quake3/q3map2/surface.cpp index 96973422..77c3138d 100644 --- a/tools/quake3/q3map2/surface.cpp +++ b/tools/quake3/q3map2/surface.cpp @@ -766,8 +766,7 @@ shaderInfo_t *GetIndexedShader( const shaderInfo_t *parent, const indexMap_t *im const double SNAP_FLOAT_TO_INT = 8.0; const double SNAP_INT_TO_FLOAT = ( 1.0 / SNAP_FLOAT_TO_INT ); -mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w ){ - int i, j, k; +mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, const winding_t& w ){ mapDrawSurface_t *ds; shaderInfo_t *si, *parent; bspDrawVert_t *dv; @@ -785,8 +784,8 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin } /* range check */ - if ( w->numpoints > MAX_POINTS_ON_WINDING ) { - Error( "DrawSurfaceForSide: w->numpoints = %d (> %d)", w->numpoints, MAX_POINTS_ON_WINDING ); + if ( w.size() > MAX_POINTS_ON_WINDING ) { + Error( "DrawSurfaceForSide: w->numpoints = %zu (> %d)", w.size(), MAX_POINTS_ON_WINDING ); } /* get shader */ @@ -798,16 +797,16 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin indexed = true; /* get shader indexes for each point */ - for ( i = 0; i < w->numpoints; i++ ) + for ( size_t i = 0; i < w.size(); i++ ) { - shaderIndexes[ i ] = GetShaderIndexForPoint( b->im, b->eMinmax, w->p[ i ] ); + shaderIndexes[ i ] = GetShaderIndexForPoint( b->im, b->eMinmax, w[ i ] ); offsets[ i ] = b->im->offsets[ shaderIndexes[ i ] ]; //% Sys_Printf( "%f ", offsets[ i ] ); } /* get matching shader and set alpha */ parent = si; - si = GetIndexedShader( parent, b->im, w->numpoints, shaderIndexes ); + si = GetIndexedShader( parent, b->im, w.size(), shaderIndexes ); } else{ indexed = false; @@ -836,26 +835,26 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin ds->fogNum = -1; ds->sampleSize = b->lightmapSampleSize; ds->lightmapScale = b->lightmapScale; - ds->numVerts = w->numpoints; + ds->numVerts = w.size(); ds->verts = safe_calloc( ds->numVerts * sizeof( *ds->verts ) ); /* compute s/t coordinates from brush primitive texture matrix (compute axis base) */ ComputeAxisBase( mapplanes[ s->planenum ].normal(), texX, texY ); /* create the vertexes */ - for ( j = 0; j < w->numpoints; j++ ) + for ( size_t j = 0; j < w.size(); j++ ) { /* get the drawvert */ dv = ds->verts + j; /* copy xyz and do potential z offset */ - dv->xyz = w->p[ j ]; + dv->xyz = w[ j ]; if ( indexed ) { dv->xyz[ 2 ] += offsets[ j ]; } /* round the xyz to a given precision and translate by origin */ - for ( i = 0 ; i < 3 ; i++ ) + for ( size_t i = 0 ; i < 3 ; i++ ) dv->xyz[ i ] = SNAP_INT_TO_FLOAT * floor( dv->xyz[ i ] * SNAP_FLOAT_TO_INT + 0.5 ); vTranslated = dv->xyz + e->originbrush_origin; @@ -892,7 +891,7 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin dv->normal = mapplanes[ s->planenum ].normal(); /* ydnar: set color */ - for ( k = 0; k < MAX_LIGHTMAPS; k++ ) + for ( int k = 0; k < MAX_LIGHTMAPS; k++ ) { dv->color[ k ].set( 255 ); @@ -1203,7 +1202,7 @@ static void AddSurfaceFlare( mapDrawSurface_t *ds, const Vector3& entityOrigin ) subdivides a face surface until it is smaller than the specified size (subdivisions) */ -static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_t *w, int fogNum, float subdivisions ){ +static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, const winding_t *w, int fogNum, float subdivisions ){ int axis; MinMax bounds; const float epsilon = 0.1; @@ -1216,12 +1215,12 @@ static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_ if ( w == NULL ) { return; } - if ( w->numpoints < 3 ) { - Error( "SubdivideFace_r: Bad w->numpoints (%d < 3)", w->numpoints ); + if ( w->size() < 3 ) { + Error( "SubdivideFace_r: Bad w->numpoints (%zu < 3)", w->size() ); } /* determine surface bounds */ - WindingExtendBounds( w, bounds ); + WindingExtendBounds( *w, bounds ); /* split the face */ for ( axis = 0; axis < 3; axis++ ) @@ -1240,7 +1239,7 @@ static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_ /* subdivide if necessary */ if ( ( subCeil - subFloor ) > subdivisions ) { /* clip the winding */ - ClipWindingEpsilon( w, plane, epsilon, &frontWinding, &backWinding ); /* not strict; we assume we always keep a winding */ + ClipWindingEpsilon( *w, plane, epsilon, frontWinding, backWinding ); /* not strict; we assume we always keep a winding */ /* the clip may not produce two polygons if it was epsilon close */ if ( frontWinding == NULL ) { @@ -1259,7 +1258,7 @@ static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_ } /* create a face surface */ - ds = DrawSurfaceForSide( e, brush, side, w ); + ds = DrawSurfaceForSide( e, brush, side, *w ); /* set correct fog num */ ds->fogNum = fogNum; @@ -1384,8 +1383,8 @@ void ClipSideIntoTree_r( winding_t *w, side_t *side, node_t *node ){ } const Plane3f& plane = mapplanes[ node->planenum ].plane; - ClipWindingEpsilonStrict( w, plane, - ON_EPSILON, &front, &back ); /* strict, we handle the "winding disappeared" case */ + ClipWindingEpsilonStrict( *w, plane, + ON_EPSILON, front, back ); /* strict, we handle the "winding disappeared" case */ if ( !front && !back ) { /* in doubt, register it in both nodes */ front = CopyWinding( w ); @@ -1401,7 +1400,7 @@ void ClipSideIntoTree_r( winding_t *w, side_t *side, node_t *node ){ // if opaque leaf, don't add if ( !node->opaque ) { - AddWindingToConvexHull( w, &side->visibleHull, mapplanes[ side->planenum ].normal() ); + AddWindingToConvexHull( *w, side->visibleHull, mapplanes[ side->planenum ].normal() ); } FreeWinding( w ); @@ -1444,7 +1443,7 @@ bool SideInBrush( side_t *side, brush_t *b ){ /* check if side's winding is on or behind the plane */ const Plane3f& plane = mapplanes[ b->sides[ i ].planenum ].plane; - const EPlaneSide s = WindingOnPlaneSide( side->winding, plane ); + const EPlaneSide s = WindingOnPlaneSide( *side->winding, plane ); if ( s == eSideFront || s == eSideCross ) { return false; } @@ -1526,7 +1525,7 @@ void CullSides( entity_t *e ){ if ( w1 == NULL ) { continue; } - numPoints = w1->numpoints; + numPoints = w1->size(); if ( side1->shaderInfo == NULL ) { continue; } @@ -1543,7 +1542,7 @@ void CullSides( entity_t *e ){ if ( side2->shaderInfo == NULL ) { continue; } - if ( w1->numpoints != w2->numpoints ) { + if ( w1->size() != w2->size() ) { continue; } if ( side1->culled && side2->culled ) { @@ -1569,7 +1568,7 @@ void CullSides( entity_t *e ){ first = -1; for ( k = 0; k < numPoints; k++ ) { - if ( VectorCompare( w1->p[ 0 ], w2->p[ k ] ) ) { + if ( VectorCompare( ( *w1 )[ 0 ], ( *w2 )[ k ] ) ) { first = k; break; } @@ -1587,7 +1586,7 @@ void CullSides( entity_t *e ){ else{ second = 0; } - if ( vector3_equal_epsilon( w1->p[ 1 ], w2->p[ second ], CULL_EPSILON ) ) { + if ( vector3_equal_epsilon( ( *w1 )[ 1 ], ( *w2 )[ second ], CULL_EPSILON ) ) { dir = 1; } else @@ -1598,7 +1597,7 @@ void CullSides( entity_t *e ){ else{ second = numPoints - 1; } - if ( vector3_equal_epsilon( w1->p[ 1 ], w2->p[ second ], CULL_EPSILON ) ) { + if ( vector3_equal_epsilon( ( *w1 )[ 1 ], ( *w2 )[ second ], CULL_EPSILON ) ) { dir = -1; } } @@ -1610,7 +1609,7 @@ void CullSides( entity_t *e ){ l = first; for ( k = 0; k < numPoints; k++ ) { - if ( !vector3_equal_epsilon( w1->p[ k ], w2->p[ l ], CULL_EPSILON ) ) { + if ( !vector3_equal_epsilon( ( *w1 )[ k ], ( *w2 )[ l ], CULL_EPSILON ) ) { k = 100000; } @@ -1721,7 +1720,7 @@ void ClipSidesIntoTree( entity_t *e, tree_t *tree ){ } /* save this winding as a visible surface */ - DrawSurfaceForSide( e, b, side, w ); + DrawSurfaceForSide( e, b, side, *w ); /* make a back side for fog */ if ( !( si->compileFlags & C_FOG ) ) { @@ -1729,14 +1728,14 @@ void ClipSidesIntoTree( entity_t *e, tree_t *tree ){ } /* duplicate the up-facing side */ - w = ReverseWinding( w ); + w = ReverseWinding( *w ); newSide = safe_malloc( sizeof( *side ) ); *newSide = *side; newSide->visibleHull = w; newSide->planenum ^= 1; /* save this winding as a visible surface */ - DrawSurfaceForSide( e, b, newSide, w ); + DrawSurfaceForSide( e, b, newSide, *w ); } } } @@ -1912,7 +1911,7 @@ int FilterPointConvexHullIntoTree_r( Vector3 *points[], const int npoints, mapDr */ int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){ - int i, refs = 0; + int refs = 0; winding_t *fat, *front, *back; shaderInfo_t *si; @@ -1930,17 +1929,17 @@ int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){ /* 'fatten' the winding by the shader mins/maxs (parsed from vertexDeform move) */ /* note this winding is completely invalid (concave, nonplanar, etc) */ - fat = AllocWinding( w->numpoints * 3 + 3 ); - fat->numpoints = w->numpoints * 3 + 3; - for ( i = 0; i < w->numpoints; i++ ) + fat = AllocWinding( w->size() * 3 + 3 ); + fat->resize( w->size() * 3 + 3 ); + for ( size_t i = 0; i < w->size(); i++ ) { - fat->p[ i ] = w->p[ i ]; - fat->p[ i + ( w->numpoints + 1 ) ] = w->p[ i ] + si->minmax.mins; - fat->p[ i + ( w->numpoints + 1 ) * 2 ] = w->p[ i ] + si->minmax.maxs; + ( *fat )[ i ] = ( *w )[ i ]; + ( *fat )[ i + ( w->size() + 1 ) ] = ( *w )[ i ] + si->minmax.mins; + ( *fat )[ i + ( w->size() + 1 ) * 2 ] = ( *w )[ i ] + si->minmax.maxs; } - fat->p[ i ] = w->p[ 0 ]; - fat->p[ i + w->numpoints ] = w->p[ 0 ] + si->minmax.mins; - fat->p[ i + w->numpoints * 2 ] = w->p[ 0 ] + si->minmax.maxs; + ( *fat )[ w->size() ] = ( *w )[ 0 ]; + ( *fat )[ w->size() * 2 ] = ( *w )[ 0 ] + si->minmax.mins; + ( *fat )[ w->size() * 3 ] = ( *w )[ 0 ] + si->minmax.maxs; /* * note: this winding is STILL not suitable for ClipWindingEpsilon, and @@ -1990,7 +1989,7 @@ int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){ } /* clip the winding by this plane */ - ClipWindingEpsilonStrict( w, plane1, ON_EPSILON, &front, &back ); /* strict; we handle the "winding disappeared" case */ + ClipWindingEpsilonStrict( *w, plane1, ON_EPSILON, front, back ); /* strict; we handle the "winding disappeared" case */ /* filter by this plane */ refs = 0; @@ -2092,10 +2091,9 @@ static int FilterTrianglesIntoTree( mapDrawSurface_t *ds, tree_t *tree ){ /* make a triangle winding and filter it into the tree */ w = AllocWinding( 3 ); - w->numpoints = 3; - w->p[ 0 ] = ds->verts[ ds->indexes[ i ] ].xyz; - w->p[ 1 ] = ds->verts[ ds->indexes[ i + 1 ] ].xyz; - w->p[ 2 ] = ds->verts[ ds->indexes[ i + 2 ] ].xyz; + w->push_back( ds->verts[ ds->indexes[ i ] ].xyz ); + w->push_back( ds->verts[ ds->indexes[ i + 1 ] ].xyz ); + w->push_back( ds->verts[ ds->indexes[ i + 2 ] ].xyz ); refs += FilterWindingIntoTree_r( w, ds, tree->headnode ); } @@ -2138,10 +2136,9 @@ static int FilterFoliageIntoTree( mapDrawSurface_t *ds, tree_t *tree ){ /* make a triangle winding and filter it into the tree */ w = AllocWinding( 3 ); - w->numpoints = 3; - w->p[ 0 ] = instance->xyz + ds->verts[ ds->indexes[ i ] ].xyz; - w->p[ 1 ] = instance->xyz + ds->verts[ ds->indexes[ i + 1 ] ].xyz; - w->p[ 2 ] = instance->xyz + ds->verts[ ds->indexes[ i + 2 ] ].xyz; + w->push_back( instance->xyz + ds->verts[ ds->indexes[ i ] ].xyz ); + w->push_back( instance->xyz + ds->verts[ ds->indexes[ i + 1 ] ].xyz ); + w->push_back( instance->xyz + ds->verts[ ds->indexes[ i + 2 ] ].xyz ); refs += FilterWindingIntoTree_r( w, ds, tree->headnode ); } @@ -2779,8 +2776,8 @@ static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si ){ } /* check max points */ - if ( w->numpoints > 64 ) { - Error( "MakePortalSurfs_r: w->numpoints = %d", w->numpoints ); + if ( w->size() > 64 ) { + Error( "MakePortalSurfs_r: w->numpoints = %zu", w->size() ); } /* allocate a drawsurface */ @@ -2791,7 +2788,7 @@ static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si ){ ds->planeNum = FindFloatPlane( p->plane.plane, 0, NULL ); ds->lightmapVecs[ 2 ] = p->plane.normal(); ds->fogNum = -1; - ds->numVerts = w->numpoints; + ds->numVerts = w->size(); ds->verts = safe_calloc( ds->numVerts * sizeof( *ds->verts ) ); /* walk the winding */ @@ -2801,7 +2798,7 @@ static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si ){ dv = ds->verts + i; /* set it */ - dv->xyz = w->p[ i ]; + dv->xyz = ( *w )[ i ]; dv->normal = p->plane.normal(); dv->st = { 0, 0 }; for ( k = 0; k < MAX_LIGHTMAPS; k++ ) diff --git a/tools/quake3/q3map2/tjunction.cpp b/tools/quake3/q3map2/tjunction.cpp index 8af6f76e..0277bd97 100644 --- a/tools/quake3/q3map2/tjunction.cpp +++ b/tools/quake3/q3map2/tjunction.cpp @@ -513,7 +513,7 @@ bool FixBrokenSurface( mapDrawSurface_t *ds ){ /* create an average drawvert */ /* ydnar 2002-01-26: added nearest-integer welding preference */ - SnapWeldVector( dv1->xyz, dv2->xyz, avg.xyz ); + avg.xyz = SnapWeldVector( dv1->xyz, dv2->xyz ); avg.normal = VectorNormalized( dv1->normal + dv2->normal ); avg.st = vector2_mid( dv1->st, dv2->st );