From 5dbb0af073ba8f8a8debafd9dd735ed1e552dacd Mon Sep 17 00:00:00 2001 From: Garux Date: Mon, 20 Oct 2025 14:52:24 +0500 Subject: [PATCH] minor tweaks --- tools/quake3/q3map2/convert_bsp.cpp | 62 +++++++++---------------- tools/quake3/q3map2/convert_map.cpp | 14 ++---- tools/quake3/q3map2/light.cpp | 9 ++-- tools/quake3/q3map2/light_ydnar.cpp | 29 ++++-------- tools/quake3/q3map2/lightmaps_ydnar.cpp | 12 ++--- 5 files changed, 45 insertions(+), 81 deletions(-) diff --git a/tools/quake3/q3map2/convert_bsp.cpp b/tools/quake3/q3map2/convert_bsp.cpp index 80c4e7a4..38b576f0 100644 --- a/tools/quake3/q3map2/convert_bsp.cpp +++ b/tools/quake3/q3map2/convert_bsp.cpp @@ -698,45 +698,27 @@ int MergeBSPMain( Args& args ){ LoadBSPFile( source ); ParseEntities(); - struct bsp + struct { - std::vector entities; - std::vector bspModels; - std::vector bspShaders; - std::vector bspLeafs; - std::vector bspPlanes; - std::vector bspNodes; - std::vector bspLeafSurfaces; - std::vector bspLeafBrushes; - std::vector bspBrushes; - std::vector bspBrushSides; - std::vector bspLightBytes; - std::vector bspGridPoints; - std::vector bspVisBytes; - std::vector bspDrawVerts; - std::vector bspDrawIndexes; - std::vector bspDrawSurfaces; - std::vector bspFogs; + decltype( entities ) entities = std::move( ::entities ); + decltype( bspModels ) bspModels = std::move( ::bspModels ); + decltype( bspShaders ) bspShaders = std::move( ::bspShaders ); + decltype( bspLeafs ) bspLeafs = std::move( ::bspLeafs ); + decltype( bspPlanes ) bspPlanes = std::move( ::bspPlanes ); + decltype( bspNodes ) bspNodes = std::move( ::bspNodes ); + decltype( bspLeafSurfaces ) bspLeafSurfaces = std::move( ::bspLeafSurfaces ); + decltype( bspLeafBrushes ) bspLeafBrushes = std::move( ::bspLeafBrushes ); + decltype( bspBrushes ) bspBrushes = std::move( ::bspBrushes ); + decltype( bspBrushSides ) bspBrushSides = std::move( ::bspBrushSides ); + decltype( bspLightBytes ) bspLightBytes = std::move( ::bspLightBytes ); + decltype( bspGridPoints ) bspGridPoints = std::move( ::bspGridPoints ); + decltype( bspVisBytes ) bspVisBytes = std::move( ::bspVisBytes ); + decltype( bspDrawVerts ) bspDrawVerts = std::move( ::bspDrawVerts ); + decltype( bspDrawIndexes ) bspDrawIndexes = std::move( ::bspDrawIndexes ); + decltype( bspDrawSurfaces ) bspDrawSurfaces = std::move( ::bspDrawSurfaces ); + decltype( bspFogs ) bspFogs = std::move( ::bspFogs ); } bsp; - bsp.entities = std::move( entities ); - bsp.bspModels = std::move( bspModels ); - bsp.bspShaders = std::move( bspShaders ); - bsp.bspLeafs = std::move( bspLeafs ); - bsp.bspPlanes = std::move( bspPlanes ); - bsp.bspNodes = std::move( bspNodes ); - bsp.bspLeafSurfaces = std::move( bspLeafSurfaces ); - bsp.bspLeafBrushes = std::move( bspLeafBrushes ); - bsp.bspBrushes = std::move( bspBrushes ); - bsp.bspBrushSides = std::move( bspBrushSides ); - bsp.bspLightBytes = std::move( bspLightBytes ); - bsp.bspGridPoints = std::move( bspGridPoints ); - bsp.bspVisBytes = std::move( bspVisBytes ); - bsp.bspDrawVerts = std::move( bspDrawVerts ); - bsp.bspDrawIndexes = std::move( bspDrawIndexes ); - bsp.bspDrawSurfaces = std::move( bspDrawSurfaces ); - bsp.bspFogs = std::move( bspFogs ); - /* do some path mangling */ strcpy( source, ExpandArg( fileName1 ) ); path_set_extension( source, ".bsp" ); @@ -894,8 +876,8 @@ int MergeBSPMain( Args& args ){ minmax = { surf->lightmapVecs[0], surf->lightmapVecs[1] }; } else{ - for( int i = 0; i < surf->numIndexes; ++i ) - minmax.extend( bspDrawVerts[surf->firstVert + bspDrawIndexes[surf->firstIndex + i]].xyz ); + for( const int i : Span( &bspDrawIndexes[surf->firstIndex], surf->numIndexes ) ) + minmax.extend( bspDrawVerts[surf->firstVert + i].xyz ); } for( auto&& leaf : bspLeafs ){ @@ -920,9 +902,9 @@ int MergeBSPMain( Args& args ){ for( auto end = bspBrushes.cbegin() + bspModels[0].firstBSPBrush + bspModels[0].numBSPBrushes, brush = end - brushes.size(); brush != end; ++brush ){ buildBrush.sides.clear(); - for( auto side = bspBrushSides.cbegin() + brush->firstSide, end = side + brush->numSides; side != end; ++side ){ + for( const bspBrushSide_t& side : Span( &bspBrushSides[ brush->firstSide ], brush->numSides ) ){ auto& s = buildBrush.sides.emplace_back(); - s.planenum = side->planeNum; + s.planenum = side.planeNum; } if( CreateBrushWindings( buildBrush ) ){ // cheap minmax test diff --git a/tools/quake3/q3map2/convert_map.cpp b/tools/quake3/q3map2/convert_map.cpp index 717096ff..c9cf52f2 100644 --- a/tools/quake3/q3map2/convert_map.cpp +++ b/tools/quake3/q3map2/convert_map.cpp @@ -199,11 +199,8 @@ static void bspBrush_to_buildBrush( const bspBrush_t& brush ){ if ( force ){ int notNoShader = 0; modelclip = true; - for ( int i = 0; i < brush.numSides; ++i ) + for ( const bspBrushSide_t& side : Span( &bspBrushSides[ brush.firstSide ], brush.numSides ) ) { - /* get side */ - const bspBrushSide_t& side = bspBrushSides[ brush.firstSide + i ]; - /* get shader */ if ( side.shaderNum < 0 || side.shaderNum >= int( bspShaders.size() ) ) { continue; @@ -221,11 +218,8 @@ static void bspBrush_to_buildBrush( const bspBrush_t& brush ){ } /* iterate through bsp brush sides */ - for ( int i = 0; i < brush.numSides; ++i ) + for ( const bspBrushSide_t& side : Span( &bspBrushSides[ brush.firstSide ], brush.numSides ) ) { - /* get side */ - const bspBrushSide_t& side = bspBrushSides[ brush.firstSide + i ]; - /* get shader */ if ( side.shaderNum < 0 || side.shaderNum >= int( bspShaders.size() ) ) { continue; @@ -342,8 +336,8 @@ static void ConvertBrush( FILE *f, int bspBrushNum, const Vector3& origin, bool if( !( bspShaders[bspBrushes[bspBrushNum].shaderNum].contentFlags & GetRequiredSurfaceParm<"structural">().contentFlags ) ){ // sort out structural transparent brushes, e.g. hints for( const auto& leaf : bspLeafs ){ if( leaf.cluster > CLUSTER_OPAQUE ) - for( auto id = bspLeafBrushes.cbegin() + leaf.firstBSPLeafBrush, end = id + leaf.numBSPLeafBrushes; id != end; ++id ){ - if( *id == bspBrushNum ){ + for( const int id : Span( &bspLeafBrushes[ leaf.firstBSPLeafBrush ], leaf.numBSPLeafBrushes ) ){ + if( id == bspBrushNum ){ contentFlag = C_DETAIL; break; } diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp index 21e6e5e9..9ec46bc9 100644 --- a/tools/quake3/q3map2/light.cpp +++ b/tools/quake3/q3map2/light.cpp @@ -710,15 +710,12 @@ static void SetEntityOrigins(){ } /* set origin for all surfaces for this model */ - for ( int j = 0; j < dm.numBSPSurfaces; ++j ) + for ( const bspDrawSurface_t& ds : Span( &bspDrawSurfaces[ dm.firstBSPSurface ], dm.numBSPSurfaces ) ) { - /* get drawsurf */ - const bspDrawSurface_t& ds = bspDrawSurfaces[ dm.firstBSPSurface + j ]; - /* set its verts */ - for ( int k = 0; k < ds.numVerts; ++k ) + for ( bspDrawVert_t& dv : Span( &yDrawVerts[ ds.firstVert ], ds.numVerts ) ) { - yDrawVerts[ ds.firstVert + k ].xyz += origin; + dv.xyz += origin; } } } diff --git a/tools/quake3/q3map2/light_ydnar.cpp b/tools/quake3/q3map2/light_ydnar.cpp index d1aeecb8..0a2c823a 100644 --- a/tools/quake3/q3map2/light_ydnar.cpp +++ b/tools/quake3/q3map2/light_ydnar.cpp @@ -433,12 +433,8 @@ int ClusterForPointExt( const Vector3& point, float epsilon ){ } /* transparent leaf, so check point against all brushes in the leaf */ - const int *brushes = &bspLeafBrushes[ leaf.firstBSPLeafBrush ]; - const int numBSPBrushes = leaf.numBSPLeafBrushes; - for ( int i = 0; i < numBSPBrushes; ++i ) + for ( const int b : Span( &bspLeafBrushes[ leaf.firstBSPLeafBrush ], leaf.numBSPLeafBrushes ) ) { - /* get parts */ - const int b = brushes[ i ]; if ( b > maxOpaqueBrush ) { continue; } @@ -449,11 +445,12 @@ int ClusterForPointExt( const Vector3& point, float epsilon ){ const bspBrush_t& brush = bspBrushes[ b ]; /* check point against all planes */ bool inside = true; - for ( int j = 0; j < brush.numSides && inside; ++j ) + for ( const bspBrushSide_t& side : Span( &bspBrushSides[ brush.firstSide ], brush.numSides ) ) { - const bspPlane_t& plane = bspPlanes[ bspBrushSides[ brush.firstSide + j ].planeNum ]; + const bspPlane_t& plane = bspPlanes[ side.planeNum ]; if ( plane3_distance_to_point( plane, point ) > epsilon ) { inside = false; + break; } } @@ -518,23 +515,21 @@ static int ShaderForPointInLeaf( const Vector3& point, int leafNum, float epsilo const bspLeaf_t& leaf = bspLeafs[ leafNum ]; /* transparent leaf, so check point against all brushes in the leaf */ - const int *brushes = &bspLeafBrushes[ leaf.firstBSPLeafBrush ]; - const int numBSPBrushes = leaf.numBSPLeafBrushes; - for ( int i = 0; i < numBSPBrushes; ++i ) + for ( const int b : Span( &bspLeafBrushes[ leaf.firstBSPLeafBrush ], leaf.numBSPLeafBrushes ) ) { /* get parts */ - const bspBrush_t& brush = bspBrushes[ brushes[ i ] ]; + const bspBrush_t& brush = bspBrushes[ b ]; /* check point against all planes */ bool inside = true; allSurfaceFlags = 0; allContentFlags = 0; - for ( int j = 0; j < brush.numSides && inside; ++j ) + for ( const bspBrushSide_t& side : Span( &bspBrushSides[ brush.firstSide ], brush.numSides ) ) { - const bspBrushSide_t& side = bspBrushSides[ brush.firstSide + j ]; const bspPlane_t& plane = bspPlanes[ side.planeNum ]; if ( plane3_distance_to_point( plane, point ) > epsilon ) { inside = false; + break; } else { @@ -2189,9 +2184,8 @@ static void CreateTraceLightsForSurface( int num, trace_t *trace ){ /* get the mins/maxs for the dsurf */ MinMax minmax; Vector3 normal = bspDrawVerts[ ds.firstVert ].normal; - for ( int i = 0; i < ds.numVerts; ++i ) + for ( const bspDrawVert_t& dv : Span( &yDrawVerts[ ds.firstVert ], ds.numVerts ) ) { - const bspDrawVert_t& dv = yDrawVerts[ ds.firstVert + i ]; minmax.extend( dv.xyz ); if ( !VectorCompare( dv.normal, normal ) ) { normal.set( 0 ); @@ -3343,11 +3337,8 @@ void SetupBrushesFlags( int mask_any, int test_any, int mask_all, int test_all ) /* check all sides */ compileFlags = 0; allCompileFlags = ~( 0 ); - for ( int j = 0; j < brush.numSides; ++j ) + for ( const bspBrushSide_t& side : Span( &bspBrushSides[ brush.firstSide ], brush.numSides ) ) { - /* do bsp shader calculations */ - const bspBrushSide_t& side = bspBrushSides[ brush.firstSide + j ]; - /* get shader info */ const shaderInfo_t *si = ShaderInfoForShaderNull( bspShaders[ side.shaderNum ].shader ); if ( si == nullptr ) { diff --git a/tools/quake3/q3map2/lightmaps_ydnar.cpp b/tools/quake3/q3map2/lightmaps_ydnar.cpp index 594e196e..52d627e7 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.cpp +++ b/tools/quake3/q3map2/lightmaps_ydnar.cpp @@ -932,7 +932,7 @@ struct CompareSurfaceInfo */ void SetupSurfaceLightmaps(){ - int i, j, k, s, num, num2; + int i, j, k, num, num2; bspDrawSurface_t *ds; surfaceInfo_t *info, *info2; rawLightmap_t *lm; @@ -1011,10 +1011,10 @@ void SetupSurfaceLightmaps(){ /* determine surface bounds */ info->minmax.clear(); - for ( k = 0; k < ds->numVerts; ++k ) + for ( const bspDrawVert_t& dv : Span( &yDrawVerts[ ds->firstVert ], ds->numVerts ) ) { - g_mapMinmax.extend( yDrawVerts[ ds->firstVert + k ].xyz ); - info->minmax.extend( yDrawVerts[ ds->firstVert + k ].xyz ); + g_mapMinmax.extend( dv.xyz ); + info->minmax.extend( dv.xyz ); } /* find all the bsp clusters the surface falls into */ @@ -1026,9 +1026,9 @@ void SetupSurfaceLightmaps(){ } /* test leaf surfaces */ - for ( s = 0; s < leaf.numBSPLeafSurfaces; ++s ) + for ( const int s : Span( &bspLeafSurfaces[ leaf.firstBSPLeafSurface ], leaf.numBSPLeafSurfaces ) ) { - if ( bspLeafSurfaces[ leaf.firstBSPLeafSurface + s ] == num ) { + if ( s == num ) { if ( numSurfaceClusters >= maxSurfaceClusters ) { Error( "maxSurfaceClusters exceeded" ); }