std::vector<bspDrawSurface_t> bspDrawSurfaces

This commit is contained in:
Garux 2021-09-27 06:14:12 +03:00
parent 7993cc8a1f
commit 4642753564
21 changed files with 263 additions and 445 deletions

View File

@ -239,9 +239,9 @@ int pk3BSPMain( Args& args ){
std::vector<bool> drawsurfSHs( bspShaders.size(), false ); std::vector<bool> drawsurfSHs( bspShaders.size(), false );
for ( i = 0; i < numBSPDrawSurfaces; ++i ){ for ( const bspDrawSurface_t& surf : bspDrawSurfaces ){
drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = true; drawsurfSHs[ surf.shaderNum ] = true;
//Sys_Printf( "%s\n", bspShaders[bspDrawSurfaces[i].shaderNum].shader ); //Sys_Printf( "%s\n", bspShaders[surf.shaderNum].shader );
} }
StrList* pk3Shaders = StrList_allocate( 1024 ); StrList* pk3Shaders = StrList_allocate( 1024 );
@ -911,8 +911,8 @@ int repackBSPMain( Args& args ){
std::vector<bool> drawsurfSHs( bspShaders.size(), false ); std::vector<bool> drawsurfSHs( bspShaders.size(), false );
for ( i = 0; i < numBSPDrawSurfaces; ++i ){ for ( const bspDrawSurface_t& surf : bspDrawSurfaces ){
drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = true; drawsurfSHs[ surf.shaderNum ] = true;
} }
for ( size_t i = 0; i < bspShaders.size(); ++i ){ for ( size_t i = 0; i < bspShaders.size(); ++i ){
@ -977,9 +977,7 @@ int repackBSPMain( Args& args ){
Sys_Printf( "%s\n", pk3Sounds->s[i] ); Sys_Printf( "%s\n", pk3Sounds->s[i] );
} }
/* free partially loaded bsp data */ /* free partially loaded bsp data */
free( bspDrawSurfaces ); bspDrawSurfaces.clear();
bspDrawSurfaces = NULL;
numBSPDrawSurfaces = 0;
entities.clear(); entities.clear();
numBSPEntities = 0; numBSPEntities = 0;

View File

@ -648,7 +648,6 @@ int BSPMain( Args& args ){
Sys_Printf( "--- BSP ---\n" ); Sys_Printf( "--- BSP ---\n" );
doingBSP = true; doingBSP = true;
SetDrawSurfacesBuffer();
mapDrawSurfs = safe_calloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); mapDrawSurfs = safe_calloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
numMapDrawSurfs = 0; numMapDrawSurfs = 0;

View File

@ -51,38 +51,6 @@
/* FIXME: remove the functions below that handle memory management of bsp file chunks */
int numBSPDrawSurfacesBuffer = 0;
void SetDrawSurfacesBuffer(){
free( bspDrawSurfaces );
numBSPDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS;
bspDrawSurfaces = safe_calloc_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
}
void SetDrawSurfaces( int n ){
free( bspDrawSurfaces );
numBSPDrawSurfaces =
numBSPDrawSurfacesBuffer = n;
bspDrawSurfaces = safe_calloc_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
}
void BSPFilesCleanup(){
bspDrawVerts.clear();
free( bspDrawSurfaces );
bspLightBytes.clear();
bspGridPoints.clear();
}
/* /*
SwapBlock() SwapBlock()
if all values are 32 bits, this can be used to swap everything if all values are 32 bits, this can be used to swap everything
@ -193,7 +161,7 @@ void SwapBSPFile( void ){
/* drawsurfs */ /* drawsurfs */
/* note: rbsp files (and hence q3map2 abstract bsp) have byte lightstyles index arrays, this follows sof2map convention */ /* note: rbsp files (and hence q3map2 abstract bsp) have byte lightstyles index arrays, this follows sof2map convention */
SwapBlock( (int*) bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) ); SwapBlock( bspDrawSurfaces );
/* fogs */ /* fogs */
for ( i = 0; i < numBSPFogs; i++ ) for ( i = 0; i < numBSPFogs; i++ )
@ -348,26 +316,7 @@ void PartialLoadBSPFile( const char *filename ){
/* load it, then byte swap the in-memory version */ /* load it, then byte swap the in-memory version */
//g_game->load( filename ); //g_game->load( filename );
PartialLoadIBSPFile( filename ); PartialLoadIBSPFile( filename );
SwapBSPFile();
/* PartialSwapBSPFile() */
/* shaders (don't swap the name) */
for ( bspShader_t& shader : bspShaders )
{
shader.contentFlags = LittleLong( shader.contentFlags );
shader.surfaceFlags = LittleLong( shader.surfaceFlags );
}
/* drawsurfs */
/* note: rbsp files (and hence q3map2 abstract bsp) have byte lightstyles index arrays, this follows sof2map convention */
SwapBlock( (int*) bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) );
/* fogs */
for ( int i = 0; i < numBSPFogs; i++ )
{
bspFogs[ i ].brushNum = LittleLong( bspFogs[ i ].brushNum );
bspFogs[ i ].visibleSide = LittleLong( bspFogs[ i ].visibleSide );
}
} }
/* /*
@ -412,12 +361,12 @@ void PrintBSPFileSizes( void ){
ParseEntities(); ParseEntities();
} }
int patchCount = 0, planarCount = 0, trisoupCount = 0; int patchCount = 0, planarCount = 0, trisoupCount = 0;
for ( const bspDrawSurface_t *s = bspDrawSurfaces; s != bspDrawSurfaces + numBSPDrawSurfaces; ++s ){ for ( const bspDrawSurface_t& s : bspDrawSurfaces ){
if ( s->surfaceType == MST_PATCH ) if ( s.surfaceType == MST_PATCH )
++patchCount; ++patchCount;
else if ( s->surfaceType == MST_PLANAR ) else if ( s.surfaceType == MST_PLANAR )
++planarCount; ++planarCount;
else if ( s->surfaceType == MST_TRIANGLE_SOUP ) else if ( s.surfaceType == MST_TRIANGLE_SOUP )
++trisoupCount; ++trisoupCount;
} }
/* note that this is abstracted */ /* note that this is abstracted */
@ -450,8 +399,8 @@ void PrintBSPFileSizes( void ){
bspLeafBrushes.size(), bspLeafBrushes.size() * sizeof( bspLeafBrushes[0] ) ); bspLeafBrushes.size(), bspLeafBrushes.size() * sizeof( bspLeafBrushes[0] ) );
Sys_Printf( "\n" ); Sys_Printf( "\n" );
Sys_Printf( "%9d drawsurfaces %9d *\n", Sys_Printf( "%9zu drawsurfaces %9zu *\n",
numBSPDrawSurfaces, (int) ( numBSPDrawSurfaces * sizeof( *bspDrawSurfaces ) ) ); bspDrawSurfaces.size(), bspDrawSurfaces.size() * sizeof( bspDrawSurfaces[0] ) );
Sys_Printf( "%9d patch surfaces\n", Sys_Printf( "%9d patch surfaces\n",
patchCount ); patchCount );
Sys_Printf( "%9d planar surfaces\n", Sys_Printf( "%9d planar surfaces\n",

View File

@ -112,113 +112,49 @@ struct ibspDrawSurface_t
int patchWidth; int patchWidth;
int patchHeight; int patchHeight;
ibspDrawSurface_t( const bspDrawSurface_t& other ) :
shaderNum( other.shaderNum ),
fogNum( other.fogNum ),
surfaceType( other.surfaceType ),
firstVert( other.firstVert ),
numVerts( other.numVerts ),
firstIndex( other.firstIndex ),
numIndexes( other.numIndexes ),
lightmapNum( other.lightmapNum[0] ),
lightmapX( other.lightmapX[0] ),
lightmapY( other.lightmapY[0] ),
lightmapWidth( other.lightmapWidth ),
lightmapHeight( other.lightmapHeight ),
lightmapOrigin( other.lightmapOrigin ),
lightmapVecs{ other.lightmapVecs[0], other.lightmapVecs[1], other.lightmapVecs[2] },
patchWidth( other.patchWidth ),
patchHeight( other.patchHeight ) {}
operator bspDrawSurface_t() const {
static_assert( MAX_LIGHTMAPS == 4 );
return{
shaderNum,
fogNum,
surfaceType,
firstVert,
numVerts,
firstIndex,
numIndexes,
{ LS_NORMAL, LS_NONE, LS_NONE, LS_NONE },
{ LS_NORMAL, LS_NONE, LS_NONE, LS_NONE },
{ lightmapNum, -3, -3, -3 },
{ lightmapX, 0, 0, 0 },
{ lightmapY, 0, 0, 0 },
lightmapWidth,
lightmapHeight,
lightmapOrigin,
{ lightmapVecs[0], lightmapVecs[1], lightmapVecs[2] },
patchWidth,
patchHeight
};
}
}; };
static void CopyDrawSurfacesLump( ibspHeader_t *header ){
int i, j;
ibspDrawSurface_t *in;
bspDrawSurface_t *out;
/* get count */
numBSPDrawSurfaces = GetLumpElements( (bspHeader_t*) header, LUMP_SURFACES, sizeof( *in ) );
SetDrawSurfaces( numBSPDrawSurfaces );
/* copy */
in = GetLump( (bspHeader_t*) header, LUMP_SURFACES );
out = bspDrawSurfaces;
for ( i = 0; i < numBSPDrawSurfaces; i++ )
{
out->shaderNum = in->shaderNum;
out->fogNum = in->fogNum;
out->surfaceType = in->surfaceType;
out->firstVert = in->firstVert;
out->numVerts = in->numVerts;
out->firstIndex = in->firstIndex;
out->numIndexes = in->numIndexes;
out->lightmapStyles[ 0 ] = LS_NORMAL;
out->vertexStyles[ 0 ] = LS_NORMAL;
out->lightmapNum[ 0 ] = in->lightmapNum;
out->lightmapX[ 0 ] = in->lightmapX;
out->lightmapY[ 0 ] = in->lightmapY;
for ( j = 1; j < MAX_LIGHTMAPS; j++ )
{
out->lightmapStyles[ j ] = LS_NONE;
out->vertexStyles[ j ] = LS_NONE;
out->lightmapNum[ j ] = -3;
out->lightmapX[ j ] = 0;
out->lightmapY[ j ] = 0;
}
out->lightmapWidth = in->lightmapWidth;
out->lightmapHeight = in->lightmapHeight;
out->lightmapOrigin = in->lightmapOrigin;
out->lightmapVecs[ 0 ] = in->lightmapVecs[ 0 ];
out->lightmapVecs[ 1 ] = in->lightmapVecs[ 1 ];
out->lightmapVecs[ 2 ] = in->lightmapVecs[ 2 ];
out->patchWidth = in->patchWidth;
out->patchHeight = in->patchHeight;
in++;
out++;
}
}
static void AddDrawSurfacesLump( FILE *file, ibspHeader_t *header ){
int i, size;
bspDrawSurface_t *in;
ibspDrawSurface_t *buffer, *out;
/* allocate output buffer */
size = numBSPDrawSurfaces * sizeof( *buffer );
buffer = safe_calloc( size );
/* convert */
in = bspDrawSurfaces;
out = buffer;
for ( i = 0; i < numBSPDrawSurfaces; i++ )
{
out->shaderNum = in->shaderNum;
out->fogNum = in->fogNum;
out->surfaceType = in->surfaceType;
out->firstVert = in->firstVert;
out->numVerts = in->numVerts;
out->firstIndex = in->firstIndex;
out->numIndexes = in->numIndexes;
out->lightmapNum = in->lightmapNum[ 0 ];
out->lightmapX = in->lightmapX[ 0 ];
out->lightmapY = in->lightmapY[ 0 ];
out->lightmapWidth = in->lightmapWidth;
out->lightmapHeight = in->lightmapHeight;
out->lightmapOrigin = in->lightmapOrigin;
out->lightmapVecs[ 0 ] = in->lightmapVecs[ 0 ];
out->lightmapVecs[ 1 ] = in->lightmapVecs[ 1 ];
out->lightmapVecs[ 2 ] = in->lightmapVecs[ 2 ];
out->patchWidth = in->patchWidth;
out->patchHeight = in->patchHeight;
in++;
out++;
}
/* write lump */
AddLump( file, (bspHeader_t*) header, LUMP_SURFACES, buffer, size );
/* free buffer */
free( buffer );
}
/* drawverts */ /* drawverts */
struct ibspDrawVert_t struct ibspDrawVert_t
@ -234,7 +170,7 @@ struct ibspDrawVert_t
lightmap( other.lightmap[0] ), lightmap( other.lightmap[0] ),
normal( other.normal ), normal( other.normal ),
color( other.color[0] ) {} color( other.color[0] ) {}
operator bspDrawVert_t() { operator bspDrawVert_t() const {
static_assert( MAX_LIGHTMAPS == 4 ); static_assert( MAX_LIGHTMAPS == 4 );
return { return {
xyz, xyz,
@ -315,7 +251,7 @@ void LoadIBSPFile( const char *filename ){
CopyLump<bspDrawVert_t, ibspDrawVert_t>( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts ); CopyLump<bspDrawVert_t, ibspDrawVert_t>( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts );
CopyDrawSurfacesLump( header ); CopyLump<bspDrawSurface_t, ibspDrawSurface_t>( (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces );
numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFog_t ) ); // TODO fix overflow numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFog_t ) ); // TODO fix overflow
@ -367,7 +303,7 @@ void PartialLoadIBSPFile( const char *filename ){
/* load/convert lumps */ /* load/convert lumps */
CopyLump( (bspHeader_t*) header, LUMP_SHADERS, bspShaders ); CopyLump( (bspHeader_t*) header, LUMP_SHADERS, bspShaders );
CopyDrawSurfacesLump( header ); CopyLump<bspDrawSurface_t, ibspDrawSurface_t>( (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces );
numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFog_t ) ); // TODO fix overflow numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFog_t ) ); // TODO fix overflow
@ -421,7 +357,7 @@ void WriteIBSPFile( const char *filename ){
AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes ); AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes );
AddLump( file, header->lumps[LUMP_MODELS], bspModels ); AddLump( file, header->lumps[LUMP_MODELS], bspModels );
AddLump( file, header->lumps[LUMP_DRAWVERTS], std::vector<ibspDrawVert_t>( bspDrawVerts.begin(), bspDrawVerts.end() ) ); AddLump( file, header->lumps[LUMP_DRAWVERTS], std::vector<ibspDrawVert_t>( bspDrawVerts.begin(), bspDrawVerts.end() ) );
AddDrawSurfacesLump( file, header ); AddLump( file, header->lumps[LUMP_SURFACES], std::vector<ibspDrawSurface_t>( bspDrawSurfaces.begin(), bspDrawSurfaces.end() ) );
AddLump( file, header->lumps[LUMP_VISIBILITY], bspVisBytes ); AddLump( file, header->lumps[LUMP_VISIBILITY], bspVisBytes );
AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes ); AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes );
AddLump( file, header->lumps[LUMP_LIGHTGRID], std::vector<ibspGridPoint_t>( bspGridPoints.begin(), bspGridPoints.end() ) ); AddLump( file, header->lumps[LUMP_LIGHTGRID], std::vector<ibspGridPoint_t>( bspGridPoints.begin(), bspGridPoints.end() ) );

View File

@ -217,9 +217,7 @@ void LoadRBSPFile( const char *filename ){
CopyLump( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts ); CopyLump( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts );
numBSPDrawSurfaces = GetLumpElements( (bspHeader_t*) header, LUMP_SURFACES, sizeof( bspDrawSurfaces[ 0 ] ) ); CopyLump( (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces );
SetDrawSurfaces( numBSPDrawSurfaces );
CopyLump( (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces, sizeof( bspDrawSurfaces[ 0 ] ) );
numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFogs[ 0 ] ) ); numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFogs[ 0 ] ) );
@ -283,7 +281,7 @@ void WriteRBSPFile( const char *filename ){
AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes ); AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes );
AddLump( file, header->lumps[LUMP_MODELS], bspModels ); AddLump( file, header->lumps[LUMP_MODELS], bspModels );
AddLump( file, header->lumps[LUMP_DRAWVERTS], bspDrawVerts ); AddLump( file, header->lumps[LUMP_DRAWVERTS], bspDrawVerts );
AddLump( file, (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) ); AddLump( file, header->lumps[LUMP_SURFACES], bspDrawSurfaces );
AddLump( file, header->lumps[LUMP_VISIBILITY], bspVisBytes ); AddLump( file, header->lumps[LUMP_VISIBILITY], bspVisBytes );
AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes ); AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes );
AddLightGridLumps( file, header ); AddLightGridLumps( file, header );

