From 1b32f048f897476ac685509e28073474bc792de5 Mon Sep 17 00:00:00 2001 From: Razish Date: Sat, 10 Feb 2024 19:05:12 +1100 Subject: [PATCH 1/3] misc loop overrun fixes --- code/game/wp_saberLoad.cpp | 2 +- code/rd-vanilla/tr_surface.cpp | 2 +- codemp/cgame/cg_draw.c | 2 +- codemp/cgame/cg_newDraw.c | 2 +- codemp/game/NPC_stats.c | 2 +- codemp/game/bg_saberLoad.c | 2 +- codemp/rd-rend2/tr_surface.cpp | 98 ++++++++++++++++---------------- codemp/rd-vanilla/tr_surface.cpp | 2 +- 8 files changed, 56 insertions(+), 56 deletions(-) diff --git a/code/game/wp_saberLoad.cpp b/code/game/wp_saberLoad.cpp index 1b89f34b8f..298d1775eb 100644 --- a/code/game/wp_saberLoad.cpp +++ b/code/game/wp_saberLoad.cpp @@ -490,7 +490,7 @@ static void Saber_ParseSaberType( saberInfo_t *saber, const char **p ) { if ( COM_ParseString( p, &value ) ) return; saberType = GetIDForString( SaberTable, value ); - if ( saberType >= SABER_SINGLE && saberType <= NUM_SABERS ) + if ( saberType >= SABER_SINGLE && saberType < NUM_SABERS ) saber->type = (saberType_t)saberType; } static void Saber_ParseSaberModel( saberInfo_t *saber, const char **p ) { diff --git a/code/rd-vanilla/tr_surface.cpp b/code/rd-vanilla/tr_surface.cpp index 1e51e71c90..ddcef29214 100644 --- a/code/rd-vanilla/tr_surface.cpp +++ b/code/rd-vanilla/tr_surface.cpp @@ -1111,7 +1111,7 @@ static void RB_SurfaceBeam( void ) } qglBegin( GL_TRIANGLE_STRIP ); - for ( i = 0; i <= NUM_BEAM_SEGS; i++ ) { + for ( i = 0; i < NUM_BEAM_SEGS; i++ ) { qglVertex3fv( start_points[ i % NUM_BEAM_SEGS] ); qglVertex3fv( end_points[ i % NUM_BEAM_SEGS] ); } diff --git a/codemp/cgame/cg_draw.c b/codemp/cgame/cg_draw.c index 8b793c1593..bc6e4983a7 100644 --- a/codemp/cgame/cg_draw.c +++ b/codemp/cgame/cg_draw.c @@ -3978,7 +3978,7 @@ static float CG_DrawTeamOverlay( float y, qboolean right, qboolean upper ) { } else { xx = x + w - TINYCHAR_WIDTH; } - for (j = 0; j <= PW_NUM_POWERUPS; j++) { + for (j = 0; j < PW_NUM_POWERUPS; j++) { if (ci->powerups & (1 << j)) { item = BG_FindItemForPowerup( j ); diff --git a/codemp/cgame/cg_newDraw.c b/codemp/cgame/cg_newDraw.c index 6fb6e93848..ab2b384284 100644 --- a/codemp/cgame/cg_newDraw.c +++ b/codemp/cgame/cg_newDraw.c @@ -367,7 +367,7 @@ void CG_DrawNewTeamInfo(rectDef_t *rect, float text_x, float text_y, float scale if ( ci->infoValid && ci->team == cg.snap->ps.persistant[PERS_TEAM]) { xx = rect->x + 1; - for (j = 0; j <= PW_NUM_POWERUPS; j++) { + for (j = 0; j < PW_NUM_POWERUPS; j++) { if (ci->powerups & (1 << j)) { item = BG_FindItemForPowerup( j ); diff --git a/codemp/game/NPC_stats.c b/codemp/game/NPC_stats.c index 4920ad8a68..3293411e58 100644 --- a/codemp/game/NPC_stats.c +++ b/codemp/game/NPC_stats.c @@ -2554,7 +2554,7 @@ qboolean NPC_ParseParms( const char *NPCName, gentity_t *NPC ) } //FIXME: need to precache the weapon, too? (in above func) weap = GetIDForString( WPTable, value ); - if ( weap >= WP_NONE && weap <= WP_NUM_WEAPONS )///*WP_BLASTER_PISTOL*/WP_SABER ) //?! + if ( weap >= WP_NONE && weap < WP_NUM_WEAPONS )///*WP_BLASTER_PISTOL*/WP_SABER ) //?! { NPC->client->ps.weapon = weap; NPC->client->ps.stats[STAT_WEAPONS] |= ( 1 << NPC->client->ps.weapon ); diff --git a/codemp/game/bg_saberLoad.c b/codemp/game/bg_saberLoad.c index ae7460dc1c..a2d02cd2ab 100644 --- a/codemp/game/bg_saberLoad.c +++ b/codemp/game/bg_saberLoad.c @@ -532,7 +532,7 @@ static void Saber_ParseSaberType( saberInfo_t *saber, const char **p ) { if ( COM_ParseString( p, &value ) ) return; saberType = GetIDForString( saberTable, value ); - if ( saberType >= SABER_SINGLE && saberType <= NUM_SABERS ) + if ( saberType >= SABER_SINGLE && saberType < NUM_SABERS ) saber->type = (saberType_t)saberType; } static void Saber_ParseSaberModel( saberInfo_t *saber, const char **p ) { diff --git a/codemp/rd-rend2/tr_surface.cpp b/codemp/rd-rend2/tr_surface.cpp index fc3255a5ed..025e2574a4 100644 --- a/codemp/rd-rend2/tr_surface.cpp +++ b/codemp/rd-rend2/tr_surface.cpp @@ -240,14 +240,14 @@ void RB_InstantQuad(vec4_t quadVerts[4]) VectorSet2(texCoords[3], 0.0f, 1.0f); GLSL_BindProgram(&tr.textureColorShader); - + GLSL_SetUniformMatrix4x4(&tr.textureColorShader, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); GLSL_SetUniformVec4(&tr.textureColorShader, UNIFORM_COLOR, colorWhite); RB_InstantQuad2(quadVerts, texCoords); } -void RB_InstantTriangle() +void RB_InstantTriangle() { qglDrawArrays(GL_TRIANGLES, 0, 3); } @@ -273,7 +273,7 @@ static void RB_SurfaceSprite( void ) { } else { float s, c; float ang; - + ang = M_PI * ent->e.rotation / 180; s = sin( ang ); c = cos( ang ); @@ -310,17 +310,17 @@ static void RB_SurfaceOrientedQuad( void ) VectorCopy( backEnd.currentEntity->e.axis[1], left ); VectorCopy( backEnd.currentEntity->e.axis[2], up ); - if ( backEnd.currentEntity->e.rotation == 0 ) + if ( backEnd.currentEntity->e.rotation == 0 ) { VectorScale( left, radius, left ); VectorScale( up, radius, up ); - } - else + } + else { vec3_t tempLeft, tempUp; float s, c; float ang; - + ang = M_PI * backEnd.currentEntity->e.rotation / 180; s = sin( ang ); c = cos( ang ); @@ -336,7 +336,7 @@ static void RB_SurfaceOrientedQuad( void ) VectorCopy( tempLeft, left ); } - if ( backEnd.viewParms.isMirror ) + if ( backEnd.viewParms.isMirror ) { VectorSubtract( vec3_origin, left, left ); } @@ -658,7 +658,7 @@ static void RB_SurfaceBeam( void ) tess.minIndex = 0; tess.maxIndex = 0; - for ( i = 0; i <= NUM_BEAM_SEGS; i++ ) { + for ( i = 0; i < NUM_BEAM_SEGS; i++ ) { VectorCopy(start_points[ i % NUM_BEAM_SEGS ], tess.xyz[tess.numVertexes++]); VectorCopy(end_points [ i % NUM_BEAM_SEGS ], tess.xyz[tess.numVertexes++]); } @@ -679,12 +679,12 @@ static void RB_SurfaceBeam( void ) // FIXME: A lot of this can probably be removed for speed, and refactored into a more convenient function RB_UpdateVBOs(ATTR_POSITION); - + GLSL_VertexAttribsState(ATTR_POSITION, NULL); GLSL_BindProgram(sp); - + GLSL_SetUniformMatrix4x4(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); - + GLSL_SetUniformVec4(sp, UNIFORM_COLOR, colorRed); R_DrawElementsVBO(tess.numIndexes, tess.firstIndex, tess.minIndex, tess.maxIndex); @@ -702,13 +702,13 @@ static void RB_SurfaceBeam( void ) //------------------ // DoSprite //------------------ -static void DoSprite( vec3_t origin, float radius, float rotation ) +static void DoSprite( vec3_t origin, float radius, float rotation ) { float s, c; float ang; vec3_t left, up; float color[4]; - + ang = M_PI * rotation / 180.0f; s = sin( ang ); c = cos( ang ); @@ -719,7 +719,7 @@ static void DoSprite( vec3_t origin, float radius, float rotation ) VectorScale( backEnd.viewParms.ori.axis[2], c * radius, up ); VectorMA( up, s * radius, backEnd.viewParms.ori.axis[1], up ); - if ( backEnd.viewParms.isMirror ) + if ( backEnd.viewParms.isMirror ) { VectorSubtract( vec3_origin, left, left ); } @@ -733,7 +733,7 @@ static void DoSprite( vec3_t origin, float radius, float rotation ) // RB_SurfaceSaber //------------------ static void RB_SurfaceSaberGlow() -{ +{ vec3_t end; refEntity_t *e; @@ -765,13 +765,13 @@ RB_SurfaceLine // STScale (how many times to loop a texture) // alpha // RGB -// +// // Values for proper line object... // lifetime // dscale // startalpha, endalpha // startRGB, endRGB -// +// static void DoLine( const vec3_t start, const vec3_t end, const vec3_t up, float spanWidth ) { @@ -907,7 +907,7 @@ static void DoLine_Oriented( const vec3_t start, const vec3_t end, const vec3_t //----------------- // RB_SurfaceLine //----------------- -static void RB_SurfaceLine( void ) +static void RB_SurfaceLine( void ) { refEntity_t *e; vec3_t right; @@ -928,7 +928,7 @@ static void RB_SurfaceLine( void ) DoLine( start, end, right, e->radius); } -static void RB_SurfaceOrientedLine( void ) +static void RB_SurfaceOrientedLine( void ) { refEntity_t *e; vec3_t right; @@ -971,7 +971,7 @@ static void DoCylinderPart(polyVert_t *verts) VectorScale4 (verts->modulate, 1.0f / 255.0f, tess.vertexColors[tess.numVertexes]); tess.numVertexes++; verts++; - } + } tess.indexes[tess.numIndexes++] = vbase; tess.indexes[tess.numIndexes++] = vbase + 1; @@ -1036,12 +1036,12 @@ static void RB_SurfaceCylinder( void ) //Upper ring RotatePointAroundVector( upper_points[i].xyz, e->axis[0], vu, detail * i ); VectorAdd( upper_points[i].xyz, e->origin, upper_points[i].xyz ); - + //Lower ring RotatePointAroundVector( lower_points[i].xyz, e->axis[0], v1, detail * i ); VectorAdd( lower_points[i].xyz, e->oldorigin, lower_points[i].xyz ); } - + // Calculate the texture coords so the texture can wrap around the whole cylinder detail = 1.0f / (float)segments; @@ -1136,7 +1136,7 @@ static void ApplyShape( vec3_t start, vec3_t end, vec3_t right, float sradius, f DoLine2( start, end, right, sradius, eradius ); return; } - + CreateShape(); VectorSubtract( end, start, fwd ); @@ -1165,7 +1165,7 @@ static void ApplyShape( vec3_t start, vec3_t end, vec3_t right, float sradius, f VectorMA( point2, 1.0f - perc, end, point2 ); VectorMA( point2, dis * sh2[1], rt, point2 ); VectorMA( point2, dis * sh2[2], up, point2 ); - + // recursion ApplyShape( point2, point1, right, rads1, rads2, count - 1 ); ApplyShape( point2, end, right, rads2, eradius, count - 1 ); @@ -1191,7 +1191,7 @@ static void DoBoltSeg( vec3_t start, vec3_t end, vec3_t right, float radius ) MakeNormalVectors( fwd, rt, up ); VectorCopy( start, old ); - + oldRadius = newRadius = radius; for ( i = 20; i <= dis; i+= 20 ) @@ -1231,7 +1231,7 @@ static void DoBoltSeg( vec3_t start, vec3_t end, vec3_t right, float radius ) // Apply the random shape to our line seg to give it some micro-detail-jaggy-coolness. ApplyShape( cur, old, right, newRadius, oldRadius, LIGHTNING_RECURSION_LEVEL ); - + // randomly split off to create little tendrils, but don't do it too close to the end and especially if we are not even of the forked variety if ( ( e->renderfx & RF_FORKED ) && f_count > 0 && Q_random(&e->frame) > 0.94f && radius * (1.0f - perc) > 0.2f ) { @@ -1316,13 +1316,13 @@ static void RB_SurfaceElectricity() static void VectorArrayNormalize(vec4_t *normals, unsigned int count) { // assert(count); - + #if idppc { register float half = 0.5; register float one = 1.0; float *components = (float *)normals; - + // Vanilla PPC code, but since PPC has a reciprocal square root estimate instruction, // runs *much* faster than calling sqrt(). We'll use a single Newton-Raphson // refinement step to get a little more precision. This seems to yeild results @@ -1331,14 +1331,14 @@ static void VectorArrayNormalize(vec4_t *normals, unsigned int count) do { float x, y, z; float B, y0, y1; - + x = components[0]; y = components[1]; z = components[2]; components += 4; B = x*x + y*y + z*z; -#ifdef __GNUC__ +#ifdef __GNUC__ asm("frsqrte %0,%1" : "=f" (y0) : "f" (B)); #else y0 = __frsqrte(B); @@ -1404,11 +1404,11 @@ static void LerpMeshVertexes_altivec(md3Surface_t *surf, float backlerp) vector unsigned char newNormalsLoadPermute; vector unsigned char newNormalsStorePermute; vector float zero; - + newNormalsStorePermute = vec_lvsl(0,(float *)&newXyzScaleVec); newXyzScaleVec = *(vector float *)&newXyzScale; newXyzScaleVec = vec_perm(newXyzScaleVec,newXyzScaleVec,newNormalsStorePermute); - newXyzScaleVec = vec_splat(newXyzScaleVec,0); + newXyzScaleVec = vec_splat(newXyzScaleVec,0); newNormalsLoadPermute = vec_lvsl(0,newXyz); newNormalsStorePermute = vec_lvsr(0,outXyz); zero = (vector float)vec_splat_s8(0); @@ -1417,7 +1417,7 @@ static void LerpMeshVertexes_altivec(md3Surface_t *surf, float backlerp) // for (vertNum=0 ; vertNum < numVerts ; vertNum++, newXyz += 4, newNormals += 4, - outXyz += 4, outNormal += 4) + outXyz += 4, outNormal += 4) { newNormalsLoadPermute = vec_lvsl(0,newXyz); newNormalsStorePermute = vec_lvsr(0,outXyz); @@ -1462,7 +1462,7 @@ static void LerpMeshVertexes_altivec(md3Surface_t *surf, float backlerp) for (vertNum=0 ; vertNum < numVerts ; vertNum++, oldXyz += 4, newXyz += 4, oldNormals += 4, newNormals += 4, - outXyz += 4, outNormal += 4) + outXyz += 4, outNormal += 4) { vec3_t uncompressedOldNormal, uncompressedNewNormal; @@ -1530,7 +1530,7 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp) // for (vertNum=0 ; vertNum < numVerts ; vertNum++, newXyz += 4, newNormals += 4, - outXyz += 4, outNormal += 4) + outXyz += 4, outNormal += 4) { outXyz[0] = newXyz[0] * newXyzScale; @@ -1563,7 +1563,7 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp) for (vertNum=0 ; vertNum < numVerts ; vertNum++, oldXyz += 4, newXyz += 4, oldNormals += 4, newNormals += 4, - outXyz += 4, outNormal += 4) + outXyz += 4, outNormal += 4) { vec3_t uncompressedOldNormal, uncompressedNewNormal; @@ -1742,11 +1742,11 @@ static float LodErrorForVolume( vec3_t local, float radius ) { return 0; } - world[0] = local[0] * backEnd.ori.axis[0][0] + local[1] * backEnd.ori.axis[1][0] + + world[0] = local[0] * backEnd.ori.axis[0][0] + local[1] * backEnd.ori.axis[1][0] + local[2] * backEnd.ori.axis[2][0] + backEnd.ori.origin[0]; - world[1] = local[0] * backEnd.ori.axis[0][1] + local[1] * backEnd.ori.axis[1][1] + + world[1] = local[0] * backEnd.ori.axis[0][1] + local[1] * backEnd.ori.axis[1][1] + local[2] * backEnd.ori.axis[2][1] + backEnd.ori.origin[1]; - world[2] = local[0] * backEnd.ori.axis[0][2] + local[1] * backEnd.ori.axis[1][2] + + world[2] = local[0] * backEnd.ori.axis[0][2] + local[1] * backEnd.ori.axis[1][2] + local[2] * backEnd.ori.axis[2][2] + backEnd.ori.origin[2]; VectorSubtract( world, backEnd.viewParms.ori.origin, world ); @@ -1848,7 +1848,7 @@ static void RB_SurfaceBSPGrid( srfBspSurface_t *srf ) { break; } } while ( 1 ); - + rows = irows; if ( vrows < irows + 1 ) { rows = vrows - 1; @@ -1932,7 +1932,7 @@ static void RB_SurfaceBSPGrid( srfBspSurface_t *srf ) { for (i = 0 ; i < h ; i++) { for (j = 0 ; j < w ; j++) { int v1, v2, v3, v4; - + // vertex order to be reckognized as tristrips v1 = numVertexes + i*lodWidth + j + 1; v2 = v1 - 1; @@ -1942,7 +1942,7 @@ static void RB_SurfaceBSPGrid( srfBspSurface_t *srf ) { tess.indexes[numIndexes] = v2; tess.indexes[numIndexes+1] = v3; tess.indexes[numIndexes+2] = v1; - + tess.indexes[numIndexes+3] = v1; tess.indexes[numIndexes+4] = v3; tess.indexes[numIndexes+5] = v4; @@ -2043,7 +2043,7 @@ static void RB_SurfaceEntity( surfaceType_t *surfType ) { const int count = backEnd.currentEntity->e.uRefEnt.uMini.miniCount; assert(count > 0); backEnd.currentEntity = &tempEnt; - + assert(backEnd.currentEntity->e.renderfx >= 0); for (int i = 0, j = start; i < count; i++, j++) @@ -2094,7 +2094,7 @@ void RB_SurfaceVBOMDVMesh(srfVBOMDVMesh_t * surface) RB_EndSurface(); } - //drawSurf_t drawSurf = + //drawSurf_t drawSurf = R_BindVBO(surface->vbo); R_BindIBO(surface->ibo); @@ -2197,7 +2197,7 @@ static void RB_SurfaceSprites( srfSprites_t *surf ) // TODO: Do we want a 2-level lod system where far away sprites are // just flat surfaces? - + // TODO: Check which pass (z-prepass/shadow/forward) we're rendering for? shader_t *shader = surf->shader; shaderStage_t *firstStage = shader->stages[0]; @@ -2231,7 +2231,7 @@ static void RB_SurfaceSprites( srfSprites_t *surf ) UniformDataWriter uniformDataWriter; uniformDataWriter.Start(program); - + // FIXME: Use entity block for this uniformDataWriter.SetUniformMatrix4x4( UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); @@ -2304,8 +2304,8 @@ static void RB_SurfaceSprites( srfSprites_t *surf ) } void (*rb_surfaceTable[SF_NUM_SURFACE_TYPES])( void *) = { - (void(*)(void*))RB_SurfaceBad, // SF_BAD, - (void(*)(void*))RB_SurfaceSkip, // SF_SKIP, + (void(*)(void*))RB_SurfaceBad, // SF_BAD, + (void(*)(void*))RB_SurfaceSkip, // SF_SKIP, (void(*)(void*))RB_SurfaceBSPFace, // SF_FACE, (void(*)(void*))RB_SurfaceBSPGrid, // SF_GRID, (void(*)(void*))RB_SurfaceBSPTriangles, // SF_TRIANGLES, diff --git a/codemp/rd-vanilla/tr_surface.cpp b/codemp/rd-vanilla/tr_surface.cpp index 3be021dce6..5fd11fb24f 100644 --- a/codemp/rd-vanilla/tr_surface.cpp +++ b/codemp/rd-vanilla/tr_surface.cpp @@ -430,7 +430,7 @@ static void RB_SurfaceBeam( void ) qglColor3f( 1, 0, 0 ); qglBegin( GL_TRIANGLE_STRIP ); - for ( i = 0; i <= NUM_BEAM_SEGS; i++ ) { + for ( i = 0; i < NUM_BEAM_SEGS; i++ ) { qglVertex3fv( start_points[ i % NUM_BEAM_SEGS] ); qglVertex3fv( end_points[ i % NUM_BEAM_SEGS] ); } From 3585e7183cc1edf7c323b741ac5dac907477b673 Mon Sep 17 00:00:00 2001 From: Razish Date: Sun, 18 Feb 2024 01:31:22 +1100 Subject: [PATCH 2/3] revert RT_BEAM changes the extra iteration is intentional to seal the tri strip --- code/rd-vanilla/tr_surface.cpp | 2 +- codemp/rd-rend2/tr_surface.cpp | 2 +- codemp/rd-vanilla/tr_surface.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code/rd-vanilla/tr_surface.cpp b/code/rd-vanilla/tr_surface.cpp index ddcef29214..1e51e71c90 100644 --- a/code/rd-vanilla/tr_surface.cpp +++ b/code/rd-vanilla/tr_surface.cpp @@ -1111,7 +1111,7 @@ static void RB_SurfaceBeam( void ) } qglBegin( GL_TRIANGLE_STRIP ); - for ( i = 0; i < NUM_BEAM_SEGS; i++ ) { + for ( i = 0; i <= NUM_BEAM_SEGS; i++ ) { qglVertex3fv( start_points[ i % NUM_BEAM_SEGS] ); qglVertex3fv( end_points[ i % NUM_BEAM_SEGS] ); } diff --git a/codemp/rd-rend2/tr_surface.cpp b/codemp/rd-rend2/tr_surface.cpp index 025e2574a4..95bb89c24e 100644 --- a/codemp/rd-rend2/tr_surface.cpp +++ b/codemp/rd-rend2/tr_surface.cpp @@ -658,7 +658,7 @@ static void RB_SurfaceBeam( void ) tess.minIndex = 0; tess.maxIndex = 0; - for ( i = 0; i < NUM_BEAM_SEGS; i++ ) { + for ( i = 0; i <= NUM_BEAM_SEGS; i++ ) { VectorCopy(start_points[ i % NUM_BEAM_SEGS ], tess.xyz[tess.numVertexes++]); VectorCopy(end_points [ i % NUM_BEAM_SEGS ], tess.xyz[tess.numVertexes++]); } diff --git a/codemp/rd-vanilla/tr_surface.cpp b/codemp/rd-vanilla/tr_surface.cpp index 5fd11fb24f..3be021dce6 100644 --- a/codemp/rd-vanilla/tr_surface.cpp +++ b/codemp/rd-vanilla/tr_surface.cpp @@ -430,7 +430,7 @@ static void RB_SurfaceBeam( void ) qglColor3f( 1, 0, 0 ); qglBegin( GL_TRIANGLE_STRIP ); - for ( i = 0; i < NUM_BEAM_SEGS; i++ ) { + for ( i = 0; i <= NUM_BEAM_SEGS; i++ ) { qglVertex3fv( start_points[ i % NUM_BEAM_SEGS] ); qglVertex3fv( end_points[ i % NUM_BEAM_SEGS] ); } From 9771007c7488904bcc7a142f066197e1da6ffa51 Mon Sep 17 00:00:00 2001 From: Razish Date: Sun, 18 Feb 2024 01:33:04 +1100 Subject: [PATCH 3/3] revert inadvertent whitespace changes --- codemp/rd-rend2/tr_surface.cpp | 96 +++++++++++++++++----------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/codemp/rd-rend2/tr_surface.cpp b/codemp/rd-rend2/tr_surface.cpp index 95bb89c24e..fc3255a5ed 100644 --- a/codemp/rd-rend2/tr_surface.cpp +++ b/codemp/rd-rend2/tr_surface.cpp @@ -240,14 +240,14 @@ void RB_InstantQuad(vec4_t quadVerts[4]) VectorSet2(texCoords[3], 0.0f, 1.0f); GLSL_BindProgram(&tr.textureColorShader); - + GLSL_SetUniformMatrix4x4(&tr.textureColorShader, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); GLSL_SetUniformVec4(&tr.textureColorShader, UNIFORM_COLOR, colorWhite); RB_InstantQuad2(quadVerts, texCoords); } -void RB_InstantTriangle() +void RB_InstantTriangle() { qglDrawArrays(GL_TRIANGLES, 0, 3); } @@ -273,7 +273,7 @@ static void RB_SurfaceSprite( void ) { } else { float s, c; float ang; - + ang = M_PI * ent->e.rotation / 180; s = sin( ang ); c = cos( ang ); @@ -310,17 +310,17 @@ static void RB_SurfaceOrientedQuad( void ) VectorCopy( backEnd.currentEntity->e.axis[1], left ); VectorCopy( backEnd.currentEntity->e.axis[2], up ); - if ( backEnd.currentEntity->e.rotation == 0 ) + if ( backEnd.currentEntity->e.rotation == 0 ) { VectorScale( left, radius, left ); VectorScale( up, radius, up ); - } - else + } + else { vec3_t tempLeft, tempUp; float s, c; float ang; - + ang = M_PI * backEnd.currentEntity->e.rotation / 180; s = sin( ang ); c = cos( ang ); @@ -336,7 +336,7 @@ static void RB_SurfaceOrientedQuad( void ) VectorCopy( tempLeft, left ); } - if ( backEnd.viewParms.isMirror ) + if ( backEnd.viewParms.isMirror ) { VectorSubtract( vec3_origin, left, left ); } @@ -679,12 +679,12 @@ static void RB_SurfaceBeam( void ) // FIXME: A lot of this can probably be removed for speed, and refactored into a more convenient function RB_UpdateVBOs(ATTR_POSITION); - + GLSL_VertexAttribsState(ATTR_POSITION, NULL); GLSL_BindProgram(sp); - + GLSL_SetUniformMatrix4x4(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); - + GLSL_SetUniformVec4(sp, UNIFORM_COLOR, colorRed); R_DrawElementsVBO(tess.numIndexes, tess.firstIndex, tess.minIndex, tess.maxIndex); @@ -702,13 +702,13 @@ static void RB_SurfaceBeam( void ) //------------------ // DoSprite //------------------ -static void DoSprite( vec3_t origin, float radius, float rotation ) +static void DoSprite( vec3_t origin, float radius, float rotation ) { float s, c; float ang; vec3_t left, up; float color[4]; - + ang = M_PI * rotation / 180.0f; s = sin( ang ); c = cos( ang ); @@ -719,7 +719,7 @@ static void DoSprite( vec3_t origin, float radius, float rotation ) VectorScale( backEnd.viewParms.ori.axis[2], c * radius, up ); VectorMA( up, s * radius, backEnd.viewParms.ori.axis[1], up ); - if ( backEnd.viewParms.isMirror ) + if ( backEnd.viewParms.isMirror ) { VectorSubtract( vec3_origin, left, left ); } @@ -733,7 +733,7 @@ static void DoSprite( vec3_t origin, float radius, float rotation ) // RB_SurfaceSaber //------------------ static void RB_SurfaceSaberGlow() -{ +{ vec3_t end; refEntity_t *e; @@ -765,13 +765,13 @@ RB_SurfaceLine // STScale (how many times to loop a texture) // alpha // RGB -// +// // Values for proper line object... // lifetime // dscale // startalpha, endalpha // startRGB, endRGB -// +// static void DoLine( const vec3_t start, const vec3_t end, const vec3_t up, float spanWidth ) { @@ -907,7 +907,7 @@ static void DoLine_Oriented( const vec3_t start, const vec3_t end, const vec3_t //----------------- // RB_SurfaceLine //----------------- -static void RB_SurfaceLine( void ) +static void RB_SurfaceLine( void ) { refEntity_t *e; vec3_t right; @@ -928,7 +928,7 @@ static void RB_SurfaceLine( void ) DoLine( start, end, right, e->radius); } -static void RB_SurfaceOrientedLine( void ) +static void RB_SurfaceOrientedLine( void ) { refEntity_t *e; vec3_t right; @@ -971,7 +971,7 @@ static void DoCylinderPart(polyVert_t *verts) VectorScale4 (verts->modulate, 1.0f / 255.0f, tess.vertexColors[tess.numVertexes]); tess.numVertexes++; verts++; - } + } tess.indexes[tess.numIndexes++] = vbase; tess.indexes[tess.numIndexes++] = vbase + 1; @@ -1036,12 +1036,12 @@ static void RB_SurfaceCylinder( void ) //Upper ring RotatePointAroundVector( upper_points[i].xyz, e->axis[0], vu, detail * i ); VectorAdd( upper_points[i].xyz, e->origin, upper_points[i].xyz ); - + //Lower ring RotatePointAroundVector( lower_points[i].xyz, e->axis[0], v1, detail * i ); VectorAdd( lower_points[i].xyz, e->oldorigin, lower_points[i].xyz ); } - + // Calculate the texture coords so the texture can wrap around the whole cylinder detail = 1.0f / (float)segments; @@ -1136,7 +1136,7 @@ static void ApplyShape( vec3_t start, vec3_t end, vec3_t right, float sradius, f DoLine2( start, end, right, sradius, eradius ); return; } - + CreateShape(); VectorSubtract( end, start, fwd ); @@ -1165,7 +1165,7 @@ static void ApplyShape( vec3_t start, vec3_t end, vec3_t right, float sradius, f VectorMA( point2, 1.0f - perc, end, point2 ); VectorMA( point2, dis * sh2[1], rt, point2 ); VectorMA( point2, dis * sh2[2], up, point2 ); - + // recursion ApplyShape( point2, point1, right, rads1, rads2, count - 1 ); ApplyShape( point2, end, right, rads2, eradius, count - 1 ); @@ -1191,7 +1191,7 @@ static void DoBoltSeg( vec3_t start, vec3_t end, vec3_t right, float radius ) MakeNormalVectors( fwd, rt, up ); VectorCopy( start, old ); - + oldRadius = newRadius = radius; for ( i = 20; i <= dis; i+= 20 ) @@ -1231,7 +1231,7 @@ static void DoBoltSeg( vec3_t start, vec3_t end, vec3_t right, float radius ) // Apply the random shape to our line seg to give it some micro-detail-jaggy-coolness. ApplyShape( cur, old, right, newRadius, oldRadius, LIGHTNING_RECURSION_LEVEL ); - + // randomly split off to create little tendrils, but don't do it too close to the end and especially if we are not even of the forked variety if ( ( e->renderfx & RF_FORKED ) && f_count > 0 && Q_random(&e->frame) > 0.94f && radius * (1.0f - perc) > 0.2f ) { @@ -1316,13 +1316,13 @@ static void RB_SurfaceElectricity() static void VectorArrayNormalize(vec4_t *normals, unsigned int count) { // assert(count); - + #if idppc { register float half = 0.5; register float one = 1.0; float *components = (float *)normals; - + // Vanilla PPC code, but since PPC has a reciprocal square root estimate instruction, // runs *much* faster than calling sqrt(). We'll use a single Newton-Raphson // refinement step to get a little more precision. This seems to yeild results @@ -1331,14 +1331,14 @@ static void VectorArrayNormalize(vec4_t *normals, unsigned int count) do { float x, y, z; float B, y0, y1; - + x = components[0]; y = components[1]; z = components[2]; components += 4; B = x*x + y*y + z*z; -#ifdef __GNUC__ +#ifdef __GNUC__ asm("frsqrte %0,%1" : "=f" (y0) : "f" (B)); #else y0 = __frsqrte(B); @@ -1404,11 +1404,11 @@ static void LerpMeshVertexes_altivec(md3Surface_t *surf, float backlerp) vector unsigned char newNormalsLoadPermute; vector unsigned char newNormalsStorePermute; vector float zero; - + newNormalsStorePermute = vec_lvsl(0,(float *)&newXyzScaleVec); newXyzScaleVec = *(vector float *)&newXyzScale; newXyzScaleVec = vec_perm(newXyzScaleVec,newXyzScaleVec,newNormalsStorePermute); - newXyzScaleVec = vec_splat(newXyzScaleVec,0); + newXyzScaleVec = vec_splat(newXyzScaleVec,0); newNormalsLoadPermute = vec_lvsl(0,newXyz); newNormalsStorePermute = vec_lvsr(0,outXyz); zero = (vector float)vec_splat_s8(0); @@ -1417,7 +1417,7 @@ static void LerpMeshVertexes_altivec(md3Surface_t *surf, float backlerp) // for (vertNum=0 ; vertNum < numVerts ; vertNum++, newXyz += 4, newNormals += 4, - outXyz += 4, outNormal += 4) + outXyz += 4, outNormal += 4) { newNormalsLoadPermute = vec_lvsl(0,newXyz); newNormalsStorePermute = vec_lvsr(0,outXyz); @@ -1462,7 +1462,7 @@ static void LerpMeshVertexes_altivec(md3Surface_t *surf, float backlerp) for (vertNum=0 ; vertNum < numVerts ; vertNum++, oldXyz += 4, newXyz += 4, oldNormals += 4, newNormals += 4, - outXyz += 4, outNormal += 4) + outXyz += 4, outNormal += 4) { vec3_t uncompressedOldNormal, uncompressedNewNormal; @@ -1530,7 +1530,7 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp) // for (vertNum=0 ; vertNum < numVerts ; vertNum++, newXyz += 4, newNormals += 4, - outXyz += 4, outNormal += 4) + outXyz += 4, outNormal += 4) { outXyz[0] = newXyz[0] * newXyzScale; @@ -1563,7 +1563,7 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp) for (vertNum=0 ; vertNum < numVerts ; vertNum++, oldXyz += 4, newXyz += 4, oldNormals += 4, newNormals += 4, - outXyz += 4, outNormal += 4) + outXyz += 4, outNormal += 4) { vec3_t uncompressedOldNormal, uncompressedNewNormal; @@ -1742,11 +1742,11 @@ static float LodErrorForVolume( vec3_t local, float radius ) { return 0; } - world[0] = local[0] * backEnd.ori.axis[0][0] + local[1] * backEnd.ori.axis[1][0] + + world[0] = local[0] * backEnd.ori.axis[0][0] + local[1] * backEnd.ori.axis[1][0] + local[2] * backEnd.ori.axis[2][0] + backEnd.ori.origin[0]; - world[1] = local[0] * backEnd.ori.axis[0][1] + local[1] * backEnd.ori.axis[1][1] + + world[1] = local[0] * backEnd.ori.axis[0][1] + local[1] * backEnd.ori.axis[1][1] + local[2] * backEnd.ori.axis[2][1] + backEnd.ori.origin[1]; - world[2] = local[0] * backEnd.ori.axis[0][2] + local[1] * backEnd.ori.axis[1][2] + + world[2] = local[0] * backEnd.ori.axis[0][2] + local[1] * backEnd.ori.axis[1][2] + local[2] * backEnd.ori.axis[2][2] + backEnd.ori.origin[2]; VectorSubtract( world, backEnd.viewParms.ori.origin, world ); @@ -1848,7 +1848,7 @@ static void RB_SurfaceBSPGrid( srfBspSurface_t *srf ) { break; } } while ( 1 ); - + rows = irows; if ( vrows < irows + 1 ) { rows = vrows - 1; @@ -1932,7 +1932,7 @@ static void RB_SurfaceBSPGrid( srfBspSurface_t *srf ) { for (i = 0 ; i < h ; i++) { for (j = 0 ; j < w ; j++) { int v1, v2, v3, v4; - + // vertex order to be reckognized as tristrips v1 = numVertexes + i*lodWidth + j + 1; v2 = v1 - 1; @@ -1942,7 +1942,7 @@ static void RB_SurfaceBSPGrid( srfBspSurface_t *srf ) { tess.indexes[numIndexes] = v2; tess.indexes[numIndexes+1] = v3; tess.indexes[numIndexes+2] = v1; - + tess.indexes[numIndexes+3] = v1; tess.indexes[numIndexes+4] = v3; tess.indexes[numIndexes+5] = v4; @@ -2043,7 +2043,7 @@ static void RB_SurfaceEntity( surfaceType_t *surfType ) { const int count = backEnd.currentEntity->e.uRefEnt.uMini.miniCount; assert(count > 0); backEnd.currentEntity = &tempEnt; - + assert(backEnd.currentEntity->e.renderfx >= 0); for (int i = 0, j = start; i < count; i++, j++) @@ -2094,7 +2094,7 @@ void RB_SurfaceVBOMDVMesh(srfVBOMDVMesh_t * surface) RB_EndSurface(); } - //drawSurf_t drawSurf = + //drawSurf_t drawSurf = R_BindVBO(surface->vbo); R_BindIBO(surface->ibo); @@ -2197,7 +2197,7 @@ static void RB_SurfaceSprites( srfSprites_t *surf ) // TODO: Do we want a 2-level lod system where far away sprites are // just flat surfaces? - + // TODO: Check which pass (z-prepass/shadow/forward) we're rendering for? shader_t *shader = surf->shader; shaderStage_t *firstStage = shader->stages[0]; @@ -2231,7 +2231,7 @@ static void RB_SurfaceSprites( srfSprites_t *surf ) UniformDataWriter uniformDataWriter; uniformDataWriter.Start(program); - + // FIXME: Use entity block for this uniformDataWriter.SetUniformMatrix4x4( UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); @@ -2304,8 +2304,8 @@ static void RB_SurfaceSprites( srfSprites_t *surf ) } void (*rb_surfaceTable[SF_NUM_SURFACE_TYPES])( void *) = { - (void(*)(void*))RB_SurfaceBad, // SF_BAD, - (void(*)(void*))RB_SurfaceSkip, // SF_SKIP, + (void(*)(void*))RB_SurfaceBad, // SF_BAD, + (void(*)(void*))RB_SurfaceSkip, // SF_SKIP, (void(*)(void*))RB_SurfaceBSPFace, // SF_FACE, (void(*)(void*))RB_SurfaceBSPGrid, // SF_GRID, (void(*)(void*))RB_SurfaceBSPTriangles, // SF_TRIANGLES,