Skip to content

Commit c250e8c

Browse files
committed
Use SphereFromBounds() instead of FinishGenericSurface()
The only other code in `FinishGenericSurface()` was duplicate from `ParseFace()`. Also moved both `ShaderForShaderNum()` and `SphereFromBounds()` closer to where they're actually used.
1 parent 663f4e7 commit c250e8c

1 file changed

Lines changed: 30 additions & 59 deletions

File tree

src/engine/renderer/tr_bsp.cpp

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -746,62 +746,6 @@ static void R_LoadVisibility( lump_t *l )
746746

747747
//===============================================================================
748748

749-
/*
750-
===============
751-
ShaderForShaderNum
752-
===============
753-
*/
754-
static shader_t *ShaderForShaderNum( int shaderNum )
755-
{
756-
shader_t *shader;
757-
dshader_t *dsh;
758-
759-
shaderNum = LittleLong( shaderNum ) + 0; // silence the warning
760-
761-
if ( shaderNum < 0 || shaderNum >= s_worldData.numShaders )
762-
{
763-
Sys::Drop( "ShaderForShaderNum: bad num %i", shaderNum );
764-
}
765-
766-
dsh = &s_worldData.shaders[ shaderNum ];
767-
768-
shader = R_FindShader( dsh->shader, shaderType_t::SHADER_3D_STATIC, RSF_DEFAULT );
769-
770-
// if the shader had errors, just use default shader
771-
if ( shader->defaultShader )
772-
{
773-
return tr.defaultShader;
774-
}
775-
776-
return shader;
777-
}
778-
779-
/*
780-
SphereFromBounds() - ydnar
781-
creates a bounding sphere from a bounding box
782-
*/
783-
784-
static void SphereFromBounds( vec3_t mins, vec3_t maxs, vec3_t origin, float *radius )
785-
{
786-
vec3_t temp;
787-
788-
VectorAdd( mins, maxs, origin );
789-
VectorScale( origin, 0.5, origin );
790-
VectorSubtract( maxs, origin, temp );
791-
*radius = VectorLength( temp );
792-
}
793-
794-
/*
795-
FinishGenericSurface() - ydnar
796-
handles final surface classification
797-
*/
798-
799-
static void FinishGenericSurface( dsurface_t *ds, srfGeneric_t *gen, vec3_t pt )
800-
{
801-
// set bounding sphere
802-
SphereFromBounds( gen->bounds[ 0 ], gen->bounds[ 1 ], gen->origin, &gen->radius );
803-
}
804-
805749
// Generate the skybox mesh and add it to world
806750
static void FinishSkybox() {
807751
// Min and max coordinates of the skybox cube corners
@@ -875,6 +819,34 @@ static void FinishSkybox() {
875819
tr.skybox = skybox;
876820
}
877821

822+
static shader_t* ShaderForShaderNum( int shaderNum ) {
823+
shaderNum = LittleLong( shaderNum ) + 0; // silence the warning
824+
825+
if ( shaderNum < 0 || shaderNum >= s_worldData.numShaders ) {
826+
Sys::Drop( "ShaderForShaderNum: bad num %i", shaderNum );
827+
}
828+
829+
dshader_t* dsh = &s_worldData.shaders[shaderNum];
830+
831+
shader_t* shader = R_FindShader( dsh->shader, shaderType_t::SHADER_3D_STATIC, RSF_DEFAULT );
832+
833+
// If the shader had errors, just use default shader
834+
if ( shader->defaultShader ) {
835+
return tr.defaultShader;
836+
}
837+
838+
return shader;
839+
}
840+
841+
static void SphereFromBounds( vec3_t mins, vec3_t maxs, vec3_t origin, float* radius ) {
842+
vec3_t temp;
843+
844+
VectorAdd( mins, maxs, origin );
845+
VectorScale( origin, 0.5, origin );
846+
VectorSubtract( maxs, origin, temp );
847+
*radius = VectorLength( temp );
848+
}
849+
878850
static void ParseTriangleSurface( dsurface_t* ds, drawVert_t* verts, bspSurface_t* surf, int* indexes ) {
879851
int realLightmapNum = LittleLong( ds->lightmapNum );
880852

@@ -1043,7 +1015,7 @@ static void ParseTriangleSurface( dsurface_t* ds, drawVert_t* verts, bspSurface_
10431015
dv2->qtangent );
10441016
}
10451017

1046-
FinishGenericSurface( ds, ( srfGeneric_t* ) cv, cv->verts[0].xyz );
1018+
SphereFromBounds( cv->bounds[0], cv->bounds[1], cv->origin, &cv->radius );
10471019
}
10481020

10491021
static void ParseFace( dsurface_t* ds, drawVert_t* verts, bspSurface_t* surf, int* indexes ) {
@@ -1203,8 +1175,7 @@ static void ParseMesh( dsurface_t *ds, drawVert_t *verts, bspSurface_t *surf )
12031175
VectorSubtract( bounds[ 0 ], grid->lodOrigin, tmpVec );
12041176
grid->lodRadius = VectorLength( tmpVec );
12051177

1206-
// finish surface
1207-
FinishGenericSurface( ds, ( srfGeneric_t * ) grid, grid->verts[ 0 ].xyz );
1178+
SphereFromBounds( grid->bounds[0], grid->bounds[1], grid->origin, &grid->radius );
12081179
}
12091180

12101181
/*

0 commit comments

Comments
 (0)