std::vector<rawGridPoint_t> rawGridPoints

This commit is contained in:
Garux 2021-09-28 05:07:56 +03:00
parent d1ccdb0fcf
commit 5283f631e7
2 changed files with 22 additions and 32 deletions

View File

@ -1603,10 +1603,6 @@ void TraceGrid( int num ){
*/ */
void SetupGrid( void ){ void SetupGrid( void ){
int i, j;
char temp[ 64 ];
/* don't do this if not grid lighting */ /* don't do this if not grid lighting */
if ( noGridLighting ) { if ( noGridLighting ) {
return; return;
@ -1617,15 +1613,15 @@ void SetupGrid( void ){
/* quantize it */ /* quantize it */
const Vector3 oldGridSize = gridSize; const Vector3 oldGridSize = gridSize;
for ( i = 0; i < 3; i++ ) for ( int i = 0; i < 3; i++ )
gridSize[ i ] = std::max( 8.0, floor( gridSize[ i ] ) ); gridSize[ i ] = std::max( 8.0, floor( gridSize[ i ] ) );
/* ydnar: increase gridSize until grid count is smaller than max allowed */ /* ydnar: increase gridSize until grid count is smaller than max allowed */
j = 0; size_t numGridPoints;
while ( true ) for( int j = 0; ; )
{ {
/* get world bounds */ /* get world bounds */
for ( i = 0; i < 3; i++ ) for ( int i = 0; i < 3; i++ )
{ {
gridMins[ i ] = gridSize[ i ] * ceil( bspModels[ 0 ].minmax.mins[ i ] / gridSize[ i ] ); gridMins[ i ] = gridSize[ i ] * ceil( bspModels[ 0 ].minmax.mins[ i ] / gridSize[ i ] );
const float max = gridSize[ i ] * floor( bspModels[ 0 ].minmax.maxs[ i ] / gridSize[ i ] ); const float max = gridSize[ i ] * floor( bspModels[ 0 ].minmax.maxs[ i ] / gridSize[ i ] );
@ -1640,7 +1636,7 @@ void SetupGrid( void ){
} }
else{ else{
/* set grid size */ /* set grid size */
numRawGridPoints = num; numGridPoints = num;
break; break;
} }
} }
@ -1650,34 +1646,29 @@ void SetupGrid( void ){
/* different? */ /* different? */
if ( !VectorCompare( gridSize, oldGridSize ) ) { if ( !VectorCompare( gridSize, oldGridSize ) ) {
char temp[ 64 ];
sprintf( temp, "%.0f %.0f %.0f", gridSize[ 0 ], gridSize[ 1 ], gridSize[ 2 ] ); sprintf( temp, "%.0f %.0f %.0f", gridSize[ 0 ], gridSize[ 1 ], gridSize[ 2 ] );
entities[ 0 ].setKeyValue( "gridsize", (const char*) temp ); entities[ 0 ].setKeyValue( "gridsize", (const char*) temp );
Sys_FPrintf( SYS_VRB, "Storing adjusted grid size\n" ); Sys_FPrintf( SYS_VRB, "Storing adjusted grid size\n" );
} }
/* allocate lightgrid */ /* allocate and clear lightgrid */
rawGridPoints = safe_calloc( numRawGridPoints * sizeof( *rawGridPoints ) );
bspGridPoints.resize( numRawGridPoints );
memset( bspGridPoints.data(), 0, bspGridPoints.size() * sizeof( bspGridPoints[0] ) );
/* clear lightgrid */
for ( i = 0; i < numRawGridPoints; i++ )
{ {
for ( j = 0; j < MAX_LIGHTMAPS; j++ ) static_assert( MAX_LIGHTMAPS == 4 );
rawGridPoints[ i ].ambient[ j ] = ambientColor; rawGridPoints = decltype( rawGridPoints )( numGridPoints, rawGridPoint_t{
{ ambientColor, ambientColor, ambientColor, ambientColor },
rawGridPoints[ i ].styles[ 0 ] = LS_NORMAL; { g_vector3_identity, g_vector3_identity, g_vector3_identity, g_vector3_identity },
bspGridPoints[ i ].styles[ 0 ] = LS_NORMAL; g_vector3_identity,
for ( j = 1; j < MAX_LIGHTMAPS; j++ ) { LS_NORMAL, LS_NONE, LS_NONE, LS_NONE } } );
{ bspGridPoints = decltype( bspGridPoints )( numGridPoints, bspGridPoint_t{
rawGridPoints[ i ].styles[ j ] = LS_NONE; { Vector3b( 0 ), Vector3b( 0 ), Vector3b( 0 ), Vector3b( 0 ) },
bspGridPoints[ i ].styles[ j ] = LS_NONE; { Vector3b( 0 ), Vector3b( 0 ), Vector3b( 0 ), Vector3b( 0 ) },
} { LS_NORMAL, LS_NONE, LS_NONE, LS_NONE },
{ 0, 0 } } );
} }
/* note it */ /* note it */
Sys_Printf( "%9d grid points\n", numRawGridPoints ); Sys_Printf( "%9zu grid points\n", rawGridPoints.size() );
} }
@ -1759,7 +1750,7 @@ void LightWorld( bool fastAllocate ){
Sys_Printf( "--- TraceGrid ---\n" ); Sys_Printf( "--- TraceGrid ---\n" );
inGrid = true; inGrid = true;
RunThreadsOnIndividual( numRawGridPoints, true, TraceGrid ); RunThreadsOnIndividual( rawGridPoints.size(), true, TraceGrid );
inGrid = false; inGrid = false;
Sys_Printf( "%d x %d x %d = %zu grid\n", Sys_Printf( "%d x %d x %d = %zu grid\n",
gridBounds[ 0 ], gridBounds[ 1 ], gridBounds[ 2 ], bspGridPoints.size() ); gridBounds[ 0 ], gridBounds[ 1 ], gridBounds[ 2 ], bspGridPoints.size() );
@ -1851,7 +1842,7 @@ void LightWorld( bool fastAllocate ){
Sys_Printf( "--- BounceGrid ---\n" ); Sys_Printf( "--- BounceGrid ---\n" );
inGrid = true; inGrid = true;
RunThreadsOnIndividual( numRawGridPoints, true, TraceGrid ); RunThreadsOnIndividual( rawGridPoints.size(), true, TraceGrid );
inGrid = false; inGrid = false;
Sys_FPrintf( SYS_VRB, "%9d grid points envelope culled\n", gridEnvelopeCulled ); Sys_FPrintf( SYS_VRB, "%9d grid points envelope culled\n", gridEnvelopeCulled );
Sys_FPrintf( SYS_VRB, "%9d grid points bounds culled\n", gridBoundsCulled ); Sys_FPrintf( SYS_VRB, "%9d grid points bounds culled\n", gridBoundsCulled );

View File

@ -2284,8 +2284,7 @@ Q_EXTERN outLightmap_t *outLightmaps Q_ASSIGN( NULL );
Q_EXTERN int numSurfacesFloodlighten Q_ASSIGN( 0 ); Q_EXTERN int numSurfacesFloodlighten Q_ASSIGN( 0 );
/* grid points */ /* grid points */
Q_EXTERN int numRawGridPoints Q_ASSIGN( 0 ); Q_EXTERN std::vector<rawGridPoint_t> rawGridPoints;
Q_EXTERN rawGridPoint_t *rawGridPoints Q_ASSIGN( NULL );
Q_EXTERN int numSurfsVertexLit Q_ASSIGN( 0 ); Q_EXTERN int numSurfsVertexLit Q_ASSIGN( 0 );
Q_EXTERN int numSurfsVertexForced Q_ASSIGN( 0 ); Q_EXTERN int numSurfsVertexForced Q_ASSIGN( 0 );