diff --git a/tools/quake3/q3map2/decals.cpp b/tools/quake3/q3map2/decals.cpp index 5ca08df2..ab0c22e9 100644 --- a/tools/quake3/q3map2/decals.cpp +++ b/tools/quake3/q3map2/decals.cpp @@ -360,7 +360,7 @@ static int MakeDecalProjector( shaderInfo_t *si, const Plane3f& projection, floa #define PLANAR_EPSILON 0.5f void ProcessDecals( void ){ - int j, x, y, pw[ 5 ], r, iterations; + int x, y, pw[ 5 ], r, iterations; float distance; Plane3f projection, plane; entity_t *e2; @@ -424,8 +424,8 @@ void ProcessDecals( void ){ FreeMesh( subdivided ); /* offset by projector origin */ - for ( j = 0; j < ( mesh->width * mesh->height ); j++ ) - mesh->verts[ j ].xyz += e.origin; + for ( bspDrawVert_t& vert : Span( mesh->verts, mesh->width * mesh->height ) ) + vert.xyz += e.origin; /* iterate through the mesh quads */ for ( y = 0; y < ( mesh->height - 1 ); y++ ) @@ -699,7 +699,7 @@ static void ProjectDecalOntoTriangles( decalProjector_t *dp, mapDrawSurface_t *d { /* generate decal */ winding_t w{ - ds->verts[ ds->indexes[ i ] ].xyz, + ds->verts[ ds->indexes[ i + 0 ] ].xyz, ds->verts[ ds->indexes[ i + 1 ] ].xyz, ds->verts[ ds->indexes[ i + 2 ] ].xyz }; ProjectDecalOntoWinding( dp, ds, w ); diff --git a/tools/quake3/q3map2/fog.cpp b/tools/quake3/q3map2/fog.cpp index 4d5f8ec4..d7284508 100644 --- a/tools/quake3/q3map2/fog.cpp +++ b/tools/quake3/q3map2/fog.cpp @@ -344,8 +344,8 @@ winding_t WindingFromDrawSurf( const mapDrawSurface_t *ds ){ } winding_t w = AllocWinding( ds->numVerts ); - for ( int i = 0; i < ds->numVerts; i++ ) { - w.push_back( ds->verts[i].xyz ); + for ( const bspDrawVert_t& vert : Span( ds->verts, ds->numVerts ) ) { + w.push_back( vert.xyz ); } return w; } @@ -485,8 +485,8 @@ void FogDrawSurfaces( entity_t *e ){ { /* find drawsurface bounds */ MinMax minmax; - for ( int j = 0; j < ds->numVerts; j++ ) - minmax.extend( ds->verts[ j ].xyz ); + for ( const bspDrawVert_t& vert : Span( ds->verts, ds->numVerts ) ) + minmax.extend( vert.xyz ); /* check against the fog brush */ if( !minmax.test( fog.brush->minmax ) ){ diff --git a/tools/quake3/q3map2/light_bounce.cpp b/tools/quake3/q3map2/light_bounce.cpp index a6b287f2..e635eaea 100644 --- a/tools/quake3/q3map2/light_bounce.cpp +++ b/tools/quake3/q3map2/light_bounce.cpp @@ -48,7 +48,6 @@ static void RadClipWindingEpsilon( radWinding_t *in, const Vector3& normal, floa int counts[ 3 ]; float dot; /* ydnar: changed from static b/c of threading */ /* VC 4.2 optimizer bug if not static? */ int i, k; - radVert_t *v1, *v2, mid; int maxPoints; @@ -97,20 +96,20 @@ static void RadClipWindingEpsilon( radWinding_t *in, const Vector3& normal, floa for ( i = 0; i < in->numVerts; i++ ) { /* do simple vertex copies first */ - v1 = &in->verts[ i ]; + const radVert_t& v1 = in->verts[ i ]; if ( sides[ i ] == eSideOn ) { - memcpy( &front->verts[ front->numVerts++ ], v1, sizeof( radVert_t ) ); - memcpy( &back->verts[ back->numVerts++ ], v1, sizeof( radVert_t ) ); + front->verts[ front->numVerts++ ] = v1; + back->verts[ back->numVerts++ ] = v1; continue; } if ( sides[ i ] == eSideFront ) { - memcpy( &front->verts[ front->numVerts++ ], v1, sizeof( radVert_t ) ); + front->verts[ front->numVerts++ ] = v1; } if ( sides[ i ] == eSideBack ) { - memcpy( &back->verts[ back->numVerts++ ], v1, sizeof( radVert_t ) ); + back->verts[ back->numVerts++ ] = v1; } if ( sides[ i + 1 ] == eSideOn || sides[ i + 1 ] == sides[ i ] ) { @@ -118,29 +117,30 @@ static void RadClipWindingEpsilon( radWinding_t *in, const Vector3& normal, floa } /* generate a split vertex */ - v2 = &in->verts[ ( i + 1 ) % in->numVerts ]; + const radVert_t& v2 = in->verts[ ( i + 1 ) % in->numVerts ]; dot = dists[ i ] / ( dists[ i ] - dists[ i + 1 ] ); /* average vertex values */ + radVert_t mid; /* color */ for ( k = 0; k < MAX_LIGHTMAPS; k++ ){ - mid.color[ k ] = v1->color[ k ] + ( v2->color[ k ] - v1->color[ k ] ) * dot; + mid.color[ k ] = v1.color[ k ] + ( v2.color[ k ] - v1.color[ k ] ) * dot; } /* xyz, normal */ - mid.xyz = v1->xyz + ( v2->xyz - v1->xyz ) * dot; - mid.normal = v1->normal + ( v2->normal - v1->normal ) * dot; + mid.xyz = v1.xyz + ( v2.xyz - v1.xyz ) * dot; + mid.normal = v1.normal + ( v2.normal - v1.normal ) * dot; /* st, lightmap */ - mid.st = v1->st + ( v2->st - v1->st ) * dot; + mid.st = v1.st + ( v2.st - v1.st ) * dot; for ( k = 0; k < MAX_LIGHTMAPS; k++ ) - mid.lightmap[ k ] = v1->lightmap[ k ] + ( v2->lightmap[ k ] - v1->lightmap[ k ] ) * dot; + mid.lightmap[ k ] = v1.lightmap[ k ] + ( v2.lightmap[ k ] - v1.lightmap[ k ] ) * dot; /* normalize the averaged normal */ VectorNormalize( mid.normal ); /* copy the midpoint to both windings */ - memcpy( &front->verts[ front->numVerts++ ], &mid, sizeof( radVert_t ) ); - memcpy( &back->verts[ back->numVerts++ ], &mid, sizeof( radVert_t ) ); + front->verts[ front->numVerts++ ] = mid; + back->verts[ back->numVerts++ ] = mid; } /* error check */ @@ -373,8 +373,8 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw /* get bounds for winding */ MinMax minmax; - for ( i = 0; i < rw->numVerts; i++ ) - minmax.extend( rw->verts[ i ].xyz ); + for ( const radVert_t& vert : Span( rw->verts, rw->numVerts ) ) + minmax.extend( vert.xyz ); /* subdivide if necessary */ for ( i = 0; i < 3; i++ ) @@ -421,9 +421,9 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw /* create an average normal */ normal.set( 0 ); - for ( i = 0; i < rw->numVerts; i++ ) + for ( const radVert_t& vert : Span( rw->verts, rw->numVerts ) ) { - normal += rw->verts[ i ].normal; + normal += vert.normal; } normal /= rw->numVerts; if ( VectorNormalize( normal ) == 0.0f ) { @@ -469,9 +469,9 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw light.fade = 1.0f; /* create a regular winding */ light.w = AllocWinding( rw->numVerts ); - for ( i = 0; i < rw->numVerts; i++ ) + for ( const radVert_t& vert : Span( rw->verts, rw->numVerts ) ) { - light.w.push_back( rw->verts[ i ].xyz ); + light.w.push_back( vert.xyz ); } /* set falloff threshold */ @@ -683,11 +683,10 @@ void RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, const shader /* FIXME: build interpolation table into color[ 1 ] */ /* fix up color indexes */ - for ( i = 0; i < ( mesh->width * mesh->height ); i++ ) + for ( bspDrawVert_t& vert : Span( mesh->verts, mesh->width * mesh->height ) ) { - dv[ 0 ] = &mesh->verts[ i ]; - if ( dv[ 0 ]->color[ 0 ][ 0 ] >= ds->numVerts ) { - dv[ 0 ]->color[ 0 ][ 0 ] = ds->numVerts - 1; + if ( vert.color[ 0 ][ 0 ] >= ds->numVerts ) { + vert.color[ 0 ][ 0 ] = ds->numVerts - 1; } } diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index 8462bf3e..def5dd23 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -1303,8 +1303,8 @@ void SetEntityBounds( entity_t *e ){ } for ( parseMesh_t *p = e->patches; p; p = p->next ) { - for ( int i = 0; i < ( p->mesh.width * p->mesh.height ); i++ ) - minmax.extend( p->mesh.verts[ i ].xyz ); + for ( const bspDrawVert_t& vert : Span( p->mesh.verts, p->mesh.width * p->mesh.height ) ) + minmax.extend( vert.xyz ); } /* try to find explicit min/max key */ diff --git a/tools/quake3/q3map2/surface_foliage.cpp b/tools/quake3/q3map2/surface_foliage.cpp index 4e4f2fe2..f76bd1bb 100644 --- a/tools/quake3/q3map2/surface_foliage.cpp +++ b/tools/quake3/q3map2/surface_foliage.cpp @@ -156,7 +156,7 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, const foliage_t& f */ void Foliage( mapDrawSurface_t *src ){ - int i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs; + int i, j, x, y, pw[ 5 ], r, oldNumMapDrawSurfs; mapDrawSurface_t *ds; shaderInfo_t *si; mesh_t srcMesh, *subdivided, *mesh; @@ -291,9 +291,9 @@ void Foliage( mapDrawSurface_t *src ){ fi->normal = foliageInstances[ j ].normal; /* ydnar: set color */ - for ( k = 0; k < MAX_LIGHTMAPS; k++ ) + for ( auto& color : fi->color ) { - fi->color[ k ].set( 255 ); + color.set( 255 ); } } diff --git a/tools/quake3/q3map2/writebsp.cpp b/tools/quake3/q3map2/writebsp.cpp index 17164afe..003f49c8 100644 --- a/tools/quake3/q3map2/writebsp.cpp +++ b/tools/quake3/q3map2/writebsp.cpp @@ -501,8 +501,8 @@ void BeginModel( void ){ /* bound patches */ for ( const parseMesh_t *p = e.patches; p; p = p->next ) { - for ( int i = 0; i < ( p->mesh.width * p->mesh.height ); i++ ) - minmax.extend( p->mesh.verts[i].xyz ); + for ( const bspDrawVert_t& vert : Span( p->mesh.verts, p->mesh.width * p->mesh.height ) ) + minmax.extend( vert.xyz ); } /* ydnar: lightgrid mins/maxs */