View File

@ -41,17 +41,17 @@
int numLightmapsASE = 0; int numLightmapsASE = 0;
static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const std::vector<int>& lmIndices ){ static void ConvertSurface( FILE *f, int modelNum, int surfaceNum, const Vector3& origin, const std::vector<int>& lmIndices ){
char name[ 1024 ]; char name[ 1024 ];
const bspDrawSurface_t& ds = bspDrawSurfaces[ surfaceNum ];
/* ignore patches for now */ /* ignore patches for now */
if ( ds->surfaceType != MST_PLANAR && ds->surfaceType != MST_TRIANGLE_SOUP ) { if ( ds.surfaceType != MST_PLANAR && ds.surfaceType != MST_TRIANGLE_SOUP ) {
return; return;
} }
/* print object header for each dsurf */ /* print object header for each dsurf */
sprintf( name, "mat%dmodel%dsurf%d", ds->shaderNum, modelNum, surfaceNum ); sprintf( name, "mat%dmodel%dsurf%d", ds.shaderNum, modelNum, surfaceNum );
fprintf( f, "*GEOMOBJECT\t{\r\n" ); fprintf( f, "*GEOMOBJECT\t{\r\n" );
fprintf( f, "\t*NODE_NAME\t\"%s\"\r\n", name ); fprintf( f, "\t*NODE_NAME\t\"%s\"\r\n", name );
fprintf( f, "\t*NODE_TM\t{\r\n" ); fprintf( f, "\t*NODE_TM\t{\r\n" );
@ -69,9 +69,9 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
/* print mesh header */ /* print mesh header */
fprintf( f, "\t*MESH\t{\r\n" ); fprintf( f, "\t*MESH\t{\r\n" );
fprintf( f, "\t\t*TIMEVALUE\t0\r\n" ); fprintf( f, "\t\t*TIMEVALUE\t0\r\n" );
fprintf( f, "\t\t*MESH_NUMVERTEX\t%d\r\n", ds->numVerts ); fprintf( f, "\t\t*MESH_NUMVERTEX\t%d\r\n", ds.numVerts );
fprintf( f, "\t\t*MESH_NUMFACES\t%d\r\n", ds->numIndexes / 3 ); fprintf( f, "\t\t*MESH_NUMFACES\t%d\r\n", ds.numIndexes / 3 );
switch ( ds->surfaceType ) switch ( ds.surfaceType )
{ {
case MST_PLANAR: case MST_PLANAR:
fprintf( f, "\t\t*COMMENT\t\"SURFACETYPE\tMST_PLANAR\"\r\n" ); fprintf( f, "\t\t*COMMENT\t\"SURFACETYPE\tMST_PLANAR\"\r\n" );
@ -83,32 +83,32 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
/* export vertex xyz */ /* export vertex xyz */
fprintf( f, "\t\t*MESH_VERTEX_LIST\t{\r\n" ); fprintf( f, "\t\t*MESH_VERTEX_LIST\t{\r\n" );
for ( int i = 0; i < ds->numVerts; i++ ) for ( int i = 0; i < ds.numVerts; i++ )
{ {
const bspDrawVert_t& dv = bspDrawVerts[ ds->firstVert + i ]; const bspDrawVert_t& dv = bspDrawVerts[ ds.firstVert + i ];
fprintf( f, "\t\t\t*MESH_VERTEX\t%d\t%f\t%f\t%f\r\n", i, dv.xyz[ 0 ], dv.xyz[ 1 ], dv.xyz[ 2 ] ); fprintf( f, "\t\t\t*MESH_VERTEX\t%d\t%f\t%f\t%f\r\n", i, dv.xyz[ 0 ], dv.xyz[ 1 ], dv.xyz[ 2 ] );
} }
fprintf( f, "\t\t}\r\n" ); fprintf( f, "\t\t}\r\n" );
/* export faces */ /* export faces */
fprintf( f, "\t\t*MESH_FACE_LIST\t{\r\n" ); fprintf( f, "\t\t*MESH_FACE_LIST\t{\r\n" );
for ( int i = 0; i < ds->numIndexes; i += 3 ) for ( int i = 0; i < ds.numIndexes; i += 3 )
{ {
const int face = ( i / 3 ); const int face = ( i / 3 );
const int a = bspDrawIndexes[ i + ds->firstIndex ]; const int a = bspDrawIndexes[ i + ds.firstIndex ];
const int c = bspDrawIndexes[ i + ds->firstIndex + 1 ]; const int c = bspDrawIndexes[ i + ds.firstIndex + 1 ];
const int b = bspDrawIndexes[ i + ds->firstIndex + 2 ]; const int b = bspDrawIndexes[ i + ds.firstIndex + 2 ];
fprintf( f, "\t\t\t*MESH_FACE\t%d\tA:\t%d\tB:\t%d\tC:\t%d\tAB:\t1\tBC:\t1\tCA:\t1\t*MESH_SMOOTHING\t0\t*MESH_MTLID\t0\r\n", fprintf( f, "\t\t\t*MESH_FACE\t%d\tA:\t%d\tB:\t%d\tC:\t%d\tAB:\t1\tBC:\t1\tCA:\t1\t*MESH_SMOOTHING\t0\t*MESH_MTLID\t0\r\n",
face, a, b, c ); face, a, b, c );
} }
fprintf( f, "\t\t}\r\n" ); fprintf( f, "\t\t}\r\n" );
/* export vertex st */ /* export vertex st */
fprintf( f, "\t\t*MESH_NUMTVERTEX\t%d\r\n", ds->numVerts ); fprintf( f, "\t\t*MESH_NUMTVERTEX\t%d\r\n", ds.numVerts );
fprintf( f, "\t\t*MESH_TVERTLIST\t{\r\n" ); fprintf( f, "\t\t*MESH_TVERTLIST\t{\r\n" );
for ( int i = 0; i < ds->numVerts; i++ ) for ( int i = 0; i < ds.numVerts; i++ )
{ {
const bspDrawVert_t& dv = bspDrawVerts[ ds->firstVert + i ]; const bspDrawVert_t& dv = bspDrawVerts[ ds.firstVert + i ];
if ( lightmapsAsTexcoord ) { if ( lightmapsAsTexcoord ) {
fprintf( f, "\t\t\t*MESH_TVERT\t%d\t%f\t%f\t%f\r\n", i, dv.lightmap[0][0], ( 1.0 - dv.lightmap[0][1] ), 1.0f ); // dv.lightmap[0][1] internal, ( 1.0 - dv.lightmap[0][1] ) external fprintf( f, "\t\t\t*MESH_TVERT\t%d\t%f\t%f\t%f\r\n", i, dv.lightmap[0][0], ( 1.0 - dv.lightmap[0][1] ), 1.0f ); // dv.lightmap[0][1] internal, ( 1.0 - dv.lightmap[0][1] ) external
} }
@ -119,26 +119,26 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
fprintf( f, "\t\t}\r\n" ); fprintf( f, "\t\t}\r\n" );
/* export texture faces */ /* export texture faces */
fprintf( f, "\t\t*MESH_NUMTVFACES\t%d\r\n", ds->numIndexes / 3 ); fprintf( f, "\t\t*MESH_NUMTVFACES\t%d\r\n", ds.numIndexes / 3 );
fprintf( f, "\t\t*MESH_TFACELIST\t{\r\n" ); fprintf( f, "\t\t*MESH_TFACELIST\t{\r\n" );
for ( int i = 0; i < ds->numIndexes; i += 3 ) for ( int i = 0; i < ds.numIndexes; i += 3 )
{ {
const int face = ( i / 3 ); const int face = ( i / 3 );
const int a = bspDrawIndexes[ i + ds->firstIndex ]; const int a = bspDrawIndexes[ i + ds.firstIndex ];
const int c = bspDrawIndexes[ i + ds->firstIndex + 1 ]; const int c = bspDrawIndexes[ i + ds.firstIndex + 1 ];
const int b = bspDrawIndexes[ i + ds->firstIndex + 2 ]; const int b = bspDrawIndexes[ i + ds.firstIndex + 2 ];
fprintf( f, "\t\t\t*MESH_TFACE\t%d\t%d\t%d\t%d\r\n", face, a, b, c ); fprintf( f, "\t\t\t*MESH_TFACE\t%d\t%d\t%d\t%d\r\n", face, a, b, c );
} }
fprintf( f, "\t\t}\r\n" ); fprintf( f, "\t\t}\r\n" );
/* export vertex normals */ /* export vertex normals */
fprintf( f, "\t\t*MESH_NORMALS\t{\r\n" ); fprintf( f, "\t\t*MESH_NORMALS\t{\r\n" );
for ( int i = 0; i < ds->numIndexes; i += 3 ) for ( int i = 0; i < ds.numIndexes; i += 3 )
{ {
const int face = ( i / 3 ); const int face = ( i / 3 );
const int a = bspDrawIndexes[ i + ds->firstIndex ]; const int a = bspDrawIndexes[ i + ds.firstIndex ];
const int b = bspDrawIndexes[ i + ds->firstIndex + 1 ]; const int b = bspDrawIndexes[ i + ds.firstIndex + 1 ];
const int c = bspDrawIndexes[ i + ds->firstIndex + 2 ]; const int c = bspDrawIndexes[ i + ds.firstIndex + 2 ];
const Vector3 normal = VectorNormalized( bspDrawVerts[ a ].normal + bspDrawVerts[ b ].normal + bspDrawVerts[ c ].normal ); const Vector3 normal = VectorNormalized( bspDrawVerts[ a ].normal + bspDrawVerts[ b ].normal + bspDrawVerts[ c ].normal );
fprintf( f, "\t\t\t*MESH_FACENORMAL\t%d\t%f\t%f\t%f\r\n", face, normal[ 0 ], normal[ 1 ], normal[ 2 ] ); fprintf( f, "\t\t\t*MESH_FACENORMAL\t%d\t%f\t%f\t%f\r\n", face, normal[ 0 ], normal[ 1 ], normal[ 2 ] );
for( const auto idx : { a, b, c } ){ for( const auto idx : { a, b, c } ){
@ -156,7 +156,7 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
fprintf( f, "\t*PROP_CASTSHADOW\t1\r\n" ); fprintf( f, "\t*PROP_CASTSHADOW\t1\r\n" );
fprintf( f, "\t*PROP_RECVSHADOW\t1\r\n" ); fprintf( f, "\t*PROP_RECVSHADOW\t1\r\n" );
if ( lightmapsAsTexcoord ) { if ( lightmapsAsTexcoord ) {
const int lmNum = ds->lightmapNum[0] >= 0? ds->lightmapNum[0]: lmIndices[ds->shaderNum] >= 0? lmIndices[ds->shaderNum] : ds->lightmapNum[0]; const int lmNum = ds.lightmapNum[0] >= 0? ds.lightmapNum[0]: lmIndices[ds.shaderNum] >= 0? lmIndices[ds.shaderNum] : ds.lightmapNum[0];
if ( lmNum >= 0 && lmNum + (int)deluxemap < numLightmapsASE ) { if ( lmNum >= 0 && lmNum + (int)deluxemap < numLightmapsASE ) {
fprintf( f, "\t*MATERIAL_REF\t%d\r\n", lmNum + deluxemap ); fprintf( f, "\t*MATERIAL_REF\t%d\r\n", lmNum + deluxemap );
} }
@ -165,7 +165,7 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
} }
} }
else{ else{
fprintf( f, "\t*MATERIAL_REF\t%d\r\n", ds->shaderNum ); fprintf( f, "\t*MATERIAL_REF\t%d\r\n", ds.shaderNum );
} }
fprintf( f, "}\r\n" ); fprintf( f, "}\r\n" );
} }
@ -183,8 +183,7 @@ static void ConvertModel( FILE *f, int modelNum, const Vector3& origin, const st
/* go through each drawsurf in the model */ /* go through each drawsurf in the model */
for ( int i = 0; i < model.numBSPSurfaces; i++ ) for ( int i = 0; i < model.numBSPSurfaces; i++ )
{ {
const int s = model.firstBSPSurface + i; ConvertSurface( f, modelNum, model.firstBSPSurface + i, origin, lmIndices );
ConvertSurface( f, modelNum, &bspDrawSurfaces[ s ], s, origin, lmIndices );
} }
} }

View File

@ -374,7 +374,6 @@ static void ExtrapolateTexcoords( const float *axyz, const float *ast,
*/ */
int ScaleBSPMain( Args& args ){ int ScaleBSPMain( Args& args ){
int i, j;
float f, a; float f, a;
Vector3 scale; Vector3 scale;
Vector3 vec; Vector3 vec;
@ -520,19 +519,19 @@ int ScaleBSPMain( Args& args ){
} }
if ( texscale ) { if ( texscale ) {
for ( i = 0; i < numBSPDrawSurfaces; i++ ) for ( const bspDrawSurface_t& surf : bspDrawSurfaces )
{ {
switch ( bspDrawSurfaces[i].surfaceType ) switch ( surf.surfaceType )
{ {
case MST_PLANAR: case MST_PLANAR:
if ( bspDrawSurfaces[i].numIndexes % 3 ) { if ( surf.numIndexes % 3 ) {
Error( "Not a triangulation!" ); Error( "Not a triangulation!" );
} }
for ( j = bspDrawSurfaces[i].firstIndex; j < bspDrawSurfaces[i].firstIndex + bspDrawSurfaces[i].numIndexes; j += 3 ) for ( int j = surf.firstIndex; j < surf.firstIndex + surf.numIndexes; j += 3 )
{ {
const int ia = bspDrawIndexes[j] + bspDrawSurfaces[i].firstVert, const int ia = bspDrawIndexes[j + 0] + surf.firstVert,
ib = bspDrawIndexes[j + 1] + bspDrawSurfaces[i].firstVert, ib = bspDrawIndexes[j + 1] + surf.firstVert,
ic = bspDrawIndexes[j + 2] + bspDrawSurfaces[i].firstVert; ic = bspDrawIndexes[j + 2] + surf.firstVert;
bspDrawVert_t &a = bspDrawVerts[ia], &b = bspDrawVerts[ib], &c = bspDrawVerts[ic]; bspDrawVert_t &a = bspDrawVerts[ia], &b = bspDrawVerts[ib], &c = bspDrawVerts[ic];
const float *oa = &old_xyzst[ia * 5], *ob = &old_xyzst[ib * 5], *oc = &old_xyzst[ic * 5]; const float *oa = &old_xyzst[ia * 5], *ob = &old_xyzst[ib * 5], *oc = &old_xyzst[ic * 5];
// extrapolate: // extrapolate:
@ -707,7 +706,6 @@ void PseudoCompileBSP( bool need_tree ){
facelist_t faces; facelist_t faces;
tree_t tree{}; tree_t tree{};
SetDrawSurfacesBuffer();
mapDrawSurfs = safe_calloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); mapDrawSurfs = safe_calloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
numMapDrawSurfs = 0; numMapDrawSurfs = 0;

View File

@ -274,7 +274,7 @@ static void write_json( const char *directory ){
} }
{ {
doc.RemoveAllMembers(); doc.RemoveAllMembers();
for_indexed( auto&& surf : Span( bspDrawSurfaces, numBSPDrawSurfaces ) ){ for_indexed( const auto& surf : bspDrawSurfaces ){
rapidjson::Value value( rapidjson::kObjectType ); rapidjson::Value value( rapidjson::kObjectType );
value.AddMember( "shaderNum", surf.shaderNum, all ); value.AddMember( "shaderNum", surf.shaderNum, all );
value.AddMember( "fogNum", surf.fogNum, all ); value.AddMember( "fogNum", surf.fogNum, all );
@ -477,9 +477,8 @@ static void read_json( const char *directory ){
} }
{ {
const auto doc = load_json( StringOutputStream( 256 )( directory, "DrawSurfaces.json" ) ); const auto doc = load_json( StringOutputStream( 256 )( directory, "DrawSurfaces.json" ) );
static std::vector<bspDrawSurface_t> items;
for( auto&& obj : doc.GetObj() ){ for( auto&& obj : doc.GetObj() ){
auto&& item = items.emplace_back(); auto&& item = bspDrawSurfaces.emplace_back();
item.shaderNum = obj.value["shaderNum"].GetInt(); item.shaderNum = obj.value["shaderNum"].GetInt();
item.fogNum = obj.value["fogNum"].GetInt(); item.fogNum = obj.value["fogNum"].GetInt();
item.surfaceType = obj.value["surfaceType"].GetInt(); item.surfaceType = obj.value["surfaceType"].GetInt();
@ -499,8 +498,6 @@ static void read_json( const char *directory ){
item.patchWidth = obj.value["patchWidth"].GetInt(); item.patchWidth = obj.value["patchWidth"].GetInt();
item.patchHeight = obj.value["patchHeight"].GetInt(); item.patchHeight = obj.value["patchHeight"].GetInt();
} }
bspDrawSurfaces = items.data();
numBSPDrawSurfaces = items.size();
} }
{ {
const auto doc = load_json( StringOutputStream( 256 )( directory, "fogs.json" ) ); const auto doc = load_json( StringOutputStream( 256 )( directory, "fogs.json" ) );

View File

@ -48,9 +48,6 @@ static float Det3x3( float a00, float a01, float a02,
} }
void GetBestSurfaceTriangleMatchForBrushside( const side_t& buildSide, const bspDrawVert_t *bestVert[3] ){ void GetBestSurfaceTriangleMatchForBrushside( const side_t& buildSide, const bspDrawVert_t *bestVert[3] ){
bspDrawSurface_t *s;
int i;
int t;
float best = 0; float best = 0;
float thisarea; float thisarea;
const bspDrawVert_t *vert[3]; const bspDrawVert_t *vert[3];
@ -61,20 +58,20 @@ void GetBestSurfaceTriangleMatchForBrushside( const side_t& buildSide, const bsp
bestVert[0] = bestVert[1] = bestVert[2] = NULL; bestVert[0] = bestVert[1] = bestVert[2] = NULL;
// brute force through all surfaces // brute force through all surfaces
for ( s = bspDrawSurfaces; s != bspDrawSurfaces + numBSPDrawSurfaces; ++s ) for ( const bspDrawSurface_t& s : bspDrawSurfaces )
{ {
if ( s->surfaceType != MST_PLANAR && s->surfaceType != MST_TRIANGLE_SOUP ) { if ( s.surfaceType != MST_PLANAR && s.surfaceType != MST_TRIANGLE_SOUP ) {
continue; continue;
} }
if ( !strEqual( buildSide.shaderInfo->shader, bspShaders[s->shaderNum].shader ) ) { if ( !strEqual( buildSide.shaderInfo->shader, bspShaders[s.shaderNum].shader ) ) {
continue; continue;
} }
for ( t = 0; t + 3 <= s->numIndexes; t += 3 ) for ( int t = 0; t + 3 <= s.numIndexes; t += 3 )
{ {
vert[0] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 0]]; vert[0] = &bspDrawVerts[s.firstVert + bspDrawIndexes[s.firstIndex + t + 0]];
vert[1] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 1]]; vert[1] = &bspDrawVerts[s.firstVert + bspDrawIndexes[s.firstIndex + t + 1]];
vert[2] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 2]]; vert[2] = &bspDrawVerts[s.firstVert + bspDrawIndexes[s.firstIndex + t + 2]];
if ( s->surfaceType == MST_PLANAR && VectorCompare( vert[0]->normal, vert[1]->normal ) && VectorCompare( vert[1]->normal, vert[2]->normal ) ) { if ( s.surfaceType == MST_PLANAR && VectorCompare( vert[0]->normal, vert[1]->normal ) && VectorCompare( vert[1]->normal, vert[2]->normal ) ) {
if ( vector3_length( vert[0]->normal - buildPlane.normal() ) >= normalEpsilon if ( vector3_length( vert[0]->normal - buildPlane.normal() ) >= normalEpsilon
|| vector3_length( vert[1]->normal - buildPlane.normal() ) >= normalEpsilon || vector3_length( vert[1]->normal - buildPlane.normal() ) >= normalEpsilon
|| vector3_length( vert[2]->normal - buildPlane.normal() ) >= normalEpsilon ) { || vector3_length( vert[2]->normal - buildPlane.normal() ) >= normalEpsilon ) {
@ -99,7 +96,7 @@ void GetBestSurfaceTriangleMatchForBrushside( const side_t& buildSide, const bsp
} }
// Okay. Correct surface type, correct shader, correct plane. Let's start with the business... // Okay. Correct surface type, correct shader, correct plane. Let's start with the business...
winding_t polygon( buildSide.winding ); winding_t polygon( buildSide.winding );
for ( i = 0; i < 3; ++i ) for ( int i = 0; i < 3; ++i )
{ {
// 0: 1, 2 // 0: 1, 2
// 1: 2, 0 // 1: 2, 0

View File

@ -44,14 +44,16 @@ int lastLightmap = -1;
int objVertexCount = 0; int objVertexCount = 0;
int objLastShaderNum = -1; int objLastShaderNum = -1;
static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const std::vector<int>& lmIndices ){ static void ConvertSurfaceToOBJ( FILE *f, int modelNum, int surfaceNum, const Vector3& origin, const std::vector<int>& lmIndices ){
const bspDrawSurface_t& ds = bspDrawSurfaces[ surfaceNum ];
/* ignore patches for now */ /* ignore patches for now */
if ( ds->surfaceType != MST_PLANAR && ds->surfaceType != MST_TRIANGLE_SOUP ) { if ( ds.surfaceType != MST_PLANAR && ds.surfaceType != MST_TRIANGLE_SOUP ) {
return; return;
} }
fprintf( f, "g mat%dmodel%dsurf%d\r\n", ds->shaderNum, modelNum, surfaceNum ); fprintf( f, "g mat%dmodel%dsurf%d\r\n", ds.shaderNum, modelNum, surfaceNum );
switch ( ds->surfaceType ) switch ( ds.surfaceType )
{ {
case MST_PLANAR: case MST_PLANAR:
fprintf( f, "# SURFACETYPE MST_PLANAR\r\n" ); fprintf( f, "# SURFACETYPE MST_PLANAR\r\n" );
@ -63,7 +65,7 @@ static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, in
/* export shader */ /* export shader */
if ( lightmapsAsTexcoord ) { if ( lightmapsAsTexcoord ) {
const int lmNum = ds->lightmapNum[0] >= 0? ds->lightmapNum[0]: lmIndices[ds->shaderNum] >= 0? lmIndices[ds->shaderNum] : ds->lightmapNum[0]; const int lmNum = ds.lightmapNum[0] >= 0? ds.lightmapNum[0]: lmIndices[ds.shaderNum] >= 0? lmIndices[ds.shaderNum] : ds.lightmapNum[0];
if ( objLastShaderNum != lmNum ) { if ( objLastShaderNum != lmNum ) {
fprintf( f, "usemtl lm_%04d\r\n", lmNum + deluxemap ); fprintf( f, "usemtl lm_%04d\r\n", lmNum + deluxemap );
objLastShaderNum = lmNum + deluxemap; objLastShaderNum = lmNum + deluxemap;
@ -79,16 +81,16 @@ static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, in
} }
else else
{ {
if ( objLastShaderNum != ds->shaderNum ) { if ( objLastShaderNum != ds.shaderNum ) {
fprintf( f, "usemtl %s\r\n", bspShaders[ds->shaderNum].shader ); fprintf( f, "usemtl %s\r\n", bspShaders[ds.shaderNum].shader );
objLastShaderNum = ds->shaderNum; objLastShaderNum = ds.shaderNum;
} }
} }
/* export vertex */ /* export vertex */
for ( int i = 0; i < ds->numVerts; i++ ) for ( int i = 0; i < ds.numVerts; i++ )
{ {
const bspDrawVert_t& dv = bspDrawVerts[ ds->firstVert + i ]; const bspDrawVert_t& dv = bspDrawVerts[ ds.firstVert + i ];
fprintf( f, "# vertex %d\r\n", i + objVertexCount + 1 ); fprintf( f, "# vertex %d\r\n", i + objVertexCount + 1 );
fprintf( f, "v %f %f %f\r\n", dv.xyz[ 0 ], dv.xyz[ 2 ], -dv.xyz[ 1 ] ); fprintf( f, "v %f %f %f\r\n", dv.xyz[ 0 ], dv.xyz[ 2 ], -dv.xyz[ 1 ] );
fprintf( f, "vn %f %f %f\r\n", dv.normal[ 0 ], dv.normal[ 2 ], -dv.normal[ 1 ] ); fprintf( f, "vn %f %f %f\r\n", dv.normal[ 0 ], dv.normal[ 2 ], -dv.normal[ 1 ] );
@ -101,11 +103,11 @@ static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, in
} }
/* export faces */ /* export faces */
for ( int i = 0; i < ds->numIndexes; i += 3 ) for ( int i = 0; i < ds.numIndexes; i += 3 )
{ {
const int a = bspDrawIndexes[ i + ds->firstIndex ]; const int a = bspDrawIndexes[ i + ds.firstIndex ];
const int c = bspDrawIndexes[ i + ds->firstIndex + 1 ]; const int c = bspDrawIndexes[ i + ds.firstIndex + 1 ];
const int b = bspDrawIndexes[ i + ds->firstIndex + 2 ]; const int b = bspDrawIndexes[ i + ds.firstIndex + 2 ];
fprintf( f, "f %d/%d/%d %d/%d/%d %d/%d/%d\r\n", fprintf( f, "f %d/%d/%d %d/%d/%d %d/%d/%d\r\n",
a + objVertexCount + 1, a + objVertexCount + 1, a + objVertexCount + 1, a + objVertexCount + 1, a + objVertexCount + 1, a + objVertexCount + 1,
b + objVertexCount + 1, b + objVertexCount + 1, b + objVertexCount + 1, b + objVertexCount + 1, b + objVertexCount + 1, b + objVertexCount + 1,
@ -113,7 +115,7 @@ static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, in
); );
} }
objVertexCount += ds->numVerts; objVertexCount += ds.numVerts;
} }
@ -129,8 +131,7 @@ static void ConvertModelToOBJ( FILE *f, int modelNum, const Vector3& origin, con
/* go through each drawsurf in the model */ /* go through each drawsurf in the model */
for ( int i = 0; i < model.numBSPSurfaces; i++ ) for ( int i = 0; i < model.numBSPSurfaces; i++ )
{ {
const int s = model.firstBSPSurface + i; ConvertSurfaceToOBJ( f, modelNum, model.firstBSPSurface + i, origin, lmIndices );
ConvertSurfaceToOBJ( f, modelNum, &bspDrawSurfaces[ s ], s, origin, lmIndices );
} }
} }

View File

@ -467,11 +467,6 @@ void CreateEntityLights( void ){
#define APPROX_BOUNCE 1.0f #define APPROX_BOUNCE 1.0f
void CreateSurfaceLights( void ){ void CreateSurfaceLights( void ){
int i;
bspDrawSurface_t *ds;
surfaceInfo_t *info;
shaderInfo_t *si;
float subdivide;
clipWork_t cw; clipWork_t cw;
@ -479,25 +474,25 @@ void CreateSurfaceLights( void ){
const bool nss = entities[ 0 ].boolForKey( "_noshadersun" ); const bool nss = entities[ 0 ].boolForKey( "_noshadersun" );
/* walk the list of surfaces */ /* walk the list of surfaces */
for ( i = 0; i < numBSPDrawSurfaces; i++ ) for ( size_t i = 0; i < bspDrawSurfaces.size(); i++ )
{ {
/* get surface and other bits */ /* get surface and other bits */
ds = &bspDrawSurfaces[ i ]; bspDrawSurface_t *ds = &bspDrawSurfaces[ i ];
info = &surfaceInfos[ i ]; surfaceInfo_t *info = &surfaceInfos[ i ];
si = info->si; const shaderInfo_t *si = info->si;
/* sunlight? */ /* sunlight? */
if ( si->sun != NULL && !nss ) { if ( si->sun != NULL && !nss ) {
Sys_FPrintf( SYS_VRB, "Sun: %s\n", si->shader.c_str() ); Sys_FPrintf( SYS_VRB, "Sun: %s\n", si->shader.c_str() );
CreateSunLight( si->sun ); CreateSunLight( si->sun );
si->sun = NULL; /* FIXME: leak! */ const_cast<shaderInfo_t*>( si )->sun = NULL; /* FIXME: leak! */
} }
/* sky light? */ /* sky light? */
if ( si->skyLightValue > 0.0f ) { if ( si->skyLightValue > 0.0f ) {
Sys_FPrintf( SYS_VRB, "Sky: %s\n", si->shader.c_str() ); Sys_FPrintf( SYS_VRB, "Sky: %s\n", si->shader.c_str() );
CreateSkyLights( si->color, si->skyLightValue, si->skyLightIterations, si->lightFilterRadius, si->lightStyle ); CreateSkyLights( si->color, si->skyLightValue, si->skyLightIterations, si->lightFilterRadius, si->lightStyle );
si->skyLightValue = 0.0f; /* FIXME: hack! */ const_cast<shaderInfo_t*>( si )->skyLightValue = 0.0f; /* FIXME: hack! */
} }
/* try to early out */ /* try to early out */
@ -527,12 +522,7 @@ void CreateSurfaceLights( void ){
} }
/* get subdivision amount */ /* get subdivision amount */
if ( si->lightSubdivide > 0 ) { const float subdivide = si->lightSubdivide > 0? si->lightSubdivide : defaultLightSubdivide;
subdivide = si->lightSubdivide;
}
else{
subdivide = defaultLightSubdivide;
}
/* switch on type */ /* switch on type */
switch ( ds->surfaceType ) switch ( ds->surfaceType )
@ -1819,7 +1809,7 @@ void LightWorld( bool fastAllocate ){
StitchSurfaceLightmaps(); StitchSurfaceLightmaps();
Sys_Printf( "--- IlluminateVertexes ---\n" ); Sys_Printf( "--- IlluminateVertexes ---\n" );
RunThreadsOnIndividual( numBSPDrawSurfaces, true, IlluminateVertexes ); RunThreadsOnIndividual( bspDrawSurfaces.size(), true, IlluminateVertexes );
Sys_Printf( "%9d vertexes illuminated\n", numVertsIlluminated ); Sys_Printf( "%9d vertexes illuminated\n", numVertsIlluminated );
/* ydnar: emit statistics on light culling */ /* ydnar: emit statistics on light culling */
@ -1886,7 +1876,7 @@ void LightWorld( bool fastAllocate ){
StitchSurfaceLightmaps(); StitchSurfaceLightmaps();
Sys_Printf( "--- IlluminateVertexes ---\n" ); Sys_Printf( "--- IlluminateVertexes ---\n" );
RunThreadsOnIndividual( numBSPDrawSurfaces, true, IlluminateVertexes ); RunThreadsOnIndividual( bspDrawSurfaces.size(), true, IlluminateVertexes );
Sys_Printf( "%9d vertexes illuminated\n", numVertsIlluminated ); Sys_Printf( "%9d vertexes illuminated\n", numVertsIlluminated );
/* ydnar: emit statistics on light culling */ /* ydnar: emit statistics on light culling */

View File

@ -165,7 +165,7 @@ float Modulo1IfNegative( float f ){
returns false if pixels are bad returns false if pixels are bad
*/ */
bool RadSampleImage( byte *pixels, int width, int height, const Vector2& st, Color4f& color ){ bool RadSampleImage( const byte *pixels, int width, int height, const Vector2& st, Color4f& color ){
int x, y; int x, y;
/* clear color first */ /* clear color first */
@ -207,7 +207,7 @@ bool RadSampleImage( byte *pixels, int width, int height, const Vector2& st, Col
#define MAX_SAMPLES 150 #define MAX_SAMPLES 150
#define SAMPLE_GRANULARITY 6 #define SAMPLE_GRANULARITY 6
static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, shaderInfo_t *si, radWinding_t *rw, Vector3& average, Vector3& gradient, int *style ){ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, const shaderInfo_t *si, radWinding_t *rw, Vector3& average, Vector3& gradient, int *style ){
int i, j, k, l, v, samples; int i, j, k, l, v, samples;
Vector3 color; Vector3 color;
MinMax minmax; MinMax minmax;
@ -359,7 +359,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, shaderInfo_t *si, static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, const shaderInfo_t *si,
float scale, float subdivide, radWinding_t *rw, clipWork_t *cw ){ float scale, float subdivide, radWinding_t *rw, clipWork_t *cw ){
int i, style = 0; int i, style = 0;
float dist, area, value; float dist, area, value;
@ -602,7 +602,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
creates unbounced diffuse lights for triangle soup (misc_models, etc) creates unbounced diffuse lights for triangle soup (misc_models, etc)
*/ */
void RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw ){ void RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, const shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw ){
int i, j, k, v; int i, j, k, v;
bspDrawSurface_t *ds; bspDrawSurface_t *ds;
radWinding_t rw; radWinding_t rw;
@ -646,7 +646,7 @@ void RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderIn
#define PLANAR_EPSILON 0.1f #define PLANAR_EPSILON 0.1f
void RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw ){ void RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, const shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw ){
int i, x, y, v, t, pw[ 5 ], r; int i, x, y, v, t, pw[ 5 ], r;
bspDrawSurface_t *ds; bspDrawSurface_t *ds;
surfaceInfo_t *info; surfaceInfo_t *info;
@ -791,7 +791,7 @@ void RadLight( int num ){
bspDrawSurface_t *ds; bspDrawSurface_t *ds;
surfaceInfo_t *info; surfaceInfo_t *info;
rawLightmap_t *lm; rawLightmap_t *lm;
shaderInfo_t *si; const shaderInfo_t *si;
clipWork_t cw; clipWork_t cw;
@ -869,7 +869,7 @@ void RadCreateDiffuseLights( void ){
numPatchDiffuseLights = 0; numPatchDiffuseLights = 0;
/* hit every surface (threaded) */ /* hit every surface (threaded) */
RunThreadsOnIndividual( numBSPDrawSurfaces, true, RadLight ); RunThreadsOnIndividual( bspDrawSurfaces.size(), true, RadLight );
/* dump the lights generated to a file */ /* dump the lights generated to a file */
if ( dump ) { if ( dump ) {

View File

@ -63,7 +63,7 @@ struct traceVert_t
struct traceInfo_t struct traceInfo_t
{ {
shaderInfo_t *si; const shaderInfo_t *si;
int surfaceNum, castShadows; int surfaceNum, castShadows;
bool skipGrid; bool skipGrid;
}; };
@ -1261,8 +1261,8 @@ bool TraceTriangle( traceInfo_t *ti, traceTriangle_t *tt, trace_t *trace ){
float det, invDet, depth; float det, invDet, depth;
float u, v, w, s, t; float u, v, w, s, t;
int is, it; int is, it;
byte *pixel; const byte *pixel;
shaderInfo_t *si; const shaderInfo_t *si;
/* don't double-trace against sky */ /* don't double-trace against sky */

View File

@ -157,7 +157,7 @@ Vector3b ColorToBytes( const Vector3& color, float scale ){
#define EQUAL_NORMAL_EPSILON 0.01f #define EQUAL_NORMAL_EPSILON 0.01f
void SmoothNormals( void ){ void SmoothNormals( void ){
int i, j, k, f, fOld, start; int fOld, start;
float shadeAngle, defaultShadeAngle, maxShadeAngle; float shadeAngle, defaultShadeAngle, maxShadeAngle;
int indexes[ MAX_SAMPLES ]; int indexes[ MAX_SAMPLES ];
Vector3 votes[ MAX_SAMPLES ]; Vector3 votes[ MAX_SAMPLES ];
@ -176,7 +176,7 @@ void SmoothNormals( void ){
/* run through every surface and flag verts belonging to non-lightmapped surfaces /* run through every surface and flag verts belonging to non-lightmapped surfaces
and set per-vertex smoothing angle */ and set per-vertex smoothing angle */
for ( i = 0; i < numBSPDrawSurfaces; i++ ) for ( size_t i = 0; i < bspDrawSurfaces.size(); ++i )
{ {
/* get drawsurf */ /* get drawsurf */
bspDrawSurface_t& ds = bspDrawSurfaces[ i ]; bspDrawSurface_t& ds = bspDrawSurfaces[ i ];
@ -192,9 +192,9 @@ void SmoothNormals( void ){
value_maximize( maxShadeAngle, shadeAngle ); value_maximize( maxShadeAngle, shadeAngle );
/* flag its verts */ /* flag its verts */
for ( j = 0; j < ds.numVerts; j++ ) for ( int j = 0; j < ds.numVerts; j++ )
{ {
f = ds.firstVert + j; const int f = ds.firstVert + j;
shadeAngles[ f ] = shadeAngle; shadeAngles[ f ] = shadeAngle;
if ( ds.surfaceType == MST_TRIANGLE_SOUP ) { if ( ds.surfaceType == MST_TRIANGLE_SOUP ) {
smoothed[ f ] = true; smoothed[ f ] = true;
@ -218,11 +218,10 @@ void SmoothNormals( void ){
start = I_FloatTime(); start = I_FloatTime();
/* go through the list of vertexes */ /* go through the list of vertexes */
for ( i = 0; i < numBSPDrawVerts; i++ ) for ( int i = 0; i < numBSPDrawVerts; i++ )
{ {
/* print pacifier */ /* print pacifier */
f = 10 * i / numBSPDrawVerts; if ( const int f = 10 * i / numBSPDrawVerts; f != fOld ) {
if ( f != fOld ) {
fOld = f; fOld = f;
Sys_Printf( "%i...", f ); Sys_Printf( "%i...", f );
} }
@ -238,7 +237,7 @@ void SmoothNormals( void ){
int numVotes = 0; int numVotes = 0;
/* build a table of coincident vertexes */ /* build a table of coincident vertexes */
for ( j = i; j < numBSPDrawVerts && numVerts < MAX_SAMPLES; j++ ) for ( int j = i; j < numBSPDrawVerts && numVerts < MAX_SAMPLES; j++ )
{ {
/* already smoothed? */ /* already smoothed? */
if ( smoothed[ j ] ) { if ( smoothed[ j ] ) {
@ -268,6 +267,7 @@ void SmoothNormals( void ){
smoothed[ j ] = true; smoothed[ j ] = true;
/* see if this normal has already been voted */ /* see if this normal has already been voted */
int k;
for ( k = 0; k < numVotes; k++ ) for ( k = 0; k < numVotes; k++ )
{ {
if ( vector3_equal_epsilon( bspDrawVerts[ j ].normal, votes[ k ], EQUAL_NORMAL_EPSILON ) ) { if ( vector3_equal_epsilon( bspDrawVerts[ j ].normal, votes[ k ], EQUAL_NORMAL_EPSILON ) ) {
@ -291,7 +291,7 @@ void SmoothNormals( void ){
/* average normal */ /* average normal */
if ( VectorNormalize( average ) != 0 ) { if ( VectorNormalize( average ) != 0 ) {
/* smooth */ /* smooth */
for ( j = 0; j < numVerts; j++ ) for ( int j = 0; j < numVerts; j++ )
yDrawVerts[ indexes[ j ] ].normal = average; yDrawVerts[ indexes[ j ] ].normal = average;
} }
} }
@ -375,7 +375,7 @@ static bool CalcTangentVectors( int numVerts, bspDrawVert_t **dv, Vector3 *stv,
perterbs the normal by the shader's normalmap in tangent space perterbs the normal by the shader's normalmap in tangent space
*/ */
static void PerturbNormal( bspDrawVert_t *dv, shaderInfo_t *si, Vector3& pNormal, const Vector3 stv[ 3 ], const Vector3 ttv[ 3 ] ){ static void PerturbNormal( bspDrawVert_t *dv, const shaderInfo_t *si, Vector3& pNormal, const Vector3 stv[ 3 ], const Vector3 ttv[ 3 ] ){
/* passthrough */ /* passthrough */
pNormal = dv->normal; pNormal = dv->normal;
@ -408,7 +408,7 @@ static void PerturbNormal( bspDrawVert_t *dv, shaderInfo_t *si, Vector3& pNormal
static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv, const Plane3f* plane, float pass, const Vector3 stv[ 3 ], const Vector3 ttv[ 3 ], const Vector3 worldverts[ 3 ] ){ static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv, const Plane3f* plane, float pass, const Vector3 stv[ 3 ], const Vector3 ttv[ 3 ], const Vector3 worldverts[ 3 ] ){
int i, numClusters, *clusters, pointCluster; int i, numClusters, *clusters, pointCluster;
float lightmapSampleOffset; float lightmapSampleOffset;
shaderInfo_t *si; const shaderInfo_t *si;
Vector3 pNormal; Vector3 pNormal;
Vector3 vecs[ 3 ]; Vector3 vecs[ 3 ];
Vector3 nudged; Vector3 nudged;
@ -3676,35 +3676,29 @@ void FreeTraceLights( trace_t *trace ){
*/ */
void CreateTraceLightsForSurface( int num, trace_t *trace ){ void CreateTraceLightsForSurface( int num, trace_t *trace ){
int i;
bspDrawVert_t *dv;
bspDrawSurface_t *ds;
surfaceInfo_t *info;
/* dummy check */ /* dummy check */
if ( num < 0 ) { if ( num < 0 ) {
return; return;
} }
/* get drawsurface and info */ /* get drawsurface and info */
ds = &bspDrawSurfaces[ num ]; const bspDrawSurface_t& ds = bspDrawSurfaces[ num ];
info = &surfaceInfos[ num ]; const surfaceInfo_t& info = surfaceInfos[ num ];
/* get the mins/maxs for the dsurf */ /* get the mins/maxs for the dsurf */
MinMax minmax; MinMax minmax;
Vector3 normal = bspDrawVerts[ ds->firstVert ].normal; Vector3 normal = bspDrawVerts[ ds.firstVert ].normal;
for ( i = 0; i < ds->numVerts; i++ ) for ( int i = 0; i < ds.numVerts; i++ )
{ {
dv = &yDrawVerts[ ds->firstVert + i ]; const bspDrawVert_t& dv = yDrawVerts[ ds.firstVert + i ];
minmax.extend( dv->xyz ); minmax.extend( dv.xyz );
if ( !VectorCompare( dv->normal, normal ) ) { if ( !VectorCompare( dv.normal, normal ) ) {
normal.set( 0 ); normal.set( 0 );
} }
} }
/* create the lights for the bounding box */ /* create the lights for the bounding box */
CreateTraceLightsForBounds( minmax, &normal, info->numSurfaceClusters, &surfaceClusters[ info->firstSurfaceCluster ], LightFlags::Surfaces, trace ); CreateTraceLightsForBounds( minmax, &normal, info.numSurfaceClusters, &surfaceClusters[ info.firstSurfaceCluster ], LightFlags::Surfaces, trace );
} }
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////

View File

@ -930,6 +930,7 @@ void SetupSurfaceLightmaps( void ){
surfaceInfo_t *info, *info2; surfaceInfo_t *info, *info2;
rawLightmap_t *lm; rawLightmap_t *lm;
bool added; bool added;
const int numBSPDrawSurfaces = bspDrawSurfaces.size();
/* note it */ /* note it */
@ -1068,7 +1069,6 @@ void SetupSurfaceLightmaps( void ){
{ {
/* get info and attempt early out */ /* get info and attempt early out */
num = sortSurfaces[ i ]; num = sortSurfaces[ i ];
ds = &bspDrawSurfaces[ num ];
info = &surfaceInfos[ num ]; info = &surfaceInfos[ num ];
if ( !info->hasLightmap || info->lm != NULL || info->parentSurfaceNum >= 0 ) { if ( !info->hasLightmap || info->lm != NULL || info->parentSurfaceNum >= 0 ) {
continue; continue;
@ -2343,7 +2343,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){
outLightmap_t *olm; outLightmap_t *olm;
bspDrawVert_t *dv, *ydv, *dvParent; bspDrawVert_t *dv, *ydv, *dvParent;
char dirname[ 1024 ], filename[ 1024 ]; char dirname[ 1024 ], filename[ 1024 ];
shaderInfo_t *csi; const shaderInfo_t *csi;
char lightmapName[ 128 ]; char lightmapName[ 128 ];
const char *rgbGenValues[ 256 ] = {0}; const char *rgbGenValues[ 256 ] = {0};
const char *alphaGenValues[ 256 ] = {0}; const char *alphaGenValues[ 256 ] = {0};
@ -3064,7 +3064,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){
timer_start = I_FloatTime(); timer_start = I_FloatTime();
/* walk the list of surfaces */ /* walk the list of surfaces */
for ( i = 0; i < numBSPDrawSurfaces; i++ ) for ( size_t i = 0; i < bspDrawSurfaces.size(); ++i )
{ {
/* get the surface and info */ /* get the surface and info */
ds = &bspDrawSurfaces[ i ]; ds = &bspDrawSurfaces[ i ];

View File

@ -47,7 +47,6 @@
static void ExitQ3Map( void ){ static void ExitQ3Map( void ){
/* flush xml send buffer, shut down connection */ /* flush xml send buffer, shut down connection */
Broadcast_Shutdown(); Broadcast_Shutdown();
BSPFilesCleanup();
free( mapDrawSurfs ); free( mapDrawSurfs );
} }

View File

@ -1142,7 +1142,7 @@ struct light_t
{ {
ELightType type; ELightType type;
LightFlags flags; /* ydnar: condensed all the booleans into one flags int */ LightFlags flags; /* ydnar: condensed all the booleans into one flags int */
shaderInfo_t *si; const shaderInfo_t *si;
Vector3 origin{ 0 }; Vector3 origin{ 0 };
Vector3 normal{ 0 }; /* for surfaces, spotlights, and suns */ Vector3 normal{ 0 }; /* for surfaces, spotlights, and suns */
@ -1247,7 +1247,7 @@ struct outLightmap_t
int numLightmaps; int numLightmaps;
int freeLuxels; int freeLuxels;
int numShaders; int numShaders;
shaderInfo_t *shaders[ MAX_LIGHTMAP_SHADERS ]; const shaderInfo_t *shaders[ MAX_LIGHTMAP_SHADERS ];
byte *lightBits; byte *lightBits;
Vector3b *bspLightBytes; Vector3b *bspLightBytes;
Vector3b *bspDirBytes; Vector3b *bspDirBytes;
@ -1391,7 +1391,7 @@ struct rawGridPoint_t
struct surfaceInfo_t struct surfaceInfo_t
{ {
int modelindex; int modelindex;
shaderInfo_t *si; const shaderInfo_t *si;
rawLightmap_t *lm; rawLightmap_t *lm;
int parentSurfaceNum, childSurfaceNum; int parentSurfaceNum, childSurfaceNum;
int entityNum, castShadows, recvShadows, sampleSize, patchIterations; int entityNum, castShadows, recvShadows, sampleSize, patchIterations;
@ -1705,9 +1705,9 @@ void EmitMetaStats(); // vortex: print meta statistics ev
/* surface_extra.c */ /* surface_extra.c */
void SetDefaultSampleSize( int sampleSize ); void SetDefaultSampleSize( int sampleSize );
void SetSurfaceExtra( mapDrawSurface_t *ds, int num ); void SetSurfaceExtra( const mapDrawSurface_t& ds );
shaderInfo_t *GetSurfaceExtraShaderInfo( int num ); const shaderInfo_t *GetSurfaceExtraShaderInfo( int num );
int GetSurfaceExtraParentSurfaceNum( int num ); int GetSurfaceExtraParentSurfaceNum( int num );
int GetSurfaceExtraEntityNum( int num ); int GetSurfaceExtraEntityNum( int num );
int GetSurfaceExtraCastShadows( int num ); int GetSurfaceExtraCastShadows( int num );
@ -1759,9 +1759,9 @@ float SetupTrace( trace_t *trace );
/* light_bounce.c */ /* light_bounce.c */
bool RadSampleImage( byte * pixels, int width, int height, const Vector2& st, Color4f& color ); bool RadSampleImage( const byte * pixels, int width, int height, const Vector2& st, Color4f& color );
void RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw ); void RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, const shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
void RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw ); void RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, const shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
void RadCreateDiffuseLights( void ); void RadCreateDiffuseLights( void );
@ -1835,7 +1835,7 @@ bool ApplySurfaceParm( const char *name, int *contentFlag
void BeginMapShaderFile( const char *mapFile ); void BeginMapShaderFile( const char *mapFile );
void WriteMapShaderFile( void ); void WriteMapShaderFile( void );
shaderInfo_t *CustomShader( shaderInfo_t *si, const char *find, char *replace ); const shaderInfo_t *CustomShader( const shaderInfo_t *si, const char *find, char *replace );
void EmitVertexRemapShader( char *from, char *to ); void EmitVertexRemapShader( char *from, char *to );
void LoadShaderInfo( void ); void LoadShaderInfo( void );
@ -1844,11 +1844,6 @@ shaderInfo_t *ShaderInfoForShaderNull( const char *shader );
/* bspfile_abstract.c */ /* bspfile_abstract.c */
void SetGridPoints( int n );
void SetDrawSurfaces( int n );
void SetDrawSurfacesBuffer();
void BSPFilesCleanup();
void SwapBlock( int *block, int size ); void SwapBlock( int *block, int size );
int GetLumpElements( bspHeader_t *header, int lump, int size ); int GetLumpElements( bspHeader_t *header, int lump, int size );
@ -2362,8 +2357,7 @@ Q_EXTERN std::vector<bspDrawVert_t> bspDrawVerts;
Q_EXTERN std::vector<int> bspDrawIndexes; Q_EXTERN std::vector<int> bspDrawIndexes;
Q_EXTERN int numBSPDrawSurfaces Q_ASSIGN( 0 ); Q_EXTERN std::vector<bspDrawSurface_t> bspDrawSurfaces; // MAX_MAP_DRAW_SURFS
Q_EXTERN bspDrawSurface_t *bspDrawSurfaces Q_ASSIGN( NULL );
Q_EXTERN int numBSPFogs Q_ASSIGN( 0 ); Q_EXTERN int numBSPFogs Q_ASSIGN( 0 );
Q_EXTERN bspFog_t bspFogs[ MAX_MAP_FOGS ]; Q_EXTERN bspFog_t bspFogs[ MAX_MAP_FOGS ];

View File

@ -386,7 +386,7 @@ void WriteMapShaderFile( void ){
sets up a custom map shader sets up a custom map shader
*/ */
shaderInfo_t *CustomShader( shaderInfo_t *si, const char *find, char *replace ){ const shaderInfo_t *CustomShader( const shaderInfo_t *si, const char *find, char *replace ){
shaderInfo_t *csi; shaderInfo_t *csi;
char shader[ MAX_QPATH ]; char shader[ MAX_QPATH ];
char *s; char *s;

View File

@ -1633,6 +1633,7 @@ void ClipSidesIntoTree( entity_t *e, const tree_t& tree ){
int AddReferenceToLeaf( mapDrawSurface_t *ds, node_t *node ){ int AddReferenceToLeaf( mapDrawSurface_t *ds, node_t *node ){
drawSurfRef_t *dsr; drawSurfRef_t *dsr;
const int numBSPDrawSurfaces = bspDrawSurfaces.size();
/* dummy check */ /* dummy check */
@ -2035,13 +2036,13 @@ static int FilterFlareSurfIntoTree( mapDrawSurface_t *ds, tree_t& tree ){
emits bsp drawverts from a map drawsurface emits bsp drawverts from a map drawsurface
*/ */
void EmitDrawVerts( const mapDrawSurface_t *ds, bspDrawSurface_t *out ){ void EmitDrawVerts( const mapDrawSurface_t *ds, bspDrawSurface_t& out ){
/* get stuff */ /* get stuff */
const float offset = ds->shaderInfo->offset; const float offset = ds->shaderInfo->offset;
/* copy the verts */ /* copy the verts */
out->firstVert = bspDrawVerts.size(); out.firstVert = bspDrawVerts.size();
out->numVerts = ds->numVerts; out.numVerts = ds->numVerts;
for ( int i = 0; i < ds->numVerts; i++ ) for ( int i = 0; i < ds->numVerts; i++ )
{ {
/* allocate a new vert */ /* copy it */ /* allocate a new vert */ /* copy it */
@ -2145,11 +2146,11 @@ int FindDrawIndexes( int numIndexes, const int *indexes ){
attempts to find an existing run of drawindexes before adding new ones attempts to find an existing run of drawindexes before adding new ones
*/ */
void EmitDrawIndexes( const mapDrawSurface_t *ds, bspDrawSurface_t *out ){ void EmitDrawIndexes( const mapDrawSurface_t *ds, bspDrawSurface_t& out ){
/* attempt to use redundant indexing */ /* attempt to use redundant indexing */
out->firstIndex = FindDrawIndexes( ds->numIndexes, ds->indexes ); out.firstIndex = FindDrawIndexes( ds->numIndexes, ds->indexes );
out->numIndexes = ds->numIndexes; out.numIndexes = ds->numIndexes;
if ( out->firstIndex == int( bspDrawIndexes.size() ) ) { if ( out.firstIndex == int( bspDrawIndexes.size() ) ) {
/* copy new unique indexes */ /* copy new unique indexes */
for ( int i = 0; i < ds->numIndexes; i++ ) for ( int i = 0; i < ds->numIndexes; i++ )
{ {
@ -2158,8 +2159,8 @@ void EmitDrawIndexes( const mapDrawSurface_t *ds, bspDrawSurface_t *out ){
/* validate the index */ /* validate the index */
if ( ds->type != ESurfaceType::Patch ) { if ( ds->type != ESurfaceType::Patch ) {
if ( index < 0 || index >= ds->numVerts ) { if ( index < 0 || index >= ds->numVerts ) {
Sys_Warning( "%d %s has invalid index %d (%d)\n", Sys_Warning( "%zu %s has invalid index %d (%d)\n",
numBSPDrawSurfaces, bspDrawSurfaces.size() - 1,
ds->shaderInfo->shader.c_str(), ds->shaderInfo->shader.c_str(),
index, index,
i ); i );
@ -2179,45 +2180,34 @@ void EmitDrawIndexes( const mapDrawSurface_t *ds, bspDrawSurface_t *out ){
*/ */
void EmitFlareSurface( mapDrawSurface_t *ds ){ void EmitFlareSurface( mapDrawSurface_t *ds ){
int i;
bspDrawSurface_t *out;
/* ydnar: nuking useless flare drawsurfaces */ /* ydnar: nuking useless flare drawsurfaces */
if ( !emitFlares && ds->type != ESurfaceType::Shader ) { if ( !emitFlares && ds->type != ESurfaceType::Shader ) {
return; return;
} }
/* limit check */
if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) {
Error( "MAX_MAP_DRAW_SURFS" );
}
/* allocate a new surface */ /* allocate a new surface */
out = &bspDrawSurfaces[ numBSPDrawSurfaces ]; bspDrawSurface_t& out = bspDrawSurfaces.emplace_back();
ds->outputNum = numBSPDrawSurfaces; ds->outputNum = bspDrawSurfaces.size() - 1;
numBSPDrawSurfaces++;
memset( out, 0, sizeof( *out ) );
/* set it up */ /* set it up */
out->surfaceType = MST_FLARE; out.surfaceType = MST_FLARE;
out->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags ); out.shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
out->fogNum = ds->fogNum; out.fogNum = ds->fogNum;
/* RBSP */ /* RBSP */
for ( i = 0; i < MAX_LIGHTMAPS; i++ ) for ( int i = 0; i < MAX_LIGHTMAPS; i++ )
{ {
out->lightmapNum[ i ] = -3; out.lightmapNum[ i ] = -3;
out->lightmapStyles[ i ] = LS_NONE; out.lightmapStyles[ i ] = LS_NONE;
out->vertexStyles[ i ] = LS_NONE; out.vertexStyles[ i ] = LS_NONE;
} }
out->lightmapStyles[ 0 ] = ds->lightStyle; out.lightmapStyles[ 0 ] = ds->lightStyle;
out->vertexStyles[ 0 ] = ds->lightStyle; out.vertexStyles[ 0 ] = ds->lightStyle;
out->lightmapOrigin = ds->lightmapOrigin; /* origin */ out.lightmapOrigin = ds->lightmapOrigin; /* origin */
out->lightmapVecs[ 0 ] = ds->lightmapVecs[ 0 ]; /* color */ out.lightmapVecs[ 0 ] = ds->lightmapVecs[ 0 ]; /* color */
out->lightmapVecs[ 1 ] = ds->lightmapVecs[ 1 ]; out.lightmapVecs[ 1 ] = ds->lightmapVecs[ 1 ];
out->lightmapVecs[ 2 ] = ds->lightmapVecs[ 2 ]; /* normal */ out.lightmapVecs[ 2 ] = ds->lightmapVecs[ 2 ]; /* normal */
/* add to count */ /* add to count */
numSurfacesByType[ static_cast<std::size_t>( ds->type ) ]++; numSurfacesByType[ static_cast<std::size_t>( ds->type ) ]++;
@ -2230,7 +2220,6 @@ void EmitFlareSurface( mapDrawSurface_t *ds ){
void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
int i, j; int i, j;
bspDrawSurface_t *out;
int surfaceFlags, contentFlags; int surfaceFlags, contentFlags;
/* vortex: _patchMeta support */ /* vortex: _patchMeta support */
@ -2262,18 +2251,13 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
} }
/* allocate a new surface */ /* allocate a new surface */
if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) { bspDrawSurface_t& out = bspDrawSurfaces.emplace_back();
Error( "MAX_MAP_DRAW_SURFS" ); ds->outputNum = bspDrawSurfaces.size() - 1;
}
out = &bspDrawSurfaces[ numBSPDrawSurfaces ];
ds->outputNum = numBSPDrawSurfaces;
numBSPDrawSurfaces++;
memset( out, 0, sizeof( *out ) );
/* set it up */ /* set it up */
out->surfaceType = MST_PATCH; out.surfaceType = MST_PATCH;
if ( debugSurfaces ) { if ( debugSurfaces ) {
out->shaderNum = EmitShader( "debugsurfaces", NULL, NULL ); out.shaderNum = EmitShader( "debugsurfaces", NULL, NULL );
} }
else if ( patchMeta || forcePatchMeta ) { else if ( patchMeta || forcePatchMeta ) {
/* patch meta requires that we have nodraw patches for collision */ /* patch meta requires that we have nodraw patches for collision */
@ -2288,34 +2272,34 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
ds->sampleSize = 0; ds->sampleSize = 0;
/* emit the new fake shader */ /* emit the new fake shader */
out->shaderNum = EmitShader( ds->shaderInfo->shader, &contentFlags, &surfaceFlags ); out.shaderNum = EmitShader( ds->shaderInfo->shader, &contentFlags, &surfaceFlags );
} }
else{ else{
out->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags ); out.shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
} }
out->patchWidth = ds->patchWidth; out.patchWidth = ds->patchWidth;
out->patchHeight = ds->patchHeight; out.patchHeight = ds->patchHeight;
out->fogNum = ds->fogNum; out.fogNum = ds->fogNum;
/* RBSP */ /* RBSP */
for ( i = 0; i < MAX_LIGHTMAPS; i++ ) for ( i = 0; i < MAX_LIGHTMAPS; i++ )
{ {
out->lightmapNum[ i ] = -3; out.lightmapNum[ i ] = -3;
out->lightmapStyles[ i ] = LS_NONE; out.lightmapStyles[ i ] = LS_NONE;
out->vertexStyles[ i ] = LS_NONE; out.vertexStyles[ i ] = LS_NONE;
} }
out->lightmapStyles[ 0 ] = LS_NORMAL; out.lightmapStyles[ 0 ] = LS_NORMAL;
out->vertexStyles[ 0 ] = LS_NORMAL; out.vertexStyles[ 0 ] = LS_NORMAL;
/* ydnar: gs mods: previously, the lod bounds were stored in lightmapVecs[ 0 ] and [ 1 ], moved to bounds[ 0 ] and [ 1 ] */ /* ydnar: gs mods: previously, the lod bounds were stored in lightmapVecs[ 0 ] and [ 1 ], moved to bounds[ 0 ] and [ 1 ] */
out->lightmapOrigin = ds->lightmapOrigin; out.lightmapOrigin = ds->lightmapOrigin;
out->lightmapVecs[ 0 ] = ds->bounds.mins; out.lightmapVecs[ 0 ] = ds->bounds.mins;
out->lightmapVecs[ 1 ] = ds->bounds.maxs; out.lightmapVecs[ 1 ] = ds->bounds.maxs;
out->lightmapVecs[ 2 ] = ds->lightmapVecs[ 2 ]; out.lightmapVecs[ 2 ] = ds->lightmapVecs[ 2 ];
/* ydnar: gs mods: clear out the plane normal */ /* ydnar: gs mods: clear out the plane normal */
if ( !ds->planar ) { if ( !ds->planar ) {
out->lightmapVecs[ 2 ].set( 0 ); out.lightmapVecs[ 2 ].set( 0 );
} }
/* emit the verts and indexes */ /* emit the verts and indexes */
@ -2452,7 +2436,6 @@ static void OptimizeTriangleSurface( mapDrawSurface_t *ds ){
void EmitTriangleSurface( mapDrawSurface_t *ds ){ void EmitTriangleSurface( mapDrawSurface_t *ds ){
int i, temp; int i, temp;
bspDrawSurface_t *out;
/* invert the surface if necessary */ /* invert the surface if necessary */
if ( ds->backSide || ds->shaderInfo->invert ) { if ( ds->backSide || ds->shaderInfo->invert ) {
@ -2473,17 +2456,12 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
} }
/* allocate a new surface */ /* allocate a new surface */
if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) { bspDrawSurface_t& out = bspDrawSurfaces.emplace_back();
Error( "MAX_MAP_DRAW_SURFS" ); ds->outputNum = bspDrawSurfaces.size() - 1;
}
out = &bspDrawSurfaces[ numBSPDrawSurfaces ];
ds->outputNum = numBSPDrawSurfaces;
numBSPDrawSurfaces++;
memset( out, 0, sizeof( *out ) );
/* ydnar/sd: handle wolf et foliage surfaces */ /* ydnar/sd: handle wolf et foliage surfaces */
if ( ds->type == ESurfaceType::Foliage ) { if ( ds->type == ESurfaceType::Foliage ) {
out->surfaceType = MST_FOLIAGE; out.surfaceType = MST_FOLIAGE;
} }
/* ydnar: gs mods: handle lightmapped terrain (force to planar type) */ /* ydnar: gs mods: handle lightmapped terrain (force to planar type) */
@ -2493,24 +2471,24 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
ds->type == ESurfaceType::Foghull || ds->type == ESurfaceType::Foghull ||
ds->numVerts > maxLMSurfaceVerts || ds->numVerts > maxLMSurfaceVerts ||
debugSurfaces ) { debugSurfaces ) {
out->surfaceType = MST_TRIANGLE_SOUP; out.surfaceType = MST_TRIANGLE_SOUP;
} }
/* set to a planar face */ /* set to a planar face */
else{ else{
out->surfaceType = MST_PLANAR; out.surfaceType = MST_PLANAR;
} }
/* set it up */ /* set it up */
if ( debugSurfaces ) { if ( debugSurfaces ) {
out->shaderNum = EmitShader( "debugsurfaces", NULL, NULL ); out.shaderNum = EmitShader( "debugsurfaces", NULL, NULL );
} }
else{ else{
out->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags ); out.shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
} }
out->patchWidth = ds->patchWidth; out.patchWidth = ds->patchWidth;
out->patchHeight = ds->patchHeight; out.patchHeight = ds->patchHeight;
out->fogNum = ds->fogNum; out.fogNum = ds->fogNum;
/* debug inset (push each triangle vertex towards the center of each triangle it is on */ /* debug inset (push each triangle vertex towards the center of each triangle it is on */
if ( debugInset ) { if ( debugInset ) {
@ -2537,22 +2515,22 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
/* RBSP */ /* RBSP */
for ( i = 0; i < MAX_LIGHTMAPS; i++ ) for ( i = 0; i < MAX_LIGHTMAPS; i++ )
{ {
out->lightmapNum[ i ] = -3; out.lightmapNum[ i ] = -3;
out->lightmapStyles[ i ] = LS_NONE; out.lightmapStyles[ i ] = LS_NONE;
out->vertexStyles[ i ] = LS_NONE; out.vertexStyles[ i ] = LS_NONE;
} }
out->lightmapStyles[ 0 ] = LS_NORMAL; out.lightmapStyles[ 0 ] = LS_NORMAL;
out->vertexStyles[ 0 ] = LS_NORMAL; out.vertexStyles[ 0 ] = LS_NORMAL;
/* lightmap vectors (lod bounds for patches */ /* lightmap vectors (lod bounds for patches */
out->lightmapOrigin = ds->lightmapOrigin; out.lightmapOrigin = ds->lightmapOrigin;
out->lightmapVecs[ 0 ] = ds->lightmapVecs[ 0 ]; out.lightmapVecs[ 0 ] = ds->lightmapVecs[ 0 ];
out->lightmapVecs[ 1 ] = ds->lightmapVecs[ 1 ]; out.lightmapVecs[ 1 ] = ds->lightmapVecs[ 1 ];
out->lightmapVecs[ 2 ] = ds->lightmapVecs[ 2 ]; out.lightmapVecs[ 2 ] = ds->lightmapVecs[ 2 ];
/* ydnar: gs mods: clear out the plane normal */ /* ydnar: gs mods: clear out the plane normal */
if ( !ds->planar ) { if ( !ds->planar ) {
out->lightmapVecs[ 2 ].set( 0 ); out.lightmapVecs[ 2 ].set( 0 );
} }
/* optimize the surface's triangles */ /* optimize the surface's triangles */
@ -3302,18 +3280,17 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t& tree ){
numRefs += refs; numRefs += refs;
/* emit extra surface data */ /* emit extra surface data */
SetSurfaceExtra( ds, numBSPDrawSurfaces - 1 ); SetSurfaceExtra( *ds );
//% Sys_FPrintf( SYS_VRB, "%d verts %d indexes\n", ds->numVerts, ds->numIndexes ); //% Sys_FPrintf( SYS_VRB, "%d verts %d indexes\n", ds->numVerts, ds->numIndexes );
/* one last sanity check */ /* one last sanity check */
{ {
bspDrawSurface_t *out; const bspDrawSurface_t& out = bspDrawSurfaces.back();
out = &bspDrawSurfaces[ numBSPDrawSurfaces - 1 ]; if ( out.numVerts == 3 && out.numIndexes > 3 ) {
if ( out->numVerts == 3 && out->numIndexes > 3 ) {
Sys_Printf( "\n" ); Sys_Printf( "\n" );
Sys_Warning( "Potentially bad %s surface (%d: %d, %d)\n %s\n", Sys_Warning( "Potentially bad %s surface (%zu: %d, %d)\n %s\n",
surfaceTypeName( ds->type ), surfaceTypeName( ds->type ),
numBSPDrawSurfaces - 1, out->numVerts, out->numIndexes, si->shader.c_str() ); bspDrawSurfaces.size(), out.numVerts, out.numIndexes, si->shader.c_str() );
} }
} }
@ -3327,7 +3304,7 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t& tree ){
/* emit some statistics */ /* emit some statistics */
Sys_FPrintf( SYS_VRB, "%9d references\n", numRefs ); Sys_FPrintf( SYS_VRB, "%9d references\n", numRefs );
Sys_FPrintf( SYS_VRB, "%9d (%d) emitted drawsurfs\n", numSurfs, numBSPDrawSurfaces ); Sys_FPrintf( SYS_VRB, "%9d (%zu) emitted drawsurfs\n", numSurfs, bspDrawSurfaces.size() );
Sys_FPrintf( SYS_VRB, "%9d stripped face surfaces\n", numStripSurfaces ); Sys_FPrintf( SYS_VRB, "%9d stripped face surfaces\n", numStripSurfaces );
Sys_FPrintf( SYS_VRB, "%9d fanned face surfaces\n", numFanSurfaces ); Sys_FPrintf( SYS_VRB, "%9d fanned face surfaces\n", numFanSurfaces );
Sys_FPrintf( SYS_VRB, "%9d maxarea'd face surfaces\n", numMaxAreaSurfaces ); Sys_FPrintf( SYS_VRB, "%9d maxarea'd face surfaces\n", numMaxAreaSurfaces );

View File

@ -41,8 +41,8 @@
struct surfaceExtra_t struct surfaceExtra_t
{ {
mapDrawSurface_t *mds; const mapDrawSurface_t *mds;
shaderInfo_t *si; const shaderInfo_t *si;
int parentSurfaceNum; int parentSurfaceNum;
int entityNum; int entityNum;
int castShadows, recvShadows; int castShadows, recvShadows;
@ -96,31 +96,23 @@ void SetDefaultSampleSize( int sampleSize ){
stores extra (q3map2) data for the specific numbered drawsurface stores extra (q3map2) data for the specific numbered drawsurface
*/ */
void SetSurfaceExtra( mapDrawSurface_t *ds, int num ){ void SetSurfaceExtra( const mapDrawSurface_t& ds ){
surfaceExtra_t *se;
/* dummy check */
if ( ds == NULL || num < 0 ) {
return;
}
/* get a new extra */ /* get a new extra */
se = AllocSurfaceExtra(); surfaceExtra_t *se = AllocSurfaceExtra();
/* copy out the relevant bits */ /* copy out the relevant bits */
se->mds = ds; se->mds = &ds;
se->si = ds->shaderInfo; se->si = ds.shaderInfo;
se->parentSurfaceNum = ds->parent != NULL ? ds->parent->outputNum : -1; se->parentSurfaceNum = ds.parent != NULL ? ds.parent->outputNum : -1;
se->entityNum = ds->entityNum; se->entityNum = ds.entityNum;
se->castShadows = ds->castShadows; se->castShadows = ds.castShadows;
se->recvShadows = ds->recvShadows; se->recvShadows = ds.recvShadows;
se->sampleSize = ds->sampleSize; se->sampleSize = ds.sampleSize;
se->longestCurve = ds->longestCurve; se->longestCurve = ds.longestCurve;
se->lightmapAxis = ds->lightmapAxis; se->lightmapAxis = ds.lightmapAxis;
/* debug code */ /* debug code */
//% Sys_FPrintf( SYS_VRB, "SetSurfaceExtra(): entityNum = %d\n", ds->entityNum ); //% Sys_FPrintf( SYS_VRB, "SetSurfaceExtra(): entityNum = %d\n", ds.entityNum );
} }
@ -138,7 +130,7 @@ static surfaceExtra_t *GetSurfaceExtra( int num ){
} }
shaderInfo_t *GetSurfaceExtraShaderInfo( int num ){ const shaderInfo_t *GetSurfaceExtraShaderInfo( int num ){
return GetSurfaceExtra( num )->si; return GetSurfaceExtra( num )->si;
} }

View File

@ -526,7 +526,7 @@ void BeginModel( void ){
Sys_FPrintf( SYS_VRB, "Lightgrid bounds: { %f %f %f } { %f %f %f }\n", lgMinmax.mins[0], lgMinmax.mins[1], lgMinmax.mins[2], lgMinmax.maxs[0], lgMinmax.maxs[1], lgMinmax.maxs[2] ); Sys_FPrintf( SYS_VRB, "Lightgrid bounds: { %f %f %f } { %f %f %f }\n", lgMinmax.mins[0], lgMinmax.mins[1], lgMinmax.mins[2], lgMinmax.maxs[0], lgMinmax.maxs[1], lgMinmax.maxs[2] );
/* set firsts */ /* set firsts */
mod.firstBSPSurface = numBSPDrawSurfaces; mod.firstBSPSurface = bspDrawSurfaces.size();
mod.firstBSPBrush = bspBrushes.size(); mod.firstBSPBrush = bspBrushes.size();
} }
@ -547,7 +547,7 @@ void EndModel( entity_t *e, node_t *headnode ){
EmitDrawNode_r( headnode ); EmitDrawNode_r( headnode );
/* set surfaces and brushes */ /* set surfaces and brushes */
mod.numBSPSurfaces = numBSPDrawSurfaces - mod.firstBSPSurface; mod.numBSPSurfaces = bspDrawSurfaces.size() - mod.firstBSPSurface;
mod.firstBSPBrush = e->firstBrush; mod.firstBSPBrush = e->firstBrush;
mod.numBSPBrushes = e->numBrushes; mod.numBSPBrushes = e->numBrushes;
} }