minor tweaks

This commit is contained in:
Garux 2021-10-26 20:15:09 +03:00
parent 67ea9b0390
commit 2e9bf0af1c
6 changed files with 38 additions and 39 deletions

View File

@ -360,7 +360,7 @@ static int MakeDecalProjector( shaderInfo_t *si, const Plane3f& projection, floa
#define PLANAR_EPSILON 0.5f #define PLANAR_EPSILON 0.5f
void ProcessDecals( void ){ void ProcessDecals( void ){
int j, x, y, pw[ 5 ], r, iterations; int x, y, pw[ 5 ], r, iterations;
float distance; float distance;
Plane3f projection, plane; Plane3f projection, plane;
entity_t *e2; entity_t *e2;
@ -424,8 +424,8 @@ void ProcessDecals( void ){
FreeMesh( subdivided ); FreeMesh( subdivided );
/* offset by projector origin */ /* offset by projector origin */
for ( j = 0; j < ( mesh->width * mesh->height ); j++ ) for ( bspDrawVert_t& vert : Span( mesh->verts, mesh->width * mesh->height ) )
mesh->verts[ j ].xyz += e.origin; vert.xyz += e.origin;
/* iterate through the mesh quads */ /* iterate through the mesh quads */
for ( y = 0; y < ( mesh->height - 1 ); y++ ) for ( y = 0; y < ( mesh->height - 1 ); y++ )
@ -699,7 +699,7 @@ static void ProjectDecalOntoTriangles( decalProjector_t *dp, mapDrawSurface_t *d
{ {
/* generate decal */ /* generate decal */
winding_t w{ 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 + 1 ] ].xyz,
ds->verts[ ds->indexes[ i + 2 ] ].xyz }; ds->verts[ ds->indexes[ i + 2 ] ].xyz };
ProjectDecalOntoWinding( dp, ds, w ); ProjectDecalOntoWinding( dp, ds, w );

View File

@ -344,8 +344,8 @@ winding_t WindingFromDrawSurf( const mapDrawSurface_t *ds ){
} }
winding_t w = AllocWinding( ds->numVerts ); winding_t w = AllocWinding( ds->numVerts );
for ( int i = 0; i < ds->numVerts; i++ ) { for ( const bspDrawVert_t& vert : Span( ds->verts, ds->numVerts ) ) {
w.push_back( ds->verts[i].xyz ); w.push_back( vert.xyz );
} }
return w; return w;
} }
@ -485,8 +485,8 @@ void FogDrawSurfaces( entity_t *e ){
{ {
/* find drawsurface bounds */ /* find drawsurface bounds */
MinMax minmax; MinMax minmax;
for ( int j = 0; j < ds->numVerts; j++ ) for ( const bspDrawVert_t& vert : Span( ds->verts, ds->numVerts ) )
minmax.extend( ds->verts[ j ].xyz ); minmax.extend( vert.xyz );
/* check against the fog brush */ /* check against the fog brush */
if( !minmax.test( fog.brush->minmax ) ){ if( !minmax.test( fog.brush->minmax ) ){

View File

@ -48,7 +48,6 @@ static void RadClipWindingEpsilon( radWinding_t *in, const Vector3& normal, floa
int counts[ 3 ]; int counts[ 3 ];
float dot; /* ydnar: changed from static b/c of threading */ /* VC 4.2 optimizer bug if not static? */ float dot; /* ydnar: changed from static b/c of threading */ /* VC 4.2 optimizer bug if not static? */
int i, k; int i, k;
radVert_t *v1, *v2, mid;
int maxPoints; int maxPoints;
@ -97,20 +96,20 @@ static void RadClipWindingEpsilon( radWinding_t *in, const Vector3& normal, floa
for ( i = 0; i < in->numVerts; i++ ) for ( i = 0; i < in->numVerts; i++ )
{ {
/* do simple vertex copies first */ /* do simple vertex copies first */
v1 = &in->verts[ i ]; const radVert_t& v1 = in->verts[ i ];
if ( sides[ i ] == eSideOn ) { if ( sides[ i ] == eSideOn ) {
memcpy( &front->verts[ front->numVerts++ ], v1, sizeof( radVert_t ) ); front->verts[ front->numVerts++ ] = v1;
memcpy( &back->verts[ back->numVerts++ ], v1, sizeof( radVert_t ) ); back->verts[ back->numVerts++ ] = v1;
continue; continue;
} }
if ( sides[ i ] == eSideFront ) { if ( sides[ i ] == eSideFront ) {
memcpy( &front->verts[ front->numVerts++ ], v1, sizeof( radVert_t ) ); front->verts[ front->numVerts++ ] = v1;
} }
if ( sides[ i ] == eSideBack ) { 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 ] ) { 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 */ /* 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 ] ); dot = dists[ i ] / ( dists[ i ] - dists[ i + 1 ] );
/* average vertex values */ /* average vertex values */
radVert_t mid;
/* color */ /* color */
for ( k = 0; k < MAX_LIGHTMAPS; k++ ){ 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 */ /* xyz, normal */
mid.xyz = v1->xyz + ( v2->xyz - v1->xyz ) * dot; mid.xyz = v1.xyz + ( v2.xyz - v1.xyz ) * dot;
mid.normal = v1->normal + ( v2->normal - v1->normal ) * dot; mid.normal = v1.normal + ( v2.normal - v1.normal ) * dot;
/* st, lightmap */ /* 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++ ) 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 */ /* normalize the averaged normal */
VectorNormalize( mid.normal ); VectorNormalize( mid.normal );
/* copy the midpoint to both windings */ /* copy the midpoint to both windings */
memcpy( &front->verts[ front->numVerts++ ], &mid, sizeof( radVert_t ) ); front->verts[ front->numVerts++ ] = mid;
memcpy( &back->verts[ back->numVerts++ ], &mid, sizeof( radVert_t ) ); back->verts[ back->numVerts++ ] = mid;
} }
/* error check */ /* error check */
@ -373,8 +373,8 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
/* get bounds for winding */ /* get bounds for winding */
MinMax minmax; MinMax minmax;
for ( i = 0; i < rw->numVerts; i++ ) for ( const radVert_t& vert : Span( rw->verts, rw->numVerts ) )
minmax.extend( rw->verts[ i ].xyz ); minmax.extend( vert.xyz );
/* subdivide if necessary */ /* subdivide if necessary */
for ( i = 0; i < 3; i++ ) for ( i = 0; i < 3; i++ )
@ -421,9 +421,9 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
/* create an average normal */ /* create an average normal */
normal.set( 0 ); 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; normal /= rw->numVerts;
if ( VectorNormalize( normal ) == 0.0f ) { if ( VectorNormalize( normal ) == 0.0f ) {
@ -469,9 +469,9 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
light.fade = 1.0f; light.fade = 1.0f;
/* create a regular winding */ /* create a regular winding */
light.w = AllocWinding( rw->numVerts ); 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 */ /* 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 ] */ /* FIXME: build interpolation table into color[ 1 ] */
/* fix up color indexes */ /* 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 ( vert.color[ 0 ][ 0 ] >= ds->numVerts ) {
if ( dv[ 0 ]->color[ 0 ][ 0 ] >= ds->numVerts ) { vert.color[ 0 ][ 0 ] = ds->numVerts - 1;
dv[ 0 ]->color[ 0 ][ 0 ] = ds->numVerts - 1;
} }
} }

View File

@ -1303,8 +1303,8 @@ void SetEntityBounds( entity_t *e ){
} }
for ( parseMesh_t *p = e->patches; p; p = p->next ) for ( parseMesh_t *p = e->patches; p; p = p->next )
{ {
for ( int i = 0; i < ( p->mesh.width * p->mesh.height ); i++ ) for ( const bspDrawVert_t& vert : Span( p->mesh.verts, p->mesh.width * p->mesh.height ) )
minmax.extend( p->mesh.verts[ i ].xyz ); minmax.extend( vert.xyz );
} }
/* try to find explicit min/max key */ /* try to find explicit min/max key */

View File

@ -156,7 +156,7 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, const foliage_t& f
*/ */
void Foliage( mapDrawSurface_t *src ){ 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; mapDrawSurface_t *ds;
shaderInfo_t *si; shaderInfo_t *si;
mesh_t srcMesh, *subdivided, *mesh; mesh_t srcMesh, *subdivided, *mesh;
@ -291,9 +291,9 @@ void Foliage( mapDrawSurface_t *src ){
fi->normal = foliageInstances[ j ].normal; fi->normal = foliageInstances[ j ].normal;
/* ydnar: set color */ /* ydnar: set color */
for ( k = 0; k < MAX_LIGHTMAPS; k++ ) for ( auto& color : fi->color )
{ {
fi->color[ k ].set( 255 ); color.set( 255 );
} }
} }

View File

@ -501,8 +501,8 @@ void BeginModel( void ){
/* bound patches */ /* bound patches */
for ( const parseMesh_t *p = e.patches; p; p = p->next ) for ( const parseMesh_t *p = e.patches; p; p = p->next )
{ {
for ( int i = 0; i < ( p->mesh.width * p->mesh.height ); i++ ) for ( const bspDrawVert_t& vert : Span( p->mesh.verts, p->mesh.width * p->mesh.height ) )
minmax.extend( p->mesh.verts[i].xyz ); minmax.extend( vert.xyz );
} }
/* ydnar: lightgrid mins/maxs */ /* ydnar: lightgrid mins/maxs */