Skip to content

Commit 6a96c12

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 1b4c43d commit 6a96c12

File tree

1 file changed

+30
-59
lines changed

1 file changed

+30
-59
lines changed

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

@@ -1044,7 +1016,7 @@ static void ParseTriangleSurface( dsurface_t* ds, drawVert_t* verts, bspSurface_
10441016
dv2->qtangent );
10451017
}
10461018

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

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

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

12111182
/*

0 commit comments

Comments
 (0)