std::vector<bspShader_t> bspShaders

This commit is contained in:
Garux 2021-09-24 13:39:04 +03:00
parent 6e2fc92576
commit 58911934e0
13 changed files with 76 additions and 203 deletions

View File

@ -237,7 +237,7 @@ int pk3BSPMain( Args& args ){
/* extract map name */
const CopiedString nameOFmap( PathFilename( source ) );
std::vector<bool> drawsurfSHs( numBSPShaders, false );
std::vector<bool> drawsurfSHs( bspShaders.size(), false );
for ( i = 0; i < numBSPDrawSurfaces; ++i ){
drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = true;
@ -250,7 +250,7 @@ int pk3BSPMain( Args& args ){
StrList* pk3Textures = StrList_allocate( 1024 );
StrList* pk3Videos = StrList_allocate( 1024 );
for ( i = 0; i < numBSPShaders; ++i ){
for ( size_t i = 0; i < bspShaders.size(); ++i ){
if ( drawsurfSHs[i] && !( bspShaders[i].surfaceFlags & 0x80 /* Q_SURF_NORAW */ ) ){
res2list( pk3Shaders, bspShaders[i].shader );
//Sys_Printf( "%s\n", bspShaders[i].shader );
@ -909,13 +909,13 @@ int repackBSPMain( Args& args ){
/* extract map name */
const CopiedString nameOFmap( PathFilename( source ) );
std::vector<bool> drawsurfSHs( numBSPShaders, false );
std::vector<bool> drawsurfSHs( bspShaders.size(), false );
for ( i = 0; i < numBSPDrawSurfaces; ++i ){
drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = true;
}
for ( i = 0; i < numBSPShaders; ++i ){
for ( size_t i = 0; i < bspShaders.size(); ++i ){
if ( drawsurfSHs[i] && !( bspShaders[i].surfaceFlags & 0x80 /* Q_SURF_NORAW */ ) ){
res2list( pk3Shaders, bspShaders[i].shader );
}
@ -976,122 +976,23 @@ int repackBSPMain( Args& args ){
for ( i = pk3SoundsNold; i < pk3Sounds->n; ++i ){
Sys_Printf( "%s\n", pk3Sounds->s[i] );
}
/* free bsp data */
/*
if ( bspDrawVerts != 0 ) {
free( bspDrawVerts );
bspDrawVerts = NULL;
//numBSPDrawVerts = 0;
Sys_Printf( "freed BSPDrawVerts\n" );
}
if ( bspDrawSurfaces != 0 ) {
Sys_Printf( "freed bspDrawSurfaces\n" );
}
*/ free( bspDrawSurfaces );
/* free partially loaded bsp data */
free( bspDrawSurfaces );
bspDrawSurfaces = NULL;
numBSPDrawSurfaces = 0;
/* if ( bspLightBytes != 0 ) {
free( bspLightBytes );
bspLightBytes = NULL;
//numBSPLightBytes = 0;
Sys_Printf( "freed BSPLightBytes\n" );
}
if ( bspGridPoints != 0 ) {
free( bspGridPoints );
bspGridPoints = NULL;
//numBSPGridPoints = 0;
Sys_Printf( "freed BSPGridPoints\n" );
}
if ( bspPlanes != 0 ) {
free( bspPlanes );
bspPlanes = NULL;
Sys_Printf( "freed bspPlanes\n" );
//numBSPPlanes = 0;
//allocatedBSPPlanes = 0;
}
if ( bspBrushes != 0 ) {
free( bspBrushes );
bspBrushes = NULL;
Sys_Printf( "freed bspBrushes\n" );
//numBSPBrushes = 0;
//allocatedBSPBrushes = 0;
}
*/ {
entities.clear();
//Sys_Printf( "freed entities\n" );
numBSPEntities = 0;
}
/* if ( bspModels != 0 ) {
free( bspModels );
bspModels = NULL;
Sys_Printf( "freed bspModels\n" );
}
if ( bspShaders != 0 ) {
Sys_Printf( "freed bspShaders\n" );
}
*/ free( bspShaders );
bspShaders = NULL;
numBSPShaders = 0;
allocatedBSPShaders = 0;
/* if ( bspEntData != 0 ) {
Sys_Printf( "freed bspEntData\n" );
}
*/ free( bspEntData );
entities.clear();
numBSPEntities = 0;
bspShaders.clear();
free( bspEntData );
bspEntData = NULL;
bspEntDataSize = 0;
allocatedBSPEntData = 0;
/* if ( bspNodes != 0 ) {
free( bspNodes );
bspNodes = NULL;
Sys_Printf( "freed bspNodes\n" );
//numBSPNodes = 0;
//allocatedBSPNodes = 0;
}
if ( bspDrawIndexes != 0 ) {
free( bspDrawIndexes );
bspDrawIndexes = NULL;
Sys_Printf( "freed bspDrawIndexes\n" );
//numBSPDrawIndexes = 0;
//allocatedBSPDrawIndexes = 0;
}
if ( bspLeafSurfaces != 0 ) {
free( bspLeafSurfaces );
bspLeafSurfaces = NULL;
Sys_Printf( "freed bspLeafSurfaces\n" );
//numBSPLeafSurfaces = 0;
//allocatedBSPLeafSurfaces = 0;
}
if ( bspLeafBrushes != 0 ) {
free( bspLeafBrushes );
bspLeafBrushes = NULL;
Sys_Printf( "freed bspLeafBrushes\n" );
//numBSPLeafBrushes = 0;
//allocatedBSPLeafBrushes = 0;
}
if ( bspBrushSides != 0 ) {
free( bspBrushSides );
bspBrushSides = NULL;
Sys_Printf( "freed bspBrushSides\n" );
numBSPBrushSides = 0;
allocatedBSPBrushSides = 0;
}
if ( numBSPFogs != 0 ) {
Sys_Printf( "freed numBSPFogs\n" );
}
*/ numBSPFogs = 0;
/* if ( numBSPAds != 0 ) {
Sys_Printf( "freed numBSPAds\n" );
numBSPAds = 0;
}
if ( numBSPLeafs != 0 ) {
Sys_Printf( "freed numBSPLeafs\n" );
numBSPLeafs = 0;
}
if ( numBSPVisBytes != 0 ) {
Sys_Printf( "freed numBSPVisBytes\n" );
numBSPVisBytes = 0;
}
*/ }
numBSPFogs = 0;
}
if( analyze )
return 0;

View File

@ -169,18 +169,18 @@ void SwapBSPFile( void ){
SwapBlock( bspModels );
/* shaders (don't swap the name) */
for ( i = 0; i < numBSPShaders; i++ )
for ( bspShader_t& shader : bspShaders )
{
if ( doingBSP ){
si = ShaderInfoForShader( bspShaders[ i ].shader );
si = ShaderInfoForShader( shader.shader );
if ( !strEmptyOrNull( si->remapShader ) ) {
// copy and clear the rest of memory // check for overflow by String64
const auto remap = String64()( si->remapShader );
strncpy( bspShaders[ i ].shader, remap, sizeof( bspShaders[ i ].shader ) );
strncpy( shader.shader, remap, sizeof( shader.shader ) );
}
}
bspShaders[ i ].contentFlags = LittleLong( bspShaders[ i ].contentFlags );
bspShaders[ i ].surfaceFlags = LittleLong( bspShaders[ i ].surfaceFlags );
shader.contentFlags = LittleLong( shader.contentFlags );
shader.surfaceFlags = LittleLong( shader.surfaceFlags );
}
/* planes */
@ -388,13 +388,12 @@ void PartialLoadBSPFile( const char *filename ){
PartialLoadIBSPFile( filename );
/* PartialSwapBSPFile() */
int i;
/* shaders (don't swap the name) */
for ( i = 0; i < numBSPShaders; i++ )
for ( bspShader_t& shader : bspShaders )
{
bspShaders[ i ].contentFlags = LittleLong( bspShaders[ i ].contentFlags );
bspShaders[ i ].surfaceFlags = LittleLong( bspShaders[ i ].surfaceFlags );
shader.contentFlags = LittleLong( shader.contentFlags );
shader.surfaceFlags = LittleLong( shader.surfaceFlags );
}
/* drawsurfs */
@ -402,7 +401,7 @@ void PartialLoadBSPFile( const char *filename ){
SwapBlock( (int*) bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) );
/* fogs */
for ( i = 0; i < numBSPFogs; i++ )
for ( int i = 0; i < numBSPFogs; i++ )
{
bspFogs[ i ].brushNum = LittleLong( bspFogs[ i ].brushNum );
bspFogs[ i ].visibleSide = LittleLong( bspFogs[ i ].visibleSide );
@ -465,8 +464,8 @@ void PrintBSPFileSizes( void ){
/* print various and sundry bits */
Sys_Printf( "%9zu models %9zu\n",
bspModels.size(), bspModels.size() * sizeof( bspModels[0] ) );
Sys_Printf( "%9d shaders %9d\n",
numBSPShaders, (int) ( numBSPShaders * sizeof( bspShader_t ) ) );
Sys_Printf( "%9zu shaders %9zu\n",
bspShaders.size(), bspShaders.size() * sizeof( bspShaders[0] ) );
Sys_Printf( "%9d brushes %9d\n",
numBSPBrushes, (int) ( numBSPBrushes * sizeof( bspBrush_t ) ) );
Sys_Printf( "%9d brushsides %9d *\n",

View File

@ -433,7 +433,7 @@ void LoadIBSPFile( const char *filename ){
}
/* load/convert lumps */
numBSPShaders = CopyLump_Allocate( (bspHeader_t*) header, LUMP_SHADERS, (void **) &bspShaders, sizeof( bspShader_t ), &allocatedBSPShaders );
CopyLump( (bspHeader_t*) header, LUMP_SHADERS, bspShaders );
CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels );
@ -505,7 +505,7 @@ void PartialLoadIBSPFile( const char *filename ){
}
/* load/convert lumps */
numBSPShaders = CopyLump_Allocate( (bspHeader_t*) header, LUMP_SHADERS, (void **) &bspShaders, sizeof( bspShader_t ), &allocatedBSPShaders );
CopyLump( (bspHeader_t*) header, LUMP_SHADERS, bspShaders );
CopyDrawSurfacesLump( header );
@ -551,7 +551,7 @@ void WriteIBSPFile( const char *filename ){
AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 );
/* add lumps */
AddLump( file, (bspHeader_t*) header, LUMP_SHADERS, bspShaders, numBSPShaders * sizeof( bspShader_t ) );
AddLump( file, header->lumps[LUMP_SHADERS], bspShaders );
AddLump( file, (bspHeader_t*) header, LUMP_PLANES, bspPlanes, numBSPPlanes * sizeof( bspPlane_t ) );
AddLump( file, (bspHeader_t*) header, LUMP_LEAFS, bspLeafs, numBSPLeafs * sizeof( bspLeaf_t ) );
AddLump( file, (bspHeader_t*) header, LUMP_NODES, bspNodes, numBSPNodes * sizeof( bspNode_t ) );

View File

@ -224,7 +224,7 @@ void LoadRBSPFile( const char *filename ){
}
/* load/convert lumps */
numBSPShaders = CopyLump_Allocate( (bspHeader_t*) header, LUMP_SHADERS, (void **) &bspShaders, sizeof( bspShader_t ), &allocatedBSPShaders );
CopyLump( (bspHeader_t*) header, LUMP_SHADERS, bspShaders );
CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels );
@ -304,7 +304,7 @@ void WriteRBSPFile( const char *filename ){
AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 );
/* add lumps */
AddLump( file, (bspHeader_t*) header, LUMP_SHADERS, bspShaders, numBSPShaders * sizeof( bspShader_t ) );
AddLump( file, header->lumps[LUMP_SHADERS], bspShaders );
AddLump( file, (bspHeader_t*) header, LUMP_PLANES, bspPlanes, numBSPPlanes * sizeof( bspPlane_t ) );
AddLump( file, (bspHeader_t*) header, LUMP_LEAFS, bspLeafs, numBSPLeafs * sizeof( bspLeaf_t ) );
AddLump( file, (bspHeader_t*) header, LUMP_NODES, bspNodes, numBSPNodes * sizeof( bspNode_t ) );

View File

@ -41,7 +41,7 @@
int numLightmapsASE = 0;
static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const int* lmIndices ){
static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const std::vector<int>& lmIndices ){
int i, v, face, a, b, c;
bspDrawVert_t *dv;
char name[ 1024 ];
@ -181,7 +181,7 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
exports a bsp model to an ase chunk
*/
static void ConvertModel( FILE *f, int modelNum, const Vector3& origin, const int* lmIndices ){
static void ConvertModel( FILE *f, int modelNum, const Vector3& origin, const std::vector<int>& lmIndices ){
const bspModel_t& model = bspModels[ modelNum ];
/* go through each drawsurf in the model */
@ -238,13 +238,13 @@ static void ConvertModel( FILE *f, int modelNum, const Vector3& origin, const in
}
*/
static void ConvertShader( FILE *f, bspShader_t *shader, int shaderNum ){
static void ConvertShader( FILE *f, const bspShader_t& shader ){
shaderInfo_t *si;
char *c, filename[ 1024 ];
/* get shader */
si = ShaderInfoForShader( shader->shader );
si = ShaderInfoForShader( shader.shader );
if ( si == NULL ) {
Sys_Warning( "NULL shader in BSP\n" );
return;
@ -263,21 +263,21 @@ static void ConvertShader( FILE *f, bspShader_t *shader, int shaderNum ){
}
/* print shader info */
fprintf( f, "\t*MATERIAL\t%d\t{\r\n", shaderNum );
fprintf( f, "\t\t*MATERIAL_NAME\t\"%s\"\r\n", shader->shader );
fprintf( f, "\t*MATERIAL\t%d\t{\r\n", int( &shader - bspShaders.data() ) );
fprintf( f, "\t\t*MATERIAL_NAME\t\"%s\"\r\n", shader.shader );
fprintf( f, "\t\t*MATERIAL_CLASS\t\"Standard\"\r\n" );
fprintf( f, "\t\t*MATERIAL_DIFFUSE\t%f\t%f\t%f\r\n", si->color[ 0 ], si->color[ 1 ], si->color[ 2 ] );
fprintf( f, "\t\t*MATERIAL_SHADING Phong\r\n" );
/* print map info */
fprintf( f, "\t\t*MAP_DIFFUSE\t{\r\n" );
fprintf( f, "\t\t\t*MAP_NAME\t\"%s\"\r\n", shader->shader );
fprintf( f, "\t\t\t*MAP_NAME\t\"%s\"\r\n", shader.shader );
fprintf( f, "\t\t\t*MAP_CLASS\t\"Bitmap\"\r\n" );
fprintf( f, "\t\t\t*MAP_SUBNO\t1\r\n" );
fprintf( f, "\t\t\t*MAP_AMOUNT\t1.0\r\n" );
fprintf( f, "\t\t\t*MAP_TYPE\tScreen\r\n" );
if ( shadersAsBitmap ) {
fprintf( f, "\t\t\t*BITMAP\t\"%s\"\r\n", shader->shader );
fprintf( f, "\t\t\t*BITMAP\t\"%s\"\r\n", shader.shader );
}
else{
fprintf( f, "\t\t\t*BITMAP\t\"..\\%s\"\r\n", filename );
@ -324,9 +324,8 @@ static void ConvertLightmap( FILE *f, const char *base, int lightmapNum ){
int ConvertBSPToASE( char *bspName ){
int modelNum;
FILE *f;
bspShader_t *shader;
entity_t *e;
int lmIndices[ numBSPShaders ];
std::vector<int> lmIndices( bspShaders.size(), -1 );
/* note it */
@ -365,11 +364,10 @@ int ConvertBSPToASE( char *bspName ){
}
else
{
fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", numBSPShaders );
for ( int i = 0; i < numBSPShaders; i++ )
fprintf( f, "\t*MATERIAL_COUNT\t%zu\r\n", bspShaders.size() );
for ( const bspShader_t& shader : bspShaders )
{
shader = &bspShaders[ i ];
ConvertShader( f, shader, i );
ConvertShader( f, shader );
}
}
fprintf( f, "}\r\n" );

View File

@ -144,7 +144,7 @@ static void write_json( const char *directory ){
{
doc.RemoveAllMembers();
for_indexed( auto&& shader : Span( bspShaders, numBSPShaders ) ){
for_indexed( const auto& shader : bspShaders ){
rapidjson::Value value( rapidjson::kObjectType );
value.AddMember( "shader", rapidjson::StringRef( shader.shader ), all );
value.AddMember( "surfaceFlags", shader.surfaceFlags, all ); ///////!!!!!!! decompose bits?
@ -378,15 +378,12 @@ inline rapidjson::Document load_json( const char *fileName ){
static void read_json( const char *directory ){
{
const auto doc = load_json( StringOutputStream( 256 )( directory, "shaders.json" ) );
static std::vector<bspShader_t> items;
for( auto&& obj : doc.GetObj() ){
auto&& item = items.emplace_back();
auto&& item = bspShaders.emplace_back();
strcpy( item.shader, obj.value["shader"].GetString() );
item.surfaceFlags = obj.value["surfaceFlags"].GetInt();
item.contentFlags = obj.value["contentFlags"].GetInt();
}
bspShaders = items.data();
numBSPShaders = items.size();
}
{
const auto doc = load_json( StringOutputStream( 256 )( directory, "models.json" ) );

View File

@ -208,7 +208,7 @@ static void ConvertBrushFast( FILE *f, int num, bspBrush_t *brush, const Vector3
const bspBrushSide_t& side = bspBrushSides[ brush->firstSide + i ];
/* get shader */
if ( side.shaderNum < 0 || side.shaderNum >= numBSPShaders ) {
if ( side.shaderNum < 0 || side.shaderNum >= int( bspShaders.size() ) ) {
continue;
}
const bspShader_t& shader = bspShaders[ side.shaderNum ];
@ -230,7 +230,7 @@ static void ConvertBrushFast( FILE *f, int num, bspBrush_t *brush, const Vector3
const bspBrushSide_t& side = bspBrushSides[ brush->firstSide + i ];
/* get shader */
if ( side.shaderNum < 0 || side.shaderNum >= numBSPShaders ) {
if ( side.shaderNum < 0 || side.shaderNum >= int( bspShaders.size() ) ) {
continue;
}
const bspShader_t& shader = bspShaders[ side.shaderNum ];
@ -332,7 +332,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
const bspBrushSide_t& side = bspBrushSides[ brush->firstSide + i ];
/* get shader */
if ( side.shaderNum < 0 || side.shaderNum >= numBSPShaders ) {
if ( side.shaderNum < 0 || side.shaderNum >= int( bspShaders.size() ) ) {
continue;
}
const bspShader_t& shader = bspShaders[ side.shaderNum ];
@ -354,7 +354,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
const bspBrushSide_t& side = bspBrushSides[ brush->firstSide + i ];
/* get shader */
if ( side.shaderNum < 0 || side.shaderNum >= numBSPShaders ) {
if ( side.shaderNum < 0 || side.shaderNum >= int( bspShaders.size() ) ) {
continue;
}
const bspShader_t& shader = bspShaders[ side.shaderNum ];
@ -681,7 +681,7 @@ for ( i = 0; i < brush->numSides; i++ )
side = &bspBrushSides[ brush->firstSide + i ];
/* get shader */
if ( side->shaderNum < 0 || side->shaderNum >= numBSPShaders ) {
if ( side->shaderNum < 0 || side->shaderNum >= int( bspShaders.size() ) ) {
continue;
}
shader = &bspShaders[ side->shaderNum ];
@ -758,7 +758,7 @@ static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, const Vector3&
}
/* get shader */
if ( ds->shaderNum < 0 || ds->shaderNum >= numBSPShaders ) {
if ( ds->shaderNum < 0 || ds->shaderNum >= int( bspShaders.size() ) ) {
return;
}
shader = &bspShaders[ ds->shaderNum ];

View File

@ -44,7 +44,7 @@ int lastLightmap = -1;
int objVertexCount = 0;
int objLastShaderNum = -1;
static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const int* lmIndices ){
static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const std::vector<int>& lmIndices ){
int i, v, a, b, c;
bspDrawVert_t *dv;
@ -127,7 +127,7 @@ static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, in
exports a bsp model to an ase chunk
*/
static void ConvertModelToOBJ( FILE *f, int modelNum, const Vector3& origin, const int* lmIndices ){
static void ConvertModelToOBJ( FILE *f, int modelNum, const Vector3& origin, const std::vector<int>& lmIndices ){
const bspModel_t& model = bspModels[ modelNum ];
/* go through each drawsurf in the model */
@ -145,13 +145,13 @@ static void ConvertModelToOBJ( FILE *f, int modelNum, const Vector3& origin, con
exports a bsp shader to an ase chunk
*/
static void ConvertShaderToMTL( FILE *f, bspShader_t *shader, int shaderNum ){
static void ConvertShaderToMTL( FILE *f, const bspShader_t& shader ){
shaderInfo_t *si;
char filename[ 1024 ];
/* get shader */
si = ShaderInfoForShader( shader->shader );
si = ShaderInfoForShader( shader.shader );
if ( si == NULL ) {
Sys_Warning( "NULL shader in BSP\n" );
return;
@ -172,10 +172,10 @@ static void ConvertShaderToMTL( FILE *f, bspShader_t *shader, int shaderNum ){
*/
/* print shader info */
fprintf( f, "newmtl %s\r\n", shader->shader );
fprintf( f, "newmtl %s\r\n", shader.shader );
fprintf( f, "Kd %f %f %f\r\n", si->color[ 0 ], si->color[ 1 ], si->color[ 2 ] );
if ( shadersAsBitmap ) {
fprintf( f, "map_Kd %s\r\n", shader->shader );
fprintf( f, "map_Kd %s\r\n", shader.shader );
}
else{
/* blender hates this, so let's not do it
@ -218,10 +218,7 @@ int Convert_CountLightmaps( const char* dirname ){
}
/* manage external lms, possibly referenced by q3map2_%mapname%.shader */
void Convert_ReferenceLightmaps( const char* base, int* lmIndices ){
for( int i = 0; i < numBSPShaders; ++i ) // initialize
lmIndices[i] = -1;
void Convert_ReferenceLightmaps( const char* base, std::vector<int>& lmIndices ){
char shaderfile[256];
sprintf( shaderfile, "%s/q3map2_%s.shader", g_game->shaderPath, base );
LoadScriptFile( shaderfile, 0 );
@ -269,7 +266,7 @@ void Convert_ReferenceLightmaps( const char* base, int* lmIndices ){
int okcount = 0;
if( sscanf( token + strlen( token ) - ( strlen( EXTERNAL_LIGHTMAP ) + 1 ), "/" EXTERNAL_LIGHTMAP "%n", &lmindex, &okcount )
&& okcount == ( strlen( EXTERNAL_LIGHTMAP ) + 1 ) ){
for ( int i = 0; i < numBSPShaders; ++i ){ // find bspShaders[i]<->lmindex pair
for ( size_t i = 0; i < bspShaders.size(); ++i ){ // find bspShaders[i]<->lmindex pair
if( strEqual( bspShaders[i].shader, shadername ) ){
lmIndices[i] = lmindex;
break;
@ -295,10 +292,9 @@ void Convert_ReferenceLightmaps( const char* base, int* lmIndices ){
int ConvertBSPToOBJ( char *bspName ){
int modelNum;
FILE *f, *fmtl;
bspShader_t *shader;
entity_t *e;
const char *key;
int lmIndices[ numBSPShaders ];
std::vector<int> lmIndices( bspShaders.size(), -1 );
/* note it */
@ -328,10 +324,9 @@ int ConvertBSPToOBJ( char *bspName ){
}
else
{
for ( int i = 0; i < numBSPShaders; i++ )
for ( const bspShader_t& shader : bspShaders )
{
shader = &bspShaders[ i ];
ConvertShaderToMTL( fmtl, shader, i );
ConvertShaderToMTL( fmtl, shader );
}
}

View File

@ -23,6 +23,6 @@
#define INCLUDED_CONVERT_OBJ_H
int Convert_CountLightmaps( const char* dirname );
void Convert_ReferenceLightmaps( const char* base, int* lmIndices );
void Convert_ReferenceLightmaps( const char* base, std::vector<int>& lmIndices );
#endif

View File

@ -2942,7 +2942,6 @@ void SetupBrushesFlags( int mask_any, int test_any, int mask_all, int test_all )
int compileFlags, allCompileFlags;
bspBrush_t *brush;
bspBrushSide_t *side;
bspShader_t *shader;
shaderInfo_t *si;
@ -2972,10 +2971,9 @@ void SetupBrushesFlags( int mask_any, int test_any, int mask_all, int test_all )
{
/* do bsp shader calculations */
side = &bspBrushSides[ brush->firstSide + j ];
shader = &bspShaders[ side->shaderNum ];
/* get shader info */
si = ShaderInfoForShaderNull( shader->shader );
si = ShaderInfoForShaderNull( bspShaders[ side->shaderNum ].shader );
if ( si == NULL ) {
continue;
}
@ -3236,7 +3234,6 @@ int ShaderForPointInLeaf( const Vector3& point, int leafNum, float epsilon, int
bspLeaf_t *leaf;
bspBrush_t *brush;
bspBrushSide_t *side;
bspShader_t *shader;
int allSurfaceFlags, allContentFlags;
@ -3271,9 +3268,9 @@ int ShaderForPointInLeaf( const Vector3& point, int leafNum, float epsilon, int
}
else
{
shader = &bspShaders[ side->shaderNum ];
allSurfaceFlags |= shader->surfaceFlags;
allContentFlags |= shader->contentFlags;
const bspShader_t& shader = bspShaders[ side->shaderNum ];
allSurfaceFlags |= shader.surfaceFlags;
allContentFlags |= shader.contentFlags;
}
}

View File

@ -926,7 +926,6 @@ struct CompareSurfaceInfo
void SetupSurfaceLightmaps( void ){
int i, j, k, s,num, num2;
bspModel_t *model;
bspLeaf_t *leaf;
bspDrawSurface_t *ds;
surfaceInfo_t *info, *info2;

View File

@ -2336,9 +2336,7 @@ Q_EXTERN std::vector<entity_t> entities;
Q_EXTERN std::vector<bspModel_t> bspModels;
Q_EXTERN int numBSPShaders Q_ASSIGN( 0 );
Q_EXTERN int allocatedBSPShaders Q_ASSIGN( 0 );
Q_EXTERN bspShader_t* bspShaders Q_ASSIGN( 0 );
Q_EXTERN std::vector<bspShader_t> bspShaders;
Q_EXTERN int bspEntDataSize Q_ASSIGN( 0 );
Q_EXTERN int allocatedBSPEntData Q_ASSIGN( 0 );

View File

@ -39,7 +39,6 @@
*/
int EmitShader( const char *shader, const int *contentFlags, const int *surfaceFlags ){
int i;
shaderInfo_t *si;
@ -49,7 +48,7 @@ int EmitShader( const char *shader, const int *contentFlags, const int *surfaceF
}
/* try to find an existing shader */
for ( i = 0; i < numBSPShaders; i++ )
for ( size_t i = 0; i < bspShaders.size(); ++i )
{
/* ydnar: handle custom surface/content flags */
if ( surfaceFlags != NULL && bspShaders[ i ].surfaceFlags != *surfaceFlags ) {
@ -70,27 +69,17 @@ int EmitShader( const char *shader, const int *contentFlags, const int *surfaceF
}
}
// i == numBSPShaders
/* get shaderinfo */
si = ShaderInfoForShader( shader );
/* emit a new shader */
AUTOEXPAND_BY_REALLOC_BSP( Shaders, 1024 );
numBSPShaders++;
// copy and clear the rest of memory
strncpy( bspShaders[ i ].shader, si->shader, sizeof( bspShaders[ i ].shader ) );
bspShaders[ i ].surfaceFlags = si->surfaceFlags;
bspShaders[ i ].contentFlags = si->contentFlags;
const int i = bspShaders.size(); // store index
bspShader_t& bspShader = bspShaders.emplace_back();
strcpy( bspShader.shader, si->shader );
/* handle custom content/surface flags */
if ( surfaceFlags != NULL ) {
bspShaders[ i ].surfaceFlags = *surfaceFlags;
}
if ( contentFlags != NULL ) {
bspShaders[ i ].contentFlags = *contentFlags;
}
bspShader.surfaceFlags = ( surfaceFlags != NULL )? *surfaceFlags : si->surfaceFlags;
bspShader.contentFlags = ( contentFlags != NULL )? *contentFlags : si->contentFlags;
/* recursively emit any damage shaders */
if ( !strEmptyOrNull( si->damageShader ) ) {
@ -98,7 +87,7 @@ int EmitShader( const char *shader, const int *contentFlags, const int *surfaceF
EmitShader( si->damageShader, NULL, NULL );
}
/* return it */
/* return index */
return i;
}