From fb3698b820ad0d59f67f34229e92f62e58d3bb8a Mon Sep 17 00:00:00 2001 From: Garux Date: Thu, 18 Sep 2025 23:36:30 +0500 Subject: [PATCH] minor tweaks --- tools/quake3/q3map2/bsp.cpp | 2 +- tools/quake3/q3map2/bspfile_abstract.cpp | 6 +- tools/quake3/q3map2/convert_ase.cpp | 29 +- tools/quake3/q3map2/convert_map.cpp | 2 +- tools/quake3/q3map2/convert_obj.cpp | 25 +- tools/quake3/q3map2/lightmaps_ydnar.cpp | 22 +- tools/quake3/q3map2/map.cpp | 22 +- tools/quake3/q3map2/model.cpp | 50 ++- tools/quake3/q3map2/patch.cpp | 2 +- tools/quake3/q3map2/q3map2.h | 4 +- tools/quake3/q3map2/shaders.cpp | 496 +++++++++++------------ tools/quake3/q3map2/surface.cpp | 81 ++-- tools/quake3/q3map2/surface_extra.cpp | 2 +- tools/quake3/q3map2/writebsp.cpp | 23 +- 14 files changed, 352 insertions(+), 414 deletions(-) diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp index 0b495116..38f24ec9 100644 --- a/tools/quake3/q3map2/bsp.cpp +++ b/tools/quake3/q3map2/bsp.cpp @@ -48,7 +48,7 @@ static void autocaulk_write(){ ApplySurfaceParm( "lava", &flava, NULL, NULL ); // many setups have nodraw shader nonsolid, including vQ3; and nondrawnonsolid also... fall back to caulk in such case // it would be better to decide in Radiant, as it has configurable per game common shaders, but it has no solidity info - const bool nodraw_is_solid = ShaderInfoForShader( "textures/common/nodraw" )->compileFlags & C_SOLID; + const bool nodraw_is_solid = ShaderInfoForShader( "textures/common/nodraw" ).compileFlags & C_SOLID; for ( const brush_t& b : entities[0].brushes ) { fprintf( file, "%i ", b.brushNum ); diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index eae757ef..0c685729 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -97,10 +97,10 @@ static void SwapBSPFile(){ for ( bspShader_t& shader : bspShaders ) { if ( doingBSP ){ - const shaderInfo_t *si = ShaderInfoForShader( shader.shader ); - if ( !strEmptyOrNull( si->remapShader ) ) { + const shaderInfo_t& si = ShaderInfoForShader( shader.shader ); + if ( !strEmptyOrNull( si.remapShader ) ) { // copy and clear the rest of memory // check for overflow by String64 - const String64 remap( si->remapShader ); + const String64 remap( si.remapShader ); strncpy( shader.shader, remap, sizeof( shader.shader ) ); } } diff --git a/tools/quake3/q3map2/convert_ase.cpp b/tools/quake3/q3map2/convert_ase.cpp index bdfa651a..c3b20c93 100644 --- a/tools/quake3/q3map2/convert_ase.cpp +++ b/tools/quake3/q3map2/convert_ase.cpp @@ -234,34 +234,23 @@ static void ConvertModel( FILE *f, int modelNum, const Vector3& origin, const st */ static void ConvertShader( FILE *f, const bspShader_t& shader ){ - shaderInfo_t *si; - char *c, filename[ 1024 ]; - - /* get shader */ - si = ShaderInfoForShader( shader.shader ); - if ( si == NULL ) { - Sys_Warning( "NULL shader in BSP\n" ); - return; - } + shaderInfo_t& si = ShaderInfoForShader( shader.shader ); /* set bitmap filename */ - if ( si->shaderImage->filename.c_str()[ 0 ] != '*' ) { - strcpy( filename, si->shaderImage->filename.c_str() ); - } - else{ - sprintf( filename, "%s.tga", si->shader.c_str() ); - } - for ( c = filename; *c; c++ ) - if ( *c == '/' ) { + auto filename = si.shaderImage->filename.c_str()[ 0 ] == '*' + ? StringStream<64>( si.shader, ".tga" ) + : StringStream<64>( si.shaderImage->filename ); + + for ( char *c = filename.c_str(); !strEmpty( c ); ++c ) + if ( *c == '/' ) *c = '\\'; - } /* print shader info */ 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_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 */ @@ -275,7 +264,7 @@ static void ConvertShader( FILE *f, const bspShader_t& 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 ); + fprintf( f, "\t\t\t*BITMAP\t\"..\\%s\"\r\n", filename.c_str() ); } fprintf( f, "\t\t\t*BITMAP_FILTER\tPyramidal\r\n" ); fprintf( f, "\t\t}\r\n" ); diff --git a/tools/quake3/q3map2/convert_map.cpp b/tools/quake3/q3map2/convert_map.cpp index 6c81c0e4..fd97ab98 100644 --- a/tools/quake3/q3map2/convert_map.cpp +++ b/tools/quake3/q3map2/convert_map.cpp @@ -239,7 +239,7 @@ static void bspBrush_to_buildBrush( const bspBrush_t& brush ){ buildBrush.sides.emplace_back(); /* tag it */ - buildBrush.sides.back().shaderInfo = ShaderInfoForShader( shader.shader ); + buildBrush.sides.back().shaderInfo = &ShaderInfoForShader( shader.shader ); buildBrush.sides.back().planenum = side.planeNum; } } diff --git a/tools/quake3/q3map2/convert_obj.cpp b/tools/quake3/q3map2/convert_obj.cpp index 38f1dc3f..27f53fb5 100644 --- a/tools/quake3/q3map2/convert_obj.cpp +++ b/tools/quake3/q3map2/convert_obj.cpp @@ -143,34 +143,23 @@ static void ConvertModelToOBJ( FILE *f, int modelNum, const Vector3& origin, con */ static void ConvertShaderToMTL( FILE *f, const bspShader_t& shader ){ - shaderInfo_t *si; - char filename[ 1024 ]; - - /* get shader */ - si = ShaderInfoForShader( shader.shader ); - if ( si == NULL ) { - Sys_Warning( "NULL shader in BSP\n" ); - return; - } + shaderInfo_t& si = ShaderInfoForShader( shader.shader ); /* set bitmap filename */ - if ( si->shaderImage->filename.c_str()[ 0 ] != '*' ) { - strcpy( filename, si->shaderImage->filename.c_str() ); - } - else{ - sprintf( filename, "%s.tga", si->shader.c_str() ); - } + auto filename = si.shaderImage->filename.c_str()[ 0 ] == '*' + ? StringStream<64>( si.shader, ".tga" ) + : StringStream<64>( si.shaderImage->filename ); /* blender hates this, so let's not do it - for( c = filename; *c; c++ ) + for( char *c = filename; *c; c++ ) if( *c == '/' ) *c = '\\'; */ /* print shader info */ 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 ] ); + 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 ); } @@ -178,7 +167,7 @@ static void ConvertShaderToMTL( FILE *f, const bspShader_t& shader ){ /* blender hates this, so let's not do it fprintf( f, "map_Kd ..\\%s\r\n", filename ); */ - fprintf( f, "map_Kd ../%s\r\n", filename ); + fprintf( f, "map_Kd ../%s\r\n", filename.c_str() ); } } diff --git a/tools/quake3/q3map2/lightmaps_ydnar.cpp b/tools/quake3/q3map2/lightmaps_ydnar.cpp index dd59b62e..6938d4d8 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.cpp +++ b/tools/quake3/q3map2/lightmaps_ydnar.cpp @@ -993,7 +993,7 @@ void SetupSurfaceLightmaps(){ const surfaceExtra_t& se = GetSurfaceExtra( num ); info->si = se.si; if ( info->si == NULL ) { - info->si = ShaderInfoForShader( bspShaders[ ds->shaderNum ].shader ); + info->si = &ShaderInfoForShader( bspShaders[ ds->shaderNum ].shader ); } info->parentSurfaceNum = se.parentSurfaceNum; info->entityNum = se.entityNum; @@ -2331,7 +2331,6 @@ void StoreSurfaceLightmaps( bool fastAllocate, bool storeForReal ){ outLightmap_t *olm; bspDrawVert_t *dv, *ydv, *dvParent; char dirname[ 1024 ], filename[ 1024 ]; - const shaderInfo_t *csi; char lightmapName[ 128 ]; const char *rgbGenValues[ 256 ] = {0}; const char *alphaGenValues[ 256 ] = {0}; @@ -3285,21 +3284,16 @@ void StoreSurfaceLightmaps( bool fastAllocate, bool storeForReal ){ } /* create custom shader */ - if ( info->si->styleMarker == 2 ) { - csi = CustomShader( info->si, "q3map_styleMarker2", styleStages ); - } - else{ - csi = CustomShader( info->si, "q3map_styleMarker", styleStages ); - } + const shaderInfo_t& csi = CustomShader( info->si, info->si->styleMarker == 2? "q3map_styleMarker2" : "q3map_styleMarker", styleStages ); /* emit remap command */ - //% EmitVertexRemapShader( csi->shader, info->si->shader ); + //% EmitVertexRemapShader( csi.shader, info->si->shader ); /* store it */ - //% Sys_Printf( "Emitting: %s (%d", csi->shader, strlen( csi->shader ) ); + //% Sys_Printf( "Emitting: %s (%d", csi.shader, strlen( csi.shader ) ); const int cont = bspShaders[ ds->shaderNum ].contentFlags; const int surf = bspShaders[ ds->shaderNum ].surfaceFlags; - ds->shaderNum = EmitShader( csi->shader, &cont, &surf ); + ds->shaderNum = EmitShader( csi.shader, &cont, &surf ); //% Sys_Printf( ")\n" ); } @@ -3313,13 +3307,13 @@ void StoreSurfaceLightmaps( bool fastAllocate, bool storeForReal ){ sprintf( lightmapName, "maps/%s/" EXTERNAL_LIGHTMAP "\n\t\ttcgen lightmap", mapName.c_str(), olm->extLightmapNum ); /* create custom shader */ - csi = CustomShader( info->si, "$lightmap", lightmapName ); + const shaderInfo_t& csi = CustomShader( info->si, "$lightmap", lightmapName ); /* store it */ - //% Sys_Printf( "Emitting: %s (%d", csi->shader, strlen( csi->shader ) ); + //% Sys_Printf( "Emitting: %s (%d", csi.shader, strlen( csi.shader ) ); const int cont = bspShaders[ ds->shaderNum ].contentFlags; const int surf = bspShaders[ ds->shaderNum ].surfaceFlags; - ds->shaderNum = EmitShader( csi->shader, &cont, &surf ); + ds->shaderNum = EmitShader( csi.shader, &cont, &surf ); //% Sys_Printf( ")\n" ); } diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index e9bacd16..8717a2a0 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -1003,13 +1003,13 @@ static void ParseRawBrush( bool onlyLights ){ const String64 shader( "textures/", token ); /* set default flags and values */ - shaderInfo_t *si = onlyLights? shaderInfo.begin().operator->() + shaderInfo_t& si = onlyLights? *shaderInfo.begin() : ShaderInfoForShader( shader ); - side.shaderInfo = si; - side.surfaceFlags = si->surfaceFlags; - side.contentFlags = si->contentFlags; - side.compileFlags = si->compileFlags; - side.value = si->value; + side.shaderInfo = &si; + side.surfaceFlags = si.surfaceFlags; + side.contentFlags = si.contentFlags; + side.compileFlags = si.compileFlags; + side.value = si.value; /* AP or 220? */ if ( g_brushType == EBrushType::Undefined ){ @@ -1040,9 +1040,9 @@ static void ParseRawBrush( bool onlyLights ){ scale[ 1 ] = atof( token ); /* ydnar: gs mods: bias texture shift */ - if ( !si->globalTexture ) { - shift[ 0 ] -= ( floor( shift[ 0 ] / si->shaderWidth ) * si->shaderWidth ); - shift[ 1 ] -= ( floor( shift[ 1 ] / si->shaderHeight ) * si->shaderHeight ); + if ( !si.globalTexture ) { + shift[ 0 ] -= ( floor( shift[ 0 ] / si.shaderWidth ) * si.shaderWidth ); + shift[ 1 ] -= ( floor( shift[ 1 ] / si.shaderHeight ) * si.shaderHeight ); } /* get the texture mapping for this texturedef / plane combination */ @@ -1574,11 +1574,11 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups, int mapEntit const char *value; if( mapEnt.read_keyvalue( value, "_celshader" ) || entities[ 0 ].read_keyvalue( value, "_celshader" ) ){ - celShader = ShaderInfoForShader( String64( "textures/", value ) ); + celShader = &ShaderInfoForShader( String64( "textures/", value ) ); Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt.mapEntityNum, classname, celShader->shader.c_str() ); } else{ - celShader = globalCelShader.empty() ? NULL : ShaderInfoForShader( globalCelShader ); + celShader = globalCelShader.empty() ? nullptr : &ShaderInfoForShader( globalCelShader ); } /* jal : entity based _shadeangle */ diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 89c655cf..590095ea 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -391,19 +391,19 @@ inline size_t normal_make_axial( Vector3& normal ){ } template // N = 4 or 5 -static void make_brush_sides( const Plane3f plane, const Plane3f (&p)[3], const Plane3f& reverse, Vector3 (&points)[4], shaderInfo_t *si ){ +static void make_brush_sides( const Plane3f plane, const Plane3f (&p)[3], const Plane3f& reverse, Vector3 (&points)[4], shaderInfo_t& si ){ /* set up brush sides */ buildBrush.sides.clear(); // clear, so resize() will value-initialize elements buildBrush.sides.resize( N ); if( debugClip ){ - buildBrush.sides[ 0 ].shaderInfo = ShaderInfoForShader( "debugclip2" ); + buildBrush.sides[ 0 ].shaderInfo = &ShaderInfoForShader( "debugclip2" ); for ( size_t i = 1; i < N; ++i ) - buildBrush.sides[i].shaderInfo = ShaderInfoForShader( "debugclip" ); + buildBrush.sides[i].shaderInfo = &ShaderInfoForShader( "debugclip" ); } else{ - buildBrush.sides[0].shaderInfo = si; - buildBrush.sides[0].surfaceFlags = si->surfaceFlags; + buildBrush.sides[0].shaderInfo = &si; + buildBrush.sides[0].surfaceFlags = si.surfaceFlags; for ( size_t i = 1; i < N; ++i ) buildBrush.sides[i].shaderInfo = NULL; // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works } @@ -418,11 +418,11 @@ static void make_brush_sides( const Plane3f plane, const Plane3f (&p)[3], const buildBrush.sides[4].planenum = FindFloatPlane( reverse, 0, NULL ); } -static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const mapDrawSurface_t *ds, const char *modelName, entity_t& entity ){ +static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t& si, const mapDrawSurface_t *ds, const char *modelName, entity_t& entity ){ const int spf = ( spawnFlags & ( eClipFlags & ~eClipModel ) ); /* ydnar: giant hack land: generate clipping brushes for model triangles */ - if ( ( si->clipModel && spf == 0 ) // default CLIPMODEL + if ( ( si.clipModel && spf == 0 ) // default CLIPMODEL || ( spawnFlags & eClipFlags ) == eClipModel //default CLIPMODEL || spf == eExtrudeFaceNormals || spf == eExtrudeTerrain @@ -457,7 +457,7 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const int axis; /* temp hack */ - if ( !si->clipModel && !( si->compileFlags & C_SOLID ) ) { + if ( !si.clipModel && !( si.compileFlags & C_SOLID ) ) { return; } @@ -493,9 +493,9 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const /* prepare a brush */ buildBrush.sides.reserve( MAX_BUILD_SIDES ); buildBrush.entityNum = entity.mapEntityNum; - buildBrush.contentShader = si; - buildBrush.compileFlags = si->compileFlags; - buildBrush.contentFlags = si->contentFlags; + buildBrush.contentShader = &si; + buildBrush.compileFlags = si.compileFlags; + buildBrush.contentFlags = si.contentFlags; buildBrush.detail = true; /* walk triangle list */ @@ -933,7 +933,7 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const } - else if ( ( si->clipModel && spf == 0 ) || ( spawnFlags & eClipFlags ) == eClipModel ){ //default CLIPMODEL + else if ( ( si.clipModel && spf == 0 ) || ( spawnFlags & eClipFlags ) == eClipModel ){ //default CLIPMODEL default_CLIPMODEL: // axial normal @@ -988,7 +988,6 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4& const Matrix4 nTransform( matrix4_for_normal_transform( transform ) ); const bool transform_lefthanded = MATRIX4_LEFTHANDED == matrix4_handedness( transform ); AssModel *model; - shaderInfo_t *si; mapDrawSurface_t *ds; const char *picoShaderName; @@ -1117,12 +1116,9 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4& } /* shader renaming for sof2 */ - if ( renameModelShaders ) { - si = ShaderInfoForShader( String64( PathExtensionless( picoShaderName ), ( spawnFlags & eRMG_BSP )? "_RMG_BSP" : "_BSP" ) ); - } - else{ - si = ShaderInfoForShader( picoShaderName ); - } + shaderInfo_t& si = renameModelShaders + ? ShaderInfoForShader( String64( PathExtensionless( picoShaderName ), ( spawnFlags & eRMG_BSP )? "_RMG_BSP" : "_BSP" ) ) + : ShaderInfoForShader( picoShaderName ); /* allocate a surface (ydnar: gs mods) */ ds = AllocDrawSurface( ESurfaceType::Triangles ); @@ -1131,10 +1127,10 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4& ds->recvShadows = recvShadows; /* set shader */ - ds->shaderInfo = si; + ds->shaderInfo = &si; /* force to meta? */ - if ( ( si != NULL && si->forceMeta ) || ( spawnFlags & eForceMeta ) ) { /* 3rd bit */ + if ( si.forceMeta || ( spawnFlags & eForceMeta ) ) { /* 3rd bit */ ds->type = ESurfaceType::ForcedMeta; } @@ -1183,14 +1179,14 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4& /* ydnar: tek-fu celshading support for flat shaded shit */ if ( flat ) { - dv.st = si->stFlat; + dv.st = si.stFlat; } /* ydnar: gs mods: added support for explicit shader texcoord generation */ - else if ( si->tcGen ) { + else if ( si.tcGen ) { /* project the texture */ - dv.st[ 0 ] = vector3_dot( si->vecs[ 0 ], dv.xyz ); - dv.st[ 1 ] = vector3_dot( si->vecs[ 1 ], dv.xyz ); + dv.st[ 0 ] = vector3_dot( si.vecs[ 0 ], dv.xyz ); + dv.st[ 1 ] = vector3_dot( si.vecs[ 1 ], dv.xyz ); } /* normal texture coordinates */ @@ -1366,10 +1362,10 @@ void AddTriangleModels( entity_t& eparent ){ shaderInfo_t *celShader; if( const char *value; e.read_keyvalue( value, "_celshader" ) || entities[ 0 ].read_keyvalue( value, "_celshader" ) ){ - celShader = ShaderInfoForShader( String64( "textures/", value ) ); + celShader = &ShaderInfoForShader( String64( "textures/", value ) ); } else{ - celShader = globalCelShader.empty() ? NULL : ShaderInfoForShader( globalCelShader ); + celShader = globalCelShader.empty() ? nullptr : &ShaderInfoForShader( globalCelShader ); } /* jal : entity based _samplesize */ diff --git a/tools/quake3/q3map2/patch.cpp b/tools/quake3/q3map2/patch.cpp index f7e96219..b00ead56 100644 --- a/tools/quake3/q3map2/patch.cpp +++ b/tools/quake3/q3map2/patch.cpp @@ -318,7 +318,7 @@ void ParsePatch( bool onlyLights, entity_t& mapEnt, int mapPrimitiveNum ){ pm->brushNum = mapPrimitiveNum; /* set shader */ - pm->shaderInfo = ShaderInfoForShader( shader ); + pm->shaderInfo = &ShaderInfoForShader( shader ); /* set mesh */ pm->mesh = m; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 38ffdb39..67c505ad 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1698,11 +1698,11 @@ const surfaceParm_t &GetRequiredSurfaceParm(){ void BeginMapShaderFile( const char *mapFile ); void WriteMapShaderFile(); -const shaderInfo_t *CustomShader( const 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 LoadShaderInfo(); -shaderInfo_t *ShaderInfoForShader( const char *shader ); +shaderInfo_t &ShaderInfoForShader( const char *shader ); shaderInfo_t *ShaderInfoForShaderNull( const char *shader ); diff --git a/tools/quake3/q3map2/shaders.cpp b/tools/quake3/q3map2/shaders.cpp index bce9a59f..d16a6cd7 100644 --- a/tools/quake3/q3map2/shaders.cpp +++ b/tools/quake3/q3map2/shaders.cpp @@ -345,11 +345,8 @@ void WriteMapShaderFile(){ sets up a custom map shader */ -const shaderInfo_t *CustomShader( const shaderInfo_t *si, const char *find, char *replace ){ - shaderInfo_t *csi; +const shaderInfo_t& CustomShader( const shaderInfo_t *si, const char *find, char *replace ){ char shader[ MAX_QPATH ]; - char *s; - int loc; byte digest[ 16 ]; char *srcShaderText, temp[ 8192 ], shaderText[ 8192 ]; /* ydnar: fixme (make this bigger?) */ @@ -454,20 +451,19 @@ const shaderInfo_t *CustomShader( const shaderInfo_t *si, const char *find, char } /* do some bad find-replace */ - s = strIstr( srcShaderText, find ); - if ( s == NULL ) { - //% strcpy( shaderText, srcShaderText ); - return si; /* testing just using the existing shader if this fails */ - } - else - { + if ( const char *found = strIstr( srcShaderText, find ) ) { /* substitute 'find' with 'replace' */ - loc = s - srcShaderText; + const int loc = found - srcShaderText; strcpy( shaderText, srcShaderText ); shaderText[ loc ] = '\0'; strcat( shaderText, replace ); strcat( shaderText, &srcShaderText[ loc + strlen( find ) ] ); } + else + { + //% strcpy( shaderText, srcShaderText ); + return *si; /* testing just using the existing shader if this fails */ + } /* make md4 hash of the shader text */ Com_BlockFullChecksum( shaderText, strlen( shaderText ), digest ); @@ -478,19 +474,19 @@ const shaderInfo_t *CustomShader( const shaderInfo_t *si, const char *find, char digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ], digest[ 15 ] ); /* get shader */ - csi = ShaderInfoForShader( shader ); + shaderInfo_t& csi = ShaderInfoForShader( shader ); /* might be a preexisting shader */ - if ( csi->custom ) { + if ( csi.custom ) { return csi; } /* clone the existing shader data */ - csi->copyData( *si ); - csi->custom = true; + csi.copyData( *si ); + csi.custom = true; /* store new shader text */ - csi->shaderText = copystring( shaderText ); /* LEAK! */ + csi.shaderText = copystring( shaderText ); /* LEAK! */ /* return it */ return csi; @@ -536,40 +532,40 @@ void EmitVertexRemapShader( char *from, char *to ){ allocates and initializes a new shader */ -static shaderInfo_t *AllocShaderInfo( const char *shaderName ){ - shaderInfo_t *si = shaderInfo.emplace_back( shaderName ).operator->(); +static shaderInfo_t& AllocShaderInfo( const char *shaderName ){ + shaderInfo_t& si = *shaderInfo.emplace_back( shaderName ); /* ydnar: clear to 0 first */ // new( si ) shaderInfo_t{}; // placement new /* set defaults */ - ApplySurfaceParm( "default", &si->contentFlags, &si->surfaceFlags, &si->compileFlags ); + ApplySurfaceParm( "default", &si.contentFlags, &si.surfaceFlags, &si.compileFlags ); - si->backsplashFraction = DEF_BACKSPLASH_FRACTION * g_backsplashFractionScale; - si->backsplashDistance = g_backsplashDistance < -900.0f ? DEF_BACKSPLASH_DISTANCE : g_backsplashDistance; + si.backsplashFraction = DEF_BACKSPLASH_FRACTION * g_backsplashFractionScale; + si.backsplashDistance = g_backsplashDistance < -900.0f ? DEF_BACKSPLASH_DISTANCE : g_backsplashDistance; - si->bounceScale = DEF_RADIOSITY_BOUNCE; + si.bounceScale = DEF_RADIOSITY_BOUNCE; - si->lightStyle = LS_NORMAL; + si.lightStyle = LS_NORMAL; - si->polygonOffset = false; + si.polygonOffset = false; - si->shadeAngleDegrees = 0.0f; - si->lightmapSampleSize = 0; - si->lightmapSampleOffset = DEFAULT_LIGHTMAP_SAMPLE_OFFSET; - si->patchShadows = false; - si->vertexShadows = true; /* ydnar: changed default behavior */ - si->forceSunlight = false; - si->lmBrightness = lightmapBrightness; - si->vertexScale = vertexglobalscale; - si->notjunc = false; + si.shadeAngleDegrees = 0.0f; + si.lightmapSampleSize = 0; + si.lightmapSampleOffset = DEFAULT_LIGHTMAP_SAMPLE_OFFSET; + si.patchShadows = false; + si.vertexShadows = true; /* ydnar: changed default behavior */ + si.forceSunlight = false; + si.lmBrightness = lightmapBrightness; + si.vertexScale = vertexglobalscale; + si.notjunc = false; /* ydnar: set texture coordinate transform matrix to identity */ - TCModIdentity( si->mod ); + TCModIdentity( si.mod ); /* ydnar: lightmaps can now be > 128x128 in certain games or an externally generated tga */ - si->lmCustomWidth = lmCustomSizeW; - si->lmCustomHeight = lmCustomSizeH; + si.lmCustomWidth = lmCustomSizeW; + si.lmCustomHeight = lmCustomSizeH; /* return to sender */ return si; @@ -582,57 +578,57 @@ static shaderInfo_t *AllocShaderInfo( const char *shaderName ){ sets a shader's width and height among other things */ -static void FinishShader( shaderInfo_t *si ){ +static void FinishShader( shaderInfo_t& si ){ int x, y; Vector2 st; /* don't double-dip */ - if ( si->finished ) { + if ( si.finished ) { return; } /* if they're explicitly set, copy from image size */ - if ( si->shaderWidth == 0 && si->shaderHeight == 0 ) { - si->shaderWidth = si->shaderImage->width; - si->shaderHeight = si->shaderImage->height; + if ( si.shaderWidth == 0 && si.shaderHeight == 0 ) { + si.shaderWidth = si.shaderImage->width; + si.shaderHeight = si.shaderImage->height; } /* legacy terrain has explicit image-sized texture projection */ - if ( si->legacyTerrain && !si->tcGen ) { + if ( si.legacyTerrain && !si.tcGen ) { /* set xy texture projection */ - si->tcGen = true; - si->vecs[ 0 ] = { ( 1.0f / ( si->shaderWidth * 0.5f ) ), 0, 0 }; - si->vecs[ 1 ] = { 0, ( 1.0f / ( si->shaderHeight * 0.5f ) ), 0 }; + si.tcGen = true; + si.vecs[ 0 ] = { ( 1.0f / ( si.shaderWidth * 0.5f ) ), 0, 0 }; + si.vecs[ 1 ] = { 0, ( 1.0f / ( si.shaderHeight * 0.5f ) ), 0 }; } /* find pixel coordinates best matching the average color of the image */ float bestDist = 99999999.f; - const Vector2 o( 1.0f / si->shaderImage->width, 1.0f / si->shaderImage->height ); - for ( y = 0, st[ 1 ] = 0.0f; y < si->shaderImage->height; y++, st[ 1 ] += o[ 1 ] ) + const Vector2 o( 1.0f / si.shaderImage->width, 1.0f / si.shaderImage->height ); + for ( y = 0, st[ 1 ] = 0.0f; y < si.shaderImage->height; y++, st[ 1 ] += o[ 1 ] ) { - for ( x = 0, st[ 0 ] = 0.0f; x < si->shaderImage->width; x++, st[ 0 ] += o[ 0 ] ) + for ( x = 0, st[ 0 ] = 0.0f; x < si.shaderImage->width; x++, st[ 0 ] += o[ 0 ] ) { /* sample the shader image */ Color4f color; - RadSampleImage( si->shaderImage->pixels, si->shaderImage->width, si->shaderImage->height, st, color ); + RadSampleImage( si.shaderImage->pixels, si.shaderImage->width, si.shaderImage->height, st, color ); /* determine error squared */ - const Color4f delta = color - si->averageColor; + const Color4f delta = color - si.averageColor; const float dist = vector4_dot( delta, delta ); if ( dist < bestDist ) { - si->stFlat = st; + si.stFlat = st; } } } - if( g_noob && !( si->compileFlags & C_OB ) ){ - ApplySurfaceParm( "noob", nullptr, &si->surfaceFlags, nullptr ); + if( g_noob && !( si.compileFlags & C_OB ) ){ + ApplySurfaceParm( "noob", nullptr, &si.surfaceFlags, nullptr ); } - si->surfaceFlags |= g_globalSurfaceFlags; + si.surfaceFlags |= g_globalSurfaceFlags; /* set to finished */ - si->finished = true; + si.finished = true; } @@ -643,76 +639,76 @@ static void FinishShader( shaderInfo_t *si ){ ydnar: image.c made this a bit simpler */ -static void LoadShaderImages( shaderInfo_t *si ){ +static void LoadShaderImages( shaderInfo_t& si ){ /* nodraw shaders don't need images */ - if ( si->compileFlags & C_NODRAW ) { - si->shaderImage = ImageLoad( DEFAULT_IMAGE ); + if ( si.compileFlags & C_NODRAW ) { + si.shaderImage = ImageLoad( DEFAULT_IMAGE ); } else { /* try to load editor image first */ - si->shaderImage = ImageLoad( si->editorImagePath ); + si.shaderImage = ImageLoad( si.editorImagePath ); /* then try shadername */ - if ( si->shaderImage == NULL ) { - si->shaderImage = ImageLoad( si->shader ); + if ( si.shaderImage == NULL ) { + si.shaderImage = ImageLoad( si.shader ); } /* then try implicit image path (note: new behavior!) */ - if ( si->shaderImage == NULL ) { - si->shaderImage = ImageLoad( si->implicitImagePath ); + if ( si.shaderImage == NULL ) { + si.shaderImage = ImageLoad( si.implicitImagePath ); } /* then try lightimage (note: new behavior!) */ - if ( si->shaderImage == NULL ) { - si->shaderImage = ImageLoad( si->lightImagePath ); + if ( si.shaderImage == NULL ) { + si.shaderImage = ImageLoad( si.lightImagePath ); } /* otherwise, use default image */ - if ( si->shaderImage == NULL ) { - si->shaderImage = ImageLoad( DEFAULT_IMAGE ); - if ( g_warnImage && !strEqual( si->shader, "noshader" ) ) { - Sys_Warning( "Couldn't find image for shader %s\n", si->shader.c_str() ); + if ( si.shaderImage == NULL ) { + si.shaderImage = ImageLoad( DEFAULT_IMAGE ); + if ( g_warnImage && !strEqual( si.shader, "noshader" ) ) { + Sys_Warning( "Couldn't find image for shader %s\n", si.shader.c_str() ); } } /* load light image */ - si->lightImage = ImageLoad( si->lightImagePath ); + si.lightImage = ImageLoad( si.lightImagePath ); /* load normalmap image (ok if this is NULL) */ - si->normalImage = ImageLoad( si->normalImagePath ); - if ( si->normalImage != NULL ) { + si.normalImage = ImageLoad( si.normalImagePath ); + if ( si.normalImage != NULL ) { Sys_FPrintf( SYS_VRB, "Shader %s has\n" - " NM %s\n", si->shader.c_str(), si->normalImagePath.c_str() ); + " NM %s\n", si.shader.c_str(), si.normalImagePath.c_str() ); } } /* if no light image, reuse shader image */ - if ( si->lightImage == NULL ) { - si->lightImage = si->shaderImage; + if ( si.lightImage == NULL ) { + si.lightImage = si.shaderImage; } /* create default and average colors */ - const int count = si->lightImage->width * si->lightImage->height; + const int count = si.lightImage->width * si.lightImage->height; Color4f color( 0, 0, 0, 0 ); for ( int i = 0; i < count; i++ ) { - color[ 0 ] += si->lightImage->pixels[ i * 4 + 0 ]; - color[ 1 ] += si->lightImage->pixels[ i * 4 + 1 ]; - color[ 2 ] += si->lightImage->pixels[ i * 4 + 2 ]; - color[ 3 ] += si->lightImage->pixels[ i * 4 + 3 ]; + color[ 0 ] += si.lightImage->pixels[ i * 4 + 0 ]; + color[ 1 ] += si.lightImage->pixels[ i * 4 + 1 ]; + color[ 2 ] += si.lightImage->pixels[ i * 4 + 2 ]; + color[ 3 ] += si.lightImage->pixels[ i * 4 + 3 ]; } - if ( vector3_length( si->color ) == 0.0f ) { - si->color = color.rgb(); - ColorNormalize( si->color ); - si->averageColor = color / count; + if ( vector3_length( si.color ) == 0.0f ) { + si.color = color.rgb(); + ColorNormalize( si.color ); + si.averageColor = color / count; } else { - si->averageColor.rgb() = si->color; - si->averageColor.alpha() = 1.0f; + si.averageColor.rgb() = si.color; + si.averageColor.alpha() = 1.0f; } } @@ -729,10 +725,10 @@ shaderInfo_t *ShaderInfoForShaderNull( const char *shaderName ){ if ( strEqual( shaderName, "noshader" ) ) { return NULL; } - return ShaderInfoForShader( shaderName ); + return &ShaderInfoForShader( shaderName ); } -shaderInfo_t *ShaderInfoForShader( const char *shaderName ){ +shaderInfo_t& ShaderInfoForShader( const char *shaderName ){ /* dummy check */ if ( strEmptyOrNull( shaderName ) ) { Sys_Warning( "Null or empty shader name\n" ); @@ -762,18 +758,18 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){ /* load image if necessary */ if ( !si->finished ) { - LoadShaderImages( si.operator->() ); - FinishShader( si.operator->() ); + LoadShaderImages( *si ); + FinishShader( *si ); } /* return it */ - return si.operator->(); + return *si; } break; } /* allocate a default shader */ - shaderInfo_t *si = AllocShaderInfo( shader ); + shaderInfo_t& si = AllocShaderInfo( shader ); LoadShaderImages( si ); FinishShader( si ); @@ -822,12 +818,12 @@ static void ParseShaderFile( const char *filename ){ if( isQ3mapOnlyShader ) strClear( token + strlen( token ) - strlen( ":q3map" ) ); - shaderInfo_t *si = AllocShaderInfo( token ); + shaderInfo_t& si = AllocShaderInfo( token ); /* handle { } section */ if ( !( text.GetToken( true ) && strEqual( token, "{" ) ) ) { Error( "ParseShaderFile(): %s, line %d: { not found!\nFound instead: %s\nLast known shader: %s\nFile location be: %s\n", - filename, scriptline, token, si->shader.c_str(), g_strLoadedFileLocation ); + filename, scriptline, token, si.shader.c_str(), g_strLoadedFileLocation ); } while ( text.GetToken( true ) && !strEqual( token, "}" ) ) @@ -838,11 +834,11 @@ static void ParseShaderFile( const char *filename ){ /* parse stage directives */ if ( strEqual( token, "{" ) ) { - si->hasPasses = true; + si.hasPasses = true; while ( text.GetToken( true ) && !strEqual( token, "}" ) ) { /* only care about images if we don't have a editor/light image */ - if ( si->editorImagePath.empty() && si->lightImagePath.empty() && si->implicitImagePath.empty() ) { + if ( si.editorImagePath.empty() && si.lightImagePath.empty() && si.implicitImagePath.empty() ) { /* digest any images */ if ( striEqual( token, "map" ) || striEqual( token, "clampMap" ) || @@ -858,10 +854,10 @@ static void ParseShaderFile( const char *filename ){ /* get an image */ text.GetToken( false ); if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) { - si->lightImagePath( PathExtensionless( token ) ); + si.lightImagePath( PathExtensionless( token ) ); /* debug code */ - //% Sys_FPrintf( SYS_VRB, "Deduced shader image: %s\n", si->lightImagePath ); + //% Sys_FPrintf( SYS_VRB, "Deduced shader image: %s\n", si.lightImagePath ); } } } @@ -876,7 +872,7 @@ static void ParseShaderFile( const char *filename ){ /* match surfaceparm */ else if ( striEqual( token, "surfaceparm" ) ) { text.GetToken( false ); - if ( !ApplySurfaceParm( token, &si->contentFlags, &si->surfaceFlags, &si->compileFlags ) ) { + if ( !ApplySurfaceParm( token, &si.contentFlags, &si.surfaceFlags, &si.compileFlags ) ) { Sys_Warning( "Unknown surfaceparm: \"%s\"\n", token ); } } @@ -888,25 +884,25 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: fogparms (for determining fog volumes) */ else if ( striEqual( token, "fogparms" ) ) { - si->fogParms = true; + si.fogParms = true; } /* ydnar: polygonoffset (for no culling) */ else if ( striEqual( token, "polygonoffset" ) ) { - si->polygonOffset = true; + si.polygonOffset = true; } /* tesssize is used to force liquid surfaces to subdivide */ else if ( striEqual( token, "tessSize" ) || striEqual( token, "q3map_tessSize" ) /* sof2 */ ) { text.GetToken( false ); - si->subdivisions = atof( token ); + si.subdivisions = atof( token ); } /* cull none will set twoSided (ydnar: added disable too) */ else if ( striEqual( token, "cull" ) ) { text.GetToken( false ); if ( striEqual( token, "none" ) || striEqual( token, "disable" ) || striEqual( token, "twosided" ) ) { - si->twoSided = true; + si.twoSided = true; } } @@ -919,12 +915,12 @@ static void ParseShaderFile( const char *filename ){ /* deformVertexes autosprite(2) */ if ( striEqualPrefix( token, "autosprite" ) ) { /* set it as autosprite and detail */ - si->autosprite = true; - ApplySurfaceParm( "detail", &si->contentFlags, &si->surfaceFlags, &si->compileFlags ); + si.autosprite = true; + ApplySurfaceParm( "detail", &si.contentFlags, &si.surfaceFlags, &si.compileFlags ); /* ydnar: gs mods: added these useful things */ - si->noClip = true; - si->notjunc = true; + si.noClip = true; + si.notjunc = true; } /* deformVertexes move (ydnar: for particle studio support) */ @@ -946,57 +942,57 @@ static void ParseShaderFile( const char *filename ){ text.GetToken( false ); amp = atof( token ); /* calculate */ - si->minmax.mins = amt * base; - si->minmax.maxs = amt * amp + si->minmax.mins; + si.minmax.mins = amt * base; + si.minmax.maxs = amt * amp + si.minmax.mins; } } /* light (old-style flare specification) */ else if ( striEqual( token, "light" ) ) { text.GetToken( false ); - si->flareShader = g_game->flareShader; + si.flareShader = g_game->flareShader; } /* ydnar: damageShader (sof2 mods) */ else if ( striEqual( token, "damageShader" ) ) { text.GetToken( false ); if ( !strEmpty( token ) ) { - si->damageShader = copystring( token ); + si.damageShader = copystring( token ); } text.GetToken( false ); /* don't do anything with health */ } /* ydnar: enemy territory implicit shaders */ else if ( striEqual( token, "implicitMap" ) ) { - si->implicitMap = EImplicitMap::Opaque; + si.implicitMap = EImplicitMap::Opaque; text.GetToken( false ); if ( strEqual( token, "-" ) ) { - si->implicitImagePath = si->shader; + si.implicitImagePath = si.shader; } else{ - si->implicitImagePath( PathExtensionless( token ) ); + si.implicitImagePath( PathExtensionless( token ) ); } } else if ( striEqual( token, "implicitMask" ) ) { - si->implicitMap = EImplicitMap::Masked; + si.implicitMap = EImplicitMap::Masked; text.GetToken( false ); if ( strEqual( token, "-" ) ) { - si->implicitImagePath = si->shader; + si.implicitImagePath = si.shader; } else{ - si->implicitImagePath( PathExtensionless( token ) ); + si.implicitImagePath( PathExtensionless( token ) ); } } else if ( striEqual( token, "implicitBlend" ) ) { - si->implicitMap = EImplicitMap::Blend; + si.implicitMap = EImplicitMap::Blend; text.GetToken( false ); if ( strEqual( token, "-" ) ) { - si->implicitImagePath = si->shader; + si.implicitImagePath = si.shader; } else{ - si->implicitImagePath( PathExtensionless( token ) ); + si.implicitImagePath( PathExtensionless( token ) ); } } @@ -1008,19 +1004,19 @@ static void ParseShaderFile( const char *filename ){ /* qer_editorimage */ else if ( striEqual( token, "qer_editorImage" ) ) { text.GetToken( false ); - si->editorImagePath( PathExtensionless( token ) ); + si.editorImagePath( PathExtensionless( token ) ); } /* ydnar: q3map_normalimage (bumpmapping normal map) */ else if ( striEqual( token, "q3map_normalImage" ) ) { text.GetToken( false ); - si->normalImagePath( PathExtensionless( token ) ); + si.normalImagePath( PathExtensionless( token ) ); } /* q3map_lightimage */ else if ( striEqual( token, "q3map_lightImage" ) ) { text.GetToken( false ); - si->lightImagePath( PathExtensionless( token ) ); + si.lightImagePath( PathExtensionless( token ) ); } /* ydnar: skyparms */ @@ -1030,11 +1026,11 @@ static void ParseShaderFile( const char *filename ){ /* ignore bogus paths */ if ( !strEqual( token, "-" ) && !striEqual( token, "full" ) ) { - si->skyParmsImageBase = token; + si.skyParmsImageBase = token; /* use top image as sky light image */ - if ( si->lightImagePath.empty() ) { - si->lightImagePath( si->skyParmsImageBase, "_up" ); + if ( si.lightImagePath.empty() ) { + si.lightImagePath( si.skyParmsImageBase, "_up" ); } } @@ -1053,12 +1049,12 @@ static void ParseShaderFile( const char *filename ){ degree of 0 = from the east, 90 = north, etc. altitude of 0 = sunrise/set, 90 = noon ydnar: sof2map has bareword 'sun' token, so we support that as well */ else if ( striEqual( token, "sun" ) /* sof2 */ || striEqual( token, "q3map_sun" ) || striEqual( token, "q3map_sunExt" ) ) { - sun_t& sun = si->suns.emplace_back(); + sun_t& sun = si.suns.emplace_back(); /* ydnar: extended sun directive? */ const bool ext = striEqual( token, "q3map_sunext" ); /* set style */ - sun.style = si->lightStyle; + sun.style = si.lightStyle; /* get color */ text.GetToken( false ); @@ -1091,7 +1087,7 @@ static void ParseShaderFile( const char *filename ){ sun.direction = vector3_for_spherical( a, b ); /* get filter radius from shader */ - sun.filterRadius = si->lightFilterRadius; + sun.filterRadius = si.lightFilterRadius; /* ydnar: get sun angular deviance/samples */ if ( ext && TokenAvailable() ) { @@ -1103,7 +1099,7 @@ static void ParseShaderFile( const char *filename ){ } /* apply sky surfaceparm */ - ApplySurfaceParm( "sky", &si->contentFlags, &si->surfaceFlags, &si->compileFlags ); + ApplySurfaceParm( "sky", &si.contentFlags, &si.surfaceFlags, &si.compileFlags ); /* don't process any more tokens on this line */ continue; @@ -1115,27 +1111,25 @@ static void ParseShaderFile( const char *filename ){ if ( striEqual( token, "q3map_baseShader" ) ) { /* get shader */ text.GetToken( false ); - //% Sys_FPrintf( SYS_VRB, "Shader %s has base shader %s\n", si->shader, token ); + //% Sys_FPrintf( SYS_VRB, "Shader %s has base shader %s\n", si.shader, token ); const bool oldWarnImage = std::exchange( g_warnImage, false ); - shaderInfo_t *si2 = ShaderInfoForShader( token ); + shaderInfo_t& si2 = ShaderInfoForShader( token ); g_warnImage = oldWarnImage; /* subclass it */ - if ( si2 != NULL ) { - /* copy shader data */ - si->copyData( *si2 ); + /* copy shader data */ + si.copyData( si2 ); - /* set to unfinished */ - si->shaderWidth = 0; - si->shaderHeight = 0; - si->finished = false; - } + /* set to unfinished */ + si.shaderWidth = 0; + si.shaderHeight = 0; + si.finished = false; } /* ydnar: q3map_surfacemodel */ else if ( striEqual( token, "q3map_surfacemodel" ) ) { /* allocate new model and attach it */ - surfaceModel_t& model = si->surfaceModels.emplace_back(); + surfaceModel_t& model = si.surfaceModels.emplace_back(); /* get parameters */ text.GetToken( false ); @@ -1163,7 +1157,7 @@ static void ParseShaderFile( const char *filename ){ /* ydnar/sd: q3map_foliage */ else if ( striEqual( token, "q3map_foliage" ) ) { /* allocate new foliage struct and attach it */ - foliage_t& foliage = si->foliage.emplace_back(); + foliage_t& foliage = si.foliage.emplace_back(); /* get parameters */ text.GetToken( false ); @@ -1182,12 +1176,12 @@ static void ParseShaderFile( const char *filename ){ /* ydnar: q3map_bounce (fraction of light to re-emit during radiosity passes) */ else if ( striEqual( token, "q3map_bounce" ) || striEqual( token, "q3map_bounceScale" ) ) { text.GetToken( false ); - si->bounceScale = atof( token ); + si.bounceScale = atof( token ); } /* ydnar/splashdamage: q3map_skyLight */ else if ( striEqual( token, "q3map_skyLight" ) ) { - skylight_t& skylight = si->skylights.emplace_back(); + skylight_t& skylight = si.skylights.emplace_back(); text.GetToken( false ); skylight.value = atof( token ); text.GetToken( false ); @@ -1224,155 +1218,155 @@ static void ParseShaderFile( const char *filename ){ /* q3map_surfacelight */ else if ( striEqual( token, "q3map_surfacelight" ) ) { text.GetToken( false ); - si->value = atof( token ); + si.value = atof( token ); } /* q3map_lightStyle (sof2/jk2 lightstyle) */ else if ( striEqual( token, "q3map_lightStyle" ) ) { text.GetToken( false ); - si->lightStyle = std::clamp( atoi( token ), LS_NORMAL, LS_NONE ); + si.lightStyle = std::clamp( atoi( token ), LS_NORMAL, LS_NONE ); } /* wolf: q3map_lightRGB */ else if ( striEqual( token, "q3map_lightRGB" ) ) { - si->color.set( 0 ); + si.color.set( 0 ); text.GetToken( false ); - si->color[ 0 ] = atof( token ); + si.color[ 0 ] = atof( token ); text.GetToken( false ); - si->color[ 1 ] = atof( token ); + si.color[ 1 ] = atof( token ); text.GetToken( false ); - si->color[ 2 ] = atof( token ); + si.color[ 2 ] = atof( token ); if ( colorsRGB ) { - si->color[0] = Image_LinearFloatFromsRGBFloat( si->color[0] ); - si->color[1] = Image_LinearFloatFromsRGBFloat( si->color[1] ); - si->color[2] = Image_LinearFloatFromsRGBFloat( si->color[2] ); + si.color[0] = Image_LinearFloatFromsRGBFloat( si.color[0] ); + si.color[1] = Image_LinearFloatFromsRGBFloat( si.color[1] ); + si.color[2] = Image_LinearFloatFromsRGBFloat( si.color[2] ); } - ColorNormalize( si->color ); + ColorNormalize( si.color ); } /* q3map_lightSubdivide */ else if ( striEqual( token, "q3map_lightSubdivide" ) ) { text.GetToken( false ); - si->lightSubdivide = atoi( token ); + si.lightSubdivide = atoi( token ); } /* q3map_backsplash */ else if ( striEqual( token, "q3map_backsplash" ) ) { text.GetToken( false ); - si->backsplashFraction = atof( token ) * 0.01f; + si.backsplashFraction = atof( token ) * 0.01f; text.GetToken( false ); - si->backsplashDistance = atof( token ); + si.backsplashDistance = atof( token ); } /* q3map_floodLight */ else if ( striEqual( token, "q3map_floodLight" ) ) { /* get color */ text.GetToken( false ); - si->floodlightRGB[ 0 ] = atof( token ); + si.floodlightRGB[ 0 ] = atof( token ); text.GetToken( false ); - si->floodlightRGB[ 1 ] = atof( token ); + si.floodlightRGB[ 1 ] = atof( token ); text.GetToken( false ); - si->floodlightRGB[ 2 ] = atof( token ); + si.floodlightRGB[ 2 ] = atof( token ); text.GetToken( false ); - si->floodlightDistance = atof( token ); + si.floodlightDistance = atof( token ); text.GetToken( false ); - si->floodlightIntensity = atof( token ); + si.floodlightIntensity = atof( token ); text.GetToken( false ); - si->floodlightDirectionScale = atof( token ); + si.floodlightDirectionScale = atof( token ); if ( colorsRGB ) { - si->floodlightRGB[0] = Image_LinearFloatFromsRGBFloat( si->floodlightRGB[0] ); - si->floodlightRGB[1] = Image_LinearFloatFromsRGBFloat( si->floodlightRGB[1] ); - si->floodlightRGB[2] = Image_LinearFloatFromsRGBFloat( si->floodlightRGB[2] ); + si.floodlightRGB[0] = Image_LinearFloatFromsRGBFloat( si.floodlightRGB[0] ); + si.floodlightRGB[1] = Image_LinearFloatFromsRGBFloat( si.floodlightRGB[1] ); + si.floodlightRGB[2] = Image_LinearFloatFromsRGBFloat( si.floodlightRGB[2] ); } - ColorNormalize( si->floodlightRGB ); + ColorNormalize( si.floodlightRGB ); } /* jal: q3map_nodirty : skip dirty */ else if ( striEqual( token, "q3map_nodirty" ) ) { - si->noDirty = true; + si.noDirty = true; } /* q3map_lightmapSampleSize */ else if ( striEqual( token, "q3map_lightmapSampleSize" ) ) { text.GetToken( false ); - si->lightmapSampleSize = atoi( token ); + si.lightmapSampleSize = atoi( token ); } /* q3map_lightmapSampleOffset */ else if ( striEqual( token, "q3map_lightmapSampleOffset" ) ) { text.GetToken( false ); - si->lightmapSampleOffset = atof( token ); + si.lightmapSampleOffset = atof( token ); } /* ydnar: q3map_lightmapFilterRadius */ else if ( striEqual( token, "q3map_lightmapFilterRadius" ) ) { text.GetToken( false ); - si->lmFilterRadius = atof( token ); + si.lmFilterRadius = atof( token ); text.GetToken( false ); - si->lightFilterRadius = atof( token ); + si.lightFilterRadius = atof( token ); } /* ydnar: q3map_lightmapAxis [xyz] */ else if ( striEqual( token, "q3map_lightmapAxis" ) ) { text.GetToken( false ); if ( striEqual( token, "x" ) ) { - si->lightmapAxis = g_vector3_axis_x; + si.lightmapAxis = g_vector3_axis_x; } else if ( striEqual( token, "y" ) ) { - si->lightmapAxis = g_vector3_axis_y; + si.lightmapAxis = g_vector3_axis_y; } else if ( striEqual( token, "z" ) ) { - si->lightmapAxis = g_vector3_axis_z; + si.lightmapAxis = g_vector3_axis_z; } else { Sys_Warning( "Unknown value for lightmap axis: %s\n", token ); - si->lightmapAxis.set( 0 ); + si.lightmapAxis.set( 0 ); } } /* ydnar: q3map_lightmapSize (for autogenerated shaders + external tga lightmaps) */ else if ( striEqual( token, "q3map_lightmapSize" ) ) { text.GetToken( false ); - si->lmCustomWidth = atoi( token ); + si.lmCustomWidth = atoi( token ); text.GetToken( false ); - si->lmCustomHeight = atoi( token ); + si.lmCustomHeight = atoi( token ); /* must be a power of 2 */ - if ( ( ( si->lmCustomWidth - 1 ) & si->lmCustomWidth ) || - ( ( si->lmCustomHeight - 1 ) & si->lmCustomHeight ) ) { + if ( ( ( si.lmCustomWidth - 1 ) & si.lmCustomWidth ) || + ( ( si.lmCustomHeight - 1 ) & si.lmCustomHeight ) ) { Sys_Warning( "Non power-of-two lightmap size specified (%d, %d)\n", - si->lmCustomWidth, si->lmCustomHeight ); - si->lmCustomWidth = lmCustomSizeW; - si->lmCustomHeight = lmCustomSizeH; + si.lmCustomWidth, si.lmCustomHeight ); + si.lmCustomWidth = lmCustomSizeW; + si.lmCustomHeight = lmCustomSizeH; } } /* ydnar: q3map_lightmapBrightness N (for autogenerated shaders + external tga lightmaps) */ else if ( striEqual( token, "q3map_lightmapBrightness" ) || striEqual( token, "q3map_lightmapGamma" ) ) { text.GetToken( false ); - si->lmBrightness *= atof( token ); - if ( si->lmBrightness < 0 ) { - si->lmBrightness = 1.0; + si.lmBrightness *= atof( token ); + if ( si.lmBrightness < 0 ) { + si.lmBrightness = 1.0; } } /* q3map_vertexScale (scale vertex lighting by this fraction) */ else if ( striEqual( token, "q3map_vertexScale" ) ) { text.GetToken( false ); - si->vertexScale *= atof( token ); + si.vertexScale *= atof( token ); } /* q3map_noVertexLight */ else if ( striEqual( token, "q3map_noVertexLight" ) ) { - si->noVertexLight = true; + si.noVertexLight = true; } /* q3map_flare[Shader] */ else if ( striEqual( token, "q3map_flare" ) || striEqual( token, "q3map_flareShader" ) ) { text.GetToken( false ); if ( !strEmpty( token ) ) { - si->flareShader = copystring( token ); + si.flareShader = copystring( token ); } } @@ -1380,7 +1374,7 @@ static void ParseShaderFile( const char *filename ){ else if ( striEqual( token, "q3map_backShader" ) ) { text.GetToken( false ); if ( !strEmpty( token ) ) { - si->backShader = copystring( token ); + si.backShader = copystring( token ); } } @@ -1388,7 +1382,7 @@ static void ParseShaderFile( const char *filename ){ else if ( striEqual( token, "q3map_cloneShader" ) ) { text.GetToken( false ); if ( !strEmpty( token ) ) { - si->cloneShader = copystring( token ); + si.cloneShader = copystring( token ); } } @@ -1396,7 +1390,7 @@ static void ParseShaderFile( const char *filename ){ else if ( striEqual( token, "q3map_remapShader" ) ) { text.GetToken( false ); if ( !strEmpty( token ) ) { - si->remapShader = copystring( token ); + si.remapShader = copystring( token ); } } @@ -1404,85 +1398,85 @@ static void ParseShaderFile( const char *filename ){ else if ( striEqual( token, "q3map_deprecateShader" ) ) { text.GetToken( false ); if ( !strEmpty( token ) ) { - si->deprecateShader = copystring( token ); + si.deprecateShader = copystring( token ); } } /* ydnar: q3map_offset */ else if ( striEqual( token, "q3map_offset" ) ) { text.GetToken( false ); - si->offset = atof( token ); + si.offset = atof( token ); } /* ydnar: q3map_fur */ else if ( striEqual( token, "q3map_fur" ) ) { text.GetToken( false ); - si->furNumLayers = atoi( token ); + si.furNumLayers = atoi( token ); text.GetToken( false ); - si->furOffset = atof( token ); + si.furOffset = atof( token ); text.GetToken( false ); - si->furFade = atof( token ); + si.furFade = atof( token ); } /* ydnar: gs mods: legacy support for terrain/terrain2 shaders */ else if ( striEqual( token, "q3map_terrain" ) ) { /* team arena terrain is assumed to be nonplanar, with full normal averaging, passed through the metatriangle surface pipeline, with a lightmap axis on z */ - si->legacyTerrain = true; - si->noClip = true; - si->notjunc = true; - si->indexed = true; - si->nonplanar = true; - si->forceMeta = true; - si->shadeAngleDegrees = 179.0f; - //% si->lightmapAxis = g_vector3_axis_z; /* ydnar 2002-09-21: turning this off for better lightmapping of cliff faces */ + si.legacyTerrain = true; + si.noClip = true; + si.notjunc = true; + si.indexed = true; + si.nonplanar = true; + si.forceMeta = true; + si.shadeAngleDegrees = 179.0f; + //% si.lightmapAxis = g_vector3_axis_z; /* ydnar 2002-09-21: turning this off for better lightmapping of cliff faces */ } /* ydnar: picomodel: q3map_forceMeta (forces brush faces and/or triangle models to go through the metasurface pipeline) */ else if ( striEqual( token, "q3map_forceMeta" ) ) { - si->forceMeta = true; + si.forceMeta = true; } /* ydnar: gs mods: q3map_shadeAngle */ else if ( striEqual( token, "q3map_shadeAngle" ) ) { text.GetToken( false ); - si->shadeAngleDegrees = atof( token ); + si.shadeAngleDegrees = atof( token ); } /* ydnar: q3map_textureSize (substitute for q3map_lightimage derivation for terrain) */ else if ( striEqual( token, "q3map_textureSize" ) ) { text.GetToken( false ); - si->shaderWidth = atoi( token ); + si.shaderWidth = atoi( token ); text.GetToken( false ); - si->shaderHeight = atoi( token ); + si.shaderHeight = atoi( token ); } /* ydnar: gs mods: q3map_tcGen