diff --git a/ref/soft/r_aclip.c b/ref/soft/r_aclip.c index 4b38d5b8..647d34fe 100644 --- a/ref/soft/r_aclip.c +++ b/ref/soft/r_aclip.c @@ -21,17 +21,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" -static finalvert_t fv[2][8]; +static finalvert_t fv[2][8]; -void R_AliasProjectAndClipTestFinalVert (finalvert_t *fv); -void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, - finalvert_t *out); -void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1, - finalvert_t *out); -void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, - finalvert_t *out); -void R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1, - finalvert_t *out); +void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ); +void R_Alias_clip_top( finalvert_t *pfv0, finalvert_t *pfv1, + finalvert_t *out ); +void R_Alias_clip_bottom( finalvert_t *pfv0, finalvert_t *pfv1, + finalvert_t *out ); +void R_Alias_clip_left( finalvert_t *pfv0, finalvert_t *pfv1, + finalvert_t *out ); +void R_Alias_clip_right( finalvert_t *pfv0, finalvert_t *pfv1, + finalvert_t *out ); /* @@ -41,169 +41,169 @@ R_Alias_clip_z pfv0 is the unclipped vertex, pfv1 is the z-clipped vertex ================ */ -static void R_Alias_clip_z (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) +static void R_Alias_clip_z( finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out ) { - float scale; + float scale; - scale = (ALIAS_Z_CLIP_PLANE - pfv0->xyz[2]) / - (pfv1->xyz[2] - pfv0->xyz[2]); + scale = ( ALIAS_Z_CLIP_PLANE - pfv0->xyz[2] ) + / ( pfv1->xyz[2] - pfv0->xyz[2] ); - out->xyz[0] = pfv0->xyz[0] + (pfv1->xyz[0] - pfv0->xyz[0]) * scale; - out->xyz[1] = pfv0->xyz[1] + (pfv1->xyz[1] - pfv0->xyz[1]) * scale; + out->xyz[0] = pfv0->xyz[0] + ( pfv1->xyz[0] - pfv0->xyz[0] ) * scale; + out->xyz[1] = pfv0->xyz[1] + ( pfv1->xyz[1] - pfv0->xyz[1] ) * scale; out->xyz[2] = ALIAS_Z_CLIP_PLANE; - out->s = pfv0->s + (pfv1->s - pfv0->s) * scale; - out->t = pfv0->t + (pfv1->t - pfv0->t) * scale; - out->l = pfv0->l + (pfv1->l - pfv0->l) * scale; + out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale; + out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale; + out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale; - R_AliasProjectAndClipTestFinalVert (out); + R_AliasProjectAndClipTestFinalVert( out ); } -void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) +void R_Alias_clip_left( finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out ) { - float scale; + float scale; - if (pfv0->v >= pfv1->v ) + if( pfv0->v >= pfv1->v ) { - scale = (float)(RI.aliasvrect.x - pfv0->u) / - (pfv1->u - pfv0->u); - out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5f; - out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5f; - out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5f; - out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5f; - out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5f; - out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5f; + scale = (float)( RI.aliasvrect.x - pfv0->u ) + / ( pfv1->u - pfv0->u ); + out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5f; + out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5f; + out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5f; + out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5f; + out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5f; + out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi ) * scale + 0.5f; } else { - scale = (float)(RI.aliasvrect.x - pfv1->u) / - (pfv0->u - pfv1->u); - out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5f; - out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5f; - out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5f; - out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5f; - out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5f; - out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5f; + scale = (float)( RI.aliasvrect.x - pfv1->u ) + / ( pfv0->u - pfv1->u ); + out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5f; + out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5f; + out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5f; + out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5f; + out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5f; + out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi ) * scale + 0.5f; } } -void R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) +void R_Alias_clip_right( finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out ) { - float scale; + float scale; - if ( pfv0->v >= pfv1->v ) + if( pfv0->v >= pfv1->v ) { - scale = (float)(RI.aliasvrectright - pfv0->u ) / - (pfv1->u - pfv0->u ); - out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5f; - out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5f; - out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5f; - out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5f; - out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5f; - out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5f; + scale = (float)( RI.aliasvrectright - pfv0->u ) + / ( pfv1->u - pfv0->u ); + out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5f; + out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5f; + out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5f; + out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5f; + out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5f; + out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi ) * scale + 0.5f; } else { - scale = (float)(RI.aliasvrectright - pfv1->u ) / - (pfv0->u - pfv1->u ); - out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5f; - out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5f; - out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5f; - out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5f; - out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5f; - out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5f; + scale = (float)( RI.aliasvrectright - pfv1->u ) + / ( pfv0->u - pfv1->u ); + out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5f; + out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5f; + out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5f; + out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5f; + out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5f; + out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi ) * scale + 0.5f; } } -void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) +void R_Alias_clip_top( finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out ) { - float scale; + float scale; - if (pfv0->v >= pfv1->v) + if( pfv0->v >= pfv1->v ) { - scale = (float)(RI.aliasvrect.y - pfv0->v) / - (pfv1->v - pfv0->v); - out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5f; - out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5f; - out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5f; - out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5f; - out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5f; - out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5f; + scale = (float)( RI.aliasvrect.y - pfv0->v ) + / ( pfv1->v - pfv0->v ); + out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5f; + out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5f; + out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5f; + out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5f; + out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5f; + out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi ) * scale + 0.5f; } else { - scale = (float)(RI.aliasvrect.y - pfv1->v) / - (pfv0->v - pfv1->v); - out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5f; - out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5f; - out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5f; - out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5f; - out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5f; - out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5f; + scale = (float)( RI.aliasvrect.y - pfv1->v ) + / ( pfv0->v - pfv1->v ); + out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5f; + out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5f; + out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5f; + out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5f; + out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5f; + out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi ) * scale + 0.5f; } } -void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1, - finalvert_t *out) +void R_Alias_clip_bottom( finalvert_t *pfv0, finalvert_t *pfv1, + finalvert_t *out ) { - float scale; + float scale; - if (pfv0->v >= pfv1->v) + if( pfv0->v >= pfv1->v ) { - scale = (float)(RI.aliasvrectbottom - pfv0->v) / - (pfv1->v - pfv0->v); + scale = (float)( RI.aliasvrectbottom - pfv0->v ) + / ( pfv1->v - pfv0->v ); - out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5f; - out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5f; - out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5f; - out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5f; - out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5f; - out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5f; + out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5f; + out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5f; + out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5f; + out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5f; + out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5f; + out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi ) * scale + 0.5f; } else { - scale = (float)(RI.aliasvrectbottom - pfv1->v) / - (pfv0->v - pfv1->v); + scale = (float)( RI.aliasvrectbottom - pfv1->v ) + / ( pfv0->v - pfv1->v ); - out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5f; - out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5f; - out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5f; - out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5f; - out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5f; - out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5f; + out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5f; + out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5f; + out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5f; + out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5f; + out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5f; + out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi ) * scale + 0.5f; } } -static int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count, - void(*clip)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) ) +static int R_AliasClip( finalvert_t *in, finalvert_t *out, int flag, int count, + void ( *clip )( finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out )) { - int i,j,k; - int flags, oldflags; + int i, j, k; + int flags, oldflags; - j = count-1; + j = count - 1; k = 0; - for (i=0 ; i RI.aliasvrectright) + if( out[k].u > RI.aliasvrectright ) out[k].flags |= ALIAS_RIGHT_CLIP; - if (out[k].v > RI.aliasvrectbottom) + if( out[k].v > RI.aliasvrectbottom ) out[k].flags |= ALIAS_BOTTOM_CLIP; k++; } - if (!flags) + if( !flags ) { out[k] = in[i]; k++; @@ -218,10 +218,10 @@ static int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count, R_AliasClipTriangle ================ */ -void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2) +void R_AliasClipTriangle( finalvert_t *index0, finalvert_t *index1, finalvert_t *index2 ) { - int i, k, pingpong; - unsigned clipflags; + int i, k, pingpong; + unsigned clipflags; // copy vertexes and fix seam texture coordinates fv[0][0] = *index0; @@ -231,10 +231,10 @@ void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t // clip clipflags = fv[0][0].flags | fv[0][1].flags | fv[0][2].flags; - if (clipflags & ALIAS_Z_CLIP) + if( clipflags & ALIAS_Z_CLIP ) { - k = R_AliasClip (fv[0], fv[1], ALIAS_Z_CLIP, 3, R_Alias_clip_z); - if (k == 0) + k = R_AliasClip( fv[0], fv[1], ALIAS_Z_CLIP, 3, R_Alias_clip_z ); + if( k == 0 ) return; pingpong = 1; @@ -246,67 +246,67 @@ void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t k = 3; } - if (clipflags & ALIAS_LEFT_CLIP) + if( clipflags & ALIAS_LEFT_CLIP ) { - k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1], - ALIAS_LEFT_CLIP, k, R_Alias_clip_left); - if (k == 0) + k = R_AliasClip( fv[pingpong], fv[pingpong ^ 1], + ALIAS_LEFT_CLIP, k, R_Alias_clip_left ); + if( k == 0 ) return; pingpong ^= 1; } - if (clipflags & ALIAS_RIGHT_CLIP) + if( clipflags & ALIAS_RIGHT_CLIP ) { - k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1], - ALIAS_RIGHT_CLIP, k, R_Alias_clip_right); - if (k == 0) + k = R_AliasClip( fv[pingpong], fv[pingpong ^ 1], + ALIAS_RIGHT_CLIP, k, R_Alias_clip_right ); + if( k == 0 ) return; pingpong ^= 1; } - if (clipflags & ALIAS_BOTTOM_CLIP) + if( clipflags & ALIAS_BOTTOM_CLIP ) { - k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1], - ALIAS_BOTTOM_CLIP, k, R_Alias_clip_bottom); - if (k == 0) + k = R_AliasClip( fv[pingpong], fv[pingpong ^ 1], + ALIAS_BOTTOM_CLIP, k, R_Alias_clip_bottom ); + if( k == 0 ) return; pingpong ^= 1; } - if (clipflags & ALIAS_TOP_CLIP) + if( clipflags & ALIAS_TOP_CLIP ) { - k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1], - ALIAS_TOP_CLIP, k, R_Alias_clip_top); - if (k == 0) + k = R_AliasClip( fv[pingpong], fv[pingpong ^ 1], + ALIAS_TOP_CLIP, k, R_Alias_clip_top ); + if( k == 0 ) return; pingpong ^= 1; } - for (i=0 ; i RI.aliasvrectright) + else if( fv[pingpong][i].u > RI.aliasvrectright ) fv[pingpong][i].u = RI.aliasvrectright; - if (fv[pingpong][i].v < RI.aliasvrect.y) + if( fv[pingpong][i].v < RI.aliasvrect.y ) fv[pingpong][i].v = RI.aliasvrect.y; - else if (fv[pingpong][i].v > RI.aliasvrectbottom) + else if( fv[pingpong][i].v > RI.aliasvrectbottom ) fv[pingpong][i].v = RI.aliasvrectbottom; fv[pingpong][i].flags = 0; } // draw triangles - for (i=1 ; i> 1; - if( divs < 2 ) return; + if( divs < 2 ) + return; // noise is normalized to +/- scale noise[div2] = ( noise[0] + noise[divs] ) * 0.5f + divs * gEngfuncs.COM_RandomFloat( -0.125f, 0.125f ); @@ -62,9 +63,9 @@ static void FracNoise( float *noise, int divs ) static void SineNoise( float *noise, int divs ) { - float freq = 0; - float step = M_PI_F / (float)divs; - int i; + float freq = 0; + float step = M_PI_F / (float)divs; + int i; for( i = 0; i < divs; i++ ) { @@ -84,7 +85,7 @@ BEAM MATHLIB static void R_BeamComputePerpendicular( const vec3_t vecBeamDelta, vec3_t pPerp ) { // direction in worldspace of the center of the beam - vec3_t vecBeamCenter; + vec3_t vecBeamCenter; VectorNormalize2( vecBeamDelta, vecBeamCenter ); CrossProduct( RI.vforward, vecBeamCenter, pPerp ); @@ -94,7 +95,7 @@ static void R_BeamComputePerpendicular( const vec3_t vecBeamDelta, vec3_t pPerp static void R_BeamComputeNormal( const vec3_t vStartPos, const vec3_t vNextPos, vec3_t pNormal ) { // vTangentY = line vector for beam - vec3_t vTangentY, vDirToBeam; + vec3_t vTangentY, vDirToBeam; VectorSubtract( vStartPos, vNextPos, vTangentY ); @@ -117,8 +118,8 @@ Cull the beam by bbox */ qboolean GAME_EXPORT R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly ) { - vec3_t mins, maxs; - int i; + vec3_t mins, maxs; + int i; return false; /* for( i = 0; i < 3; i++ ) @@ -193,14 +194,15 @@ general code for drawing beams */ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments, int flags ) { - int noiseIndex, noiseStep; - int i, total_segs, segs_drawn; - float div, length, fraction, factor; - float flMaxWidth, vLast, vStep, brightness; - vec3_t perp1, vLastNormal = { 0.0f }; - beamseg_t curSeg; + int noiseIndex, noiseStep; + int i, total_segs, segs_drawn; + float div, length, fraction, factor; + float flMaxWidth, vLast, vStep, brightness; + vec3_t perp1, vLastNormal = { 0.0f }; + beamseg_t curSeg; - if( segments < 2 ) return; + if( segments < 2 ) + return; length = VectorLength( delta ); flMaxWidth = width * 0.5f; @@ -210,15 +212,16 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f { // here, we have too many segments; we could get overlap... so lets have less segments segments = (int)( length / ( flMaxWidth * 1.414f )) + 1.0f; - if( segments < 2 ) segments = 2; + if( segments < 2 ) + segments = 2; } if( segments > NOISE_DIVISIONS ) segments = NOISE_DIVISIONS; - div = 1.0f / (segments - 1); + div = 1.0f / ( segments - 1 ); length *= 0.01f; - vStep = length * div; // Texture length texels per space pixel + vStep = length * div; // Texture length texels per space pixel // Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) vLast = fmod( freq * speed, 1 ); @@ -255,8 +258,8 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f // specify all the segments. for( i = 0; i < segments; i++ ) { - beamseg_t nextSeg; - vec3_t vPoint1, vPoint2; + beamseg_t nextSeg; + vec3_t vPoint1, vPoint2; Assert( noiseIndex < ( NOISE_DIVISIONS << 16 )); @@ -267,17 +270,17 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f // distort using noise if( scale != 0 ) { - factor = rgNoise[noiseIndex>>16] * scale; + factor = rgNoise[noiseIndex >> 16] * scale; if( FBitSet( flags, FBEAM_SINENOISE )) { - float s, c; + float s, c; SinCos( fraction * M_PI_F * length + freq, &s, &c ); - VectorMA( nextSeg.pos, (factor * s), RI.vup, nextSeg.pos ); + VectorMA( nextSeg.pos, ( factor * s ), RI.vup, nextSeg.pos ); // rotate the noise along the perpendicluar axis a bit to keep the bolt from looking diagonal - VectorMA( nextSeg.pos, (factor * c), RI.vright, nextSeg.pos ); + VectorMA( nextSeg.pos, ( factor * c ), RI.vright, nextSeg.pos ); } else { @@ -289,11 +292,11 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f nextSeg.width = width * 2.0f; nextSeg.texcoord = vLast; - if( segs_drawn > 0 ) + if( segs_drawn > 0 ) { // Get a vector that is perpendicular to us and perpendicular to the beam. // This is used to fatten the beam. - vec3_t vNormal, vAveNormal; + vec3_t vNormal, vAveNormal; R_BeamComputeNormal( curSeg.pos, nextSeg.pos, vNormal ); @@ -313,16 +316,16 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f // draw regular segment VectorMA( curSeg.pos, ( curSeg.width * 0.5f ), vAveNormal, vPoint1 ); - VectorMA( curSeg.pos, (-curSeg.width * 0.5f ), vAveNormal, vPoint2 ); + VectorMA( curSeg.pos, ( -curSeg.width * 0.5f ), vAveNormal, vPoint2 ); TriTexCoord2f( 0.0f, curSeg.texcoord ); TriBrightness( brightness ); - //pglNormal3fv( vAveNormal ); + // pglNormal3fv( vAveNormal ); TriVertex3fv( vPoint1 ); TriTexCoord2f( 1.0f, curSeg.texcoord ); TriBrightness( brightness ); - //pflNormal3fv( vAveNormal ); + // pflNormal3fv( vAveNormal ); TriVertex3fv( vPoint2 ); } @@ -331,8 +334,10 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f if( FBitSet( flags, FBEAM_SHADEIN ) && FBitSet( flags, FBEAM_SHADEOUT )) { - if( fraction < 0.5f ) brightness = fraction; - else brightness = ( 1.0f - fraction ); + if( fraction < 0.5f ) + brightness = fraction; + else + brightness = ( 1.0f - fraction ); } else if( FBitSet( flags, FBEAM_SHADEIN )) { @@ -343,21 +348,21 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f brightness = 1.0f - fraction; } - if( segs_drawn == total_segs ) + if( segs_drawn == total_segs ) { // draw the last segment VectorMA( curSeg.pos, ( curSeg.width * 0.5f ), vLastNormal, vPoint1 ); - VectorMA( curSeg.pos, (-curSeg.width * 0.5f ), vLastNormal, vPoint2 ); + VectorMA( curSeg.pos, ( -curSeg.width * 0.5f ), vLastNormal, vPoint2 ); // specify the points. TriTexCoord2f( 0.0f, curSeg.texcoord ); TriBrightness( brightness ); - //pglNormal3fv( vLastNormal ); + // pglNormal3fv( vLastNormal ); TriVertex3fv( vPoint1 ); TriTexCoord2f( 1.0f, curSeg.texcoord ); TriBrightness( brightness ); - //pglNormal3fv( vLastNormal ); + // pglNormal3fv( vLastNormal ); TriVertex3fv( vPoint2 ); } @@ -375,9 +380,9 @@ Draw beamtours */ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments ) { - int i, noiseIndex, noiseStep; - float div, length, fraction, factor, vLast, vStep; - vec3_t last1, last2, point, screen, screenLast, tmp, normal; + int i, noiseIndex, noiseStep; + float div, length, fraction, factor, vLast, vStep; + vec3_t last1, last2, point, screen, screenLast, tmp, normal; if( segments < 2 ) return; @@ -386,9 +391,10 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, segments = NOISE_DIVISIONS; length = VectorLength( delta ) * 0.01f; - if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams + if( length < 0.5f ) + length = 0.5f; // don't lose all of the noise/texture on short beams - div = 1.0f / (segments - 1); + div = 1.0f / ( segments - 1 ); vStep = length * div; // Texture length texels per space pixel @@ -402,7 +408,7 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, for( i = 0; i < segments; i++ ) { - float s, c; + float s, c; fraction = i * div; SinCos( fraction * M_PI2, &s, &c ); @@ -416,11 +422,11 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, { if(( noiseIndex >> 16 ) < NOISE_DIVISIONS ) { - factor = rgNoise[noiseIndex>>16] * scale; + factor = rgNoise[noiseIndex >> 16] * scale; VectorMA( point, factor, RI.vup, point ); // rotate the noise along the perpendicluar axis a bit to keep the bolt from looking diagonal - factor = rgNoise[noiseIndex>>16] * scale * cos( fraction * M_PI_F * 3 + freq ); + factor = rgNoise[noiseIndex >> 16] * scale * cos( fraction *M_PI_F * 3 + freq ); VectorMA( point, factor, RI.vright, point ); } } @@ -436,7 +442,7 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, // we don't need Z, we're in screen space tmp[2] = 0; VectorNormalize( tmp ); - VectorScale( RI.vup, -tmp[0], normal ); // Build point along noraml line (normal is -y, x) + VectorScale( RI.vup, -tmp[0], normal ); // Build point along noraml line (normal is -y, x) VectorMA( normal, tmp[1], RI.vright, normal ); // Make a wide line @@ -464,22 +470,23 @@ Draw beamdisk */ static void R_DrawDisk( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments ) { - float div, length, fraction; - float w, vLast, vStep; - vec3_t point; - int i; + float div, length, fraction; + float w, vLast, vStep; + vec3_t point; + int i; if( segments < 2 ) return; - if( segments > NOISE_DIVISIONS ) // UNDONE: Allow more segments? + if( segments > NOISE_DIVISIONS ) // UNDONE: Allow more segments? segments = NOISE_DIVISIONS; length = VectorLength( delta ) * 0.01f; - if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams + if( length < 0.5f ) + length = 0.5f; // don't lose all of the noise/texture on short beams - div = 1.0f / (segments - 1); - vStep = length * div; // Texture length texels per space pixel + div = 1.0f / ( segments - 1 ); + vStep = length * div; // Texture length texels per space pixel // scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) vLast = fmod( freq * speed, 1 ); @@ -491,7 +498,7 @@ static void R_DrawDisk( vec3_t source, vec3_t delta, float width, float scale, f // NOTE: we must force the degenerate triangles to be on the edge for( i = 0; i < segments; i++ ) { - float s, c; + float s, c; fraction = i * div; VectorCopy( source, point ); @@ -509,7 +516,7 @@ static void R_DrawDisk( vec3_t source, vec3_t delta, float width, float scale, f TriTexCoord2f( 0.0f, vLast ); TriVertex3fv( point ); - vLast += vStep; // advance texture scroll (v axis only) + vLast += vStep; // advance texture scroll (v axis only) } } @@ -522,10 +529,10 @@ Draw beam cylinder */ static void R_DrawCylinder( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments ) { - float div, length, fraction; - float vLast, vStep; - vec3_t point; - int i; + float div, length, fraction; + float vLast, vStep; + vec3_t point; + int i; if( segments < 2 ) return; @@ -534,18 +541,19 @@ static void R_DrawCylinder( vec3_t source, vec3_t delta, float width, float scal segments = NOISE_DIVISIONS; length = VectorLength( delta ) * 0.01f; - if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams + if( length < 0.5f ) + length = 0.5f; // don't lose all of the noise/texture on short beams - div = 1.0f / (segments - 1); - vStep = length * div; // texture length texels per space pixel + div = 1.0f / ( segments - 1 ); + vStep = length * div; // texture length texels per space pixel // Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) vLast = fmod( freq * speed, 1 ); scale = scale * length; - for ( i = 0; i < segments; i++ ) + for( i = 0; i < segments; i++ ) { - float s, c; + float s, c; fraction = i * div; SinCos( fraction * M_PI2, &s, &c ); @@ -566,7 +574,7 @@ static void R_DrawCylinder( vec3_t source, vec3_t delta, float width, float scal TriTexCoord2f( 0, vLast ); TriVertex3fv( point ); - vLast += vStep; // Advance texture scroll (v axis only) + vLast += vStep; // Advance texture scroll (v axis only) } } @@ -579,10 +587,10 @@ drawi followed beam */ static void R_DrawBeamFollow( BEAM *pbeam, float frametime ) { - particle_t *pnew, *particles; - float fraction, div, vLast, vStep, saved_fraction; - vec3_t last1, last2, tmp, screen, saved_last2; - vec3_t delta, screenLast, normal; + particle_t *pnew, *particles; + float fraction, div, vLast, vStep, saved_fraction; + vec3_t last1, last2, tmp, screen, saved_last2; + vec3_t delta, screenLast, normal; gEngfuncs.R_FreeDeadParticles( &pbeam->particles ); @@ -620,7 +628,8 @@ static void R_DrawBeamFollow( BEAM *pbeam, float frametime ) } // nothing to draw - if( !particles ) return; + if( !particles ) + return; if( !pnew && div != 0 ) { @@ -650,7 +659,7 @@ static void R_DrawBeamFollow( BEAM *pbeam, float frametime ) VectorNormalize( tmp ); // Build point along noraml line (normal is -y, x) - VectorScale( RI.vup, tmp[0], normal ); // Build point along normal line (normal is -y, x) + VectorScale( RI.vup, tmp[0], normal ); // Build point along normal line (normal is -y, x) VectorMA( normal, tmp[1], RI.vright, normal ); // Make a wide line @@ -683,18 +692,18 @@ static void R_DrawBeamFollow( BEAM *pbeam, float frametime ) // we don't need Z, we're in screen space tmp[2] = 0; VectorNormalize( tmp ); - VectorScale( RI.vup, tmp[0], normal ); // Build point along noraml line (normal is -y, x) + VectorScale( RI.vup, tmp[0], normal ); // Build point along noraml line (normal is -y, x) VectorMA( normal, tmp[1], RI.vright, normal ); // Make a wide line VectorMA( particles->org, pbeam->width, normal, last1 ); VectorMA( particles->org, -pbeam->width, normal, last2 ); - vLast += vStep; // Advance texture scroll (v axis only) + vLast += vStep; // Advance texture scroll (v axis only) if( particles->next != NULL ) { - fraction = (particles->die - gp_cl->time) * div; + fraction = ( particles->die - gp_cl->time ) * div; } else { @@ -739,11 +748,11 @@ Draw beamring */ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitude, float freq, float speed, int segments ) { - int i, j, noiseIndex, noiseStep; - float div, length, fraction, factor, vLast, vStep; - vec3_t last1, last2, point, screen, screenLast; - vec3_t tmp, normal, center, xaxis, yaxis; - float radius, x, y, scale; + int i, j, noiseIndex, noiseStep; + float div, length, fraction, factor, vLast, vStep; + vec3_t last1, last2, point, screen, screenLast; + vec3_t tmp, normal, center, xaxis, yaxis; + float radius, x, y, scale; if( segments < 2 ) return; @@ -755,11 +764,12 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud segments = NOISE_DIVISIONS * 8; length = VectorLength( delta ) * 0.01f * M_PI_F; - if( length < 0.5f ) length = 0.5f; // Don't lose all of the noise/texture on short beams + if( length < 0.5f ) + length = 0.5f; // Don't lose all of the noise/texture on short beams div = 1.0f / ( segments - 1 ); - vStep = length * div / 8.0f; // texture length texels per space pixel + vStep = length * div / 8.0f; // texture length texels per space pixel // Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) vLast = fmod( freq * speed, 1.0f ); @@ -779,14 +789,14 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud // -------------------------------- // Compute box center +/- radius VectorSet( last1, radius, radius, scale ); - VectorAdd( center, last1, tmp ); // maxs - VectorSubtract( center, last1, screen ); // mins + VectorAdd( center, last1, tmp ); // maxs + VectorSubtract( center, last1, screen ); // mins if( !WORLDMODEL ) return; // is that box in PVS && frustum? - if( !gEngfuncs.Mod_BoxVisible( screen, tmp, Mod_GetCurrentVis( )) ) //|| R_CullBox( screen, tmp )) + if( !gEngfuncs.Mod_BoxVisible( screen, tmp, Mod_GetCurrentVis( ))) // || R_CullBox( screen, tmp )) { return; } @@ -805,11 +815,11 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud VectorMAMAM( x, xaxis, y, yaxis, 1.0f, center, point ); // distort using noise - factor = rgNoise[(noiseIndex >> 16) & (NOISE_DIVISIONS - 1)] * scale; + factor = rgNoise[( noiseIndex >> 16 ) & ( NOISE_DIVISIONS - 1 )] * scale; VectorMA( point, factor, RI.vup, point ); // Rotate the noise along the perpendicluar axis a bit to keep the bolt from looking diagonal - factor = rgNoise[(noiseIndex >> 16) & (NOISE_DIVISIONS - 1)] * scale; + factor = rgNoise[( noiseIndex >> 16 ) & ( NOISE_DIVISIONS - 1 )] * scale; factor *= cos( fraction * M_PI_F * 24 + freq ); VectorMA( point, factor, RI.vright, point ); @@ -833,7 +843,7 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud VectorMA( point, width, normal, last1 ); VectorMA( point, -width, normal, last2 ); - vLast += vStep; // Advance texture scroll (v axis only) + vLast += vStep; // Advance texture scroll (v axis only) TriTexCoord2f( 1.0f, vLast ); TriVertex3fv( last2 ); TriTexCoord2f( 0.0f, vLast ); @@ -861,14 +871,15 @@ compute attachment point for beam */ static qboolean R_BeamComputePoint( int beamEnt, vec3_t pt ) { - cl_entity_t *ent; - int attach; + cl_entity_t *ent; + int attach; ent = gEngfuncs.R_BeamGetEntity( beamEnt ); if( beamEnt < 0 ) attach = BEAMENT_ATTACHMENT( -beamEnt ); - else attach = BEAMENT_ATTACHMENT( beamEnt ); + else + attach = BEAMENT_ATTACHMENT( beamEnt ); if( !ent ) { @@ -882,7 +893,8 @@ static qboolean R_BeamComputePoint( int beamEnt, vec3_t pt ) VectorCopy( ent->attachment[attach - 1], pt ); else if( ent->index == ( gp_cl->playernum + 1 )) VectorCopy( gp_cl->simorg, pt ); - else VectorCopy( ent->origin, pt ); + else + VectorCopy( ent->origin, pt ); return true; } @@ -949,8 +961,8 @@ Update beam vars and draw it */ static void R_BeamDraw( BEAM *pbeam, float frametime ) { - model_t *model; - vec3_t delta; + model_t *model; + vec3_t delta; model = CL_ModelHandle( pbeam->modelIndex ); SetBits( pbeam->flags, FBEAM_ISACTIVE ); @@ -976,11 +988,12 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) { if( FBitSet( pbeam->flags, FBEAM_SINENOISE )) SineNoise( rgNoise, NOISE_DIVISIONS ); - else FracNoise( rgNoise, NOISE_DIVISIONS ); + else + FracNoise( rgNoise, NOISE_DIVISIONS ); } // update end points - if( FBitSet( pbeam->flags, FBEAM_STARTENTITY|FBEAM_ENDENTITY )) + if( FBitSet( pbeam->flags, FBEAM_STARTENTITY | FBEAM_ENDENTITY )) { // makes sure attachment[0] + attachment[1] are valid if( !R_BeamRecomputeEndpoints( pbeam )) @@ -998,7 +1011,8 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) if( pbeam->amplitude >= 0.50f ) pbeam->segments = VectorLength( pbeam->delta ) * 0.25f + 3.0f; // one per 4 pixels - else pbeam->segments = VectorLength( pbeam->delta ) * 0.075f + 3.0f; // one per 16 pixels + else + pbeam->segments = VectorLength( pbeam->delta ) * 0.075f + 3.0f; // one per 16 pixels } if( pbeam->type == TE_BEAMPOINTS && R_BeamCull( pbeam->source, pbeam->target, 0 )) @@ -1013,16 +1027,17 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) return; } - if( pbeam->flags & ( FBEAM_FADEIN|FBEAM_FADEOUT )) + if( pbeam->flags & ( FBEAM_FADEIN | FBEAM_FADEOUT )) { // update life cycle pbeam->t = pbeam->freq + ( pbeam->die - gp_cl->time ); - if( pbeam->t != 0.0f ) pbeam->t = 1.0f - pbeam->freq / pbeam->t; + if( pbeam->t != 0.0f ) + pbeam->t = 1.0f - pbeam->freq / pbeam->t; } if( pbeam->type == TE_BEAMHOSE ) { - float flDot; + float flDot; VectorSubtract( pbeam->target, pbeam->source, delta ); VectorNormalize( delta ); @@ -1036,9 +1051,9 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) } else { - float flFade = pow( flDot, 10 ); - vec3_t localDir, vecProjection, tmp; - float flDistance; + float flFade = pow( flDot, 10 ); + vec3_t localDir, vecProjection, tmp; + float flDistance; // fade the beam if the player's not looking at the source VectorSubtract( RI.vieworg, pbeam->source, localDir ); @@ -1050,8 +1065,10 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) if( flDistance > 30 ) { flDistance = 1.0f - (( flDistance - 30.0f ) / 64.0f ); - if( flDistance <= 0 ) flFade = 0; - else flFade *= pow( flDistance, 3 ); + if( flDistance <= 0 ) + flFade = 0; + else + flFade *= pow( flDistance, 3 ); } if( flFade < ( 1.0f / 255.0f )) @@ -1064,7 +1081,7 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) TriRenderMode( FBitSet( pbeam->flags, FBEAM_SOLID ) ? kRenderNormal : kRenderTransAdd ); - if( !TriSpriteTexture( model, (int)(pbeam->frame + pbeam->frameRate * gp_cl->time) % pbeam->frameCount )) + if( !TriSpriteTexture( model, (int)( pbeam->frame + pbeam->frameRate * gp_cl->time ) % pbeam->frameCount )) { ClearBits( pbeam->flags, FBEAM_ISACTIVE ); return; @@ -1072,7 +1089,7 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) if( pbeam->type == TE_BEAMFOLLOW ) { - cl_entity_t *pStart; + cl_entity_t *pStart; // XASH SPECIFIC: get brightness from head entity pStart = gEngfuncs.R_BeamGetEntity( pbeam->startEntity ); @@ -1084,24 +1101,25 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) TriColor4f( pbeam->r, pbeam->g, pbeam->b, pbeam->t * pbeam->brightness ); else if( FBitSet( pbeam->flags, FBEAM_FADEOUT )) TriColor4f( pbeam->r, pbeam->g, pbeam->b, ( 1.0f - pbeam->t ) * pbeam->brightness ); - else TriColor4f( pbeam->r, pbeam->g, pbeam->b, pbeam->brightness ); + else + TriColor4f( pbeam->r, pbeam->g, pbeam->b, pbeam->brightness ); switch( pbeam->type ) { case TE_BEAMTORUS: - //GL_Cull( GL_NONE ); + // GL_Cull( GL_NONE ); TriBegin( TRI_TRIANGLE_STRIP ); R_DrawTorus( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments ); TriEnd(); break; case TE_BEAMDISK: - //GL_Cull( GL_NONE ); + // GL_Cull( GL_NONE ); TriBegin( TRI_TRIANGLE_STRIP ); R_DrawDisk( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments ); TriEnd(); break; case TE_BEAMCYLINDER: - //GL_Cull( GL_NONE ); + // GL_Cull( GL_NONE ); TriBegin( TRI_TRIANGLE_STRIP ); R_DrawCylinder( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments ); TriEnd(); @@ -1118,14 +1136,14 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) TriEnd(); break; case TE_BEAMRING: - //GL_Cull( GL_NONE ); + // GL_Cull( GL_NONE ); TriBegin( TRI_TRIANGLE_STRIP ); R_DrawRing( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments ); TriEnd(); break; } - //GL_Cull( GL_FRONT ); + // GL_Cull( GL_FRONT ); r_stats.c_view_beams_count++; } @@ -1155,9 +1173,10 @@ passed through this */ static void R_BeamSetup( BEAM *pbeam, vec3_t start, vec3_t end, int modelIndex, float life, float width, float amplitude, float brightness, float speed ) { - model_t *sprite = CL_ModelHandle( modelIndex ); + model_t *sprite = CL_ModelHandle( modelIndex ); - if( !sprite ) return; + if( !sprite ) + return; pbeam->type = BEAM_POINTS; pbeam->modelIndex = modelIndex; @@ -1177,8 +1196,9 @@ static void R_BeamSetup( BEAM *pbeam, vec3_t start, vec3_t end, int modelIndex, pbeam->speed = speed; if( amplitude >= 0.50f ) - pbeam->segments = VectorLength( pbeam->delta ) * 0.25f + 3.0f; // one per 4 pixels - else pbeam->segments = VectorLength( pbeam->delta ) * 0.075f + 3.0f; // one per 16 pixels + pbeam->segments = VectorLength( pbeam->delta ) * 0.25f + 3.0f; // one per 4 pixels + else + pbeam->segments = VectorLength( pbeam->delta ) * 0.075f + 3.0f; // one per 16 pixels pbeam->pFollowModel = NULL; pbeam->flags = 0; @@ -1195,11 +1215,11 @@ initialize beam from server entity */ static void R_BeamDrawCustomEntity( cl_entity_t *ent ) { - BEAM beam; - float amp = ent->curstate.body / 100.0f; - float blend = CL_FxBlend( ent ) / 255.0f; - float r, g, b; - int beamFlags; + BEAM beam; + float amp = ent->curstate.body / 100.0f; + float blend = CL_FxBlend( ent ) / 255.0f; + float r, g, b; + int beamFlags; r = ent->curstate.rendercolor.r / 255.0f; g = ent->curstate.rendercolor.g / 255.0f; @@ -1212,7 +1232,7 @@ static void R_BeamDrawCustomEntity( cl_entity_t *ent ) switch( ent->curstate.rendermode & 0x0F ) { case BEAM_ENTPOINT: - beam.type = TE_BEAMPOINTS; + beam.type = TE_BEAMPOINTS; if( ent->curstate.sequence ) { SetBits( beam.flags, FBEAM_STARTENTITY ); @@ -1225,13 +1245,13 @@ static void R_BeamDrawCustomEntity( cl_entity_t *ent ) } break; case BEAM_ENTS: - beam.type = TE_BEAMPOINTS; + beam.type = TE_BEAMPOINTS; SetBits( beam.flags, FBEAM_STARTENTITY | FBEAM_ENDENTITY ); beam.startEntity = ent->curstate.sequence; beam.endEntity = ent->curstate.skin; break; case BEAM_HOSE: - beam.type = TE_BEAMHOSE; + beam.type = TE_BEAMHOSE; break; case BEAM_POINTS: // already set up @@ -1266,11 +1286,11 @@ draw beam loop */ void GAME_EXPORT CL_DrawBeams( int fTrans, BEAM *active_beams ) { - BEAM *pBeam; - int i, flags; + BEAM *pBeam; + int i, flags; - //pglShadeModel( GL_SMOOTH ); - //pglDepthMask( fTrans ? GL_FALSE : GL_TRUE ); + // pglShadeModel( GL_SMOOTH ); + // pglDepthMask( fTrans ? GL_FALSE : GL_TRUE ); // server beams don't allocate beam chains // all params are stored in cl_entity_t @@ -1300,9 +1320,9 @@ void GAME_EXPORT CL_DrawBeams( int fTrans, BEAM *active_beams ) if( !fTrans && !FBitSet( pBeam->flags, FBEAM_SOLID )) continue; - R_BeamDraw( pBeam, gp_cl->time - gp_cl->oldtime ); + R_BeamDraw( pBeam, gp_cl->time - gp_cl->oldtime ); } - //pglShadeModel( GL_FLAT ); - //pglDepthMask( GL_TRUE ); + // pglShadeModel( GL_FLAT ); + // pglDepthMask( GL_TRUE ); } diff --git a/ref/soft/r_bsp.c b/ref/soft/r_bsp.c index 3b14a6de..4bc794aa 100644 --- a/ref/soft/r_bsp.c +++ b/ref/soft/r_bsp.c @@ -24,25 +24,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // current entity info // -vec3_t r_entorigin; // the currently rendering entity in world - // coordinates +vec3_t r_entorigin; // the currently rendering entity in world +// coordinates -float entity_rotation[3][3]; +float entity_rotation[3][3]; -int r_currentbkey; +int r_currentbkey; typedef enum {touchessolid, drawnode, nodrawnode} solidstate_t; -#define MAX_BMODEL_VERTS 1000 // 12K -#define MAX_BMODEL_EDGES 2000 // 24K +#define MAX_BMODEL_VERTS 1000 // 12K +#define MAX_BMODEL_EDGES 2000 // 24K -static mvertex_t *pbverts; -static bedge_t *pbedges; -static int numbverts, numbedges; +static mvertex_t *pbverts; +static bedge_t *pbedges; +static int numbverts, numbedges; -static mvertex_t *pfrontenter, *pfrontexit; +static mvertex_t *pfrontenter, *pfrontexit; -static qboolean makeclippededge; +static qboolean makeclippededge; @@ -51,44 +51,44 @@ static qboolean makeclippededge; R_ConcatRotations ================ */ -static void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]) +static void R_ConcatRotations( float in1[3][3], float in2[3][3], float out[3][3] ) { - out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + - in1[0][2] * in2[2][0]; - out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + - in1[0][2] * in2[2][1]; - out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + - in1[0][2] * in2[2][2]; - out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + - in1[1][2] * in2[2][0]; - out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + - in1[1][2] * in2[2][1]; - out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + - in1[1][2] * in2[2][2]; - out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + - in1[2][2] * in2[2][0]; - out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + - in1[2][2] * in2[2][1]; - out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + - in1[2][2] * in2[2][2]; + out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + + in1[0][2] * in2[2][0]; + out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + + in1[0][2] * in2[2][1]; + out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + + in1[0][2] * in2[2][2]; + out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + + in1[1][2] * in2[2][0]; + out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + + in1[1][2] * in2[2][1]; + out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + + in1[1][2] * in2[2][2]; + out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + + in1[2][2] * in2[2][0]; + out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + + in1[2][2] * in2[2][1]; + out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + + in1[2][2] * in2[2][2]; } -//=========================================================================== +// =========================================================================== /* ================ R_EntityRotate ================ */ -static void R_EntityRotate (vec3_t vec) +static void R_EntityRotate( vec3_t vec ) { - vec3_t tvec; + vec3_t tvec; - VectorCopy (vec, tvec); - vec[0] = DotProduct (entity_rotation[0], tvec); - vec[1] = DotProduct (entity_rotation[1], tvec); - vec[2] = DotProduct (entity_rotation[2], tvec); + VectorCopy( vec, tvec ); + vec[0] = DotProduct( entity_rotation[0], tvec ); + vec[1] = DotProduct( entity_rotation[1], tvec ); + vec[2] = DotProduct( entity_rotation[2], tvec ); } @@ -97,9 +97,9 @@ static void R_EntityRotate (vec3_t vec) R_RotateBmodel ================ */ -void R_RotateBmodel (void) +void R_RotateBmodel( void ) { - float angle, s, c, temp1[3][3], temp2[3][3], temp3[3][3]; + float angle, s, c, temp1[3][3], temp2[3][3], temp3[3][3]; // TODO: should use a look-up table // TODO: should really be stored with the entity instead of being reconstructed @@ -109,8 +109,8 @@ void R_RotateBmodel (void) // yaw angle = RI.currententity->angles[YAW]; angle = angle * M_PI_F * 2 / 360.0f; - s = sin(angle); - c = cos(angle); + s = sin( angle ); + c = cos( angle ); temp1[0][0] = c; temp1[0][1] = s; @@ -126,8 +126,8 @@ void R_RotateBmodel (void) // pitch angle = RI.currententity->angles[PITCH]; angle = angle * M_PI_F * 2 / 360.0f; - s = sin(angle); - c = cos(angle); + s = sin( angle ); + c = cos( angle ); temp2[0][0] = c; temp2[0][1] = 0; @@ -139,13 +139,13 @@ void R_RotateBmodel (void) temp2[2][1] = 0; temp2[2][2] = c; - R_ConcatRotations (temp2, temp1, temp3); + R_ConcatRotations( temp2, temp1, temp3 ); // roll angle = RI.currententity->angles[ROLL]; - angle = angle * M_PI_F*2 / 360.0f; - s = sin(angle); - c = cos(angle); + angle = angle * M_PI_F * 2 / 360.0f; + s = sin( angle ); + c = cos( angle ); temp1[0][0] = 1; temp1[0][1] = 0; @@ -157,17 +157,17 @@ void R_RotateBmodel (void) temp1[2][1] = -s; temp1[2][2] = c; - R_ConcatRotations (temp1, temp3, entity_rotation); + R_ConcatRotations( temp1, temp3, entity_rotation ); // // rotate modelorg and the transformation matrix // - R_EntityRotate (tr.modelorg); - R_EntityRotate (RI.vforward); - R_EntityRotate (RI.vright); - R_EntityRotate (RI.vup); + R_EntityRotate( tr.modelorg ); + R_EntityRotate( RI.vforward ); + R_EntityRotate( RI.vright ); + R_EntityRotate( RI.vup ); - R_TransformFrustum (); + R_TransformFrustum(); } /* @@ -175,14 +175,14 @@ void R_RotateBmodel (void) R_RecursiveClipBPoly ================ */ -static void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf) +static void R_RecursiveClipBPoly( bedge_t *pedges, mnode_t *pnode, msurface_t *psurf ) { - bedge_t *psideedges[2], *pnextedge, *ptedge; - int i, side, lastside; - float dist, frac, lastdist; - mplane_t *splitplane, tplane; - mvertex_t *pvert, *plastvert, *ptvert; - mnode_t *pn; + bedge_t *psideedges[2], *pnextedge, *ptedge; + int i, side, lastside; + float dist, frac, lastdist; + mplane_t *splitplane, tplane; + mvertex_t *pvert, *plastvert, *ptvert; + mnode_t *pn; psideedges[0] = psideedges[1] = NULL; @@ -191,62 +191,62 @@ static void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *p // transform the BSP plane into model space // FIXME: cache these? splitplane = pnode->plane; - tplane.dist = splitplane->dist - - DotProduct(r_entorigin, splitplane->normal); - tplane.normal[0] = DotProduct (entity_rotation[0], splitplane->normal); - tplane.normal[1] = DotProduct (entity_rotation[1], splitplane->normal); - tplane.normal[2] = DotProduct (entity_rotation[2], splitplane->normal); + tplane.dist = splitplane->dist + - DotProduct( r_entorigin, splitplane->normal ); + tplane.normal[0] = DotProduct( entity_rotation[0], splitplane->normal ); + tplane.normal[1] = DotProduct( entity_rotation[1], splitplane->normal ); + tplane.normal[2] = DotProduct( entity_rotation[2], splitplane->normal ); // clip edges to BSP plane - for ( ; pedges ; pedges = pnextedge) + for( ; pedges; pedges = pnextedge ) { pnextedge = pedges->pnext; - // set the status for the last point as the previous point - // FIXME: cache this stuff somehow? + // set the status for the last point as the previous point + // FIXME: cache this stuff somehow? plastvert = pedges->v[0]; - lastdist = DotProduct (plastvert->position, tplane.normal) - - tplane.dist; + lastdist = DotProduct( plastvert->position, tplane.normal ) + - tplane.dist; - if (lastdist > 0) + if( lastdist > 0 ) lastside = 0; else lastside = 1; pvert = pedges->v[1]; - dist = DotProduct (pvert->position, tplane.normal) - tplane.dist; + dist = DotProduct( pvert->position, tplane.normal ) - tplane.dist; - if (dist > 0) + if( dist > 0 ) side = 0; else side = 1; - if (side != lastside) + if( side != lastside ) { - // clipped - if (numbverts >= MAX_BMODEL_VERTS) + // clipped + if( numbverts >= MAX_BMODEL_VERTS ) return; - // generate the clipped vertex - frac = lastdist / (lastdist - dist); + // generate the clipped vertex + frac = lastdist / ( lastdist - dist ); ptvert = &pbverts[numbverts++]; - ptvert->position[0] = plastvert->position[0] + - frac * (pvert->position[0] - - plastvert->position[0]); - ptvert->position[1] = plastvert->position[1] + - frac * (pvert->position[1] - - plastvert->position[1]); - ptvert->position[2] = plastvert->position[2] + - frac * (pvert->position[2] - - plastvert->position[2]); + ptvert->position[0] = plastvert->position[0] + + frac * ( pvert->position[0] + - plastvert->position[0] ); + ptvert->position[1] = plastvert->position[1] + + frac * ( pvert->position[1] + - plastvert->position[1] ); + ptvert->position[2] = plastvert->position[2] + + frac * ( pvert->position[2] + - plastvert->position[2] ); - // split into two edges, one on each side, and remember entering - // and exiting points - // FIXME: share the clip edge by having a winding direction flag? - if (numbedges >= (MAX_BMODEL_EDGES - 1)) + // split into two edges, one on each side, and remember entering + // and exiting points + // FIXME: share the clip edge by having a winding direction flag? + if( numbedges >= ( MAX_BMODEL_EDGES - 1 )) { - //gEngfuncs.Con_Printf ("Out of edges for bmodel\n"); + // gEngfuncs.Con_Printf ("Out of edges for bmodel\n"); return; } @@ -264,9 +264,9 @@ static void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *p numbedges += 2; - if (side == 0) + if( side == 0 ) { - // entering for front, exiting for back + // entering for front, exiting for back pfrontenter = ptvert; makeclippededge = true; } @@ -278,7 +278,7 @@ static void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *p } else { - // add the edge to the appropriate side + // add the edge to the appropriate side pedges->pnext = psideedges[side]; psideedges[side] = pedges; } @@ -286,11 +286,11 @@ static void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *p // if anything was clipped, reconstitute and add the edges along the clip // plane to both sides (but in opposite directions) - if (makeclippededge) + if( makeclippededge ) { - if (numbedges >= (MAX_BMODEL_EDGES - 2)) + if( numbedges >= ( MAX_BMODEL_EDGES - 2 )) { - //gEngfuncs.Con_Printf ("Out of edges for bmodel\n"); + // gEngfuncs.Con_Printf ("Out of edges for bmodel\n"); return; } @@ -310,30 +310,30 @@ static void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *p } // draw or recurse further - for (i=0 ; i<2 ; i++) + for( i = 0; i < 2; i++ ) { - if (psideedges[i]) + if( psideedges[i] ) { - // draw if we've reached a non-solid leaf, done if all that's left is a - // solid leaf, and continue down the tree if it's not a leaf + // draw if we've reached a non-solid leaf, done if all that's left is a + // solid leaf, and continue down the tree if it's not a leaf pn = pnode->children[i]; - // we're done with this branch if the node or leaf isn't in the PVS - if (pn->visframe == tr.visframecount) + // we're done with this branch if the node or leaf isn't in the PVS + if( pn->visframe == tr.visframecount ) { - if (pn->contents < 0) + if( pn->contents < 0 ) { - if (pn->contents != CONTENTS_SOLID) + if( pn->contents != CONTENTS_SOLID ) { - //r_currentbkey = ((mleaf_t *)pn)->cluster; - r_currentbkey = LEAF_KEY (((mleaf_t *)pn)); - R_RenderBmodelFace (psideedges[i], psurf); + // r_currentbkey = ((mleaf_t *)pn)->cluster; + r_currentbkey = LEAF_KEY(((mleaf_t *)pn )); + R_RenderBmodelFace( psideedges[i], psurf ); } } else { - R_RecursiveClipBPoly (psideedges[i], pnode->children[i], - psurf); + R_RecursiveClipBPoly( psideedges[i], pnode->children[i], + psurf ); } } } @@ -347,16 +347,16 @@ R_DrawSolidClippedSubmodelPolygons Bmodel crosses multiple leafs ================ */ -void R_DrawSolidClippedSubmodelPolygons (model_t *pmodel, mnode_t *topnode) +void R_DrawSolidClippedSubmodelPolygons( model_t *pmodel, mnode_t *topnode ) { - int i, j, lindex; - vec_t dot; - msurface_t *psurf; - int numsurfaces; - mplane_t *pplane; - mvertex_t bverts[MAX_BMODEL_VERTS]; - bedge_t bedges[MAX_BMODEL_EDGES], *pbedge; - medge_t *pedge, *pedges; + int i, j, lindex; + vec_t dot; + msurface_t *psurf; + int numsurfaces; + mplane_t *pplane; + mvertex_t bverts[MAX_BMODEL_VERTS]; + bedge_t bedges[MAX_BMODEL_EDGES], *pbedge; + medge_t *pedge, *pedges; // FIXME: use bounding-box-based frustum clipping info? @@ -364,7 +364,7 @@ void R_DrawSolidClippedSubmodelPolygons (model_t *pmodel, mnode_t *topnode) numsurfaces = pmodel->nummodelsurfaces; pedges = pmodel->edges; - for (i=0 ; iflags, SURF_DRAWTURB ) && !ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE )) { @@ -373,33 +373,33 @@ void R_DrawSolidClippedSubmodelPolygons (model_t *pmodel, mnode_t *topnode) if( r_entorigin[2] + pmodel->mins[2] + 1.0f >= psurf->plane->dist ) continue; } - // find which side of the node we are on + // find which side of the node we are on pplane = psurf->plane; - dot = DotProduct (tr.modelorg, pplane->normal) - pplane->dist; + dot = DotProduct( tr.modelorg, pplane->normal ) - pplane->dist; - // draw the polygon - if (( !(psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) || - ((psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) + // draw the polygon + if(( !( psurf->flags & SURF_PLANEBACK ) && ( dot < -BACKFACE_EPSILON )) + || (( psurf->flags & SURF_PLANEBACK ) && ( dot > BACKFACE_EPSILON ))) continue; - // FIXME: use bounding-box-based frustum clipping info? + // FIXME: use bounding-box-based frustum clipping info? - // copy the edges to bedges, flipping if necessary so always - // clockwise winding - // FIXME: if edges and vertices get caches, these assignments must move - // outside the loop, and overflow checking must be done here + // copy the edges to bedges, flipping if necessary so always + // clockwise winding + // FIXME: if edges and vertices get caches, these assignments must move + // outside the loop, and overflow checking must be done here pbverts = bverts; pbedges = bedges; numbverts = numbedges = 0; pbedge = &bedges[numbedges]; numbedges += psurf->numedges; - for (j=0 ; jnumedges ; j++) + for( j = 0; j < psurf->numedges; j++ ) { - lindex = pmodel->surfedges[psurf->firstedge+j]; + lindex = pmodel->surfedges[psurf->firstedge + j]; - if (lindex > 0) + if( lindex > 0 ) { pedge = &pedges[lindex]; pbedge[j].v[0] = &r_pcurrentvertbase[pedge->v[0]]; @@ -413,14 +413,14 @@ void R_DrawSolidClippedSubmodelPolygons (model_t *pmodel, mnode_t *topnode) pbedge[j].v[1] = &r_pcurrentvertbase[pedge->v[0]]; } - pbedge[j].pnext = &pbedge[j+1]; + pbedge[j].pnext = &pbedge[j + 1]; } - pbedge[j-1].pnext = NULL; // mark end of edges + pbedge[j - 1].pnext = NULL; // mark end of edges - //if ( !( psurf->texinfo->flags & ( SURF_TRANS66 | SURF_TRANS33 ) ) ) - R_RecursiveClipBPoly (pbedge, topnode, psurf); - //else + // if ( !( psurf->texinfo->flags & ( SURF_TRANS66 | SURF_TRANS33 ) ) ) + R_RecursiveClipBPoly( pbedge, topnode, psurf ); + // else // R_RenderBmodelFace( pbedge, psurf ); } } @@ -433,20 +433,20 @@ R_DrawSubmodelPolygons All in one leaf ================ */ -void R_DrawSubmodelPolygons (model_t *pmodel, int clipflags, mnode_t *topnode) +void R_DrawSubmodelPolygons( model_t *pmodel, int clipflags, mnode_t *topnode ) { - int i; - vec_t dot; - msurface_t *psurf; - int numsurfaces; - mplane_t *pplane; + int i; + vec_t dot; + msurface_t *psurf; + int numsurfaces; + mplane_t *pplane; // FIXME: use bounding-box-based frustum clipping info? psurf = &pmodel->surfaces[pmodel->firstmodelsurface]; numsurfaces = pmodel->nummodelsurfaces; - for (i=0 ; iflags, SURF_DRAWTURB ) && !ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE )) { @@ -455,19 +455,19 @@ void R_DrawSubmodelPolygons (model_t *pmodel, int clipflags, mnode_t *topnode) if( r_entorigin[2] + pmodel->mins[2] + 1.0f >= psurf->plane->dist ) continue; } - // find which side of the node we are on + // find which side of the node we are on pplane = psurf->plane; - dot = DotProduct (tr.modelorg, pplane->normal) - pplane->dist; + dot = DotProduct( tr.modelorg, pplane->normal ) - pplane->dist; - // draw the polygon - if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) || - (!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) + // draw the polygon + if((( psurf->flags & SURF_PLANEBACK ) && ( dot < -BACKFACE_EPSILON )) + || ( !( psurf->flags & SURF_PLANEBACK ) && ( dot > BACKFACE_EPSILON ))) { - r_currentkey = LEAF_KEY(((mleaf_t *)topnode)); + r_currentkey = LEAF_KEY(((mleaf_t *)topnode )); - // FIXME: use bounding-box-based frustum clipping info? - R_RenderFace (psurf, clipflags); + // FIXME: use bounding-box-based frustum clipping info? + R_RenderFace( psurf, clipflags ); } } } @@ -482,34 +482,34 @@ int r_leafkeys[MAX_MAP_LEAFS]; R_RecursiveWorldNode ================ */ -static void R_RecursiveWorldNode (mnode_t *node, int clipflags) +static void R_RecursiveWorldNode( mnode_t *node, int clipflags ) { - int i, c, side, *pindex; - vec3_t acceptpt, rejectpt; - mplane_t *plane; - msurface_t *surf, **mark; - mleaf_t *pleaf; - double d, dot; + int i, c, side, *pindex; + vec3_t acceptpt, rejectpt; + mplane_t *plane; + msurface_t *surf, **mark; + mleaf_t *pleaf; + double d, dot; - if (node->contents == CONTENTS_SOLID) - return; // solid + if( node->contents == CONTENTS_SOLID ) + return; // solid - if (node->visframe != tr.visframecount) + if( node->visframe != tr.visframecount ) return; // cull the clipping planes if not trivial accept // FIXME: the compiler is doing a lousy job of optimizing here; it could be // twice as fast in ASM - if (clipflags) + if( clipflags ) { - for (i=0 ; i<4 ; i++) + for( i = 0; i < 4; i++ ) { - if (! (clipflags & (1<minmaxs[pindex[1]]; rejectpt[2] = (float)node->minmaxs[pindex[2]]; - d = DotProduct (rejectpt, qfrustum.view_clipplanes[i].normal); + d = DotProduct( rejectpt, qfrustum.view_clipplanes[i].normal ); d -= qfrustum.view_clipplanes[i].dist; - if (d <= 0) + if( d <= 0 ) return; - acceptpt[0] = (float)node->minmaxs[pindex[3+0]]; - acceptpt[1] = (float)node->minmaxs[pindex[3+1]]; - acceptpt[2] = (float)node->minmaxs[pindex[3+2]]; + acceptpt[0] = (float)node->minmaxs[pindex[3 + 0]]; + acceptpt[1] = (float)node->minmaxs[pindex[3 + 1]]; + acceptpt[2] = (float)node->minmaxs[pindex[3 + 2]]; - d = DotProduct (acceptpt, qfrustum.view_clipplanes[i].normal); + d = DotProduct( acceptpt, qfrustum.view_clipplanes[i].normal ); d -= qfrustum.view_clipplanes[i].dist; - if (d >= 0) - clipflags &= ~(1<= 0 ) + clipflags &= ~( 1 << i ); // node is entirely on screen } } // if a leaf node, draw stuff - if (node->contents < 0) + if( node->contents < 0 ) { pleaf = (mleaf_t *)node; mark = pleaf->firstmarksurface; c = pleaf->nummarksurfaces; - if (c) + if( c ) { do { - (*mark)->visframe = tr.framecount; + ( *mark )->visframe = tr.framecount; mark++; - } while (--c); + } + while( --c ); } - // deal with model fragments in this leaf - if (pleaf->efrags) + // deal with model fragments in this leaf + if( pleaf->efrags ) { - gEngfuncs.R_StoreEfrags(&pleaf->efrags,tr.realframecount); + gEngfuncs.R_StoreEfrags( &pleaf->efrags, tr.realframecount ); } - // pleaf->cluster - LEAF_KEY(pleaf) = r_currentkey; - r_currentkey++; // all bmodels in a leaf share the same key + // pleaf->cluster + LEAF_KEY( pleaf ) = r_currentkey; + r_currentkey++; // all bmodels in a leaf share the same key } else { - // node is just a decision point, so go down the apropriate sides + // node is just a decision point, so go down the apropriate sides - // find which side of the node we are on + // find which side of the node we are on plane = node->plane; - switch (plane->type) + switch( plane->type ) { case PLANE_X: dot = tr.modelorg[0] - plane->dist; @@ -582,58 +583,60 @@ static void R_RecursiveWorldNode (mnode_t *node, int clipflags) dot = tr.modelorg[2] - plane->dist; break; default: - dot = DotProduct (tr.modelorg, plane->normal) - plane->dist; + dot = DotProduct( tr.modelorg, plane->normal ) - plane->dist; break; } - if (dot >= 0) + if( dot >= 0 ) side = 0; else side = 1; - // recurse down the children, front side first - R_RecursiveWorldNode (node->children[side], clipflags); + // recurse down the children, front side first + R_RecursiveWorldNode( node->children[side], clipflags ); - // draw stuff + // draw stuff c = node->numsurfaces; - if (c) + if( c ) { surf = WORLDMODEL->surfaces + node->firstsurface; - if (dot < -BACKFACE_EPSILON) + if( dot < -BACKFACE_EPSILON ) { do { - if ((surf->flags & SURF_PLANEBACK) && - (surf->visframe == tr.framecount)) + if(( surf->flags & SURF_PLANEBACK ) + && ( surf->visframe == tr.framecount )) { - R_RenderFace (surf, clipflags); + R_RenderFace( surf, clipflags ); } surf++; - } while (--c); + } + while( --c ); } - else if (dot > BACKFACE_EPSILON) + else if( dot > BACKFACE_EPSILON ) { do { - if (!(surf->flags & SURF_PLANEBACK) && - (surf->visframe == tr.framecount)) + if( !( surf->flags & SURF_PLANEBACK ) + && ( surf->visframe == tr.framecount )) { - R_RenderFace (surf, clipflags); + R_RenderFace( surf, clipflags ); } surf++; - } while (--c); + } + while( --c ); } - // all surfaces on the same node share the same sequence number + // all surfaces on the same node share the same sequence number r_currentkey++; } - // recurse down the back side - R_RecursiveWorldNode (node->children[!side], clipflags); + // recurse down the back side + R_RecursiveWorldNode( node->children[!side], clipflags ); } } @@ -642,18 +645,18 @@ static void R_RecursiveWorldNode (mnode_t *node, int clipflags) R_RenderWorld ================ */ -void R_RenderWorld (void) +void R_RenderWorld( void ) { - if ( !RI.drawWorld ) + if( !RI.drawWorld ) return; // auto cycle the world frame for texture animation - RI.currententity = CL_GetEntityByIndex(0); - //RI.currententity->frame = (int)(gp_cl->time*2); + RI.currententity = CL_GetEntityByIndex( 0 ); + // RI.currententity->frame = (int)(gp_cl->time*2); - VectorCopy (RI.vieworg, tr.modelorg); + VectorCopy( RI.vieworg, tr.modelorg ); RI.currentmodel = WORLDMODEL; r_pcurrentvertbase = RI.currentmodel->vertexes; - R_RecursiveWorldNode (RI.currentmodel->nodes, 15); + R_RecursiveWorldNode( RI.currentmodel->nodes, 15 ); } diff --git a/ref/soft/r_context.c b/ref/soft/r_context.c index 120df0aa..29d2375c 100644 --- a/ref/soft/r_context.c +++ b/ref/soft/r_context.c @@ -15,14 +15,14 @@ GNU General Public License for more details. #include "r_local.h" -ref_api_t gEngfuncs; +ref_api_t gEngfuncs; ref_globals_t *gpGlobals; ref_client_t *gp_cl; ref_host_t *gp_host; -gl_globals_t tr; -ref_speeds_t r_stats; -poolhandle_t r_temppool; -viddef_t vid; +gl_globals_t tr; +ref_speeds_t r_stats; +poolhandle_t r_temppool; +viddef_t vid; void _Mem_Free( void *data, const char *filename, int fileline ) { @@ -58,8 +58,8 @@ CL_FillRGBA static void GAME_EXPORT CL_FillRGBA( int rendermode, float _x, float _y, float _w, float _h, byte r, byte g, byte b, byte a ) { vid.rendermode = rendermode; - _TriColor4ub(r,g,b,a); - Draw_Fill(_x,_y,_w,_h); + _TriColor4ub( r, g, b, a ); + Draw_Fill( _x, _y, _w, _h ); } void Mod_UnloadTextures( model_t *mod ); @@ -72,20 +72,20 @@ static qboolean GAME_EXPORT Mod_ProcessRenderData( model_t *mod, qboolean create { switch( mod->type ) { - case mod_studio: - //Mod_LoadStudioModel( mod, buf, loaded ); - break; - case mod_sprite: - Mod_LoadSpriteModel( mod, buf, &loaded, mod->numtexinfo ); - break; - case mod_alias: - //Mod_LoadAliasModel( mod, buf, &loaded ); - break; - case mod_brush: - // Mod_LoadBrushModel( mod, buf, loaded ); - break; + case mod_studio: + // Mod_LoadStudioModel( mod, buf, loaded ); + break; + case mod_sprite: + Mod_LoadSpriteModel( mod, buf, &loaded, mod->numtexinfo ); + break; + case mod_alias: + // Mod_LoadAliasModel( mod, buf, &loaded ); + break; + case mod_brush: + // Mod_LoadBrushModel( mod, buf, loaded ); + break; - default: gEngfuncs.Host_Error( "%s: unsupported type %d\n", __func__, mod->type ); + default: gEngfuncs.Host_Error( "%s: unsupported type %d\n", __func__, mod->type ); } } @@ -118,10 +118,10 @@ static int GL_RefGetParm( int parm, int arg ) return glt->srcHeight; case PARM_TEX_GLFORMAT: glt = R_GetTexture( arg ); - return 0; //glt->format; + return 0; // glt->format; case PARM_TEX_ENCODE: glt = R_GetTexture( arg ); - return 0; //glt->encode; + return 0; // glt->encode; case PARM_TEX_MIPCOUNT: glt = R_GetTexture( arg ); return glt->numMips; @@ -132,36 +132,36 @@ static int GL_RefGetParm( int parm, int arg ) Assert( arg >= 0 && arg < 6 ); return tr.skyboxTextures[arg]; case PARM_TEX_SKYTEXNUM: - return 0; //tr.skytexturenum; + return 0; // tr.skytexturenum; case PARM_TEX_LIGHTMAP: arg = bound( 0, arg, MAX_LIGHTMAPS - 1 ); return tr.lightmapTextures[arg]; case PARM_TEX_TARGET: glt = R_GetTexture( arg ); - return 0; //glt->target; + return 0; // glt->target; case PARM_TEX_TEXNUM: glt = R_GetTexture( arg ); - return 0; //glt->texnum; + return 0; // glt->texnum; case PARM_TEX_FLAGS: glt = R_GetTexture( arg ); return glt->flags; case PARM_TEX_MEMORY: return R_TexMemory(); case PARM_ACTIVE_TMU: - return 0; //glState.activeTMU; + return 0; // glState.activeTMU; case PARM_LIGHTSTYLEVALUE: arg = bound( 0, arg, MAX_LIGHTSTYLES - 1 ); return tr.lightstylevalue[arg]; case PARM_MAX_IMAGE_UNITS: - return 0; //GL_MaxTextureUnits(); + return 0; // GL_MaxTextureUnits(); case PARM_REBUILD_GAMMA: return 0; case PARM_GL_CONTEXT_TYPE: - return 0; //glConfig.context; + return 0; // glConfig.context; case PARM_GLES_WRAPPER: - return 0; //glConfig.wrapper; + return 0; // glConfig.wrapper; case PARM_STENCIL_ACTIVE: - return 0; //glState.stencilEnabled; + return 0; // glState.stencilEnabled; case PARM_SKY_SPHERE: return 0; // ref_soft doesn't support sky sphere case PARM_TEX_FILTERING: @@ -176,18 +176,24 @@ static void GAME_EXPORT R_GetDetailScaleForTexture( int texture, float *xScale, { image_t *glt = R_GetTexture( texture ); - if( xScale ) *xScale = glt->xscale; - if( yScale ) *yScale = glt->yscale; + if( xScale ) + *xScale = glt->xscale; + if( yScale ) + *yScale = glt->yscale; } static void GAME_EXPORT R_GetExtraParmsForTexture( int texture, byte *red, byte *green, byte *blue, byte *density ) { image_t *glt = R_GetTexture( texture ); - if( red ) *red = glt->fogParams[0]; - if( green ) *green = glt->fogParams[1]; - if( blue ) *blue = glt->fogParams[2]; - if( density ) *density = glt->fogParams[3]; + if( red ) + *red = glt->fogParams[0]; + if( green ) + *green = glt->fogParams[1]; + if( blue ) + *blue = glt->fogParams[2]; + if( density ) + *density = glt->fogParams[3]; } @@ -231,33 +237,33 @@ static void Mod_BrushUnloadTextures( model_t *mod ) int i; - gEngfuncs.Con_Printf("Unloading world\n"); + gEngfuncs.Con_Printf( "Unloading world\n" ); tr.map_unload = true; for( i = 0; i < mod->numtextures; i++ ) { texture_t *tx = mod->textures[i]; if( !tx || tx->gl_texturenum == tr.defaultTexture ) - continue; // free slot + continue; // free slot - GL_FreeTexture( tx->gl_texturenum ); // main texture - GL_FreeTexture( tx->fb_texturenum ); // luma texture + GL_FreeTexture( tx->gl_texturenum ); // main texture + GL_FreeTexture( tx->fb_texturenum ); // luma texture } } void Mod_UnloadTextures( model_t *mod ) { - int i, j; + int i, j; Assert( mod != NULL ); switch( mod->type ) { case mod_studio: - //Mod_StudioUnloadTextures( mod->cache.data ); + // Mod_StudioUnloadTextures( mod->cache.data ); break; case mod_alias: - //Mod_AliasUnloadTextures( mod->cache.data ); + // Mod_AliasUnloadTextures( mod->cache.data ); break; case mod_brush: Mod_BrushUnloadTextures( mod ); @@ -298,7 +304,7 @@ static void GAME_EXPORT GL_BackendEndFrame( void ) } -void GAME_EXPORT GL_SetRenderMode(int mode) +void GAME_EXPORT GL_SetRenderMode( int mode ) { vid.rendermode = mode; /// TODO: table shading/blending??? @@ -322,7 +328,7 @@ static void GAME_EXPORT R_SetupSky( int *skyboxTextures ) tr.skyboxTextures[i] = skyboxTextures[i]; } -qboolean GAME_EXPORT VID_CubemapShot(const char *base, uint size, const float *vieworg, qboolean skyshot) +qboolean GAME_EXPORT VID_CubemapShot( const char *base, uint size, const float *vieworg, qboolean skyshot ) { // cubemaps? in my softrender??? return false; @@ -339,17 +345,17 @@ static void GAME_EXPORT GL_SubdivideSurface( model_t *mod, msurface_t *fa ) } -static void GAME_EXPORT DrawSingleDecal(decal_t *pDecal, msurface_t *fa) +static void GAME_EXPORT DrawSingleDecal( decal_t *pDecal, msurface_t *fa ) { } -static void GAME_EXPORT GL_SelectTexture(int texture) +static void GAME_EXPORT GL_SelectTexture( int texture ) { } -static void GAME_EXPORT GL_LoadTexMatrixExt(const float *glmatrix) +static void GAME_EXPORT GL_LoadTexMatrixExt( const float *glmatrix ) { } @@ -359,27 +365,27 @@ static void GAME_EXPORT GL_LoadIdentityTexMatrix( void ) } -static void GAME_EXPORT GL_CleanUpTextureUnits(int last) +static void GAME_EXPORT GL_CleanUpTextureUnits( int last ) { } -static void GAME_EXPORT GL_TexGen(unsigned int coord, unsigned int mode) +static void GAME_EXPORT GL_TexGen( unsigned int coord, unsigned int mode ) { } -static void GAME_EXPORT GL_TextureTarget(uint target) +static void GAME_EXPORT GL_TextureTarget( uint target ) { } -void GAME_EXPORT Mod_SetOrthoBounds(const float *mins, const float *maxs) +void GAME_EXPORT Mod_SetOrthoBounds( const float *mins, const float *maxs ) { } -qboolean GAME_EXPORT R_SpeedsMessage(char *out, size_t size) +qboolean GAME_EXPORT R_SpeedsMessage( char *out, size_t size ) { return false; } @@ -410,7 +416,7 @@ static const char *R_GetConfigName( void ) return "ref_soft"; // software specific cvars will go to ref_soft.cfg } -static void* GAME_EXPORT R_GetProcAddress( const char *name ) +static void * GAME_EXPORT R_GetProcAddress( const char *name ) { return gEngfuncs.GL_GetProcAddress( name ); } diff --git a/ref/soft/r_decals.c b/ref/soft/r_decals.c index 80629e71..e853a23f 100644 --- a/ref/soft/r_decals.c +++ b/ref/soft/r_decals.c @@ -15,44 +15,44 @@ GNU General Public License for more details. #include "r_local.h" -#define DECAL_OVERLAP_DISTANCE 2 -#define DECAL_DISTANCE 4 // too big values produce more clipped polygons -#define MAX_DECALCLIPVERT 32 // produced vertexes of fragmented decal -#define DECAL_CACHEENTRY 256 // MUST BE POWER OF 2 or code below needs to change! -#define DECAL_TRANSPARENT_THRESHOLD 230 // transparent decals draw with GL_MODULATE +#define DECAL_OVERLAP_DISTANCE 2 +#define DECAL_DISTANCE 4 // too big values produce more clipped polygons +#define MAX_DECALCLIPVERT 32 // produced vertexes of fragmented decal +#define DECAL_CACHEENTRY 256 // MUST BE POWER OF 2 or code below needs to change! +#define DECAL_TRANSPARENT_THRESHOLD 230 // transparent decals draw with GL_MODULATE // empirically determined constants for minimizing overalpping decals -#define MAX_OVERLAP_DECALS 6 -#define DECAL_OVERLAP_DIST 8 -#define MIN_DECAL_SCALE 0.01f -#define MAX_DECAL_SCALE 16.0f +#define MAX_OVERLAP_DECALS 6 +#define DECAL_OVERLAP_DIST 8 +#define MIN_DECAL_SCALE 0.01f +#define MAX_DECAL_SCALE 16.0f // clip edges -#define LEFT_EDGE 0 -#define RIGHT_EDGE 1 -#define TOP_EDGE 2 -#define BOTTOM_EDGE 3 +#define LEFT_EDGE 0 +#define RIGHT_EDGE 1 +#define TOP_EDGE 2 +#define BOTTOM_EDGE 3 // This structure contains the information used to create new decals typedef struct { - vec3_t m_Position; // world coordinates of the decal center - model_t *m_pModel; // the model the decal is going to be applied in - int m_iTexture; // The decal material - int m_Size; // Size of the decal (in world coords) - int m_Flags; - int m_Entity; // Entity the decal is applied to. - float m_scale; - int m_decalWidth; - int m_decalHeight; - vec3_t m_Basis[3]; + vec3_t m_Position; // world coordinates of the decal center + model_t *m_pModel; // the model the decal is going to be applied in + int m_iTexture; // The decal material + int m_Size; // Size of the decal (in world coords) + int m_Flags; + int m_Entity; // Entity the decal is applied to. + float m_scale; + int m_decalWidth; + int m_decalHeight; + vec3_t m_Basis[3]; } decalinfo_t; -static float g_DecalClipVerts[MAX_DECALCLIPVERT][VERTEXSIZE]; -static float g_DecalClipVerts2[MAX_DECALCLIPVERT][VERTEXSIZE]; +static float g_DecalClipVerts[MAX_DECALCLIPVERT][VERTEXSIZE]; +static float g_DecalClipVerts2[MAX_DECALCLIPVERT][VERTEXSIZE]; -decal_t gDecalPool[MAX_RENDER_DECALS]; -static int gDecalCount; +decal_t gDecalPool[MAX_RENDER_DECALS]; +static int gDecalCount; void R_ClearDecals( void ) { @@ -63,7 +63,7 @@ void R_ClearDecals( void ) // unlink pdecal from any surface it's attached to static void R_DecalUnlink( decal_t *pdecal ) { - decal_t *tmp; + decal_t *tmp; if( pdecal->psurface ) { @@ -74,7 +74,8 @@ static void R_DecalUnlink( decal_t *pdecal ) else { tmp = pdecal->psurface->pdecals; - if( !tmp ) gEngfuncs.Host_Error( "%s: bad decal list\n", __func__ ); + if( !tmp ) + gEngfuncs.Host_Error( "%s: bad decal list\n", __func__ ); while( tmp->pnext ) { @@ -100,16 +101,17 @@ static void R_DecalUnlink( decal_t *pdecal ) // as each surface needs it's own. static decal_t *R_DecalAlloc( decal_t *pdecal ) { - int limit = MAX_RENDER_DECALS; + int limit = MAX_RENDER_DECALS; if( r_decals->value < limit ) limit = r_decals->value; - if( !limit ) return NULL; + if( !limit ) + return NULL; if( !pdecal ) { - int count = 0; + int count = 0; // check for the odd possiblity of infinte loop do @@ -120,7 +122,8 @@ static decal_t *R_DecalAlloc( decal_t *pdecal ) pdecal = &gDecalPool[gDecalCount]; // reuse next decal gDecalCount++; count++; - } while( FBitSet( pdecal->flags, FDECAL_PERMANENT ) && count < limit ); + } + while( FBitSet( pdecal->flags, FDECAL_PERMANENT ) && count < limit ); } // if decal is already linked to a surface, unlink it. @@ -129,28 +132,31 @@ static decal_t *R_DecalAlloc( decal_t *pdecal ) return pdecal; } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // find decal image and grab size from it -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- static void R_GetDecalDimensions( int texture, int *width, int *height ) { - if( width ) *width = 1; // to avoid divide by zero - if( height ) *height = 1; + if( width ) + *width = 1; // to avoid divide by zero + if( height ) + *height = 1; R_GetTextureParms( width, height, texture ); } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // compute the decal basis based on surface normal -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- void R_DecalComputeBasis( msurface_t *surf, int flags, vec3_t textureSpaceBasis[3] ) { - vec3_t surfaceNormal; + vec3_t surfaceNormal; // setup normal if( surf->flags & SURF_PLANEBACK ) VectorNegate( surf->plane->normal, surfaceNormal ); - else VectorCopy( surf->plane->normal, surfaceNormal ); + else + VectorCopy( surf->plane->normal, surfaceNormal ); VectorNormalize2( surfaceNormal, textureSpaceBasis[2] ); VectorNormalize2( surf->texinfo->vecs[0], textureSpaceBasis[0] ); @@ -159,7 +165,7 @@ void R_DecalComputeBasis( msurface_t *surf, int flags, vec3_t textureSpaceBasis[ static void R_SetupDecalTextureSpaceBasis( decal_t *pDecal, msurface_t *surf, int texture, vec3_t textureSpaceBasis[3], float decalWorldScale[2] ) { - int width, height; + int width, height; // Compute the non-scaled decal basis R_DecalComputeBasis( surf, pDecal->flags, textureSpaceBasis ); @@ -177,10 +183,10 @@ static void R_SetupDecalTextureSpaceBasis( decal_t *pDecal, msurface_t *surf, in } // Build the initial list of vertices from the surface verts into the global array, 'verts'. -static void R_SetupDecalVertsForMSurface( decal_t *pDecal, msurface_t *surf, vec3_t textureSpaceBasis[3], float *verts ) +static void R_SetupDecalVertsForMSurface( decal_t *pDecal, msurface_t *surf, vec3_t textureSpaceBasis[3], float *verts ) { - float *v; - int i; + float *v; + int i; if( !surf->polys ) return; @@ -235,7 +241,7 @@ static int R_ClipInside( float *vert, int edge ) static void R_ClipIntersect( float *one, float *two, float *out, int edge ) { - float t; + float t; // t is the parameter of the line between one and two clipped to the edge // or the fraction of the clipped point between one & two @@ -250,36 +256,36 @@ static void R_ClipIntersect( float *one, float *two, float *out, int edge ) if( edge == LEFT_EDGE ) { // left - t = ((one[3] - 0.0f) / (one[3] - two[3])); + t = (( one[3] - 0.0f ) / ( one[3] - two[3] )); out[3] = out[5] = 0.0f; } else { // right - t = ((one[3] - 1.0f) / (one[3] - two[3])); + t = (( one[3] - 1.0f ) / ( one[3] - two[3] )); out[3] = out[5] = 1.0f; } - out[4] = one[4] + (two[4] - one[4]) * t; - out[6] = one[6] + (two[6] - one[6]) * t; + out[4] = one[4] + ( two[4] - one[4] ) * t; + out[6] = one[6] + ( two[6] - one[6] ) * t; } else { if( edge == TOP_EDGE ) { // top - t = ((one[4] - 0.0f) / (one[4] - two[4])); + t = (( one[4] - 0.0f ) / ( one[4] - two[4] )); out[4] = out[6] = 0.0f; } else { // bottom - t = ((one[4] - 1.0f) / (one[4] - two[4])); + t = (( one[4] - 1.0f ) / ( one[4] - two[4] )); out[4] = out[6] = 1.0f; } - out[3] = one[3] + (two[3] - one[3]) * t; - out[5] = one[5] + (two[4] - one[5]) * t; + out[3] = one[3] + ( two[3] - one[3] ) * t; + out[5] = one[5] + ( two[4] - one[5] ) * t; } VectorLerp( one, t, two, out ); @@ -287,12 +293,12 @@ static void R_ClipIntersect( float *one, float *two, float *out, int edge ) static int SHClip( float *vert, int vertCount, float *out, int edge ) { - int j, outCount; - float *s, *p; + int j, outCount; + float *s, *p; outCount = 0; - s = &vert[(vertCount - 1) * VERTEXSIZE]; + s = &vert[( vertCount - 1 ) * VERTEXSIZE]; for( j = 0; j < vertCount; j++ ) { @@ -336,8 +342,8 @@ static int SHClip( float *vert, int vertCount, float *out, int edge ) static float *R_DoDecalSHClip( float *pInVerts, decal_t *pDecal, int nStartVerts, int *pVertCount ) { - float *pOutVerts = g_DecalClipVerts[0]; - int outCount; + float *pOutVerts = g_DecalClipVerts[0]; + int outCount; // clip the polygon to the decal texture space outCount = SHClip( pInVerts, nStartVerts, g_DecalClipVerts2[0], LEFT_EDGE ); @@ -351,13 +357,13 @@ static float *R_DoDecalSHClip( float *pInVerts, decal_t *pDecal, int nStartVerts return pOutVerts; } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // Generate clipped vertex list for decal pdecal projected onto polygon psurf -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- static float *R_DecalVertsClip( decal_t *pDecal, msurface_t *surf, int texture, int *pVertCount ) { - float decalWorldScale[2]; - vec3_t textureSpaceBasis[3]; + float decalWorldScale[2]; + vec3_t textureSpaceBasis[3]; // figure out where the decal maps onto the surface. R_SetupDecalClip( pDecal, surf, texture, textureSpaceBasis, decalWorldScale ); @@ -373,11 +379,11 @@ static float *R_DecalVertsClip( decal_t *pDecal, msurface_t *surf, int texture, // Generate lighting coordinates at each vertex for decal vertices v[] on surface psurf static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount ) { - float s, t; - mtexinfo_t *tex; - mextrasurf_t *info = surf->info; - float sample_size; - int j; + float s, t; + mtexinfo_t *tex; + mextrasurf_t *info = surf->info; + float sample_size; + int j; sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); tex = surf->texinfo; @@ -388,12 +394,12 @@ static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount ) s = DotProduct( v, info->lmvecs[0] ) + info->lmvecs[0][3] - info->lightmapmins[0]; s += surf->light_s * sample_size; s += sample_size * 0.5f; - s /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->width; + s /= BLOCK_SIZE * sample_size; // fa->texinfo->texture->width; t = DotProduct( v, info->lmvecs[1] ) + info->lmvecs[1][3] - info->lightmapmins[1]; t += surf->light_t * sample_size; t += sample_size * 0.5f; - t /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->height; + t /= BLOCK_SIZE * sample_size; // fa->texinfo->texture->height; v[5] = s; v[6] = t; @@ -403,11 +409,11 @@ static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount ) // Check for intersecting decals on this surface static decal_t *R_DecalIntersect( decalinfo_t *decalinfo, msurface_t *surf, int *pcount ) { - int texture; - decal_t *plast, *pDecal; - vec3_t decalExtents[2]; - float lastArea = 2; - int mapSize[2]; + int texture; + decal_t *plast, *pDecal; + vec3_t decalExtents[2]; + float lastArea = 2; + int mapSize[2]; plast = NULL; *pcount = 0; @@ -417,8 +423,8 @@ static decal_t *R_DecalIntersect( decalinfo_t *decalinfo, msurface_t *surf, int // precalculate the extents of decalinfo's decal in world space. R_GetDecalDimensions( texture, &mapSize[0], &mapSize[1] ); - VectorScale( decalinfo->m_Basis[0], ((mapSize[0] / decalinfo->m_scale) * 0.5f), decalExtents[0] ); - VectorScale( decalinfo->m_Basis[1], ((mapSize[1] / decalinfo->m_scale) * 0.5f), decalExtents[1] ); + VectorScale( decalinfo->m_Basis[0], (( mapSize[0] / decalinfo->m_scale ) * 0.5f ), decalExtents[0] ); + VectorScale( decalinfo->m_Basis[1], (( mapSize[1] / decalinfo->m_scale ) * 0.5f ), decalExtents[1] ); pDecal = surf->pdecals; @@ -430,11 +436,11 @@ static decal_t *R_DecalIntersect( decalinfo_t *decalinfo, msurface_t *surf, int // Don't steal permanent decals if( !FBitSet( pDecal->flags, FDECAL_PERMANENT )) { - vec3_t testBasis[3]; - vec3_t testPosition[2]; - float testWorldScale[2]; - vec2_t vDecalMin, vDecalMax; - vec2_t vUnionMin, vUnionMax; + vec3_t testBasis[3]; + vec3_t testPosition[2]; + float testWorldScale[2]; + vec2_t vDecalMin, vDecalMax; + vec2_t vUnionMin, vUnionMax; R_SetupDecalTextureSpaceBasis( pDecal, surf, texture, testBasis, testWorldScale ); @@ -445,15 +451,15 @@ static decal_t *R_DecalIntersect( decalinfo_t *decalinfo, msurface_t *surf, int // this decal's (pDecal's) [0,0,1,1] clip space, just like we would if we were // clipping a triangle into pDecal's clip space. Vector2Set( vDecalMin, - DotProduct( testPosition[0], testBasis[0] ) - pDecal->dx + 0.5f, - DotProduct( testPosition[1], testBasis[1] ) - pDecal->dy + 0.5f ); + DotProduct( testPosition[0], testBasis[0] ) - pDecal->dx + 0.5f, + DotProduct( testPosition[1], testBasis[1] ) - pDecal->dy + 0.5f ); VectorAdd( decalinfo->m_Position, decalExtents[0], testPosition[0] ); VectorAdd( decalinfo->m_Position, decalExtents[1], testPosition[1] ); Vector2Set( vDecalMax, - DotProduct( testPosition[0], testBasis[0] ) - pDecal->dx + 0.5f, - DotProduct( testPosition[1], testBasis[1] ) - pDecal->dy + 0.5f ); + DotProduct( testPosition[0], testBasis[0] ) - pDecal->dx + 0.5f, + DotProduct( testPosition[1], testBasis[1] ) - pDecal->dy + 0.5f ); // Now figure out the part of the projection that intersects pDecal's // clip box [0,0,1,1]. @@ -463,7 +469,7 @@ static decal_t *R_DecalIntersect( decalinfo_t *decalinfo, msurface_t *surf, int if( vUnionMin[0] < 1 && vUnionMin[1] < 1 && vUnionMax[0] > 0 && vUnionMax[1] > 0 ) { // Figure out how much of this intersects the (0,0) - (1,1) bbox. - float flArea = (vUnionMax[0] - vUnionMin[1]) * (vUnionMax[1] - vUnionMin[1]); + float flArea = ( vUnionMax[0] - vUnionMin[1] ) * ( vUnionMax[1] - vUnionMin[1] ); if( flArea > 0.6f ) { @@ -472,7 +478,7 @@ static decal_t *R_DecalIntersect( decalinfo_t *decalinfo, msurface_t *surf, int if( !plast || flArea <= lastArea ) { plast = pDecal; - lastArea = flArea; + lastArea = flArea; } } } @@ -491,17 +497,18 @@ creates mesh for decal on first rendering */ static glpoly2_t *R_DecalCreatePoly( decalinfo_t *decalinfo, decal_t *pdecal, msurface_t *surf ) { - int lnumverts; - glpoly2_t *poly; - float *v; - int i; + int lnumverts; + glpoly2_t *poly; + float *v; + int i; return NULL; - if( pdecal->polys ) // already created? + if( pdecal->polys ) // already created? return pdecal->polys; v = R_DecalSetupVerts( pdecal, surf, pdecal->texture, &lnumverts ); - if( !lnumverts ) return NULL; // probably this never happens + if( !lnumverts ) + return NULL; // probably this never happens // allocate glpoly // REFTODO: com_studiocache pool! @@ -526,7 +533,7 @@ static glpoly2_t *R_DecalCreatePoly( decalinfo_t *decalinfo, decal_t *pdecal, ms // Add the decal to the surface's list of decals. static void R_AddDecalToSurface( decal_t *pdecal, msurface_t *surf, decalinfo_t *decalinfo ) { - decal_t *pold; + decal_t *pold; pdecal->pnext = NULL; pold = surf->pdecals; @@ -554,21 +561,24 @@ static void R_AddDecalToSurface( decal_t *pdecal, msurface_t *surf, decalinfo_t // alloc clipped poly for decal R_DecalCreatePoly( decalinfo, pdecal, surf ); - //R_AddDecalVBO( pdecal, surf ); + // R_AddDecalVBO( pdecal, surf ); } static void R_DecalCreate( decalinfo_t *decalinfo, msurface_t *surf, float x, float y ) { - decal_t *pdecal, *pold; - int count, vertCount; + decal_t *pdecal, *pold; + int count, vertCount; - if( !surf ) return; // ??? + if( !surf ) + return; // ??? pold = R_DecalIntersect( decalinfo, surf, &count ); - if( count < MAX_OVERLAP_DECALS ) pold = NULL; + if( count < MAX_OVERLAP_DECALS ) + pold = NULL; pdecal = R_DecalAlloc( pold ); - if( !pdecal ) return; // r_decals == 0 ??? + if( !pdecal ) + return; // r_decals == 0 ??? pdecal->flags = decalinfo->m_Flags; @@ -599,10 +609,10 @@ static void R_DecalCreate( decalinfo_t *decalinfo, msurface_t *surf, float x, fl static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo ) { // get the texture associated with this surface - mtexinfo_t *tex = surf->texinfo; - decal_t *decal = surf->pdecals; - vec4_t textureU, textureV; - float s, t, w, h; + mtexinfo_t *tex = surf->texinfo; + decal_t *decal = surf->pdecals; + vec4_t textureU, textureV; + float s, t, w, h; connstate_t state = ENGINE_GET_PARM( PARM_CONNSTATE ); // we in restore mode @@ -643,18 +653,18 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo ) // (decalWidth * decalBasis[0], decalHeight * decalBasis[1]) // in texture coordinates: - w = fabs( decalinfo->m_decalWidth * DotProduct( textureU, decalinfo->m_Basis[0] )) + - fabs( decalinfo->m_decalHeight * DotProduct( textureU, decalinfo->m_Basis[1] )); + w = fabs( decalinfo->m_decalWidth * DotProduct( textureU, decalinfo->m_Basis[0] )) + + fabs( decalinfo->m_decalHeight * DotProduct( textureU, decalinfo->m_Basis[1] )); - h = fabs( decalinfo->m_decalWidth * DotProduct( textureV, decalinfo->m_Basis[0] )) + - fabs( decalinfo->m_decalHeight * DotProduct( textureV, decalinfo->m_Basis[1] )); + h = fabs( decalinfo->m_decalWidth * DotProduct( textureV, decalinfo->m_Basis[0] )) + + fabs( decalinfo->m_decalHeight * DotProduct( textureV, decalinfo->m_Basis[1] )); // move s,t to upper left corner s -= ( w * 0.5f ); t -= ( h * 0.5f ); // Is this rect within the surface? -- tex width & height are unsigned - if( s <= -w || t <= -h || s > (surf->extents[0] + w) || t > (surf->extents[1] + h)) + if( s <= -w || t <= -h || s > ( surf->extents[0] + w ) || t > ( surf->extents[1] + h )) { return; // nope } @@ -663,40 +673,40 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo ) R_DecalCreate( decalinfo, surf, s, t ); } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // iterate over all surfaces on a node, looking for surfaces to decal -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- static void R_DecalNodeSurfaces( model_t *model, mnode_t *node, decalinfo_t *decalinfo ) { // iterate over all surfaces in the node - msurface_t *surf; - int i; + msurface_t *surf; + int i; surf = model->surfaces + node->firstsurface; for( i = 0; i < node->numsurfaces; i++, surf++ ) { // never apply decals on the water or sky surfaces - if( surf->flags & (SURF_DRAWTURB|SURF_DRAWSKY|SURF_CONVEYOR)) + if( surf->flags & ( SURF_DRAWTURB | SURF_DRAWSKY | SURF_CONVEYOR )) continue; // we can implement alpha testing without stencil - //if( surf->flags & SURF_TRANSPARENT && !glState.stencilEnabled ) - //continue; + // if( surf->flags & SURF_TRANSPARENT && !glState.stencilEnabled ) + // continue; R_DecalSurface( surf, decalinfo ); } } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // Recursive routine to find surface to apply a decal to. World coordinates of // the decal are passed in r_recalpos like the rest of the engine. This should // be called through R_DecalShoot() -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- static void R_DecalNode( model_t *model, mnode_t *node, decalinfo_t *decalinfo ) { - mplane_t *splitplane; - float dist; + mplane_t *splitplane; + float dist; Assert( node != NULL ); @@ -738,11 +748,11 @@ static void R_DecalNode( model_t *model, mnode_t *node, decalinfo_t *decalinfo ) // Shoots a decal onto the surface of the BSP. position is the center of the decal in world coords void GAME_EXPORT R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos, int flags, float scale ) { - decalinfo_t decalInfo; - cl_entity_t *ent = NULL; - model_t *model = NULL; - int width, height; - hull_t *hull; + decalinfo_t decalInfo; + cl_entity_t *ent = NULL; + model_t *model = NULL; + int width, height; + hull_t *hull; if( textureIndex <= 0 || textureIndex >= MAX_TEXTURES ) { @@ -754,15 +764,20 @@ void GAME_EXPORT R_DecalShoot( int textureIndex, int entityIndex, int modelIndex { ent = CL_GetEntityByIndex( entityIndex ); - if( modelIndex > 0 ) model = CL_ModelHandle( modelIndex ); - else if( ent != NULL ) model = CL_ModelHandle( ent->curstate.modelindex ); - else return; + if( modelIndex > 0 ) + model = CL_ModelHandle( modelIndex ); + else if( ent != NULL ) + model = CL_ModelHandle( ent->curstate.modelindex ); + else + return; } else if( modelIndex > 0 ) model = CL_ModelHandle( modelIndex ); - else model = WORLDMODEL; + else + model = WORLDMODEL; - if( !model ) return; + if( !model ) + return; if( model->type != mod_brush ) { @@ -771,18 +786,18 @@ void GAME_EXPORT R_DecalShoot( int textureIndex, int entityIndex, int modelIndex } decalInfo.m_pModel = model; - hull = &model->hulls[0]; // always use #0 hull + hull = &model->hulls[0]; // always use #0 hull // NOTE: all the decals at 'first shoot' placed into local space of parent entity // and won't transform again on a next restore, levelchange etc if( ent && !FBitSet( flags, FDECAL_LOCAL_SPACE )) { - vec3_t pos_l; + vec3_t pos_l; // transform decal position in local bmodel space if( !VectorIsNull( ent->angles )) { - matrix4x4 matrix; + matrix4x4 matrix; Matrix4x4_CreateFromEntity( matrix, ent->angles, ent->origin, 1.0f ); Matrix4x4_VectorITransform( matrix, pos, pos_l ); @@ -831,9 +846,9 @@ void GAME_EXPORT R_DecalShoot( int textureIndex, int entityIndex, int modelIndex // triangles the same way. float * GAME_EXPORT R_DecalSetupVerts( decal_t *pDecal, msurface_t *surf, int texture, int *outCount ) { - glpoly2_t *p = pDecal->polys; - int i, count; - float *v, *v2; + glpoly2_t *p = pDecal->polys; + int i, count; + float *v, *v2; if( p ) { @@ -884,30 +899,31 @@ static qboolean R_DecalUnProject( decal_t *pdecal, decallist_t *entry ) // Grab surface plane equation if( pdecal->psurface->flags & SURF_PLANEBACK ) VectorNegate( pdecal->psurface->plane->normal, entry->impactPlaneNormal ); - else VectorCopy( pdecal->psurface->plane->normal, entry->impactPlaneNormal ); + else + VectorCopy( pdecal->psurface->plane->normal, entry->impactPlaneNormal ); return true; } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // Purpose: // Input : *pList - // count - // Output : static int -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- static int DecalListAdd( decallist_t *pList, int count ) { - vec3_t tmp; - decallist_t *pdecal; - int i; + vec3_t tmp; + decallist_t *pdecal; + int i; pdecal = pList + count; for( i = 0; i < count; i++ ) { - if( !Q_strcmp( pdecal->name, pList[i].name ) && pdecal->entityIndex == pList[i].entityIndex ) + if( !Q_strcmp( pdecal->name, pList[i].name ) && pdecal->entityIndex == pList[i].entityIndex ) { - VectorSubtract( pdecal->position, pList[i].position, tmp ); // Merge + VectorSubtract( pdecal->position, pList[i].position, tmp ); // Merge if( VectorLength( tmp ) < DECAL_OVERLAP_DISTANCE ) return count; @@ -920,7 +936,7 @@ static int DecalListAdd( decallist_t *pList, int count ) static int DecalDepthCompare( const void *a, const void *b ) { - const decallist_t *elem1, *elem2; + const decallist_t *elem1, *elem2; elem1 = (const decallist_t *)a; elem2 = (const decallist_t *)b; @@ -933,15 +949,15 @@ static int DecalDepthCompare( const void *a, const void *b ) return 0; } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // Purpose: Called by CSaveRestore::SaveClientState // Input : *pList - // Output : int -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- int GAME_EXPORT R_CreateDecalList( decallist_t *pList ) { - int total = 0; - int i, depth; + int total = 0; + int i, depth; // return 0; // crash on changelevel. API bug? @@ -949,12 +965,12 @@ int GAME_EXPORT R_CreateDecalList( decallist_t *pList ) { for( i = 0; i < MAX_RENDER_DECALS; i++ ) { - decal_t *decal = &gDecalPool[i]; - decal_t *pdecals; + decal_t *decal = &gDecalPool[i]; + decal_t *pdecals; // decal is in use and is not a custom decal if( decal->psurface == NULL || FBitSet( decal->flags, FDECAL_DONTSAVE )) - continue; + continue; // compute depth depth = 0; @@ -998,8 +1014,8 @@ remove all decals with specified texture */ void GAME_EXPORT R_DecalRemoveAll( int textureIndex ) { - decal_t *pdecal; - int i; + decal_t *pdecal; + int i; if( textureIndex < 0 || textureIndex >= MAX_TEXTURES ) return; // out of bounds @@ -1026,9 +1042,9 @@ remove all decals from specified entity */ void GAME_EXPORT R_EntityRemoveDecals( model_t *mod ) { - msurface_t *psurf; - decal_t *p; - int i; + msurface_t *psurf; + decal_t *p; + int i; if( !mod || mod->type != mod_brush ) return; @@ -1051,8 +1067,8 @@ used for full decals restart */ void GAME_EXPORT R_ClearAllDecals( void ) { - decal_t *pdecal; - int i; + decal_t *pdecal; + int i; // because gDecalCount may be zeroed after recach the decal limit for( i = 0; i < MAX_RENDER_DECALS; i++ ) diff --git a/ref/soft/r_draw.c b/ref/soft/r_draw.c index 4b21ee85..c01d4697 100644 --- a/ref/soft/r_draw.c +++ b/ref/soft/r_draw.c @@ -22,11 +22,13 @@ R_GetImageParms */ void R_GetTextureParms( int *w, int *h, int texnum ) { - image_t *glt; + image_t *glt; glt = R_GetTexture( texnum ); - if( w ) *w = glt->srcWidth; - if( h ) *h = glt->srcHeight; + if( w ) + *w = glt->srcWidth; + if( h ) + *h = glt->srcHeight; } /* @@ -39,14 +41,18 @@ for sprite models */ void GAME_EXPORT R_GetSpriteParms( int *frameWidth, int *frameHeight, int *numFrames, int currentFrame, const model_t *pSprite ) { - mspriteframe_t *pFrame; + mspriteframe_t *pFrame; - if( !pSprite || pSprite->type != mod_sprite ) return; // bad model ? + if( !pSprite || pSprite->type != mod_sprite ) + return; // bad model ? pFrame = R_GetSpriteFrame( pSprite, currentFrame, 0.0f ); - if( frameWidth ) *frameWidth = pFrame->width; - if( frameHeight ) *frameHeight = pFrame->height; - if( numFrames ) *numFrames = pSprite->numframes; + if( frameWidth ) + *frameWidth = pFrame->width; + if( frameHeight ) + *frameHeight = pFrame->height; + if( numFrames ) + *numFrames = pSprite->numframes; } int GAME_EXPORT R_GetSpriteTexture( const model_t *m_pSpriteModel, int frame ) @@ -63,33 +69,33 @@ int GAME_EXPORT R_GetSpriteTexture( const model_t *m_pSpriteModel, int frame ) Draw_StretchPicImplementation ============= */ -static void R_DrawStretchPicImplementation( int x, int y, int w, int h, int s1, int t1, int s2, int t2, image_t *pic ) +static void R_DrawStretchPicImplementation( int x, int y, int w, int h, int s1, int t1, int s2, int t2, image_t *pic ) { - unsigned int height; - int skip, v; - qboolean transparent = false; - pixel_t *buffer; + unsigned int height; + int skip, v; + qboolean transparent = false; + pixel_t *buffer; if( x < 0 ) { - s1 += (-x)*(s2-s1) / w; + s1 += ( -x ) * ( s2 - s1 ) / w; x = 0; } if( x + w > vid.width ) { - s2 -= (x + w - vid.width) * (s2 - s1)/ w ; + s2 -= ( x + w - vid.width ) * ( s2 - s1 ) / w; w = vid.width - x; } if( y + h > vid.height ) { - t2 -= (y + h - vid.height) * (t2 - t1) / h; + t2 -= ( y + h - vid.height ) * ( t2 - t1 ) / h; h = vid.height - y; } if( !pic->pixels[0] || s1 >= s2 || t1 >= t2 ) return; - //gEngfuncs.Con_Printf ("pixels is %p\n", pic->pixels[0] ); + // gEngfuncs.Con_Printf ("pixels is %p\n", pic->pixels[0] ); height = h; @@ -115,21 +121,21 @@ static void R_DrawStretchPicImplementation( int x, int y, int w, int h, int s1, #pragma omp parallel for schedule(static) - for (v=0 ; vwidth + s1; + int alpha1 = vid.alpha; + pixel_t *dest = vid.buffer + ( y + v ) * vid.rowbytes + x; + uint sv = ( skip + v ) * ( t2 - t1 ) / h + t1; + uint u, f, fstep; + pixel_t *source = buffer + sv * pic->width + s1; f = 0; - fstep = ((s2-s1) << 16)/w; + fstep = (( s2 - s1 ) << 16 ) / w; - for (u=0 ; u>16]; - int alpha = alpha1; + pixel_t src = source[f >> 16]; + int alpha = alpha1; f += fstep; if( transparent ) @@ -142,22 +148,22 @@ static void R_DrawStretchPicImplementation( int x, int y, int w, int h, int s1, continue; if( vid.color != COLOR_WHITE ) - src = vid.modmap[(src & 0xff00)|(vid.color>>8)] << 8 | (src & vid.color & 0xff) | ((src & 0xff) >> 3); + src = vid.modmap[( src & 0xff00 ) | ( vid.color >> 8 )] << 8 | ( src & vid.color & 0xff ) | (( src & 0xff ) >> 3 ); - if( vid.rendermode == kRenderTransAdd) + if( vid.rendermode == kRenderTransAdd ) { pixel_t screen = dest[u]; - dest[u] = vid.addmap[(src & 0xff00)|(screen>>8)] << 8 | (screen & 0xff) | ((src & 0xff) >> 0); + dest[u] = vid.addmap[( src & 0xff00 ) | ( screen >> 8 )] << 8 | ( screen & 0xff ) | (( src & 0xff ) >> 0 ); } else if( vid.rendermode == kRenderScreenFadeModulate ) { pixel_t screen = dest[u]; dest[u] = BLEND_COLOR( screen, vid.color ); } - else if( alpha < 7) // && (vid.rendermode == kRenderTransAlpha || vid.rendermode == kRenderTransTexture ) ) + else if( alpha < 7 ) // && (vid.rendermode == kRenderTransAlpha || vid.rendermode == kRenderTransTexture ) ) { - pixel_t screen = dest[u]; // | 0xff & screen & src ; - dest[u] = BLEND_ALPHA( alpha, src, screen );//vid.alphamap[( alpha << 16)|(src & 0xff00)|(screen>>8)] << 8 | (screen & 0xff) >> 3 | ((src & 0xff) >> 3); + pixel_t screen = dest[u]; // | 0xff & screen & src ; + dest[u] = BLEND_ALPHA( alpha, src, screen ); // vid.alphamap[( alpha << 16)|(src & 0xff00)|(screen>>8)] << 8 | (screen & 0xff) >> 3 | ((src & 0xff) >> 3); } else dest[u] = src; @@ -174,8 +180,8 @@ R_DrawStretchPic */ void GAME_EXPORT R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum ) { - image_t *pic = R_GetTexture(texnum); - int width = pic->width, height = pic->height; + image_t *pic = R_GetTexture( texnum ); + int width = pic->width, height = pic->height; // GL_Bind( XASH_TEXTURE0, texnum ); if( s2 > 1.0f || t2 > 1.0f ) return; @@ -183,15 +189,15 @@ void GAME_EXPORT R_DrawStretchPic( float x, float y, float w, float h, float s1, return; if( w < 1.0f || h < 1.0f ) return; - R_DrawStretchPicImplementation(x,y,w,h, width * s1, height * t1, width * s2, height * t2, pic); + R_DrawStretchPicImplementation( x, y, w, h, width * s1, height * t1, width * s2, height * t2, pic ); } -void Draw_Fill (int x, int y, int w, int h) +void Draw_Fill( int x, int y, int w, int h ) { unsigned int height; - int v; - pixel_t src = vid.color; - int alpha = vid.alpha; + int v; + pixel_t src = vid.color; + int alpha = vid.alpha; if( x < 0 ) x = 0; @@ -218,25 +224,25 @@ void Draw_Fill (int x, int y, int w, int h) } #pragma omp parallel for schedule(static) - for (v=0 ; v>8)] << 8 | (screen & 0xff) | ((src & 0xff) >> 0); + dest[u] = vid.addmap[( src & 0xff00 ) | ( screen >> 8 )] << 8 | ( screen & 0xff ) | (( src & 0xff ) >> 0 ); } - else if( alpha < 7) // && (vid.rendermode == kRenderTransAlpha || vid.rendermode == kRenderTransTexture ) ) + else if( alpha < 7 ) // && (vid.rendermode == kRenderTransAlpha || vid.rendermode == kRenderTransTexture ) ) { - pixel_t screen = dest[u]; // | 0xff & screen & src ; - dest[u] = BLEND_ALPHA( alpha, src, screen);//vid.alphamap[( alpha << 16)|(src & 0xff00)|(screen>>8)] << 8 | (screen & 0xff) >> 3 | ((src & 0xff) >> 3); + pixel_t screen = dest[u]; // | 0xff & screen & src ; + dest[u] = BLEND_ALPHA( alpha, src, screen ); // vid.alphamap[( alpha << 16)|(src & 0xff00)|(screen>>8)] << 8 | (screen & 0xff) >> 3 | ((src & 0xff) >> 3); } else dest[u] = src; @@ -251,14 +257,14 @@ R_DrawStretchRaw */ void GAME_EXPORT R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty ) { - byte *raw = NULL; - image_t *tex; + byte *raw = NULL; + image_t *tex; raw = (byte *)data; - //pglDisable( GL_BLEND ); - //pglDisable( GL_ALPHA_TEST ); - //pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); + // pglDisable( GL_BLEND ); + // pglDisable( GL_ALPHA_TEST ); + // pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); tex = R_GetTexture( tr.cinTexture ); GL_Bind( XASH_TEXTURE0, tr.cinTexture ); @@ -271,8 +277,8 @@ R_UploadStretchRaw */ void GAME_EXPORT R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data ) { - byte *raw = NULL; - image_t *tex; + byte *raw = NULL; + image_t *tex; raw = (byte *)data; tex = R_GetTexture( texture ); diff --git a/ref/soft/r_edge.c b/ref/soft/r_edge.c index 556a6d9e..a523ed66 100644 --- a/ref/soft/r_edge.c +++ b/ref/soft/r_edge.c @@ -21,52 +21,52 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" -edge_t *auxedges; -edge_t *r_edges, *edge_p, *edge_max; +edge_t *auxedges; +edge_t *r_edges, *edge_p, *edge_max; -surf_t *surfaces, *surface_p, *surf_max; +surf_t *surfaces, *surface_p, *surf_max; // surfaces are generated in back to front order by the bsp, so if a surf // pointer is greater than another one, it should be drawn in front // surfaces[1] is the background, and is used as the active surface stack -edge_t *newedges[MAXHEIGHT]; -edge_t *removeedges[MAXHEIGHT]; +edge_t *newedges[MAXHEIGHT]; +edge_t *removeedges[MAXHEIGHT]; -espan_t *span_p, *max_span_p; +espan_t *span_p, *max_span_p; -int r_currentkey; +int r_currentkey; -int current_iv; +int current_iv; -int edge_head_u_shift20, edge_tail_u_shift20; +int edge_head_u_shift20, edge_tail_u_shift20; -static void (*pdrawfunc)(void); +static void (*pdrawfunc)( void ); -edge_t edge_head; -edge_t edge_tail; +edge_t edge_head; +edge_t edge_tail; -edge_t edge_aftertail; -edge_t edge_sentinel; +edge_t edge_aftertail; +edge_t edge_sentinel; -static float fv; +static float fv; -static int miplevel; +static int miplevel; -float scale_for_mip; +float scale_for_mip; // FIXME: should go away -extern void R_RotateBmodel (void); -extern void R_TransformFrustum (void); +extern void R_RotateBmodel( void ); +extern void R_TransformFrustum( void ); -void R_GenerateSpans (void); -void R_GenerateSpansBackward (void); +void R_GenerateSpans( void ); +void R_GenerateSpansBackward( void ); -void R_LeadingEdge (edge_t *edge); -void R_LeadingEdgeBackwards (edge_t *edge); -void R_TrailingEdge (surf_t *surf, edge_t *edge); +void R_LeadingEdge( edge_t *edge ); +void R_LeadingEdgeBackwards( edge_t *edge ); +void R_TrailingEdge( surf_t *surf, edge_t *edge ); /* @@ -82,20 +82,20 @@ EDGE SCANNING R_BeginEdgeFrame ============== */ -void R_BeginEdgeFrame (void) +void R_BeginEdgeFrame( void ) { - int v; + int v; edge_p = r_edges; edge_max = &r_edges[r_numallocatededges]; - surface_p = &surfaces[2]; // background is surface 1, - // surface 0 is a dummy - surfaces[1].spans = NULL; // no background spans yet - surfaces[1].flags = 0; // SURF_DRAWBACKGROUND; + surface_p = &surfaces[2]; // background is surface 1, + // surface 0 is a dummy + surfaces[1].spans = NULL; // no background spans yet + surfaces[1].flags = 0; // SURF_DRAWBACKGROUND; // put the background behind everything in the world - if (sw_draworder.value) + if( sw_draworder.value ) { pdrawfunc = R_GenerateSpansBackward; surfaces[1].key = 0; @@ -109,7 +109,7 @@ void R_BeginEdgeFrame (void) } // FIXME: set with memset - for (v=RI.vrect.y ; vu >= edgestoadd->u) + if( edgelist->u >= edgestoadd->u ) goto addedge; - edgelist=edgelist->next; - if (edgelist->u >= edgestoadd->u) + edgelist = edgelist->next; + if( edgelist->u >= edgestoadd->u ) goto addedge; - edgelist=edgelist->next; - if (edgelist->u >= edgestoadd->u) + edgelist = edgelist->next; + if( edgelist->u >= edgestoadd->u ) goto addedge; - edgelist=edgelist->next; - if (edgelist->u >= edgestoadd->u) + edgelist = edgelist->next; + if( edgelist->u >= edgestoadd->u ) goto addedge; - edgelist=edgelist->next; + edgelist = edgelist->next; goto edgesearch; - // insert edgestoadd before edgelist + // insert edgestoadd before edgelist addedge: edgestoadd->next = edgelist; edgestoadd->prev = edgelist->prev; edgelist->prev->next = edgestoadd; edgelist->prev = edgestoadd; - } while ((edgestoadd = next_edge) != NULL); + } + while(( edgestoadd = next_edge ) != NULL ); } /* @@ -166,14 +167,15 @@ addedge: R_RemoveEdges ============== */ -static void R_RemoveEdges (edge_t *pedge) +static void R_RemoveEdges( edge_t *pedge ) { do { pedge->next->prev = pedge->prev; pedge->prev->next = pedge->next; - } while ((pedge = pedge->nextremove) != NULL); + } + while(( pedge = pedge->nextremove ) != NULL ); } /* @@ -181,66 +183,66 @@ static void R_RemoveEdges (edge_t *pedge) R_StepActiveU ============== */ -static void R_StepActiveU (edge_t *pedge) +static void R_StepActiveU( edge_t *pedge ) { - edge_t *pnext_edge, *pwedge; + edge_t *pnext_edge, *pwedge; - while (1) + while( 1 ) { nextedge: pedge->u += pedge->u_step; - if (pedge->u < pedge->prev->u) + if( pedge->u < pedge->prev->u ) goto pushback; pedge = pedge->next; pedge->u += pedge->u_step; - if (pedge->u < pedge->prev->u) + if( pedge->u < pedge->prev->u ) goto pushback; pedge = pedge->next; pedge->u += pedge->u_step; - if (pedge->u < pedge->prev->u) + if( pedge->u < pedge->prev->u ) goto pushback; pedge = pedge->next; pedge->u += pedge->u_step; - if (pedge->u < pedge->prev->u) + if( pedge->u < pedge->prev->u ) goto pushback; pedge = pedge->next; goto nextedge; pushback: - if (pedge == &edge_aftertail) + if( pedge == &edge_aftertail ) return; - // push it back to keep it sorted + // push it back to keep it sorted pnext_edge = pedge->next; - // pull the edge out of the edge list + // pull the edge out of the edge list pedge->next->prev = pedge->prev; pedge->prev->next = pedge->next; - // find out where the edge goes in the edge list + // find out where the edge goes in the edge list pwedge = pedge->prev->prev; - // if( !pwedge ) + // if( !pwedge ) // return; - while (pwedge->u > pedge->u) + while( pwedge->u > pedge->u ) { pwedge = pwedge->prev; - //if( !pwedge ) - //return; + // if( !pwedge ) + // return; } - // put the edge back into the edge list + // put the edge back into the edge list pedge->next = pwedge->next; pedge->prev = pwedge; pedge->next->prev = pedge; pwedge->next = pedge; pedge = pnext_edge; - if (pedge == &edge_tail) + if( pedge == &edge_tail ) return; } } @@ -250,17 +252,17 @@ pushback: R_CleanupSpan ============== */ -static void R_CleanupSpan (void) +static void R_CleanupSpan( void ) { - surf_t *surf; - int iu; - espan_t *span; + surf_t *surf; + int iu; + espan_t *span; // now that we've reached the right edge of the screen, we're done with any // unfinished surfaces, so emit a span for whatever's on top surf = surfaces[1].next; iu = edge_tail_u_shift20; - if (iu > surf->last_u) + if( iu > surf->last_u ) { span = span_p++; span->u = surf->last_u; @@ -275,7 +277,8 @@ static void R_CleanupSpan (void) { surf->spanstate = 0; surf = surf->next; - } while (surf != &surfaces[1]); + } + while( surf != &surfaces[1] ); } @@ -284,11 +287,11 @@ static void R_CleanupSpan (void) R_LeadingEdgeBackwards ============== */ -void R_LeadingEdgeBackwards (edge_t *edge) +void R_LeadingEdgeBackwards( edge_t *edge ) { - espan_t *span; - surf_t *surf, *surf2; - int iu; + espan_t *span; + surf_t *surf, *surf2; + int iu; // it's adding a new surface in, so find the correct place surf = &surfaces[edge->surfs[1]]; @@ -296,19 +299,19 @@ void R_LeadingEdgeBackwards (edge_t *edge) // don't start a span if this is an inverted span, with the end // edge preceding the start edge (that is, we've already seen the // end edge) - if (++surf->spanstate == 1) + if( ++surf->spanstate == 1 ) { surf2 = surfaces[1].next; - if (surf->key > surf2->key) + if( surf->key > surf2->key ) goto newtop; - // if it's two surfaces on the same plane, the one that's already - // active is in front, so keep going unless it's a bmodel - if (surf->insubmodel && (surf->key == surf2->key)) + // if it's two surfaces on the same plane, the one that's already + // active is in front, so keep going unless it's a bmodel + if( surf->insubmodel && ( surf->key == surf2->key )) { - // must be two bmodels in the same leaf; don't care, because they'll - // never be farthest anyway + // must be two bmodels in the same leaf; don't care, because they'll + // never be farthest anyway goto newtop; } @@ -317,26 +320,27 @@ continue_search: do { surf2 = surf2->next; - } while (surf->key < surf2->key); + } + while( surf->key < surf2->key ); - if (surf->key == surf2->key) + if( surf->key == surf2->key ) { - // if it's two surfaces on the same plane, the one that's already - // active is in front, so keep going unless it's a bmodel - if (!surf->insubmodel) + // if it's two surfaces on the same plane, the one that's already + // active is in front, so keep going unless it's a bmodel + if( !surf->insubmodel ) goto continue_search; - // must be two bmodels in the same leaf; don't care which is really - // in front, because they'll never be farthest anyway + // must be two bmodels in the same leaf; don't care which is really + // in front, because they'll never be farthest anyway } goto gotposition; newtop: - // emit a span (obscures current top) + // emit a span (obscures current top) iu = edge->u >> 20; - if (iu > surf2->last_u) + if( iu > surf2->last_u ) { span = span_p++; span->u = surf2->last_u; @@ -350,7 +354,7 @@ newtop: surf->last_u = iu; gotposition: - // insert before surf2 + // insert before surf2 surf->next = surf2; surf->prev = surf2->prev; surf2->prev->next = surf; @@ -364,21 +368,21 @@ gotposition: R_TrailingEdge ============== */ -void R_TrailingEdge (surf_t *surf, edge_t *edge) +void R_TrailingEdge( surf_t *surf, edge_t *edge ) { - espan_t *span; - int iu; + espan_t *span; + int iu; // don't generate a span if this is an inverted span, with the end // edge preceding the start edge (that is, we haven't seen the // start edge yet) - if (--surf->spanstate == 0) + if( --surf->spanstate == 0 ) { - if (surf == surfaces[1].next) + if( surf == surfaces[1].next ) { - // emit a span (current top going away) + // emit a span (current top going away) iu = edge->u >> 20; - if (iu > surf->last_u) + if( iu > surf->last_u ) { span = span_p++; span->u = surf->last_u; @@ -388,7 +392,7 @@ void R_TrailingEdge (surf_t *surf, edge_t *edge) surf->spans = span; } - // set last_u on the surface below + // set last_u on the surface below surf->next->last_u = iu; } @@ -402,50 +406,50 @@ void R_TrailingEdge (surf_t *surf, edge_t *edge) R_LeadingEdge ============== */ -void R_LeadingEdge (edge_t *edge) +void R_LeadingEdge( edge_t *edge ) { - espan_t *span; - surf_t *surf, *surf2; - int iu; - float fu, newzi, testzi, newzitop, newzibottom; + espan_t *span; + surf_t *surf, *surf2; + int iu; + float fu, newzi, testzi, newzitop, newzibottom; - if (edge->surfs[1]) + if( edge->surfs[1] ) { - // it's adding a new surface in, so find the correct place + // it's adding a new surface in, so find the correct place surf = &surfaces[edge->surfs[1]]; - // don't start a span if this is an inverted span, with the end - // edge preceding the start edge (that is, we've already seen the - // end edge) - if (++surf->spanstate == 1) + // don't start a span if this is an inverted span, with the end + // edge preceding the start edge (that is, we've already seen the + // end edge) + if( ++surf->spanstate == 1 ) { surf2 = surfaces[1].next; - if (surf->key < surf2->key) + if( surf->key < surf2->key ) goto newtop; - // if it's two surfaces on the same plane, the one that's already - // active is in front, so keep going unless it's a bmodel - if (surf->insubmodel && (surf->key == surf2->key)) + // if it's two surfaces on the same plane, the one that's already + // active is in front, so keep going unless it's a bmodel + if( surf->insubmodel && ( surf->key == surf2->key )) { - // must be two bmodels in the same leaf; sort on 1/z - fu = (float)(edge->u - 0xFFFFF) * (1.0f / 0x100000); - newzi = surf->d_ziorigin + fv*surf->d_zistepv + - fu*surf->d_zistepu; + // must be two bmodels in the same leaf; sort on 1/z + fu = (float)( edge->u - 0xFFFFF ) * ( 1.0f / 0x100000 ); + newzi = surf->d_ziorigin + fv * surf->d_zistepv + + fu * surf->d_zistepu; newzibottom = newzi * 0.99f; - testzi = surf2->d_ziorigin + fv*surf2->d_zistepv + - fu*surf2->d_zistepu; + testzi = surf2->d_ziorigin + fv * surf2->d_zistepv + + fu * surf2->d_zistepu; - if (newzibottom >= testzi) + if( newzibottom >= testzi ) { goto newtop; } newzitop = newzi * 1.01f; - if (newzitop >= testzi) + if( newzitop >= testzi ) { - if (surf->d_zistepu >= surf2->d_zistepu) + if( surf->d_zistepu >= surf2->d_zistepu ) { goto newtop; } @@ -457,33 +461,34 @@ continue_search: do { surf2 = surf2->next; - } while (surf->key > surf2->key); + } + while( surf->key > surf2->key ); - if (surf->key == surf2->key) + if( surf->key == surf2->key ) { - // if it's two surfaces on the same plane, the one that's already - // active is in front, so keep going unless it's a bmodel - if (!surf->insubmodel) + // if it's two surfaces on the same plane, the one that's already + // active is in front, so keep going unless it's a bmodel + if( !surf->insubmodel ) goto continue_search; - // must be two bmodels in the same leaf; sort on 1/z - fu = (float)(edge->u - 0xFFFFF) * (1.0f / 0x100000); - newzi = surf->d_ziorigin + fv*surf->d_zistepv + - fu*surf->d_zistepu; + // must be two bmodels in the same leaf; sort on 1/z + fu = (float)( edge->u - 0xFFFFF ) * ( 1.0f / 0x100000 ); + newzi = surf->d_ziorigin + fv * surf->d_zistepv + + fu * surf->d_zistepu; newzibottom = newzi * 0.99f; - testzi = surf2->d_ziorigin + fv*surf2->d_zistepv + - fu*surf2->d_zistepu; + testzi = surf2->d_ziorigin + fv * surf2->d_zistepv + + fu * surf2->d_zistepu; - if (newzibottom >= testzi) + if( newzibottom >= testzi ) { goto gotposition; } newzitop = newzi * 1.01f; - if (newzitop >= testzi) + if( newzitop >= testzi ) { - if (surf->d_zistepu >= surf2->d_zistepu) + if( surf->d_zistepu >= surf2->d_zistepu ) { goto gotposition; } @@ -495,10 +500,10 @@ continue_search: goto gotposition; newtop: - // emit a span (obscures current top) + // emit a span (obscures current top) iu = edge->u >> 20; - if (iu > surf2->last_u) + if( iu > surf2->last_u ) { span = span_p++; span->u = surf2->last_u; @@ -512,7 +517,7 @@ newtop: surf->last_u = iu; gotposition: - // insert before surf2 + // insert before surf2 surf->next = surf2; surf->prev = surf2->prev; surf2->prev->next = surf; @@ -527,33 +532,33 @@ gotposition: R_GenerateSpans ============== */ -void R_GenerateSpans (void) +void R_GenerateSpans( void ) { - edge_t *edge; - surf_t *surf; + edge_t *edge; + surf_t *surf; // clear active surfaces to just the background surface surfaces[1].next = surfaces[1].prev = &surfaces[1]; surfaces[1].last_u = edge_head_u_shift20; // generate spans - for (edge=edge_head.next ; edge != &edge_tail; edge=edge->next) + for( edge = edge_head.next; edge != &edge_tail; edge = edge->next ) { - if (edge->surfs[0]) + if( edge->surfs[0] ) { - // it has a left surface, so a surface is going away for this span + // it has a left surface, so a surface is going away for this span surf = &surfaces[edge->surfs[0]]; - R_TrailingEdge (surf, edge); + R_TrailingEdge( surf, edge ); - if (!edge->surfs[1]) + if( !edge->surfs[1] ) continue; } - R_LeadingEdge (edge); + R_LeadingEdge( edge ); } - R_CleanupSpan (); + R_CleanupSpan(); } /* @@ -561,25 +566,25 @@ void R_GenerateSpans (void) R_GenerateSpansBackward ============== */ -void R_GenerateSpansBackward (void) +void R_GenerateSpansBackward( void ) { - edge_t *edge; + edge_t *edge; // clear active surfaces to just the background surface surfaces[1].next = surfaces[1].prev = &surfaces[1]; surfaces[1].last_u = edge_head_u_shift20; // generate spans - for (edge=edge_head.next ; edge != &edge_tail; edge=edge->next) + for( edge = edge_head.next; edge != &edge_tail; edge = edge->next ) { - if (edge->surfs[0]) - R_TrailingEdge (&surfaces[edge->surfs[0]], edge); + if( edge->surfs[0] ) + R_TrailingEdge( &surfaces[edge->surfs[0]], edge ); - if (edge->surfs[1]) - R_LeadingEdgeBackwards (edge); + if( edge->surfs[1] ) + R_LeadingEdgeBackwards( edge ); } - R_CleanupSpan (); + R_CleanupSpan(); } @@ -595,15 +600,15 @@ Output: Each surface has a linked list of its visible spans ============== */ -void R_ScanEdges (void) +void R_ScanEdges( void ) { - int iv, bottom; - byte basespans[MAXSPANS*sizeof(espan_t)+CACHE_SIZE]; - espan_t *basespan_p; - surf_t *s; + int iv, bottom; + byte basespans[MAXSPANS * sizeof( espan_t ) + CACHE_SIZE]; + espan_t *basespan_p; + surf_t *s; basespan_p = (espan_t *) - ((uintptr_t)(basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); + ((uintptr_t)( basespans + CACHE_SIZE - 1 ) & ~( CACHE_SIZE - 1 )); max_span_p = &basespan_p[MAXSPANS - RI.vrect.width]; span_p = basespan_p; @@ -618,7 +623,7 @@ void R_ScanEdges (void) edge_head.surfs[0] = 0; edge_head.surfs[1] = 1; - edge_tail.u =(RI.vrectright << 20) + 0xFFFFF; // (r_refdef.vrectright << 20) + 0xFFFFF; + edge_tail.u = ( RI.vrectright << 20 ) + 0xFFFFF; // (r_refdef.vrectright << 20) + 0xFFFFF; edge_tail_u_shift20 = edge_tail.u >> 20; edge_tail.u_step = 0; edge_tail.prev = &edge_head; @@ -626,13 +631,13 @@ void R_ScanEdges (void) edge_tail.surfs[0] = 1; edge_tail.surfs[1] = 0; - edge_aftertail.u = -1; // force a move + edge_aftertail.u = -1; // force a move edge_aftertail.u_step = 0; edge_aftertail.next = &edge_sentinel; edge_aftertail.prev = &edge_tail; // FIXME: do we need this now that we clamp x in r_draw.c? - edge_sentinel.u = 2000 << 20; // make sure nothing sorts past this + edge_sentinel.u = 2000 << 20; // make sure nothing sorts past this edge_sentinel.prev = &edge_aftertail; // @@ -640,37 +645,37 @@ void R_ScanEdges (void) // bottom = RI.vrectbottom - 1; - for (iv=0 ; iv max_span_p) + // flush the span list if we can't be sure we have enough spans left for + // the next scan + if( span_p > max_span_p ) { - D_DrawSurfaces (); + D_DrawSurfaces(); - // clear the surface span pointers - for (s = &surfaces[1] ; sspans = NULL; span_p = basespan_p; } - if (removeedges[iv]) - R_RemoveEdges (removeedges[iv]); + if( removeedges[iv] ) + R_RemoveEdges( removeedges[iv] ); - if (edge_head.next != &edge_tail) - R_StepActiveU (edge_head.next); + if( edge_head.next != &edge_tail ) + R_StepActiveU( edge_head.next ); } // do the last scan (no need to step or sort or remove on the last scan) @@ -681,13 +686,13 @@ void R_ScanEdges (void) // mark that the head (background start) span is pre-included surfaces[1].spanstate = 1; - if (newedges[iv]) - R_InsertNewEdges (newedges[iv], edge_head.next); + if( newedges[iv] ) + R_InsertNewEdges( newedges[iv], edge_head.next ); - (*pdrawfunc) (); + ( *pdrawfunc )(); // draw whatever's left in the span list - D_DrawSurfaces (); + D_DrawSurfaces(); } @@ -699,31 +704,31 @@ SURFACE FILLING ========================================================================= */ -msurface_t *pface; -surfcache_t *pcurrentcache; -vec3_t transformed_modelorg; -vec3_t world_transformed_modelorg; -vec3_t local_modelorg; +msurface_t *pface; +surfcache_t *pcurrentcache; +vec3_t transformed_modelorg; +vec3_t world_transformed_modelorg; +vec3_t local_modelorg; /* ============= D_MipLevelForScale ============= */ -static int D_MipLevelForScale (float scale) +static int D_MipLevelForScale( float scale ) { - int lmiplevel; + int lmiplevel; - if (scale >= d_scalemip[0] ) + if( scale >= d_scalemip[0] ) lmiplevel = 0; - else if (scale >= d_scalemip[1] ) + else if( scale >= d_scalemip[1] ) lmiplevel = 1; - else if (scale >= d_scalemip[2] ) + else if( scale >= d_scalemip[2] ) lmiplevel = 2; else lmiplevel = 3; - if (lmiplevel < d_minmip) + if( lmiplevel < d_minmip ) lmiplevel = d_minmip; return lmiplevel; @@ -737,18 +742,18 @@ D_FlatFillSurface Simple single color fill with no texture mapping ============== */ -static void D_FlatFillSurface (surf_t *surf, int color) +static void D_FlatFillSurface( surf_t *surf, int color ) { - espan_t *span; - pixel_t *pdest; - int u, u2; + espan_t *span; + pixel_t *pdest; + int u, u2; - for (span=surf->spans ; span ; span=span->pnext) + for( span = surf->spans; span; span = span->pnext ) { - pdest = d_viewbuffer + r_screenwidth*span->v; + pdest = d_viewbuffer + r_screenwidth * span->v; u = span->u; u2 = span->u + span->count - 1; - for ( ; u <= u2 ; u++) + for( ; u <= u2; u++ ) pdest[u] = color; } } @@ -759,28 +764,28 @@ static void D_FlatFillSurface (surf_t *surf, int color) D_CalcGradients ============== */ -static void D_CalcGradients (msurface_t *pface) +static void D_CalcGradients( msurface_t *pface ) { - mplane_t *pplane; - float mipscale; - vec3_t p_temp1; - vec3_t p_saxis, p_taxis; - float t; + mplane_t *pplane; + float mipscale; + vec3_t p_temp1; + vec3_t p_saxis, p_taxis; + float t; pplane = pface->plane; - mipscale = 1.0f / (float)(1 << miplevel); + mipscale = 1.0f / (float)( 1 << miplevel ); if( pface->texinfo->flags & TEX_WORLD_LUXELS ) { - TransformVector (pface->texinfo->vecs[0], p_saxis); - TransformVector (pface->texinfo->vecs[1], p_taxis); + TransformVector( pface->texinfo->vecs[0], p_saxis ); + TransformVector( pface->texinfo->vecs[1], p_taxis ); } else { - TransformVector (pface->info->lmvecs[0], p_saxis); - TransformVector (pface->info->lmvecs[1], p_taxis); + TransformVector( pface->info->lmvecs[0], p_saxis ); + TransformVector( pface->info->lmvecs[1], p_taxis ); } t = xscaleinv * mipscale; @@ -791,50 +796,50 @@ static void D_CalcGradients (msurface_t *pface) d_sdivzstepv = -p_saxis[1] * t; d_tdivzstepv = -p_taxis[1] * t; - d_sdivzorigin = p_saxis[2] * mipscale - xcenter * d_sdivzstepu - - ycenter * d_sdivzstepv; - d_tdivzorigin = p_taxis[2] * mipscale - xcenter * d_tdivzstepu - - ycenter * d_tdivzstepv; + d_sdivzorigin = p_saxis[2] * mipscale - xcenter * d_sdivzstepu + - ycenter * d_sdivzstepv; + d_tdivzorigin = p_taxis[2] * mipscale - xcenter * d_tdivzstepu + - ycenter * d_tdivzstepv; - VectorScale (transformed_modelorg, mipscale, p_temp1); + VectorScale( transformed_modelorg, mipscale, p_temp1 ); - t = 0x10000*mipscale; + t = 0x10000 * mipscale; if( pface->texinfo->flags & TEX_WORLD_LUXELS ) { - sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5f)) - - ((pface->texturemins[0] << 16) >> miplevel) - + pface->texinfo->vecs[0][3]*t; - tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5f)) - - ((pface->texturemins[1] << 16) >> miplevel) - + pface->texinfo->vecs[1][3]*t; + sadjust = ((fixed16_t)( DotProduct( p_temp1, p_saxis ) * 0x10000 + 0.5f )) + - (( pface->texturemins[0] << 16 ) >> miplevel ) + + pface->texinfo->vecs[0][3] * t; + tadjust = ((fixed16_t)( DotProduct( p_temp1, p_taxis ) * 0x10000 + 0.5f )) + - (( pface->texturemins[1] << 16 ) >> miplevel ) + + pface->texinfo->vecs[1][3] * t; } else { - sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5f)) - - ((pface->info->lightmapmins[0] << 16) >> miplevel) - + pface->info->lmvecs[0][3]*t; - tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5f)) - - ((pface->info->lightmapmins[1] << 16) >> miplevel) - + pface->info->lmvecs[1][3]*t; + sadjust = ((fixed16_t)( DotProduct( p_temp1, p_saxis ) * 0x10000 + 0.5f )) + - (( pface->info->lightmapmins[0] << 16 ) >> miplevel ) + + pface->info->lmvecs[0][3] * t; + tadjust = ((fixed16_t)( DotProduct( p_temp1, p_taxis ) * 0x10000 + 0.5f )) + - (( pface->info->lightmapmins[1] << 16 ) >> miplevel ) + + pface->info->lmvecs[1][3] * t; } // PGM - changing flow speed for non-warping textures. - if (pface->flags & SURF_CONVEYOR) + if( pface->flags & SURF_CONVEYOR ) { - if(pface->flags & SURF_DRAWTURB) - sadjust += 0x10000 * (-128 * ( (gp_cl->time * 0.25f) - (int)(gp_cl->time * 0.25f) )); + if( pface->flags & SURF_DRAWTURB ) + sadjust += 0x10000 * ( -128 * (( gp_cl->time * 0.25f ) - (int)( gp_cl->time * 0.25f ))); else - sadjust += 0x10000 * (-128 * ( (gp_cl->time * 0.77f) - (int)(gp_cl->time * 0.77f) )); - bbextents = ((pface->extents[0] << 16) >> miplevel) - 1; + sadjust += 0x10000 * ( -128 * (( gp_cl->time * 0.77f ) - (int)( gp_cl->time * 0.77f ))); + bbextents = (( pface->extents[0] << 16 ) >> miplevel ) - 1; } else - bbextents = ((pface->info->lightextents[0] << 16) >> miplevel) - 1; - bbextentt = ((pface->info->lightextents[1] << 16) >> miplevel) - 1; + bbextents = (( pface->info->lightextents[0] << 16 ) >> miplevel ) - 1; + bbextentt = (( pface->info->lightextents[1] << 16 ) >> miplevel ) - 1; if( pface->texinfo->flags & TEX_WORLD_LUXELS ) { - bbextents = ((pface->extents[0] << 16) >> miplevel) - 1; - bbextentt = ((pface->extents[1] << 16) >> miplevel) - 1; + bbextents = (( pface->extents[0] << 16 ) >> miplevel ) - 1; + bbextentt = (( pface->extents[1] << 16 ) >> miplevel ) - 1; } } @@ -846,7 +851,7 @@ D_BackgroundSurf The grey background filler seen when there is a hole in the map ============== */ -static void D_BackgroundSurf (surf_t *s) +static void D_BackgroundSurf( surf_t *s ) { // set up a gradient for the background surface that places it // effectively at infinity distance from the viewpoint @@ -854,8 +859,8 @@ static void D_BackgroundSurf (surf_t *s) d_zistepv = 0; d_ziorigin = -0.9; - D_FlatFillSurface (s, (int)sw_clearcolor.value & 0xFFFF); - D_DrawZSpans (s->spans); + D_FlatFillSurface( s, (int)sw_clearcolor.value & 0xFFFF ); + D_DrawZSpans( s->spans ); } /* @@ -863,7 +868,7 @@ static void D_BackgroundSurf (surf_t *s) D_TurbulentSurf ================= */ -static void D_TurbulentSurf (surf_t *s) +static void D_TurbulentSurf( surf_t *s ) { d_zistepu = s->d_zistepu; d_zistepv = s->d_zistepv; @@ -871,51 +876,51 @@ static void D_TurbulentSurf (surf_t *s) pface = s->msurf; miplevel = 0; - cacheblock = R_GetTexture(pface->texinfo->texture->gl_texturenum)->pixels[0]; + cacheblock = R_GetTexture( pface->texinfo->texture->gl_texturenum )->pixels[0]; cachewidth = 64; - if (s->insubmodel) + if( s->insubmodel ) { - // FIXME: we don't want to do all this for every polygon! - // TODO: store once at start of frame - RI.currententity = s->entity; //FIXME: make this passed in to - // R_RotateBmodel () - VectorSubtract (RI.vieworg, RI.currententity->origin, - local_modelorg); - TransformVector (local_modelorg, transformed_modelorg); + // FIXME: we don't want to do all this for every polygon! + // TODO: store once at start of frame + RI.currententity = s->entity; // FIXME: make this passed in to + // R_RotateBmodel () + VectorSubtract( RI.vieworg, RI.currententity->origin, + local_modelorg ); + TransformVector( local_modelorg, transformed_modelorg ); - R_RotateBmodel (); // FIXME: don't mess with the frustum, - // make entity passed in + R_RotateBmodel(); // FIXME: don't mess with the frustum, + // make entity passed in } - D_CalcGradients (pface); + D_CalcGradients( pface ); -//============ -//PGM +// ============ +// PGM // textures that aren't warping are just flowing. Use NonTurbulent8 instead - if(!(pface->flags & SURF_DRAWTURB)) - NonTurbulent8 (s->spans); + if( !( pface->flags & SURF_DRAWTURB )) + NonTurbulent8( s->spans ); else - Turbulent8 (s->spans); -//PGM -//============ + Turbulent8( s->spans ); +// PGM +// ============ - D_DrawZSpans (s->spans); + D_DrawZSpans( s->spans ); - if (s->insubmodel) + if( s->insubmodel ) { - // - // restore the old drawing state - // FIXME: we don't want to do this every time! - // TODO: speed up - // - RI.currententity = NULL; // &r_worldentity; - VectorCopy (world_transformed_modelorg, - transformed_modelorg); - VectorCopy (RI.base_vpn, RI.vforward); - VectorCopy (RI.base_vup, RI.vup); - VectorCopy (RI.base_vright, RI.vright); - R_TransformFrustum (); + // + // restore the old drawing state + // FIXME: we don't want to do this every time! + // TODO: speed up + // + RI.currententity = NULL; // &r_worldentity; + VectorCopy( world_transformed_modelorg, + transformed_modelorg ); + VectorCopy( RI.base_vpn, RI.vforward ); + VectorCopy( RI.base_vup, RI.vup ); + VectorCopy( RI.base_vright, RI.vright ); + R_TransformFrustum(); } } @@ -927,27 +932,27 @@ D_SolidSurf Normal surface cached, texture mapped surface ============== */ -static void D_AlphaSurf (surf_t *s) +static void D_AlphaSurf( surf_t *s ) { int alpha; d_zistepu = s->d_zistepu; d_zistepv = s->d_zistepv; d_ziorigin = s->d_ziorigin; - if(s->flags & SURF_DRAWSKY) + if( s->flags & SURF_DRAWSKY ) return; - if (!s->insubmodel) // wtf? how it is possible? + if( !s->insubmodel )// wtf? how it is possible? return; // FIXME: we don't want to do all this for every polygon! // TODO: store once at start of frame - RI.currententity = s->entity; //FIXME: make this passed in to - // R_RotateBmodel () - VectorSubtract (RI.vieworg, RI.currententity->origin, local_modelorg); - TransformVector (local_modelorg, transformed_modelorg); + RI.currententity = s->entity; // FIXME: make this passed in to + // R_RotateBmodel () + VectorSubtract( RI.vieworg, RI.currententity->origin, local_modelorg ); + TransformVector( local_modelorg, transformed_modelorg ); - R_RotateBmodel (); // FIXME: don't mess with the frustum, - // make entity passed in + R_RotateBmodel(); // FIXME: don't mess with the frustum, + // make entity passed in pface = s->msurf; @@ -965,39 +970,39 @@ static void D_AlphaSurf (surf_t *s) if( alpha <= 0 && RI.currententity->curstate.renderamt > 0 ) alpha = 1; - if (s->flags & SURF_DRAWTURB ) + if( s->flags & SURF_DRAWTURB ) { - cacheblock = R_GetTexture(pface->texinfo->texture->gl_texturenum)->pixels[0]; + cacheblock = R_GetTexture( pface->texinfo->texture->gl_texturenum )->pixels[0]; cachewidth = 64; - D_CalcGradients (pface); - TurbulentZ8( s->spans, alpha); + D_CalcGradients( pface ); + TurbulentZ8( s->spans, alpha ); } else { // FIXME: make this passed in to D_CacheSurface - pcurrentcache = D_CacheSurface (pface, miplevel); + pcurrentcache = D_CacheSurface( pface, miplevel ); cacheblock = (pixel_t *)pcurrentcache->data; cachewidth = pcurrentcache->width; - D_CalcGradients (pface); + D_CalcGradients( pface ); if( RI.currententity->curstate.rendermode == kRenderTransAlpha ) - D_AlphaSpans16(s->spans); + D_AlphaSpans16( s->spans ); else if( RI.currententity->curstate.rendermode == kRenderTransAdd ) - D_AddSpans16(s->spans); + D_AddSpans16( s->spans ); else - D_BlendSpans16(s->spans, alpha ); + D_BlendSpans16( s->spans, alpha ); } - VectorCopy (world_transformed_modelorg, - transformed_modelorg); - VectorCopy (RI.base_vpn, RI.vforward); - VectorCopy (RI.base_vup, RI.vup); - VectorCopy (RI.base_vright, RI.vright); - R_TransformFrustum (); + VectorCopy( world_transformed_modelorg, + transformed_modelorg ); + VectorCopy( RI.base_vpn, RI.vforward ); + VectorCopy( RI.base_vup, RI.vup ); + VectorCopy( RI.base_vright, RI.vright ); + R_TransformFrustum(); } @@ -1008,27 +1013,27 @@ D_SolidSurf Normal surface cached, texture mapped surface ============== */ -static void D_SolidSurf (surf_t *s) +static void D_SolidSurf( surf_t *s ) { d_zistepu = s->d_zistepu; d_zistepv = s->d_zistepv; d_ziorigin = s->d_ziorigin; - if(s->flags & SURF_DRAWSKY) + if( s->flags & SURF_DRAWSKY ) return; - if (s->flags & SURF_DRAWTURB ) + if( s->flags & SURF_DRAWTURB ) return; - if (s->insubmodel) + if( s->insubmodel ) { - // FIXME: we don't want to do all this for every polygon! - // TODO: store once at start of frame - RI.currententity = s->entity; //FIXME: make this passed in to - // R_RotateBmodel () - VectorSubtract (RI.vieworg, RI.currententity->origin, local_modelorg); - TransformVector (local_modelorg, transformed_modelorg); + // FIXME: we don't want to do all this for every polygon! + // TODO: store once at start of frame + RI.currententity = s->entity; // FIXME: make this passed in to + // R_RotateBmodel () + VectorSubtract( RI.vieworg, RI.currententity->origin, local_modelorg ); + TransformVector( local_modelorg, transformed_modelorg ); - R_RotateBmodel (); // FIXME: don't mess with the frustum, - // make entity passed in + R_RotateBmodel(); // FIXME: don't mess with the frustum, + // make entity passed in // setup dlight transform if( s->msurf && s->msurf->dlightframe == tr.framecount ) { @@ -1040,7 +1045,7 @@ static void D_SolidSurf (surf_t *s) { if( alphaspans ) return; - RI.currententity = CL_GetEntityByIndex(0); //r_worldentity; + RI.currententity = CL_GetEntityByIndex( 0 ); // r_worldentity; tr.modelviewIdentity = true; } @@ -1053,36 +1058,36 @@ static void D_SolidSurf (surf_t *s) if( pface->flags & SURF_CONVEYOR ) miplevel = 1; else - miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip ); - while( 1 << miplevel > gEngfuncs.Mod_SampleSizeForFace(pface)) + miplevel = D_MipLevelForScale( s->nearzi * scale_for_mip ); + while( 1 << miplevel > gEngfuncs.Mod_SampleSizeForFace( pface )) miplevel--; // FIXME: make this passed in to D_CacheSurface - pcurrentcache = D_CacheSurface (pface, miplevel); + pcurrentcache = D_CacheSurface( pface, miplevel ); cacheblock = (pixel_t *)pcurrentcache->data; cachewidth = pcurrentcache->width; - D_CalcGradients (pface); + D_CalcGradients( pface ); - D_DrawSpans16 (s->spans); + D_DrawSpans16( s->spans ); - D_DrawZSpans (s->spans); + D_DrawZSpans( s->spans ); - if (s->insubmodel) + if( s->insubmodel ) { - // - // restore the old drawing state - // FIXME: we don't want to do this every time! - // TODO: speed up - // - VectorCopy (world_transformed_modelorg, - transformed_modelorg); - VectorCopy (RI.base_vpn, RI.vforward); - VectorCopy (RI.base_vup, RI.vup); - VectorCopy (RI.base_vright, RI.vright); - R_TransformFrustum (); - RI.currententity = NULL; //&r_worldentity; + // + // restore the old drawing state + // FIXME: we don't want to do this every time! + // TODO: speed up + // + VectorCopy( world_transformed_modelorg, + transformed_modelorg ); + VectorCopy( RI.base_vpn, RI.vforward ); + VectorCopy( RI.base_vup, RI.vup ); + VectorCopy( RI.base_vright, RI.vright ); + R_TransformFrustum(); + RI.currententity = NULL; // &r_worldentity; } } @@ -1093,13 +1098,13 @@ D_DrawflatSurfaces To allow developers to see the polygon carving of the world ============= */ -static void D_DrawflatSurfaces (void) +static void D_DrawflatSurfaces( void ) { - surf_t *s; + surf_t *s; - for (s = &surfaces[1] ; sspans) + if( !s->spans ) continue; d_zistepu = s->d_zistepu; @@ -1108,8 +1113,8 @@ static void D_DrawflatSurfaces (void) // make a stable color for each surface by taking the low // bits of the msurface pointer - D_FlatFillSurface (s, (uintptr_t)s->msurf & 0xFFFF); - D_DrawZSpans (s->spans); + D_FlatFillSurface( s, (uintptr_t)s->msurf & 0xFFFF ); + D_DrawZSpans( s->spans ); } } @@ -1121,37 +1126,37 @@ Rasterize all the span lists. Guaranteed zero overdraw. May be called more than once a frame if the surf list overflows (higher res) ============== */ -void D_DrawSurfaces (void) +void D_DrawSurfaces( void ) { - surf_t *s; + surf_t *s; // currententity = NULL; //&r_worldentity; - VectorSubtract (RI.vieworg, vec3_origin, tr.modelorg); - TransformVector (tr.modelorg, transformed_modelorg); - VectorCopy (transformed_modelorg, world_transformed_modelorg); + VectorSubtract( RI.vieworg, vec3_origin, tr.modelorg ); + TransformVector( tr.modelorg, transformed_modelorg ); + VectorCopy( transformed_modelorg, world_transformed_modelorg ); - if (!sw_drawflat.value) + if( !sw_drawflat.value ) { - for (s = &surfaces[1] ; sspans) + if( !s->spans ) continue; if( alphaspans ) - D_AlphaSurf (s); - else if(s->flags & SURF_DRAWSKY) - D_BackgroundSurf (s); - else if (s->flags & SURF_DRAWTURB ) - D_TurbulentSurf (s); + D_AlphaSurf( s ); + else if( s->flags & SURF_DRAWSKY ) + D_BackgroundSurf( s ); + else if( s->flags & SURF_DRAWTURB ) + D_TurbulentSurf( s ); else - D_SolidSurf (s); + D_SolidSurf( s ); } } else - D_DrawflatSurfaces (); + D_DrawflatSurfaces(); - //RI.currententity = NULL; //&r_worldentity; - VectorSubtract (RI.vieworg, vec3_origin, tr.modelorg); - R_TransformFrustum (); + // RI.currententity = NULL; //&r_worldentity; + VectorSubtract( RI.vieworg, vec3_origin, tr.modelorg ); + R_TransformFrustum(); } diff --git a/ref/soft/r_glblit.c b/ref/soft/r_glblit.c index 1253a658..6aa21909 100644 --- a/ref/soft/r_glblit.c +++ b/ref/soft/r_glblit.c @@ -4,13 +4,13 @@ struct swblit_s { - uint stride; - uint bpp; - uint rmask, gmask, bmask; - void *(*pLockBuffer)( void ); - void (*pUnlockBuffer)( void ); - qboolean(*pCreateBuffer)( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b ); - uint rotate; + uint stride; + uint bpp; + uint rmask, gmask, bmask; + void *(*pLockBuffer)( void ); + void (*pUnlockBuffer)( void ); + qboolean (*pCreateBuffer)( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b ); + uint rotate; qboolean gl1; } swblit; @@ -20,7 +20,7 @@ qboolean R_SetDisplayTransform( ref_screen_rotation_t rotate, int offset_x, int qboolean ret = true; if( rotate > 1 ) { - gEngfuncs.Con_Printf("only 0-1 rotation supported\n"); + gEngfuncs.Con_Printf( "only 0-1 rotation supported\n" ); ret = false; } else @@ -29,14 +29,14 @@ qboolean R_SetDisplayTransform( ref_screen_rotation_t rotate, int offset_x, int if( offset_x || offset_y ) { // it is possible implement for offset > 0 - gEngfuncs.Con_Printf("offset transform not supported\n"); + gEngfuncs.Con_Printf( "offset transform not supported\n" ); ret = false; } if( scale_x != 1.0f || scale_y != 1.0f ) { // maybe implement 2x2? - gEngfuncs.Con_Printf("scale transform not supported\n"); + gEngfuncs.Con_Printf( "scale transform not supported\n" ); ret = false; } @@ -76,8 +76,8 @@ static void APIENTRY GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLui static unsigned short *glbuf; static int tex; -#define LOAD(x) p##x = gEngfuncs.GL_GetProcAddress(#x); \ - gEngfuncs.Con_Printf(#x " : %p\n",p##x) +#define LOAD( x ) p ## x = gEngfuncs.GL_GetProcAddress(#x ); \ + gEngfuncs.Con_Printf(#x " : %p\n", p ## x ) void GAME_EXPORT GL_SetupAttributes( int safegl ) @@ -108,69 +108,69 @@ void GAME_EXPORT GL_SetupAttributes( int safegl ) gEngfuncs.GL_SetAttribute( REF_GL_BLUE_SIZE, 5 ); } -void (*pglOrthof)(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); -void GL_FUNCTION( glBindBuffer)(GLenum target, GLuint buffer); +void (*pglOrthof)( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ); +void GL_FUNCTION( glBindBuffer )( GLenum target, GLuint buffer ); -void GL_FUNCTION( glBufferData )(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); -void GL_FUNCTION( glGenBuffers )(GLsizei n, GLuint *buffers); -void GL_FUNCTION( glDeleteBuffers )(GLsizei n, const GLuint *buffers); -GLvoid* GL_FUNCTION( glMapBufferOES )(GLenum target, GLenum access); -GLboolean GL_FUNCTION( glUnmapBufferOES )(GLenum target); +void GL_FUNCTION( glBufferData )( GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage ); +void GL_FUNCTION( glGenBuffers )( GLsizei n, GLuint *buffers ); +void GL_FUNCTION( glDeleteBuffers )( GLsizei n, const GLuint *buffers ); +GLvoid * GL_FUNCTION( glMapBufferOES )( GLenum target, GLenum access ); +GLboolean GL_FUNCTION( glUnmapBufferOES )( GLenum target ); #define GL_PIXEL_UNPACK_BUFFER 0x88EC -#define GL_FRAMEBUFFER 0x8D40 -#define GL_COLOR_ATTACHMENT0 0x8CE0 -#define GL_READ_FRAMEBUFFER 0x8CA8 -#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 void GAME_EXPORT GL_InitExtensions( void ) { - LOAD(glBegin); - LOAD(glEnd); - LOAD(glTexCoord2f); - LOAD(glVertex2f); - LOAD(glEnable); - LOAD(glDisable); - LOAD(glTexImage2D); - LOAD(glOrtho); - LOAD(glOrthof); - LOAD(glMatrixMode); - LOAD(glLoadIdentity); - LOAD(glViewport); - LOAD(glBindTexture); - LOAD(glDebugMessageCallbackARB); - LOAD(glDebugMessageControlARB); - LOAD(glGetError); - LOAD(glGenTextures); - LOAD(glTexParameteri); - LOAD(glEnableClientState); - LOAD(glDisableClientState); - LOAD(glVertexPointer); - LOAD(glTexCoordPointer); - LOAD(glDrawElements); - LOAD(glClear); - LOAD(glClearColor); - LOAD(glGetString); - LOAD(glColor4f); - LOAD(glDrawArrays); - LOAD(glBindBuffer); - LOAD(glBufferData); - LOAD(glGenBuffers); - LOAD(glDeleteBuffers); - LOAD(glMapBufferOES); + LOAD( glBegin ); + LOAD( glEnd ); + LOAD( glTexCoord2f ); + LOAD( glVertex2f ); + LOAD( glEnable ); + LOAD( glDisable ); + LOAD( glTexImage2D ); + LOAD( glOrtho ); + LOAD( glOrthof ); + LOAD( glMatrixMode ); + LOAD( glLoadIdentity ); + LOAD( glViewport ); + LOAD( glBindTexture ); + LOAD( glDebugMessageCallbackARB ); + LOAD( glDebugMessageControlARB ); + LOAD( glGetError ); + LOAD( glGenTextures ); + LOAD( glTexParameteri ); + LOAD( glEnableClientState ); + LOAD( glDisableClientState ); + LOAD( glVertexPointer ); + LOAD( glTexCoordPointer ); + LOAD( glDrawElements ); + LOAD( glClear ); + LOAD( glClearColor ); + LOAD( glGetString ); + LOAD( glColor4f ); + LOAD( glDrawArrays ); + LOAD( glBindBuffer ); + LOAD( glBufferData ); + LOAD( glGenBuffers ); + LOAD( glDeleteBuffers ); + LOAD( glMapBufferOES ); if( !pglMapBufferOES ) - pglMapBufferOES = gEngfuncs.GL_GetProcAddress("glMapBuffer"); - LOAD(glUnmapBufferOES); + pglMapBufferOES = gEngfuncs.GL_GetProcAddress( "glMapBuffer" ); + LOAD( glUnmapBufferOES ); if( !pglUnmapBufferOES ) - pglUnmapBufferOES = gEngfuncs.GL_GetProcAddress("glUnmapBuffer"); - LOAD(glGenFramebuffers); - LOAD(glBindFramebuffer); - LOAD(glFramebufferTexture2D); - LOAD(glBlitFramebuffer); - LOAD(glGenTextures); - gEngfuncs.Con_Printf("version:%s\n",pglGetString(GL_VERSION)); + pglUnmapBufferOES = gEngfuncs.GL_GetProcAddress( "glUnmapBuffer" ); + LOAD( glGenFramebuffers ); + LOAD( glBindFramebuffer ); + LOAD( glFramebufferTexture2D ); + LOAD( glBlitFramebuffer ); + LOAD( glGenTextures ); + gEngfuncs.Con_Printf( "version:%s\n", pglGetString( GL_VERSION )); #if GLDEBUG if( gpGlobals->developer ) { - gEngfuncs.Con_Reportf( "Installing GL_DebugOutput...\n"); + gEngfuncs.Con_Reportf( "Installing GL_DebugOutput...\n" ); pglDebugMessageCallbackARB( GL_DebugOutput, NULL ); // force everything to happen in the main thread instead of in a separate driver thread @@ -196,19 +196,19 @@ static void R_Unlock_GL1( void ) { pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vid.width, vid.height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glbuf ); - //gEngfuncs.Con_Printf("%d\n",pglGetError()); + // gEngfuncs.Con_Printf("%d\n",pglGetError()); pglBegin( GL_QUADS ); - pglTexCoord2f( 0, 0 ); - pglVertex2f( 0, 0 ); + pglTexCoord2f( 0, 0 ); + pglVertex2f( 0, 0 ); - pglTexCoord2f( 1, 0 ); - pglVertex2f( 1, 0 ); + pglTexCoord2f( 1, 0 ); + pglVertex2f( 1, 0 ); - pglTexCoord2f( 1, 1 ); - pglVertex2f( 1, 1 ); + pglTexCoord2f( 1, 1 ); + pglVertex2f( 1, 1 ); - pglTexCoord2f( 0, 1 ); - pglVertex2f( 0, 1 ); + pglTexCoord2f( 0, 1 ); + pglVertex2f( 0, 1 ); pglEnd(); gEngfuncs.GL_SwapBuffers(); } @@ -217,7 +217,7 @@ static void R_Unlock_GL1( void ) static void R_Unlock_GLES1( void ) { pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vid.width, vid.height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glbuf ); - pglDrawArrays( GL_TRIANGLE_FAN, 0,4 ); + pglDrawArrays( GL_TRIANGLE_FAN, 0, 4 ); gEngfuncs.GL_SwapBuffers(); } @@ -232,19 +232,19 @@ static qboolean R_CreateBuffer_GL1( int width, int height, uint *stride, uint *b pglLoadIdentity(); pglEnable( GL_TEXTURE_2D ); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); if( glbuf ) - Mem_Free(glbuf); + Mem_Free( glbuf ); - glbuf = Mem_Malloc( r_temppool, width*height*2 ); + glbuf = Mem_Malloc( r_temppool, width * height * 2 ); *stride = width; *bpp = 2; - *r = MASK(5) << (6 + 5); - *g = MASK(6) << 5; - *b = MASK(5); + *r = MASK( 5 ) << ( 6 + 5 ); + *g = MASK( 6 ) << 5; + *b = MASK( 5 ); return true; } @@ -258,7 +258,7 @@ static qboolean R_CreateBuffer_GLES1( int width, int height, uint *stride, uint 1, 1, 0, 1, }; - int vbo; + int vbo; pglViewport( 0, 0, width, height ); pglMatrixMode( GL_PROJECTION ); @@ -272,32 +272,32 @@ static qboolean R_CreateBuffer_GLES1( int width, int height, uint *stride, uint pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); - //if( vbo ) + // if( vbo ) // pglDeleteBuffers( 1,&vbo ); - pglGenBuffers( 1,&vbo ); + pglGenBuffers( 1, &vbo ); pglBindBuffer( GL_ARRAY_BUFFER_ARB, vbo ); - pglBufferData( GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB ); + pglBufferData( GL_ARRAY_BUFFER_ARB, sizeof( data ), data, GL_STATIC_DRAW_ARB ); pglEnableClientState( GL_VERTEX_ARRAY ); pglEnableClientState( GL_TEXTURE_COORD_ARRAY ); pglVertexPointer( 2, GL_FLOAT, 8, 0 ); pglTexCoordPointer( 2, GL_FLOAT, 8, 0 ); - pglBindBuffer( GL_ARRAY_BUFFER_ARB, 0 ) ; + pglBindBuffer( GL_ARRAY_BUFFER_ARB, 0 ); pglColor4f( 1, 1, 1, 1 ); if( glbuf ) Mem_Free( glbuf ); - glbuf = Mem_Malloc( r_temppool, width*height*2 ); + glbuf = Mem_Malloc( r_temppool, width * height * 2 ); *stride = width; *bpp = 2; - *r = MASK(5) << (6 + 5); - *g = MASK(6) << 5; - *b = MASK(5); + *r = MASK( 5 ) << ( 6 + 5 ); + *g = MASK( 6 ) << 5; + *b = MASK( 5 ); return true; } @@ -320,7 +320,7 @@ static void *R_Lock_GLES3( void ) if( pglUnmapBufferOES ) pglUnmapBufferOES( GL_PIXEL_UNPACK_BUFFER ); pglBindBuffer( GL_PIXEL_UNPACK_BUFFER, 0 ); - glbuf = Mem_Malloc( r_temppool, vid.width*vid.height*2 ); + glbuf = Mem_Malloc( r_temppool, vid.width * vid.height * 2 ); pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vid.width, vid.height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glbuf ); return glbuf; } @@ -340,13 +340,13 @@ static void R_Unlock_GLES3( void ) pglUnmapBufferOES( GL_PIXEL_UNPACK_BUFFER ); pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vid.width, vid.height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0 ); } - //pglDrawArrays( GL_TRIANGLE_FAN, 0,4 ); + // pglDrawArrays( GL_TRIANGLE_FAN, 0,4 ); pglBlitFramebuffer( 0, vid.height, vid.width, 0, 0, 0, vid.width, vid.height, GL_COLOR_BUFFER_BIT, GL_NEAREST ); } static qboolean R_CreateBuffer_GLES3( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b ) { - float data[] = { + float data[] = { // quad verts match texcoords 0, 0, 1, 0, @@ -378,35 +378,35 @@ static qboolean R_CreateBuffer_GLES3( int width, int height, uint *stride, uint pglDeleteBuffers( 1,&pbo ); */ - //pglGenBuffers( 1,&vbo ); + // pglGenBuffers( 1,&vbo ); pglGenBuffers( 1, &pbo ); - //pglBindBuffer( GL_ARRAY_BUFFER_ARB, vbo ); - //pglBufferData( GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB ); + // pglBindBuffer( GL_ARRAY_BUFFER_ARB, vbo ); + // pglBufferData( GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB ); - //pglEnableClientState( GL_VERTEX_ARRAY ); - //pglEnableClientState( GL_TEXTURE_COORD_ARRAY ); + // pglEnableClientState( GL_VERTEX_ARRAY ); + // pglEnableClientState( GL_TEXTURE_COORD_ARRAY ); - //pglVertexPointer( 2, GL_FLOAT, 8, 0 ); - //pglTexCoordPointer( 2, GL_FLOAT, 8, 0 ); - //pglBindBuffer( GL_ARRAY_BUFFER_ARB, 0 ); + // pglVertexPointer( 2, GL_FLOAT, 8, 0 ); + // pglTexCoordPointer( 2, GL_FLOAT, 8, 0 ); + // pglBindBuffer( GL_ARRAY_BUFFER_ARB, 0 ); pglBindBuffer( GL_PIXEL_UNPACK_BUFFER, pbo ); pglBufferData( GL_PIXEL_UNPACK_BUFFER, width * height * 2, 0, GL_STREAM_DRAW_ARB ); pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0 ); - pglGenFramebuffers(1, &fbo); - pglBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - pglFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, to, 0); - pglBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + pglGenFramebuffers( 1, &fbo ); + pglBindFramebuffer( GL_READ_FRAMEBUFFER, fbo ); + pglFramebufferTexture2D( GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, to, 0 ); + pglBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); - //pglColor4f( 1, 1, 1, 1 ); + // pglColor4f( 1, 1, 1, 1 ); *stride = width; *bpp = 2; - *r = MASK(5) << (6 + 5); - *g = MASK(6) << 5; - *b = MASK(5); + *r = MASK( 5 ) << ( 6 + 5 ); + *g = MASK( 6 ) << 5; + *b = MASK( 5 ); return true; } @@ -417,7 +417,8 @@ static int FIRST_BIT( uint mask ) { uint i; - for( i = 0; !(BIT(i) & mask); i++ ); + for( i = 0; !( BIT( i ) & mask ); i++ ) + ; return i; } @@ -434,60 +435,60 @@ static int COUNT_BITS( uint mask ) static void R_BuildScreenMap( void ) { - int i; - uint rshift = FIRST_BIT(swblit.rmask), gshift = FIRST_BIT(swblit.gmask), bshift = FIRST_BIT(swblit.bmask); - uint rbits = COUNT_BITS(swblit.rmask), gbits = COUNT_BITS(swblit.gmask), bbits = COUNT_BITS(swblit.bmask); - uint rmult = BIT(rbits), gmult = BIT(gbits), bmult = BIT(bbits); - uint rdiv = MASK(5), gdiv = MASK(6), bdiv = MASK(5); + int i; + uint rshift = FIRST_BIT( swblit.rmask ), gshift = FIRST_BIT( swblit.gmask ), bshift = FIRST_BIT( swblit.bmask ); + uint rbits = COUNT_BITS( swblit.rmask ), gbits = COUNT_BITS( swblit.gmask ), bbits = COUNT_BITS( swblit.bmask ); + uint rmult = BIT( rbits ), gmult = BIT( gbits ), bmult = BIT( bbits ); + uint rdiv = MASK( 5 ), gdiv = MASK( 6 ), bdiv = MASK( 5 ); - gEngfuncs.Con_Printf("Blit table: %d %d %d %d %d %d\n", rmult, gmult, bmult, rdiv, gdiv, bdiv ); + gEngfuncs.Con_Printf( "Blit table: %d %d %d %d %d %d\n", rmult, gmult, bmult, rdiv, gdiv, bdiv ); #ifdef SEPARATE_BLIT for( i = 0; i < 256; i++ ) { - unsigned int r,g,b; + unsigned int r, g, b; // 332 to 565 - r = ((i >> (8 - 3) )<< 2 ) & MASK(5); - g = ((i >> (8 - 3 - 3)) << 3) & MASK(6); - b = ((i >> (8 - 3 - 3 - 2)) << 3) & MASK(5); - vid.screen_major[i] = r << (6 + 5) | (g << 5) | b; + r = (( i >> ( 8 - 3 )) << 2 ) & MASK( 5 ); + g = (( i >> ( 8 - 3 - 3 )) << 3 ) & MASK( 6 ); + b = (( i >> ( 8 - 3 - 3 - 2 )) << 3 ) & MASK( 5 ); + vid.screen_major[i] = r << ( 6 + 5 ) | ( g << 5 ) | b; // restore minor GBRGBRGB - r = MOVE_BIT(i, 5, 1) | MOVE_BIT(i, 2, 0); - g = MOVE_BIT(i, 7, 2) | MOVE_BIT(i, 4, 1) | MOVE_BIT(i, 1, 0); - b = MOVE_BIT(i, 6, 2) | MOVE_BIT(i, 3, 1) | MOVE_BIT(i, 0, 0); - vid.screen_minor[i] = r << (6 + 5) | (g << 5) | b; + r = MOVE_BIT( i, 5, 1 ) | MOVE_BIT( i, 2, 0 ); + g = MOVE_BIT( i, 7, 2 ) | MOVE_BIT( i, 4, 1 ) | MOVE_BIT( i, 1, 0 ); + b = MOVE_BIT( i, 6, 2 ) | MOVE_BIT( i, 3, 1 ) | MOVE_BIT( i, 0, 0 ); + vid.screen_minor[i] = r << ( 6 + 5 ) | ( g << 5 ) | b; } #else for( i = 0; i < 256; i++ ) { - unsigned int r,g,b , major, j; + unsigned int r, g, b, major, j; // 332 to 565 - r = ((i >> (8 - 3) )<< 2 ) & MASK(5); - g = ((i >> (8 - 3 - 3)) << 3) & MASK(6); - b = ((i >> (8 - 3 - 3 - 2)) << 3) & MASK(5); - //major = r << (6 + 5) | (g << 5) | b; - major = (r * rmult / rdiv) << rshift | (g * gmult / gdiv) << gshift | (b * bmult / bdiv) << bshift; + r = (( i >> ( 8 - 3 )) << 2 ) & MASK( 5 ); + g = (( i >> ( 8 - 3 - 3 )) << 3 ) & MASK( 6 ); + b = (( i >> ( 8 - 3 - 3 - 2 )) << 3 ) & MASK( 5 ); + // major = r << (6 + 5) | (g << 5) | b; + major = ( r * rmult / rdiv ) << rshift | ( g * gmult / gdiv ) << gshift | ( b * bmult / bdiv ) << bshift; for( j = 0; j < 256; j++ ) { uint minor; // restore minor GBRGBRGB - r = MOVE_BIT(j, 5, 1) | MOVE_BIT(j, 2, 0); - g = MOVE_BIT(j, 7, 2) | MOVE_BIT(j, 4, 1) | MOVE_BIT(j, 1, 0); - b = MOVE_BIT(j, 6, 2) | MOVE_BIT(j, 3, 1) | MOVE_BIT(j, 0, 0); - //vid.screen[(i<<8)|j] = r << (6 + 5) | (g << 5) | b | major; - minor = (r * rmult / rdiv) << rshift | (g * gmult / gdiv) << gshift | (b * bmult / bdiv) << bshift; + r = MOVE_BIT( j, 5, 1 ) | MOVE_BIT( j, 2, 0 ); + g = MOVE_BIT( j, 7, 2 ) | MOVE_BIT( j, 4, 1 ) | MOVE_BIT( j, 1, 0 ); + b = MOVE_BIT( j, 6, 2 ) | MOVE_BIT( j, 3, 1 ) | MOVE_BIT( j, 0, 0 ); + // vid.screen[(i<<8)|j] = r << (6 + 5) | (g << 5) | b | major; + minor = ( r * rmult / rdiv ) << rshift | ( g * gmult / gdiv ) << gshift | ( b * bmult / bdiv ) << bshift; if( swblit.bpp == 2 ) - vid.screen[(i<<8)|j] = major | minor; + vid.screen[( i << 8 ) | j] = major | minor; else - vid.screen32[(i<<8)|j] = major | minor; + vid.screen32[( i << 8 ) | j] = major | minor; } @@ -495,7 +496,7 @@ static void R_BuildScreenMap( void ) #endif } -#define FOR_EACH_COLOR(x) for( r##x = 0; r##x < BIT(3); r##x++ ) for( g##x = 0; g##x < BIT(3); g##x++ ) for( b##x = 0; b##x < BIT(2); b##x++ ) +#define FOR_EACH_COLOR( x ) for( r ## x = 0; r ## x < BIT( 3 ); r ## x++ ) for( g ## x = 0; g ## x < BIT( 3 ); g ## x++ ) for( b ## x = 0; b ## x < BIT( 2 ); b ## x++ ) static void R_BuildBlendMaps( void ) { @@ -503,82 +504,82 @@ static void R_BuildBlendMaps( void ) unsigned int r2, g2, b2; unsigned int i, j; - FOR_EACH_COLOR(1)FOR_EACH_COLOR(2) + FOR_EACH_COLOR( 1 ) FOR_EACH_COLOR( 2 ) { - unsigned int r, g, b; - unsigned short index1 = r1 << (2 + 3) | g1 << 2 | b1; - unsigned short index2 = (r2 << (2 + 3) | g2 << 2 | b2) << 8; - unsigned int a; + unsigned int r, g, b; + unsigned short index1 = r1 << ( 2 + 3 ) | g1 << 2 | b1; + unsigned short index2 = ( r2 << ( 2 + 3 ) | g2 << 2 | b2 ) << 8; + unsigned int a; r = r1 + r2; g = g1 + g2; b = b1 + b2; - if( r > MASK(3) ) - r = MASK(3); - if( g > MASK(3) ) - g = MASK(3); - if( b > MASK(2) ) - b = MASK(2); - ASSERT(!vid.addmap[index2|index1]); + if( r > MASK( 3 )) + r = MASK( 3 ); + if( g > MASK( 3 )) + g = MASK( 3 ); + if( b > MASK( 2 )) + b = MASK( 2 ); + ASSERT( !vid.addmap[index2 | index1] ); - vid.addmap[index2|index1] = r << (2 + 3) | g << 2 | b; - r = r1 * r2 / MASK(3); - g = g1 * g2 / MASK(3); - b = b1 * b2 / MASK(2); + vid.addmap[index2 | index1] = r << ( 2 + 3 ) | g << 2 | b; + r = r1 * r2 / MASK( 3 ); + g = g1 * g2 / MASK( 3 ); + b = b1 * b2 / MASK( 2 ); - vid.modmap[index2|index1] = r << (2 + 3) | g << 2 | b; + vid.modmap[index2 | index1] = r << ( 2 + 3 ) | g << 2 | b; } for( i = 0; i < 8192; i++ ) { - unsigned int r, g, b; - uint color = i << 3; - uint m = color >> 8; - uint j = color & 0xff; + unsigned int r, g, b; + uint color = i << 3; + uint m = color >> 8; + uint j = color & 0xff; unsigned short index1 = i; - r1 = ((m >> (8 - 3) )<< 2 ) & MASK(5); - g1 = ((m >> (8 - 3 - 3)) << 3) & MASK(6); - b1 = ((m >> (8 - 3 - 3 - 2)) << 3) & MASK(5); - r1 |= MOVE_BIT(j, 5, 1) | MOVE_BIT(j, 2, 0); - g1 |= MOVE_BIT(j, 7, 2) | MOVE_BIT(j, 4, 1) | MOVE_BIT(j, 1, 0); - b1 |= MOVE_BIT(j, 6, 2) | MOVE_BIT(j, 3, 1) | MOVE_BIT(j, 0, 0); + r1 = (( m >> ( 8 - 3 )) << 2 ) & MASK( 5 ); + g1 = (( m >> ( 8 - 3 - 3 )) << 3 ) & MASK( 6 ); + b1 = (( m >> ( 8 - 3 - 3 - 2 )) << 3 ) & MASK( 5 ); + r1 |= MOVE_BIT( j, 5, 1 ) | MOVE_BIT( j, 2, 0 ); + g1 |= MOVE_BIT( j, 7, 2 ) | MOVE_BIT( j, 4, 1 ) | MOVE_BIT( j, 1, 0 ); + b1 |= MOVE_BIT( j, 6, 2 ) | MOVE_BIT( j, 3, 1 ) | MOVE_BIT( j, 0, 0 ); - for( j = 0; j < 32; j++) + for( j = 0; j < 32; j++ ) { unsigned int index2 = j << 13; unsigned int major, minor; r = r1 * j / 32; g = g1 * j / 32; b = b1 * j / 32; - major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2))); + major = ((( r >> 2 ) & MASK( 3 )) << 5 ) | (((( g >> 3 ) & MASK( 3 )) << 2 )) | ((( b >> 3 ) & MASK( 2 ))); // save minor GBRGBRGB - minor = MOVE_BIT(r,1,5) | MOVE_BIT(r,0,2) | MOVE_BIT(g,2,7) | MOVE_BIT(g,1,4) | MOVE_BIT(g,0,1) | MOVE_BIT(b,2,6)| MOVE_BIT(b,1,3)|MOVE_BIT(b,0,0); + minor = MOVE_BIT( r, 1, 5 ) | MOVE_BIT( r, 0, 2 ) | MOVE_BIT( g, 2, 7 ) | MOVE_BIT( g, 1, 4 ) | MOVE_BIT( g, 0, 1 ) | MOVE_BIT( b, 2, 6 ) | MOVE_BIT( b, 1, 3 ) | MOVE_BIT( b, 0, 0 ); - vid.colormap[index2|index1] = major << 8 | (minor & 0xFF); + vid.colormap[index2 | index1] = major << 8 | ( minor & 0xFF ); } } for( i = 0; i < 1024; i++ ) { - unsigned int r, g, b; - uint color = i << 6 | BIT(5) | BIT(4) | BIT(3); - uint m = color >> 8; - uint j = color & 0xff; + unsigned int r, g, b; + uint color = i << 6 | BIT( 5 ) | BIT( 4 ) | BIT( 3 ); + uint m = color >> 8; + uint j = color & 0xff; unsigned short index1 = i; - r1 = ((m >> (8 - 3) )<< 2 ) & MASK(5); - g1 = ((m >> (8 - 3 - 3)) << 3) & MASK(6); - b1 = ((m >> (8 - 3 - 3 - 2)) << 3) & MASK(5); - r1 |= MOVE_BIT(j, 5, 1) | MOVE_BIT(j, 2, 0); - g1 |= MOVE_BIT(j, 7, 2) | MOVE_BIT(j, 4, 1) | MOVE_BIT(j, 1, 0); - b1 |= MOVE_BIT(j, 6, 2) | MOVE_BIT(j, 3, 1) | MOVE_BIT(j, 0, 0); + r1 = (( m >> ( 8 - 3 )) << 2 ) & MASK( 5 ); + g1 = (( m >> ( 8 - 3 - 3 )) << 3 ) & MASK( 6 ); + b1 = (( m >> ( 8 - 3 - 3 - 2 )) << 3 ) & MASK( 5 ); + r1 |= MOVE_BIT( j, 5, 1 ) | MOVE_BIT( j, 2, 0 ); + g1 |= MOVE_BIT( j, 7, 2 ) | MOVE_BIT( j, 4, 1 ) | MOVE_BIT( j, 1, 0 ); + b1 |= MOVE_BIT( j, 6, 2 ) | MOVE_BIT( j, 3, 1 ) | MOVE_BIT( j, 0, 0 ); - FOR_EACH_COLOR(2) + FOR_EACH_COLOR( 2 ) { - unsigned int index2 = (r2 << (2 + 3) | g2 << 2 | b2) << 10; + unsigned int index2 = ( r2 << ( 2 + 3 ) | g2 << 2 | b2 ) << 10; unsigned int k; for( k = 0; k < 3; k++ ) { @@ -586,25 +587,25 @@ static void R_BuildBlendMaps( void ) unsigned int a = k + 2; - r = r1 * (7 - a) / 7 + (r2 << 2 | BIT(2)) * a / 7; - g = g1 * (7 - a) / 7 + (g2 << 3 | MASK(2)) * a / 7; - b = b1 * (7 - a) / 7 + (b2 << 3 | MASK(2)) * a / 7; - if( r > MASK(5) ) - r = MASK(5); - if( g > MASK(6) ) - g = MASK(6); - if( b > MASK(5) ) - b = MASK(5); + r = r1 * ( 7 - a ) / 7 + ( r2 << 2 | BIT( 2 )) * a / 7; + g = g1 * ( 7 - a ) / 7 + ( g2 << 3 | MASK( 2 )) * a / 7; + b = b1 * ( 7 - a ) / 7 + ( b2 << 3 | MASK( 2 )) * a / 7; + if( r > MASK( 5 )) + r = MASK( 5 ); + if( g > MASK( 6 )) + g = MASK( 6 ); + if( b > MASK( 5 )) + b = MASK( 5 ); ASSERT( b < 32 ); - major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2))); + major = ((( r >> 2 ) & MASK( 3 )) << 5 ) | (((( g >> 3 ) & MASK( 3 )) << 2 )) | ((( b >> 3 ) & MASK( 2 ))); // save minor GBRGBRGB - minor = MOVE_BIT(r,1,5) | MOVE_BIT(r,0,2) | MOVE_BIT(g,2,7) | MOVE_BIT(g,1,4) | MOVE_BIT(g,0,1) | MOVE_BIT(b,2,6)| MOVE_BIT(b,1,3)|MOVE_BIT(b,0,0); + minor = MOVE_BIT( r, 1, 5 ) | MOVE_BIT( r, 0, 2 ) | MOVE_BIT( g, 2, 7 ) | MOVE_BIT( g, 1, 4 ) | MOVE_BIT( g, 0, 1 ) | MOVE_BIT( b, 2, 6 ) | MOVE_BIT( b, 1, 3 ) | MOVE_BIT( b, 0, 0 ); minor = minor & ~0x3f; - vid.alphamap[k << 18|index2|index1] = major << 8 | (minor & 0xFF); + vid.alphamap[k << 18 | index2 | index1] = major << 8 | ( minor & 0xFF ); } } } @@ -661,7 +662,7 @@ static qboolean R_AllocScreen( void ) } if( !swblit.pCreateBuffer( w, h, &swblit.stride, &swblit.bpp, - &swblit.rmask, &swblit.gmask, &swblit.bmask )) + &swblit.rmask, &swblit.gmask, &swblit.bmask )) return false; R_BuildScreenMap(); @@ -670,40 +671,40 @@ static qboolean R_AllocScreen( void ) vid.rowbytes = gpGlobals->width; // rowpixels if( d_pzbuffer ) free( d_pzbuffer ); - d_pzbuffer = malloc( vid.width*vid.height*2 + 64 ); + d_pzbuffer = malloc( vid.width * vid.height * 2 + 64 ); if( vid.buffer ) free( vid.buffer ); - vid.buffer = malloc( vid.width * vid.height*sizeof( pixel_t ) ); + vid.buffer = malloc( vid.width * vid.height * sizeof( pixel_t )); return true; } void R_BlitScreen( void ) { - int u, v; + int u, v; void *buffer = swblit.pLockBuffer(); // gEngfuncs.Con_Printf("blit begin\n"); - //memset( vid.buffer, 10, vid.width * vid.height ); + // memset( vid.buffer, 10, vid.width * vid.height ); if( !buffer || gpGlobals->width != vid.width || gpGlobals->height != vid.height ) { - gEngfuncs.Con_Printf("pre allocscrn\n"); + gEngfuncs.Con_Printf( "pre allocscrn\n" ); R_AllocScreen(); - gEngfuncs.Con_Printf("post allocscrn\n"); + gEngfuncs.Con_Printf( "post allocscrn\n" ); return; } - //return; - //byte *buf = vid.buffer; + // return; + // byte *buf = vid.buffer; - //#pragma omp parallel for schedule(static) - //gEngfuncs.Con_Printf("swblit %d %d", swblit.bpp, vid.height ); + // #pragma omp parallel for schedule(static) + // gEngfuncs.Con_Printf("swblit %d %d", swblit.bpp, vid.height ); if( swblit.rotate ) { if( swblit.bpp == 2 ) { unsigned short *pbuf = buffer; - for( v = 0; v < vid.height;v++) + for( v = 0; v < vid.height; v++ ) { uint start = vid.rowbytes * v; uint d = swblit.stride - v - 1; @@ -720,7 +721,7 @@ void R_BlitScreen( void ) { unsigned int *pbuf = buffer; - for( v = 0; v < vid.height;v++) + for( v = 0; v < vid.height; v++ ) { uint start = vid.rowbytes * v; uint d = swblit.stride - v - 1; @@ -736,7 +737,7 @@ void R_BlitScreen( void ) else if( swblit.bpp == 3 ) { byte *pbuf = buffer; - for( v = 0; v < vid.height;v++) + for( v = 0; v < vid.height; v++ ) { uint start = vid.rowbytes * v; uint d = swblit.stride - v - 1; @@ -744,11 +745,11 @@ void R_BlitScreen( void ) for( u = 0; u < vid.width; u++ ) { unsigned int s = vid.screen32[vid.buffer[start + u]]; - pbuf[(d)*3] = s; + pbuf[( d ) * 3] = s; s = s >> 8; - pbuf[(d)*3+1] = s; + pbuf[( d ) * 3 + 1] = s; s = s >> 8; - pbuf[(d)*3+2] = s; + pbuf[( d ) * 3 + 2] = s; d += swblit.stride; } } @@ -759,7 +760,7 @@ void R_BlitScreen( void ) if( swblit.bpp == 2 ) { unsigned short *pbuf = buffer; - for( v = 0; v < vid.height;v++) + for( v = 0; v < vid.height; v++ ) { uint start = vid.rowbytes * v; uint dstart = swblit.stride * v; @@ -775,7 +776,7 @@ void R_BlitScreen( void ) { unsigned int *pbuf = buffer; - for( v = 0; v < vid.height;v++) + for( v = 0; v < vid.height; v++ ) { uint start = vid.rowbytes * v; uint dstart = swblit.stride * v; @@ -790,7 +791,7 @@ void R_BlitScreen( void ) else if( swblit.bpp == 3 ) { byte *pbuf = buffer; - for( v = 0; v < vid.height;v++) + for( v = 0; v < vid.height; v++ ) { uint start = vid.rowbytes * v; uint dstart = swblit.stride * v; @@ -798,11 +799,11 @@ void R_BlitScreen( void ) for( u = 0; u < vid.width; u++ ) { unsigned int s = vid.screen32[vid.buffer[start + u]]; - pbuf[(dstart+u)*3] = s; + pbuf[( dstart + u ) * 3] = s; s = s >> 8; - pbuf[(dstart+u)*3+1] = s; + pbuf[( dstart + u ) * 3 + 1] = s; s = s >> 8; - pbuf[(dstart+u)*3+2] = s; + pbuf[( dstart + u ) * 3 + 2] = s; } } } @@ -822,8 +823,8 @@ static uint32_t Get8888PixelAt( int u, int start ) pixel_t color = vid.screen[vid.buffer[start + u]]; uint8_t c[3]; c[0] = (((( color >> 11 ) & 0x1F ) * 527 ) + 23 ) >> 6; - c[1] = (((( color >> 5 ) & 0x3F ) * 259 ) + 33 ) >> 6; - c[2] = (((( color ) & 0x1F ) * 527 ) + 23 ) >> 6; + c[1] = (((( color >> 5 ) & 0x3F ) * 259 ) + 33 ) >> 6; + c[2] = (((( color ) & 0x1F ) * 527 ) + 23 ) >> 6; s = c[0] << 16 | c[1] << 8 | c[2]; break; @@ -840,13 +841,13 @@ static uint32_t Get8888PixelAt( int u, int start ) qboolean GAME_EXPORT VID_ScreenShot( const char *filename, int shot_type ) { rgbdata_t *r_shot; - uint flags = IMAGE_FLIP_Y; - int width = 0, height = 0, u, v; - qboolean result; + uint flags = IMAGE_FLIP_Y; + int width = 0, height = 0, u, v; + qboolean result; r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t )); - r_shot->width = (vid.width + 3) & ~3; - r_shot->height = (vid.height + 3) & ~3; + r_shot->width = ( vid.width + 3 ) & ~3; + r_shot->height = ( vid.height + 3 ) & ~3; r_shot->flags = IMAGE_HAS_COLOR; r_shot->type = PF_BGRA_32; // was RGBA r_shot->size = r_shot->width * r_shot->height * gEngfuncs.Image_GetPFDesc( r_shot->type )->bpp; @@ -874,7 +875,7 @@ qboolean GAME_EXPORT VID_ScreenShot( const char *filename, int shot_type ) { uint32_t *pbuf = (uint32_t *)r_shot->buffer; - for( v = 0; v < vid.height;v++) + for( v = 0; v < vid.height; v++ ) { uint start = vid.rowbytes * ( vid.height - v ); uint dstart = swblit.stride * v; @@ -900,7 +901,7 @@ qboolean GAME_EXPORT VID_ScreenShot( const char *filename, int shot_type ) width = Q_rint( height * ((double)r_shot->width / r_shot->height )); break; case VID_MAPSHOT: - flags |= IMAGE_RESAMPLE|IMAGE_QUANTIZE; // GoldSrc request overviews in 8-bit format + flags |= IMAGE_RESAMPLE | IMAGE_QUANTIZE; // GoldSrc request overviews in 8-bit format height = 768; width = 1024; break; @@ -910,7 +911,7 @@ qboolean GAME_EXPORT VID_ScreenShot( const char *filename, int shot_type ) // write image result = gEngfuncs.FS_SaveImage( filename, r_shot ); - gEngfuncs.fsapi->AllowDirectPaths( false ); // always reset after store screenshot + gEngfuncs.fsapi->AllowDirectPaths( false ); // always reset after store screenshot gEngfuncs.FS_FreeImage( r_shot ); return result; diff --git a/ref/soft/r_image.c b/ref/soft/r_image.c index df20e242..00619936 100644 --- a/ref/soft/r_image.c +++ b/ref/soft/r_image.c @@ -15,13 +15,13 @@ GNU General Public License for more details. #include "r_local.h" -#define TEXTURES_HASH_SIZE (MAX_TEXTURES >> 2) +#define TEXTURES_HASH_SIZE ( MAX_TEXTURES >> 2 ) -static image_t r_images[MAX_TEXTURES]; -static image_t* r_imagesHashTable[TEXTURES_HASH_SIZE]; -static uint r_numImages; +static image_t r_images[MAX_TEXTURES]; +static image_t *r_imagesHashTable[TEXTURES_HASH_SIZE]; +static uint r_numImages; -#define IsLightMap( tex ) ( FBitSet(( tex )->flags, TF_ATLAS_PAGE )) +#define IsLightMap( tex ) ( FBitSet(( tex )->flags, TF_ATLAS_PAGE )) /* ================= R_GetTexture @@ -42,17 +42,17 @@ GL_Bind */ void GAME_EXPORT GL_Bind( int tmu, unsigned int texnum ) { - image_t *image; + image_t *image; image = &r_images[texnum]; - //vid.rendermode = kRenderNormal; + // vid.rendermode = kRenderNormal; if( vid.rendermode == kRenderNormal ) { r_affinetridesc.pskin = image->pixels[0]; - d_pdrawspans = R_PolysetFillSpans8 ; + d_pdrawspans = R_PolysetFillSpans8; } - else if( vid.rendermode == kRenderTransAdd) + else if( vid.rendermode == kRenderTransAdd ) { r_affinetridesc.pskin = image->pixels[0]; d_pdrawspans = R_PolysetDrawSpansAdditive; @@ -95,11 +95,12 @@ GL_UpdateTextureParams */ static void GL_UpdateTextureParams( int iTexture ) { - image_t *tex = &r_images[iTexture]; + image_t *tex = &r_images[iTexture]; Assert( tex != NULL ); - if( !tex->pixels) return; // free slot + if( !tex->pixels ) + return; // free slot GL_Bind( XASH_TEXTURE0, iTexture ); } @@ -111,7 +112,7 @@ R_SetTextureParameters */ void R_SetTextureParameters( void ) { - int i; + int i; // change all the existing mipmapped texture objects for( i = 0; i < r_numImages; i++ ) @@ -126,7 +127,7 @@ GL_CalcImageSize */ static size_t GL_CalcImageSize( pixformat_t format, int width, int height, int depth ) { - size_t size = 0; + size_t size = 0; // check the depth error depth = Q_max( 1, depth ); @@ -142,12 +143,12 @@ static size_t GL_CalcImageSize( pixformat_t format, int width, int height, int d size = width * height * depth * 4; break; case PF_DXT1: - size = (((width + 3) >> 2) * ((height + 3) >> 2) * 8) * depth; + size = ((( width + 3 ) >> 2 ) * (( height + 3 ) >> 2 ) * 8 ) * depth; break; case PF_DXT3: case PF_DXT5: case PF_ATI2: - size = (((width + 3) >> 2) * ((height + 3) >> 2) * 16) * depth; + size = ((( width + 3 ) >> 2 ) * (( height + 3 ) >> 2 ) * 16 ) * depth; break; } @@ -166,8 +167,8 @@ static size_t GL_CalcTextureSize( int width, int height, int depth ) static int GL_CalcMipmapCount( image_t *tex, qboolean haveBuffer ) { - int width, height; - int mipcount; + int width, height; + int mipcount; Assert( tex != NULL ); @@ -197,8 +198,8 @@ GL_SetTextureDimensions */ static void GL_SetTextureDimensions( image_t *tex, int width, int height, int depth ) { - int maxTextureSize = 1024; - int maxDepthSize = 1; + int maxTextureSize = 1024; + int maxDepthSize = 1; Assert( tex != NULL ); @@ -246,11 +247,11 @@ GL_SetTextureFormat */ static void GL_SetTextureFormat( image_t *tex, pixformat_t format, int channelMask ) { - qboolean haveColor = ( channelMask & IMAGE_HAS_COLOR ); - qboolean haveAlpha = ( channelMask & IMAGE_HAS_ALPHA ); + qboolean haveColor = ( channelMask & IMAGE_HAS_COLOR ); + qboolean haveAlpha = ( channelMask & IMAGE_HAS_ALPHA ); Assert( tex != NULL ); - //tex->transparent = !!( channelMask & IMAGE_HAS_ALPHA ); + // tex->transparent = !!( channelMask & IMAGE_HAS_ALPHA ); } /* @@ -262,16 +263,17 @@ Assume input buffer is RGBA */ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int outWidth, int outHeight, qboolean isNormalMap ) { - uint frac, fracStep; - uint *in = (uint *)source; - uint p1[0x1000], p2[0x1000]; - byte *pix1, *pix2, *pix3, *pix4; - uint *out, *inRow1, *inRow2; - static byte *scaledImage = NULL; // pointer to a scaled image - vec3_t normal; - int i, x, y; + uint frac, fracStep; + uint *in = (uint *)source; + uint p1[0x1000], p2[0x1000]; + byte *pix1, *pix2, *pix3, *pix4; + uint *out, *inRow1, *inRow2; + static byte *scaledImage = NULL; // pointer to a scaled image + vec3_t normal; + int i, x, y; - if( !source ) return NULL; + if( !source ) + return NULL; scaledImage = Mem_Realloc( r_temppool, scaledImage, outWidth * outHeight * 4 ); fracStep = inWidth * 0x10000 / outWidth; @@ -280,14 +282,14 @@ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int out frac = fracStep >> 2; for( i = 0; i < outWidth; i++ ) { - p1[i] = 4 * (frac >> 16); + p1[i] = 4 * ( frac >> 16 ); frac += fracStep; } - frac = (fracStep >> 2) * 3; + frac = ( fracStep >> 2 ) * 3; for( i = 0; i < outWidth; i++ ) { - p2[i] = 4 * (frac >> 16); + p2[i] = 4 * ( frac >> 16 ); frac += fracStep; } @@ -295,8 +297,8 @@ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int out { for( y = 0; y < outHeight; y++, out += outWidth ) { - inRow1 = in + inWidth * (int)(((float)y + 0.25f) * inHeight / outHeight); - inRow2 = in + inWidth * (int)(((float)y + 0.75f) * inHeight / outHeight); + inRow1 = in + inWidth * (int)(((float)y + 0.25f ) * inHeight / outHeight ); + inRow2 = in + inWidth * (int)(((float)y + 0.75f ) * inHeight / outHeight ); for( x = 0; x < outWidth; x++ ) { @@ -312,10 +314,10 @@ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int out if( !VectorNormalizeLength( normal )) VectorSet( normal, 0.5f, 0.5f, 1.0f ); - ((byte *)(out+x))[0] = 128 + (byte)(127.0f * normal[0]); - ((byte *)(out+x))[1] = 128 + (byte)(127.0f * normal[1]); - ((byte *)(out+x))[2] = 128 + (byte)(127.0f * normal[2]); - ((byte *)(out+x))[3] = 255; + ((byte *)( out + x ))[0] = 128 + (byte)( 127.0f * normal[0] ); + ((byte *)( out + x ))[1] = 128 + (byte)( 127.0f * normal[1] ); + ((byte *)( out + x ))[2] = 128 + (byte)( 127.0f * normal[2] ); + ((byte *)( out + x ))[3] = 255; } } } @@ -323,8 +325,8 @@ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int out { for( y = 0; y < outHeight; y++, out += outWidth ) { - inRow1 = in + inWidth * (int)(((float)y + 0.25f) * inHeight / outHeight); - inRow2 = in + inWidth * (int)(((float)y + 0.75f) * inHeight / outHeight); + inRow1 = in + inWidth * (int)(((float)y + 0.25f ) * inHeight / outHeight ); + inRow2 = in + inWidth * (int)(((float)y + 0.75f ) * inHeight / outHeight ); for( x = 0; x < outWidth; x++ ) { @@ -333,10 +335,10 @@ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int out pix3 = (byte *)inRow2 + p1[x]; pix4 = (byte *)inRow2 + p2[x]; - ((byte *)(out+x))[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0]) >> 2; - ((byte *)(out+x))[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1]) >> 2; - ((byte *)(out+x))[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2]) >> 2; - ((byte *)(out+x))[3] = (pix1[3] + pix2[3] + pix3[3] + pix4[3]) >> 2; + ((byte *)( out + x ))[0] = ( pix1[0] + pix2[0] + pix3[0] + pix4[0] ) >> 2; + ((byte *)( out + x ))[1] = ( pix1[1] + pix2[1] + pix3[1] + pix4[1] ) >> 2; + ((byte *)( out + x ))[2] = ( pix1[2] + pix2[2] + pix3[2] + pix4[2] ) >> 2; + ((byte *)( out + x ))[3] = ( pix1[3] + pix2[3] + pix3[3] + pix4[3] ) >> 2; } } } @@ -353,10 +355,10 @@ box filter 3x3 */ static void GL_BoxFilter3x3( byte *out, const byte *in, int w, int h, int x, int y ) { - int r = 0, g = 0, b = 0, a = 0; - int count = 0, acount = 0; - int i, j, u, v; - const byte *pixel; + int r = 0, g = 0, b = 0, a = 0; + int count = 0, acount = 0; + int i, j, u, v; + const byte *pixel; for( i = 0; i < 3; i++ ) { @@ -382,7 +384,7 @@ static void GL_BoxFilter3x3( byte *out, const byte *in, int w, int h, int x, int } } - if( acount == 0 ) + if( acount == 0 ) acount = 1; out[0] = r / acount; @@ -400,11 +402,11 @@ Apply box-filter to 1-bit alpha */ static byte *GL_ApplyFilter( const byte *source, int width, int height ) { - byte *in = (byte *)source; - byte *out = (byte *)source; - int i; + byte *in = (byte *)source; + byte *out = (byte *)source; + int i; - if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ) ) + if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE )) return in; for( i = 0; source && i < width * height; i++, in += 4 ) @@ -425,13 +427,14 @@ Operates in place, quartering the size of the texture */ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth, int flags ) { - byte *out = in; - int instride = ALIGN( srcWidth * 4, 1 ); - int mipWidth, mipHeight, outpadding; - int row, x, y, z; - vec3_t normal; + byte *out = in; + int instride = ALIGN( srcWidth * 4, 1 ); + int mipWidth, mipHeight, outpadding; + int row, x, y, z; + vec3_t normal; - if( !in ) return; + if( !in ) + return; mipWidth = Q_max( 1, ( srcWidth >> 1 )); mipHeight = Q_max( 1, ( srcHeight >> 1 )); @@ -456,26 +459,26 @@ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth, { if((( x << 1 ) + 1 ) < srcWidth ) { - normal[0] = MAKE_SIGNED( in[row+0] ) + MAKE_SIGNED( in[row+4] ) - + MAKE_SIGNED( next[row+0] ) + MAKE_SIGNED( next[row+4] ); - normal[1] = MAKE_SIGNED( in[row+1] ) + MAKE_SIGNED( in[row+5] ) - + MAKE_SIGNED( next[row+1] ) + MAKE_SIGNED( next[row+5] ); - normal[2] = MAKE_SIGNED( in[row+2] ) + MAKE_SIGNED( in[row+6] ) - + MAKE_SIGNED( next[row+2] ) + MAKE_SIGNED( next[row+6] ); + normal[0] = MAKE_SIGNED( in[row + 0] ) + MAKE_SIGNED( in[row + 4] ) + + MAKE_SIGNED( next[row + 0] ) + MAKE_SIGNED( next[row + 4] ); + normal[1] = MAKE_SIGNED( in[row + 1] ) + MAKE_SIGNED( in[row + 5] ) + + MAKE_SIGNED( next[row + 1] ) + MAKE_SIGNED( next[row + 5] ); + normal[2] = MAKE_SIGNED( in[row + 2] ) + MAKE_SIGNED( in[row + 6] ) + + MAKE_SIGNED( next[row + 2] ) + MAKE_SIGNED( next[row + 6] ); } else { - normal[0] = MAKE_SIGNED( in[row+0] ) + MAKE_SIGNED( next[row+0] ); - normal[1] = MAKE_SIGNED( in[row+1] ) + MAKE_SIGNED( next[row+1] ); - normal[2] = MAKE_SIGNED( in[row+2] ) + MAKE_SIGNED( next[row+2] ); + normal[0] = MAKE_SIGNED( in[row + 0] ) + MAKE_SIGNED( next[row + 0] ); + normal[1] = MAKE_SIGNED( in[row + 1] ) + MAKE_SIGNED( next[row + 1] ); + normal[2] = MAKE_SIGNED( in[row + 2] ) + MAKE_SIGNED( next[row + 2] ); } if( !VectorNormalizeLength( normal )) VectorSet( normal, 0.5f, 0.5f, 1.0f ); - out[0] = 128 + (byte)(127.0f * normal[0]); - out[1] = 128 + (byte)(127.0f * normal[1]); - out[2] = 128 + (byte)(127.0f * normal[2]); + out[0] = 128 + (byte)( 127.0f * normal[0] ); + out[1] = 128 + (byte)( 127.0f * normal[1] ); + out[2] = 128 + (byte)( 127.0f * normal[2] ); out[3] = 255; } } @@ -489,17 +492,17 @@ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth, { if((( x << 1 ) + 1 ) < srcWidth ) { - out[0] = (in[row+0] + in[row+4] + next[row+0] + next[row+4]) >> 2; - out[1] = (in[row+1] + in[row+5] + next[row+1] + next[row+5]) >> 2; - out[2] = (in[row+2] + in[row+6] + next[row+2] + next[row+6]) >> 2; - out[3] = (in[row+3] + in[row+7] + next[row+3] + next[row+7]) >> 2; + out[0] = ( in[row + 0] + in[row + 4] + next[row + 0] + next[row + 4] ) >> 2; + out[1] = ( in[row + 1] + in[row + 5] + next[row + 1] + next[row + 5] ) >> 2; + out[2] = ( in[row + 2] + in[row + 6] + next[row + 2] + next[row + 6] ) >> 2; + out[3] = ( in[row + 3] + in[row + 7] + next[row + 3] + next[row + 7] ) >> 2; } else { - out[0] = (in[row+0] + next[row+0]) >> 1; - out[1] = (in[row+1] + next[row+1]) >> 1; - out[2] = (in[row+2] + next[row+2]) >> 1; - out[3] = (in[row+3] + next[row+3]) >> 1; + out[0] = ( in[row + 0] + next[row + 0] ) >> 1; + out[1] = ( in[row + 1] + next[row + 1] ) >> 1; + out[2] = ( in[row + 2] + next[row + 2] ) >> 1; + out[3] = ( in[row + 3] + next[row + 3] ) >> 1; } } } @@ -516,14 +519,14 @@ upload texture into video memory */ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) { - byte *buf, *data; - size_t texsize, size; - uint width, height; - uint i, j, numSides; - uint offset = 0; - qboolean normalMap = false; - const byte *bufend; - int mipCount; + byte *buf, *data; + size_t texsize, size; + uint width, height; + uint i, j, numSides; + uint offset = 0; + qboolean normalMap = false; + const byte *bufend; + int mipCount; tex->fogParams[0] = pic->fogParams[0]; tex->fogParams[1] = pic->fogParams[1]; @@ -532,7 +535,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) GL_SetTextureDimensions( tex, pic->width, pic->height, pic->depth ); GL_SetTextureFormat( tex, pic->type, pic->flags ); - //gEngfuncs.Con_Printf("%s %d %d\n", tex->name, tex->width, tex->height ); + // gEngfuncs.Con_Printf("%s %d %d\n", tex->name, tex->width, tex->height ); Assert( pic != NULL ); Assert( tex != NULL ); @@ -542,59 +545,60 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) buf = pic->buffer; - mipCount = 4;//GL_CalcMipmapCount( tex, ( buf != NULL )); + mipCount = 4; // GL_CalcMipmapCount( tex, ( buf != NULL )); // NOTE: only single uncompressed textures can be resamples, no mips, no layers, no sides if((( pic->width != tex->width ) || ( pic->height != tex->height ))) data = GL_ResampleTexture( buf, pic->width, pic->height, tex->width, tex->height, normalMap ); - else data = buf; + else + data = buf; - //if( !ImageCompressed( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA )) + // if( !ImageCompressed( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA )) // data = GL_ApplyFilter( data, tex->width, tex->height ); // mips will be auto-generated if desired for( j = 0; j < mipCount; j++ ) { - int x, y; + int x, y; width = Q_max( 1, ( tex->width >> j )); height = Q_max( 1, ( tex->height >> j )); texsize = GL_CalcTextureSize( width, height, tex->depth ); size = GL_CalcImageSize( pic->type, width, height, tex->depth ); - //GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data ); + // GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data ); // increase size to workaround triangle renderer bugs // it seems to assume memory readable. maybe it was pointed to WAD? - //tex->pixels[j] = (byte*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 1024 ) + 512; - tex->pixels[j] = (pixel_t*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) ); + // tex->pixels[j] = (byte*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 1024 ) + 512; + tex->pixels[j] = (pixel_t *)Mem_Calloc( r_temppool, width * height * sizeof( pixel_t )); - //memset( (byte*)tex->pixels[j] - 512, 0xFF, 512 ); - //memset( (byte*)tex->pixels[j] + width * height * sizeof(pixel_t), 0xFF, 512 ); + // memset( (byte*)tex->pixels[j] - 512, 0xFF, 512 ); + // memset( (byte*)tex->pixels[j] + width * height * sizeof(pixel_t), 0xFF, 512 ); - if( j == 0 && tex->flags & TF_HAS_ALPHA ) - tex->alpha_pixels = (pixel_t*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) ); + if( j == 0 && tex->flags & TF_HAS_ALPHA ) + tex->alpha_pixels = (pixel_t *)Mem_Calloc( r_temppool, width * height * sizeof( pixel_t )); - for(i = 0; i < height * width; i++ ) + for( i = 0; i < height * width; i++ ) { - unsigned int r, g, b, major, minor; - // seems to look better - r = data[i * 4 + 0] * BIT(5) / 256; - g = data[i * 4 + 1] * BIT(6) / 256; - b = data[i * 4 + 2] * BIT(5) / 256; + unsigned int r, g, b, major, minor; + // seems to look better + r = data[i * 4 + 0] * BIT( 5 ) / 256; + g = data[i * 4 + 1] * BIT( 6 ) / 256; + b = data[i * 4 + 2] * BIT( 5 ) / 256; - // 565 to 332 - major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2))); + // 565 to 332 + major = ((( r >> 2 ) & MASK( 3 )) << 5 ) | (((( g >> 3 ) & MASK( 3 )) << 2 )) | ((( b >> 3 ) & MASK( 2 ))); - // save minor GBRGBRGB - minor = MOVE_BIT(r,1,5) | MOVE_BIT(r,0,2) | MOVE_BIT(g,2,7) | MOVE_BIT(g,1,4) | MOVE_BIT(g,0,1) | MOVE_BIT(b,2,6)| MOVE_BIT(b,1,3)|MOVE_BIT(b,0,0); + // save minor GBRGBRGB + minor = MOVE_BIT( r, 1, 5 ) | MOVE_BIT( r, 0, 2 ) | MOVE_BIT( g, 2, 7 ) | MOVE_BIT( g, 1, 4 ) | MOVE_BIT( g, 0, 1 ) | MOVE_BIT( b, 2, 6 ) | MOVE_BIT( b, 1, 3 ) | MOVE_BIT( b, 0, 0 ); - tex->pixels[j][i] = major << 8 | (minor & 0xFF); - if( j == 0 && tex->alpha_pixels ) - { - unsigned int alpha = (data[i * 4 + 3] * 8 / 256) << (16 - 3); - tex->alpha_pixels[i] = (tex->pixels[j][i] >> 3) | alpha; - if( !sw_noalphabrushes.value && data[i * 4 + 3] < 128 && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA ) ) - tex->pixels[j][i] = TRANSPARENT_COLOR; //0000 0011 0100 1001; - } + tex->pixels[j][i] = major << 8 | ( minor & 0xFF ); + if( j == 0 && tex->alpha_pixels ) + { + unsigned int alpha = ( data[i * 4 + 3] * 8 / 256 ) << ( 16 - 3 ); + tex->alpha_pixels[i] = ( tex->pixels[j][i] >> 3 ) | alpha; + if( !sw_noalphabrushes.value && data[i * 4 + 3] < 128 && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA )) + tex->pixels[j][i] = TRANSPARENT_COLOR; // 0000 0011 0100 1001; + } } @@ -604,7 +608,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) tex->size += texsize; tex->numMips++; - //GL_CheckTexImageError( tex ); + // GL_CheckTexImageError( tex ); } return true; @@ -619,11 +623,13 @@ do specified actions on pixels */ static void GL_ProcessImage( image_t *tex, rgbdata_t *pic ) { - uint img_flags = 0; + uint img_flags = 0; // force upload texture as RGB or RGBA (detail textures requires this) - if( tex->flags & TF_FORCE_COLOR ) pic->flags |= IMAGE_HAS_COLOR; - if( pic->flags & IMAGE_HAS_ALPHA ) tex->flags |= TF_HAS_ALPHA; + if( tex->flags & TF_FORCE_COLOR ) + pic->flags |= IMAGE_HAS_COLOR; + if( pic->flags & IMAGE_HAS_ALPHA ) + tex->flags |= TF_HAS_ALPHA; if( ImageCompressed( pic->type )) { @@ -670,7 +676,7 @@ static qboolean GL_CheckTexName( const char *name ) { int len; - if( !COM_CheckString( name ) ) + if( !COM_CheckString( name )) return false; len = Q_strlen( name ); @@ -678,7 +684,7 @@ static qboolean GL_CheckTexName( const char *name ) // because multi-layered textures can exceed name string if( len >= sizeof( r_images->name )) { - gEngfuncs.Con_Printf( S_ERROR "%s: too long name %s (%d)\n", __func__, name, len); + gEngfuncs.Con_Printf( S_ERROR "%s: too long name %s (%d)\n", __func__, name, len ); return false; } @@ -692,8 +698,8 @@ GL_TextureForName */ static image_t *GL_TextureForName( const char *name ) { - image_t *tex; - uint hash; + image_t *tex; + uint hash; // find the texture in array hash = COM_HashKey( name, TEXTURES_HASH_SIZE ); @@ -714,12 +720,13 @@ GL_AllocTexture */ static image_t *GL_AllocTexture( const char *name, texFlags_t flags ) { - image_t *tex; - uint i; + image_t *tex; + uint i; // find a free texture_t slot for( i = 0, tex = r_images; i < r_numImages; i++, tex++ ) - if( !tex->name[0] ) break; + if( !tex->name[0] ) + break; if( i == r_numImages ) { @@ -733,7 +740,7 @@ static image_t *GL_AllocTexture( const char *name, texFlags_t flags ) // copy initial params Q_strncpy( tex->name, name, sizeof( tex->name )); - //tex->texnum = i; // texnum is used for fast acess into gl_textures array too + // tex->texnum = i; // texnum is used for fast acess into gl_textures array too tex->flags = flags; // add to hash table @@ -751,14 +758,15 @@ GL_DeleteTexture */ static void GL_DeleteTexture( image_t *tex ) { - image_t **prev; - image_t *cur; - int i; + image_t **prev; + image_t *cur; + int i; ASSERT( tex != NULL ); // already freed? - if( !tex->pixels[0]) return; + if( !tex->pixels[0] ) + return; // debug if( !tex->name[0] ) @@ -773,7 +781,8 @@ static void GL_DeleteTexture( image_t *tex ) while( 1 ) { cur = *prev; - if( !cur ) break; + if( !cur ) + break; if( cur == tex ) { @@ -788,8 +797,10 @@ static void GL_DeleteTexture( image_t *tex ) gEngfuncs.FS_FreeImage( tex->original ); for( i = 0; i < 4; i++ ) - if( tex->pixels[i]) Mem_Free(tex->pixels[i]); - if( tex->alpha_pixels ) Mem_Free(tex->alpha_pixels); + if( tex->pixels[i] ) + Mem_Free( tex->pixels[i] ); + if( tex->alpha_pixels ) + Mem_Free( tex->alpha_pixels ); memset( tex, 0, sizeof( *tex )); } @@ -803,9 +814,9 @@ recalc image room */ void GAME_EXPORT GL_UpdateTexSize( int texnum, int width, int height, int depth ) { - int i, j, texsize; - int numSides; - image_t *tex; + int i, j, texsize; + int numSides; + image_t *tex; if( texnum <= 0 || texnum >= MAX_TEXTURES ) return; @@ -834,16 +845,16 @@ GL_LoadTexture */ int GAME_EXPORT GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags ) { - image_t *tex; - rgbdata_t *pic; - uint picFlags = 0; + image_t *tex; + rgbdata_t *pic; + uint picFlags = 0; if( !GL_CheckTexName( name )) return 0; // see if already loaded if(( tex = GL_TextureForName( name ))) - return (tex - r_images); + return( tex - r_images ); if( FBitSet( flags, TF_NOFLIP_TGA )) SetBits( picFlags, IL_DONTFLIP_TGA ); @@ -855,7 +866,8 @@ int GAME_EXPORT GL_LoadTexture( const char *name, const byte *buf, size_t size, gEngfuncs.Image_SetForceFlags( picFlags ); pic = gEngfuncs.FS_LoadImage( name, buf, size ); - if( !pic ) return 0; // couldn't loading image + if( !pic ) + return 0; // couldn't loading image // allocate the new one tex = GL_AllocTexture( name, flags ); @@ -868,7 +880,7 @@ int GAME_EXPORT GL_LoadTexture( const char *name, const byte *buf, size_t size, return 0; } - GL_ApplyTextureParams( tex ); // update texture filter, wrap etc + GL_ApplyTextureParams( tex ); // update texture filter, wrap etc gEngfuncs.FS_FreeImage( pic ); // release source texture // NOTE: always return texnum as index in array or engine will stop work !!! @@ -892,17 +904,18 @@ GL_LoadTextureFromBuffer */ int GAME_EXPORT GL_LoadTextureFromBuffer( const char *name, rgbdata_t *pic, texFlags_t flags, qboolean update ) { - image_t *tex; + image_t *tex; if( !GL_CheckTexName( name )) return 0; // see if already loaded if(( tex = GL_TextureForName( name )) && !update ) - return (tex - r_images); + return( tex - r_images ); // couldn't loading image - if( !pic ) return 0; + if( !pic ) + return 0; if( update ) { @@ -924,7 +937,7 @@ int GAME_EXPORT GL_LoadTextureFromBuffer( const char *name, rgbdata_t *pic, texF } GL_ApplyTextureParams( tex ); // update texture filter, wrap etc - return (tex - r_images); + return( tex - r_images ); } /* @@ -936,8 +949,8 @@ creates texture from buffer */ int GAME_EXPORT GL_CreateTexture( const char *name, int width, int height, const void *buffer, texFlags_t flags ) { - int datasize = 1; - rgbdata_t r_empty; + int datasize = 1; + rgbdata_t r_empty; if( FBitSet( flags, TF_ARB_16BIT )) datasize = 2; @@ -988,14 +1001,14 @@ GL_FindTexture */ int GAME_EXPORT GL_FindTexture( const char *name ) { - image_t *tex; + image_t *tex; if( !GL_CheckTexName( name )) return 0; // see if already loaded if(( tex = GL_TextureForName( name ))) - return (tex - r_images); + return( tex - r_images ); return 0; } @@ -1021,9 +1034,9 @@ GL_ProcessTexture */ void GAME_EXPORT GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor ) { - image_t *image; - rgbdata_t *pic; - int flags = 0; + image_t *image; + rgbdata_t *pic; + int flags = 0; if( texnum <= 0 || texnum >= MAX_TEXTURES ) return; // missed image @@ -1080,7 +1093,7 @@ return size of all uploaded textures */ int R_TexMemory( void ) { - int i, total = 0; + int i, total = 0; for( i = 0; i < r_numImages; i++ ) total += r_images[i].size; @@ -1102,8 +1115,8 @@ GL_FakeImage */ static rgbdata_t *GL_FakeImage( int width, int height, int depth, int flags ) { - static byte data2D[1024]; // 16x16x4 - static rgbdata_t r_image; + static byte data2D[1024]; // 16x16x4 + static rgbdata_t r_image; // also use this for bad textures, but without alpha r_image.width = Q_max( 1, width ); @@ -1112,7 +1125,7 @@ static rgbdata_t *GL_FakeImage( int width, int height, int depth, int flags ) r_image.flags = flags; r_image.type = PF_RGBA_32; r_image.size = r_image.width * r_image.height * r_image.depth * 4; - r_image.buffer = (r_image.size > sizeof( data2D )) ? NULL : data2D; + r_image.buffer = ( r_image.size > sizeof( data2D )) ? NULL : data2D; r_image.palette = NULL; r_image.numMips = 1; r_image.encode = 0; @@ -1131,7 +1144,7 @@ R_InitDlightTexture */ void R_InitDlightTexture( void ) { - rgbdata_t r_image; + rgbdata_t r_image; if( tr.dlightTexture != 0 ) return; // already initialized @@ -1143,7 +1156,7 @@ void R_InitDlightTexture( void ) r_image.type = PF_RGBA_32; r_image.size = r_image.width * r_image.height * 4; - tr.dlightTexture = GL_LoadTextureInternal( "*dlight", &r_image, TF_NOMIPMAP|TF_CLAMP|TF_ATLAS_PAGE ); + tr.dlightTexture = GL_LoadTextureInternal( "*dlight", &r_image, TF_NOMIPMAP | TF_CLAMP | TF_ATLAS_PAGE ); } /* @@ -1153,9 +1166,9 @@ GL_CreateInternalTextures */ static void GL_CreateInternalTextures( void ) { - int dx2, dy, d; - int x, y; - rgbdata_t *pic; + int dx2, dy, d; + int x, y; + rgbdata_t *pic; // emo-texture from quake1 pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR ); @@ -1165,15 +1178,16 @@ static void GL_CreateInternalTextures( void ) for( x = 0; x < 16; x++ ) { if(( y < 8 ) ^ ( x < 8 )) - ((uint *)pic->buffer)[y*16+x] = 0xFFFF00FF; - else ((uint *)pic->buffer)[y*16+x] = 0xFF000000; + ((uint *)pic->buffer )[y * 16 + x] = 0xFFFF00FF; + else + ((uint *)pic->buffer )[y * 16 + x] = 0xFF000000; } } tr.defaultTexture = GL_LoadTextureInternal( REF_DEFAULT_TEXTURE, pic, TF_COLORMAP ); // particle texture from quake1 - pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA ); + pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA ); for( x = 0; x < 16; x++ ) { @@ -1193,24 +1207,24 @@ static void GL_CreateInternalTextures( void ) // white texture pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); for( x = 0; x < 16; x++ ) - ((uint *)pic->buffer)[x] = 0xFFFFFFFF; + ((uint *)pic->buffer )[x] = 0xFFFFFFFF; tr.whiteTexture = GL_LoadTextureInternal( REF_WHITE_TEXTURE, pic, TF_COLORMAP ); // gray texture pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); for( x = 0; x < 16; x++ ) - ((uint *)pic->buffer)[x] = 0xFF7F7F7F; + ((uint *)pic->buffer )[x] = 0xFF7F7F7F; tr.grayTexture = GL_LoadTextureInternal( REF_GRAY_TEXTURE, pic, TF_COLORMAP ); // black texture pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); for( x = 0; x < 16; x++ ) - ((uint *)pic->buffer)[x] = 0xFF000000; + ((uint *)pic->buffer )[x] = 0xFF000000; tr.blackTexture = GL_LoadTextureInternal( REF_BLACK_TEXTURE, pic, TF_COLORMAP ); // cinematic dummy pic = GL_FakeImage( 640, 100, 1, IMAGE_HAS_COLOR ); - tr.cinTexture = GL_LoadTextureInternal( "*cintexture", pic, TF_NOMIPMAP|TF_CLAMP ); + tr.cinTexture = GL_LoadTextureInternal( "*cintexture", pic, TF_NOMIPMAP | TF_CLAMP ); } /* @@ -1220,15 +1234,16 @@ R_TextureList_f */ void R_TextureList_f( void ) { - image_t *image; - int i, texCount, bytes = 0; + image_t *image; + int i, texCount, bytes = 0; gEngfuncs.Con_Printf( "\n" ); gEngfuncs.Con_Printf( " -id- -w- -h- -size- -fmt- -type- -data- -encode- -wrap- -depth- -name--------\n" ); for( i = texCount = 0, image = r_images; i < r_numImages; i++, image++ ) { - if( !image->pixels ) continue; + if( !image->pixels ) + continue; bytes += image->size; texCount++; @@ -1239,13 +1254,15 @@ void R_TextureList_f( void ) if( image->flags & TF_NORMALMAP ) gEngfuncs.Con_Printf( "normal " ); - else gEngfuncs.Con_Printf( "diffuse " ); + else + gEngfuncs.Con_Printf( "diffuse " ); if( image->flags & TF_CLAMP ) gEngfuncs.Con_Printf( "clamp " ); else if( image->flags & TF_BORDER ) gEngfuncs.Con_Printf( "border " ); - else gEngfuncs.Con_Printf( "repeat " ); + else + gEngfuncs.Con_Printf( "repeat " ); gEngfuncs.Con_Printf( " %d ", image->depth ); gEngfuncs.Con_Printf( " %s\n", image->name ); } @@ -1288,8 +1305,8 @@ R_ShutdownImages */ void R_ShutdownImages( void ) { - image_t *tex; - int i; + image_t *tex; + int i; gEngfuncs.Cmd_RemoveCommand( "texturelist" ); diff --git a/ref/soft/r_light.c b/ref/soft/r_light.c index f32945b6..1f115846 100644 --- a/ref/soft/r_light.c +++ b/ref/soft/r_light.c @@ -19,8 +19,8 @@ GNU General Public License for more details. #include "xash3d_mathlib.h" #include "ref_params.h" -//unused, need refactor -unsigned blocklights[10240]; +// unused, need refactor +unsigned blocklights[10240]; /* ============================================================================= @@ -37,8 +37,8 @@ CL_RunLightStyles */ void CL_RunLightStyles( lightstyle_t *ls ) { - int i; - float frametime = (gp_cl->time - gp_cl->oldtime); + int i; + float frametime = ( gp_cl->time - gp_cl->oldtime ); if( !WORLDMODEL ) return; @@ -54,7 +54,7 @@ void CL_RunLightStyles( lightstyle_t *ls ) // 'm' is normal light, 'a' is no light, 'z' is double bright for( i = 0; i < MAX_LIGHTSTYLES; i++ ) { - int k, flight, clight; + int k, flight, clight; float l, lerpfrac, backlerp; if( !gp_cl->paused && frametime <= 0.1f ) @@ -76,7 +76,7 @@ void CL_RunLightStyles( lightstyle_t *ls ) if( !ls[i].interp || !cl_lightstyle_lerping->value ) { - tr.lightstylevalue[i] = ls[i].map[flight%ls[i].length] * 22; + tr.lightstylevalue[i] = ls[i].map[flight % ls[i].length] * 22; continue; } @@ -104,9 +104,9 @@ R_MarkLights */ void R_MarkLights( dlight_t *light, int bit, mnode_t *node ) { - float dist; - msurface_t *surf; - int i; + float dist; + msurface_t *surf; + int i; if( !node || node->contents < 0 ) return; @@ -130,12 +130,12 @@ void R_MarkLights( dlight_t *light, int bit, mnode_t *node ) for( i = 0; i < node->numsurfaces; i++, surf++ ) { if( !BoundsAndSphereIntersect( surf->info->mins, surf->info->maxs, light->origin, light->radius )) - continue; // no intersection + continue; // no intersection - if( surf->dlightframe != tr.framecount )//tr.dlightframecount ) + if( surf->dlightframe != tr.framecount ) // tr.dlightframecount ) { surf->dlightbits = 0; - surf->dlightframe = tr.framecount; //tr.dlightframecount; + surf->dlightframe = tr.framecount; // tr.dlightframecount; } surf->dlightbits |= bit; } @@ -151,7 +151,7 @@ R_PushDlights */ void R_PushDlights( void ) { - int i; + int i; tr.dlightframecount = tr.framecount; @@ -170,10 +170,10 @@ void R_PushDlights( void ) if( l->die < gp_cl->time || !l->radius ) continue; - //if( GL_FrustumCullSphere( &RI.frustum, l->origin, l->radius, 15 )) - //continue; + // if( GL_FrustumCullSphere( &RI.frustum, l->origin, l->radius, 15 )) + // continue; - R_MarkLights( l, 1<nodes ); + R_MarkLights( l, 1 << i, RI.currentmodel->nodes ); } } @@ -184,9 +184,9 @@ void R_PushDlights( void ) ======================================================================= */ -static vec3_t g_trace_lightspot; -static vec3_t g_trace_lightvec; -static float g_trace_fraction; +static vec3_t g_trace_lightspot; +static vec3_t g_trace_lightvec; +static float g_trace_fraction; /* ================= @@ -195,16 +195,16 @@ R_RecursiveLightPoint */ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, float p2f, colorVec *cv, const vec3_t start, const vec3_t end ) { - float front, back, frac, midf; - int i, map, side, size; - float ds, dt, s, t; - int sample_size; - color24 *lm, *dm; - mextrasurf_t *info; - msurface_t *surf; - mtexinfo_t *tex; - matrix3x4 tbn; - vec3_t mid; + float front, back, frac, midf; + int i, map, side, size; + float ds, dt, s, t; + int sample_size; + color24 *lm, *dm; + mextrasurf_t *info; + msurface_t *surf; + mtexinfo_t *tex; + matrix3x4 tbn; + vec3_t mid; // didn't hit anything if( !node || node->contents < 0 ) @@ -242,13 +242,13 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, for( i = 0; i < node->numsurfaces; i++, surf++ ) { - int smax, tmax; + int smax, tmax; tex = surf->texinfo; info = surf->info; if( FBitSet( surf->flags, SURF_DRAWTILED )) - continue; // no lightmaps + continue; // no lightmaps s = DotProduct( mid, info->lmvecs[0] ) + info->lmvecs[0][3]; t = DotProduct( mid, info->lmvecs[1] ) + info->lmvecs[1][3]; @@ -259,7 +259,7 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, ds = s - info->lightmapmins[0]; dt = t - info->lightmapmins[1]; - if ( ds > info->lightextents[0] || dt > info->lightextents[1] ) + if( ds > info->lightextents[0] || dt > info->lightextents[1] ) continue; cv->r = cv->g = cv->b = cv->a = 0; @@ -268,8 +268,8 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, return true; sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - smax = (info->lightextents[0] / sample_size) + 1; - tmax = (info->lightextents[1] / sample_size) + 1; + smax = ( info->lightextents[0] / sample_size ) + 1; + tmax = ( info->lightextents[1] / sample_size ) + 1; ds /= sample_size; dt /= sample_size; @@ -280,11 +280,12 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, if( surf->info->deluxemap ) { - vec3_t faceNormal; + vec3_t faceNormal; if( FBitSet( surf->flags, SURF_PLANEBACK )) VectorNegate( surf->plane->normal, faceNormal ); - else VectorCopy( surf->plane->normal, faceNormal ); + else + VectorCopy( surf->plane->normal, faceNormal ); // compute face TBN #if 1 @@ -304,7 +305,7 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, for( map = 0; map < MAXLIGHTMAPS && surf->styles[map] != 255; map++ ) { - uint scale = tr.lightstylevalue[surf->styles[map]]; + uint scale = tr.lightstylevalue[surf->styles[map]]; cv->r += lm->r * scale; cv->g += lm->g * scale; @@ -314,12 +315,12 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, if( dm != NULL ) { - vec3_t srcNormal, lightNormal; - float f = (1.0f / 128.0f); + vec3_t srcNormal, lightNormal; + float f = ( 1.0f / 128.0f ); - VectorSet( srcNormal, ((float)dm->r - 128.0f) * f, ((float)dm->g - 128.0f) * f, ((float)dm->b - 128.0f) * f ); - Matrix3x4_VectorIRotate( tbn, srcNormal, lightNormal ); // turn to world space - VectorScale( lightNormal, (float)scale * -1.0f, lightNormal ); // turn direction from light + VectorSet( srcNormal, ((float)dm->r - 128.0f ) * f, ((float)dm->g - 128.0f ) * f, ((float)dm->b - 128.0f ) * f ); + Matrix3x4_VectorIRotate( tbn, srcNormal, lightNormal ); // turn to world space + VectorScale( lightNormal, (float)scale * -1.0f, lightNormal ); // turn direction from light VectorAdd( g_trace_lightvec, lightNormal, g_trace_lightvec ); dm += size; // skip to next deluxmap } @@ -341,12 +342,14 @@ check bspmodels to get light from */ static colorVec R_LightVecInternal( const vec3_t start, const vec3_t end, vec3_t lspot, vec3_t lvec ) { - float last_fraction; - int i, maxEnts = 1; - colorVec light, cv; + float last_fraction; + int i, maxEnts = 1; + colorVec light, cv; - if( lspot ) VectorClear( lspot ); - if( lvec ) VectorClear( lvec ); + if( lspot ) + VectorClear( lspot ); + if( lvec ) + VectorClear( lvec ); if( WORLDMODEL && WORLDMODEL->lightdata ) { @@ -354,16 +357,16 @@ static colorVec R_LightVecInternal( const vec3_t start, const vec3_t end, vec3_t last_fraction = 1.0f; // get light from bmodels too - //if( CVAR_TO_BOOL( r_lighting_extended )) - maxEnts = MAX_PHYSENTS; + // if( CVAR_TO_BOOL( r_lighting_extended )) + maxEnts = MAX_PHYSENTS; // check all the bsp-models for( i = 0; i < maxEnts; i++ ) { - physent_t *pe = gEngfuncs.EV_GetPhysent( i ); - vec3_t offset, start_l, end_l; - mnode_t *pnodes; - matrix4x4 matrix; + physent_t *pe = gEngfuncs.EV_GetPhysent( i ); + vec3_t offset, start_l, end_l; + mnode_t *pnodes; + matrix4x4 matrix; if( !pe ) break; @@ -390,12 +393,14 @@ static colorVec R_LightVecInternal( const vec3_t start, const vec3_t end, vec3_t g_trace_fraction = 1.0f; if( !R_RecursiveLightPoint( pe->model, pnodes, 0.0f, 1.0f, &cv, start_l, end_l )) - continue; // didn't hit anything + continue; // didn't hit anything if( g_trace_fraction < last_fraction ) { - if( lspot ) VectorCopy( g_trace_lightspot, lspot ); - if( lvec ) VectorNormalize2( g_trace_lightvec, lvec ); + if( lspot ) + VectorCopy( g_trace_lightspot, lspot ); + if( lvec ) + VectorNormalize2( g_trace_lightvec, lvec ); light.r = Q_min(( cv.r >> 8 ), 255 ); light.g = Q_min(( cv.g >> 8 ), 255 ); light.b = Q_min(( cv.b >> 8 ), 255 ); @@ -424,9 +429,9 @@ check bspmodels to get light from */ colorVec GAME_EXPORT R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot, vec3_t lvec ) { - colorVec light = R_LightVecInternal( start, end, lspot, lvec ); + colorVec light = R_LightVecInternal( start, end, lspot, lvec ); - //light.r = light.g = light.b = 255; + // light.r = light.g = light.b = 255; if( lspot != NULL && lvec != NULL ) // CVAR_TO_BOOL( r_lighting_extended ) && { @@ -447,7 +452,7 @@ light from floor */ colorVec GAME_EXPORT R_LightPoint( const vec3_t p0 ) { - vec3_t p1; + vec3_t p1; VectorSet( p1, p0[0], p0[1], p0[2] - 2048.0f ); diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index 23670a73..687aa0b1 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -33,66 +33,66 @@ GNU General Public License for more details. #include "cvardef.h" typedef struct mip_s mip_t; -typedef int fixed8_t; -typedef int fixed16_t; +typedef int fixed8_t; +typedef int fixed16_t; -#define ASSERT(x) if(!( x )) gEngfuncs.Host_Error( "assert failed at %s:%i\n", __FILE__, __LINE__ ) -#define Assert(x) if(!( x )) gEngfuncs.Host_Error( "assert failed at %s:%i\n", __FILE__, __LINE__ ) +#define ASSERT( x ) if( !( x )) gEngfuncs.Host_Error( "assert failed at %s:%i\n", __FILE__, __LINE__ ) +#define Assert( x ) if( !( x )) gEngfuncs.Host_Error( "assert failed at %s:%i\n", __FILE__, __LINE__ ) #include // make mod_ref.h? -#define LM_SAMPLE_SIZE 16 +#define LM_SAMPLE_SIZE 16 extern poolhandle_t r_temppool; -#define BLOCK_SIZE tr.block_size // lightmap blocksize -#define BLOCK_SIZE_DEFAULT 128 // for keep backward compatibility -#define BLOCK_SIZE_MAX 1024 +#define BLOCK_SIZE tr.block_size // lightmap blocksize +#define BLOCK_SIZE_DEFAULT 128 // for keep backward compatibility +#define BLOCK_SIZE_MAX 1024 -#define MAX_TEXTURES 8192 // a1ba: increased by users request -#define MAX_DECAL_SURFS 4096 +#define MAX_TEXTURES 8192 // a1ba: increased by users request +#define MAX_DECAL_SURFS 4096 #if XASH_LOW_MEMORY #undef MAX_TEXTURES #undef MAX_DECAL_SURFS - #define MAX_TEXTURES 1024 + #define MAX_TEXTURES 1024 #define MAX_DECAL_SURFS 256 #endif -#define MAX_DETAIL_TEXTURES 256 -#define MAX_LIGHTMAPS 256 -#define SUBDIVIDE_SIZE 64 -#define MAX_DRAW_STACK 2 // normal view and menu view +#define MAX_DETAIL_TEXTURES 256 +#define MAX_LIGHTMAPS 256 +#define SUBDIVIDE_SIZE 64 +#define MAX_DRAW_STACK 2 // normal view and menu view -#define SHADEDOT_QUANT 16 // precalculated dot products for quantized angles -#define SHADE_LAMBERT 1.4953241 -#define DEFAULT_ALPHATEST 0.0f +#define SHADEDOT_QUANT 16 // precalculated dot products for quantized angles +#define SHADE_LAMBERT 1.4953241 +#define DEFAULT_ALPHATEST 0.0f // refparams -#define RP_NONE 0 -#define RP_ENVVIEW BIT( 0 ) // used for cubemapshot -#define RP_OLDVIEWLEAF BIT( 1 ) -#define RP_CLIPPLANE BIT( 2 ) +#define RP_NONE 0 +#define RP_ENVVIEW BIT( 0 ) // used for cubemapshot +#define RP_OLDVIEWLEAF BIT( 1 ) +#define RP_CLIPPLANE BIT( 2 ) -#define RP_NONVIEWERREF (RP_ENVVIEW) -#define R_ModelOpaque( rm ) ( rm == kRenderNormal ) -#define R_StaticEntity( ent ) ( VectorIsNull( ent->origin ) && VectorIsNull( ent->angles )) -#define RP_LOCALCLIENT( e ) ((e) != NULL && (e)->index == ( gp_cl->playernum + 1 ) && e->player ) -#define RP_NORMALPASS() ( FBitSet( RI.params, RP_NONVIEWERREF ) == 0 ) +#define RP_NONVIEWERREF ( RP_ENVVIEW ) +#define R_ModelOpaque( rm ) ( rm == kRenderNormal ) +#define R_StaticEntity( ent ) ( VectorIsNull( ent->origin ) && VectorIsNull( ent->angles )) +#define RP_LOCALCLIENT( e ) (( e ) != NULL && ( e )->index == ( gp_cl->playernum + 1 ) && e->player ) +#define RP_NORMALPASS() ( FBitSet( RI.params, RP_NONVIEWERREF ) == 0 ) #define CL_IsViewEntityLocalPlayer() ( gp_cl->viewentity == ( gp_cl->playernum + 1 )) -#define CULL_VISIBLE 0 // not culled -#define CULL_BACKSIDE 1 // backside of transparent wall -#define CULL_FRUSTUM 2 // culled by frustum -#define CULL_VISFRAME 3 // culled by PVS -#define CULL_OTHER 4 // culled by other reason +#define CULL_VISIBLE 0 // not culled +#define CULL_BACKSIDE 1 // backside of transparent wall +#define CULL_FRUSTUM 2 // culled by frustum +#define CULL_VISFRAME 3 // culled by PVS +#define CULL_OTHER 4 // culled by other reason // bit operation helpers -#define MASK(x) (BIT(x)-1) -#define GET_BIT(s,b) ((s & (1 << b)) >> b) -#define MOVE_BIT(s, f, t) (GET_BIT(s,f) << t ) +#define MASK( x ) ( BIT( x ) - 1 ) +#define GET_BIT( s, b ) (( s & ( 1 << b )) >> b ) +#define MOVE_BIT( s, f, t ) ( GET_BIT( s, f ) << t ) /* @@ -115,258 +115,258 @@ typedef enum } imagetype_t; -//=================================================================== +// =================================================================== typedef unsigned short pixel_t; typedef struct vrect_s { - int x,y,width,height; - struct vrect_s *pnext; + int x, y, width, height; + struct vrect_s *pnext; } vrect_t; #define COLOR_WHITE 0xFFFF -//#define SEPARATE_BLIT +// #define SEPARATE_BLIT typedef struct { - pixel_t *buffer; // invisible buffer - pixel_t colormap[32*8192]; // 8192 * light levels - //pixel_t *alphamap; // 256 * 256 translucency map + pixel_t *buffer; // invisible buffer + pixel_t colormap[32 * 8192]; // 8192 * light levels + // pixel_t *alphamap; // 256 * 256 translucency map #ifdef SEPARATE_BLIT - pixel_t screen_minor[256]; - pixel_t screen_major[256]; + pixel_t screen_minor[256]; + pixel_t screen_major[256]; #else - pixel_t screen[256*256]; - unsigned int screen32[256*256]; + pixel_t screen[256 * 256]; + unsigned int screen32[256 * 256]; #endif - byte addmap[256*256]; - byte modmap[256*256]; - pixel_t alphamap[3*1024*256]; - pixel_t color; - qboolean is2d; - byte alpha; + byte addmap[256 * 256]; + byte modmap[256 * 256]; + pixel_t alphamap[3 * 1024 * 256]; + pixel_t color; + qboolean is2d; + byte alpha; // maybe compute colormask for minor byte? - int rendermode; - int rowbytes; // may be > width if displayed in a window - // can be negative for stupid dibs - int width; - int height; + int rendermode; + int rowbytes; // may be > width if displayed in a window + // can be negative for stupid dibs + int width; + int height; } viddef_t; extern viddef_t vid; typedef struct { - int params; // rendering parameters + int params; // rendering parameters - qboolean drawWorld; // ignore world for drawing PlayerModel - qboolean isSkyVisible; // sky is visible - qboolean onlyClientDraw; // disabled by client request - qboolean drawOrtho; // draw world as orthogonal projection + qboolean drawWorld; // ignore world for drawing PlayerModel + qboolean isSkyVisible; // sky is visible + qboolean onlyClientDraw; // disabled by client request + qboolean drawOrtho; // draw world as orthogonal projection - float fov_x, fov_y; // current view fov + float fov_x, fov_y; // current view fov - cl_entity_t *currententity; - model_t *currentmodel; - cl_entity_t *currentbeam; // same as above but for beams + cl_entity_t *currententity; + model_t *currentmodel; + cl_entity_t *currentbeam; // same as above but for beams - int viewport[4]; - //gl_frustum_t frustum; + int viewport[4]; + // gl_frustum_t frustum; - mleaf_t *viewleaf; - mleaf_t *oldviewleaf; - vec3_t pvsorigin; - vec3_t vieworg; // locked vieworigin - vec3_t viewangles; - vec3_t vforward; - vec3_t vright; - vec3_t vup; - vec3_t base_vup; - vec3_t base_vpn; - vec3_t base_vright; + mleaf_t *viewleaf; + mleaf_t *oldviewleaf; + vec3_t pvsorigin; + vec3_t vieworg; // locked vieworigin + vec3_t viewangles; + vec3_t vforward; + vec3_t vright; + vec3_t vup; + vec3_t base_vup; + vec3_t base_vpn; + vec3_t base_vright; - vec3_t cullorigin; - vec3_t cull_vforward; - vec3_t cull_vright; - vec3_t cull_vup; + vec3_t cullorigin; + vec3_t cull_vforward; + vec3_t cull_vright; + vec3_t cull_vup; - int cached_contents; // in water - int cached_waterlevel; // was in water - float farClip; + int cached_contents; // in water + int cached_waterlevel; // was in water + float farClip; - float skyMins[2][6]; - float skyMaxs[2][6]; + float skyMins[2][6]; + float skyMaxs[2][6]; - matrix4x4 objectMatrix; // currententity matrix - matrix4x4 worldviewMatrix; // modelview for world - matrix4x4 modelviewMatrix; // worldviewMatrix * objectMatrix + matrix4x4 objectMatrix; // currententity matrix + matrix4x4 worldviewMatrix; // modelview for world + matrix4x4 modelviewMatrix; // worldviewMatrix * objectMatrix - matrix4x4 projectionMatrix; - matrix4x4 worldviewProjectionMatrix; // worldviewMatrix * projectionMatrix - byte visbytes[(MAX_MAP_LEAFS+7)/8];// actual PVS for current frame + matrix4x4 projectionMatrix; + matrix4x4 worldviewProjectionMatrix; // worldviewMatrix * projectionMatrix + byte visbytes[( MAX_MAP_LEAFS + 7 ) / 8]; // actual PVS for current frame - float viewplanedist; + float viewplanedist; // q2 oldrefdef - vrect_t vrect; // subwindow in video for refresh - // FIXME: not need vrect next field here? - vrect_t aliasvrect; // scaled Alias version - int vrectright, vrectbottom; // right & bottom screen coords - int aliasvrectright, aliasvrectbottom; // scaled Alias versions - float vrectrightedge; // rightmost right edge we care about, - // for use in edge list - float fvrectx, fvrecty; // for floating-point compares - float fvrectx_adj, fvrecty_adj; // left and top edges, for clamping - int vrect_x_adj_shift20; // (vrect.x + 0.5 - epsilon) << 20 - int vrectright_adj_shift20; // (vrectright + 0.5 - epsilon) << 20 - float fvrectright_adj, fvrectbottom_adj; - // right and bottom edges, for clamping - float fvrectright; // rightmost edge, for Alias clamping - float fvrectbottom; // bottommost edge, for Alias clampin + vrect_t vrect; // subwindow in video for refresh + // FIXME: not need vrect next field here? + vrect_t aliasvrect; // scaled Alias version + int vrectright, vrectbottom; // right & bottom screen coords + int aliasvrectright, aliasvrectbottom; // scaled Alias versions + float vrectrightedge; // rightmost right edge we care about, + // for use in edge list + float fvrectx, fvrecty; // for floating-point compares + float fvrectx_adj, fvrecty_adj; // left and top edges, for clamping + int vrect_x_adj_shift20; // (vrect.x + 0.5 - epsilon) << 20 + int vrectright_adj_shift20; // (vrectright + 0.5 - epsilon) << 20 + float fvrectright_adj, fvrectbottom_adj; + // right and bottom edges, for clamping + float fvrectright; // rightmost edge, for Alias clamping + float fvrectbottom; // bottommost edge, for Alias clampin } ref_instance_t; typedef struct { - cl_entity_t *edge_entities[MAX_VISIBLE_PACKET]; // brush edge drawing - cl_entity_t *solid_entities[MAX_VISIBLE_PACKET]; // opaque moving or alpha brushes - cl_entity_t *trans_entities[MAX_VISIBLE_PACKET]; // translucent brushes - cl_entity_t *beam_entities[MAX_VISIBLE_PACKET]; - uint num_edge_entities; - uint num_solid_entities; - uint num_trans_entities; - uint num_beam_entities; + cl_entity_t *edge_entities[MAX_VISIBLE_PACKET]; // brush edge drawing + cl_entity_t *solid_entities[MAX_VISIBLE_PACKET]; // opaque moving or alpha brushes + cl_entity_t *trans_entities[MAX_VISIBLE_PACKET]; // translucent brushes + cl_entity_t *beam_entities[MAX_VISIBLE_PACKET]; + uint num_edge_entities; + uint num_solid_entities; + uint num_trans_entities; + uint num_beam_entities; } draw_list_t; typedef struct { - int defaultTexture; // use for bad textures - int particleTexture; - int whiteTexture; - int grayTexture; - int blackTexture; - int solidskyTexture; // quake1 solid-sky layer - int alphaskyTexture; // quake1 alpha-sky layer - int lightmapTextures[MAX_LIGHTMAPS]; - int dlightTexture; // custom dlight texture - int skyboxTextures[6]; // skybox sides - int cinTexture; // cinematic texture + int defaultTexture; // use for bad textures + int particleTexture; + int whiteTexture; + int grayTexture; + int blackTexture; + int solidskyTexture; // quake1 solid-sky layer + int alphaskyTexture; // quake1 alpha-sky layer + int lightmapTextures[MAX_LIGHTMAPS]; + int dlightTexture; // custom dlight texture + int skyboxTextures[6]; // skybox sides + int cinTexture; // cinematic texture // entity lists - draw_list_t draw_stack[MAX_DRAW_STACK]; - int draw_stack_pos; - draw_list_t *draw_list; + draw_list_t draw_stack[MAX_DRAW_STACK]; + int draw_stack_pos; + draw_list_t *draw_list; - msurface_t *draw_decals[MAX_DECAL_SURFS]; - int num_draw_decals; + msurface_t *draw_decals[MAX_DECAL_SURFS]; + int num_draw_decals; // OpenGL matrix states - qboolean modelviewIdentity; + qboolean modelviewIdentity; - int visframecount; // PVS frame - int dlightframecount; // dynamic light frame - int realframecount; // not including viewpasses - int framecount; + int visframecount; // PVS frame + int dlightframecount; // dynamic light frame + int realframecount; // not including viewpasses + int framecount; - qboolean fCustomRendering; - qboolean fResetVis; - qboolean fFlipViewModel; + qboolean fCustomRendering; + qboolean fResetVis; + qboolean fFlipViewModel; // tree visualization stuff - int recursion_level; - int max_recursion; + int recursion_level; + int max_recursion; - byte visbytes[(MAX_MAP_LEAFS+7)/8]; // member custom PVS - int lightstylevalue[MAX_LIGHTSTYLES]; // value 0 - 65536 - int block_size; // lightmap blocksize + byte visbytes[( MAX_MAP_LEAFS + 7 ) / 8]; // member custom PVS + int lightstylevalue[MAX_LIGHTSTYLES]; // value 0 - 65536 + int block_size; // lightmap blocksize - double frametime; // special frametime for multipass rendering (will set to 0 on a nextview) - float blend; // global blend value + double frametime; // special frametime for multipass rendering (will set to 0 on a nextview) + float blend; // global blend value // cull info - vec3_t modelorg; // relative to viewpoint + vec3_t modelorg; // relative to viewpoint - int sample_size; - uint sample_bits; - qboolean map_unload; + int sample_size; + uint sample_bits; + qboolean map_unload; // get from engine - cl_entity_t *entities; - movevars_t *movevars; - color24 *palette; - cl_entity_t *viewent; + cl_entity_t *entities; + movevars_t *movevars; + color24 *palette; + cl_entity_t *viewent; lightstyle_t *lightstyles; - dlight_t *dlights; - dlight_t *elights; - byte *texgammatable; - uint *lightgammatable; - uint *lineargammatable; - uint *screengammatable; + dlight_t *dlights; + dlight_t *elights; + byte *texgammatable; + uint *lightgammatable; + uint *lineargammatable; + uint *screengammatable; - uint max_entities; + uint max_entities; } gl_globals_t; typedef struct { - uint c_world_polys; - uint c_studio_polys; - uint c_sprite_polys; - uint c_alias_polys; - uint c_world_leafs; + uint c_world_polys; + uint c_studio_polys; + uint c_sprite_polys; + uint c_alias_polys; + uint c_world_leafs; - uint c_view_beams_count; - uint c_active_tents_count; - uint c_alias_models_drawn; - uint c_studio_models_drawn; - uint c_sprite_models_drawn; - uint c_particle_count; + uint c_view_beams_count; + uint c_active_tents_count; + uint c_alias_models_drawn; + uint c_studio_models_drawn; + uint c_sprite_models_drawn; + uint c_particle_count; - uint c_client_ents; // entities that moved to client - double t_world_node; - double t_world_draw; + uint c_client_ents; // entities that moved to client + double t_world_node; + double t_world_draw; } ref_speeds_t; -extern ref_speeds_t r_stats; -extern ref_instance_t RI; -extern gl_globals_t tr; +extern ref_speeds_t r_stats; +extern ref_instance_t RI; +extern gl_globals_t tr; -#define r_numEntities (tr.draw_list->num_solid_entities + tr.draw_list->num_trans_entities) -#define r_numStatics (r_stats.c_client_ents) +#define r_numEntities ( tr.draw_list->num_solid_entities + tr.draw_list->num_trans_entities ) +#define r_numStatics ( r_stats.c_client_ents ) typedef struct image_s { - char name[256]; // game path, including extension (can be store image programs) - word srcWidth; // keep unscaled sizes - word srcHeight; - word width; // upload width\height - word height; - word depth; // texture depth or count of layers for 2D_ARRAY - byte numMips; // mipmap count + char name[256]; // game path, including extension (can be store image programs) + word srcWidth; // keep unscaled sizes + word srcHeight; + word width; // upload width\height + word height; + word depth; // texture depth or count of layers for 2D_ARRAY + byte numMips; // mipmap count - texFlags_t flags; + texFlags_t flags; - rgba_t fogParams; // some water textures - // contain info about underwater fog - rgbdata_t *original; // keep original image + rgba_t fogParams; // some water textures + // contain info about underwater fog + rgbdata_t *original; // keep original image // debug info - size_t size; // upload size for debug targets + size_t size; // upload size for debug targets // detail textures stuff - float xscale; - float yscale; + float xscale; + float yscale; - imagetype_t type; - pixel_t *pixels[4]; // mip levels - pixel_t *alpha_pixels; // mip levels + imagetype_t type; + pixel_t *pixels[4]; // mip levels + pixel_t *alpha_pixels; // mip levels - int servercount; - uint hashValue; - struct image_s *nextHash; + int servercount; + uint hashValue; + struct image_s *nextHash; } image_t; // @@ -380,9 +380,9 @@ qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly ); // void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse ); float *R_DecalSetupVerts( decal_t *pDecal, msurface_t *surf, int texture, int *outCount ); -//void DrawSingleDecal( decal_t *pDecal, msurface_t *fa ); +// void DrawSingleDecal( decal_t *pDecal, msurface_t *fa ); void R_EntityRemoveDecals( model_t *mod ); -//void DrawDecalsBatch( void ); +// void DrawDecalsBatch( void ); void R_ClearDecals( void ); void R_DecalComputeBasis( msurface_t *surf, int flags, vec3_t textureSpaceBasis[3] ); @@ -392,13 +392,13 @@ void GL_Bind( int tmu, unsigned int texnum ); // gl_draw.c // void R_Set2DMode( qboolean enable ); -void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data );// +void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data ); // // gl_image.c // void R_SetTextureParameters( void ); image_t *R_GetTexture( unsigned int texnum ); -#define GL_LoadTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, false ) +#define GL_LoadTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, false ) #define GL_UpdateTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, true ) int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags ); int GL_LoadTextureArray( const char **names, int flags ); @@ -456,8 +456,8 @@ void Matrix4x4_ConcatTranslate( matrix4x4 out, float x, float y, float z ); void Matrix4x4_ConcatRotate( matrix4x4 out, float angle, float x, float y, float z ); void Matrix4x4_CreateTranslate( matrix4x4 out, float x, float y, float z ); void Matrix4x4_CreateRotate( matrix4x4 out, float angle, float x, float y, float z ); -void Matrix4x4_CreateProjection(matrix4x4 out, float xMax, float xMin, float yMax, float yMin, float zNear, float zFar); -void Matrix4x4_CreateOrtho(matrix4x4 m, float xLeft, float xRight, float yBottom, float yTop, float zNear, float zFar); +void Matrix4x4_CreateProjection( matrix4x4 out, float xMax, float xMin, float yMax, float yMin, float zNear, float zFar ); +void Matrix4x4_CreateOrtho( matrix4x4 m, float xLeft, float xRight, float yBottom, float yTop, float zNear, float zFar ); void Matrix4x4_CreateModelview( matrix4x4 out ); // @@ -498,24 +498,25 @@ void Mod_StudioUnloadTextures( void *data ); // r_polyse.c // // !!! if this is changed, it must be changed in asm_draw.h too !!! -typedef struct { - void *pdest; - short *pz; - int count; - pixel_t *ptex; - int sfrac, tfrac, light, zi; +typedef struct +{ + void *pdest; + short *pz; + int count; + pixel_t *ptex; + int sfrac, tfrac, light, zi; } spanpackage_t; extern void (*d_pdrawspans)( spanpackage_t * ); void R_PolysetFillSpans8( spanpackage_t * ); void R_PolysetDrawSpans8_33( spanpackage_t * ); -void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage); -void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage); -void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage); -void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage); -void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage); +void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage ); +void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage ); +void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage ); +void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage ); +void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage ); -//#include "vid_common.h" +// #include "vid_common.h" // // renderer exports @@ -581,10 +582,10 @@ void TriFogParams( float flDensity, int iFogSkybox ); void TriCullFace( TRICULLSTYLE mode ); void TriBrightness( float brightness ); -#define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm) -#define ENGINE_GET_PARM( parm ) ENGINE_GET_PARM_( (parm), 0 ) +#define ENGINE_GET_PARM_ ( *gEngfuncs.EngineGetParm ) +#define ENGINE_GET_PARM( parm ) ENGINE_GET_PARM_(( parm ), 0 ) -extern ref_api_t gEngfuncs; +extern ref_api_t gEngfuncs; extern ref_globals_t *gpGlobals; extern ref_client_t *gp_cl; extern ref_host_t *gp_host; @@ -639,14 +640,14 @@ static inline uint LinearGammaTable( uint b ) return !FBitSet( gp_host->features, ENGINE_LINEAR_GAMMA_SPACE ) ? tr.lineargammatable[b] : b; } -#define WORLDMODEL (gp_cl->models[1]) +#define WORLDMODEL ( gp_cl->models[1] ) // todo: gl_cull.c -#define R_CullModel(...) 0 +#define R_CullModel( ... ) 0 // softrender defs -#define CACHE_SIZE 32 +#define CACHE_SIZE 32 /* ==================================================== @@ -654,86 +655,86 @@ static inline uint LinearGammaTable( uint b ) ==================================================== */ -#define VID_CBITS 6 -#define VID_GRADES (1 << VID_CBITS) +#define VID_CBITS 6 +#define VID_GRADES ( 1 << VID_CBITS ) // r_shared.h: general refresh-related stuff shared between the refresh and the // driver -#define MAXVERTS 64 // max points in a surface polygon -#define MAXWORKINGVERTS (MAXVERTS+4) // max points in an intermediate - // polygon (while processing) +#define MAXVERTS 64 // max points in a surface polygon +#define MAXWORKINGVERTS ( MAXVERTS + 4 ) // max points in an intermediate +// polygon (while processing) // !!! if this is changed, it must be changed in d_ifacea.h too !!! -#define MAXHEIGHT 1200 -#define MAXWIDTH 1920 +#define MAXHEIGHT 1200 +#define MAXWIDTH 1920 -#define INFINITE_DISTANCE 0x10000 // distance that's always guaranteed to - // be farther away than anything in - // the scene +#define INFINITE_DISTANCE 0x10000 // distance that's always guaranteed to +// be farther away than anything in +// the scene // d_iface.h: interface header file for rasterization driver modules -#define WARP_WIDTH 320 -#define WARP_HEIGHT 240 +#define WARP_WIDTH 320 +#define WARP_HEIGHT 240 -#define MAX_LBM_HEIGHT 480 +#define MAX_LBM_HEIGHT 480 #define PARTICLE_Z_CLIP 8.0 // !!! must be kept the same as in quakeasm.h !!! -#define TRANSPARENT_COLOR 0x0349 //0xFF +#define TRANSPARENT_COLOR 0x0349 // 0xFF // !!! if this is changed, it must be changed in d_ifacea.h too !!! -#define TURB_TEX_SIZE 64 // base turbulent texture size +#define TURB_TEX_SIZE 64 // base turbulent texture size // !!! if this is changed, it must be changed in d_ifacea.h too !!! -#define CYCLE 128 // turbulent cycle size +#define CYCLE 128 // turbulent cycle size -#define SCANBUFFERPAD 0x1000 +#define SCANBUFFERPAD 0x1000 -#define DS_SPAN_LIST_END -128 +#define DS_SPAN_LIST_END -128 -#define NUMSTACKEDGES 4000 -#define MINEDGES NUMSTACKEDGES -#define NUMSTACKSURFACES 2000 -#define MINSURFACES NUMSTACKSURFACES -#define MAXSPANS 6000 +#define NUMSTACKEDGES 4000 +#define MINEDGES NUMSTACKEDGES +#define NUMSTACKSURFACES 2000 +#define MINSURFACES NUMSTACKSURFACES +#define MAXSPANS 6000 // flags in finalvert_t.flags -#define ALIAS_LEFT_CLIP 0x0001 -#define ALIAS_TOP_CLIP 0x0002 -#define ALIAS_RIGHT_CLIP 0x0004 -#define ALIAS_BOTTOM_CLIP 0x0008 -#define ALIAS_Z_CLIP 0x0010 -#define ALIAS_XY_CLIP_MASK 0x000F +#define ALIAS_LEFT_CLIP 0x0001 +#define ALIAS_TOP_CLIP 0x0002 +#define ALIAS_RIGHT_CLIP 0x0004 +#define ALIAS_BOTTOM_CLIP 0x0008 +#define ALIAS_Z_CLIP 0x0010 +#define ALIAS_XY_CLIP_MASK 0x000F -#define SURFCACHE_SIZE_AT_320X240 1024*768 +#define SURFCACHE_SIZE_AT_320X240 1024 * 768 -#define BMODEL_FULLY_CLIPPED 0x10 // value returned by R_BmodelCheckBBox () - // if bbox is trivially rejected +#define BMODEL_FULLY_CLIPPED 0x10 // value returned by R_BmodelCheckBBox () +// if bbox is trivially rejected -#define XCENTERING (1.0f / 2.0f) -#define YCENTERING (1.0f / 2.0f) +#define XCENTERING ( 1.0f / 2.0f ) +#define YCENTERING ( 1.0f / 2.0f ) -#define CLIP_EPSILON 0.001f +#define CLIP_EPSILON 0.001f // !!! if this is changed, it must be changed in asm_draw.h too !!! -#define NEAR_CLIP 0.01f +#define NEAR_CLIP 0.01f -//#define MAXALIASVERTS 2000 // TODO: tune this -#define ALIAS_Z_CLIP_PLANE 4 +// #define MAXALIASVERTS 2000 // TODO: tune this +#define ALIAS_Z_CLIP_PLANE 4 // turbulence stuff -#define AMP 8*0x10000 -#define AMP2 3 -#define SPEED 20 +#define AMP 8 * 0x10000 +#define AMP2 3 +#define SPEED 20 /* @@ -744,9 +745,9 @@ TYPES typedef struct { - float u, v; - float s, t; - float zi; + float u, v; + float s, t; + float zi; } emitpoint_t; /* @@ -757,19 +758,20 @@ typedef struct #if SMALL_FINALVERT -typedef struct finalvert_s { - short u, v, s, t; - int l; - int zi; - int flags; - float xyz[3]; // eye space +typedef struct finalvert_s +{ + short u, v, s, t; + int l; + int zi; + int flags; + float xyz[3]; // eye space } finalvert_t; -#define FINALVERT_V0 0 -#define FINALVERT_V1 2 -#define FINALVERT_V2 4 -#define FINALVERT_V3 6 -#define FINALVERT_V4 8 +#define FINALVERT_V0 0 +#define FINALVERT_V1 2 +#define FINALVERT_V2 4 +#define FINALVERT_V3 6 +#define FINALVERT_V4 8 #define FINALVERT_V5 12 #define FINALVERT_FLAGS 16 #define FINALVERT_X 20 @@ -779,17 +781,18 @@ typedef struct finalvert_s { #else -typedef struct finalvert_s { - int u, v, s, t; - int l; - int zi; - int flags; - float xyz[3]; // eye space +typedef struct finalvert_s +{ + int u, v, s, t; + int l; + int zi; + int flags; + float xyz[3]; // eye space } finalvert_t; -#define FINALVERT_V0 0 -#define FINALVERT_V1 4 -#define FINALVERT_V2 8 +#define FINALVERT_V0 0 +#define FINALVERT_V1 4 +#define FINALVERT_V2 8 #define FINALVERT_V3 12 #define FINALVERT_V4 16 #define FINALVERT_V5 20 @@ -804,20 +807,20 @@ typedef struct finalvert_s { typedef struct { - short s; - short t; + short s; + short t; } dstvert_t; typedef struct { - short index_xyz[3]; - short index_st[3]; + short index_xyz[3]; + short index_st[3]; } dtriangle_t; typedef struct { - byte v[3]; // scaled byte to fit in frame mins/maxs - byte lightnormalindex; + byte v[3]; // scaled byte to fit in frame mins/maxs + byte lightnormalindex; } dtrivertx_t; #define DTRIVERTX_V0 0 @@ -828,73 +831,73 @@ typedef struct typedef struct { - void *pskin; - int pskindesc; - int skinwidth; - int skinheight; - dtriangle_t *ptriangles; - finalvert_t *pfinalverts; - int numtriangles; - int drawtype; - int seamfixupX16; - qboolean do_vis_thresh; - int vis_thresh; + void *pskin; + int pskindesc; + int skinwidth; + int skinheight; + dtriangle_t *ptriangles; + finalvert_t *pfinalverts; + int numtriangles; + int drawtype; + int seamfixupX16; + qboolean do_vis_thresh; + int vis_thresh; } affinetridesc_t; typedef struct { - pixel_t *surfdat; // destination for generated surface - int rowbytes; // destination logical width in bytes - msurface_t *surf; // description for surface to generate - fixed8_t lightadj[MAXLIGHTMAPS]; - // adjust for lightmap levels for dynamic lighting - image_t *image; - int surfmip; // mipmapped ratio of surface texels / world pixels - int surfwidth; // in mipmapped texels - int surfheight; // in mipmapped texels + pixel_t *surfdat; // destination for generated surface + int rowbytes; // destination logical width in bytes + msurface_t *surf; // description for surface to generate + fixed8_t lightadj[MAXLIGHTMAPS]; + // adjust for lightmap levels for dynamic lighting + image_t *image; + int surfmip; // mipmapped ratio of surface texels / world pixels + int surfwidth; // in mipmapped texels + int surfheight; // in mipmapped texels } drawsurf_t; // clipped bmodel edges typedef struct bedge_s { - mvertex_t *v[2]; - struct bedge_s *pnext; + mvertex_t *v[2]; + struct bedge_s *pnext; } bedge_t; // !!! if this is changed, it must be changed in asm_draw.h too !!! typedef struct clipplane_s { - vec3_t normal; - float dist; - struct clipplane_s *next; - byte leftedge; - byte rightedge; - byte reserved[2]; + vec3_t normal; + float dist; + struct clipplane_s *next; + byte leftedge; + byte rightedge; + byte reserved[2]; } clipplane_t; typedef struct surfcache_s { - struct surfcache_s *next; - struct surfcache_s **owner; // NULL is an empty chunk of memory - int lightadj[MAXLIGHTMAPS]; // checked for strobe flush - int dlight; - int size; // including header - unsigned width; - unsigned height; // DEBUG only needed for debug - float mipscale; - image_t *image; - byte data[4]; // width*height elements + struct surfcache_s *next; + struct surfcache_s **owner; // NULL is an empty chunk of memory + int lightadj[MAXLIGHTMAPS]; // checked for strobe flush + int dlight; + int size; // including header + unsigned width; + unsigned height; // DEBUG only needed for debug + float mipscale; + image_t *image; + byte data[4]; // width*height elements } surfcache_t; // !!! if this is changed, it must be changed in asm_draw.h too !!! typedef struct espan_s { - int u, v, count; - struct espan_s *pnext; + int u, v, count; + struct espan_s *pnext; } espan_t; @@ -902,35 +905,35 @@ typedef struct espan_s // insubmodel is only 1, flags is fewer than 32, spanstate could be a byte typedef struct surf_s { - struct surf_s *next; // active surface stack in r_edge.c - struct surf_s *prev; // used in r_edge.c for active surf stack - struct espan_s *spans; // pointer to linked list of spans to draw - int key; // sorting key (BSP order) - int last_u; // set during tracing - int spanstate; // 0 = not in span - // 1 = in span - // -1 = in inverted span (end before - // start) - int flags; // currentface flags - msurface_t *msurf; - cl_entity_t *entity; - float nearzi; // nearest 1/z on surface, for mipmapping - qboolean insubmodel; - float d_ziorigin, d_zistepu, d_zistepv; + struct surf_s *next; // active surface stack in r_edge.c + struct surf_s *prev; // used in r_edge.c for active surf stack + struct espan_s *spans; // pointer to linked list of spans to draw + int key; // sorting key (BSP order) + int last_u; // set during tracing + int spanstate; // 0 = not in span + // 1 = in span + // -1 = in inverted span (end before + // start) + int flags; // currentface flags + msurface_t *msurf; + cl_entity_t *entity; + float nearzi; // nearest 1/z on surface, for mipmapping + qboolean insubmodel; + float d_ziorigin, d_zistepu, d_zistepv; - int pad[2]; // to 64 bytes + int pad[2]; // to 64 bytes } surf_t; // !!! if this is changed, it must be changed in asm_draw.h too !!! typedef struct edge_s { - fixed16_t u; - fixed16_t u_step; - struct edge_s *prev, *next; - unsigned short surfs[2]; - struct edge_s *nextremove; - float nearzi; - medge_t *owner; + fixed16_t u; + fixed16_t u_step; + struct edge_s *prev, *next; + unsigned short surfs[2]; + struct edge_s *nextremove; + float nearzi; + medge_t *owner; } edge_t; @@ -940,78 +943,78 @@ VARS ==================================================== */ - // started -extern float r_aliasuvscale; // scale-up factor for screen u and v - // on Alias vertices passed to driver +// started +extern float r_aliasuvscale; // scale-up factor for screen u and v +// on Alias vertices passed to driver -extern affinetridesc_t r_affinetridesc; +extern affinetridesc_t r_affinetridesc; -void D_DrawSurfaces (void); +void D_DrawSurfaces( void ); void R_DrawParticle( void ); -void D_ViewChanged (void); +void D_ViewChanged( void ); -//=======================================================================// +// =======================================================================// // callbacks to Quake -extern drawsurf_t r_drawsurf; +extern drawsurf_t r_drawsurf; -void R_DrawSurface (void); +void R_DrawSurface( void ); -//extern int c_surf; +// extern int c_surf; -extern byte r_warpbuffer[WARP_WIDTH * WARP_HEIGHT]; +extern byte r_warpbuffer[WARP_WIDTH * WARP_HEIGHT]; -extern float scale_for_mip; +extern float scale_for_mip; -extern qboolean d_roverwrapped; -extern surfcache_t *sc_rover; -extern surfcache_t *d_initial_rover; +extern qboolean d_roverwrapped; +extern surfcache_t *sc_rover; +extern surfcache_t *d_initial_rover; -extern float d_sdivzstepu, d_tdivzstepu, d_zistepu; -extern float d_sdivzstepv, d_tdivzstepv, d_zistepv; -extern float d_sdivzorigin, d_tdivzorigin, d_ziorigin; +extern float d_sdivzstepu, d_tdivzstepu, d_zistepu; +extern float d_sdivzstepv, d_tdivzstepv, d_zistepv; +extern float d_sdivzorigin, d_tdivzorigin, d_ziorigin; -extern fixed16_t sadjust, tadjust; -extern fixed16_t bbextents, bbextentt; +extern fixed16_t sadjust, tadjust; +extern fixed16_t bbextents, bbextentt; -void D_DrawSpans16 (espan_t *pspans); -void D_DrawZSpans (espan_t *pspans); -void Turbulent8 (espan_t *pspan); -void NonTurbulent8 (espan_t *pspan); //PGM +void D_DrawSpans16( espan_t *pspans ); +void D_DrawZSpans( espan_t *pspans ); +void Turbulent8( espan_t *pspan ); +void NonTurbulent8( espan_t *pspan ); // PGM void D_BlendSpans16( espan_t *pspan, int alpha ); void D_AlphaSpans16( espan_t *pspan ); void D_AddSpans16( espan_t *pspan ); void TurbulentZ8( espan_t *pspan, int alpha ); -surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel); +surfcache_t *D_CacheSurface( msurface_t *surface, int miplevel ); -extern pixel_t *d_viewbuffer; -extern short *d_pzbuffer; +extern pixel_t *d_viewbuffer; +extern short *d_pzbuffer; extern unsigned int d_zrowbytes, d_zwidth; -extern short *zspantable[MAXHEIGHT]; -extern int d_scantable[MAXHEIGHT]; +extern short *zspantable[MAXHEIGHT]; +extern int d_scantable[MAXHEIGHT]; -extern int d_minmip; -extern float d_scalemip[3]; +extern int d_minmip; +extern float d_scalemip[3]; -//=================================================================== +// =================================================================== -extern int cachewidth; -extern pixel_t *cacheblock; -extern int r_screenwidth; +extern int cachewidth; +extern pixel_t *cacheblock; +extern int r_screenwidth; -extern int sintable[1280]; -extern int intsintable[1280]; -extern int blanktable[1280]; // PGM +extern int sintable[1280]; +extern int intsintable[1280]; +extern int blanktable[1280]; // PGM -extern surf_t *surfaces, *surface_p, *surf_max; +extern surf_t *surfaces, *surface_p, *surf_max; // surfaces are generated in back to front order by the bsp, so if a surf // pointer is greater than another one, it should be drawn in front @@ -1019,66 +1022,67 @@ extern surf_t *surfaces, *surface_p, *surf_max; // surfaces[0] is a dummy, because index 0 is used to indicate no surface // attached to an edge_t -//=================================================================== +// =================================================================== -//extern vec3_t sxformaxis[4]; // s axis transformed into viewspace -//extern vec3_t txformaxis[4]; // t axis transformed into viewspac +// extern vec3_t sxformaxis[4]; // s axis transformed into viewspace +// extern vec3_t txformaxis[4]; // t axis transformed into viewspac -extern float xcenter, ycenter; -extern float xscale, yscale; -extern float xscaleinv, yscaleinv; -//extern float xscaleshrink, yscaleshrink; +extern float xcenter, ycenter; +extern float xscale, yscale; +extern float xscaleinv, yscaleinv; +// extern float xscaleshrink, yscaleshrink; -extern edge_t *auxedges; -extern int r_numallocatededges; -extern edge_t *r_edges, *edge_p, *edge_max; +extern edge_t *auxedges; +extern int r_numallocatededges; +extern edge_t *r_edges, *edge_p, *edge_max; -extern edge_t *newedges[MAXHEIGHT]; -extern edge_t *removeedges[MAXHEIGHT]; +extern edge_t *newedges[MAXHEIGHT]; +extern edge_t *removeedges[MAXHEIGHT]; -extern int r_viewcluster, r_oldviewcluster; +extern int r_viewcluster, r_oldviewcluster; -extern int r_clipflags; -//extern qboolean r_fov_greater_than_90; +extern int r_clipflags; +// extern qboolean r_fov_greater_than_90; -extern convar_t sw_clearcolor; -extern convar_t sw_drawflat; -extern convar_t sw_draworder; -extern convar_t sw_maxedges; -extern convar_t sw_mipcap; -extern convar_t sw_mipscale; -extern convar_t sw_surfcacheoverride; -extern convar_t sw_texfilt; -extern convar_t r_traceglow; -extern convar_t sw_noalphabrushes; -extern convar_t r_studio_sort_textures; +extern convar_t sw_clearcolor; +extern convar_t sw_drawflat; +extern convar_t sw_draworder; +extern convar_t sw_maxedges; +extern convar_t sw_mipcap; +extern convar_t sw_mipscale; +extern convar_t sw_surfcacheoverride; +extern convar_t sw_texfilt; +extern convar_t r_traceglow; +extern convar_t sw_noalphabrushes; +extern convar_t r_studio_sort_textures; -extern struct qfrustum_s { - mplane_t screenedge[4]; - clipplane_t view_clipplanes[4]; - int frustum_indexes[4*6]; - int *pfrustum_indexes[4]; +extern struct qfrustum_s +{ + mplane_t screenedge[4]; + clipplane_t view_clipplanes[4]; + int frustum_indexes[4 * 6]; + int *pfrustum_indexes[4]; } qfrustum; -#define CACHESPOT(surf) ((surfcache_t**)surf->info->reserved) -extern int r_currentkey; -extern int r_currentbkey; -extern qboolean insubmodel; +#define CACHESPOT( surf ) ((surfcache_t **)surf->info->reserved ) +extern int r_currentkey; +extern int r_currentbkey; +extern qboolean insubmodel; -extern vec3_t r_entorigin; +extern vec3_t r_entorigin; #if XASH_LOW_MEMORY extern unsigned short r_leafkeys[MAX_MAP_LEAFS]; #else -extern int r_leafkeys[MAX_MAP_LEAFS]; +extern int r_leafkeys[MAX_MAP_LEAFS]; #endif -#define LEAF_KEY(pleaf) r_leafkeys[(pleaf - WORLDMODEL->leafs)] +#define LEAF_KEY( pleaf ) r_leafkeys[( pleaf - WORLDMODEL->leafs )] -extern mvertex_t *r_pcurrentvertbase; -//extern int r_maxvalidedgeoffset; +extern mvertex_t *r_pcurrentvertbase; +// extern int r_maxvalidedgeoffset; typedef struct { @@ -1088,27 +1092,27 @@ typedef struct extern aliastriangleparms_t aliastriangleparms; -extern int r_aliasblendcolor; +extern int r_aliasblendcolor; -extern float aliasxscale, aliasyscale, aliasxcenter, aliasycenter; -extern float s_ziscale; +extern float aliasxscale, aliasyscale, aliasxcenter, aliasycenter; +extern float s_ziscale; void R_DrawTriangle( void ); -//void R_DrawTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2); -void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2); +// void R_DrawTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2); +void R_AliasClipTriangle( finalvert_t *index0, finalvert_t *index1, finalvert_t *index2 ); // // r_bsp.c // -void R_RotateBmodel (void); -void R_DrawSolidClippedSubmodelPolygons (model_t *pmodel, mnode_t *topnode); -void R_DrawSubmodelPolygons (model_t *pmodel, int clipflags, mnode_t *topnode); -void R_DrawBrushModel(cl_entity_t *pent); +void R_RotateBmodel( void ); +void R_DrawSolidClippedSubmodelPolygons( model_t *pmodel, mnode_t *topnode ); +void R_DrawSubmodelPolygons( model_t *pmodel, int clipflags, mnode_t *topnode ); +void R_DrawBrushModel( cl_entity_t *pent ); // // r_blitscreen.c // -void R_InitCaches (void); +void R_InitCaches( void ); void R_BlitScreen( void ); qboolean R_InitBlit( qboolean gl ); qboolean R_SetDisplayTransform( ref_screen_rotation_t rotate, int offset_x, int offset_y, float scale_x, float scale_y ); @@ -1116,10 +1120,11 @@ qboolean R_SetDisplayTransform( ref_screen_rotation_t rotate, int offset_x, int // // r_edge.c // -static inline void R_SurfacePatch (void) { } -void R_BeginEdgeFrame (void); -void R_RenderWorld (void); -void R_ScanEdges (void); +static inline void R_SurfacePatch( void ) { +} +void R_BeginEdgeFrame( void ); +void R_RenderWorld( void ); +void R_ScanEdges( void ); // @@ -1131,40 +1136,40 @@ void D_FlushCaches( void ); // // r_draw.c // -void Draw_Fill (int x, int y, int w, int h); +void Draw_Fill( int x, int y, int w, int h ); // // r_misc.c // -void R_SetupFrameQ (void); -void R_TransformFrustum (void); -void TransformVector (vec3_t in, vec3_t out); +void R_SetupFrameQ( void ); +void R_TransformFrustum( void ); +void TransformVector( vec3_t in, vec3_t out ); // // r_rast.c // -void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf); -void R_RenderFace (msurface_t *fa, int clipflags); +void R_RenderBmodelFace( bedge_t *pedges, msurface_t *psurf ); +void R_RenderFace( msurface_t *fa, int clipflags ); // // r_main.c // -void R_RenderTriangle( finalvert_t *fv1 , finalvert_t *fv2, finalvert_t *fv3 ); +void R_RenderTriangle( finalvert_t *fv1, finalvert_t *fv2, finalvert_t *fv3 ); void R_SetupFinalVert( finalvert_t *fv, float x, float y, float z, int light, int s, int t ); -void RotatedBBox (vec3_t mins, vec3_t maxs, vec3_t angles, vec3_t tmins, vec3_t tmaxs); -int R_BmodelCheckBBox (float *minmaxs); +void RotatedBBox( vec3_t mins, vec3_t maxs, vec3_t angles, vec3_t tmins, vec3_t tmaxs ); +int R_BmodelCheckBBox( float *minmaxs ); int CL_FxBlend( cl_entity_t *e ); -void R_SetUpWorldTransform (void); +void R_SetUpWorldTransform( void ); -#define BLEND_ALPHA_LOW(alpha, src, screen) (vid.alphamap[((alpha) << 18) | (((src) & 0xff00) << 2) | ((screen) >> 6)] | ((screen) & 0x3f)) -#define BLEND_ALPHA(alpha, src, dst) (alpha) > 3?BLEND_ALPHA_LOW(7 - 1 - (alpha), (dst), (src)) : BLEND_ALPHA_LOW((alpha)-1, (src), (dst)) -#define BLEND_ADD(src, screen) vid.addmap[((src)& 0xff00)|((screen)>>8)] << 8 | ((screen) & 0xff) | (((src) & 0xff) >> 0); -#define BLEND_COLOR(src, color) vid.modmap[((src) & 0xff00)|((color)>>8)] << 8 | ((src) & (color) & 0xff) | (((src) & 0xff) >> 3); +#define BLEND_ALPHA_LOW( alpha, src, screen ) ( vid.alphamap[(( alpha ) << 18 ) | ((( src ) & 0xff00 ) << 2 ) | (( screen ) >> 6 )] | (( screen ) & 0x3f )) +#define BLEND_ALPHA( alpha, src, dst ) ( alpha ) > 3 ? BLEND_ALPHA_LOW( 7 - 1 - ( alpha ), ( dst ), ( src )) : BLEND_ALPHA_LOW(( alpha ) - 1, ( src ), ( dst )) +#define BLEND_ADD( src, screen ) vid.addmap[(( src ) & 0xff00 ) | (( screen ) >> 8 )] << 8 | (( screen ) & 0xff ) | ((( src ) & 0xff ) >> 0 ); +#define BLEND_COLOR( src, color ) vid.modmap[(( src ) & 0xff00 ) | (( color ) >> 8 )] << 8 | (( src ) & ( color ) & 0xff ) | ((( src ) & 0xff ) >> 3 ); -#define LM_SAMPLE_SIZE_AUTO(surf) (tr.sample_size == -1?gEngfuncs.Mod_SampleSizeForFace( surf ): tr.sample_size) +#define LM_SAMPLE_SIZE_AUTO( surf ) ( tr.sample_size == -1 ? gEngfuncs.Mod_SampleSizeForFace( surf ) : tr.sample_size ) @@ -1175,14 +1180,14 @@ void R_SetUpWorldTransform (void); #include "crclib.h" void _Mem_Free( void *data, const char *filename, int fileline ); void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) - ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT; +ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT; -#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ ) -#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ ) +#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ ) +#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ ) #define Mem_Realloc( pool, ptr, size ) gEngfuncs._Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ ) -#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ ) -#define Mem_AllocPool( name ) gEngfuncs._Mem_AllocPool( name, __FILE__, __LINE__ ) -#define Mem_FreePool( pool ) gEngfuncs._Mem_FreePool( pool, __FILE__, __LINE__ ) -#define Mem_EmptyPool( pool ) gEngfuncs._Mem_EmptyPool( pool, __FILE__, __LINE__ ) +#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ ) +#define Mem_AllocPool( name ) gEngfuncs._Mem_AllocPool( name, __FILE__, __LINE__ ) +#define Mem_FreePool( pool ) gEngfuncs._Mem_FreePool( pool, __FILE__, __LINE__ ) +#define Mem_EmptyPool( pool ) gEngfuncs._Mem_EmptyPool( pool, __FILE__, __LINE__ ) #endif // GL_LOCAL_H diff --git a/ref/soft/r_main.c b/ref/soft/r_main.c index b380622e..dd1c6c3f 100644 --- a/ref/soft/r_main.c +++ b/ref/soft/r_main.c @@ -16,14 +16,14 @@ GNU General Public License for more details. #include "r_local.h" #include "xash3d_mathlib.h" #include "library.h" -//#include "beamdef.h" -//#include "particledef.h" +// #include "beamdef.h" +// #include "particledef.h" #include "entity_types.h" #include "mod_local.h" int r_cnumsurfs; -#define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA ) +#define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA ) -ref_instance_t RI; +ref_instance_t RI; // quake defines. will be refactored @@ -34,13 +34,13 @@ ref_instance_t RI; // // screen size info // -float xcenter, ycenter; -float xscale, yscale; -float xscaleinv, yscaleinv; -//float xscaleshrink, yscaleshrink; -float aliasxscale, aliasyscale, aliasxcenter, aliasycenter; +float xcenter, ycenter; +float xscale, yscale; +float xscaleinv, yscaleinv; +// float xscaleshrink, yscaleshrink; +float aliasxscale, aliasyscale, aliasxcenter, aliasycenter; -int r_screenwidth; +int r_screenwidth; @@ -49,66 +49,66 @@ int r_screenwidth; // refresh flags // -//int d_spanpixcount; -//int r_polycount; -//int r_drawnpolycount; -//int r_wholepolycount; +// int d_spanpixcount; +// int r_polycount; +// int r_drawnpolycount; +// int r_wholepolycount; -int r_viewcluster, r_oldviewcluster; +int r_viewcluster, r_oldviewcluster; -CVAR_DEFINE_AUTO( sw_clearcolor, "48999", 0, "screen clear color"); -CVAR_DEFINE_AUTO( sw_drawflat, "0", FCVAR_CHEAT, ""); -CVAR_DEFINE_AUTO( sw_draworder, "0", FCVAR_CHEAT, ""); -CVAR_DEFINE_AUTO( sw_maxedges, "32", 0, ""); -static CVAR_DEFINE_AUTO( sw_maxsurfs, "0", 0, ""); -CVAR_DEFINE_AUTO( sw_mipscale, "1", FCVAR_GLCONFIG, "nothing"); +CVAR_DEFINE_AUTO( sw_clearcolor, "48999", 0, "screen clear color" ); +CVAR_DEFINE_AUTO( sw_drawflat, "0", FCVAR_CHEAT, "" ); +CVAR_DEFINE_AUTO( sw_draworder, "0", FCVAR_CHEAT, "" ); +CVAR_DEFINE_AUTO( sw_maxedges, "32", 0, "" ); +static CVAR_DEFINE_AUTO( sw_maxsurfs, "0", 0, "" ); +CVAR_DEFINE_AUTO( sw_mipscale, "1", FCVAR_GLCONFIG, "nothing" ); CVAR_DEFINE_AUTO( sw_mipcap, "0", FCVAR_GLCONFIG, "nothing" ); -CVAR_DEFINE_AUTO( sw_surfcacheoverride, "0", 0, ""); -static CVAR_DEFINE_AUTO( sw_waterwarp, "1", FCVAR_GLCONFIG, "nothing"); -static CVAR_DEFINE_AUTO( sw_notransbrushes, "0", FCVAR_GLCONFIG, "do not apply transparency to water/glasses (faster)"); -CVAR_DEFINE_AUTO( sw_noalphabrushes, "0", FCVAR_GLCONFIG, "do not draw brush holes (faster)"); +CVAR_DEFINE_AUTO( sw_surfcacheoverride, "0", 0, "" ); +static CVAR_DEFINE_AUTO( sw_waterwarp, "1", FCVAR_GLCONFIG, "nothing" ); +static CVAR_DEFINE_AUTO( sw_notransbrushes, "0", FCVAR_GLCONFIG, "do not apply transparency to water/glasses (faster)" ); +CVAR_DEFINE_AUTO( sw_noalphabrushes, "0", FCVAR_GLCONFIG, "do not draw brush holes (faster)" ); CVAR_DEFINE_AUTO( r_traceglow, "0", FCVAR_GLCONFIG, "cull flares behind models" ); -CVAR_DEFINE_AUTO( sw_texfilt, "0", FCVAR_GLCONFIG, "texture dither"); +CVAR_DEFINE_AUTO( sw_texfilt, "0", FCVAR_GLCONFIG, "texture dither" ); static CVAR_DEFINE_AUTO( r_novis, "0", 0, "" ); DEFINE_ENGINE_SHARED_CVAR_LIST() -int r_viewcluster, r_oldviewcluster; +int r_viewcluster, r_oldviewcluster; -float d_sdivzstepu, d_tdivzstepu, d_zistepu; -float d_sdivzstepv, d_tdivzstepv, d_zistepv; -float d_sdivzorigin, d_tdivzorigin, d_ziorigin; +float d_sdivzstepu, d_tdivzstepu, d_zistepu; +float d_sdivzstepv, d_tdivzstepv, d_zistepv; +float d_sdivzorigin, d_tdivzorigin, d_ziorigin; -fixed16_t sadjust, tadjust, bbextents, bbextentt; +fixed16_t sadjust, tadjust, bbextents, bbextentt; -pixel_t *cacheblock; -int cachewidth; -pixel_t *d_viewbuffer; -short *d_pzbuffer; -unsigned int d_zrowbytes; -unsigned int d_zwidth; +pixel_t *cacheblock; +int cachewidth; +pixel_t *d_viewbuffer; +short *d_pzbuffer; +unsigned int d_zrowbytes; +unsigned int d_zwidth; -mvertex_t *r_pcurrentvertbase; +mvertex_t *r_pcurrentvertbase; -//int c_surf; -qboolean r_surfsonstack; -int r_clipflags; -byte r_warpbuffer[WARP_WIDTH * WARP_HEIGHT]; -int r_numallocatededges; +// int c_surf; +qboolean r_surfsonstack; +int r_clipflags; +byte r_warpbuffer[WARP_WIDTH * WARP_HEIGHT]; +int r_numallocatededges; -float r_aliasuvscale = 1.0; +float r_aliasuvscale = 1.0; static int R_RankForRenderMode( int rendermode ) { switch( rendermode ) { case kRenderTransTexture: - return 1; // draw second + return 1; // draw second case kRenderTransAdd: - return 2; // draw third + return 2; // draw third case kRenderGlow: - return 3; // must be last! + return 3; // must be last! } return 0; } @@ -158,11 +158,11 @@ Sorting translucent entities by rendermode then by distance */ static int R_TransEntityCompare( const cl_entity_t **a, const cl_entity_t **b ) { - cl_entity_t *ent1, *ent2; - vec3_t vecLen, org; - float dist1, dist2; - int rendermode1; - int rendermode2; + cl_entity_t *ent1, *ent2; + vec3_t vecLen, org; + float dist1, dist2; + int rendermode1; + int rendermode2; ent1 = (cl_entity_t *)*a; ent2 = (cl_entity_t *)*b; @@ -170,23 +170,25 @@ static int R_TransEntityCompare( const cl_entity_t **a, const cl_entity_t **b ) rendermode2 = R_GetEntityRenderMode( ent2 ); // sort by distance - if( ( ent1->model && ent1->model->type != mod_brush ) || rendermode1 != kRenderTransAlpha ) + if(( ent1->model && ent1->model->type != mod_brush ) || rendermode1 != kRenderTransAlpha ) { VectorAverage( ent1->model->mins, ent1->model->maxs, org ); VectorAdd( ent1->origin, org, org ); VectorSubtract( RI.vieworg, org, vecLen ); dist1 = DotProduct( vecLen, vecLen ); } - else dist1 = 1000000000; + else + dist1 = 1000000000; - if( ( ent1->model && ent2->model->type != mod_brush ) || rendermode2 != kRenderTransAlpha ) + if(( ent1->model && ent2->model->type != mod_brush ) || rendermode2 != kRenderTransAlpha ) { VectorAverage( ent2->model->mins, ent2->model->maxs, org ); VectorAdd( ent2->origin, org, org ); VectorSubtract( RI.vieworg, org, vecLen ); dist2 = DotProduct( vecLen, vecLen ); } - else dist2 = 1000000000; + else + dist2 = 1000000000; if( dist1 > dist2 ) return -1; @@ -212,9 +214,9 @@ Returns true if we behind to screen */ int R_WorldToScreen( const vec3_t point, vec3_t screen ) { - matrix4x4 worldToScreen; - qboolean behind; - float w; + matrix4x4 worldToScreen; + qboolean behind; + float w; if( !point || !screen ) return true; @@ -249,8 +251,8 @@ Convert a given point from screen into world space */ void GAME_EXPORT R_ScreenToWorld( const vec3_t screen, vec3_t point ) { - matrix4x4 screenToWorld; - float w; + matrix4x4 screenToWorld; + float w; if( !point || !screen ) return; @@ -261,7 +263,8 @@ void GAME_EXPORT R_ScreenToWorld( const vec3_t screen, vec3_t point ) point[1] = screen[0] * screenToWorld[1][0] + screen[1] * screenToWorld[1][1] + screen[2] * screenToWorld[1][2] + screenToWorld[1][3]; point[2] = screen[0] * screenToWorld[2][0] + screen[1] * screenToWorld[2][1] + screen[2] * screenToWorld[2][2] + screenToWorld[2][3]; w = screen[0] * screenToWorld[3][0] + screen[1] * screenToWorld[3][1] + screen[2] * screenToWorld[3][2] + screenToWorld[3][3]; - if( w != 0.0f ) VectorScale( point, ( 1.0f / w ), point ); + if( w != 0.0f ) + VectorScale( point, ( 1.0f / w ), point ); } /* @@ -367,10 +370,10 @@ R_Clear */ static void R_Clear( int bitMask ) { - memset( vid.buffer, 0, vid.width * vid.height *2); + memset( vid.buffer, 0, vid.width * vid.height * 2 ); } -//============================================================================= +// ============================================================================= /* =============== R_GetFarClip @@ -408,7 +411,7 @@ R_SetupProjectionMatrix */ static void R_SetupProjectionMatrix( matrix4x4 m ) { - float xMin, xMax, yMin, yMax, zNear, zFar; + float xMin, xMax, yMin, yMax, zNear, zFar; if( RI.drawOrtho ) { @@ -496,7 +499,7 @@ static void R_SetupFrame( void ) // if( !gl_nosort->value ) { // sort translucents entities by rendermode and distance - qsort( tr.draw_list->trans_entities, tr.draw_list->num_trans_entities, sizeof( cl_entity_t* ), (void*)R_TransEntityCompare ); + qsort( tr.draw_list->trans_entities, tr.draw_list->num_trans_entities, sizeof( cl_entity_t * ), (void *)R_TransEntityCompare ); } // current viewleaf @@ -533,13 +536,13 @@ static image_t *R_RecursiveFindWaterTexture( const mnode_t *node, const mnode_t if( node->contents < 0 ) { - mleaf_t *pleaf; - msurface_t **mark; - int i, c; + mleaf_t *pleaf; + msurface_t **mark; + int i, c; // ignore non-liquid leaves if( node->contents != CONTENTS_WATER && node->contents != CONTENTS_LAVA && node->contents != CONTENTS_SLIME ) - return NULL; + return NULL; // find texture pleaf = (mleaf_t *)node; @@ -548,8 +551,8 @@ static image_t *R_RecursiveFindWaterTexture( const mnode_t *node, const mnode_t for( i = 0; i < c; i++, mark++ ) { - if( (*mark)->flags & SURF_DRAWTURB && (*mark)->texinfo && (*mark)->texinfo->texture ) - return R_GetTexture( (*mark)->texinfo->texture->gl_texturenum ); + if(( *mark )->flags & SURF_DRAWTURB && ( *mark )->texinfo && ( *mark )->texinfo->texture ) + return R_GetTexture(( *mark )->texinfo->texture->gl_texturenum ); } // texture not found @@ -561,17 +564,20 @@ static image_t *R_RecursiveFindWaterTexture( const mnode_t *node, const mnode_t if( node->children[0] && ( node->children[0] != ignore )) { tex = R_RecursiveFindWaterTexture( node->children[0], node, true ); - if( tex ) return tex; + if( tex ) + return tex; } if( node->children[1] && ( node->children[1] != ignore )) { tex = R_RecursiveFindWaterTexture( node->children[1], node, true ); - if( tex ) return tex; + if( tex ) + return tex; } // for down recursion, return immediately - if( down ) return NULL; + if( down ) + return NULL; // texture not found, step up if any if( node->parent ) @@ -588,20 +594,20 @@ R_DrawEntitiesOnList */ static void R_DrawEntitiesOnList( void ) { - int i; - //extern int d_aflatcolor; - //d_aflatcolor = 0; + int i; + // extern int d_aflatcolor; + // d_aflatcolor = 0; tr.blend = 1.0f; // GL_CheckForErrors(); - //RI.currententity = CL_GetEntityByIndex(0); + // RI.currententity = CL_GetEntityByIndex(0); d_pdrawspans = R_PolysetFillSpans8; - GL_SetRenderMode(kRenderNormal); + GL_SetRenderMode( kRenderNormal ); // first draw solid entities for( i = 0; i < tr.draw_list->num_solid_entities && !RI.onlyClientDraw; i++ ) { RI.currententity = tr.draw_list->solid_entities[i]; RI.currentmodel = RI.currententity->model; - //d_aflatcolor += 500; + // d_aflatcolor += 500; Assert( RI.currententity != NULL ); Assert( RI.currentmodel != NULL ); @@ -612,7 +618,7 @@ static void R_DrawEntitiesOnList( void ) R_DrawBrushModel( RI.currententity ); break; case mod_alias: - //R_DrawAliasModel( RI.currententity ); + // R_DrawAliasModel( RI.currententity ); break; case mod_studio: R_SetUpWorldTransform(); @@ -659,9 +665,11 @@ static void R_DrawEntitiesOnList( void ) // handle studiomodels with custom rendermodes on texture if( RI.currententity->curstate.rendermode != kRenderNormal ) tr.blend = CL_FxBlend( RI.currententity ) / 255.0f; - else tr.blend = 1.0f; // draw as solid but sorted by distance + else + tr.blend = 1.0f; // draw as solid but sorted by distance - if( tr.blend <= 0.0f ) continue; + if( tr.blend <= 0.0f ) + continue; Assert( RI.currententity != NULL ); Assert( RI.currentmodel != NULL ); @@ -672,7 +680,7 @@ static void R_DrawEntitiesOnList( void ) R_DrawBrushModel( RI.currententity ); break; case mod_alias: - //R_DrawAliasModel( RI.currententity ); + // R_DrawAliasModel( RI.currententity ); break; case mod_studio: R_SetUpWorldTransform(); @@ -689,7 +697,7 @@ static void R_DrawEntitiesOnList( void ) if( RI.drawWorld ) { - gEngfuncs.pfnDrawTransparentTriangles (); + gEngfuncs.pfnDrawTransparentTriangles(); } if( !RI.onlyClientDraw ) @@ -699,7 +707,7 @@ static void R_DrawEntitiesOnList( void ) R_AllowFog( true ); } - GL_SetRenderMode(kRenderNormal); + GL_SetRenderMode( kRenderNormal ); R_SetUpWorldTransform(); if( !RI.onlyClientDraw ) R_DrawViewModel(); @@ -714,19 +722,19 @@ qboolean insubmodel; R_BmodelCheckBBox ============= */ -int R_BmodelCheckBBox (float *minmaxs) +int R_BmodelCheckBBox( float *minmaxs ) { - int i, *pindex, clipflags; - vec3_t acceptpt, rejectpt; - float d; + int i, *pindex, clipflags; + vec3_t acceptpt, rejectpt; + float d; clipflags = 0; - for (i=0 ; i<4 ; i++) + for( i = 0; i < 4; i++ ) { - // generate accept and reject points - // FIXME: do with fast look-ups or integer tests based on the sign bit - // of the floating point values + // generate accept and reject points + // FIXME: do with fast look-ups or integer tests based on the sign bit + // of the floating point values pindex = qfrustum.pfrustum_indexes[i]; @@ -734,21 +742,21 @@ int R_BmodelCheckBBox (float *minmaxs) rejectpt[1] = minmaxs[pindex[1]]; rejectpt[2] = minmaxs[pindex[2]]; - d = DotProduct (rejectpt, qfrustum.view_clipplanes[i].normal); + d = DotProduct( rejectpt, qfrustum.view_clipplanes[i].normal ); d -= qfrustum.view_clipplanes[i].dist; - if (d <= 0) + if( d <= 0 ) return BMODEL_FULLY_CLIPPED; - acceptpt[0] = minmaxs[pindex[3+0]]; - acceptpt[1] = minmaxs[pindex[3+1]]; - acceptpt[2] = minmaxs[pindex[3+2]]; + acceptpt[0] = minmaxs[pindex[3 + 0]]; + acceptpt[1] = minmaxs[pindex[3 + 1]]; + acceptpt[2] = minmaxs[pindex[3 + 2]]; - d = DotProduct (acceptpt, qfrustum.view_clipplanes[i].normal); + d = DotProduct( acceptpt, qfrustum.view_clipplanes[i].normal ); d -= qfrustum.view_clipplanes[i].dist; - if (d <= 0) - clipflags |= (1<nodes; + node = WORLDMODEL->nodes; - while (1) + while( 1 ) + { + if( node->visframe != tr.visframecount ) + return NULL; // not visible at all + + if( node->contents < 0 ) { - if (node->visframe != tr.visframecount) - return NULL; // not visible at all - - if (node->contents < 0) - { - if (node->contents != CONTENTS_SOLID) - return node; // we've reached a non-solid leaf, so it's - // visible and not BSP clipped - return NULL; // in solid, so not visible - } - - splitplane = node->plane; - sides = BOX_ON_PLANE_SIDE (mins, maxs, splitplane); - - if (sides == 3) - return node; // this is the splitter - - // not split yet; recurse down the contacted side - if (sides & 1) - node = node->children[0]; - else - node = node->children[1]; + if( node->contents != CONTENTS_SOLID ) + return node; // we've reached a non-solid leaf, so it's + // visible and not BSP clipped + return NULL; // in solid, so not visible } + + splitplane = node->plane; + sides = BOX_ON_PLANE_SIDE( mins, maxs, splitplane ); + + if( sides == 3 ) + return node; // this is the splitter + + // not split yet; recurse down the contacted side + if( sides & 1 ) + node = node->children[0]; + else + node = node->children[1]; + } } @@ -802,54 +810,54 @@ RotatedBBox Returns an axially aligned box that contains the input box at the given rotation ============= */ -void RotatedBBox (vec3_t mins, vec3_t maxs, vec3_t angles, vec3_t tmins, vec3_t tmaxs) +void RotatedBBox( vec3_t mins, vec3_t maxs, vec3_t angles, vec3_t tmins, vec3_t tmaxs ) { - vec3_t tmp, v; - int i, j; - vec3_t forward, right, up; + vec3_t tmp, v; + int i, j; + vec3_t forward, right, up; - if (!angles[0] && !angles[1] && !angles[2]) + if( !angles[0] && !angles[1] && !angles[2] ) { - VectorCopy (mins, tmins); - VectorCopy (maxs, tmaxs); + VectorCopy( mins, tmins ); + VectorCopy( maxs, tmaxs ); return; } - for (i=0 ; i<3 ; i++) + for( i = 0; i < 3; i++ ) { tmins[i] = 99999; tmaxs[i] = -99999; } - AngleVectors (angles, forward, right, up); + AngleVectors( angles, forward, right, up ); - for ( i = 0; i < 8; i++ ) + for( i = 0; i < 8; i++ ) { - if ( i & 1 ) + if( i & 1 ) tmp[0] = mins[0]; else tmp[0] = maxs[0]; - if ( i & 2 ) + if( i & 2 ) tmp[1] = mins[1]; else tmp[1] = maxs[1]; - if ( i & 4 ) + if( i & 4 ) tmp[2] = mins[2]; else tmp[2] = maxs[2]; - VectorScale (forward, tmp[0], v); - VectorMA (v, -tmp[1], right, v); - VectorMA (v, tmp[2], up, v); + VectorScale( forward, tmp[0], v ); + VectorMA( v, -tmp[1], right, v ); + VectorMA( v, tmp[2], up, v ); - for (j=0 ; j<3 ; j++) + for( j = 0; j < 3; j++ ) { - if (v[j] < tmins[j]) + if( v[j] < tmins[j] ) tmins[j] = v[j]; - if (v[j] > tmaxs[j]) + if( v[j] > tmaxs[j] ) tmaxs[j] = v[j]; } } @@ -861,15 +869,15 @@ void RotatedBBox (vec3_t mins, vec3_t maxs, vec3_t angles, vec3_t tmins, vec3_t R_DrawBEntitiesOnList ============= */ -static void R_DrawBEntitiesOnList (void) +static void R_DrawBEntitiesOnList( void ) { - int i, clipflags; - vec3_t oldorigin; - vec3_t mins, maxs; - float minmaxs[6]; - mnode_t *topnode; + int i, clipflags; + vec3_t oldorigin; + vec3_t mins, maxs; + float minmaxs[6]; + mnode_t *topnode; - VectorCopy (tr.modelorg, oldorigin); + VectorCopy( tr.modelorg, oldorigin ); insubmodel = true; for( i = 0; i < tr.draw_list->num_edge_entities && !RI.onlyClientDraw; i++ ) @@ -877,41 +885,41 @@ static void R_DrawBEntitiesOnList (void) int k; RI.currententity = tr.draw_list->edge_entities[i]; RI.currentmodel = RI.currententity->model; - if (!RI.currentmodel) + if( !RI.currentmodel ) continue; - if (RI.currentmodel->nummodelsurfaces == 0) - continue; // clip brush only - if (RI.currentmodel->type != mod_brush) + if( RI.currentmodel->nummodelsurfaces == 0 ) + continue; // clip brush only + if( RI.currentmodel->type != mod_brush ) continue; - // see if the bounding box lets us trivially reject, also sets - // trivial accept status - RotatedBBox (RI.currentmodel->mins, RI.currentmodel->maxs, - RI.currententity->angles, mins, maxs); - VectorAdd (mins, RI.currententity->origin, minmaxs); - VectorAdd (maxs, RI.currententity->origin, (minmaxs+3)); + // see if the bounding box lets us trivially reject, also sets + // trivial accept status + RotatedBBox( RI.currentmodel->mins, RI.currentmodel->maxs, + RI.currententity->angles, mins, maxs ); + VectorAdd( mins, RI.currententity->origin, minmaxs ); + VectorAdd( maxs, RI.currententity->origin, ( minmaxs + 3 )); - clipflags = R_BmodelCheckBBox (minmaxs); - if (clipflags == BMODEL_FULLY_CLIPPED) - continue; // off the edge of the screen - //clipflags = 0; + clipflags = R_BmodelCheckBBox( minmaxs ); + if( clipflags == BMODEL_FULLY_CLIPPED ) + continue; // off the edge of the screen + // clipflags = 0; - topnode = R_FindTopnode (minmaxs, minmaxs+3); - if (!topnode) - continue; // no part in a visible leaf + topnode = R_FindTopnode( minmaxs, minmaxs + 3 ); + if( !topnode ) + continue; // no part in a visible leaf - VectorCopy (RI.currententity->origin, r_entorigin); - VectorSubtract (RI.vieworg, r_entorigin, tr.modelorg); - //VectorSubtract (r_origin, RI.currententity->origin, modelorg); + VectorCopy( RI.currententity->origin, r_entorigin ); + VectorSubtract( RI.vieworg, r_entorigin, tr.modelorg ); + // VectorSubtract (r_origin, RI.currententity->origin, modelorg); r_pcurrentvertbase = RI.currentmodel->vertexes; - // FIXME: stop transforming twice - R_RotateBmodel (); + // FIXME: stop transforming twice + R_RotateBmodel(); // calculate dynamic lighting for bmodel for( k = 0; k < MAX_DLIGHTS; k++ ) { dlight_t *l = &tr.dlights[k]; - vec3_t origin_l, oldorigin; + vec3_t origin_l, oldorigin; if( l->die < gp_cl->time || !l->radius ) continue; @@ -920,33 +928,33 @@ static void R_DrawBEntitiesOnList (void) Matrix4x4_CreateFromEntity( RI.objectMatrix, RI.currententity->angles, RI.currententity->origin, 1 ); Matrix4x4_VectorITransform( RI.objectMatrix, l->origin, origin_l ); VectorCopy( origin_l, l->origin ); // move light in bmodel space - R_MarkLights( l, 1<nodes + RI.currentmodel->hulls[0].firstclipnode ); + R_MarkLights( l, 1 << k, RI.currentmodel->nodes + RI.currentmodel->hulls[0].firstclipnode ); VectorCopy( oldorigin, l->origin ); // restore lightorigin } RI.currententity->topnode = topnode; - if (topnode->contents >= 0) + if( topnode->contents >= 0 ) { - // not a leaf; has to be clipped to the world BSP + // not a leaf; has to be clipped to the world BSP r_clipflags = clipflags; - R_DrawSolidClippedSubmodelPolygons (RI.currentmodel, topnode); + R_DrawSolidClippedSubmodelPolygons( RI.currentmodel, topnode ); } else { - // falls entirely in one leaf, so we just put all the - // edges in the edge list and let 1/z sorting handle - // drawing order - R_DrawSubmodelPolygons (RI.currentmodel, clipflags, topnode); + // falls entirely in one leaf, so we just put all the + // edges in the edge list and let 1/z sorting handle + // drawing order + R_DrawSubmodelPolygons( RI.currentmodel, clipflags, topnode ); } RI.currententity->topnode = NULL; - // put back world rotation and frustum clipping - // FIXME: R_RotateBmodel should just work off base_vxx - VectorCopy (RI.base_vpn, RI.vforward); - VectorCopy (RI.base_vup, RI.vup); - VectorCopy (RI.base_vright, RI.vright); - VectorCopy (oldorigin, tr.modelorg); - R_TransformFrustum (); + // put back world rotation and frustum clipping + // FIXME: R_RotateBmodel should just work off base_vxx + VectorCopy( RI.base_vpn, RI.vforward ); + VectorCopy( RI.base_vup, RI.vup ); + VectorCopy( RI.base_vright, RI.vright ); + VectorCopy( oldorigin, tr.modelorg ); + R_TransformFrustum(); } insubmodel = false; @@ -958,121 +966,121 @@ extern qboolean alphaspans; R_DrawBEntitiesOnList ============= */ -void R_DrawBrushModel(cl_entity_t *pent) +void R_DrawBrushModel( cl_entity_t *pent ) { - int i, clipflags; - vec3_t oldorigin; - vec3_t mins, maxs; - float minmaxs[6]; - mnode_t *topnode; - int k; - edge_t ledges[NUMSTACKEDGES + - ((CACHE_SIZE - 1) / sizeof(edge_t)) + 1]; - surf_t lsurfs[NUMSTACKSURFACES + - ((CACHE_SIZE - 1) / sizeof(surf_t)) + 1]; + int i, clipflags; + vec3_t oldorigin; + vec3_t mins, maxs; + float minmaxs[6]; + mnode_t *topnode; + int k; + edge_t ledges[NUMSTACKEDGES + + (( CACHE_SIZE - 1 ) / sizeof( edge_t )) + 1]; + surf_t lsurfs[NUMSTACKSURFACES + + (( CACHE_SIZE - 1 ) / sizeof( surf_t )) + 1]; - if ( !RI.drawWorld ) + if( !RI.drawWorld ) return; - if (auxedges) + if( auxedges ) { r_edges = auxedges; } else { - r_edges = (edge_t *) - (((uintptr_t)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); + r_edges = (edge_t *) + (((uintptr_t)&ledges[0] + CACHE_SIZE - 1 ) & ~( CACHE_SIZE - 1 )); } - if (r_surfsonstack) + if( r_surfsonstack ) { - surfaces = (surf_t *)(((uintptr_t)&lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); + surfaces = (surf_t *)(((uintptr_t)&lsurfs[0] + CACHE_SIZE - 1 ) & ~( CACHE_SIZE - 1 )); surf_max = &surfaces[r_cnumsurfs]; - // surface 0 doesn't really exist; it's just a dummy because index 0 - // is used to indicate no edge attached to surface - memset(&surfaces[0], 0, sizeof(surf_t)); + // surface 0 doesn't really exist; it's just a dummy because index 0 + // is used to indicate no edge attached to surface + memset( &surfaces[0], 0, sizeof( surf_t )); surfaces--; - R_SurfacePatch (); + R_SurfacePatch(); } R_BeginEdgeFrame(); - VectorCopy (tr.modelorg, oldorigin); + VectorCopy( tr.modelorg, oldorigin ); insubmodel = true; - if (!RI.currentmodel) - return; - if (RI.currentmodel->nummodelsurfaces == 0) - return; // clip brush only - if (RI.currentmodel->type != mod_brush) - return; + if( !RI.currentmodel ) + return; + if( RI.currentmodel->nummodelsurfaces == 0 ) + return; // clip brush only + if( RI.currentmodel->type != mod_brush ) + return; // see if the bounding box lets us trivially reject, also sets // trivial accept status - RotatedBBox (RI.currentmodel->mins, RI.currentmodel->maxs, - RI.currententity->angles, mins, maxs); - VectorAdd (mins, RI.currententity->origin, minmaxs); - VectorAdd (maxs, RI.currententity->origin, (minmaxs+3)); + RotatedBBox( RI.currentmodel->mins, RI.currentmodel->maxs, + RI.currententity->angles, mins, maxs ); + VectorAdd( mins, RI.currententity->origin, minmaxs ); + VectorAdd( maxs, RI.currententity->origin, ( minmaxs + 3 )); - clipflags = R_BmodelCheckBBox (minmaxs); - if (clipflags == BMODEL_FULLY_CLIPPED) - return; // off the edge of the screen - //clipflags = 0; + clipflags = R_BmodelCheckBBox( minmaxs ); + if( clipflags == BMODEL_FULLY_CLIPPED ) + return; // off the edge of the screen + // clipflags = 0; - topnode = R_FindTopnode (minmaxs, minmaxs+3); - if (!topnode) - return; // no part in a visible leaf + topnode = R_FindTopnode( minmaxs, minmaxs + 3 ); + if( !topnode ) + return; // no part in a visible leaf - alphaspans = true; - VectorCopy (RI.currententity->origin, r_entorigin); - VectorSubtract (RI.vieworg, r_entorigin, tr.modelorg); - //VectorSubtract (r_origin, RI.currententity->origin, modelorg); - r_pcurrentvertbase = RI.currentmodel->vertexes; + alphaspans = true; + VectorCopy( RI.currententity->origin, r_entorigin ); + VectorSubtract( RI.vieworg, r_entorigin, tr.modelorg ); + // VectorSubtract (r_origin, RI.currententity->origin, modelorg); + r_pcurrentvertbase = RI.currentmodel->vertexes; // FIXME: stop transforming twice - R_RotateBmodel (); + R_RotateBmodel(); - // calculate dynamic lighting for bmodel - for( k = 0; k < MAX_DLIGHTS; k++ ) - { - dlight_t *l = &tr.dlights[k]; - vec3_t origin_l, oldorigin; + // calculate dynamic lighting for bmodel + for( k = 0; k < MAX_DLIGHTS; k++ ) + { + dlight_t *l = &tr.dlights[k]; + vec3_t origin_l, oldorigin; - if( l->die < gp_cl->time || !l->radius ) - continue; + if( l->die < gp_cl->time || !l->radius ) + continue; - VectorCopy( l->origin, oldorigin ); // save lightorigin - Matrix4x4_CreateFromEntity( RI.objectMatrix, RI.currententity->angles, RI.currententity->origin, 1 ); - Matrix4x4_VectorITransform( RI.objectMatrix, l->origin, origin_l ); - tr.modelviewIdentity = false; - VectorCopy( origin_l, l->origin ); // move light in bmodel space - R_MarkLights( l, 1<nodes + RI.currentmodel->hulls[0].firstclipnode ); - VectorCopy( oldorigin, l->origin ); // restore lightorigin*/ - } + VectorCopy( l->origin, oldorigin ); // save lightorigin + Matrix4x4_CreateFromEntity( RI.objectMatrix, RI.currententity->angles, RI.currententity->origin, 1 ); + Matrix4x4_VectorITransform( RI.objectMatrix, l->origin, origin_l ); + tr.modelviewIdentity = false; + VectorCopy( origin_l, l->origin ); // move light in bmodel space + R_MarkLights( l, 1 << k, RI.currentmodel->nodes + RI.currentmodel->hulls[0].firstclipnode ); + VectorCopy( oldorigin, l->origin ); // restore lightorigin*/ + } - RI.currententity->topnode = topnode; - if (topnode->contents >= 0) - { + RI.currententity->topnode = topnode; + if( topnode->contents >= 0 ) + { // not a leaf; has to be clipped to the world BSP - r_clipflags = clipflags; - R_DrawSolidClippedSubmodelPolygons (RI.currentmodel, topnode); - } - else - { + r_clipflags = clipflags; + R_DrawSolidClippedSubmodelPolygons( RI.currentmodel, topnode ); + } + else + { // falls entirely in one leaf, so we just put all the // edges in the edge list and let 1/z sorting handle // drawing order - R_DrawSubmodelPolygons (RI.currentmodel, clipflags, topnode); - } - RI.currententity->topnode = NULL; + R_DrawSubmodelPolygons( RI.currentmodel, clipflags, topnode ); + } + RI.currententity->topnode = NULL; // put back world rotation and frustum clipping // FIXME: R_RotateBmodel should just work off base_vxx - VectorCopy (RI.base_vpn, RI.vforward); - VectorCopy (RI.base_vup, RI.vup); - VectorCopy (RI.base_vright, RI.vright); - VectorCopy (oldorigin, tr.modelorg); - R_TransformFrustum (); + VectorCopy( RI.base_vpn, RI.vforward ); + VectorCopy( RI.base_vup, RI.vup ); + VectorCopy( RI.base_vright, RI.vright ); + VectorCopy( oldorigin, tr.modelorg ); + R_TransformFrustum(); insubmodel = false; @@ -1085,49 +1093,49 @@ void R_DrawBrushModel(cl_entity_t *pent) R_EdgeDrawing ================ */ -static void R_EdgeDrawing (void) +static void R_EdgeDrawing( void ) { - edge_t ledges[NUMSTACKEDGES + - ((CACHE_SIZE - 1) / sizeof(edge_t)) + 1]; - surf_t lsurfs[NUMSTACKSURFACES + - ((CACHE_SIZE - 1) / sizeof(surf_t)) + 1]; + edge_t ledges[NUMSTACKEDGES + + (( CACHE_SIZE - 1 ) / sizeof( edge_t )) + 1]; + surf_t lsurfs[NUMSTACKSURFACES + + (( CACHE_SIZE - 1 ) / sizeof( surf_t )) + 1]; - if ( !RI.drawWorld ) + if( !RI.drawWorld ) return; - if (auxedges) + if( auxedges ) { r_edges = auxedges; } else { - r_edges = (edge_t *) - (((uintptr_t)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); + r_edges = (edge_t *) + (((uintptr_t)&ledges[0] + CACHE_SIZE - 1 ) & ~( CACHE_SIZE - 1 )); } - if (r_surfsonstack) + if( r_surfsonstack ) { - surfaces = (surf_t *)(((uintptr_t)&lsurfs + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); + surfaces = (surf_t *)(((uintptr_t)&lsurfs + CACHE_SIZE - 1 ) & ~( CACHE_SIZE - 1 )); surf_max = &surfaces[r_cnumsurfs]; // surface 0 doesn't really exist; it's just a dummy because index 0 // is used to indicate no edge attached to surface - memset(surfaces, 0, sizeof(surf_t)); + memset( surfaces, 0, sizeof( surf_t )); surfaces--; - R_SurfacePatch (); + R_SurfacePatch(); } - R_BeginEdgeFrame (); + R_BeginEdgeFrame(); // this will prepare edges - R_RenderWorld (); + R_RenderWorld(); // move brushes to separate list to merge with edges? - R_DrawBEntitiesOnList (); + R_DrawBEntitiesOnList(); // display all edges - R_ScanEdges (); + R_ScanEdges(); } /* @@ -1135,13 +1143,13 @@ static void R_EdgeDrawing (void) R_MarkLeaves =============== */ -static void R_MarkLeaves (void) +static void R_MarkLeaves( void ) { - byte *vis; - mnode_t *node; - int i; + byte *vis; + mnode_t *node; + int i; - if (r_oldviewcluster == r_viewcluster && !r_novis.value && r_viewcluster != -1) + if( r_oldviewcluster == r_viewcluster && !r_novis.value && r_viewcluster != -1 ) return; tr.visframecount++; @@ -1150,18 +1158,19 @@ static void R_MarkLeaves (void) gEngfuncs.R_FatPVS( RI.pvsorigin, REFPVS_RADIUS, RI.visbytes, FBitSet( RI.params, RP_OLDVIEWLEAF ), false ); vis = RI.visbytes; - for (i = 0; i < WORLDMODEL->numleafs; i++) + for( i = 0; i < WORLDMODEL->numleafs; i++ ) { - if (vis[i>>3] & (1<<(i&7))) + if( vis[i >> 3] & ( 1 << ( i & 7 ))) { - node = (mnode_t *) &WORLDMODEL->leafs[i+1]; + node = (mnode_t *) &WORLDMODEL->leafs[i + 1]; do { - if (node->visframe == tr.visframecount) + if( node->visframe == tr.visframecount ) break; node->visframe = tr.visframecount; node = node->parent; - } while (node); + } + while( node ); } } } @@ -1180,8 +1189,9 @@ void GAME_EXPORT R_RenderScene( void ) // frametime is valid only for normal pass if( RP_NORMALPASS( )) - tr.frametime = gp_cl->time - gp_cl->oldtime; - else tr.frametime = 0.0; + tr.frametime = gp_cl->time - gp_cl->oldtime; + else + tr.frametime = 0.0; // begin a new frame tr.framecount++; @@ -1204,14 +1214,14 @@ void GAME_EXPORT R_RenderScene( void ) tr.modelviewIdentity = true; // R_SetupGL( true ); - //R_Clear( ~0 ); + // R_Clear( ~0 ); R_MarkLeaves(); // R_PushDlights (r_worldmodel); ?? - //R_DrawWorld(); - R_EdgeDrawing (); + // R_DrawWorld(); + R_EdgeDrawing(); - gEngfuncs.CL_ExtraUpdate (); // don't let sound get messed up if going slow + gEngfuncs.CL_ExtraUpdate(); // don't let sound get messed up if going slow R_DrawEntitiesOnList(); @@ -1238,13 +1248,13 @@ void GAME_EXPORT R_BeginFrame( qboolean clearScene ) R_Set2DMode( true ); // draw buffer stuff - //pglDrawBuffer( GL_BACK ); + // pglDrawBuffer( GL_BACK ); // update texture parameters - //if( FBitSet( gl_texture_nearest->flags|gl_lightmap_nearest->flags|gl_texture_anisotropy->flags|gl_texture_lodbias->flags, FCVAR_CHANGED )) - //R_SetTextureParameters(); + // if( FBitSet( gl_texture_nearest->flags|gl_lightmap_nearest->flags|gl_texture_anisotropy->flags|gl_texture_lodbias->flags, FCVAR_CHANGED )) + // R_SetTextureParameters(); - gEngfuncs.CL_ExtraUpdate (); + gEngfuncs.CL_ExtraUpdate(); } /* @@ -1262,7 +1272,8 @@ void R_SetupRefParams( const ref_viewpass_t *rvp ) if( !FBitSet( rvp->flags, RF_DRAW_CUBEMAP )) RI.drawOrtho = FBitSet( rvp->flags, RF_DRAW_OVERVIEW ); - else RI.drawOrtho = false; + else + RI.drawOrtho = false; // setup viewport RI.viewport[0] = rvp->viewport[0]; @@ -1303,7 +1314,7 @@ void GAME_EXPORT R_RenderFrame( const ref_viewpass_t *rvp ) if( gEngfuncs.drawFuncs->GL_RenderFrame( rvp )) { - //R_GatherPlayerLight(); + // R_GatherPlayerLight(); tr.realframecount++; tr.fResetVis = true; return; @@ -1358,7 +1369,7 @@ void R_DrawCubemapView( const vec3_t origin, const vec3_t angles, int size ) R_RenderFrame( &rvp ); - RI.viewleaf = NULL; // force markleafs next frame + RI.viewleaf = NULL; // force markleafs next frame } /* @@ -1366,9 +1377,9 @@ void R_DrawCubemapView( const vec3_t origin, const vec3_t angles, int size ) R_NewMap =============== */ -void GAME_EXPORT R_NewMap (void) +void GAME_EXPORT R_NewMap( void ) { - int i; + int i; model_t *world = WORLDMODEL; r_viewcluster = -1; @@ -1383,42 +1394,42 @@ void GAME_EXPORT R_NewMap (void) r_cnumsurfs = sw_maxsurfs.value; - if (r_cnumsurfs <= MINSURFACES) - r_cnumsurfs = MINSURFACES; + if( r_cnumsurfs <= MINSURFACES ) + r_cnumsurfs = MINSURFACES; - if (r_cnumsurfs > NUMSTACKSURFACES) + if( r_cnumsurfs > NUMSTACKSURFACES ) { - surfaces = Mem_Calloc (r_temppool, r_cnumsurfs * sizeof(surf_t)); - surface_p = surfaces; - surf_max = &surfaces[r_cnumsurfs]; - r_surfsonstack = false; - // surface 0 doesn't really exist; it's just a dummy because index 0 - // is used to indicate no edge attached to surface - surfaces--; - R_SurfacePatch (); + surfaces = Mem_Calloc( r_temppool, r_cnumsurfs * sizeof( surf_t )); + surface_p = surfaces; + surf_max = &surfaces[r_cnumsurfs]; + r_surfsonstack = false; + // surface 0 doesn't really exist; it's just a dummy because index 0 + // is used to indicate no edge attached to surface + surfaces--; + R_SurfacePatch(); } else { - r_surfsonstack = true; + r_surfsonstack = true; } r_numallocatededges = sw_maxedges.value; - if (r_numallocatededges < MINEDGES) - r_numallocatededges = MINEDGES; + if( r_numallocatededges < MINEDGES ) + r_numallocatededges = MINEDGES; - if (r_numallocatededges <= NUMSTACKEDGES) + if( r_numallocatededges <= NUMSTACKEDGES ) { - auxedges = NULL; + auxedges = NULL; } else { - auxedges = Mem_Malloc (r_temppool, r_numallocatededges * sizeof(edge_t) ); + auxedges = Mem_Malloc( r_temppool, r_numallocatededges * sizeof( edge_t )); } // clear out efrags in case the level hasn't been reloaded for( i = 0; i < world->numleafs; i++ ) - world->leafs[i+1].efrags = NULL; + world->leafs[i + 1].efrags = NULL; tr.sample_size = gEngfuncs.Mod_SampleSizeForFace( &world->surfaces[0] ); @@ -1439,10 +1450,11 @@ void GAME_EXPORT R_NewMap (void) tr.sample_bits = 0; - for( sample_pot = 1; sample_pot < tr.sample_size; sample_pot <<= 1, tr.sample_bits++ ); + for( sample_pot = 1; sample_pot < tr.sample_size; sample_pot <<= 1, tr.sample_bits++ ) + ; } - gEngfuncs.Con_Printf("Map sample size is %d\n", tr.sample_size ); + gEngfuncs.Con_Printf( "Map sample size is %d\n", tr.sample_size ); } @@ -1451,15 +1463,15 @@ void GAME_EXPORT R_NewMap (void) R_InitTurb ================ */ -static void R_InitTurb (void) +static void R_InitTurb( void ) { - int i; + int i; - for (i=0 ; i<1280 ; i++) + for( i = 0; i < 1280; i++ ) { - sintable[i] = AMP + sin(i*3.14159*2/CYCLE)*AMP; - intsintable[i] = AMP2 + sin(i*3.14159*2/CYCLE)*AMP2; // AMP2, not 20 - blanktable[i] = 0; //PGM + sintable[i] = AMP + sin( i * 3.14159 * 2 / CYCLE ) * AMP; + intsintable[i] = AMP2 + sin( i * 3.14159 * 2 / CYCLE ) * AMP2; // AMP2, not 20 + blanktable[i] = 0; // PGM } } @@ -1498,7 +1510,7 @@ qboolean GAME_EXPORT R_Init( void ) if( !glblit && !gEngfuncs.R_Init_Video( REF_SOFTWARE )) // request software blitter { gEngfuncs.R_Free_Video(); - gEngfuncs.Con_Printf("failed to initialize software blitter, fallback to glblit\n"); + gEngfuncs.Con_Printf( "failed to initialize software blitter, fallback to glblit\n" ); glblit = true; } @@ -1531,7 +1543,7 @@ qboolean GAME_EXPORT R_Init( void ) tr.draw_stack_pos = 0; qfrustum.view_clipplanes[0].leftedge = true; qfrustum.view_clipplanes[1].rightedge = true; - qfrustum.view_clipplanes[1].leftedge = qfrustum.view_clipplanes[2].leftedge =qfrustum.view_clipplanes[3].leftedge = false; + qfrustum.view_clipplanes[1].leftedge = qfrustum.view_clipplanes[2].leftedge = qfrustum.view_clipplanes[3].leftedge = false; qfrustum.view_clipplanes[0].rightedge = qfrustum.view_clipplanes[2].rightedge = qfrustum.view_clipplanes[3].rightedge = false; R_StudioInit(); R_SpriteInit(); @@ -1555,9 +1567,9 @@ CL_FxBlend */ int CL_FxBlend( cl_entity_t *e ) { - int blend = 0; - float offset, dist; - vec3_t tmp; + int blend = 0; + float offset, dist; + vec3_t tmp; offset = ((int)e->index ) * 363.0f; // Use ent index to de-sync these fx @@ -1580,7 +1592,8 @@ int CL_FxBlend( cl_entity_t *e ) { if( e->curstate.renderamt > 0 ) e->curstate.renderamt -= 1; - else e->curstate.renderamt = 0; + else + e->curstate.renderamt = 0; } blend = e->curstate.renderamt; break; @@ -1589,7 +1602,8 @@ int CL_FxBlend( cl_entity_t *e ) { if( e->curstate.renderamt > 3 ) e->curstate.renderamt -= 4; - else e->curstate.renderamt = 0; + else + e->curstate.renderamt = 0; } blend = e->curstate.renderamt; break; @@ -1598,7 +1612,8 @@ int CL_FxBlend( cl_entity_t *e ) { if( e->curstate.renderamt < 255 ) e->curstate.renderamt += 1; - else e->curstate.renderamt = 255; + else + e->curstate.renderamt = 255; } blend = e->curstate.renderamt; break; @@ -1607,34 +1622,45 @@ int CL_FxBlend( cl_entity_t *e ) { if( e->curstate.renderamt < 252 ) e->curstate.renderamt += 4; - else e->curstate.renderamt = 255; + else + e->curstate.renderamt = 255; } blend = e->curstate.renderamt; break; case kRenderFxStrobeSlow: blend = 20 * sin( gp_cl->time * 4 + offset ); - if( blend < 0 ) blend = 0; - else blend = e->curstate.renderamt; + if( blend < 0 ) + blend = 0; + else + blend = e->curstate.renderamt; break; case kRenderFxStrobeFast: blend = 20 * sin( gp_cl->time * 16 + offset ); - if( blend < 0 ) blend = 0; - else blend = e->curstate.renderamt; + if( blend < 0 ) + blend = 0; + else + blend = e->curstate.renderamt; break; case kRenderFxStrobeFaster: blend = 20 * sin( gp_cl->time * 36 + offset ); - if( blend < 0 ) blend = 0; - else blend = e->curstate.renderamt; + if( blend < 0 ) + blend = 0; + else + blend = e->curstate.renderamt; break; case kRenderFxFlickerSlow: - blend = 20 * (sin( gp_cl->time * 2 ) + sin( gp_cl->time * 17 + offset )); - if( blend < 0 ) blend = 0; - else blend = e->curstate.renderamt; + blend = 20 * ( sin( gp_cl->time * 2 ) + sin( gp_cl->time * 17 + offset )); + if( blend < 0 ) + blend = 0; + else + blend = e->curstate.renderamt; break; case kRenderFxFlickerFast: - blend = 20 * (sin( gp_cl->time * 16 ) + sin( gp_cl->time * 23 + offset )); - if( blend < 0 ) blend = 0; - else blend = e->curstate.renderamt; + blend = 20 * ( sin( gp_cl->time * 16 ) + sin( gp_cl->time * 23 + offset )); + if( blend < 0 ) + blend = 0; + else + blend = e->curstate.renderamt; break; case kRenderFxHologram: case kRenderFxDistort: @@ -1653,8 +1679,10 @@ int CL_FxBlend( cl_entity_t *e ) else { e->curstate.renderamt = 180; - if( dist <= 100 ) blend = e->curstate.renderamt; - else blend = (int) ((1.0f - ( dist - 100 ) * ( 1.0f / 400.0f )) * e->curstate.renderamt ); + if( dist <= 100 ) + blend = e->curstate.renderamt; + else + blend = (int) (( 1.0f - ( dist - 100 ) * ( 1.0f / 400.0f )) * e->curstate.renderamt ); blend += gEngfuncs.COM_RandomLong( -32, 31 ); } break; diff --git a/ref/soft/r_math.c b/ref/soft/r_math.c index 26e9e019..bf377d4f 100644 --- a/ref/soft/r_math.c +++ b/ref/soft/r_math.c @@ -67,17 +67,17 @@ void Matrix4x4_CreateProjection( matrix4x4 out, float xMax, float xMin, float yM void Matrix4x4_CreateOrtho( matrix4x4 out, float xLeft, float xRight, float yBottom, float yTop, float zNear, float zFar ) { - out[0][0] = 2.0f / (xRight - xLeft); - out[1][1] = 2.0f / (yTop - yBottom); - out[2][2] = -2.0f / (zFar - zNear); + out[0][0] = 2.0f / ( xRight - xLeft ); + out[1][1] = 2.0f / ( yTop - yBottom ); + out[2][2] = -2.0f / ( zFar - zNear ); out[3][3] = 1.0f; out[0][1] = out[0][2] = out[1][0] = out[1][2] = out[3][0] = out[3][1] = out[3][2] = 0.0f; out[2][0] = 0.0f; out[2][1] = 0.0f; - out[0][3] = -(xRight + xLeft) / (xRight - xLeft); - out[1][3] = -(yTop + yBottom) / (yTop - yBottom); - out[2][3] = -(zFar + zNear) / (zFar - zNear); + out[0][3] = -( xRight + xLeft ) / ( xRight - xLeft ); + out[1][3] = -( yTop + yBottom ) / ( yTop - yBottom ); + out[2][3] = -( zFar + zNear ) / ( zFar - zNear ); } /* @@ -121,33 +121,34 @@ void Matrix4x4_CreateTranslate( matrix4x4 out, float x, float y, float z ) void Matrix4x4_CreateRotate( matrix4x4 out, float angle, float x, float y, float z ) { - float len, c, s; + float len, c, s; len = x * x + y * y + z * z; - if( len != 0.0f ) len = 1.0f / sqrt( len ); + if( len != 0.0f ) + len = 1.0f / sqrt( len ); x *= len; y *= len; z *= len; - angle *= (-M_PI_F / 180.0f); + angle *= ( -M_PI_F / 180.0f ); SinCos( angle, &s, &c ); - out[0][0]=x * x + c * (1 - x * x); - out[0][1]=x * y * (1 - c) + z * s; - out[0][2]=z * x * (1 - c) - y * s; - out[0][3]=0.0f; - out[1][0]=x * y * (1 - c) - z * s; - out[1][1]=y * y + c * (1 - y * y); - out[1][2]=y * z * (1 - c) + x * s; - out[1][3]=0.0f; - out[2][0]=z * x * (1 - c) + y * s; - out[2][1]=y * z * (1 - c) - x * s; - out[2][2]=z * z + c * (1 - z * z); - out[2][3]=0.0f; - out[3][0]=0.0f; - out[3][1]=0.0f; - out[3][2]=0.0f; - out[3][3]=1.0f; + out[0][0] = x * x + c * ( 1 - x * x ); + out[0][1] = x * y * ( 1 - c ) + z * s; + out[0][2] = z * x * ( 1 - c ) - y * s; + out[0][3] = 0.0f; + out[1][0] = x * y * ( 1 - c ) - z * s; + out[1][1] = y * y + c * ( 1 - y * y ); + out[1][2] = y * z * ( 1 - c ) + x * s; + out[1][3] = 0.0f; + out[2][0] = z * x * ( 1 - c ) + y * s; + out[2][1] = y * z * ( 1 - c ) - x * s; + out[2][2] = z * z + c * ( 1 - z * z ); + out[2][3] = 0.0f; + out[3][0] = 0.0f; + out[3][1] = 0.0f; + out[3][2] = 0.0f; + out[3][3] = 1.0f; } static void Matrix4x4_CreateScale( matrix4x4 out, float x ) diff --git a/ref/soft/r_misc.c b/ref/soft/r_misc.c index 032ecbb3..7af67152 100644 --- a/ref/soft/r_misc.c +++ b/ref/soft/r_misc.c @@ -21,29 +21,29 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" -#define NUM_MIPS 4 +#define NUM_MIPS 4 -surfcache_t *d_initial_rover; -qboolean d_roverwrapped; -int d_minmip; -float d_scalemip[NUM_MIPS-1]; +surfcache_t *d_initial_rover; +qboolean d_roverwrapped; +int d_minmip; +float d_scalemip[NUM_MIPS - 1]; -static float basemip[NUM_MIPS-1] = {1.0, 0.5*0.8, 0.25*0.8}; +static float basemip[NUM_MIPS - 1] = {1.0, 0.5 * 0.8, 0.25 * 0.8}; -//int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle; +// int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle; -//int d_pix_min, d_pix_max, d_pix_shift; +// int d_pix_min, d_pix_max, d_pix_shift; -int d_scantable[MAXHEIGHT]; -short *zspantable[MAXHEIGHT]; +int d_scantable[MAXHEIGHT]; +short *zspantable[MAXHEIGHT]; struct qfrustum_s qfrustum; /* ================ D_Patch ================ */ -static void D_Patch (void) +static void D_Patch( void ) { } /* @@ -52,12 +52,12 @@ D_ViewChanged ================ */ -void D_ViewChanged (void) +void D_ViewChanged( void ) { - int i; + int i; scale_for_mip = xscale; - if (yscale > xscale) + if( yscale > xscale ) scale_for_mip = yscale; d_zrowbytes = vid.width * 2; @@ -72,27 +72,27 @@ void D_ViewChanged (void) if (d_pix_max < 1) d_pix_max = 1;*/ - //d_vrectx = RI.vrect.x; - //d_vrecty = RI.vrect.y; - //d_vrectright_particle = gpGlobals->width - d_pix_max; - //d_vrectbottom_particle = - // gpGlobals->height - d_pix_max; + // d_vrectx = RI.vrect.x; + // d_vrecty = RI.vrect.y; + // d_vrectright_particle = gpGlobals->width - d_pix_max; + // d_vrectbottom_particle = + // gpGlobals->height - d_pix_max; - for (i=0 ; iflags & FCVAR_CHANGED) + if( r_fullbright->flags & FCVAR_CHANGED ) { r_fullbright->flags &= ~FCVAR_CHANGED; - D_FlushCaches( ); // so all lighting changes + D_FlushCaches( ); // so all lighting changes } - //tr.framecount++; + // tr.framecount++; // build the transformation matrix for the given view angles - VectorCopy (RI.vieworg, tr.modelorg); + VectorCopy( RI.vieworg, tr.modelorg ); - //AngleVectors (RI.viewangles, RI.vforward, RI.vright, RI.vup); + // AngleVectors (RI.viewangles, RI.vforward, RI.vright, RI.vup); // current viewleaf - if ( RI.drawWorld ) + if( RI.drawWorld ) { - RI.viewleaf = gEngfuncs.Mod_PointInLeaf (RI.vieworg, WORLDMODEL->nodes); + RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.vieworg, WORLDMODEL->nodes ); r_viewcluster = RI.viewleaf->cluster; } @@ -315,16 +315,16 @@ void R_SetupFrameQ (void) d_viewbuffer = (void *)vid.buffer; r_screenwidth = vid.rowbytes; - R_ViewChanged (&vrect); + R_ViewChanged( &vrect ); // start off with just the four screen edge clip planes - R_TransformFrustum (); - R_SetUpFrustumIndexes (); + R_TransformFrustum(); + R_SetUpFrustumIndexes(); // save base values - VectorCopy (RI.vforward, RI.base_vpn); - VectorCopy (RI.vright, RI.base_vright); - VectorCopy (RI.vup, RI.base_vup); + VectorCopy( RI.vforward, RI.base_vpn ); + VectorCopy( RI.vright, RI.base_vright ); + VectorCopy( RI.vup, RI.base_vup ); // clear frame counts /* c_faceclip = 0; @@ -341,13 +341,13 @@ void R_SetupFrameQ (void) d_initial_rover = sc_rover; d_minmip = sw_mipcap.value; - if (d_minmip > 3) + if( d_minmip > 3 ) d_minmip = 3; - else if (d_minmip < 0) + else if( d_minmip < 0 ) d_minmip = 0; - for (i=0 ; i<(NUM_MIPS-1) ; i++) + for( i = 0; i < ( NUM_MIPS - 1 ); i++ ) d_scalemip[i] = basemip[i] * sw_mipscale.value; - //d_aflatcolor = 0; + // d_aflatcolor = 0; } diff --git a/ref/soft/r_part.c b/ref/soft/r_part.c index 9f3670ce..fef1e0c1 100644 --- a/ref/soft/r_part.c +++ b/ref/soft/r_part.c @@ -21,21 +21,21 @@ GNU General Public License for more details. #include "pm_local.h" #include "studio.h" -static float gTracerSize[11] = { 1.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; +static float gTracerSize[11] = { 1.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; static color24 gTracerColors[] = { -{ 255, 255, 255 }, // White -{ 255, 0, 0 }, // Red -{ 0, 255, 0 }, // Green -{ 0, 0, 255 }, // Blue -{ 0, 0, 0 }, // Tracer default, filled in from cvars, etc. -{ 255, 167, 17 }, // Yellow-orange sparks -{ 255, 130, 90 }, // Yellowish streaks (garg) -{ 55, 60, 144 }, // Blue egon streak -{ 255, 130, 90 }, // More Yellowish streaks (garg) -{ 255, 140, 90 }, // More Yellowish streaks (garg) -{ 200, 130, 90 }, // More red streaks (garg) -{ 255, 120, 70 }, // Darker red streaks (garg) + { 255, 255, 255 }, // White + { 255, 0, 0 }, // Red + { 0, 255, 0 }, // Green + { 0, 0, 255 }, // Blue + { 0, 0, 0 }, // Tracer default, filled in from cvars, etc. + { 255, 167, 17 }, // Yellow-orange sparks + { 255, 130, 90 }, // Yellowish streaks (garg) + { 55, 60, 144 }, // Blue egon streak + { 255, 130, 90 }, // More Yellowish streaks (garg) + { 255, 140, 90 }, // More Yellowish streaks (garg) + { 200, 130, 90 }, // More red streaks (garg) + { 255, 120, 70 }, // Darker red streaks (garg) }; /* @@ -47,23 +47,23 @@ update particle color, position, free expired and draw it */ void GAME_EXPORT CL_DrawParticles( double frametime, particle_t *cl_active_particles, float partsize ) { - particle_t *p; - vec3_t right, up; - color24 color; - int alpha; - float size; + particle_t *p; + vec3_t right, up; + color24 color; + int alpha; + float size; if( !cl_active_particles ) - return; // nothing to draw? + return; // nothing to draw? - //pglEnable( GL_BLEND ); - //pglDisable( GL_ALPHA_TEST ); - //pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + // pglEnable( GL_BLEND ); + // pglDisable( GL_ALPHA_TEST ); + // pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); GL_SetRenderMode( kRenderTransAdd ); GL_Bind( XASH_TEXTURE0, tr.particleTexture ); - //pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - //pglDepthMask( GL_FALSE ); + // pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + // pglDepthMask( GL_FALSE ); for( p = cl_active_particles; p; p = p->next ) { @@ -72,12 +72,14 @@ void GAME_EXPORT CL_DrawParticles( double frametime, particle_t *cl_active_parti size = partsize; // get initial size of particle // scale up to keep particles from disappearing - size += (p->org[0] - RI.vieworg[0]) * RI.cull_vforward[0]; - size += (p->org[1] - RI.vieworg[1]) * RI.cull_vforward[1]; - size += (p->org[2] - RI.vieworg[2]) * RI.cull_vforward[2]; + size += ( p->org[0] - RI.vieworg[0] ) * RI.cull_vforward[0]; + size += ( p->org[1] - RI.vieworg[1] ) * RI.cull_vforward[1]; + size += ( p->org[2] - RI.vieworg[2] ) * RI.cull_vforward[2]; - if( size < 20.0f ) size = partsize; - else size = partsize + size * 0.002f; + if( size < 20.0f ) + size = partsize; + else + size = partsize + size * 0.002f; // scale the axes by radius VectorScale( RI.cull_vright, size, right ); @@ -86,15 +88,15 @@ void GAME_EXPORT CL_DrawParticles( double frametime, particle_t *cl_active_parti p->color = bound( 0, p->color, 255 ); color = tr.palette[p->color]; - alpha = 255 * (p->die - gp_cl->time) * 16.0f; + alpha = 255 * ( p->die - gp_cl->time ) * 16.0f; if( alpha > 255 || p->type == pt_static ) alpha = 255; - //TriColor4ub( LightToTexGamma( color.r ), + // TriColor4ub( LightToTexGamma( color.r ), // LightToTexGamma( color.g ), - // LightToTexGamma( color.b ), alpha ); - //TriBrightness( alpha / 255.0f ); - _TriColor4f(1.0f*alpha/255/255*color.r,1.0f*alpha/255/255*color.g,1.0f*alpha/255/255* color.b,1.0f ); + // LightToTexGamma( color.b ), alpha ); + // TriBrightness( alpha / 255.0f ); + _TriColor4f( 1.0f * alpha / 255 / 255 * color.r, 1.0f * alpha / 255 / 255 * color.g, 1.0f * alpha / 255 / 255 * color.b, 1.0f ); TriBegin( TRI_QUADS ); TriTexCoord2f( 0.0f, 1.0f ); @@ -113,7 +115,7 @@ void GAME_EXPORT CL_DrawParticles( double frametime, particle_t *cl_active_parti } TriEnd(); - //pglDepthMask( GL_TRUE ); + // pglDepthMask( GL_TRUE ); } /* @@ -125,8 +127,8 @@ check tracer bbox */ static qboolean CL_CullTracer( particle_t *p, const vec3_t start, const vec3_t end ) { - vec3_t mins, maxs; - int i; + vec3_t mins, maxs; + int i; return false; /* // compute the bounding box @@ -163,18 +165,18 @@ update tracer color, position, free expired and draw it */ void GAME_EXPORT CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) { - float scale, atten, gravity; - vec3_t screenLast, screen; - vec3_t start, end, delta; - particle_t *p; + float scale, atten, gravity; + vec3_t screenLast, screen; + vec3_t start, end, delta; + particle_t *p; // update tracer color if this is changed - if( FBitSet( tracerred->flags|tracergreen->flags|tracerblue->flags|traceralpha->flags, FCVAR_CHANGED )) + if( FBitSet( tracerred->flags | tracergreen->flags | tracerblue->flags | traceralpha->flags, FCVAR_CHANGED )) { color24 *customColors = &gTracerColors[4]; - customColors->r = (byte)(tracerred->value * traceralpha->value * 255); - customColors->g = (byte)(tracergreen->value * traceralpha->value * 255); - customColors->b = (byte)(tracerblue->value * traceralpha->value * 255); + customColors->r = (byte)( tracerred->value * traceralpha->value * 255 ); + customColors->g = (byte)( tracergreen->value * traceralpha->value * 255 ); + customColors->b = (byte)( tracerblue->value * traceralpha->value * 255 ); ClearBits( tracerred->flags, FCVAR_CHANGED ); ClearBits( tracergreen->flags, FCVAR_CHANGED ); ClearBits( tracerblue->flags, FCVAR_CHANGED ); @@ -182,26 +184,28 @@ void GAME_EXPORT CL_DrawTracers( double frametime, particle_t *cl_active_tracers } if( !cl_active_tracers ) - return; // nothing to draw? + return; // nothing to draw? GL_SetRenderMode( kRenderTransAdd ); if( !TriSpriteTexture( gEngfuncs.GetDefaultSprite( REF_DOT_SPRITE ), 0 )) return; - //pglEnable( GL_BLEND ); - //pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); - //pglDisable( GL_ALPHA_TEST ); - //pglDepthMask( GL_FALSE ); + // pglEnable( GL_BLEND ); + // pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); + // pglDisable( GL_ALPHA_TEST ); + // pglDepthMask( GL_FALSE ); gravity = frametime * tr.movevars->gravity; - scale = 1.0 - (frametime * 0.9); - if( scale < 0.0f ) scale = 0.0f; + scale = 1.0 - ( frametime * 0.9 ); + if( scale < 0.0f ) + scale = 0.0f; for( p = cl_active_tracers; p; p = p->next ) { - atten = (p->die - gp_cl->time); - if( atten > 0.1f ) atten = 0.1f; + atten = ( p->die - gp_cl->time ); + if( atten > 0.1f ) + atten = 0.1f; VectorScale( p->vel, ( p->ramp * atten ), delta ); VectorAdd( p->org, delta, end ); @@ -209,10 +213,10 @@ void GAME_EXPORT CL_DrawTracers( double frametime, particle_t *cl_active_tracers if( !CL_CullTracer( p, start, end )) { - vec3_t verts[4], tmp2; - vec3_t tmp, normal; - color24 color; - short alpha = p->packedColor; + vec3_t verts[4], tmp2; + vec3_t tmp, normal; + color24 color; + short alpha = p->packedColor; // Transform point into screen space TriWorldToScreen( start, screen ); @@ -242,19 +246,19 @@ void GAME_EXPORT CL_DrawTracers( double frametime, particle_t *cl_active_tracers } color = gTracerColors[p->color]; - //TriColor4ub( color.r, color.g, color.b, p->packedColor ); - _TriColor4f(1.0f*alpha/255/255*color.r,1.0f*alpha/255/255*color.g,1.0f*alpha/255/255* color.b,1.0f ); + // TriColor4ub( color.r, color.g, color.b, p->packedColor ); + _TriColor4f( 1.0f * alpha / 255 / 255 * color.r, 1.0f * alpha / 255 / 255 * color.g, 1.0f * alpha / 255 / 255 * color.b, 1.0f ); TriBegin( TRI_QUADS ); - TriTexCoord2f( 0.0f, 0.8f ); - TriVertex3fv( verts[2] ); - TriTexCoord2f( 1.0f, 0.8f ); - TriVertex3fv( verts[3] ); - TriTexCoord2f( 1.0f, 0.0f ); - TriVertex3fv( verts[1] ); - TriTexCoord2f( 0.0f, 0.0f ); - TriVertex3fv( verts[0] ); + TriTexCoord2f( 0.0f, 0.8f ); + TriVertex3fv( verts[2] ); + TriTexCoord2f( 1.0f, 0.8f ); + TriVertex3fv( verts[3] ); + TriTexCoord2f( 1.0f, 0.0f ); + TriVertex3fv( verts[1] ); + TriTexCoord2f( 0.0f, 0.0f ); + TriVertex3fv( verts[0] ); TriEnd(); } @@ -267,8 +271,9 @@ void GAME_EXPORT CL_DrawTracers( double frametime, particle_t *cl_active_tracers p->vel[1] *= scale; p->vel[2] -= gravity; - p->packedColor = 255 * (p->die - gp_cl->time) * 2; - if( p->packedColor > 255 ) p->packedColor = 255; + p->packedColor = 255 * ( p->die - gp_cl->time ) * 2; + if( p->packedColor > 255 ) + p->packedColor = 255; } else if( p->type == pt_slowgrav ) { @@ -276,7 +281,7 @@ void GAME_EXPORT CL_DrawTracers( double frametime, particle_t *cl_active_tracers } } - //pglDepthMask( GL_TRUE ); + // pglDepthMask( GL_TRUE ); } /* @@ -288,7 +293,7 @@ allow to draw effects from custom renderer */ void GAME_EXPORT CL_DrawParticlesExternal( const ref_viewpass_t *rvp, qboolean trans_pass, float frametime ) { - ref_instance_t oldRI = RI; + ref_instance_t oldRI = RI; R_SetupRefParams( rvp ); R_SetupFrustum(); diff --git a/ref/soft/r_polyse.c b/ref/soft/r_polyse.c index a74d5eda..4cc19083 100644 --- a/ref/soft/r_polyse.c +++ b/ref/soft/r_polyse.c @@ -24,38 +24,39 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // TODO: put in span spilling to shrink list size // !!! if this is changed, it must be changed in d_polysa.s too !!! -#define DPS_MAXSPANS MAXHEIGHT+1 - // 1 extra for spanpackage that marks end +#define DPS_MAXSPANS MAXHEIGHT + 1 +// 1 extra for spanpackage that marks end -typedef struct { - int isflattop; - int numleftedges; - int *pleftedgevert0; - int *pleftedgevert1; - int *pleftedgevert2; - int numrightedges; - int *prightedgevert0; - int *prightedgevert1; - int *prightedgevert2; +typedef struct +{ + int isflattop; + int numleftedges; + int *pleftedgevert0; + int *pleftedgevert1; + int *pleftedgevert2; + int numrightedges; + int *prightedgevert0; + int *prightedgevert1; + int *prightedgevert2; } edgetable; aliastriangleparms_t aliastriangleparms; -int r_p0[6], r_p1[6], r_p2[6]; +int r_p0[6], r_p1[6], r_p2[6]; -int d_xdenom; +int d_xdenom; -edgetable *pedgetable; +edgetable *pedgetable; -edgetable edgetables[12] = { +edgetable edgetables[12] = { {0, 1, r_p0, r_p2, NULL, 2, r_p0, r_p1, r_p2 }, - {0, 2, r_p1, r_p0, r_p2, 1, r_p1, r_p2, NULL}, + {0, 2, r_p1, r_p0, r_p2, 1, r_p1, r_p2, NULL}, {1, 1, r_p0, r_p2, NULL, 1, r_p1, r_p2, NULL}, {0, 1, r_p1, r_p0, NULL, 2, r_p1, r_p2, r_p0 }, - {0, 2, r_p0, r_p2, r_p1, 1, r_p0, r_p1, NULL}, + {0, 2, r_p0, r_p2, r_p1, 1, r_p0, r_p1, NULL}, {0, 1, r_p2, r_p1, NULL, 1, r_p2, r_p0, NULL}, {0, 1, r_p2, r_p1, NULL, 2, r_p2, r_p0, r_p1 }, - {0, 2, r_p2, r_p1, r_p0, 1, r_p2, r_p0, NULL}, + {0, 2, r_p2, r_p1, r_p0, 1, r_p2, r_p0, NULL}, {0, 1, r_p1, r_p0, NULL, 1, r_p1, r_p2, NULL}, {1, 1, r_p2, r_p1, NULL, 1, r_p0, r_p1, NULL}, {1, 1, r_p1, r_p0, NULL, 1, r_p2, r_p0, NULL}, @@ -63,56 +64,57 @@ edgetable edgetables[12] = { }; // FIXME: some of these can become statics -int a_sstepxfrac, a_tstepxfrac, r_lstepx, a_ststepxwhole; -int r_sstepx, r_tstepx, r_lstepy, r_sstepy, r_tstepy; -int r_zistepx, r_zistepy; -int d_aspancount, d_countextrastep; +int a_sstepxfrac, a_tstepxfrac, r_lstepx, a_ststepxwhole; +int r_sstepx, r_tstepx, r_lstepy, r_sstepy, r_tstepy; +int r_zistepx, r_zistepy; +int d_aspancount, d_countextrastep; -spanpackage_t *a_spans; -spanpackage_t *d_pedgespanpackage; -static int ystart; -pixel_t *d_pdest, *d_ptex; -short *d_pz; -int d_sfrac, d_tfrac, d_light, d_zi; -int d_ptexextrastep, d_sfracextrastep; -int d_tfracextrastep, d_lightextrastep, d_pdestextrastep; -int d_lightbasestep, d_pdestbasestep, d_ptexbasestep; -int d_sfracbasestep, d_tfracbasestep; -int d_ziextrastep, d_zibasestep; -int d_pzextrastep, d_pzbasestep; +spanpackage_t *a_spans; +spanpackage_t *d_pedgespanpackage; +static int ystart; +pixel_t *d_pdest, *d_ptex; +short *d_pz; +int d_sfrac, d_tfrac, d_light, d_zi; +int d_ptexextrastep, d_sfracextrastep; +int d_tfracextrastep, d_lightextrastep, d_pdestextrastep; +int d_lightbasestep, d_pdestbasestep, d_ptexbasestep; +int d_sfracbasestep, d_tfracbasestep; +int d_ziextrastep, d_zibasestep; +int d_pzextrastep, d_pzbasestep; -static int ubasestep, errorterm, erroradjustup, erroradjustdown; +static int ubasestep, errorterm, erroradjustup, erroradjustdown; -typedef struct { - int quotient; - int remainder; +typedef struct +{ + int quotient; + int remainder; } adivtab_t; -static adivtab_t adivtab[32*32] = { +static adivtab_t adivtab[32 * 32] = { #include "adivtab.h" }; -byte *skintable[MAX_LBM_HEIGHT]; -int skinwidth; -byte *skinstart; +byte *skintable[MAX_LBM_HEIGHT]; +int skinwidth; +byte *skinstart; -void (*d_pdrawspans)(spanpackage_t *pspanpackage); +void (*d_pdrawspans)( spanpackage_t *pspanpackage ); -static void R_PolysetStub (spanpackage_t *pspanpackage) +static void R_PolysetStub( spanpackage_t *pspanpackage ) { } -void R_PolysetDrawSpans8_33 (spanpackage_t *pspanpackage); -void R_PolysetDrawSpans8_66 (spanpackage_t *pspanpackage); -void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage); +void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage ); +void R_PolysetDrawSpans8_66( spanpackage_t *pspanpackage ); +void R_PolysetDrawSpans8_Opaque( spanpackage_t *pspanpackage ); -qboolean R_PolysetCalcGradients(int skinwidth); -void R_DrawNonSubdiv (void); -void R_PolysetSetEdgeTable (void); -void R_RasterizeAliasPolySmooth (void); -void R_PolysetScanLeftEdge(int height); -qboolean R_PolysetScanLeftEdge_C(int height); +qboolean R_PolysetCalcGradients( int skinwidth ); +void R_DrawNonSubdiv( void ); +void R_PolysetSetEdgeTable( void ); +void R_RasterizeAliasPolySmooth( void ); +void R_PolysetScanLeftEdge( int height ); +qboolean R_PolysetScanLeftEdge_C( int height ); /* ================ @@ -123,8 +125,8 @@ void R_DrawTriangle( void ) { spanpackage_t spans[DPS_MAXSPANS]; - int dv1_ab, dv0_ac; - int dv0_ab, dv1_ac; + int dv1_ab, dv0_ac; + int dv0_ab, dv1_ac; /* d_xdenom = ( aliastriangleparms.a->v[1] - aliastriangleparms.b->v[1] ) * ( aliastriangleparms.a->v[0] - aliastriangleparms.c->v[0] ) - @@ -134,27 +136,27 @@ void R_DrawTriangle( void ) dv0_ab = aliastriangleparms.a->u - aliastriangleparms.b->u; dv1_ab = aliastriangleparms.a->v - aliastriangleparms.b->v; - if ( !( dv0_ab | dv1_ab ) ) + if( !( dv0_ab | dv1_ab )) return; dv0_ac = aliastriangleparms.a->u - aliastriangleparms.c->u; dv1_ac = aliastriangleparms.a->v - aliastriangleparms.c->v; - if ( !( dv0_ac | dv1_ac ) ) + if( !( dv0_ac | dv1_ac )) return; d_xdenom = ( dv0_ac * dv1_ab ) - ( dv0_ab * dv1_ac ); - if ( d_xdenom < 0 ) + if( d_xdenom < 0 ) { a_spans = spans; - r_p0[0] = aliastriangleparms.a->u; // u - r_p0[1] = aliastriangleparms.a->v; // v - r_p0[2] = aliastriangleparms.a->s; // s - r_p0[3] = aliastriangleparms.a->t; // t - r_p0[4] = aliastriangleparms.a->l; // light - r_p0[5] = aliastriangleparms.a->zi; // iz + r_p0[0] = aliastriangleparms.a->u; // u + r_p0[1] = aliastriangleparms.a->v; // v + r_p0[2] = aliastriangleparms.a->s; // s + r_p0[3] = aliastriangleparms.a->t; // t + r_p0[4] = aliastriangleparms.a->l; // light + r_p0[5] = aliastriangleparms.a->zi; // iz r_p1[0] = aliastriangleparms.b->u; r_p1[1] = aliastriangleparms.b->v; @@ -170,8 +172,8 @@ void R_DrawTriangle( void ) r_p2[4] = aliastriangleparms.c->l; r_p2[5] = aliastriangleparms.c->zi; - R_PolysetSetEdgeTable (); - R_RasterizeAliasPolySmooth (); + R_PolysetSetEdgeTable(); + R_RasterizeAliasPolySmooth(); } } @@ -188,7 +190,7 @@ static inline qboolean R_DrawCheckBounds( pixel_t *lptex ) static inline qboolean R_PolysetCheckBounds( pixel_t *lptex, int lsfrac, int ltfrac, int lcount ) { - pixel_t *start, *end; + pixel_t *start, *end; start = r_affinetridesc.pskin; end = skinend; @@ -196,10 +198,10 @@ static inline qboolean R_PolysetCheckBounds( pixel_t *lptex, int lsfrac, int ltf if( lptex - start < 0 || lptex - end >= 0 ) return false; - if( !(--lcount) ) + if( !( --lcount )) return true; - lptex = lptex + a_ststepxwhole * lcount + ((lsfrac + ( a_sstepxfrac * lcount)) >> 16) + ((ltfrac + (a_tstepxfrac * lcount)) >> 16) * r_affinetridesc.skinwidth; + lptex = lptex + a_ststepxwhole * lcount + (( lsfrac + ( a_sstepxfrac * lcount )) >> 16 ) + (( ltfrac + ( a_tstepxfrac * lcount )) >> 16 ) * r_affinetridesc.skinwidth; if( lptex - start < 0 || lptex - end >= 0 ) return false; @@ -214,7 +216,7 @@ static inline qboolean R_PolysetCheckBounds( pixel_t *lptex, int lsfrac, int ltf R_PolysetScanLeftEdge_C ==================== */ -qboolean R_PolysetScanLeftEdge_C(int height) +qboolean R_PolysetScanLeftEdge_C( int height ) { do { @@ -226,14 +228,14 @@ qboolean R_PolysetScanLeftEdge_C(int height) d_pedgespanpackage->sfrac = d_sfrac; d_pedgespanpackage->tfrac = d_tfrac; - // FIXME: need to clamp l, s, t, at both ends? + // FIXME: need to clamp l, s, t, at both ends? d_pedgespanpackage->light = d_light; d_pedgespanpackage->zi = d_zi; d_pedgespanpackage++; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_pdest += d_pdestextrastep; d_pz += d_pzextrastep; @@ -245,7 +247,7 @@ qboolean R_PolysetScanLeftEdge_C(int height) d_sfrac &= 0xFFFF; d_tfrac += d_tfracextrastep; - if (d_tfrac & 0x10000) + if( d_tfrac & 0x10000 ) { d_ptex += r_affinetridesc.skinwidth; d_tfrac &= 0xFFFF; @@ -264,7 +266,7 @@ qboolean R_PolysetScanLeftEdge_C(int height) d_ptex += d_sfrac >> 16; d_sfrac &= 0xFFFF; d_tfrac += d_tfracbasestep; - if (d_tfrac & 0x10000) + if( d_tfrac & 0x10000 ) { d_ptex += r_affinetridesc.skinwidth; d_tfrac &= 0xFFFF; @@ -272,7 +274,8 @@ qboolean R_PolysetScanLeftEdge_C(int height) d_light += d_lightbasestep; d_zi += d_zibasestep; } - } while (--height); + } + while( --height ); return true; } @@ -286,28 +289,28 @@ quotient must fit in 32 bits. FIXME: GET RID OF THIS! (FloorDivMod) ==================== */ -static void FloorDivMod (float numer, float denom, int *quotient, - int *rem) +static void FloorDivMod( float numer, float denom, int *quotient, + int *rem ) { - int q, r; - float x; + int q, r; + float x; - if (numer >= 0.0f) + if( numer >= 0.0f ) { - x = floor(numer / denom); + x = floor( numer / denom ); q = (int)x; - r = (int)floor(numer - (x * denom)); + r = (int)floor( numer - ( x * denom )); } else { - // - // perform operations with positive values, and fix mod to make floor-based - // - x = floor(-numer / denom); + // + // perform operations with positive values, and fix mod to make floor-based + // + x = floor( -numer / denom ); q = -(int)x; - r = (int)floor(-numer - (x * denom)); - if (r != 0) + r = (int)floor( -numer - ( x * denom )); + if( r != 0 ) { q--; r = (int)denom - r; @@ -339,12 +342,12 @@ static void FloorDivMod (float numer, float denom, int *quotient, R_PolysetSetUpForLineScan ==================== */ -static void R_PolysetSetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv, - fixed8_t endvertu, fixed8_t endvertv) +static void R_PolysetSetUpForLineScan( fixed8_t startvertu, fixed8_t startvertv, + fixed8_t endvertu, fixed8_t endvertv ) { - float dm, dn; - int tm, tn; - adivtab_t *ptemp; + float dm, dn; + int tm, tn; + adivtab_t *ptemp; // TODO: implement x86 version @@ -353,10 +356,10 @@ static void R_PolysetSetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv, tm = endvertu - startvertu; tn = endvertv - startvertv; - if (((tm <= 16) && (tm >= -15)) && - ((tn <= 16) && (tn >= -15))) + if((( tm <= 16 ) && ( tm >= -15 )) + && (( tn <= 16 ) && ( tn >= -15 ))) { - ptemp = &adivtab[((tm+15) << 5) + (tn+15)]; + ptemp = &adivtab[(( tm + 15 ) << 5 ) + ( tn + 15 )]; ubasestep = ptemp->quotient; erroradjustup = ptemp->remainder; erroradjustdown = tn; @@ -366,7 +369,7 @@ static void R_PolysetSetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv, dm = tm; dn = tn; - FloorDivMod (dm, dn, &ubasestep, &erroradjustup); + FloorDivMod( dm, dn, &ubasestep, &erroradjustup ); erroradjustdown = dn; } @@ -379,10 +382,10 @@ static void R_PolysetSetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv, R_PolysetCalcGradients ================ */ -qboolean R_PolysetCalcGradients (int skinwidth) +qboolean R_PolysetCalcGradients( int skinwidth ) { - float xstepdenominv, ystepdenominv, t0, t1; - float p01_minus_p21, p11_minus_p21, p00_minus_p20, p10_minus_p20; + float xstepdenominv, ystepdenominv, t0, t1; + float p01_minus_p21, p11_minus_p21, p00_minus_p20, p10_minus_p20; p00_minus_p20 = r_p0[0] - r_p2[0]; p01_minus_p21 = r_p0[1] - r_p2[1]; @@ -393,7 +396,7 @@ qboolean R_PolysetCalcGradients (int skinwidth) printf("%d %d %d %d %d %d\n" , r_p0[0], r_p0[1], r_p0[2] >> 16, r_p0[3] >> 16, r_p0[4], r_p0[5]); printf("%d %d %d %d %d %d\n" , r_p1[0], r_p1[1], r_p1[2] >> 16, r_p1[3] >> 16, r_p1[4], r_p1[5]); printf("%d %d %d %d %d %d\n\n", r_p2[0], r_p2[1], r_p2[2] >> 16, r_p2[3] >> 16, r_p2[4], r_p2[5]); -*/ + */ xstepdenominv = 1.0f / (float)d_xdenom; ystepdenominv = -xstepdenominv; @@ -404,39 +407,39 @@ qboolean R_PolysetCalcGradients (int skinwidth) t0 = r_p0[4] - r_p2[4]; t1 = r_p1[4] - r_p2[4]; r_lstepx = (int) - ceil((t1 * p01_minus_p21 - t0 * p11_minus_p21) * xstepdenominv); + ceil(( t1 * p01_minus_p21 - t0 * p11_minus_p21 ) * xstepdenominv ); r_lstepy = (int) - ceil((t1 * p00_minus_p20 - t0 * p10_minus_p20) * ystepdenominv); + ceil(( t1 * p00_minus_p20 - t0 * p10_minus_p20 ) * ystepdenominv ); t0 = r_p0[2] - r_p2[2]; t1 = r_p1[2] - r_p2[2]; - r_sstepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) * - xstepdenominv); - r_sstepy = (int)((t1 * p00_minus_p20 - t0* p10_minus_p20) * - ystepdenominv); + r_sstepx = (int)(( t1 * p01_minus_p21 - t0 * p11_minus_p21 ) + * xstepdenominv ); + r_sstepy = (int)(( t1 * p00_minus_p20 - t0 * p10_minus_p20 ) + * ystepdenominv ); t0 = r_p0[3] - r_p2[3]; t1 = r_p1[3] - r_p2[3]; - r_tstepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) * - xstepdenominv); - r_tstepy = (int)((t1 * p00_minus_p20 - t0 * p10_minus_p20) * - ystepdenominv); + r_tstepx = (int)(( t1 * p01_minus_p21 - t0 * p11_minus_p21 ) + * xstepdenominv ); + r_tstepy = (int)(( t1 * p00_minus_p20 - t0 * p10_minus_p20 ) + * ystepdenominv ); t0 = r_p0[5] - r_p2[5]; t1 = r_p1[5] - r_p2[5]; - r_zistepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) * - xstepdenominv); - r_zistepy = (int)((t1 * p00_minus_p20 - t0 * p10_minus_p20) * - ystepdenominv); + r_zistepx = (int)(( t1 * p01_minus_p21 - t0 * p11_minus_p21 ) + * xstepdenominv ); + r_zistepy = (int)(( t1 * p00_minus_p20 - t0 * p10_minus_p20 ) + * ystepdenominv ); { a_sstepxfrac = r_sstepx & 0xFFFF; a_tstepxfrac = r_tstepx & 0xFFFF; } - a_ststepxwhole = skinwidth * (r_tstepx >> 16) + (r_sstepx >> 16); + a_ststepxwhole = skinwidth * ( r_tstepx >> 16 ) + ( r_sstepx >> 16 ); - skinend = (pixel_t*)r_affinetridesc.pskin + r_affinetridesc.skinwidth * r_affinetridesc.skinheight; + skinend = (pixel_t *)r_affinetridesc.pskin + r_affinetridesc.skinwidth * r_affinetridesc.skinheight; return true; } @@ -446,22 +449,22 @@ qboolean R_PolysetCalcGradients (int skinwidth) R_PolysetDrawSpans8 ================ */ -void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage) +void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage ) { - int lcount; - pixel_t *lpdest; - pixel_t *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; + int lcount; + pixel_t *lpdest; + pixel_t *lptex; + int lsfrac, ltfrac; + int llight; + int lzi; + short *lpz; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -471,7 +474,7 @@ void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { lpdest = pspanpackage->pdest; lptex = pspanpackage->ptex; @@ -482,26 +485,26 @@ void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage) lzi = pspanpackage->zi; pspanpackage++; #if BOUNDCHECK_MODE == 0 - if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount ) ) + if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount )) continue; #endif do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { #if BOUNDCHECK_MODE == 1 - if( !R_DrawCheckBounds( lptex ) ) + if( !R_DrawCheckBounds( lptex )) return; #endif - pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )]; - int alpha = vid.alpha; - temp = BLEND_COLOR(temp, vid.color); + pixel_t temp = *lptex; // vid.colormap[*lptex + ( llight & 0xFF00 )]; + int alpha = vid.alpha; + temp = BLEND_COLOR( temp, vid.color ); if( alpha == 7 ) *lpdest = temp; - else if(alpha) - *lpdest = BLEND_ALPHA(alpha,temp,*lpdest);//vid.alphamap[temp+ *lpdest*256]; + else if( alpha ) + *lpdest = BLEND_ALPHA( alpha, temp, *lpdest ); // vid.alphamap[temp+ *lpdest*256]; } lpdest++; lzi += r_zistepx; @@ -512,15 +515,18 @@ void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage) lptex += lsfrac >> 16; lsfrac &= 0xFFFF; ltfrac += a_tstepxfrac; - if (ltfrac & 0x10000) + if( ltfrac & 0x10000 ) { lptex += r_affinetridesc.skinwidth; ltfrac &= 0xFFFF; } - } while (--lcount); + } + while( --lcount ); } - else pspanpackage++; - } while (pspanpackage->count != -999999); + else + pspanpackage++; + } + while( pspanpackage->count != -999999 ); } @@ -529,22 +535,22 @@ void R_PolysetDrawSpansBlended( spanpackage_t *pspanpackage) R_PolysetDrawSpans8 ================ */ -void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage) +void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage ) { - int lcount; - pixel_t *lpdest; - pixel_t *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; + int lcount; + pixel_t *lpdest; + pixel_t *lptex; + int lsfrac, ltfrac; + int llight; + int lzi; + short *lpz; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -554,7 +560,7 @@ void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { lpdest = pspanpackage->pdest; lptex = pspanpackage->ptex; @@ -565,23 +571,23 @@ void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage) lzi = pspanpackage->zi; pspanpackage++; #if BOUNDCHECK_MODE == 0 - if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount ) ) + if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount )) continue; #endif do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { #if BOUNDCHECK_MODE == 1 - if( !R_DrawCheckBounds( lptex ) ) + if( !R_DrawCheckBounds( lptex )) return; #endif - pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )]; - temp = BLEND_COLOR(temp, vid.color); + pixel_t temp = *lptex; // vid.colormap[*lptex + ( llight & 0xFF00 )]; + temp = BLEND_COLOR( temp, vid.color ); - *lpdest = BLEND_ADD(temp,*lpdest); + *lpdest = BLEND_ADD( temp, *lpdest ); } lpdest++; @@ -593,15 +599,18 @@ void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage) lptex += lsfrac >> 16; lsfrac &= 0xFFFF; ltfrac += a_tstepxfrac; - if (ltfrac & 0x10000) + if( ltfrac & 0x10000 ) { lptex += r_affinetridesc.skinwidth; ltfrac &= 0xFFFF; } - } while (--lcount); + } + while( --lcount ); } - else pspanpackage++; - } while (pspanpackage->count != -999999); + else + pspanpackage++; + } + while( pspanpackage->count != -999999 ); } @@ -610,22 +619,22 @@ void R_PolysetDrawSpansAdditive( spanpackage_t *pspanpackage) R_PolysetDrawSpans8 ================ */ -void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage) +void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage ) { - int lcount; - pixel_t *lpdest; - pixel_t *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; + int lcount; + pixel_t *lpdest; + pixel_t *lptex; + int lsfrac, ltfrac; + int llight; + int lzi; + short *lpz; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -635,7 +644,7 @@ void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { lpdest = pspanpackage->pdest; lptex = pspanpackage->ptex; @@ -646,21 +655,21 @@ void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage) lzi = pspanpackage->zi; pspanpackage++; #if BOUNDCHECK_MODE == 0 - if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount ) ) + if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount )) continue; #endif do { - //if ((lzi >> 16) >= *lpz) + // if ((lzi >> 16) >= *lpz) { #if BOUNDCHECK_MODE == 1 - if( !R_DrawCheckBounds( lptex ) ) + if( !R_DrawCheckBounds( lptex )) return; #endif - pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )]; - temp = BLEND_COLOR(temp, vid.color); + pixel_t temp = *lptex; // vid.colormap[*lptex + ( llight & 0xFF00 )]; + temp = BLEND_COLOR( temp, vid.color ); - *lpdest = BLEND_ADD(temp,*lpdest); + *lpdest = BLEND_ADD( temp, *lpdest ); } lpdest++; @@ -672,16 +681,18 @@ void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage) lptex += lsfrac >> 16; lsfrac &= 0xFFFF; ltfrac += a_tstepxfrac; - if (ltfrac & 0x10000) + if( ltfrac & 0x10000 ) { lptex += r_affinetridesc.skinwidth; ltfrac &= 0xFFFF; } - } while (--lcount); + } + while( --lcount ); } else pspanpackage++; - } while (pspanpackage->count != -999999); + } + while( pspanpackage->count != -999999 ); } @@ -690,22 +701,22 @@ void R_PolysetDrawSpansGlow( spanpackage_t *pspanpackage) R_PolysetDrawSpans8 ================ */ -void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage) +void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage ) { - int lcount; - pixel_t *lpdest; - pixel_t *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; + int lcount; + pixel_t *lpdest; + pixel_t *lptex; + int lsfrac, ltfrac; + int llight; + int lzi; + short *lpz; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -715,7 +726,7 @@ void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { lpdest = pspanpackage->pdest; @@ -727,26 +738,26 @@ void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage) lzi = pspanpackage->zi; pspanpackage++; #if BOUNDCHECK_MODE == 0 - if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount ) ) + if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount )) continue; #endif do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { #if BOUNDCHECK_MODE == 1 - if( !R_DrawCheckBounds( lptex ) ) + if( !R_DrawCheckBounds( lptex )) return; #endif - pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )]; + pixel_t temp = *lptex; // vid.colormap[*lptex + ( llight & 0xFF00 )]; - int alpha = temp >> 13; + int alpha = temp >> 13; temp = temp << 3; - temp = BLEND_COLOR(temp, vid.color); + temp = BLEND_COLOR( temp, vid.color ); if( alpha == 7 ) *lpdest = temp; - else if(alpha) - *lpdest = BLEND_ALPHA(alpha,temp,*lpdest);//vid.alphamap[temp+ *lpdest*256]; + else if( alpha ) + *lpdest = BLEND_ALPHA( alpha, temp, *lpdest ); // vid.alphamap[temp+ *lpdest*256]; } lpdest++; lzi += r_zistepx; @@ -757,16 +768,18 @@ void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage) lptex += lsfrac >> 16; lsfrac &= 0xFFFF; ltfrac += a_tstepxfrac; - if (ltfrac & 0x10000) + if( ltfrac & 0x10000 ) { lptex += r_affinetridesc.skinwidth; ltfrac &= 0xFFFF; } - } while (--lcount); + } + while( --lcount ); } else pspanpackage++; - } while (pspanpackage->count != -999999); + } + while( pspanpackage->count != -999999 ); } @@ -776,22 +789,22 @@ void R_PolysetDrawSpansTextureBlended( spanpackage_t *pspanpackage) R_PolysetDrawSpans8 ================ */ -void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage) +void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage ) { - int lcount; - pixel_t *lpdest; - pixel_t *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; + int lcount; + pixel_t *lpdest; + pixel_t *lptex; + int lsfrac, ltfrac; + int llight; + int lzi; + short *lpz; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -801,7 +814,7 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { lpdest = pspanpackage->pdest; lptex = pspanpackage->ptex; @@ -813,15 +826,15 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage) do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { - pixel_t temp = *lptex;//vid.colormap[*lptex + ( llight & 0xFF00 )]; + pixel_t temp = *lptex; // vid.colormap[*lptex + ( llight & 0xFF00 )]; - int alpha = tr.blend * 7; + int alpha = tr.blend * 7; if( alpha == 7 ) *lpdest = temp; - else if(alpha) - *lpdest = BLEND_ALPHA(alpha,temp,*lpdest);//vid.alphamap[temp+ *lpdest*256]; + else if( alpha ) + *lpdest = BLEND_ALPHA( alpha, temp, *lpdest ); // vid.alphamap[temp+ *lpdest*256]; } lpdest++; lzi += r_zistepx; @@ -832,31 +845,33 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage) lptex += lsfrac >> 16; lsfrac &= 0xFFFF; ltfrac += a_tstepxfrac; - if (ltfrac & 0x10000) + if( ltfrac & 0x10000 ) { lptex += r_affinetridesc.skinwidth; ltfrac &= 0xFFFF; } - } while (--lcount); + } + while( --lcount ); } pspanpackage++; - } while (pspanpackage->count != -999999); + } + while( pspanpackage->count != -999999 ); } -void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage) +void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage ) { - int lcount; - pixel_t *lpdest; - int lzi; - short *lpz; + int lcount; + pixel_t *lpdest; + int lzi; + short *lpz; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -866,7 +881,7 @@ void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { lpdest = pspanpackage->pdest; lpz = pspanpackage->pz; @@ -874,36 +889,38 @@ void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage) do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { - *lpdest = BLEND_ALPHA(2,r_aliasblendcolor,*lpdest);//vid.alphamap[r_aliasblendcolor + *lpdest*256]; + *lpdest = BLEND_ALPHA( 2, r_aliasblendcolor, *lpdest ); // vid.alphamap[r_aliasblendcolor + *lpdest*256]; } lpdest++; lzi += r_zistepx; lpz++; - } while (--lcount); + } + while( --lcount ); } pspanpackage++; - } while (pspanpackage->count != -999999); + } + while( pspanpackage->count != -999999 ); } -void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage) +void R_PolysetDrawSpans8_66( spanpackage_t *pspanpackage ) { - int lcount; - pixel_t *lpdest; - pixel_t *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; + int lcount; + pixel_t *lpdest; + pixel_t *lptex; + int lsfrac, ltfrac; + int llight; + int lzi; + short *lpz; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -913,7 +930,7 @@ void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { lpdest = pspanpackage->pdest; lptex = pspanpackage->ptex; @@ -925,11 +942,11 @@ void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage) do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { int temp = vid.colormap[*lptex + ( llight & 0xFF00 )]; - *lpdest = BLEND_ALPHA(5,temp,*lpdest);//vid.alphamap[temp*256 + *lpdest]; + *lpdest = BLEND_ALPHA( 5, temp, *lpdest ); // vid.alphamap[temp*256 + *lpdest]; *lpz = lzi >> 16; } lpdest++; @@ -941,31 +958,33 @@ void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage) lptex += lsfrac >> 16; lsfrac &= 0xFFFF; ltfrac += a_tstepxfrac; - if (ltfrac & 0x10000) + if( ltfrac & 0x10000 ) { lptex += r_affinetridesc.skinwidth; ltfrac &= 0xFFFF; } - } while (--lcount); + } + while( --lcount ); } pspanpackage++; - } while (pspanpackage->count != -999999); + } + while( pspanpackage->count != -999999 ); } -static void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage) +static void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage ) { - int lcount; - pixel_t *lpdest; - int lzi; - short *lpz; + int lcount; + pixel_t *lpdest; + int lzi; + short *lpz; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -975,7 +994,7 @@ static void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { lpdest = pspanpackage->pdest; lpz = pspanpackage->pz; @@ -983,30 +1002,32 @@ static void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage) do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { - *lpdest = BLEND_ALPHA(5,r_aliasblendcolor,*lpdest);//vid.alphamap[r_aliasblendcolor*256 + *lpdest]; + *lpdest = BLEND_ALPHA( 5, r_aliasblendcolor, *lpdest ); // vid.alphamap[r_aliasblendcolor*256 + *lpdest]; } lpdest++; lzi += r_zistepx; lpz++; - } while (--lcount); + } + while( --lcount ); } pspanpackage++; - } while (pspanpackage->count != -999999); + } + while( pspanpackage->count != -999999 ); } -void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage) +void R_PolysetDrawSpans8_Opaque( spanpackage_t *pspanpackage ) { - int lcount; + int lcount; do { lcount = d_aspancount - pspanpackage->count; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -1016,14 +1037,14 @@ void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { - int lsfrac, ltfrac; - pixel_t *lpdest; - pixel_t *lptex; - int llight; - int lzi; - short *lpz; + int lsfrac, ltfrac; + pixel_t *lpdest; + pixel_t *lptex; + int llight; + int lzi; + short *lpz; lpdest = pspanpackage->pdest; lptex = pspanpackage->ptex; @@ -1035,14 +1056,14 @@ void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage) do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { -//PGM +// PGM /*if(r_newrefdef.rdflags & RDF_IRGOGGLES && RI.currententity->flags & RF_IR_VISIBLE) *lpdest = ((byte *)vid.colormap)[irtable[*lptex]]; else*/ - *lpdest = ((byte *)vid.colormap)[*lptex + (llight & 0xFF00)]; -//PGM + *lpdest = ((byte *)vid.colormap )[*lptex + ( llight & 0xFF00 )]; +// PGM *lpz = lzi >> 16; } lpdest++; @@ -1054,25 +1075,27 @@ void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage) lptex += lsfrac >> 16; lsfrac &= 0xFFFF; ltfrac += a_tstepxfrac; - if (ltfrac & 0x10000) + if( ltfrac & 0x10000 ) { lptex += r_affinetridesc.skinwidth; ltfrac &= 0xFFFF; } - } while (--lcount); + } + while( --lcount ); } pspanpackage++; - } while (pspanpackage->count != -999999); + } + while( pspanpackage->count != -999999 ); } -void R_PolysetFillSpans8 (spanpackage_t *pspanpackage) +void R_PolysetFillSpans8( spanpackage_t *pspanpackage ) { - //int color; - int lcount; + // int color; + int lcount; // FIXME: do z buffering - //color = d_aflatcolor++ * 10; + // color = d_aflatcolor++ * 10; do { @@ -1080,7 +1103,7 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage) // d_ptex + a_ststepxwhole * lcount + ((a_sstepxfrac * lcount) >> 16) + ((a_tstepxfrac * lcount) >> 16)*r_affinetridesc.skinwidth; errorterm += erroradjustup; - if (errorterm >= 0) + if( errorterm >= 0 ) { d_aspancount += d_countextrastep; errorterm -= erroradjustdown; @@ -1090,14 +1113,14 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage) d_aspancount += ubasestep; } - if (lcount) + if( lcount ) { - int lsfrac, ltfrac; - pixel_t *lpdest; - pixel_t *lptex; - int llight; - int lzi; - short *lpz; + int lsfrac, ltfrac; + pixel_t *lpdest; + pixel_t *lptex; + int llight; + int lzi; + short *lpz; lpdest = pspanpackage->pdest; @@ -1107,22 +1130,22 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage) ltfrac = pspanpackage->tfrac; llight = pspanpackage->light; lzi = pspanpackage->zi; - pspanpackage ++; + pspanpackage++; #if BOUNDCHECK_MODE == 0 - if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount ) ) + if( !R_PolysetCheckBounds( lptex, lsfrac, ltfrac, lcount )) continue; #endif do { - if ((lzi >> 16) >= *lpz) + if(( lzi >> 16 ) >= *lpz ) { #if BOUNDCHECK_MODE == 1 - if( !R_DrawCheckBounds( lptex ) ) + if( !R_DrawCheckBounds( lptex )) return; #endif pixel_t src = *lptex; - *lpdest = vid.colormap[(src >> 3) | ((llight & 0x1F00) << 5)] | (src & 7); + *lpdest = vid.colormap[( src >> 3 ) | (( llight & 0x1F00 ) << 5 )] | ( src & 7 ); *lpz = lzi >> 16; } lpdest++; @@ -1134,15 +1157,18 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage) lptex += lsfrac >> 16; lsfrac &= 0xFFFF; ltfrac += a_tstepxfrac; - if (ltfrac & 0x10000) + if( ltfrac & 0x10000 ) { lptex += r_affinetridesc.skinwidth; ltfrac &= 0xFFFF; } - } while (--lcount); + } + while( --lcount ); } - else pspanpackage++; - } while (pspanpackage->count != -999999); + else + pspanpackage++; + } + while( pspanpackage->count != -999999 ); } /* @@ -1150,11 +1176,11 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage) R_RasterizeAliasPolySmooth ================ */ -void R_RasterizeAliasPolySmooth (void) +void R_RasterizeAliasPolySmooth( void ) { - int initialleftheight, initialrightheight; - int *plefttop, *prighttop, *pleftbottom, *prightbottom; - int working_lstepx, originalcount; + int initialleftheight, initialrightheight; + int *plefttop, *prighttop, *pleftbottom, *prightbottom; + int working_lstepx, originalcount; plefttop = pedgetable->pleftedgevert0; prighttop = pedgetable->prightedgevert0; @@ -1169,7 +1195,7 @@ void R_RasterizeAliasPolySmooth (void) // set the s, t, and light gradients, which are consistent across the triangle // because being a triangle, things are affine // - if( !R_PolysetCalcGradients (r_affinetridesc.skinwidth) ) + if( !R_PolysetCalcGradients( r_affinetridesc.skinwidth )) return; // // rasterize the polygon @@ -1183,8 +1209,8 @@ void R_RasterizeAliasPolySmooth (void) ystart = plefttop[1]; d_aspancount = plefttop[0] - prighttop[0]; - d_ptex = (pixel_t*)r_affinetridesc.pskin + (plefttop[2] >> 16) + - (plefttop[3] >> 16) * r_affinetridesc.skinwidth; + d_ptex = (pixel_t *)r_affinetridesc.pskin + ( plefttop[2] >> 16 ) + + ( plefttop[3] >> 16 ) * r_affinetridesc.skinwidth; { d_sfrac = plefttop[2] & 0xFFFF; @@ -1193,11 +1219,11 @@ void R_RasterizeAliasPolySmooth (void) d_light = plefttop[4]; d_zi = plefttop[5]; - d_pdest = (pixel_t *)d_viewbuffer + - ystart * r_screenwidth + plefttop[0]; + d_pdest = (pixel_t *)d_viewbuffer + + ystart * r_screenwidth + plefttop[0]; d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0]; - if (initialleftheight == 1) + if( initialleftheight == 1 ) { d_pedgespanpackage->pdest = d_pdest; @@ -1208,15 +1234,15 @@ void R_RasterizeAliasPolySmooth (void) d_pedgespanpackage->sfrac = d_sfrac; d_pedgespanpackage->tfrac = d_tfrac; - // FIXME: need to clamp l, s, t, at both ends? + // FIXME: need to clamp l, s, t, at both ends? d_pedgespanpackage->light = d_light; d_pedgespanpackage->zi = d_zi; d_pedgespanpackage++; } else { - R_PolysetSetUpForLineScan(plefttop[0], plefttop[1], - pleftbottom[0], pleftbottom[1]); + R_PolysetSetUpForLineScan( plefttop[0], plefttop[1], + pleftbottom[0], pleftbottom[1] ); { d_pzbasestep = d_zwidth + ubasestep; @@ -1226,39 +1252,39 @@ void R_RasterizeAliasPolySmooth (void) d_pdestbasestep = r_screenwidth + ubasestep; d_pdestextrastep = d_pdestbasestep + 1; - // TODO: can reuse partial expressions here + // TODO: can reuse partial expressions here - // for negative steps in x along left edge, bias toward overflow rather than - // underflow (sort of turning the floor () we did in the gradient calcs into - // ceil (), but plus a little bit) - if (ubasestep < 0) + // for negative steps in x along left edge, bias toward overflow rather than + // underflow (sort of turning the floor () we did in the gradient calcs into + // ceil (), but plus a little bit) + if( ubasestep < 0 ) working_lstepx = r_lstepx - 1; else working_lstepx = r_lstepx; d_countextrastep = ubasestep + 1; - d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) + - ((r_tstepy + r_tstepx * ubasestep) >> 16) * - r_affinetridesc.skinwidth; + d_ptexbasestep = (( r_sstepy + r_sstepx * ubasestep ) >> 16 ) + + (( r_tstepy + r_tstepx * ubasestep ) >> 16 ) + * r_affinetridesc.skinwidth; { - d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF; - d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF; + d_sfracbasestep = ( r_sstepy + r_sstepx * ubasestep ) & 0xFFFF; + d_tfracbasestep = ( r_tstepy + r_tstepx * ubasestep ) & 0xFFFF; } d_lightbasestep = r_lstepy + working_lstepx * ubasestep; d_zibasestep = r_zistepy + r_zistepx * ubasestep; - d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) + - ((r_tstepy + r_tstepx * d_countextrastep) >> 16) * - r_affinetridesc.skinwidth; + d_ptexextrastep = (( r_sstepy + r_sstepx * d_countextrastep ) >> 16 ) + + (( r_tstepy + r_tstepx * d_countextrastep ) >> 16 ) + * r_affinetridesc.skinwidth; { - d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) & 0xFFFF; - d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) & 0xFFFF; + d_sfracextrastep = ( r_sstepy + r_sstepx * d_countextrastep ) & 0xFFFF; + d_tfracextrastep = ( r_tstepy + r_tstepx * d_countextrastep ) & 0xFFFF; } d_lightextrastep = d_lightbasestep + working_lstepx; d_ziextrastep = d_zibasestep + r_zistepx; { - if(!R_PolysetScanLeftEdge_C(initialleftheight)) + if( !R_PolysetScanLeftEdge_C( initialleftheight )) return; } } @@ -1266,9 +1292,9 @@ void R_RasterizeAliasPolySmooth (void) // // scan out the bottom part of the left edge, if it exists // - if (pedgetable->numleftedges == 2) + if( pedgetable->numleftedges == 2 ) { - int height; + int height; plefttop = pleftbottom; pleftbottom = pedgetable->pleftedgevert2; @@ -1279,8 +1305,8 @@ void R_RasterizeAliasPolySmooth (void) ystart = plefttop[1]; d_aspancount = plefttop[0] - prighttop[0]; - d_ptex = (pixel_t*)r_affinetridesc.pskin + (plefttop[2] >> 16) + - (plefttop[3] >> 16) * r_affinetridesc.skinwidth; + d_ptex = (pixel_t *)r_affinetridesc.pskin + ( plefttop[2] >> 16 ) + + ( plefttop[3] >> 16 ) * r_affinetridesc.skinwidth; d_sfrac = 0; d_tfrac = 0; @@ -1292,7 +1318,7 @@ void R_RasterizeAliasPolySmooth (void) - if (height == 1) + if( height == 1 ) { d_pedgespanpackage->pdest = d_pdest; d_pedgespanpackage->pz = d_pz; @@ -1302,15 +1328,15 @@ void R_RasterizeAliasPolySmooth (void) d_pedgespanpackage->sfrac = d_sfrac; d_pedgespanpackage->tfrac = d_tfrac; - // FIXME: need to clamp l, s, t, at both ends? + // FIXME: need to clamp l, s, t, at both ends? d_pedgespanpackage->light = d_light; d_pedgespanpackage->zi = d_zi; d_pedgespanpackage++; } else { - R_PolysetSetUpForLineScan(plefttop[0], plefttop[1], - pleftbottom[0], pleftbottom[1]); + R_PolysetSetUpForLineScan( plefttop[0], plefttop[1], + pleftbottom[0], pleftbottom[1] ); d_pdestbasestep = r_screenwidth + ubasestep; d_pdestextrastep = d_pdestbasestep + 1; @@ -1320,34 +1346,34 @@ void R_RasterizeAliasPolySmooth (void) d_pzextrastep = d_pzbasestep + 1; } - if (ubasestep < 0) + if( ubasestep < 0 ) working_lstepx = r_lstepx - 1; else working_lstepx = r_lstepx; d_countextrastep = ubasestep + 1; - d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) + - ((r_tstepy + r_tstepx * ubasestep) >> 16) * - r_affinetridesc.skinwidth; + d_ptexbasestep = (( r_sstepy + r_sstepx * ubasestep ) >> 16 ) + + (( r_tstepy + r_tstepx * ubasestep ) >> 16 ) + * r_affinetridesc.skinwidth; { - d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF; - d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF; + d_sfracbasestep = ( r_sstepy + r_sstepx * ubasestep ) & 0xFFFF; + d_tfracbasestep = ( r_tstepy + r_tstepx * ubasestep ) & 0xFFFF; } d_lightbasestep = r_lstepy + working_lstepx * ubasestep; d_zibasestep = r_zistepy + r_zistepx * ubasestep; - d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) + - ((r_tstepy + r_tstepx * d_countextrastep) >> 16) * - r_affinetridesc.skinwidth; + d_ptexextrastep = (( r_sstepy + r_sstepx * d_countextrastep ) >> 16 ) + + (( r_tstepy + r_tstepx * d_countextrastep ) >> 16 ) + * r_affinetridesc.skinwidth; { - d_sfracextrastep = (r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF; - d_tfracextrastep = (r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF; + d_sfracextrastep = ( r_sstepy + r_sstepx * d_countextrastep ) & 0xFFFF; + d_tfracextrastep = ( r_tstepy + r_tstepx * d_countextrastep ) & 0xFFFF; } d_lightextrastep = d_lightbasestep + working_lstepx; d_ziextrastep = d_zibasestep + r_zistepx; { - if(!R_PolysetScanLeftEdge_C(height)) + if( !R_PolysetScanLeftEdge_C( height )) return; } } @@ -1357,20 +1383,20 @@ void R_RasterizeAliasPolySmooth (void) // count field d_pedgespanpackage = a_spans; - R_PolysetSetUpForLineScan(prighttop[0], prighttop[1], - prightbottom[0], prightbottom[1]); + R_PolysetSetUpForLineScan( prighttop[0], prighttop[1], + prightbottom[0], prightbottom[1] ); d_aspancount = 0; d_countextrastep = ubasestep + 1; originalcount = a_spans[initialrightheight].count; a_spans[initialrightheight].count = -999999; // mark end of the spanpackages - (*d_pdrawspans) (a_spans); + ( *d_pdrawspans )( a_spans ); // scan out the bottom part of the right edge, if it exists - if (pedgetable->numrightedges == 2) + if( pedgetable->numrightedges == 2 ) { - int height; - spanpackage_t *pstart; + int height; + spanpackage_t *pstart; pstart = a_spans + initialrightheight; pstart->count = originalcount; @@ -1382,13 +1408,13 @@ void R_RasterizeAliasPolySmooth (void) height = prightbottom[1] - prighttop[1]; - R_PolysetSetUpForLineScan(prighttop[0], prighttop[1], - prightbottom[0], prightbottom[1]); + R_PolysetSetUpForLineScan( prighttop[0], prighttop[1], + prightbottom[0], prightbottom[1] ); d_countextrastep = ubasestep + 1; a_spans[initialrightheight + height].count = -999999; // mark end of the spanpackages - (*d_pdrawspans) (pstart); + ( *d_pdrawspans )( pstart ); } } @@ -1398,22 +1424,22 @@ void R_RasterizeAliasPolySmooth (void) R_PolysetSetEdgeTable ================ */ -void R_PolysetSetEdgeTable (void) +void R_PolysetSetEdgeTable( void ) { - int edgetableindex; + int edgetableindex; - edgetableindex = 0; // assume the vertices are already in - // top to bottom order + edgetableindex = 0; // assume the vertices are already in + // top to bottom order // // determine which edges are right & left, and the order in which // to rasterize them // - if (r_p0[1] >= r_p1[1]) + if( r_p0[1] >= r_p1[1] ) { - if (r_p0[1] == r_p1[1]) + if( r_p0[1] == r_p1[1] ) { - if (r_p0[1] < r_p2[1]) + if( r_p0[1] < r_p2[1] ) pedgetable = &edgetables[2]; else pedgetable = &edgetables[5]; @@ -1426,18 +1452,18 @@ void R_PolysetSetEdgeTable (void) } } - if (r_p0[1] == r_p2[1]) + if( r_p0[1] == r_p2[1] ) { - if (edgetableindex) + if( edgetableindex ) pedgetable = &edgetables[8]; else pedgetable = &edgetables[9]; return; } - else if (r_p1[1] == r_p2[1]) + else if( r_p1[1] == r_p2[1] ) { - if (edgetableindex) + if( edgetableindex ) pedgetable = &edgetables[10]; else pedgetable = &edgetables[11]; @@ -1445,10 +1471,10 @@ void R_PolysetSetEdgeTable (void) return; } - if (r_p0[1] > r_p2[1]) + if( r_p0[1] > r_p2[1] ) edgetableindex += 2; - if (r_p1[1] > r_p2[1]) + if( r_p1[1] > r_p2[1] ) edgetableindex += 4; pedgetable = &edgetables[edgetableindex]; diff --git a/ref/soft/r_rast.c b/ref/soft/r_rast.c index b0f39cd7..1c316f13 100644 --- a/ref/soft/r_rast.c +++ b/ref/soft/r_rast.c @@ -23,81 +23,81 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" -#define MAXLEFTCLIPEDGES 100 +#define MAXLEFTCLIPEDGES 100 // !!! if these are changed, they must be changed in asm_draw.h too !!! -#define FULLY_CLIPPED_CACHED 0x80000000 -#define FRAMECOUNT_MASK 0x7FFFFFFF +#define FULLY_CLIPPED_CACHED 0x80000000 +#define FRAMECOUNT_MASK 0x7FFFFFFF -unsigned int cacheoffset; +unsigned int cacheoffset; -int c_faceclip; // number of faces clipped +int c_faceclip; // number of faces clipped -clipplane_t *entity_clipplanes; -clipplane_t world_clipplanes[16]; +clipplane_t *entity_clipplanes; +clipplane_t world_clipplanes[16]; -medge_t *r_pedge; +medge_t *r_pedge; -qboolean r_leftclipped, r_rightclipped; -static qboolean makeleftedge, makerightedge; -qboolean r_nearzionly; +qboolean r_leftclipped, r_rightclipped; +static qboolean makeleftedge, makerightedge; +qboolean r_nearzionly; -int sintable[1280]; -int intsintable[1280]; -int blanktable[1280]; // PGM +int sintable[1280]; +int intsintable[1280]; +int blanktable[1280]; // PGM -mvertex_t r_leftenter, r_leftexit; -mvertex_t r_rightenter, r_rightexit; +mvertex_t r_leftenter, r_leftexit; +mvertex_t r_rightenter, r_rightexit; typedef struct { - float u,v; - int ceilv; + float u, v; + int ceilv; } evert_t; -int r_emitted; -float r_nearzi; -float r_u1, r_v1, r_lzi1; -int r_ceilv1; +int r_emitted; +float r_nearzi; +float r_u1, r_v1, r_lzi1; +int r_ceilv1; -qboolean r_lastvertvalid; -int r_skyframe; +qboolean r_lastvertvalid; +int r_skyframe; -msurface_t *r_skyfaces; -mplane_t r_skyplanes[6]; -mtexinfo_t r_skytexinfo[6]; -mvertex_t *r_skyverts; -medge_t *r_skyedges; -int *r_skysurfedges; +msurface_t *r_skyfaces; +mplane_t r_skyplanes[6]; +mtexinfo_t r_skytexinfo[6]; +mvertex_t *r_skyverts; +medge_t *r_skyedges; +int *r_skysurfedges; // I just copied this data from a box map... -int skybox_planes[12] = {2,-128, 0,-128, 2,128, 1,128, 0,128, 1,-128}; +int skybox_planes[12] = {2, -128, 0, -128, 2, 128, 1, 128, 0, 128, 1, -128}; -int box_surfedges[24] = { 1,2,3,4, -1,5,6,7, 8,9,-6,10, -2,-7,-9,11, - 12,-3,-11,-8, -12,-10,-5,-4}; -int box_edges[24] = { 1,2, 2,3, 3,4, 4,1, 1,5, 5,6, 6,2, 7,8, 8,6, 5,7, 8,3, 7,4}; +int box_surfedges[24] = { 1, 2, 3, 4, -1, 5, 6, 7, 8, 9, -6, 10, -2, -7, -9, 11, + 12, -3, -11, -8, -12, -10, -5, -4}; +int box_edges[24] = { 1, 2, 2, 3, 3, 4, 4, 1, 1, 5, 5, 6, 6, 2, 7, 8, 8, 6, 5, 7, 8, 3, 7, 4}; -int box_faces[6] = {0,0,2,2,2,0}; +int box_faces[6] = {0, 0, 2, 2, 2, 0}; -vec3_t box_vecs[6][2] = { - { {0,-1,0}, {-1,0,0} }, - { {0,1,0}, {0,0,-1} }, - { {0,-1,0}, {1,0,0} }, - { {1,0,0}, {0,0,-1} }, - { {0,-1,0}, {0,0,-1} }, - { {-1,0,0}, {0,0,-1} } +vec3_t box_vecs[6][2] = { + { {0, -1, 0}, {-1, 0, 0} }, + { {0, 1, 0}, {0, 0, -1} }, + { {0, -1, 0}, {1, 0, 0} }, + { {1, 0, 0}, {0, 0, -1} }, + { {0, -1, 0}, {0, 0, -1} }, + { {-1, 0, 0}, {0, 0, -1} } }; -float box_verts[8][3] = { - {-1,-1,-1}, - {-1,1,-1}, - {1,1,-1}, - {1,-1,-1}, - {-1,-1,1}, - {-1,1,1}, - {1,-1,1}, - {1,1,1} +float box_verts[8][3] = { + {-1, -1, -1}, + {-1, 1, -1}, + {1, 1, -1}, + {1, -1, -1}, + {-1, -1, 1}, + {-1, 1, 1}, + {1, -1, 1}, + {1, 1, 1} }; // down, west, up, north, east, south @@ -108,18 +108,18 @@ float box_verts[8][3] = { R_EmitEdge ================ */ -static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) +static void R_EmitEdge( mvertex_t *pv0, mvertex_t *pv1 ) { - edge_t *edge, *pcheck; - int u_check; - float u, u_step; - vec3_t local, transformed; - float *world; - int v, v2, ceilv0; - float scale, lzi0, u0, v0; - int side; + edge_t *edge, *pcheck; + int u_check; + float u, u_step; + vec3_t local, transformed; + float *world; + int v, v2, ceilv0; + float scale, lzi0, u0, v0; + int side; - if (r_lastvertvalid) + if( r_lastvertvalid ) { u0 = r_u1; v0 = r_v1; @@ -130,84 +130,84 @@ static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) { world = &pv0->position[0]; - // transform and project - VectorSubtract (world, tr.modelorg, local); - TransformVector (local, transformed); + // transform and project + VectorSubtract( world, tr.modelorg, local ); + TransformVector( local, transformed ); - if (transformed[2] < NEAR_CLIP) + if( transformed[2] < NEAR_CLIP ) transformed[2] = NEAR_CLIP; lzi0 = 1.0f / transformed[2]; - // FIXME: build x/yscale into transform? + // FIXME: build x/yscale into transform? scale = xscale * lzi0; - u0 = (xcenter + scale*transformed[0]); - if (u0 < RI.fvrectx_adj) + u0 = ( xcenter + scale * transformed[0] ); + if( u0 < RI.fvrectx_adj ) u0 = RI.fvrectx_adj; - if (u0 > RI.fvrectright_adj) + if( u0 > RI.fvrectright_adj ) u0 = RI.fvrectright_adj; scale = yscale * lzi0; - v0 = (ycenter - scale*transformed[1]); - if (v0 < RI.fvrecty_adj) + v0 = ( ycenter - scale * transformed[1] ); + if( v0 < RI.fvrecty_adj ) v0 = RI.fvrecty_adj; - if (v0 > RI.fvrectbottom_adj) + if( v0 > RI.fvrectbottom_adj ) v0 = RI.fvrectbottom_adj; - ceilv0 = (int) ceil(v0); + ceilv0 = (int) ceil( v0 ); } world = &pv1->position[0]; // transform and project - VectorSubtract (world, tr.modelorg, local); - TransformVector (local, transformed); + VectorSubtract( world, tr.modelorg, local ); + TransformVector( local, transformed ); - if (transformed[2] < NEAR_CLIP) + if( transformed[2] < NEAR_CLIP ) transformed[2] = NEAR_CLIP; r_lzi1 = 1.0f / transformed[2]; scale = xscale * r_lzi1; - r_u1 = (xcenter + scale*transformed[0]); - if (r_u1 < RI.fvrectx_adj) + r_u1 = ( xcenter + scale * transformed[0] ); + if( r_u1 < RI.fvrectx_adj ) r_u1 = RI.fvrectx_adj; - if (r_u1 > RI.fvrectright_adj) + if( r_u1 > RI.fvrectright_adj ) r_u1 = RI.fvrectright_adj; scale = yscale * r_lzi1; - r_v1 = (ycenter - scale*transformed[1]); - if (r_v1 < RI.fvrecty_adj) + r_v1 = ( ycenter - scale * transformed[1] ); + if( r_v1 < RI.fvrecty_adj ) r_v1 = RI.fvrecty_adj; - if (r_v1 > RI.fvrectbottom_adj) + if( r_v1 > RI.fvrectbottom_adj ) r_v1 = RI.fvrectbottom_adj; - if (r_lzi1 > lzi0) + if( r_lzi1 > lzi0 ) lzi0 = r_lzi1; - if (lzi0 > r_nearzi) // for mipmap finding + if( lzi0 > r_nearzi ) // for mipmap finding r_nearzi = lzi0; // for right edges, all we want is the effect on 1/z - if (r_nearzionly) + if( r_nearzionly ) return; r_emitted = 1; - r_ceilv1 = (int) ceil(r_v1); + r_ceilv1 = (int) ceil( r_v1 ); // create the edge - if (ceilv0 == r_ceilv1 || ceilv0 < 0 ) + if( ceilv0 == r_ceilv1 || ceilv0 < 0 ) { - // we cache unclipped horizontal edges as fully clipped - if (cacheoffset != 0x7FFFFFFF) + // we cache unclipped horizontal edges as fully clipped + if( cacheoffset != 0x7FFFFFFF ) { - cacheoffset = FULLY_CLIPPED_CACHED | - (tr.framecount & FRAMECOUNT_MASK); + cacheoffset = FULLY_CLIPPED_CACHED + | ( tr.framecount & FRAMECOUNT_MASK ); } - return; // horizontal edge + return; // horizontal edge } side = ceilv0 > r_ceilv1; @@ -218,9 +218,9 @@ static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) edge->nearzi = lzi0; - if (side == 0) + if( side == 0 ) { - // trailing edge (go from p1 to p2) + // trailing edge (go from p1 to p2) v = ceilv0; v2 = r_ceilv1 - 1; @@ -233,12 +233,12 @@ static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) edge->surfs[0] = surface_p - surfaces; edge->surfs[1] = 0; - u_step = ((r_u1 - u0) / (r_v1 - v0)); - u = u0 + ((float)v - v0) * u_step; + u_step = (( r_u1 - u0 ) / ( r_v1 - v0 )); + u = u0 + ((float)v - v0 ) * u_step; } else { - // leading edge (go from p2 to p1) + // leading edge (go from p2 to p1) v2 = ceilv0 - 1; v = r_ceilv1; @@ -251,12 +251,12 @@ static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) edge->surfs[0] = 0; edge->surfs[1] = surface_p - surfaces; - u_step = ((u0 - r_u1) / (v0 - r_v1)); - u = r_u1 + ((float)v - r_v1) * u_step; + u_step = (( u0 - r_u1 ) / ( v0 - r_v1 )); + u = r_u1 + ((float)v - r_v1 ) * u_step; } - edge->u_step = u_step*0x100000; - edge->u = u*0x100000 + 0xFFFFF; + edge->u_step = u_step * 0x100000; + edge->u = u * 0x100000 + 0xFFFFF; // we need to do this to avoid stepping off the edges if a very nearly // horizontal edge is less than epsilon above a scan, and numeric error causes @@ -269,9 +269,9 @@ static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) edge->u = x; if (edge->u > r) edge->u = r;*/ - if (edge->u < RI.vrect_x_adj_shift20) + if( edge->u < RI.vrect_x_adj_shift20 ) edge->u = RI.vrect_x_adj_shift20; - if (edge->u > RI.vrectright_adj_shift20) + if( edge->u > RI.vrectright_adj_shift20 ) edge->u = RI.vrectright_adj_shift20; @@ -279,10 +279,10 @@ static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) // sort the edge in normally // u_check = edge->u; - if (edge->surfs[0]) - u_check++; // sort trailers after leaders + if( edge->surfs[0] ) + u_check++; // sort trailers after leaders - if (!newedges[v] || newedges[v]->u >= u_check) + if( !newedges[v] || newedges[v]->u >= u_check ) { edge->next = newedges[v]; newedges[v] = edge; @@ -290,7 +290,7 @@ static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) else { pcheck = newedges[v]; - while (pcheck->next && pcheck->next->u < u_check) + while( pcheck->next && pcheck->next->u < u_check ) pcheck = pcheck->next; edge->next = pcheck->next; pcheck->next = edge; @@ -306,100 +306,101 @@ static void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) R_ClipEdge ================ */ -static void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip) +static void R_ClipEdge( mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip ) { - float d0, d1, f; - mvertex_t clipvert; + float d0, d1, f; + mvertex_t clipvert; - if (clip) + if( clip ) { do { - d0 = DotProduct (pv0->position, clip->normal) - clip->dist; - d1 = DotProduct (pv1->position, clip->normal) - clip->dist; + d0 = DotProduct( pv0->position, clip->normal ) - clip->dist; + d1 = DotProduct( pv1->position, clip->normal ) - clip->dist; - if (d0 >= 0) + if( d0 >= 0 ) { - // point 0 is unclipped - if (d1 >= 0) + // point 0 is unclipped + if( d1 >= 0 ) { - // both points are unclipped + // both points are unclipped continue; } - // only point 1 is clipped + // only point 1 is clipped - // we don't cache clipped edges + // we don't cache clipped edges cacheoffset = 0x7FFFFFFF; - f = d0 / (d0 - d1); - clipvert.position[0] = pv0->position[0] + - f * (pv1->position[0] - pv0->position[0]); - clipvert.position[1] = pv0->position[1] + - f * (pv1->position[1] - pv0->position[1]); - clipvert.position[2] = pv0->position[2] + - f * (pv1->position[2] - pv0->position[2]); + f = d0 / ( d0 - d1 ); + clipvert.position[0] = pv0->position[0] + + f * ( pv1->position[0] - pv0->position[0] ); + clipvert.position[1] = pv0->position[1] + + f * ( pv1->position[1] - pv0->position[1] ); + clipvert.position[2] = pv0->position[2] + + f * ( pv1->position[2] - pv0->position[2] ); - if (clip->leftedge) + if( clip->leftedge ) { r_leftclipped = true; r_leftexit = clipvert; } - else if (clip->rightedge) + else if( clip->rightedge ) { r_rightclipped = true; r_rightexit = clipvert; } - R_ClipEdge (pv0, &clipvert, clip->next); + R_ClipEdge( pv0, &clipvert, clip->next ); return; } else { - // point 0 is clipped - if (d1 < 0) + // point 0 is clipped + if( d1 < 0 ) { - // both points are clipped - // we do cache fully clipped edges - if (!r_leftclipped) - cacheoffset = FULLY_CLIPPED_CACHED | - (tr.framecount & FRAMECOUNT_MASK); + // both points are clipped + // we do cache fully clipped edges + if( !r_leftclipped ) + cacheoffset = FULLY_CLIPPED_CACHED + | ( tr.framecount & FRAMECOUNT_MASK ); return; } - // only point 0 is clipped + // only point 0 is clipped r_lastvertvalid = false; - // we don't cache partially clipped edges + // we don't cache partially clipped edges cacheoffset = 0x7FFFFFFF; - f = d0 / (d0 - d1); - clipvert.position[0] = pv0->position[0] + - f * (pv1->position[0] - pv0->position[0]); - clipvert.position[1] = pv0->position[1] + - f * (pv1->position[1] - pv0->position[1]); - clipvert.position[2] = pv0->position[2] + - f * (pv1->position[2] - pv0->position[2]); + f = d0 / ( d0 - d1 ); + clipvert.position[0] = pv0->position[0] + + f * ( pv1->position[0] - pv0->position[0] ); + clipvert.position[1] = pv0->position[1] + + f * ( pv1->position[1] - pv0->position[1] ); + clipvert.position[2] = pv0->position[2] + + f * ( pv1->position[2] - pv0->position[2] ); - if (clip->leftedge) + if( clip->leftedge ) { r_leftclipped = true; r_leftenter = clipvert; } - else if (clip->rightedge) + else if( clip->rightedge ) { r_rightclipped = true; r_rightenter = clipvert; } - R_ClipEdge (&clipvert, pv1, clip->next); + R_ClipEdge( &clipvert, pv1, clip->next ); return; } - } while ((clip = clip->next) != NULL); + } + while(( clip = clip->next ) != NULL ); } // add the edge - R_EmitEdge (pv0, pv1); + R_EmitEdge( pv0, pv1 ); } /* @@ -407,18 +408,18 @@ static void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip) R_EmitCachedEdge ================ */ -static void R_EmitCachedEdge (void) +static void R_EmitCachedEdge( void ) { - edge_t *pedge_t; + edge_t *pedge_t; - pedge_t = (edge_t *)((uintptr_t)r_edges + r_pedge->cachededgeoffset); + pedge_t = (edge_t *)((uintptr_t)r_edges + r_pedge->cachededgeoffset ); - if (!pedge_t->surfs[0]) + if( !pedge_t->surfs[0] ) pedge_t->surfs[0] = surface_p - surfaces; else pedge_t->surfs[1] = surface_p - surfaces; - if (pedge_t->nearzi > r_nearzi) // for mipmap finding + if( pedge_t->nearzi > r_nearzi )// for mipmap finding r_nearzi = pedge_t->nearzi; r_emitted = 1; @@ -430,43 +431,43 @@ static void R_EmitCachedEdge (void) R_RenderFace ================ */ -void R_RenderFace (msurface_t *fa, int clipflags) +void R_RenderFace( msurface_t *fa, int clipflags ) { - int i, lindex; - unsigned mask; - mplane_t *pplane; - float distinv; - vec3_t p_normal; - medge_t *pedges, tedge; - clipplane_t *pclip; + int i, lindex; + unsigned mask; + mplane_t *pplane; + float distinv; + vec3_t p_normal; + medge_t *pedges, tedge; + clipplane_t *pclip; // translucent surfaces are not drawn by the edge renderer - if (fa->flags & (SURF_DRAWTURB|SURF_TRANSPARENT)) + if( fa->flags & ( SURF_DRAWTURB | SURF_TRANSPARENT )) { - //fa->nextalphasurface = r_alpha_surfaces; - //r_alpha_surfaces = fa; - //return; + // fa->nextalphasurface = r_alpha_surfaces; + // r_alpha_surfaces = fa; + // return; } // sky surfaces encountered in the world will cause the // environment box surfaces to be emited - if ( fa->flags & SURF_DRAWSKY ) + if( fa->flags & SURF_DRAWSKY ) { - //R_EmitSkyBox (); - // return; + // R_EmitSkyBox (); + // return; } // skip out if no more surfs - if ((surface_p) >= surf_max) + if(( surface_p ) >= surf_max ) { - // r_outofsurfaces++; + // r_outofsurfaces++; return; } // ditto if not enough edges left, or switch to auxedges if possible - if ((edge_p + fa->numedges + 4) >= edge_max) + if(( edge_p + fa->numedges + 4 ) >= edge_max ) { - //r_outofedges += fa->numedges; + // r_outofedges += fa->numedges; return; } @@ -475,9 +476,9 @@ void R_RenderFace (msurface_t *fa, int clipflags) // set up clip planes pclip = NULL; - for (i=3, mask = 0x08 ; i>=0 ; i--, mask >>= 1) + for( i = 3, mask = 0x08; i >= 0; i--, mask >>= 1 ) { - if (clipflags & mask) + if( clipflags & mask ) { qfrustum.view_clipplanes[i].next = pclip; pclip = &qfrustum.view_clipplanes[i]; @@ -492,21 +493,21 @@ void R_RenderFace (msurface_t *fa, int clipflags) pedges = RI.currentmodel->edges; r_lastvertvalid = false; - for (i=0 ; inumedges ; i++) + for( i = 0; i < fa->numedges; i++ ) { lindex = RI.currentmodel->surfedges[fa->firstedge + i]; - if (lindex > 0) + if( lindex > 0 ) { r_pedge = &pedges[lindex]; - // if the edge is cached, we can just reuse the edge - if (!insubmodel) + // if the edge is cached, we can just reuse the edge + if( !insubmodel ) { - if (r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED) + if( r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED ) { - if ((r_pedge->cachededgeoffset & FRAMECOUNT_MASK) == - tr.framecount) + if(( r_pedge->cachededgeoffset & FRAMECOUNT_MASK ) + == tr.framecount ) { r_lastvertvalid = false; continue; @@ -514,29 +515,29 @@ void R_RenderFace (msurface_t *fa, int clipflags) } else { - if ((((uintptr_t)edge_p - (uintptr_t)r_edges) > - r_pedge->cachededgeoffset) && - (((edge_t *)((uintptr_t)r_edges + - r_pedge->cachededgeoffset))->owner == r_pedge)) + if((((uintptr_t)edge_p - (uintptr_t)r_edges ) + > r_pedge->cachededgeoffset ) + && (((edge_t *)((uintptr_t)r_edges + + r_pedge->cachededgeoffset ))->owner == r_pedge )) { - R_EmitCachedEdge (); + R_EmitCachedEdge(); r_lastvertvalid = false; continue; } } } - // assume it's cacheable + // assume it's cacheable cacheoffset = (byte *)edge_p - (byte *)r_edges; r_leftclipped = r_rightclipped = false; - R_ClipEdge (&r_pcurrentvertbase[r_pedge->v[0]], - &r_pcurrentvertbase[r_pedge->v[1]], - pclip); + R_ClipEdge( &r_pcurrentvertbase[r_pedge->v[0]], + &r_pcurrentvertbase[r_pedge->v[1]], + pclip ); r_pedge->cachededgeoffset = cacheoffset; - if (r_leftclipped) + if( r_leftclipped ) makeleftedge = true; - if (r_rightclipped) + if( r_rightclipped ) makerightedge = true; r_lastvertvalid = true; } @@ -544,13 +545,13 @@ void R_RenderFace (msurface_t *fa, int clipflags) { lindex = -lindex; r_pedge = &pedges[lindex]; - // if the edge is cached, we can just reuse the edge - if (!insubmodel) + // if the edge is cached, we can just reuse the edge + if( !insubmodel ) { - if (r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED) + if( r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED ) { - if ((r_pedge->cachededgeoffset & FRAMECOUNT_MASK) == - tr.framecount) + if(( r_pedge->cachededgeoffset & FRAMECOUNT_MASK ) + == tr.framecount ) { r_lastvertvalid = false; continue; @@ -558,31 +559,31 @@ void R_RenderFace (msurface_t *fa, int clipflags) } else { - // it's cached if the cached edge is valid and is owned - // by this medge_t - if ((((uintptr_t)edge_p - (uintptr_t)r_edges) > - r_pedge->cachededgeoffset) && - (((edge_t *)((uintptr_t)r_edges + - r_pedge->cachededgeoffset))->owner == r_pedge)) + // it's cached if the cached edge is valid and is owned + // by this medge_t + if((((uintptr_t)edge_p - (uintptr_t)r_edges ) + > r_pedge->cachededgeoffset ) + && (((edge_t *)((uintptr_t)r_edges + + r_pedge->cachededgeoffset ))->owner == r_pedge )) { - R_EmitCachedEdge (); + R_EmitCachedEdge(); r_lastvertvalid = false; continue; } } } - // assume it's cacheable + // assume it's cacheable cacheoffset = (byte *)edge_p - (byte *)r_edges; r_leftclipped = r_rightclipped = false; - R_ClipEdge (&r_pcurrentvertbase[r_pedge->v[1]], - &r_pcurrentvertbase[r_pedge->v[0]], - pclip); + R_ClipEdge( &r_pcurrentvertbase[r_pedge->v[1]], + &r_pcurrentvertbase[r_pedge->v[0]], + pclip ); r_pedge->cachededgeoffset = cacheoffset; - if (r_leftclipped) + if( r_leftclipped ) makeleftedge = true; - if (r_rightclipped) + if( r_rightclipped ) makerightedge = true; r_lastvertvalid = true; } @@ -591,24 +592,24 @@ void R_RenderFace (msurface_t *fa, int clipflags) // if there was a clip off the left edge, add that edge too // FIXME: faster to do in screen space? // FIXME: share clipped edges? - if (makeleftedge) + if( makeleftedge ) { r_pedge = &tedge; r_lastvertvalid = false; - R_ClipEdge (&r_leftexit, &r_leftenter, pclip->next); + R_ClipEdge( &r_leftexit, &r_leftenter, pclip->next ); } // if there was a clip off the right edge, get the right r_nearzi - if (makerightedge) + if( makerightedge ) { r_pedge = &tedge; r_lastvertvalid = false; r_nearzionly = true; - R_ClipEdge (&r_rightexit, &r_rightenter, qfrustum.view_clipplanes[1].next); + R_ClipEdge( &r_rightexit, &r_rightenter, qfrustum.view_clipplanes[1].next ); } // if no edges made it out, return without posting the surface - if (!r_emitted) + if( !r_emitted ) return; // r_polycount++; @@ -624,15 +625,15 @@ void R_RenderFace (msurface_t *fa, int clipflags) pplane = fa->plane; // FIXME: cache this? - TransformVector (pplane->normal, p_normal); + TransformVector( pplane->normal, p_normal ); // FIXME: cache this? - distinv = 1.0f / (pplane->dist - DotProduct (tr.modelorg, pplane->normal)); + distinv = 1.0f / ( pplane->dist - DotProduct( tr.modelorg, pplane->normal )); surface_p->d_zistepu = p_normal[0] * xscaleinv * distinv; surface_p->d_zistepv = -p_normal[1] * yscaleinv * distinv; - surface_p->d_ziorigin = p_normal[2] * distinv - - xcenter * surface_p->d_zistepu - - ycenter * surface_p->d_zistepv; + surface_p->d_ziorigin = p_normal[2] * distinv + - xcenter * surface_p->d_zistepu + - ycenter * surface_p->d_zistepv; surface_p++; } @@ -643,15 +644,15 @@ void R_RenderFace (msurface_t *fa, int clipflags) R_RenderBmodelFace ================ */ -void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) +void R_RenderBmodelFace( bedge_t *pedges, msurface_t *psurf ) { - int i; - unsigned mask; - mplane_t *pplane; - float distinv; - vec3_t p_normal; - medge_t tedge; - clipplane_t *pclip; + int i; + unsigned mask; + mplane_t *pplane; + float distinv; + vec3_t p_normal; + medge_t tedge; + clipplane_t *pclip; /*if (psurf->texinfo->flags & (SURF_TRANS33|SURF_TRANS66)) { @@ -661,16 +662,16 @@ void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) }*/ // skip out if no more surfs - if (surface_p >= surf_max) + if( surface_p >= surf_max ) { - //r_outofsurfaces++; + // r_outofsurfaces++; return; } // ditto if not enough edges left, or switch to auxedges if possible - if ((edge_p + psurf->numedges + 4) >= edge_max) + if(( edge_p + psurf->numedges + 4 ) >= edge_max ) { - //r_outofedges += psurf->numedges; + // r_outofedges += psurf->numedges; return; } @@ -682,9 +683,9 @@ void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) // set up clip planes pclip = NULL; - for (i=3, mask = 0x08 ; i>=0 ; i--, mask >>= 1) + for( i = 3, mask = 0x08; i >= 0; i--, mask >>= 1 ) { - if (r_clipflags & mask) + if( r_clipflags & mask ) { qfrustum.view_clipplanes[i].next = pclip; pclip = &qfrustum.view_clipplanes[i]; @@ -700,39 +701,39 @@ void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) // can be used? r_lastvertvalid = false; - for ( ; pedges ; pedges = pedges->pnext) + for( ; pedges; pedges = pedges->pnext ) { r_leftclipped = r_rightclipped = false; - R_ClipEdge (pedges->v[0], pedges->v[1], pclip); + R_ClipEdge( pedges->v[0], pedges->v[1], pclip ); - if (r_leftclipped) + if( r_leftclipped ) makeleftedge = true; - if (r_rightclipped) + if( r_rightclipped ) makerightedge = true; } // if there was a clip off the left edge, add that edge too // FIXME: faster to do in screen space? // FIXME: share clipped edges? - if (makeleftedge) + if( makeleftedge ) { r_pedge = &tedge; - R_ClipEdge (&r_leftexit, &r_leftenter, pclip->next); + R_ClipEdge( &r_leftexit, &r_leftenter, pclip->next ); } // if there was a clip off the right edge, get the right r_nearzi - if (makerightedge) + if( makerightedge ) { r_pedge = &tedge; r_nearzionly = true; - R_ClipEdge (&r_rightexit, &r_rightenter, qfrustum.view_clipplanes[1].next); + R_ClipEdge( &r_rightexit, &r_rightenter, qfrustum.view_clipplanes[1].next ); } // if no edges made it out, return without posting the surface - if (!r_emitted) + if( !r_emitted ) return; - //r_polycount++; + // r_polycount++; surface_p->msurf = psurf; surface_p->nearzi = r_nearzi; @@ -745,15 +746,15 @@ void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) pplane = psurf->plane; // FIXME: cache this? - TransformVector (pplane->normal, p_normal); + TransformVector( pplane->normal, p_normal ); // FIXME: cache this? - distinv = 1.0f / (pplane->dist - DotProduct (tr.modelorg, pplane->normal)); + distinv = 1.0f / ( pplane->dist - DotProduct( tr.modelorg, pplane->normal )); surface_p->d_zistepu = p_normal[0] * xscaleinv * distinv; surface_p->d_zistepv = -p_normal[1] * yscaleinv * distinv; - surface_p->d_ziorigin = p_normal[2] * distinv - - xcenter * surface_p->d_zistepu - - ycenter * surface_p->d_zistepv; + surface_p->d_ziorigin = p_normal[2] * distinv + - xcenter * surface_p->d_zistepu + - ycenter * surface_p->d_zistepv; surface_p++; } diff --git a/ref/soft/r_scan.c b/ref/soft/r_scan.c index 25e65c33..631609ad 100644 --- a/ref/soft/r_scan.c +++ b/ref/soft/r_scan.c @@ -23,31 +23,32 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" -pixel_t *r_turb_pbase, *r_turb_pdest; -short *r_turb_pz; -fixed16_t r_turb_s, r_turb_t, r_turb_sstep, r_turb_tstep; -int r_turb_izistep, r_turb_izi; -int *r_turb_turb; -static int r_turb_spancount; -int alpha; +pixel_t *r_turb_pbase, *r_turb_pdest; +short *r_turb_pz; +fixed16_t r_turb_s, r_turb_t, r_turb_sstep, r_turb_tstep; +int r_turb_izistep, r_turb_izi; +int *r_turb_turb; +static int r_turb_spancount; +int alpha; /* ============= D_DrawTurbulent8Span ============= */ -void D_DrawTurbulent8Span (void) +void D_DrawTurbulent8Span( void ) { - int sturb, tturb; + int sturb, tturb; do { - sturb = ((r_turb_s + r_turb_turb[(r_turb_t>>16)&(CYCLE-1)])>>16)&63; - tturb = ((r_turb_t + r_turb_turb[(r_turb_s>>16)&(CYCLE-1)])>>16)&63; - *r_turb_pdest++ = *(r_turb_pbase + (tturb<<6) + sturb); + sturb = (( r_turb_s + r_turb_turb[( r_turb_t >> 16 ) & ( CYCLE - 1 )] ) >> 16 ) & 63; + tturb = (( r_turb_t + r_turb_turb[( r_turb_s >> 16 ) & ( CYCLE - 1 )] ) >> 16 ) & 63; + *r_turb_pdest++ = *( r_turb_pbase + ( tturb << 6 ) + sturb ); r_turb_s += r_turb_sstep; r_turb_t += r_turb_tstep; - } while (--r_turb_spancount > 0); + } + while( --r_turb_spancount > 0 ); } /* @@ -55,28 +56,29 @@ void D_DrawTurbulent8Span (void) D_DrawTurbulent8Span ============= */ -static void D_DrawTurbulent8ZSpan (void) +static void D_DrawTurbulent8ZSpan( void ) { - int sturb, tturb; + int sturb, tturb; do { - sturb = ((r_turb_s + r_turb_turb[(r_turb_t>>16)&(CYCLE-1)])>>16)&63; - tturb = ((r_turb_t + r_turb_turb[(r_turb_s>>16)&(CYCLE-1)])>>16)&63; - if (*r_turb_pz <= (r_turb_izi >> 16)) + sturb = (( r_turb_s + r_turb_turb[( r_turb_t >> 16 ) & ( CYCLE - 1 )] ) >> 16 ) & 63; + tturb = (( r_turb_t + r_turb_turb[( r_turb_s >> 16 ) & ( CYCLE - 1 )] ) >> 16 ) & 63; + if( *r_turb_pz <= ( r_turb_izi >> 16 )) { - pixel_t btemp = *(r_turb_pbase + (tturb<<6) + sturb); + pixel_t btemp = *( r_turb_pbase + ( tturb << 6 ) + sturb ); if( alpha == 7 ) *r_turb_pdest = btemp; else - *r_turb_pdest = BLEND_ALPHA( alpha, btemp, *r_turb_pdest); + *r_turb_pdest = BLEND_ALPHA( alpha, btemp, *r_turb_pdest ); } r_turb_pdest++; r_turb_pz++; r_turb_izi += r_turb_izistep; r_turb_s += r_turb_sstep; r_turb_t += r_turb_tstep; - } while (--r_turb_spancount > 0); + } + while( --r_turb_spancount > 0 ); } /* @@ -84,17 +86,17 @@ static void D_DrawTurbulent8ZSpan (void) Turbulent8 ============= */ -void Turbulent8 (espan_t *pspan) +void Turbulent8( espan_t *pspan ) { - int count; - fixed16_t snext, tnext; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz16stepu, tdivz16stepu, zi16stepu; + int count; + fixed16_t snext, tnext; + float sdivz, tdivz, zi, z, du, dv, spancountminus1; + float sdivz16stepu, tdivz16stepu, zi16stepu; - r_turb_turb = sintable + ((int)(gp_cl->time*SPEED)&(CYCLE-1)); + r_turb_turb = sintable + ((int)( gp_cl->time * SPEED ) & ( CYCLE - 1 )); - r_turb_sstep = 0; // keep compiler happy - r_turb_tstep = 0; // ditto + r_turb_sstep = 0; // keep compiler happy + r_turb_tstep = 0; // ditto r_turb_pbase = cacheblock; @@ -104,111 +106,113 @@ void Turbulent8 (espan_t *pspan) do { - r_turb_pdest = (d_viewbuffer + - (r_screenwidth * pspan->v) + pspan->u); + r_turb_pdest = ( d_viewbuffer + + ( r_screenwidth * pspan->v ) + pspan->u ); count = pspan->count; - // calculate the initial s/z, t/z, 1/z, s, and t and clamp + // calculate the initial s/z, t/z, 1/z, s, and t and clamp du = (float)pspan->u; dv = (float)pspan->v; - sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu; - tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu; - zi = d_ziorigin + dv*d_zistepv + du*d_zistepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; + tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; + zi = d_ziorigin + dv * d_zistepv + du * d_zistepu; + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - r_turb_s = (int)(sdivz * z) + sadjust; - if (r_turb_s > bbextents) + r_turb_s = (int)( sdivz * z ) + sadjust; + if( r_turb_s > bbextents ) r_turb_s = bbextents; - else if (r_turb_s < 0) + else if( r_turb_s < 0 ) r_turb_s = 0; - r_turb_t = (int)(tdivz * z) + tadjust; - if (r_turb_t > bbextentt) + r_turb_t = (int)( tdivz * z ) + tadjust; + if( r_turb_t > bbextentt ) r_turb_t = bbextentt; - else if (r_turb_t < 0) + else if( r_turb_t < 0 ) r_turb_t = 0; do { - // calculate s and t at the far end of the span - if (count >= 16) + // calculate s and t at the far end of the span + if( count >= 16 ) r_turb_spancount = 16; else r_turb_spancount = count; count -= r_turb_spancount; - if (count) + if( count ) { - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting + // calculate s/z, t/z, zi->fixed s and t at far end of span, + // calculate s and t steps across span by shifting sdivz += sdivz16stepu; tdivz += tdivz16stepu; zi += zi16stepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 16) - snext = 16; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 16 ) + snext = 16; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 16) - tnext = 16; // guard against round-off error on <0 steps + else if( tnext < 16 ) + tnext = 16; // guard against round-off error on <0 steps - r_turb_sstep = (snext - r_turb_s) >> 4; - r_turb_tstep = (tnext - r_turb_t) >> 4; + r_turb_sstep = ( snext - r_turb_s ) >> 4; + r_turb_tstep = ( tnext - r_turb_t ) >> 4; } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so - // can't step off polygon), clamp, calculate s and t steps across - // span by division, biasing steps low so we don't run off the - // texture - spancountminus1 = (float)(r_turb_spancount - 1); + // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so + // can't step off polygon), clamp, calculate s and t steps across + // span by division, biasing steps low so we don't run off the + // texture + spancountminus1 = (float)( r_turb_spancount - 1 ); sdivz += d_sdivzstepu * spancountminus1; tdivz += d_tdivzstepu * spancountminus1; zi += d_zistepu * spancountminus1; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 16) - snext = 16; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 16 ) + snext = 16; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 16) - tnext = 16; // guard against round-off error on <0 steps + else if( tnext < 16 ) + tnext = 16; // guard against round-off error on <0 steps - if (r_turb_spancount > 1) + if( r_turb_spancount > 1 ) { - r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1); - r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1); + r_turb_sstep = ( snext - r_turb_s ) / ( r_turb_spancount - 1 ); + r_turb_tstep = ( tnext - r_turb_t ) / ( r_turb_spancount - 1 ); } } - r_turb_s = r_turb_s & ((CYCLE<<16)-1); - r_turb_t = r_turb_t & ((CYCLE<<16)-1); + r_turb_s = r_turb_s & (( CYCLE << 16 ) - 1 ); + r_turb_t = r_turb_t & (( CYCLE << 16 ) - 1 ); - D_DrawTurbulent8Span (); + D_DrawTurbulent8Span(); r_turb_s = snext; r_turb_t = tnext; - } while (count > 0); + } + while( count > 0 ); - } while ((pspan = pspan->pnext) != NULL); + } + while(( pspan = pspan->pnext ) != NULL ); } /* @@ -216,12 +220,12 @@ void Turbulent8 (espan_t *pspan) Turbulent8 ============= */ -void TurbulentZ8 (espan_t *pspan, int alpha1) +void TurbulentZ8( espan_t *pspan, int alpha1 ) { - int count; - fixed16_t snext, tnext; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz16stepu, tdivz16stepu, zi16stepu; + int count; + fixed16_t snext, tnext; + float sdivz, tdivz, zi, z, du, dv, spancountminus1; + float sdivz16stepu, tdivz16stepu, zi16stepu; alpha = alpha1; if( alpha > 7 ) @@ -229,152 +233,154 @@ void TurbulentZ8 (espan_t *pspan, int alpha1) if( alpha == 0 ) return; - r_turb_turb = sintable + ((int)(gp_cl->time*SPEED)&(CYCLE-1)); + r_turb_turb = sintable + ((int)( gp_cl->time * SPEED ) & ( CYCLE - 1 )); - r_turb_sstep = 0; // keep compiler happy - r_turb_tstep = 0; // ditto + r_turb_sstep = 0; // keep compiler happy + r_turb_tstep = 0; // ditto r_turb_pbase = cacheblock; sdivz16stepu = d_sdivzstepu * 16; tdivz16stepu = d_tdivzstepu * 16; zi16stepu = d_zistepu * 16; - r_turb_izistep = (int)(d_zistepu * 0x8000 * 0x10000); + r_turb_izistep = (int)( d_zistepu * 0x8000 * 0x10000 ); do { - r_turb_pdest = (d_viewbuffer + - (r_screenwidth * pspan->v) + pspan->u); - r_turb_pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; + r_turb_pdest = ( d_viewbuffer + + ( r_screenwidth * pspan->v ) + pspan->u ); + r_turb_pz = d_pzbuffer + ( d_zwidth * pspan->v ) + pspan->u; count = pspan->count; - // calculate the initial s/z, t/z, 1/z, s, and t and clamp + // calculate the initial s/z, t/z, 1/z, s, and t and clamp du = (float)pspan->u; dv = (float)pspan->v; - sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu; - tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu; - zi = d_ziorigin + dv*d_zistepv + du*d_zistepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - r_turb_izi = (int)(zi * 0x8000 * 0x10000); + sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; + tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; + zi = d_ziorigin + dv * d_zistepv + du * d_zistepu; + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + r_turb_izi = (int)( zi * 0x8000 * 0x10000 ); - r_turb_s = (int)(sdivz * z) + sadjust; - if (r_turb_s > bbextents) + r_turb_s = (int)( sdivz * z ) + sadjust; + if( r_turb_s > bbextents ) r_turb_s = bbextents; - else if (r_turb_s < 0) + else if( r_turb_s < 0 ) r_turb_s = 0; - r_turb_t = (int)(tdivz * z) + tadjust; - if (r_turb_t > bbextentt) + r_turb_t = (int)( tdivz * z ) + tadjust; + if( r_turb_t > bbextentt ) r_turb_t = bbextentt; - else if (r_turb_t < 0) + else if( r_turb_t < 0 ) r_turb_t = 0; do { - // calculate s and t at the far end of the span - if (count >= 16) + // calculate s and t at the far end of the span + if( count >= 16 ) r_turb_spancount = 16; else r_turb_spancount = count; count -= r_turb_spancount; - if (count) + if( count ) { - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting + // calculate s/z, t/z, zi->fixed s and t at far end of span, + // calculate s and t steps across span by shifting sdivz += sdivz16stepu; tdivz += tdivz16stepu; zi += zi16stepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 16) - snext = 16; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 16 ) + snext = 16; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 16) - tnext = 16; // guard against round-off error on <0 steps + else if( tnext < 16 ) + tnext = 16; // guard against round-off error on <0 steps - r_turb_sstep = (snext - r_turb_s) >> 4; - r_turb_tstep = (tnext - r_turb_t) >> 4; + r_turb_sstep = ( snext - r_turb_s ) >> 4; + r_turb_tstep = ( tnext - r_turb_t ) >> 4; } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so - // can't step off polygon), clamp, calculate s and t steps across - // span by division, biasing steps low so we don't run off the - // texture - spancountminus1 = (float)(r_turb_spancount - 1); + // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so + // can't step off polygon), clamp, calculate s and t steps across + // span by division, biasing steps low so we don't run off the + // texture + spancountminus1 = (float)( r_turb_spancount - 1 ); sdivz += d_sdivzstepu * spancountminus1; tdivz += d_tdivzstepu * spancountminus1; zi += d_zistepu * spancountminus1; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 16) - snext = 16; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 16 ) + snext = 16; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 16) - tnext = 16; // guard against round-off error on <0 steps + else if( tnext < 16 ) + tnext = 16; // guard against round-off error on <0 steps - if (r_turb_spancount > 1) + if( r_turb_spancount > 1 ) { - r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1); - r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1); + r_turb_sstep = ( snext - r_turb_s ) / ( r_turb_spancount - 1 ); + r_turb_tstep = ( tnext - r_turb_t ) / ( r_turb_spancount - 1 ); } } - r_turb_s = r_turb_s & ((CYCLE<<16)-1); - r_turb_t = r_turb_t & ((CYCLE<<16)-1); + r_turb_s = r_turb_s & (( CYCLE << 16 ) - 1 ); + r_turb_t = r_turb_t & (( CYCLE << 16 ) - 1 ); - D_DrawTurbulent8ZSpan (); + D_DrawTurbulent8ZSpan(); r_turb_s = snext; r_turb_t = tnext; - } while (count > 0); + } + while( count > 0 ); - } while ((pspan = pspan->pnext) != NULL); + } + while(( pspan = pspan->pnext ) != NULL ); } -//==================== -//PGM +// ==================== +// PGM /* ============= NonTurbulent8 - this is for drawing scrolling textures. they're warping water textures but the turbulence is automatically 0. ============= */ -void NonTurbulent8 (espan_t *pspan) +void NonTurbulent8( espan_t *pspan ) { - int count; - fixed16_t snext, tnext; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz16stepu, tdivz16stepu, zi16stepu; + int count; + fixed16_t snext, tnext; + float sdivz, tdivz, zi, z, du, dv, spancountminus1; + float sdivz16stepu, tdivz16stepu, zi16stepu; // r_turb_turb = sintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1)); r_turb_turb = blanktable; - r_turb_sstep = 0; // keep compiler happy - r_turb_tstep = 0; // ditto + r_turb_sstep = 0; // keep compiler happy + r_turb_tstep = 0; // ditto r_turb_pbase = cacheblock; @@ -384,129 +390,131 @@ void NonTurbulent8 (espan_t *pspan) do { - r_turb_pdest = (d_viewbuffer + - (r_screenwidth * pspan->v) + pspan->u); + r_turb_pdest = ( d_viewbuffer + + ( r_screenwidth * pspan->v ) + pspan->u ); count = pspan->count; - // calculate the initial s/z, t/z, 1/z, s, and t and clamp + // calculate the initial s/z, t/z, 1/z, s, and t and clamp du = (float)pspan->u; dv = (float)pspan->v; - sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu; - tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu; - zi = d_ziorigin + dv*d_zistepv + du*d_zistepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; + tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; + zi = d_ziorigin + dv * d_zistepv + du * d_zistepu; + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - r_turb_s = (int)(sdivz * z) + sadjust; - if (r_turb_s > bbextents) + r_turb_s = (int)( sdivz * z ) + sadjust; + if( r_turb_s > bbextents ) r_turb_s = bbextents; - else if (r_turb_s < 0) + else if( r_turb_s < 0 ) r_turb_s = 0; - r_turb_t = (int)(tdivz * z) + tadjust; - if (r_turb_t > bbextentt) + r_turb_t = (int)( tdivz * z ) + tadjust; + if( r_turb_t > bbextentt ) r_turb_t = bbextentt; - else if (r_turb_t < 0) + else if( r_turb_t < 0 ) r_turb_t = 0; do { - // calculate s and t at the far end of the span - if (count >= 16) + // calculate s and t at the far end of the span + if( count >= 16 ) r_turb_spancount = 16; else r_turb_spancount = count; count -= r_turb_spancount; - if (count) + if( count ) { - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting + // calculate s/z, t/z, zi->fixed s and t at far end of span, + // calculate s and t steps across span by shifting sdivz += sdivz16stepu; tdivz += tdivz16stepu; zi += zi16stepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 16) - snext = 16; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 16 ) + snext = 16; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 16) - tnext = 16; // guard against round-off error on <0 steps + else if( tnext < 16 ) + tnext = 16; // guard against round-off error on <0 steps - r_turb_sstep = (snext - r_turb_s) >> 4; - r_turb_tstep = (tnext - r_turb_t) >> 4; + r_turb_sstep = ( snext - r_turb_s ) >> 4; + r_turb_tstep = ( tnext - r_turb_t ) >> 4; } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so - // can't step off polygon), clamp, calculate s and t steps across - // span by division, biasing steps low so we don't run off the - // texture - spancountminus1 = (float)(r_turb_spancount - 1); + // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so + // can't step off polygon), clamp, calculate s and t steps across + // span by division, biasing steps low so we don't run off the + // texture + spancountminus1 = (float)( r_turb_spancount - 1 ); sdivz += d_sdivzstepu * spancountminus1; tdivz += d_tdivzstepu * spancountminus1; zi += d_zistepu * spancountminus1; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 16) - snext = 16; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 16 ) + snext = 16; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 16) - tnext = 16; // guard against round-off error on <0 steps + else if( tnext < 16 ) + tnext = 16; // guard against round-off error on <0 steps - if (r_turb_spancount > 1) + if( r_turb_spancount > 1 ) { - r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1); - r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1); + r_turb_sstep = ( snext - r_turb_s ) / ( r_turb_spancount - 1 ); + r_turb_tstep = ( tnext - r_turb_t ) / ( r_turb_spancount - 1 ); } } - r_turb_s = r_turb_s & ((CYCLE<<16)-1); - r_turb_t = r_turb_t & ((CYCLE<<16)-1); + r_turb_s = r_turb_s & (( CYCLE << 16 ) - 1 ); + r_turb_t = r_turb_t & (( CYCLE << 16 ) - 1 ); - D_DrawTurbulent8Span (); + D_DrawTurbulent8Span(); r_turb_s = snext; r_turb_t = tnext; - } while (count > 0); + } + while( count > 0 ); - } while ((pspan = pspan->pnext) != NULL); + } + while(( pspan = pspan->pnext ) != NULL ); } -//PGM -//==================== +// PGM +// ==================== int kernel[2][2][2] = { - { - {16384,0}, - {49152,32768} - } - , - { - {32768,49152}, - {0,16384} - } + { + {16384, 0}, + {49152, 32768} + } + , + { + {32768, 49152}, + {0, 16384} + } }; #ifndef DISABLE_TEXFILTER -#define SW_TEXFILT (sw_texfilt.value == 1.0f) +#define SW_TEXFILT ( sw_texfilt.value == 1.0f ) #else #define SW_TEXFILT 0 #endif @@ -517,16 +525,16 @@ D_DrawSpans16 FIXME: actually make this subdivide by 16 instead of 8!!! ============= */ -void D_DrawSpans16 (espan_t *pspan) +void D_DrawSpans16( espan_t *pspan ) { - int count, spancount; - pixel_t *pbase, *pdest; - fixed16_t s, t, snext, tnext, sstep, tstep; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz8stepu, tdivz8stepu, zi8stepu; + int count, spancount; + pixel_t *pbase, *pdest; + fixed16_t s, t, snext, tnext, sstep, tstep; + float sdivz, tdivz, zi, z, du, dv, spancountminus1; + float sdivz8stepu, tdivz8stepu, zi8stepu; - sstep = 0; // keep compiler happy - tstep = 0; // ditto + sstep = 0; // keep compiler happy + tstep = 0; // ditto pbase = cacheblock; @@ -536,143 +544,147 @@ void D_DrawSpans16 (espan_t *pspan) do { - pdest = (d_viewbuffer + - (r_screenwidth * pspan->v) + pspan->u); + pdest = ( d_viewbuffer + + ( r_screenwidth * pspan->v ) + pspan->u ); count = pspan->count; - // calculate the initial s/z, t/z, 1/z, s, and t and clamp + // calculate the initial s/z, t/z, 1/z, s, and t and clamp du = (float)pspan->u; dv = (float)pspan->v; - sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu; - tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu; - zi = d_ziorigin + dv*d_zistepv + du*d_zistepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; + tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; + zi = d_ziorigin + dv * d_zistepv + du * d_zistepu; + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - s = (int)(sdivz * z) + sadjust; - if (s > bbextents) + s = (int)( sdivz * z ) + sadjust; + if( s > bbextents ) s = bbextents; - else if (s < 0) + else if( s < 0 ) s = 0; - t = (int)(tdivz * z) + tadjust; - if (t > bbextentt) + t = (int)( tdivz * z ) + tadjust; + if( t > bbextentt ) t = bbextentt; - else if (t < 0) + else if( t < 0 ) t = 0; do { - // calculate s and t at the far end of the span - if (count >= 8) + // calculate s and t at the far end of the span + if( count >= 8 ) spancount = 8; else spancount = count; count -= spancount; - if (count) + if( count ) { - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting + // calculate s/z, t/z, zi->fixed s and t at far end of span, + // calculate s and t steps across span by shifting sdivz += sdivz8stepu; tdivz += tdivz8stepu; zi += zi8stepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 8 ) + snext = 8; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on <0 steps + else if( tnext < 8 ) + tnext = 8; // guard against round-off error on <0 steps - sstep = (snext - s) >> 3; - tstep = (tnext - t) >> 3; + sstep = ( snext - s ) >> 3; + tstep = ( tnext - t ) >> 3; } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so - // can't step off polygon), clamp, calculate s and t steps across - // span by division, biasing steps low so we don't run off the - // texture - spancountminus1 = (float)(spancount - 1); + // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so + // can't step off polygon), clamp, calculate s and t steps across + // span by division, biasing steps low so we don't run off the + // texture + spancountminus1 = (float)( spancount - 1 ); sdivz += d_sdivzstepu * spancountminus1; tdivz += d_tdivzstepu * spancountminus1; zi += d_zistepu * spancountminus1; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 8 ) + snext = 8; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on <0 steps + else if( tnext < 8 ) + tnext = 8; // guard against round-off error on <0 steps - if (spancount > 1) + if( spancount > 1 ) { - sstep = (snext - s) / (spancount - 1); - tstep = (tnext - t) / (spancount - 1); + sstep = ( snext - s ) / ( spancount - 1 ); + tstep = ( tnext - t ) / ( spancount - 1 ); } - } + } // Drawing phrase - if (!SW_TEXFILT) + if( !SW_TEXFILT ) + { + do { - do - { - *pdest++ = *(pbase + (s >> 16) + (t >> 16) * cachewidth); - s += sstep; - t += tstep; - } while (--spancount > 0); + *pdest++ = *( pbase + ( s >> 16 ) + ( t >> 16 ) * cachewidth ); + s += sstep; + t += tstep; } - else + while( --spancount > 0 ); + } + else + { + do { - do - { - int idiths = s; - int iditht = t; + int idiths = s; + int iditht = t; - int X = (pspan->u + spancount) & 1; - int Y = (pspan->v)&1; + int X = ( pspan->u + spancount ) & 1; + int Y = ( pspan->v ) & 1; - //Using the kernel - idiths += kernel[X][Y][0]; - iditht += kernel[X][Y][1]; + // Using the kernel + idiths += kernel[X][Y][0]; + iditht += kernel[X][Y][1]; - idiths = idiths >> 16; - idiths = idiths ? idiths -1 : idiths; + idiths = idiths >> 16; + idiths = idiths ? idiths - 1 : idiths; - iditht = iditht >> 16; - iditht = iditht ? iditht -1 : iditht; + iditht = iditht >> 16; + iditht = iditht ? iditht - 1 : iditht; - *pdest++ = *(pbase + idiths + iditht * cachewidth); - s += sstep; - t += tstep; - } while (--spancount > 0); + *pdest++ = *( pbase + idiths + iditht * cachewidth ); + s += sstep; + t += tstep; } + while( --spancount > 0 ); + } - } while (count > 0); + } + while( count > 0 ); - } while ((pspan = pspan->pnext) != NULL); + } + while(( pspan = pspan->pnext ) != NULL ); } @@ -683,191 +695,195 @@ D_DrawSpans16 FIXME: actually make this subdivide by 16 instead of 8!!! ============= */ -void D_AlphaSpans16 (espan_t *pspan) +void D_AlphaSpans16( espan_t *pspan ) { - int count, spancount; - pixel_t *pbase, *pdest; - fixed16_t s, t, snext, tnext, sstep, tstep; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz8stepu, tdivz8stepu, zi8stepu; - int izi, izistep; - short *pz; + int count, spancount; + pixel_t *pbase, *pdest; + fixed16_t s, t, snext, tnext, sstep, tstep; + float sdivz, tdivz, zi, z, du, dv, spancountminus1; + float sdivz8stepu, tdivz8stepu, zi8stepu; + int izi, izistep; + short *pz; - sstep = 0; // keep compiler happy - tstep = 0; // ditto + sstep = 0; // keep compiler happy + tstep = 0; // ditto pbase = cacheblock; sdivz8stepu = d_sdivzstepu * 8; tdivz8stepu = d_tdivzstepu * 8; zi8stepu = d_zistepu * 8; - izistep = (int)(d_zistepu * 0x8000 * 0x10000); + izistep = (int)( d_zistepu * 0x8000 * 0x10000 ); do { - pdest = (d_viewbuffer + - (r_screenwidth * pspan->v) + pspan->u); - pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; + pdest = ( d_viewbuffer + + ( r_screenwidth * pspan->v ) + pspan->u ); + pz = d_pzbuffer + ( d_zwidth * pspan->v ) + pspan->u; count = pspan->count; - // calculate the initial s/z, t/z, 1/z, s, and t and clamp + // calculate the initial s/z, t/z, 1/z, s, and t and clamp du = (float)pspan->u; dv = (float)pspan->v; - sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu; - tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu; - zi = d_ziorigin + dv*d_zistepv + du*d_zistepu; - izi = (int)(zi * 0x8000 * 0x10000); - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; + tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; + zi = d_ziorigin + dv * d_zistepv + du * d_zistepu; + izi = (int)( zi * 0x8000 * 0x10000 ); + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - s = (int)(sdivz * z) + sadjust; - if (s > bbextents) + s = (int)( sdivz * z ) + sadjust; + if( s > bbextents ) s = bbextents; - else if (s < 0) + else if( s < 0 ) s = 0; - t = (int)(tdivz * z) + tadjust; - if (t > bbextentt) + t = (int)( tdivz * z ) + tadjust; + if( t > bbextentt ) t = bbextentt; - else if (t < 0) + else if( t < 0 ) t = 0; do { - // calculate s and t at the far end of the span - if (count >= 8) + // calculate s and t at the far end of the span + if( count >= 8 ) spancount = 8; else spancount = count; count -= spancount; - if (count) + if( count ) { - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting + // calculate s/z, t/z, zi->fixed s and t at far end of span, + // calculate s and t steps across span by shifting sdivz += sdivz8stepu; tdivz += tdivz8stepu; zi += zi8stepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 8 ) + snext = 8; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on <0 steps + else if( tnext < 8 ) + tnext = 8; // guard against round-off error on <0 steps - sstep = (snext - s) >> 3; - tstep = (tnext - t) >> 3; + sstep = ( snext - s ) >> 3; + tstep = ( tnext - t ) >> 3; } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so - // can't step off polygon), clamp, calculate s and t steps across - // span by division, biasing steps low so we don't run off the - // texture - spancountminus1 = (float)(spancount - 1); + // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so + // can't step off polygon), clamp, calculate s and t steps across + // span by division, biasing steps low so we don't run off the + // texture + spancountminus1 = (float)( spancount - 1 ); sdivz += d_sdivzstepu * spancountminus1; tdivz += d_tdivzstepu * spancountminus1; zi += d_zistepu * spancountminus1; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 8 ) + snext = 8; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on <0 steps + else if( tnext < 8 ) + tnext = 8; // guard against round-off error on <0 steps - if (spancount > 1) + if( spancount > 1 ) { - sstep = (snext - s) / (spancount - 1); - tstep = (tnext - t) / (spancount - 1); + sstep = ( snext - s ) / ( spancount - 1 ); + tstep = ( tnext - t ) / ( spancount - 1 ); } - } + } // Drawing phrase - if (!SW_TEXFILT) + if( !SW_TEXFILT ) + { + do { - do + pixel_t btemp; + + btemp = *( pbase + ( s >> 16 ) + ( t >> 16 ) * cachewidth ); + if( btemp != TRANSPARENT_COLOR ) { + if( *pz <= ( izi >> 16 )) + { + *pdest = btemp; + *pz = izi >> 16; + } + } + pdest++; + pz++; + izi += izistep; + s += sstep; + t += tstep; + } + while( --spancount > 0 ); + } + else + { + do + { + if( *pz <= ( izi >> 16 )) + { + int idiths = s; + int iditht = t; + + int X = ( pspan->u + spancount ) & 1; + int Y = ( pspan->v ) & 1; pixel_t btemp; - btemp = *(pbase + (s >> 16) + (t >> 16) * cachewidth); - if (btemp != TRANSPARENT_COLOR) + // Using the kernel + idiths += kernel[X][Y][0]; + iditht += kernel[X][Y][1]; + + idiths = idiths >> 16; + idiths = idiths ? idiths - 1 : idiths; + + + iditht = iditht >> 16; + iditht = iditht ? iditht - 1 : iditht; + + + btemp = *( pbase + idiths + iditht * cachewidth ); + if( btemp != TRANSPARENT_COLOR ) { - if (*pz <= (izi >> 16)) - { - *pdest = btemp; - *pz = izi >> 16; - } + *pdest = btemp; + *pz = izi >> 16; } - pdest++; - pz++; - izi += izistep; - s += sstep; - t += tstep; - } while (--spancount > 0); + } + pdest++; + pz++; + s += sstep; + t += tstep; } - else - { - do - { - if (*pz <= (izi >> 16)) - { - int idiths = s; - int iditht = t; - - int X = (pspan->u + spancount) & 1; - int Y = (pspan->v)&1; - pixel_t btemp; - - //Using the kernel - idiths += kernel[X][Y][0]; - iditht += kernel[X][Y][1]; - - idiths = idiths >> 16; - idiths = idiths ? idiths -1 : idiths; + while( --spancount > 0 ); + } - iditht = iditht >> 16; - iditht = iditht ? iditht -1 : iditht; + } + while( count > 0 ); - - btemp = *(pbase + idiths + iditht * cachewidth); - if (btemp != TRANSPARENT_COLOR) - { - *pdest = btemp; - *pz = izi >> 16; - } - } - pdest++; - pz++; - s += sstep; - t += tstep; - } while (--spancount > 0); - } - - - } while (count > 0); - - } while ((pspan = pspan->pnext) != NULL); + } + while(( pspan = pspan->pnext ) != NULL ); } @@ -881,200 +897,204 @@ D_DrawSpans16 */ void D_BlendSpans16( espan_t *pspan, int alpha ) { - int count, spancount; - pixel_t *pbase, *pdest; - fixed16_t s, t, snext, tnext, sstep, tstep; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz8stepu, tdivz8stepu, zi8stepu; - int izi, izistep; - short *pz; + int count, spancount; + pixel_t *pbase, *pdest; + fixed16_t s, t, snext, tnext, sstep, tstep; + float sdivz, tdivz, zi, z, du, dv, spancountminus1; + float sdivz8stepu, tdivz8stepu, zi8stepu; + int izi, izistep; + short *pz; if( alpha > 7 ) alpha = 7; if( alpha == 0 ) return; - sstep = 0; // keep compiler happy - tstep = 0; // ditto + sstep = 0; // keep compiler happy + tstep = 0; // ditto pbase = cacheblock; sdivz8stepu = d_sdivzstepu * 8; tdivz8stepu = d_tdivzstepu * 8; zi8stepu = d_zistepu * 8; - izistep = (int)(d_zistepu * 0x8000 * 0x10000); + izistep = (int)( d_zistepu * 0x8000 * 0x10000 ); do { - pdest = (d_viewbuffer + - (r_screenwidth * pspan->v) + pspan->u); - pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; + pdest = ( d_viewbuffer + + ( r_screenwidth * pspan->v ) + pspan->u ); + pz = d_pzbuffer + ( d_zwidth * pspan->v ) + pspan->u; count = pspan->count; - // calculate the initial s/z, t/z, 1/z, s, and t and clamp + // calculate the initial s/z, t/z, 1/z, s, and t and clamp du = (float)pspan->u; dv = (float)pspan->v; - sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu; - tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu; - zi = d_ziorigin + dv*d_zistepv + du*d_zistepu; - izi = (int)(zi * 0x8000 * 0x10000); - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; + tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; + zi = d_ziorigin + dv * d_zistepv + du * d_zistepu; + izi = (int)( zi * 0x8000 * 0x10000 ); + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - s = (int)(sdivz * z) + sadjust; - if (s > bbextents) + s = (int)( sdivz * z ) + sadjust; + if( s > bbextents ) s = bbextents; - else if (s < 0) + else if( s < 0 ) s = 0; - t = (int)(tdivz * z) + tadjust; - if (t > bbextentt) + t = (int)( tdivz * z ) + tadjust; + if( t > bbextentt ) t = bbextentt; - else if (t < 0) + else if( t < 0 ) t = 0; do { - // calculate s and t at the far end of the span - if (count >= 8) + // calculate s and t at the far end of the span + if( count >= 8 ) spancount = 8; else spancount = count; count -= spancount; - if (count) + if( count ) { - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting + // calculate s/z, t/z, zi->fixed s and t at far end of span, + // calculate s and t steps across span by shifting sdivz += sdivz8stepu; tdivz += tdivz8stepu; zi += zi8stepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 8 ) + snext = 8; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on <0 steps + else if( tnext < 8 ) + tnext = 8; // guard against round-off error on <0 steps - sstep = (snext - s) >> 3; - tstep = (tnext - t) >> 3; + sstep = ( snext - s ) >> 3; + tstep = ( tnext - t ) >> 3; } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so - // can't step off polygon), clamp, calculate s and t steps across - // span by division, biasing steps low so we don't run off the - // texture - spancountminus1 = (float)(spancount - 1); + // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so + // can't step off polygon), clamp, calculate s and t steps across + // span by division, biasing steps low so we don't run off the + // texture + spancountminus1 = (float)( spancount - 1 ); sdivz += d_sdivzstepu * spancountminus1; tdivz += d_tdivzstepu * spancountminus1; zi += d_zistepu * spancountminus1; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 8 ) + snext = 8; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on <0 steps + else if( tnext < 8 ) + tnext = 8; // guard against round-off error on <0 steps - if (spancount > 1) + if( spancount > 1 ) { - sstep = (snext - s) / (spancount - 1); - tstep = (tnext - t) / (spancount - 1); + sstep = ( snext - s ) / ( spancount - 1 ); + tstep = ( tnext - t ) / ( spancount - 1 ); } - } + } // Drawing phrase - if (!SW_TEXFILT) + if( !SW_TEXFILT ) + { + do { - do + if( *pz <= ( izi >> 16 )) { - if (*pz <= (izi >> 16)) + pixel_t btemp; + + btemp = *( pbase + ( s >> 16 ) + ( t >> 16 ) * cachewidth ); + + if( btemp != TRANSPARENT_COLOR ) { - pixel_t btemp; - - btemp = *(pbase + (s >> 16) + (t >> 16) * cachewidth); - - if( btemp != TRANSPARENT_COLOR ) - { - if( alpha != 7 ) - btemp = BLEND_ALPHA( alpha, btemp, *pdest); - *pdest = btemp; - } - //*pz = izi >> 16; + if( alpha != 7 ) + btemp = BLEND_ALPHA( alpha, btemp, *pdest ); + *pdest = btemp; } - pdest++; - pz++; - izi += izistep; - s += sstep; - t += tstep; - } while (--spancount > 0); + // *pz = izi >> 16; + } + pdest++; + pz++; + izi += izistep; + s += sstep; + t += tstep; } - else + while( --spancount > 0 ); + } + else + { + do { - do + int idiths = s; + int iditht = t; + + int X = ( pspan->u + spancount ) & 1; + int Y = ( pspan->v ) & 1; + if( *pz <= ( izi >> 16 )) { - int idiths = s; - int iditht = t; + pixel_t btemp; - int X = (pspan->u + spancount) & 1; - int Y = (pspan->v)&1; - if (*pz <= (izi >> 16)) + // Using the kernel + idiths += kernel[X][Y][0]; + iditht += kernel[X][Y][1]; + + idiths = idiths >> 16; + idiths = idiths ? idiths - 1 : idiths; + + + iditht = iditht >> 16; + iditht = iditht ? iditht - 1 : iditht; + + btemp = *( pbase + idiths + iditht * cachewidth ); + + if( btemp != TRANSPARENT_COLOR ) { - pixel_t btemp; - - //Using the kernel - idiths += kernel[X][Y][0]; - iditht += kernel[X][Y][1]; - - idiths = idiths >> 16; - idiths = idiths ? idiths -1 : idiths; - - - iditht = iditht >> 16; - iditht = iditht ? iditht -1 : iditht; - - btemp = *(pbase + idiths + iditht * cachewidth); - - if( btemp != TRANSPARENT_COLOR ) - { - if( alpha != 7 ) - btemp = BLEND_ALPHA( alpha, btemp, *pdest); - *pdest = btemp; - } - //*pz = izi >> 16; + if( alpha != 7 ) + btemp = BLEND_ALPHA( alpha, btemp, *pdest ); + *pdest = btemp; } - pdest++; - pz++; - izi += izistep; - s += sstep; - t += tstep; - } while (--spancount > 0); + // *pz = izi >> 16; + } + pdest++; + pz++; + izi += izistep; + s += sstep; + t += tstep; } + while( --spancount > 0 ); + } - } while (count > 0); + } + while( count > 0 ); - } while ((pspan = pspan->pnext) != NULL); + } + while(( pspan = pspan->pnext ) != NULL ); } @@ -1086,195 +1106,199 @@ D_DrawSpans16 FIXME: actually make this subdivide by 16 instead of 8!!! ============= */ -void D_AddSpans16 (espan_t *pspan) +void D_AddSpans16( espan_t *pspan ) { - int count, spancount; - pixel_t *pbase, *pdest; - fixed16_t s, t, snext, tnext, sstep, tstep; - float sdivz, tdivz, zi, z, du, dv, spancountminus1; - float sdivz8stepu, tdivz8stepu, zi8stepu; - int izi, izistep; - short *pz; + int count, spancount; + pixel_t *pbase, *pdest; + fixed16_t s, t, snext, tnext, sstep, tstep; + float sdivz, tdivz, zi, z, du, dv, spancountminus1; + float sdivz8stepu, tdivz8stepu, zi8stepu; + int izi, izistep; + short *pz; - sstep = 0; // keep compiler happy - tstep = 0; // ditto + sstep = 0; // keep compiler happy + tstep = 0; // ditto pbase = cacheblock; sdivz8stepu = d_sdivzstepu * 8; tdivz8stepu = d_tdivzstepu * 8; zi8stepu = d_zistepu * 8; - izistep = (int)(d_zistepu * 0x8000 * 0x10000); + izistep = (int)( d_zistepu * 0x8000 * 0x10000 ); do { - pdest = (d_viewbuffer + - (r_screenwidth * pspan->v) + pspan->u); - pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; + pdest = ( d_viewbuffer + + ( r_screenwidth * pspan->v ) + pspan->u ); + pz = d_pzbuffer + ( d_zwidth * pspan->v ) + pspan->u; count = pspan->count; - // calculate the initial s/z, t/z, 1/z, s, and t and clamp + // calculate the initial s/z, t/z, 1/z, s, and t and clamp du = (float)pspan->u; dv = (float)pspan->v; - sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu; - tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu; - zi = d_ziorigin + dv*d_zistepv + du*d_zistepu; - izi = (int)(zi * 0x8000 * 0x10000); - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu; + tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu; + zi = d_ziorigin + dv * d_zistepv + du * d_zistepu; + izi = (int)( zi * 0x8000 * 0x10000 ); + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - s = (int)(sdivz * z) + sadjust; - if (s > bbextents) + s = (int)( sdivz * z ) + sadjust; + if( s > bbextents ) s = bbextents; - else if (s < 0) + else if( s < 0 ) s = 0; - t = (int)(tdivz * z) + tadjust; - if (t > bbextentt) + t = (int)( tdivz * z ) + tadjust; + if( t > bbextentt ) t = bbextentt; - else if (t < 0) + else if( t < 0 ) t = 0; do { - // calculate s and t at the far end of the span - if (count >= 8) + // calculate s and t at the far end of the span + if( count >= 8 ) spancount = 8; else spancount = count; count -= spancount; - if (count) + if( count ) { - // calculate s/z, t/z, zi->fixed s and t at far end of span, - // calculate s and t steps across span by shifting + // calculate s/z, t/z, zi->fixed s and t at far end of span, + // calculate s and t steps across span by shifting sdivz += sdivz8stepu; tdivz += tdivz8stepu; zi += zi8stepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 8 ) + snext = 8; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on <0 steps + else if( tnext < 8 ) + tnext = 8; // guard against round-off error on <0 steps - sstep = (snext - s) >> 3; - tstep = (tnext - t) >> 3; + sstep = ( snext - s ) >> 3; + tstep = ( tnext - t ) >> 3; } else { - // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so - // can't step off polygon), clamp, calculate s and t steps across - // span by division, biasing steps low so we don't run off the - // texture - spancountminus1 = (float)(spancount - 1); + // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so + // can't step off polygon), clamp, calculate s and t steps across + // span by division, biasing steps low so we don't run off the + // texture + spancountminus1 = (float)( spancount - 1 ); sdivz += d_sdivzstepu * spancountminus1; tdivz += d_tdivzstepu * spancountminus1; zi += d_zistepu * spancountminus1; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) + z = (float)0x10000 / zi; // prescale to 16.16 fixed-point + snext = (int)( sdivz * z ) + sadjust; + if( snext > bbextents ) snext = bbextents; - else if (snext < 8) - snext = 8; // prevent round-off error on <0 steps from - // from causing overstepping & running off the - // edge of the texture + else if( snext < 8 ) + snext = 8; // prevent round-off error on <0 steps from + // from causing overstepping & running off the + // edge of the texture - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) + tnext = (int)( tdivz * z ) + tadjust; + if( tnext > bbextentt ) tnext = bbextentt; - else if (tnext < 8) - tnext = 8; // guard against round-off error on <0 steps + else if( tnext < 8 ) + tnext = 8; // guard against round-off error on <0 steps - if (spancount > 1) + if( spancount > 1 ) { - sstep = (snext - s) / (spancount - 1); - tstep = (tnext - t) / (spancount - 1); + sstep = ( snext - s ) / ( spancount - 1 ); + tstep = ( tnext - t ) / ( spancount - 1 ); } - } + } // Drawing phrase - if (!SW_TEXFILT) + if( !SW_TEXFILT ) + { + do { - do + if( *pz <= ( izi >> 16 )) { - if (*pz <= (izi >> 16)) + pixel_t btemp; + + btemp = *( pbase + ( s >> 16 ) + ( t >> 16 ) * cachewidth ); + + if( btemp != TRANSPARENT_COLOR ) { - pixel_t btemp; - - btemp = *(pbase + (s >> 16) + (t >> 16) * cachewidth); - - if( btemp != TRANSPARENT_COLOR ) - { - btemp = BLEND_ADD( btemp, *pdest); - *pdest = btemp; - } - //*pz = izi >> 16; + btemp = BLEND_ADD( btemp, *pdest ); + *pdest = btemp; } - pdest++; - pz++; - izi += izistep; - s += sstep; - t += tstep; - } while (--spancount > 0); + // *pz = izi >> 16; + } + pdest++; + pz++; + izi += izistep; + s += sstep; + t += tstep; } - else + while( --spancount > 0 ); + } + else + { + do { - do + int idiths = s; + int iditht = t; + + int X = ( pspan->u + spancount ) & 1; + int Y = ( pspan->v ) & 1; + if( *pz <= ( izi >> 16 )) { - int idiths = s; - int iditht = t; + pixel_t btemp; - int X = (pspan->u + spancount) & 1; - int Y = (pspan->v)&1; - if (*pz <= (izi >> 16)) + // Using the kernel + idiths += kernel[X][Y][0]; + iditht += kernel[X][Y][1]; + + idiths = idiths >> 16; + idiths = idiths ? idiths - 1 : idiths; + + + iditht = iditht >> 16; + iditht = iditht ? iditht - 1 : iditht; + + btemp = *( pbase + idiths + iditht * cachewidth ); + + if( btemp != TRANSPARENT_COLOR ) { - pixel_t btemp; - - //Using the kernel - idiths += kernel[X][Y][0]; - iditht += kernel[X][Y][1]; - - idiths = idiths >> 16; - idiths = idiths ? idiths -1 : idiths; - - - iditht = iditht >> 16; - iditht = iditht ? iditht -1 : iditht; - - btemp = *(pbase + idiths + iditht * cachewidth); - - if( btemp != TRANSPARENT_COLOR ) - { - btemp = BLEND_ADD( btemp, *pdest); - *pdest = btemp; - } - //*pz = izi >> 16; + btemp = BLEND_ADD( btemp, *pdest ); + *pdest = btemp; } - pdest++; - pz++; - izi += izistep; - s += sstep; - t += tstep; - } while (--spancount > 0); + // *pz = izi >> 16; + } + pdest++; + pz++; + izi += izistep; + s += sstep; + t += tstep; } + while( --spancount > 0 ); + } - } while (count > 0); + } + while( count > 0 ); - } while ((pspan = pspan->pnext) != NULL); + } + while(( pspan = pspan->pnext ) != NULL ); } /* @@ -1282,41 +1306,41 @@ void D_AddSpans16 (espan_t *pspan) D_DrawZSpans ============= */ -void D_DrawZSpans (espan_t *pspan) +void D_DrawZSpans( espan_t *pspan ) { - int count, doublecount, izistep; - int izi; - short *pdest; - unsigned ltemp; - float zi; - float du, dv; + int count, doublecount, izistep; + int izi; + short *pdest; + unsigned ltemp; + float zi; + float du, dv; // FIXME: check for clamping/range problems // we count on FP exceptions being turned off to avoid range problems - izistep = (int)(d_zistepu * 0x8000 * 0x10000); + izistep = (int)( d_zistepu * 0x8000 * 0x10000 ); do { - pdest = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; + pdest = d_pzbuffer + ( d_zwidth * pspan->v ) + pspan->u; count = pspan->count; - // calculate the initial 1/z + // calculate the initial 1/z du = (float)pspan->u; dv = (float)pspan->v; - zi = d_ziorigin + dv*d_zistepv + du*d_zistepu; - // we count on FP exceptions being turned off to avoid range problems - izi = (int)(zi * 0x8000 * 0x10000); + zi = d_ziorigin + dv * d_zistepv + du * d_zistepu; + // we count on FP exceptions being turned off to avoid range problems + izi = (int)( zi * 0x8000 * 0x10000 ); - if ((uintptr_t)pdest & 0x02) + if((uintptr_t)pdest & 0x02 ) { - *pdest++ = (short)(izi >> 16); + *pdest++ = (short)( izi >> 16 ); izi += izistep; count--; } - if ((doublecount = count >> 1) > 0) + if(( doublecount = count >> 1 ) > 0 ) { do { @@ -1326,12 +1350,14 @@ void D_DrawZSpans (espan_t *pspan) izi += izistep; *(int *)pdest = ltemp; pdest += 2; - } while (--doublecount > 0); + } + while( --doublecount > 0 ); } - if (count & 1) - *pdest = (short)(izi >> 16); + if( count & 1 ) + *pdest = (short)( izi >> 16 ); - } while ((pspan = pspan->pnext) != NULL); + } + while(( pspan = pspan->pnext ) != NULL ); } diff --git a/ref/soft/r_sprite.c b/ref/soft/r_sprite.c index 3ef8cd0c..94801bce 100644 --- a/ref/soft/r_sprite.c +++ b/ref/soft/r_sprite.c @@ -19,13 +19,13 @@ GNU General Public License for more details. #include "studio.h" #include "entity_types.h" -#define GLARE_FALLOFF 19000.0f +#define GLARE_FALLOFF 19000.0f -char sprite_name[MAX_QPATH]; -char group_suffix[8]; -static uint r_texFlags = 0; -static int sprite_version; -float sprite_radius; +char sprite_name[MAX_QPATH]; +char group_suffix[8]; +static uint r_texFlags = 0; +static int sprite_version; +float sprite_radius; /* ==================== @@ -46,11 +46,11 @@ upload a single frame */ static const byte *R_SpriteLoadFrame( model_t *mod, const void *pin, mspriteframe_t **ppframe, int num ) { - dspriteframe_t pinframe; - mspriteframe_t *pspriteframe; - int gl_texturenum = 0; - char texname[128]; - int bytes = 1; + dspriteframe_t pinframe; + mspriteframe_t *pspriteframe; + int gl_texturenum = 0; + char texname[128]; + int bytes = 1; memcpy( &pinframe, pin, sizeof( dspriteframe_t )); @@ -80,7 +80,7 @@ static const byte *R_SpriteLoadFrame( model_t *mod, const void *pin, mspritefram pspriteframe->gl_texturenum = gl_texturenum; *ppframe = pspriteframe; - return ( const byte* )(( const byte* )pin + sizeof( dspriteframe_t ) + pinframe.width * pinframe.height * bytes ); + return (const byte *)((const byte *)pin + sizeof( dspriteframe_t ) + pinframe.width * pinframe.height * bytes ); } /* @@ -92,22 +92,22 @@ upload a group frames */ static const void *R_SpriteLoadGroup( model_t *mod, const void *pin, mspriteframe_t **ppframe, int framenum ) { - const dspritegroup_t *pingroup; - mspritegroup_t *pspritegroup; - const dspriteinterval_t *pin_intervals; - float *poutintervals; - int i, groupsize, numframes; - const void *ptemp; + const dspritegroup_t *pingroup; + mspritegroup_t *pspritegroup; + const dspriteinterval_t *pin_intervals; + float *poutintervals; + int i, groupsize, numframes; + const void *ptemp; pingroup = (const dspritegroup_t *)pin; numframes = pingroup->numframes; - groupsize = sizeof( mspritegroup_t ) + (numframes - 1) * sizeof( pspritegroup->frames[0] ); + groupsize = sizeof( mspritegroup_t ) + ( numframes - 1 ) * sizeof( pspritegroup->frames[0] ); pspritegroup = Mem_Calloc( mod->mempool, groupsize ); pspritegroup->numframes = numframes; *ppframe = (mspriteframe_t *)pspritegroup; - pin_intervals = (const dspriteinterval_t *)(pingroup + 1); + pin_intervals = (const dspriteinterval_t *)( pingroup + 1 ); poutintervals = Mem_Calloc( mod->mempool, numframes * sizeof( float )); pspritegroup->intervals = poutintervals; @@ -138,11 +138,11 @@ load sprite model */ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, uint texFlags ) { - const dsprite_t *pin; - const short *numi = NULL; - const byte *pframetype; - msprite_t *psprite; - int i; + const dsprite_t *pin; + const short *numi = NULL; + const byte *pframetype; + msprite_t *psprite; + int i; pin = buffer; psprite = mod->cache.data; @@ -150,7 +150,7 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui if( pin->version == SPRITE_VERSION_Q1 || pin->version == SPRITE_VERSION_32 ) numi = NULL; else if( pin->version == SPRITE_VERSION_HL ) - numi = (const short *)((const byte*)buffer + sizeof( dsprite_hl_t )); + numi = (const short *)((const byte *)buffer + sizeof( dsprite_hl_t )); r_texFlags = texFlags; sprite_version = pin->version; @@ -159,16 +159,16 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui if( numi == NULL ) { - rgbdata_t *pal; + rgbdata_t *pal; pal = gEngfuncs.FS_LoadImage( "#id.pal", (byte *)&i, 768 ); - pframetype = ((const byte*)buffer + sizeof( dsprite_q1_t )); // pinq1 + 1 - gEngfuncs.FS_FreeImage( pal ); // palette installed, no reason to keep this data + pframetype = ((const byte *)buffer + sizeof( dsprite_q1_t )); // pinq1 + 1 + gEngfuncs.FS_FreeImage( pal ); // palette installed, no reason to keep this data } else if( *numi == 256 ) { - const byte *src = (const byte *)(numi+1); - rgbdata_t *pal; + const byte *src = (const byte *)( numi + 1 ); + rgbdata_t *pal; // install palette switch( psprite->texFormat ) @@ -184,7 +184,7 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui break; } - pframetype = (const byte *)(src + 768); + pframetype = (const byte *)( src + 768 ); gEngfuncs.FS_FreeImage( pal ); // palette installed, no reason to keep this data } else @@ -198,7 +198,7 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui for( i = 0; i < mod->numframes; i++ ) { - frametype_t frametype; + frametype_t frametype; dframetype_t dframetype; memcpy( &dframetype, pframetype, sizeof( dframetype )); @@ -220,10 +220,12 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui pframetype = R_SpriteLoadGroup( mod, pframetype + sizeof( dframetype_t ), &psprite->frames[i].frameptr, i ); break; } - if( pframetype == NULL ) break; // technically an error + if( pframetype == NULL ) + break; // technically an error } - if( loaded ) *loaded = true; // done + if( loaded ) + *loaded = true; // done } /* @@ -235,10 +237,10 @@ release sprite model and frames */ void Mod_SpriteUnloadTextures( void *data ) { - msprite_t *psprite; - mspritegroup_t *pspritegroup; - mspriteframe_t *pspriteframe; - int i, j; + msprite_t *psprite; + mspritegroup_t *pspritegroup; + mspriteframe_t *pspriteframe; + int i, j; psprite = data; @@ -275,12 +277,12 @@ assume pModel is valid */ mspriteframe_t *R_GetSpriteFrame( const model_t *pModel, int frame, float yaw ) { - msprite_t *psprite; - mspritegroup_t *pspritegroup; - mspriteframe_t *pspriteframe = NULL; - float *pintervals, fullinterval; - int i, numframes; - float targettime; + msprite_t *psprite; + mspritegroup_t *pspritegroup; + mspriteframe_t *pspriteframe = NULL; + float *pintervals, fullinterval; + int i, numframes; + float targettime; Assert( pModel != NULL ); psprite = pModel->cache.data; @@ -305,13 +307,13 @@ mspriteframe_t *R_GetSpriteFrame( const model_t *pModel, int frame, float yaw ) pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; pintervals = pspritegroup->intervals; numframes = pspritegroup->numframes; - fullinterval = pintervals[numframes-1]; + fullinterval = pintervals[numframes - 1]; // when loading in Mod_LoadSpriteGroup, we guaranteed all interval values // are positive, so we don't have to worry about division by zero targettime = gp_cl->time - ((int)( gp_cl->time / fullinterval )) * fullinterval; - for( i = 0; i < (numframes - 1); i++ ) + for( i = 0; i < ( numframes - 1 ); i++ ) { if( pintervals[i] > targettime ) break; @@ -320,7 +322,7 @@ mspriteframe_t *R_GetSpriteFrame( const model_t *pModel, int frame, float yaw ) } else if( psprite->frames[frame].type == FRAME_ANGLED ) { - int angleframe = (int)(Q_rint(( RI.viewangles[1] - yaw + 45.0f ) / 360 * 8) - 4) & 7; + int angleframe = (int)( Q_rint(( RI.viewangles[1] - yaw + 45.0f ) / 360 * 8 ) - 4 ) & 7; // e.g. doom-style sprite monsters pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; @@ -340,19 +342,19 @@ between frames where are we lerping */ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **oldframe, mspriteframe_t **curframe ) { - msprite_t *psprite; - mspritegroup_t *pspritegroup; - int i, j, numframes, frame; - float lerpFrac, time, jtime, jinterval; - float *pintervals, fullinterval, targettime; - int m_fDoInterp; + msprite_t *psprite; + mspritegroup_t *pspritegroup; + int i, j, numframes, frame; + float lerpFrac, time, jtime, jinterval; + float *pintervals, fullinterval, targettime; + int m_fDoInterp; psprite = ent->model->cache.data; frame = (int)ent->curstate.frame; lerpFrac = 1.0f; // misc info - m_fDoInterp = (ent->curstate.effects & EF_NOINTERP) ? false : true; + m_fDoInterp = ( ent->curstate.effects & EF_NOINTERP ) ? false : true; if( frame < 0 ) { @@ -386,7 +388,8 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old ent->latched.sequencetime = gp_cl->time; lerpFrac = 0.0f; } - else lerpFrac = (gp_cl->time - ent->latched.sequencetime) * 11.0f; + else + lerpFrac = ( gp_cl->time - ent->latched.sequencetime ) * 11.0f; } else { @@ -410,26 +413,28 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old } // get the interpolated frames - if( oldframe ) *oldframe = psprite->frames[ent->latched.prevblending[0]].frameptr; - if( curframe ) *curframe = psprite->frames[frame].frameptr; + if( oldframe ) + *oldframe = psprite->frames[ent->latched.prevblending[0]].frameptr; + if( curframe ) + *curframe = psprite->frames[frame].frameptr; } else if( psprite->frames[frame].type == FRAME_GROUP ) { pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; pintervals = pspritegroup->intervals; numframes = pspritegroup->numframes; - fullinterval = pintervals[numframes-1]; + fullinterval = pintervals[numframes - 1]; jinterval = pintervals[1] - pintervals[0]; time = gp_cl->time; jtime = 0.0f; // when loading in Mod_LoadSpriteGroup, we guaranteed all interval values // are positive, so we don't have to worry about division by zero - targettime = time - ((int)(time / fullinterval)) * fullinterval; + targettime = time - ((int)( time / fullinterval )) * fullinterval; // LordHavoc: since I can't measure the time properly when it loops from numframes - 1 to 0, // i instead measure the time of the first frame, hoping it is consistent - for( i = 0, j = numframes - 1; i < (numframes - 1); i++ ) + for( i = 0, j = numframes - 1; i < ( numframes - 1 ); i++ ) { if( pintervals[i] > targettime ) break; @@ -439,18 +444,21 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old } if( m_fDoInterp ) - lerpFrac = (targettime - jtime) / jinterval; - else j = i; // no lerping + lerpFrac = ( targettime - jtime ) / jinterval; + else + j = i; // no lerping // get the interpolated frames - if( oldframe ) *oldframe = pspritegroup->frames[j]; - if( curframe ) *curframe = pspritegroup->frames[i]; + if( oldframe ) + *oldframe = pspritegroup->frames[j]; + if( curframe ) + *curframe = pspritegroup->frames[i]; } else if( psprite->frames[frame].type == FRAME_ANGLED ) { // e.g. doom-style sprite monsters - float yaw = ent->angles[YAW]; - int angleframe = (int)(Q_rint(( RI.viewangles[1] - yaw + 45.0f ) / 360 * 8) - 4) & 7; + float yaw = ent->angles[YAW]; + int angleframe = (int)( Q_rint(( RI.viewangles[1] - yaw + 45.0f ) / 360 * 8 ) - 4 ) & 7; if( m_fDoInterp ) { @@ -472,7 +480,8 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old ent->latched.sequencetime = gp_cl->time; lerpFrac = 0.0f; } - else lerpFrac = (gp_cl->time - ent->latched.sequencetime) * ent->curstate.framerate; + else + lerpFrac = ( gp_cl->time - ent->latched.sequencetime ) * ent->curstate.framerate; } else { @@ -488,10 +497,12 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old } pspritegroup = (mspritegroup_t *)psprite->frames[ent->latched.prevblending[0]].frameptr; - if( oldframe ) *oldframe = pspritegroup->frames[angleframe]; + if( oldframe ) + *oldframe = pspritegroup->frames[angleframe]; pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; - if( curframe ) *curframe = pspritegroup->frames[angleframe]; + if( curframe ) + *curframe = pspritegroup->frames[angleframe]; } return lerpFrac; @@ -506,8 +517,8 @@ Cull sprite model by bbox */ static qboolean R_CullSpriteModel( cl_entity_t *e, vec3_t origin ) { - vec3_t sprite_mins, sprite_maxs; - float scale = 1.0f; + vec3_t sprite_mins, sprite_maxs; + float scale = 1.0f; if( !e->model->cache.data ) return true; @@ -536,16 +547,16 @@ Set sprite brightness factor */ static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, float *pscale ) { - float dist, brightness; - vec3_t glowDist; - pmtrace_t *tr; + float dist, brightness; + vec3_t glowDist; + pmtrace_t *tr; VectorSubtract( origin, RI.vieworg, glowDist ); dist = VectorLength( glowDist ); if( RP_NORMALPASS( )) { - tr = gEngfuncs.EV_VisTraceLine( RI.vieworg, origin, r_traceglow.value ? PM_GLASS_IGNORE : (PM_GLASS_IGNORE|PM_STUDIO_IGNORE)); + tr = gEngfuncs.EV_VisTraceLine( RI.vieworg, origin, r_traceglow.value ? PM_GLASS_IGNORE : ( PM_GLASS_IGNORE | PM_STUDIO_IGNORE )); if(( 1.0f - tr->fraction ) * dist > 8.0f ) return 0.0f; @@ -572,8 +583,8 @@ static qboolean R_SpriteOccluded( cl_entity_t *e, vec3_t origin, float *pscale ) { if( e->curstate.rendermode == kRenderGlow ) { - float blend; - vec3_t v; + float blend; + vec3_t v; TriWorldToScreen( origin, v ); @@ -604,7 +615,7 @@ R_DrawSpriteQuad */ static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale ) { - vec3_t point; + vec3_t point; image_t *image; r_stats.c_sprite_polys++; @@ -614,22 +625,22 @@ static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right, r_affinetridesc.skinheight = image->height;*/ TriBegin( TRI_QUADS ); - TriTexCoord2f( 0.0f, 1.0f ); - VectorMA( org, frame->down * scale, v_up, point ); - VectorMA( point, frame->left * scale, v_right, point ); - TriVertex3fv( point ); - TriTexCoord2f( 0.0f, 0.0f ); - VectorMA( org, frame->up * scale, v_up, point ); - VectorMA( point, frame->left * scale, v_right, point ); - TriVertex3fv( point ); - TriTexCoord2f( 1.0f, 0.0f ); - VectorMA( org, frame->up * scale, v_up, point ); - VectorMA( point, frame->right * scale, v_right, point ); - TriVertex3fv( point ); - TriTexCoord2f( 1.0f, 1.0f ); - VectorMA( org, frame->down * scale, v_up, point ); - VectorMA( point, frame->right * scale, v_right, point ); - TriVertex3fv( point ); + TriTexCoord2f( 0.0f, 1.0f ); + VectorMA( org, frame->down * scale, v_up, point ); + VectorMA( point, frame->left * scale, v_right, point ); + TriVertex3fv( point ); + TriTexCoord2f( 0.0f, 0.0f ); + VectorMA( org, frame->up * scale, v_up, point ); + VectorMA( point, frame->left * scale, v_right, point ); + TriVertex3fv( point ); + TriTexCoord2f( 1.0f, 0.0f ); + VectorMA( org, frame->up * scale, v_up, point ); + VectorMA( point, frame->right * scale, v_right, point ); + TriVertex3fv( point ); + TriTexCoord2f( 1.0f, 1.0f ); + VectorMA( org, frame->down * scale, v_up, point ); + VectorMA( point, frame->right * scale, v_right, point ); + TriVertex3fv( point ); TriEnd(); } @@ -689,26 +700,26 @@ R_DrawSpriteModel */ void R_DrawSpriteModel( cl_entity_t *e ) { - mspriteframe_t *frame, *oldframe; - msprite_t *psprite; - model_t *model; - int i, type; - float angle, dot, sr, cr; - float lerp = 1.0f, ilerp, scale; - vec3_t v_forward, v_right, v_up; - vec3_t origin, color, color2; + mspriteframe_t *frame, *oldframe; + msprite_t *psprite; + model_t *model; + int i, type; + float angle, dot, sr, cr; + float lerp = 1.0f, ilerp, scale; + vec3_t v_forward, v_right, v_up; + vec3_t origin, color, color2; if( RI.params & RP_ENVVIEW ) return; model = e->model; - psprite = (msprite_t * )model->cache.data; - VectorCopy( e->origin, origin ); // set render origin + psprite = (msprite_t *)model->cache.data; + VectorCopy( e->origin, origin ); // set render origin // do movewith if( e->curstate.aiment > 0 && e->curstate.movetype == MOVETYPE_FOLLOW ) { - cl_entity_t *parent; + cl_entity_t *parent; parent = CL_GetEntityByIndex( e->curstate.aiment ); @@ -717,14 +728,16 @@ void R_DrawSpriteModel( cl_entity_t *e ) if( parent->model->type == mod_studio && e->curstate.body > 0 ) { int num = bound( 1, e->curstate.body, MAXSTUDIOATTACHMENTS ); - VectorCopy( parent->attachment[num-1], origin ); + VectorCopy( parent->attachment[num - 1], origin ); } - else VectorCopy( parent->origin, origin ); + else + VectorCopy( parent->origin, origin ); } } scale = e->curstate.scale; - if( !scale ) scale = 1.0f; + if( !scale ) + scale = 1.0f; if( R_SpriteOccluded( e, origin, &scale )) return; // sprite culled @@ -758,12 +771,13 @@ void R_DrawSpriteModel( cl_entity_t *e ) color2[1] = (float)lightColor.g * ( 1.0f / 255.0f ); color2[2] = (float)lightColor.b * ( 1.0f / 255.0f ); // NOTE: sprites with 'lightmap' looks ugly when alpha func is GL_GREATER 0.0 - // pglAlphaFunc( GL_GREATER, 0.5f ); + // pglAlphaFunc( GL_GREATER, 0.5f ); } if( R_SpriteAllowLerping( e, psprite )) lerp = R_GetSpriteFrameInterpolant( e, &oldframe, &frame ); - else frame = oldframe = R_GetSpriteFrame( model, e->curstate.frame, e->angles[YAW] ); + else + frame = oldframe = R_GetSpriteFrame( model, e->curstate.frame, e->angles[YAW] ); type = psprite->type; @@ -775,28 +789,28 @@ void R_DrawSpriteModel( cl_entity_t *e ) { case SPR_ORIENTED: AngleVectors( e->angles, v_forward, v_right, v_up ); - VectorScale( v_forward, 0.01f, v_forward ); // to avoid z-fighting + VectorScale( v_forward, 0.01f, v_forward ); // to avoid z-fighting VectorSubtract( origin, v_forward, origin ); break; case SPR_FACING_UPRIGHT: - VectorSet( v_right, origin[1] - RI.vieworg[1], -(origin[0] - RI.vieworg[0]), 0.0f ); + VectorSet( v_right, origin[1] - RI.vieworg[1], -( origin[0] - RI.vieworg[0] ), 0.0f ); VectorSet( v_up, 0.0f, 0.0f, 1.0f ); VectorNormalize( v_right ); break; case SPR_FWD_PARALLEL_UPRIGHT: dot = RI.vforward[2]; - if(( dot > 0.999848f ) || ( dot < -0.999848f )) // cos(1 degree) = 0.999848 + if(( dot > 0.999848f ) || ( dot < -0.999848f )) // cos(1 degree) = 0.999848 return; // invisible VectorSet( v_up, 0.0f, 0.0f, 1.0f ); VectorSet( v_right, RI.vforward[1], -RI.vforward[0], 0.0f ); VectorNormalize( v_right ); break; case SPR_FWD_PARALLEL_ORIENTED: - angle = e->angles[ROLL] * (M_PI2 / 360.0f); + angle = e->angles[ROLL] * ( M_PI2 / 360.0f ); SinCos( angle, &sr, &cr ); for( i = 0; i < 3; i++ ) { - v_right[i] = (RI.vright[i] * cr + RI.vup[i] * sr); + v_right[i] = ( RI.vright[i] * cr + RI.vup[i] * sr ); v_up[i] = RI.vright[i] * -sr + RI.vup[i] * cr; } break; @@ -807,8 +821,8 @@ void R_DrawSpriteModel( cl_entity_t *e ) break; } - //if( psprite->facecull == SPR_CULL_NONE ) - //GL_Cull( GL_NONE ); + // if( psprite->facecull == SPR_CULL_NONE ) + // GL_Cull( GL_NONE ); if( oldframe == frame ) { diff --git a/ref/soft/r_studio.c b/ref/soft/r_studio.c index 4568ff58..d18ff33c 100644 --- a/ref/soft/r_studio.c +++ b/ref/soft/r_studio.c @@ -22,34 +22,34 @@ GNU General Public License for more details. #include "pm_local.h" #include "pmtrace.h" -#define EVENT_CLIENT 5000 // less than this value it's a server-side studio events -#define MAX_LOCALLIGHTS 4 +#define EVENT_CLIENT 5000 // less than this value it's a server-side studio events +#define MAX_LOCALLIGHTS 4 typedef struct { - char name[MAX_OSPATH]; - char modelname[MAX_OSPATH]; - model_t *model; + char name[MAX_OSPATH]; + char modelname[MAX_OSPATH]; + model_t *model; } player_model_t; CVAR_DEFINE_AUTO( r_shadows, "0", 0, "draw ugly shadows" ); static const vec3_t hullcolor[8] = { -{ 1.0f, 1.0f, 1.0f }, -{ 1.0f, 0.5f, 0.5f }, -{ 0.5f, 1.0f, 0.5f }, -{ 1.0f, 1.0f, 0.5f }, -{ 0.5f, 0.5f, 1.0f }, -{ 1.0f, 0.5f, 1.0f }, -{ 0.5f, 1.0f, 1.0f }, -{ 1.0f, 1.0f, 1.0f }, + { 1.0f, 1.0f, 1.0f }, + { 1.0f, 0.5f, 0.5f }, + { 0.5f, 1.0f, 0.5f }, + { 1.0f, 1.0f, 0.5f }, + { 0.5f, 0.5f, 1.0f }, + { 1.0f, 0.5f, 1.0f }, + { 0.5f, 1.0f, 1.0f }, + { 1.0f, 1.0f, 1.0f }, }; typedef struct sortedmesh_s { - mstudiomesh_t *mesh; - int flags; // face flags + mstudiomesh_t *mesh; + int flags; // face flags } sortedmesh_t; #if XASH_LOW_MEMORY @@ -59,79 +59,79 @@ typedef struct sortedmesh_s typedef struct { - double time; - double frametime; - int framecount; // studio framecount - qboolean interpolate; - int rendermode; - float blend; // blend value + double time; + double frametime; + int framecount; // studio framecount + qboolean interpolate; + int rendermode; + float blend; // blend value // bones - matrix3x4 rotationmatrix; - matrix3x4 bonestransform[MAXSTUDIOBONES]; - matrix3x4 lighttransform[MAXSTUDIOBONES]; + matrix3x4 rotationmatrix; + matrix3x4 bonestransform[MAXSTUDIOBONES]; + matrix3x4 lighttransform[MAXSTUDIOBONES]; // boneweighting stuff - matrix3x4 worldtransform[MAXSTUDIOBONES]; + matrix3x4 worldtransform[MAXSTUDIOBONES]; // cached bones - matrix3x4 cached_bonestransform[MAXSTUDIOBONES]; - matrix3x4 cached_lighttransform[MAXSTUDIOBONES]; - char cached_bonenames[MAXSTUDIOBONES][32]; - int cached_numbones; // number of bones in cache + matrix3x4 cached_bonestransform[MAXSTUDIOBONES]; + matrix3x4 cached_lighttransform[MAXSTUDIOBONES]; + char cached_bonenames[MAXSTUDIOBONES][32]; + int cached_numbones; // number of bones in cache - sortedmesh_t meshes[MAXSTUDIOMESHES]; // sorted meshes - vec3_t verts[MAXSTUDIOVERTS]; - vec3_t norms[MAXSTUDIOVERTS]; + sortedmesh_t meshes[MAXSTUDIOMESHES]; // sorted meshes + vec3_t verts[MAXSTUDIOVERTS]; + vec3_t norms[MAXSTUDIOVERTS]; // lighting state - float ambientlight; - float shadelight; - vec3_t lightvec; // averaging light direction - vec3_t lightspot; // shadow spot - vec3_t lightcolor; // averaging lightcolor - vec3_t blightvec[MAXSTUDIOBONES]; // bone light vecs - vec3_t lightvalues[MAXSTUDIOVERTS]; // precomputed lightvalues per each shared vertex of submodel + float ambientlight; + float shadelight; + vec3_t lightvec; // averaging light direction + vec3_t lightspot; // shadow spot + vec3_t lightcolor; // averaging lightcolor + vec3_t blightvec[MAXSTUDIOBONES]; // bone light vecs + vec3_t lightvalues[MAXSTUDIOVERTS]; // precomputed lightvalues per each shared vertex of submodel // chrome stuff - vec3_t chrome_origin; - vec2_t chrome[MAXSTUDIOVERTS]; // texture coords for surface normals - vec3_t chromeright[MAXSTUDIOBONES]; // chrome vector "right" in bone reference frames - vec3_t chromeup[MAXSTUDIOBONES]; // chrome vector "up" in bone reference frames - int chromeage[MAXSTUDIOBONES]; // last time chrome vectors were updated + vec3_t chrome_origin; + vec2_t chrome[MAXSTUDIOVERTS]; // texture coords for surface normals + vec3_t chromeright[MAXSTUDIOBONES]; // chrome vector "right" in bone reference frames + vec3_t chromeup[MAXSTUDIOBONES]; // chrome vector "up" in bone reference frames + int chromeage[MAXSTUDIOBONES]; // last time chrome vectors were updated // glowshell stuff - int normaltable[MAXSTUDIOVERTS]; // glowshell uses this + int normaltable[MAXSTUDIOVERTS]; // glowshell uses this // elights cache - int numlocallights; - int lightage[MAXSTUDIOBONES]; - dlight_t *locallight[MAX_LOCALLIGHTS]; - uint locallightcolor[MAX_LOCALLIGHTS][3]; - vec4_t lightpos[MAXSTUDIOVERTS][MAX_LOCALLIGHTS]; - vec3_t lightbonepos[MAXSTUDIOBONES][MAX_LOCALLIGHTS]; - float locallightR2[MAX_LOCALLIGHTS]; + int numlocallights; + int lightage[MAXSTUDIOBONES]; + dlight_t *locallight[MAX_LOCALLIGHTS]; + uint locallightcolor[MAX_LOCALLIGHTS][3]; + vec4_t lightpos[MAXSTUDIOVERTS][MAX_LOCALLIGHTS]; + vec3_t lightbonepos[MAXSTUDIOBONES][MAX_LOCALLIGHTS]; + float locallightR2[MAX_LOCALLIGHTS]; // playermodels - player_model_t player_models[MAX_CLIENTS]; + player_model_t player_models[MAX_CLIENTS]; } studio_draw_state_t; // studio-related cvars CVAR_DEFINE_AUTO( r_studio_sort_textures, "0", FCVAR_GLCONFIG, "change draw order for additive meshes" ); -static cvar_t *cl_righthand = NULL; +static cvar_t *cl_righthand = NULL; -static r_studio_interface_t *pStudioDraw; -static studio_draw_state_t g_studio; // global studio state +static r_studio_interface_t *pStudioDraw; +static studio_draw_state_t g_studio; // global studio state // global variables -static qboolean m_fDoRemap; -mstudiomodel_t *m_pSubModel; -mstudiobodyparts_t *m_pBodyPart; -player_info_t *m_pPlayerInfo; -studiohdr_t *m_pStudioHeader; -float m_flGaitMovement; -int g_nTopColor, g_nBottomColor; // remap colors -int g_nFaceFlags, g_nForceFaceFlags; +static qboolean m_fDoRemap; +mstudiomodel_t *m_pSubModel; +mstudiobodyparts_t *m_pBodyPart; +player_info_t *m_pPlayerInfo; +studiohdr_t *m_pStudioHeader; +float m_flGaitMovement; +int g_nTopColor, g_nBottomColor; // remap colors +int g_nFaceFlags, g_nForceFaceFlags; /* ==================== @@ -164,7 +164,7 @@ static void R_StudioSetupTimings( void ) { // synchronize with server time g_studio.time = gp_cl->time; - g_studio.frametime = gp_cl->time - gp_cl->oldtime; + g_studio.frametime = gp_cl->time - gp_cl->oldtime; } else { @@ -201,11 +201,11 @@ Compute a full bounding box for current sequence */ static qboolean R_StudioComputeBBox( vec3_t bbox[8] ) { - vec3_t studio_mins, studio_maxs; - vec3_t mins, maxs, p1, p2; - cl_entity_t *e = RI.currententity; - mstudioseqdesc_t *pseqdesc; - int i; + vec3_t studio_mins, studio_maxs; + vec3_t mins, maxs, p1, p2; + cl_entity_t *e = RI.currententity; + mstudioseqdesc_t *pseqdesc; + int i; if( !m_pStudioHeader ) return false; @@ -226,7 +226,7 @@ static qboolean R_StudioComputeBBox( vec3_t bbox[8] ) if( e->curstate.sequence < 0 || e->curstate.sequence >= m_pStudioHeader->numseq ) e->curstate.sequence = 0; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; + pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + e->curstate.sequence; // add sequence box to the model box AddPointToBounds( pseqdesc->bbmin, mins, maxs ); @@ -236,25 +236,26 @@ static qboolean R_StudioComputeBBox( vec3_t bbox[8] ) // compute a full bounding box for( i = 0; i < 8; i++ ) { - p1[0] = ( i & 1 ) ? mins[0] : maxs[0]; - p1[1] = ( i & 2 ) ? mins[1] : maxs[1]; - p1[2] = ( i & 4 ) ? mins[2] : maxs[2]; + p1[0] = ( i & 1 ) ? mins[0] : maxs[0]; + p1[1] = ( i & 2 ) ? mins[1] : maxs[1]; + p1[2] = ( i & 4 ) ? mins[2] : maxs[2]; Matrix3x4_VectorTransform( g_studio.rotationmatrix, p1, p2 ); AddPointToBounds( p2, studio_mins, studio_maxs ); - if( bbox ) VectorCopy( p2, bbox[i] ); + if( bbox ) + VectorCopy( p2, bbox[i] ); } if( !bbox && R_CullModel( e, studio_mins, studio_maxs )) - return false; // model culled - return true; // visible + return false; // model culled + return true; // visible } static void R_StudioComputeSkinMatrix( mstudioboneweight_t *boneweights, matrix3x4 result ) { - float flWeight0, flWeight1, flWeight2, flWeight3; - int i, numbones = 0; - float flTotal; + float flWeight0, flWeight1, flWeight2, flWeight3; + int i, numbones = 0; + float flTotal; for( i = 0; i < MAXSTUDIOBONEWEIGHTS; i++ ) { @@ -274,7 +275,8 @@ static void R_StudioComputeSkinMatrix( mstudioboneweight_t *boneweights, matrix3 flWeight3 = boneweights->weight[3] / 255.0f; flTotal = flWeight0 + flWeight1 + flWeight2 + flWeight3; - if( flTotal < 1.0f ) flWeight0 += 1.0f - flTotal; // compensate rounding error + if( flTotal < 1.0f ) + flWeight0 += 1.0f - flTotal; // compensate rounding error result[0][0] = boneMat0[0][0] * flWeight0 + boneMat1[0][0] * flWeight1 + boneMat2[0][0] * flWeight2 + boneMat3[0][0] * flWeight3; result[0][1] = boneMat0[0][1] * flWeight0 + boneMat1[0][1] * flWeight1 + boneMat2[0][1] * flWeight2 + boneMat3[0][1] * flWeight3; @@ -299,7 +301,8 @@ static void R_StudioComputeSkinMatrix( mstudioboneweight_t *boneweights, matrix3 flWeight2 = boneweights->weight[2] / 255.0f; flTotal = flWeight0 + flWeight1 + flWeight2; - if( flTotal < 1.0f ) flWeight0 += 1.0f - flTotal; // compensate rounding error + if( flTotal < 1.0f ) + flWeight0 += 1.0f - flTotal; // compensate rounding error result[0][0] = boneMat0[0][0] * flWeight0 + boneMat1[0][0] * flWeight1 + boneMat2[0][0] * flWeight2; result[0][1] = boneMat0[0][1] * flWeight0 + boneMat1[0][1] * flWeight1 + boneMat2[0][1] * flWeight2; @@ -322,7 +325,8 @@ static void R_StudioComputeSkinMatrix( mstudioboneweight_t *boneweights, matrix3 flWeight1 = boneweights->weight[1] / 255.0f; flTotal = flWeight0 + flWeight1; - if( flTotal < 1.0f ) flWeight0 += 1.0f - flTotal; // compensate rounding error + if( flTotal < 1.0f ) + flWeight0 += 1.0f - flTotal; // compensate rounding error result[0][0] = boneMat0[0][0] * flWeight0 + boneMat1[0][0] * flWeight1; result[0][1] = boneMat0[0][1] * flWeight0 + boneMat1[0][1] * flWeight1; @@ -412,9 +416,12 @@ pfnGetEngineTimes */ static void pfnGetEngineTimes( int *framecount, double *current, double *old ) { - if( framecount ) *framecount = tr.realframecount; - if( current ) *current = gp_cl->time; - if( old ) *old = gp_cl->oldtime; + if( framecount ) + *framecount = tr.realframecount; + if( current ) + *current = gp_cl->time; + if( old ) + *old = gp_cl->oldtime; } /* @@ -425,10 +432,14 @@ pfnGetViewInfo */ static void pfnGetViewInfo( float *origin, float *upv, float *rightv, float *forwardv ) { - if( origin ) VectorCopy( RI.vieworg, origin ); - if( forwardv ) VectorCopy( RI.vforward, forwardv ); - if( rightv ) VectorCopy( RI.vright, rightv ); - if( upv ) VectorCopy( RI.vup, upv ); + if( origin ) + VectorCopy( RI.vieworg, origin ); + if( forwardv ) + VectorCopy( RI.vforward, forwardv ); + if( rightv ) + VectorCopy( RI.vright, rightv ); + if( upv ) + VectorCopy( RI.vup, upv ); } /* @@ -462,8 +473,10 @@ pfnGetAliasScale */ static void pfnGetAliasScale( float *x, float *y ) { - if( x ) *x = 1.0f; - if( y ) *y = 1.0f; + if( x ) + *x = 1.0f; + if( y ) + *y = 1.0f; } /* @@ -519,7 +532,7 @@ StudioPlayerBlend static void R_StudioPlayerBlend( mstudioseqdesc_t *pseqdesc, int *pBlend, float *pPitch ) { // calc up/down pointing - *pBlend = (*pPitch * 3.0f); + *pBlend = ( *pPitch * 3.0f ); if( *pBlend < pseqdesc->blendstart[0] ) { @@ -535,7 +548,8 @@ static void R_StudioPlayerBlend( mstudioseqdesc_t *pseqdesc, int *pBlend, float { if( pseqdesc->blendend[0] - pseqdesc->blendstart[0] < 0.1f ) // catch qc error *pBlend = 127; - else *pBlend = 255 * (*pBlend - pseqdesc->blendstart[0]) / (pseqdesc->blendend[0] - pseqdesc->blendstart[0]); + else + *pBlend = 255 * ( *pBlend - pseqdesc->blendstart[0] ) / ( pseqdesc->blendend[0] - pseqdesc->blendstart[0] ); *pPitch = 0.0f; } } @@ -548,7 +562,7 @@ R_StudioLerpMovement */ void GAME_EXPORT R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ) { - float f = 1.0f; + float f = 1.0f; // don't do it if the goalstarttime hasn't updated in a while. // NOTE: Because we need to interpolate multiplayer characters, the interpolation time limit @@ -561,14 +575,15 @@ void GAME_EXPORT R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origi if( !VectorCompareEpsilon( e->curstate.angles, e->latched.prevangles, ON_EPSILON )) { - vec4_t q, q1, q2; + vec4_t q, q1, q2; AngleQuaternion( e->curstate.angles, q1, false ); AngleQuaternion( e->latched.prevangles, q2, false ); QuaternionSlerp( q2, q1, f, q ); QuaternionAngle( q, angles ); } - else VectorCopy( e->curstate.angles, angles ); + else + VectorCopy( e->curstate.angles, angles ); } /* @@ -579,7 +594,7 @@ StudioSetUpTransform */ static void R_StudioSetUpTransform( cl_entity_t *e ) { - vec3_t origin, angles; + vec3_t origin, angles; VectorCopy( e->origin, origin ); VectorCopy( e->angles, angles ); @@ -594,7 +609,8 @@ static void R_StudioSetUpTransform( cl_entity_t *e ) angles[PITCH] = -angles[PITCH]; // stupid quake bug // don't rotate clients, only aim - if( e->player ) angles[PITCH] = 0.0f; + if( e->player ) + angles[PITCH] = 0.0f; Matrix3x4_CreateFromEntity( g_studio.rotationmatrix, angles, origin, 1.0f ); @@ -614,31 +630,38 @@ StudioEstimateFrame */ float GAME_EXPORT R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time ) { - double dfdt, f; + double dfdt, f; if( g_studio.interpolate ) { - if( time < e->curstate.animtime ) dfdt = 0.0; - else dfdt = (time - e->curstate.animtime) * e->curstate.framerate * pseqdesc->fps; + if( time < e->curstate.animtime ) + dfdt = 0.0; + else + dfdt = ( time - e->curstate.animtime ) * e->curstate.framerate * pseqdesc->fps; } - else dfdt = 0; + else + dfdt = 0; - if( pseqdesc->numframes <= 1 ) f = 0.0; - else f = (e->curstate.frame * (pseqdesc->numframes - 1)) / 256.0; + if( pseqdesc->numframes <= 1 ) + f = 0.0; + else + f = ( e->curstate.frame * ( pseqdesc->numframes - 1 )) / 256.0; f += dfdt; if( pseqdesc->flags & STUDIO_LOOPING ) { if( pseqdesc->numframes > 1 ) - f -= (int)(f / (pseqdesc->numframes - 1)) * (pseqdesc->numframes - 1); - if( f < 0 ) f += (pseqdesc->numframes - 1); + f -= (int)( f / ( pseqdesc->numframes - 1 )) * ( pseqdesc->numframes - 1 ); + if( f < 0 ) + f += ( pseqdesc->numframes - 1 ); } else { if( f >= pseqdesc->numframes - 1.001 ) f = pseqdesc->numframes - 1.001; - if( f < 0.0 ) f = 0.0; + if( f < 0.0 ) + f = 0.0; } return f; } @@ -651,12 +674,13 @@ StudioEstimateInterpolant */ static float R_StudioEstimateInterpolant( cl_entity_t *e ) { - float dadt = 1.0f; + float dadt = 1.0f; if( g_studio.interpolate && ( e->curstate.animtime >= e->latched.prevanimtime + 0.01f )) { dadt = ( g_studio.time - e->curstate.animtime ) / 0.1f; - if( dadt > 2.0f ) dadt = 2.0f; + if( dadt > 2.0f ) + dadt = 2.0f; } return dadt; @@ -676,33 +700,36 @@ static void R_StudioFxTransform( cl_entity_t *ent, matrix3x4 transform ) case kRenderFxHologram: if( !gEngfuncs.COM_RandomLong( 0, 49 )) { - int axis = gEngfuncs.COM_RandomLong( 0, 1 ); + int axis = gEngfuncs.COM_RandomLong( 0, 1 ); - if( axis == 1 ) axis = 2; // choose between x & z + if( axis == 1 ) + axis = 2; // choose between x & z VectorScale( transform[axis], gEngfuncs.COM_RandomFloat( 1.0f, 1.484f ), transform[axis] ); } else if( !gEngfuncs.COM_RandomLong( 0, 49 )) { - float offset; - int axis = gEngfuncs.COM_RandomLong( 0, 1 ); + float offset; + int axis = gEngfuncs.COM_RandomLong( 0, 1 ); - if( axis == 1 ) axis = 2; // choose between x & z + if( axis == 1 ) + axis = 2; // choose between x & z offset = gEngfuncs.COM_RandomFloat( -10.0f, 10.0f ); transform[gEngfuncs.COM_RandomLong( 0, 2 )][3] += offset; } break; case kRenderFxExplode: - { - float scale; + { + float scale; - scale = 1.0f + ( g_studio.time - ent->curstate.animtime ) * 10.0f; - if( scale > 2.0f ) scale = 2.0f; // don't blow up more than 200% + scale = 1.0f + ( g_studio.time - ent->curstate.animtime ) * 10.0f; + if( scale > 2.0f ) + scale = 2.0f; // don't blow up more than 200% - transform[0][1] *= scale; - transform[1][1] *= scale; - transform[2][1] *= scale; - } - break; + transform[0][1] *= scale; + transform[1][1] *= scale; + transform[2][1] *= scale; + } + break; } } @@ -714,11 +741,11 @@ StudioCalcBoneAdj */ static void R_StudioCalcBoneAdj( float dadt, float *adj, const byte *pcontroller1, const byte *pcontroller2, byte mouthopen ) { - mstudiobonecontroller_t *pbonecontroller; - float value = 0.0f; - int i, j; + mstudiobonecontroller_t *pbonecontroller; + float value = 0.0f; + int i, j; - pbonecontroller = (mstudiobonecontroller_t *)((byte *)m_pStudioHeader + m_pStudioHeader->bonecontrollerindex); + pbonecontroller = (mstudiobonecontroller_t *)((byte *)m_pStudioHeader + m_pStudioHeader->bonecontrollerindex ); for( j = 0; j < m_pStudioHeader->numbonecontrollers; j++ ) { @@ -729,7 +756,7 @@ static void R_StudioCalcBoneAdj( float dadt, float *adj, const byte *pcontroller // mouth hardcoded at controller 4 value = (float)mouthopen / 64.0f; value = bound( 0.0f, value, 1.0f ); - value = (1.0f - value) * pbonecontroller[j].start + value * pbonecontroller[j].end; + value = ( 1.0f - value ) * pbonecontroller[j].start + value * pbonecontroller[j].end; } else if( i < 4 ) { @@ -738,20 +765,20 @@ static void R_StudioCalcBoneAdj( float dadt, float *adj, const byte *pcontroller { if( abs( pcontroller1[i] - pcontroller2[i] ) > 128 ) { - int a = (pcontroller1[i] + 128) % 256; - int b = (pcontroller2[i] + 128) % 256; - value = (( a * dadt ) + ( b * ( 1.0f - dadt )) - 128) * (360.0f / 256.0f) + pbonecontroller[j].start; + int a = ( pcontroller1[i] + 128 ) % 256; + int b = ( pcontroller2[i] + 128 ) % 256; + value = (( a * dadt ) + ( b * ( 1.0f - dadt )) - 128 ) * ( 360.0f / 256.0f ) + pbonecontroller[j].start; } else { - value = ((pcontroller1[i] * dadt + (pcontroller2[i]) * (1.0f - dadt))) * (360.0f / 256.0f) + pbonecontroller[j].start; + value = (( pcontroller1[i] * dadt + ( pcontroller2[i] ) * ( 1.0f - dadt ))) * ( 360.0f / 256.0f ) + pbonecontroller[j].start; } } else { - value = (pcontroller1[i] * dadt + pcontroller2[i] * (1.0f - dadt)) / 255.0f; + value = ( pcontroller1[i] * dadt + pcontroller2[i] * ( 1.0f - dadt )) / 255.0f; value = bound( 0.0f, value, 1.0f ); - value = (1.0f - value) * pbonecontroller[j].start + value * pbonecontroller[j].end; + value = ( 1.0f - value ) * pbonecontroller[j].start + value * pbonecontroller[j].end; } } @@ -779,10 +806,10 @@ StudioCalcRotations */ static void R_StudioCalcRotations( cl_entity_t *e, float pos[][3], vec4_t *q, mstudioseqdesc_t *pseqdesc, mstudioanim_t *panim, float f ) { - int i, frame; - float adj[MAXSTUDIOCONTROLLERS]; - float s, dadt; - mstudiobone_t *pbone; + int i, frame; + float adj[MAXSTUDIOCONTROLLERS]; + float s, dadt; + mstudiobone_t *pbone; // bah, fix this bug with changing sequences too fast if( f > pseqdesc->numframes - 1 ) @@ -800,10 +827,10 @@ static void R_StudioCalcRotations( cl_entity_t *e, float pos[][3], vec4_t *q, ms frame = (int)f; dadt = R_StudioEstimateInterpolant( e ); - s = (f - frame); + s = ( f - frame ); // add in programtic controllers - pbone = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); + pbone = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex ); R_StudioCalcBoneAdj( dadt, adj, e->curstate.controller, e->latched.prevcontroller, e->mouth.mouthopen ); @@ -813,9 +840,12 @@ static void R_StudioCalcRotations( cl_entity_t *e, float pos[][3], vec4_t *q, ms R_StudioCalcBonePosition( frame, s, pbone, panim, adj, pos[i] ); } - if( pseqdesc->motiontype & STUDIO_X ) pos[pseqdesc->motionbone][0] = 0.0f; - if( pseqdesc->motiontype & STUDIO_Y ) pos[pseqdesc->motionbone][1] = 0.0f; - if( pseqdesc->motiontype & STUDIO_Z ) pos[pseqdesc->motionbone][2] = 0.0f; + if( pseqdesc->motiontype & STUDIO_X ) + pos[pseqdesc->motionbone][0] = 0.0f; + if( pseqdesc->motiontype & STUDIO_Y ) + pos[pseqdesc->motionbone][1] = 0.0f; + if( pseqdesc->motiontype & STUDIO_Z ) + pos[pseqdesc->motionbone][2] = 0.0f; } /* @@ -826,25 +856,25 @@ StudioMergeBones */ static void R_StudioMergeBones( cl_entity_t *e, model_t *m_pSubModel ) { - int i, j; - mstudiobone_t *pbones; - mstudioseqdesc_t *pseqdesc; - mstudioanim_t *panim; - matrix3x4 bonematrix; - static vec4_t q[MAXSTUDIOBONES]; - static float pos[MAXSTUDIOBONES][3]; - float f; + int i, j; + mstudiobone_t *pbones; + mstudioseqdesc_t *pseqdesc; + mstudioanim_t *panim; + matrix3x4 bonematrix; + static vec4_t q[MAXSTUDIOBONES]; + static float pos[MAXSTUDIOBONES][3]; + float f; - if( e->curstate.sequence >= m_pStudioHeader->numseq ) + if( e->curstate.sequence >= m_pStudioHeader->numseq ) e->curstate.sequence = 0; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; + pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + e->curstate.sequence; f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, m_pSubModel, pseqdesc ); R_StudioCalcRotations( e, pos, q, pseqdesc, panim, f ); - pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); + pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex ); for( i = 0; i < m_pStudioHeader->numbones; i++ ) { @@ -886,25 +916,25 @@ StudioSetupBones */ static void R_StudioSetupBones( cl_entity_t *e ) { - float f; - mstudiobone_t *pbones; - mstudioseqdesc_t *pseqdesc; - mstudioanim_t *panim; - matrix3x4 bonematrix; - static vec3_t pos[MAXSTUDIOBONES]; - static vec4_t q[MAXSTUDIOBONES]; - static vec3_t pos2[MAXSTUDIOBONES]; - static vec4_t q2[MAXSTUDIOBONES]; - static vec3_t pos3[MAXSTUDIOBONES]; - static vec4_t q3[MAXSTUDIOBONES]; - static vec3_t pos4[MAXSTUDIOBONES]; - static vec4_t q4[MAXSTUDIOBONES]; - int i; + float f; + mstudiobone_t *pbones; + mstudioseqdesc_t *pseqdesc; + mstudioanim_t *panim; + matrix3x4 bonematrix; + static vec3_t pos[MAXSTUDIOBONES]; + static vec4_t q[MAXSTUDIOBONES]; + static vec3_t pos2[MAXSTUDIOBONES]; + static vec4_t q2[MAXSTUDIOBONES]; + static vec3_t pos3[MAXSTUDIOBONES]; + static vec4_t q3[MAXSTUDIOBONES]; + static vec3_t pos4[MAXSTUDIOBONES]; + static vec4_t q4[MAXSTUDIOBONES]; + int i; if( e->curstate.sequence >= m_pStudioHeader->numseq ) e->curstate.sequence = 0; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; + pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + e->curstate.sequence; f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); @@ -913,14 +943,14 @@ static void R_StudioSetupBones( cl_entity_t *e ) if( pseqdesc->numblends > 1 ) { - float s; - float dadt; + float s; + float dadt; panim += m_pStudioHeader->numbones; R_StudioCalcRotations( e, pos2, q2, pseqdesc, panim, f ); dadt = R_StudioEstimateInterpolant( e ); - s = (e->curstate.blending[0] * dadt + e->latched.prevblending[0] * (1.0f - dadt)) / 255.0f; + s = ( e->curstate.blending[0] * dadt + e->latched.prevblending[0] * ( 1.0f - dadt )) / 255.0f; R_StudioSlerpBones( m_pStudioHeader->numbones, q, pos, q2, pos2, s ); @@ -932,10 +962,10 @@ static void R_StudioSetupBones( cl_entity_t *e ) panim += m_pStudioHeader->numbones; R_StudioCalcRotations( e, pos4, q4, pseqdesc, panim, f ); - s = (e->curstate.blending[0] * dadt + e->latched.prevblending[0] * (1.0f - dadt)) / 255.0f; + s = ( e->curstate.blending[0] * dadt + e->latched.prevblending[0] * ( 1.0f - dadt )) / 255.0f; R_StudioSlerpBones( m_pStudioHeader->numbones, q3, pos3, q4, pos4, s ); - s = (e->curstate.blending[1] * dadt + e->latched.prevblending[1] * (1.0f - dadt)) / 255.0f; + s = ( e->curstate.blending[1] * dadt + e->latched.prevblending[1] * ( 1.0f - dadt )) / 255.0f; R_StudioSlerpBones( m_pStudioHeader->numbones, q, pos, q3, pos3, s ); } } @@ -943,11 +973,11 @@ static void R_StudioSetupBones( cl_entity_t *e ) if( g_studio.interpolate && e->latched.sequencetime && ( e->latched.sequencetime + 0.2f > g_studio.time ) && ( e->latched.prevsequence < m_pStudioHeader->numseq )) { // blend from last sequence - static vec3_t pos1b[MAXSTUDIOBONES]; - static vec4_t q1b[MAXSTUDIOBONES]; - float s; + static vec3_t pos1b[MAXSTUDIOBONES]; + static vec4_t q1b[MAXSTUDIOBONES]; + float s; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->latched.prevsequence; + pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + e->latched.prevsequence; panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, RI.currentmodel, pseqdesc ); // clip prevframe @@ -958,7 +988,7 @@ static void R_StudioSetupBones( cl_entity_t *e ) panim += m_pStudioHeader->numbones; R_StudioCalcRotations( e, pos2, q2, pseqdesc, panim, e->latched.prevframe ); - s = (e->latched.prevseqblending[0]) / 255.0f; + s = ( e->latched.prevseqblending[0] ) / 255.0f; R_StudioSlerpBones( m_pStudioHeader->numbones, q1b, pos1b, q2, pos2, s ); if( pseqdesc->numblends == 4 ) @@ -969,10 +999,10 @@ static void R_StudioSetupBones( cl_entity_t *e ) panim += m_pStudioHeader->numbones; R_StudioCalcRotations( e, pos4, q4, pseqdesc, panim, e->latched.prevframe ); - s = (e->latched.prevseqblending[0]) / 255.0f; + s = ( e->latched.prevseqblending[0] ) / 255.0f; R_StudioSlerpBones( m_pStudioHeader->numbones, q3, pos3, q4, pos4, s ); - s = (e->latched.prevseqblending[1]) / 255.0f; + s = ( e->latched.prevseqblending[1] ) / 255.0f; R_StudioSlerpBones( m_pStudioHeader->numbones, q1b, pos1b, q3, pos3, s ); } } @@ -986,17 +1016,17 @@ static void R_StudioSetupBones( cl_entity_t *e ) e->latched.prevframe = f; } - pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); + pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex ); // calc gait animation if( m_pPlayerInfo && m_pPlayerInfo->gaitsequence != 0 ) { - qboolean copy_bones = true; + qboolean copy_bones = true; if( m_pPlayerInfo->gaitsequence >= m_pStudioHeader->numseq ) m_pPlayerInfo->gaitsequence = 0; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pPlayerInfo->gaitsequence; + pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + m_pPlayerInfo->gaitsequence; panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, RI.currentmodel, pseqdesc ); R_StudioCalcRotations( e, pos2, q2, pseqdesc, panim, m_pPlayerInfo->gaitframe ); @@ -1008,7 +1038,8 @@ static void R_StudioSetupBones( cl_entity_t *e ) else if( !Q_strcmp( pbones[pbones[i].parent].name, "Bip01 Pelvis" )) copy_bones = true; - if( !copy_bones ) continue; + if( !copy_bones ) + continue; VectorCopy( pos2[i], pos[i] ); Vector4Copy( q2[i], q[i] ); @@ -1043,10 +1074,10 @@ StudioSaveBones */ static void R_StudioSaveBones( void ) { - mstudiobone_t *pbones; - int i; + mstudiobone_t *pbones; + int i; - pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); + pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex ); g_studio.cached_numbones = m_pStudioHeader->numbones; for( i = 0; i < m_pStudioHeader->numbones; i++ ) @@ -1066,9 +1097,9 @@ NOTE: m_pSubModel must be set */ static void R_StudioBuildNormalTable( void ) { - cl_entity_t *e = RI.currententity; - mstudiomesh_t *pmesh; - int i, j; + cl_entity_t *e = RI.currententity; + mstudiomesh_t *pmesh; + int i, j; Assert( m_pSubModel != NULL ); @@ -1081,14 +1112,15 @@ static void R_StudioBuildNormalTable( void ) for( j = 0; j < m_pSubModel->nummesh; j++ ) { - short *ptricmds; + short *ptricmds; - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + j; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex ) + j; + ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex ); while(( i = *( ptricmds++ ))) { - if( i < 0 ) i = -i; + if( i < 0 ) + i = -i; for( ; i > 0; i--, ptricmds += 4 ) { @@ -1104,7 +1136,8 @@ static void R_StudioBuildNormalTable( void ) if( e->curstate.rendercolor.r || e->curstate.rendercolor.g || e->curstate.rendercolor.b ) TriColor4ub( e->curstate.rendercolor.r, e->curstate.rendercolor.g, e->curstate.rendercolor.b, 255 ); - else TriColor4ub( 255, 255, 255, 255 ); + else + TriColor4ub( 255, 255, 255, 255 ); } /* @@ -1117,10 +1150,10 @@ g_studio.verts must be computed */ static void R_StudioGenerateNormals( void ) { - int v0, v1, v2; - vec3_t e0, e1, norm; - mstudiomesh_t *pmesh; - int i, j; + int v0, v1, v2; + vec3_t e0, e1, norm; + mstudiomesh_t *pmesh; + int i, j; Assert( m_pSubModel != NULL ); @@ -1129,10 +1162,10 @@ static void R_StudioGenerateNormals( void ) for( j = 0; j < m_pSubModel->nummesh; j++ ) { - short *ptricmds; + short *ptricmds; - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + j; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex ) + j; + ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex ); while(( i = *( ptricmds++ ))) { @@ -1169,7 +1202,7 @@ static void R_StudioGenerateNormals( void ) { if( i > 2 ) { - qboolean odd = false; + qboolean odd = false; v0 = ptricmds[0]; ptricmds += 4; v1 = ptricmds[0]; ptricmds += 4; @@ -1186,8 +1219,10 @@ static void R_StudioGenerateNormals( void ) VectorAdd( g_studio.norms[v1], norm, g_studio.norms[v1] ); VectorAdd( g_studio.norms[v2], norm, g_studio.norms[v2] ); - if( odd ) v1 = v2; - else v0 = v2; + if( odd ) + v1 = v2; + else + v0 = v2; odd = !odd; } @@ -1212,14 +1247,14 @@ StudioSetupChrome */ static void R_StudioSetupChrome( float *pchrome, int bone, vec3_t normal ) { - float n; + float n; if( g_studio.chromeage[bone] != g_studio.framecount ) { // calculate vectors from the viewer to the bone. This roughly adjusts for position - vec3_t chromeupvec; // g_studio.chrome t vector in world reference frame - vec3_t chromerightvec; // g_studio.chrome s vector in world reference frame - vec3_t tmp; // vector pointing at bone in world reference frame + vec3_t chromeupvec; // g_studio.chrome t vector in world reference frame + vec3_t chromerightvec; // g_studio.chrome s vector in world reference frame + vec3_t tmp; // vector pointing at bone in world reference frame VectorNegate( g_studio.chrome_origin, tmp ); tmp[0] += g_studio.lighttransform[bone][0][3]; @@ -1240,11 +1275,11 @@ static void R_StudioSetupChrome( float *pchrome, int bone, vec3_t normal ) // calc s coord n = DotProduct( normal, g_studio.chromeright[bone] ); - pchrome[0] = (n + 1.0f) * 32.0f; + pchrome[0] = ( n + 1.0f ) * 32.0f; // calc t coord n = DotProduct( normal, g_studio.chromeup[bone] ); - pchrome[1] = (n + 1.0f) * 32.0f; + pchrome[1] = ( n + 1.0f ) * 32.0f; } /* @@ -1255,20 +1290,20 @@ StudioCalcAttachments */ static void R_StudioCalcAttachments( void ) { - mstudioattachment_t *pAtt; - vec3_t forward, bonepos; - vec3_t localOrg, localAng; - int i; + mstudioattachment_t *pAtt; + vec3_t forward, bonepos; + vec3_t localOrg, localAng; + int i; // calculate attachment points - pAtt = (mstudioattachment_t *)((byte *)m_pStudioHeader + m_pStudioHeader->attachmentindex); + pAtt = (mstudioattachment_t *)((byte *)m_pStudioHeader + m_pStudioHeader->attachmentindex ); for( i = 0; i < Q_min( MAXSTUDIOATTACHMENTS, m_pStudioHeader->numattachments ); i++ ) { Matrix3x4_VectorTransform( g_studio.lighttransform[pAtt[i].bone], pAtt[i].org, RI.currententity->attachment[i] ); VectorSubtract( RI.currententity->attachment[i], RI.currententity->origin, localOrg ); Matrix3x4_OriginFromMatrix( g_studio.lighttransform[pAtt[i].bone], bonepos ); - VectorSubtract( localOrg, bonepos, forward ); // make forward + VectorSubtract( localOrg, bonepos, forward ); // make forward VectorNormalizeFast( forward ); VectorAngles( forward, localAng ); } @@ -1282,20 +1317,22 @@ pfnStudioSetupModel */ static void R_StudioSetupModel( int bodypart, void **ppbodypart, void **ppsubmodel ) { - int index; + int index; if( bodypart > m_pStudioHeader->numbodyparts ) bodypart = 0; - m_pBodyPart = (mstudiobodyparts_t *)((byte *)m_pStudioHeader + m_pStudioHeader->bodypartindex) + bodypart; + m_pBodyPart = (mstudiobodyparts_t *)((byte *)m_pStudioHeader + m_pStudioHeader->bodypartindex ) + bodypart; index = RI.currententity->curstate.body / m_pBodyPart->base; index = index % m_pBodyPart->nummodels; - m_pSubModel = (mstudiomodel_t *)((byte *)m_pStudioHeader + m_pBodyPart->modelindex) + index; + m_pSubModel = (mstudiomodel_t *)((byte *)m_pStudioHeader + m_pBodyPart->modelindex ) + index; - if( ppbodypart ) *ppbodypart = m_pBodyPart; - if( ppsubmodel ) *ppsubmodel = m_pSubModel; + if( ppbodypart ) + *ppbodypart = m_pBodyPart; + if( ppsubmodel ) + *ppsubmodel = m_pSubModel; } /* @@ -1320,13 +1357,13 @@ R_StudioDynamicLight */ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) { - movevars_t *mv = tr.movevars; - vec3_t lightDir, vecSrc, vecEnd; - vec3_t origin, dist, finalLight; - float add, radius, total; - colorVec light; - uint lnum; - dlight_t *dl; + movevars_t *mv = tr.movevars; + vec3_t lightDir, vecSrc, vecEnd; + vec3_t origin, dist, finalLight; + float add, radius, total; + colorVec light; + uint lnum; + dlight_t *dl; if( !plight || !ent || !ent->model ) return; @@ -1344,7 +1381,8 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) // determine plane to get lightvalues from: ceil or floor if( FBitSet( ent->curstate.effects, EF_INVLIGHT )) VectorSet( lightDir, 0.0f, 0.0f, 1.0f ); - else VectorSet( lightDir, 0.0f, 0.0f, -1.0f ); + else + VectorSet( lightDir, 0.0f, 0.0f, -1.0f ); VectorCopy( ent->origin, origin ); @@ -1353,8 +1391,8 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) if(( mv->skycolor_r + mv->skycolor_g + mv->skycolor_b ) != 0 ) { - msurface_t *psurf = NULL; - pmtrace_t trace; + msurface_t *psurf = NULL; + pmtrace_t trace; if( FBitSet( gp_host->features, ENGINE_WRITE_LARGE_COORD )) { @@ -1370,8 +1408,10 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) } trace = gEngfuncs.CL_TraceLine( vecSrc, vecEnd, PM_WORLD_ONLY ); - if( trace.ent > 0 ) psurf = gEngfuncs.EV_TraceSurface( trace.ent, vecSrc, vecEnd ); - else psurf = gEngfuncs.EV_TraceSurface( 0, vecSrc, vecEnd ); + if( trace.ent > 0 ) + psurf = gEngfuncs.EV_TraceSurface( trace.ent, vecSrc, vecEnd ); + else + psurf = gEngfuncs.EV_TraceSurface( 0, vecSrc, vecEnd ); if( FBitSet( ent->model->flags, STUDIO_FORCE_SKYLIGHT ) || ( psurf && FBitSet( psurf->flags, SURF_DRAWSKY ))) { @@ -1385,8 +1425,8 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) if(( light.r + light.g + light.b ) == 0 ) { - colorVec gcolor; - float grad[4]; + colorVec gcolor; + float grad[4]; VectorScale( lightDir, 2048.0f, vecEnd ); VectorAdd( vecEnd, vecSrc, vecEnd ); @@ -1442,7 +1482,8 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) ent->cvFloorColor = light; total = Q_max( Q_max( light.r, light.g ), light.b ); - if( total == 0.0f ) total = 1.0f; + if( total == 0.0f ) + total = 1.0f; // scale lightdir by light intentsity VectorScale( lightDir, total, lightDir ); @@ -1457,7 +1498,7 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) VectorSubtract( ent->origin, dl->origin, dist ); radius = VectorLength( dist ); - add = (dl->radius - radius); + add = ( dl->radius - radius ); if( add > 0.0f ) { @@ -1465,7 +1506,8 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) if( radius > 1.0f ) VectorScale( dist, ( add / radius ), dist ); - else VectorScale( dist, add, dist ); + else + VectorScale( dist, add, dist ); VectorAdd( lightDir, dist, lightDir ); @@ -1477,7 +1519,8 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) if( FBitSet( ent->model->flags, STUDIO_AMBIENT_LIGHT )) add = 0.6f; - else add = bound( 0.75f, v_direct->value, 1.0f ); + else + add = bound( 0.75f, v_direct->value, 1.0f ); VectorScale( lightDir, add, lightDir ); @@ -1492,7 +1535,8 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight ) plight->color[1] = finalLight[1] * ( 1.0f / total ); plight->color[2] = finalLight[2] * ( 1.0f / total ); } - else VectorSet( plight->color, 1.0f, 1.0f, 1.0f ); + else + VectorSet( plight->color, 1.0f, 1.0f, 1.0f ); if( plight->ambientlight > 128 ) plight->ambientlight = 128; @@ -1511,12 +1555,12 @@ pfnStudioEntityLight */ static void R_StudioEntityLight( alight_t *lightinfo ) { - int lnum, i, j, k; - float minstrength, dist2, f, r2; - float lstrength[MAX_LOCALLIGHTS]; - cl_entity_t *ent = RI.currententity; - vec3_t mid, origin, pos; - dlight_t *el; + int lnum, i, j, k; + float minstrength, dist2, f, r2; + float lstrength[MAX_LOCALLIGHTS]; + cl_entity_t *ent = RI.currententity; + vec3_t mid, origin, pos; + dlight_t *el; g_studio.numlocallights = 0; @@ -1539,10 +1583,12 @@ static void R_StudioEntityLight( alight_t *lightinfo ) if(( el->key & 0xFFF ) == ent->index ) { - int att = (el->key >> 12) & 0xF; + int att = ( el->key >> 12 ) & 0xF; - if( att ) VectorCopy( ent->attachment[att], el->origin ); - else VectorCopy( ent->origin, el->origin ); + if( att ) + VectorCopy( ent->attachment[att], el->origin ); + else + VectorCopy( ent->origin, el->origin ); } VectorCopy( el->origin, pos ); @@ -1551,8 +1597,10 @@ static void R_StudioEntityLight( alight_t *lightinfo ) f = DotProduct( mid, mid ); r2 = el->radius * el->radius; - if( f > r2 ) minstrength = r2 / f; - else minstrength = 1.0f; + if( f > r2 ) + minstrength = r2 / f; + else + minstrength = 1.0f; if( minstrength > 0.05f ) { @@ -1567,7 +1615,8 @@ static void R_StudioEntityLight( alight_t *lightinfo ) } } } - else k = g_studio.numlocallights; + else + k = g_studio.numlocallights; if( k != -1 ) { @@ -1593,8 +1642,8 @@ R_StudioSetupLighting */ static void R_StudioSetupLighting( alight_t *plight ) { - float scale = 1.0f; - int i; + float scale = 1.0f; + int i; if( !m_pStudioHeader || !plight ) return; @@ -1609,7 +1658,8 @@ static void R_StudioSetupLighting( alight_t *plight ) for( i = 0; i < m_pStudioHeader->numbones; i++ ) { Matrix3x4_VectorIRotate( g_studio.lighttransform[i], plight->plightvec, g_studio.blightvec[i] ); - if( scale > 1.0f ) VectorNormalize( g_studio.blightvec[i] ); // in case model may be scaled + if( scale > 1.0f ) + VectorNormalize( g_studio.blightvec[i] ); // in case model may be scaled } VectorCopy( plight->color, g_studio.lightcolor ); @@ -1623,7 +1673,7 @@ R_StudioLighting */ static void R_StudioLighting( float *lv, int bone, int flags, vec3_t normal ) { - float illum; + float illum; if( FBitSet( flags, STUDIO_NF_FULLBRIGHT )) { @@ -1639,11 +1689,14 @@ static void R_StudioLighting( float *lv, int bone, int flags, vec3_t normal ) } else { - float r, lightcos; + float r, lightcos; - if( bone != -1 ) lightcos = DotProduct( normal, g_studio.blightvec[bone] ); - else lightcos = DotProduct( normal, g_studio.lightvec ); // -1 colinear, 1 opposite - if( lightcos > 1.0f ) lightcos = 1.0f; + if( bone != -1 ) + lightcos = DotProduct( normal, g_studio.blightvec[bone] ); + else + lightcos = DotProduct( normal, g_studio.lightvec ); // -1 colinear, 1 opposite + if( lightcos > 1.0f ) + lightcos = 1.0f; illum += g_studio.shadelight; @@ -1653,13 +1706,13 @@ static void R_StudioLighting( float *lv, int bone, int flags, vec3_t normal ) if( r <= 1.0f ) { r += 1.0f; - lightcos = (( r - 1.0f ) - lightcos) / r; + lightcos = (( r - 1.0f ) - lightcos ) / r; if( lightcos > 0.0f ) illum += g_studio.shadelight * lightcos; } else { - lightcos = (lightcos + ( r - 1.0f )) / r; + lightcos = ( lightcos + ( r - 1.0f )) / r; if( lightcos > 0.0f ) illum -= g_studio.shadelight * lightcos; } @@ -1680,8 +1733,8 @@ R_LightLambert */ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal, const vec3_t color, byte *out ) { - vec3_t finalLight; - int i; + vec3_t finalLight; + int i; if( !g_studio.numlocallights ) { @@ -1693,7 +1746,7 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal, for( i = 0; i < g_studio.numlocallights; i++ ) { - float r; + float r; r = DotProduct( normal, light[i] ); if( likely( !tr.fFlipViewModel )) @@ -1702,7 +1755,7 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal, if( r > 0.0f ) { vec3_t localLight; - float temp; + float temp; if( light[i][3] == 0.0f ) { @@ -1710,7 +1763,8 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal, if( r2 > 0.0f ) light[i][3] = g_studio.locallightR2[i] / ( r2 * sqrt( r2 )); - else light[i][3] = 0.0001f; + else + light[i][3] = 0.0001f; } temp = r * light[i][3]; @@ -1738,9 +1792,9 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal, } } -static void R_StudioSetColorBegin(short *ptricmds, vec3_t *pstudionorms ) +static void R_StudioSetColorBegin( short *ptricmds, vec3_t *pstudionorms ) { - float *lv = (float *)g_studio.lightvalues[ptricmds[1]]; + float *lv = (float *)g_studio.lightvalues[ptricmds[1]]; rgba_t color; color[3] = tr.blend * 255; @@ -1758,7 +1812,7 @@ R_LightStrength */ static void R_LightStrength( int bone, vec3_t localpos, vec4_t light[MAX_LOCALLIGHTS] ) { - int i; + int i; if( g_studio.lightage[bone] != g_studio.framecount ) { @@ -1786,11 +1840,11 @@ R_StudioSetupSkin */ static void R_StudioSetupSkin( studiohdr_t *ptexturehdr, int index ) { - mstudiotexture_t *ptexture = NULL; + mstudiotexture_t *ptexture = NULL; if( FBitSet( g_nForceFaceFlags, STUDIO_NF_CHROME )) { - GL_Bind( XASH_TEXTURE0, tr.whiteTexture); + GL_Bind( XASH_TEXTURE0, tr.whiteTexture ); return; } @@ -1798,12 +1852,15 @@ static void R_StudioSetupSkin( studiohdr_t *ptexturehdr, int index ) return; // NOTE: user may ignore to call StudioRemapColors and remap_info will be unavailable - if( m_fDoRemap ) ptexture = gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity )->ptexture; - if( !ptexture ) ptexture = (mstudiotexture_t *)((byte *)ptexturehdr + ptexturehdr->textureindex); // fallback + if( m_fDoRemap ) + ptexture = gEngfuncs.CL_GetRemapInfoForEntity( RI.currententity )->ptexture; + if( !ptexture ) + ptexture = (mstudiotexture_t *)((byte *)ptexturehdr + ptexturehdr->textureindex ); // fallback if( r_lightmap->value && !r_fullbright->value ) GL_Bind( XASH_TEXTURE0, tr.whiteTexture ); - else GL_Bind( XASH_TEXTURE0, ptexture[index].index ); + else + GL_Bind( XASH_TEXTURE0, ptexture[index].index ); } /* @@ -1815,24 +1872,28 @@ Doesn't changes studio global state at all */ mstudiotexture_t * GAME_EXPORT R_StudioGetTexture( cl_entity_t *e ) { - mstudiotexture_t *ptexture; - studiohdr_t *phdr, *thdr; + mstudiotexture_t *ptexture; + studiohdr_t *phdr, *thdr; if(( phdr = gEngfuncs.Mod_Extradata( mod_studio, e->model )) == NULL ) return NULL; thdr = m_pStudioHeader; - if( !thdr ) return NULL; + if( !thdr ) + return NULL; - if( m_fDoRemap ) ptexture = gEngfuncs.CL_GetRemapInfoForEntity( e )->ptexture; - else ptexture = (mstudiotexture_t *)((byte *)thdr + thdr->textureindex); + if( m_fDoRemap ) + ptexture = gEngfuncs.CL_GetRemapInfoForEntity( e )->ptexture; + else + ptexture = (mstudiotexture_t *)((byte *)thdr + thdr->textureindex ); return ptexture; } static void R_StudioSetRenderamt( int iRenderamt ) { - if( !RI.currententity ) return; + if( !RI.currententity ) + return; RI.currententity->curstate.renderamt = iRenderamt; tr.blend = CL_FxBlend( RI.currententity ) / 255.0f; @@ -1868,14 +1929,14 @@ static void R_StudioRenderShadow( int iSprite, float *p1, float *p2, float *p3, _TriColor4f( 0.0f, 0.0f, 0.0f, 1.0f ); TriBegin( TRI_QUADS ); - TriTexCoord2f( 0.0f, 0.0f ); - TriVertex3fv( p1 ); - TriTexCoord2f( 0.0f, 1.0f ); - TriVertex3fv( p2 ); - TriTexCoord2f( 1.0f, 1.0f ); - TriVertex3fv( p3 ); - TriTexCoord2f( 1.0f, 0.0f ); - TriVertex3fv( p4 ); + TriTexCoord2f( 0.0f, 0.0f ); + TriVertex3fv( p1 ); + TriTexCoord2f( 0.0f, 1.0f ); + TriVertex3fv( p2 ); + TriTexCoord2f( 1.0f, 1.0f ); + TriVertex3fv( p3 ); + TriTexCoord2f( 1.0f, 0.0f ); + TriVertex3fv( p4 ); TriEnd(); TriRenderMode( kRenderNormal ); @@ -1909,8 +1970,8 @@ generic path */ static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t ) { - float *lv; - int i; + float *lv; + int i; while(( i = *( ptricmds++ ))) { @@ -1919,7 +1980,8 @@ static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float TriBegin( TRI_TRIANGLE_FAN ); i = -i; } - else TriBegin( TRI_TRIANGLE_STRIP ); + else + TriBegin( TRI_TRIANGLE_STRIP ); for( ; i > 0; i--, ptricmds += 4 ) { @@ -1942,8 +2004,8 @@ generic path */ static void R_StudioDrawFloatMesh( short *ptricmds, vec3_t *pstudionorms ) { - float *lv; - int i; + float *lv; + int i; while(( i = *( ptricmds++ ))) { @@ -1952,7 +2014,8 @@ static void R_StudioDrawFloatMesh( short *ptricmds, vec3_t *pstudionorms ) TriBegin( TRI_TRIANGLE_FAN ); i = -i; } - else TriBegin( TRI_TRIANGLE_STRIP ); + else + TriBegin( TRI_TRIANGLE_STRIP ); for( ; i > 0; i--, ptricmds += 4 ) { @@ -1974,10 +2037,10 @@ generic path */ static void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale ) { - float *lv, *av; - int i, idx; - qboolean glowShell = (scale > 0.0f) ? true : false; - vec3_t vert; + float *lv, *av; + int i, idx; + qboolean glowShell = ( scale > 0.0f ) ? true : false; + vec3_t vert; while(( i = *( ptricmds++ ))) { @@ -1986,7 +2049,8 @@ static void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float TriBegin( TRI_TRIANGLE_FAN ); i = -i; } - else TriBegin( TRI_TRIANGLE_STRIP ); + else + TriBegin( TRI_TRIANGLE_STRIP ); for( ; i > 0; i--, ptricmds += 4 ) { @@ -2025,38 +2089,39 @@ R_StudioDrawPoints */ static void R_StudioDrawPoints( void ) { - int i, j, k, m_skinnum; - float shellscale = 0.0f; - qboolean need_sort = false; - byte *pvertbone; - byte *pnormbone; - vec3_t *pstudioverts; - vec3_t *pstudionorms; - mstudiotexture_t *ptexture; - mstudiomesh_t *pmesh; - short *pskinref; - float lv_tmp; + int i, j, k, m_skinnum; + float shellscale = 0.0f; + qboolean need_sort = false; + byte *pvertbone; + byte *pnormbone; + vec3_t *pstudioverts; + vec3_t *pstudionorms; + mstudiotexture_t *ptexture; + mstudiomesh_t *pmesh; + short *pskinref; + float lv_tmp; - if( !m_pStudioHeader ) return; + if( !m_pStudioHeader ) + return; m_skinnum = RI.currententity->curstate.skin; - ptexture = (mstudiotexture_t *)((byte *)m_pStudioHeader + m_pStudioHeader->textureindex); - pvertbone = ((byte *)m_pStudioHeader + m_pSubModel->vertinfoindex); - pnormbone = ((byte *)m_pStudioHeader + m_pSubModel->norminfoindex); + ptexture = (mstudiotexture_t *)((byte *)m_pStudioHeader + m_pStudioHeader->textureindex ); + pvertbone = ((byte *)m_pStudioHeader + m_pSubModel->vertinfoindex ); + pnormbone = ((byte *)m_pStudioHeader + m_pSubModel->norminfoindex ); - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex); - pstudioverts = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->vertindex); - pstudionorms = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->normindex); + pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex ); + pstudioverts = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->vertindex ); + pstudionorms = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->normindex ); - pskinref = (short *)((byte *)m_pStudioHeader + m_pStudioHeader->skinindex); + pskinref = (short *)((byte *)m_pStudioHeader + m_pStudioHeader->skinindex ); if( m_skinnum > 0 && m_skinnum < m_pStudioHeader->numskinfamilies ) - pskinref += (m_skinnum * m_pStudioHeader->numskinref); + pskinref += ( m_skinnum * m_pStudioHeader->numskinref ); if( FBitSet( m_pStudioHeader->flags, STUDIO_HAS_BONEWEIGHTS ) && m_pSubModel->blendvertinfoindex != 0 && m_pSubModel->blendnorminfoindex != 0 ) { - mstudioboneweight_t *pvertweight = (mstudioboneweight_t *)((byte *)m_pStudioHeader + m_pSubModel->blendvertinfoindex); - mstudioboneweight_t *pnormweight = (mstudioboneweight_t *)((byte *)m_pStudioHeader + m_pSubModel->blendnorminfoindex); - matrix3x4 skinMat; + mstudioboneweight_t *pvertweight = (mstudioboneweight_t *)((byte *)m_pStudioHeader + m_pSubModel->blendvertinfoindex ); + mstudioboneweight_t *pnormweight = (mstudioboneweight_t *)((byte *)m_pStudioHeader + m_pSubModel->blendnorminfoindex ); + matrix3x4 skinMat; for( i = 0; i < m_pSubModel->numverts; i++ ) { @@ -2083,7 +2148,7 @@ static void R_StudioDrawPoints( void ) // generate shared normals for properly scaling glowing shell if( RI.currententity->curstate.renderfx == kRenderFxGlowShell ) { - float factor = (1.0f / 128.0f); + float factor = ( 1.0f / 128.0f ); shellscale = Q_max( factor, RI.currententity->curstate.renderamt * factor ); R_StudioBuildNormalTable(); R_StudioGenerateNormals(); @@ -2097,7 +2162,7 @@ static void R_StudioDrawPoints( void ) g_studio.meshes[j].flags = g_nFaceFlags; g_studio.meshes[j].mesh = &pmesh[j]; - if( FBitSet( g_nFaceFlags, STUDIO_NF_MASKED|STUDIO_NF_ADDITIVE )) + if( FBitSet( g_nFaceFlags, STUDIO_NF_MASKED | STUDIO_NF_ADDITIVE )) need_sort = true; if( RI.currententity->curstate.rendermode == kRenderTransAdd ) @@ -2115,7 +2180,8 @@ static void R_StudioDrawPoints( void ) { if( FBitSet( m_pStudioHeader->flags, STUDIO_HAS_BONEWEIGHTS )) R_StudioLighting( &lv_tmp, -1, g_nFaceFlags, g_studio.norms[k] ); - else R_StudioLighting( &lv_tmp, *pnormbone, g_nFaceFlags, (float *)pstudionorms ); + else + R_StudioLighting( &lv_tmp, *pnormbone, g_nFaceFlags, (float *)pstudionorms ); if( FBitSet( g_nFaceFlags, STUDIO_NF_CHROME )) R_StudioSetupChrome( g_studio.chrome[k], *pnormbone, (float *)pstudionorms ); @@ -2127,20 +2193,20 @@ static void R_StudioDrawPoints( void ) if( r_studio_sort_textures.value && need_sort ) { // resort opaque and translucent meshes draw order - qsort( g_studio.meshes, m_pSubModel->nummesh, sizeof( sortedmesh_t ), (void*)R_StudioMeshCompare ); + qsort( g_studio.meshes, m_pSubModel->nummesh, sizeof( sortedmesh_t ), (void *)R_StudioMeshCompare ); } // NOTE: rewind normals at start - pstudionorms = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->normindex); + pstudionorms = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->normindex ); for( j = 0; j < m_pSubModel->nummesh; j++ ) { - float oldblend = tr.blend; - short *ptricmds; - float s, t; + float oldblend = tr.blend; + short *ptricmds; + float s, t; pmesh = g_studio.meshes[j].mesh; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex ); g_nFaceFlags = ptexture[pskinref[pmesh->skinref]].flags | g_nForceFaceFlags; @@ -2149,9 +2215,9 @@ static void R_StudioDrawPoints( void ) if( FBitSet( g_nFaceFlags, STUDIO_NF_MASKED )) { - //pglEnable( GL_ALPHA_TEST ); - //pglAlphaFunc( GL_GREATER, 0.5f ); - //pglDepthMask( GL_TRUE ); + // pglEnable( GL_ALPHA_TEST ); + // pglAlphaFunc( GL_GREATER, 0.5f ); + // pglDepthMask( GL_TRUE ); if( R_ModelOpaque( RI.currententity->curstate.rendermode )) tr.blend = 1.0f; } @@ -2159,12 +2225,12 @@ static void R_StudioDrawPoints( void ) { if( R_ModelOpaque( RI.currententity->curstate.rendermode )) { - //pglBlendFunc( GL_ONE, GL_ONE ); - //pglDepthMask( GL_FALSE ); - //pglEnable( GL_BLEND ); + // pglBlendFunc( GL_ONE, GL_ONE ); + // pglDepthMask( GL_FALSE ); + // pglEnable( GL_BLEND ); R_AllowFog( false ); } - //else pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); + // else pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); } R_StudioSetupSkin( m_pStudioHeader, pskinref[pmesh->skinref] ); @@ -2174,18 +2240,19 @@ static void R_StudioDrawPoints( void ) R_StudioDrawChromeMesh( ptricmds, pstudionorms, s, t, shellscale ); else if( FBitSet( g_nFaceFlags, STUDIO_NF_UV_COORDS )) R_StudioDrawFloatMesh( ptricmds, pstudionorms ); - else R_StudioDrawNormalMesh( ptricmds, pstudionorms, s, t ); + else + R_StudioDrawNormalMesh( ptricmds, pstudionorms, s, t ); } if( FBitSet( g_nFaceFlags, STUDIO_NF_MASKED )) { - //pglAlphaFunc( GL_GREATER, DEFAULT_ALPHATEST ); - //pglDisable( GL_ALPHA_TEST ); + // pglAlphaFunc( GL_GREATER, DEFAULT_ALPHATEST ); + // pglDisable( GL_ALPHA_TEST ); } else if( FBitSet( g_nFaceFlags, STUDIO_NF_ADDITIVE ) && R_ModelOpaque( RI.currententity->curstate.rendermode )) { - //pglDepthMask( GL_TRUE ); - //pglDisable( GL_BLEND ); + // pglDepthMask( GL_TRUE ); + // pglDisable( GL_BLEND ); R_AllowFog( true ); } @@ -2212,9 +2279,9 @@ R_StudioDrawAbsBBox */ static void R_StudioDrawAbsBBox( void ) { - vec3_t p[8], tmp; - float lv; - int i; + vec3_t p[8], tmp; + float lv; + int i; // looks ugly, skip if( RI.currententity == tr.viewent ) @@ -2231,7 +2298,7 @@ static void R_StudioDrawAbsBBox( void ) for( i = 0; i < 6; i++ ) { VectorClear( tmp ); - tmp[i % 3] = (i < 3) ? 1.0f : -1.0f; + tmp[i % 3] = ( i < 3 ) ? 1.0f : -1.0f; R_StudioLighting( &lv, -1, 0, tmp ); TriBrightness( lv ); @@ -2283,8 +2350,8 @@ R_StudioSetupPlayerModel */ static model_t *R_StudioSetupPlayerModel( int index ) { - player_info_t *info = gEngfuncs.pfnPlayerInfo( index ); - player_model_t *state; + player_info_t *info = gEngfuncs.pfnPlayerInfo( index ); + player_model_t *state; state = &g_studio.player_models[index]; @@ -2300,7 +2367,8 @@ static model_t *R_StudioSetupPlayerModel( int index ) if( gEngfuncs.fsapi->FileExists( state->modelname, false )) state->model = gEngfuncs.Mod_ForName( state->modelname, false, true ); - else state->model = NULL; + else + state->model = NULL; if( !state->model ) state->model = RI.currententity->model; @@ -2325,18 +2393,19 @@ check for texture flags */ int R_GetEntityRenderMode( cl_entity_t *ent ) { - int i, opaque, trans; - mstudiotexture_t *ptexture; - cl_entity_t *oldent; - model_t *model; - studiohdr_t *phdr; + int i, opaque, trans; + mstudiotexture_t *ptexture; + cl_entity_t *oldent; + model_t *model; + studiohdr_t *phdr; oldent = RI.currententity; RI.currententity = ent; if( ent->player ) // check it for real playermodel model = R_StudioSetupPlayerModel( ent->curstate.number - 1 ); - else model = ent->model; + else + model = ent->model; RI.currententity = oldent; @@ -2350,14 +2419,15 @@ int R_GetEntityRenderMode( cl_entity_t *ent ) } return ent->curstate.rendermode; } - ptexture = (mstudiotexture_t *)((byte *)phdr + phdr->textureindex); + ptexture = (mstudiotexture_t *)((byte *)phdr + phdr->textureindex ); for( opaque = trans = i = 0; i < phdr->numtextures; i++, ptexture++ ) { // ignore chrome & additive it's just a specular-like effect if( FBitSet( ptexture->flags, STUDIO_NF_ADDITIVE ) && !FBitSet( ptexture->flags, STUDIO_NF_CHROME )) trans++; - else opaque++; + else + opaque++; } // if model is more additive than opaque @@ -2374,11 +2444,11 @@ R_StudioClientEvents */ static void R_StudioClientEvents( void ) { - mstudioseqdesc_t *pseqdesc; - mstudioevent_t *pevent; - cl_entity_t *e = RI.currententity; - int i, sequence; - float end, start; + mstudioseqdesc_t *pseqdesc; + mstudioevent_t *pevent; + cl_entity_t *e = RI.currententity; + int i, sequence; + float end, start; if( g_studio.frametime == 0.0 ) return; // gamepaused @@ -2394,7 +2464,7 @@ static void R_StudioClientEvents( void ) if( FBitSet( e->curstate.effects, EF_MUZZLEFLASH )) { - dlight_t *el = gEngfuncs.CL_AllocElight( 0 ); + dlight_t *el = gEngfuncs.CL_AllocElight( 0 ); ClearBits( e->curstate.effects, EF_MUZZLEFLASH ); VectorCopy( e->attachment[0], el->origin ); @@ -2407,7 +2477,7 @@ static void R_StudioClientEvents( void ) } sequence = bound( 0, e->curstate.sequence, m_pStudioHeader->numseq - 1 ); - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + sequence; + pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + sequence; // no events for this animation if( pseqdesc->numevents == 0 ) @@ -2415,7 +2485,7 @@ static void R_StudioClientEvents( void ) end = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); start = end - e->curstate.framerate * gp_host->frametime * pseqdesc->fps; - pevent = (mstudioevent_t *)((byte *)m_pStudioHeader + pseqdesc->eventindex); + pevent = (mstudioevent_t *)((byte *)m_pStudioHeader + pseqdesc->eventindex ); if( e->latched.sequencetime == e->curstate.animtime ) { @@ -2429,7 +2499,7 @@ static void R_StudioClientEvents( void ) if( pevent[i].event < EVENT_CLIENT ) continue; - if( (float)pevent[i].frame > start && pevent[i].frame <= end ) + if((float)pevent[i].frame > start && pevent[i].frame <= end ) gEngfuncs.pfnStudioEvent( &pevent[i], e ); } } @@ -2487,10 +2557,11 @@ R_StudioSetupRenderer */ static void R_StudioSetupRenderer( int rendermode ) { - studiohdr_t *phdr = m_pStudioHeader; - int i; + studiohdr_t *phdr = m_pStudioHeader; + int i; - if( rendermode > kRenderTransAdd ) rendermode = 0; + if( rendermode > kRenderTransAdd ) + rendermode = 0; g_studio.rendermode = bound( 0, rendermode, kRenderTransAdd ); // a point to setup local to world transform for boneweighted models @@ -2535,7 +2606,7 @@ Xash3D is always works in hardware mode */ static int pfnIsHardware( void ) { - return 1; // 0 is Software, 1 is OpenGL, 2 is Direct3D + return 1; // 0 is Software, 1 is OpenGL, 2 is Direct3D } /* @@ -2546,17 +2617,17 @@ R_StudioDrawPointsShadow */ static void R_StudioDrawPointsShadow( void ) { - float *av, height; - float vec_x, vec_y; - mstudiomesh_t *pmesh; - vec3_t point; - int i, k; + float *av, height; + float vec_x, vec_y; + mstudiomesh_t *pmesh; + vec3_t point; + int i, k; if( FBitSet( RI.currententity->curstate.effects, EF_NOSHADOW )) return; - //if( glState.stencilEnabled ) - //pglEnable( GL_STENCIL_TEST ); + // if( glState.stencilEnabled ) + // pglEnable( GL_STENCIL_TEST ); height = g_studio.lightspot[2] + 1.0f; vec_x = -g_studio.lightvec[0] * 8.0f; @@ -2564,10 +2635,10 @@ static void R_StudioDrawPointsShadow( void ) for( k = 0; k < m_pSubModel->nummesh; k++ ) { - short *ptricmds; + short *ptricmds; - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + k; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex ) + k; + ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex ); r_stats.c_studio_polys += pmesh->numtris; @@ -2587,8 +2658,8 @@ static void R_StudioDrawPointsShadow( void ) for( ; i > 0; i--, ptricmds += 4 ) { av = g_studio.verts[ptricmds[0]]; - point[0] = av[0] - (vec_x * ( av[2] - g_studio.lightspot[2] )); - point[1] = av[1] - (vec_y * ( av[2] - g_studio.lightspot[2] )); + point[0] = av[0] - ( vec_x * ( av[2] - g_studio.lightspot[2] )); + point[1] = av[1] - ( vec_y * ( av[2] - g_studio.lightspot[2] )); point[2] = g_studio.lightspot[2] + 1.0f; TriVertex3fv( point ); @@ -2598,8 +2669,8 @@ static void R_StudioDrawPointsShadow( void ) } } - //if( glState.stencilEnabled ) - //pglDisable( GL_STENCIL_TEST ); + // if( glState.stencilEnabled ) + // pglDisable( GL_STENCIL_TEST ); } /* @@ -2635,7 +2706,7 @@ StudioRenderFinal */ static void R_StudioRenderFinal( void ) { - int i, rendermode; + int i, rendermode; rendermode = R_StudioGetForceFaceFlags() ? kRenderTransAdd : RI.currententity->curstate.rendermode; R_StudioSetupRenderer( rendermode ); @@ -2652,7 +2723,7 @@ static void R_StudioRenderFinal( void ) { for( i = 0; i < m_pStudioHeader->numbodyparts; i++ ) { - R_StudioSetupModel( i, (void**)&m_pBodyPart, (void**)&m_pSubModel ); + R_StudioSetupModel( i, (void **)&m_pBodyPart, (void **)&m_pSubModel ); GL_StudioSetRenderMode( rendermode ); R_StudioDrawPoints(); @@ -2717,8 +2788,8 @@ StudioEstimateGait */ static void R_StudioEstimateGait( entity_state_t *pplayer ) { - vec3_t est_velocity; - float dt; + vec3_t est_velocity; + float dt; dt = bound( 0.0f, g_studio.frametime, 1.0f ); @@ -2741,26 +2812,31 @@ static void R_StudioEstimateGait( entity_state_t *pplayer ) if( est_velocity[1] == 0.0f && est_velocity[0] == 0.0f ) { - float flYawDiff = RI.currententity->angles[YAW] - m_pPlayerInfo->gaityaw; + float flYawDiff = RI.currententity->angles[YAW] - m_pPlayerInfo->gaityaw; - flYawDiff = flYawDiff - (int)(flYawDiff / 360) * 360; - if( flYawDiff > 180.0f ) flYawDiff -= 360.0f; - if( flYawDiff < -180.0f ) flYawDiff += 360.0f; + flYawDiff = flYawDiff - (int)( flYawDiff / 360 ) * 360; + if( flYawDiff > 180.0f ) + flYawDiff -= 360.0f; + if( flYawDiff < -180.0f ) + flYawDiff += 360.0f; if( dt < 0.25f ) flYawDiff *= dt * 4.0f; - else flYawDiff *= dt; + else + flYawDiff *= dt; m_pPlayerInfo->gaityaw += flYawDiff; - m_pPlayerInfo->gaityaw = m_pPlayerInfo->gaityaw - (int)(m_pPlayerInfo->gaityaw / 360) * 360; + m_pPlayerInfo->gaityaw = m_pPlayerInfo->gaityaw - (int)( m_pPlayerInfo->gaityaw / 360 ) * 360; m_flGaitMovement = 0.0f; } else { m_pPlayerInfo->gaityaw = ( atan2( est_velocity[1], est_velocity[0] ) * 180 / M_PI_F ); - if( m_pPlayerInfo->gaityaw > 180.0f ) m_pPlayerInfo->gaityaw = 180.0f; - if( m_pPlayerInfo->gaityaw < -180.0f ) m_pPlayerInfo->gaityaw = -180.0f; + if( m_pPlayerInfo->gaityaw > 180.0f ) + m_pPlayerInfo->gaityaw = 180.0f; + if( m_pPlayerInfo->gaityaw < -180.0f ) + m_pPlayerInfo->gaityaw = -180.0f; } } @@ -2773,16 +2849,16 @@ StudioProcessGait */ static void R_StudioProcessGait( entity_state_t *pplayer ) { - mstudioseqdesc_t *pseqdesc; - int iBlend; - float dt, flYaw; // view direction relative to movement + mstudioseqdesc_t *pseqdesc; + int iBlend; + float dt, flYaw; // view direction relative to movement if( RI.currententity->curstate.sequence >= m_pStudioHeader->numseq ) RI.currententity->curstate.sequence = 0; dt = bound( 0.0f, g_studio.frametime, 1.0f ); - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + RI.currententity->curstate.sequence; + pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + RI.currententity->curstate.sequence; R_StudioPlayerBlend( pseqdesc, &iBlend, &RI.currententity->angles[PITCH] ); @@ -2794,9 +2870,11 @@ static void R_StudioProcessGait( entity_state_t *pplayer ) // calc side to side turning flYaw = RI.currententity->angles[YAW] - m_pPlayerInfo->gaityaw; - flYaw = flYaw - (int)(flYaw / 360) * 360; - if( flYaw < -180.0f ) flYaw = flYaw + 360.0f; - if( flYaw > 180.0f ) flYaw = flYaw - 360.0f; + flYaw = flYaw - (int)( flYaw / 360 ) * 360; + if( flYaw < -180.0f ) + flYaw = flYaw + 360.0f; + if( flYaw > 180.0f ) + flYaw = flYaw - 360.0f; if( flYaw > 120.0f ) { @@ -2812,32 +2890,35 @@ static void R_StudioProcessGait( entity_state_t *pplayer ) } // adjust torso - RI.currententity->curstate.controller[0] = ((flYaw / 4.0f) + 30.0f) / (60.0f / 255.0f); - RI.currententity->curstate.controller[1] = ((flYaw / 4.0f) + 30.0f) / (60.0f / 255.0f); - RI.currententity->curstate.controller[2] = ((flYaw / 4.0f) + 30.0f) / (60.0f / 255.0f); - RI.currententity->curstate.controller[3] = ((flYaw / 4.0f) + 30.0f) / (60.0f / 255.0f); + RI.currententity->curstate.controller[0] = (( flYaw / 4.0f ) + 30.0f ) / ( 60.0f / 255.0f ); + RI.currententity->curstate.controller[1] = (( flYaw / 4.0f ) + 30.0f ) / ( 60.0f / 255.0f ); + RI.currententity->curstate.controller[2] = (( flYaw / 4.0f ) + 30.0f ) / ( 60.0f / 255.0f ); + RI.currententity->curstate.controller[3] = (( flYaw / 4.0f ) + 30.0f ) / ( 60.0f / 255.0f ); RI.currententity->latched.prevcontroller[0] = RI.currententity->curstate.controller[0]; RI.currententity->latched.prevcontroller[1] = RI.currententity->curstate.controller[1]; RI.currententity->latched.prevcontroller[2] = RI.currententity->curstate.controller[2]; RI.currententity->latched.prevcontroller[3] = RI.currententity->curstate.controller[3]; RI.currententity->angles[YAW] = m_pPlayerInfo->gaityaw; - if( RI.currententity->angles[YAW] < -0 ) RI.currententity->angles[YAW] += 360.0f; + if( RI.currententity->angles[YAW] < -0 ) + RI.currententity->angles[YAW] += 360.0f; RI.currententity->latched.prevangles[YAW] = RI.currententity->angles[YAW]; if( pplayer->gaitsequence >= m_pStudioHeader->numseq ) pplayer->gaitsequence = 0; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + pplayer->gaitsequence; + pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + pplayer->gaitsequence; // calc gait frame if( pseqdesc->linearmovement[0] > 0 ) - m_pPlayerInfo->gaitframe += (m_flGaitMovement / pseqdesc->linearmovement[0]) * pseqdesc->numframes; - else m_pPlayerInfo->gaitframe += pseqdesc->fps * dt; + m_pPlayerInfo->gaitframe += ( m_flGaitMovement / pseqdesc->linearmovement[0] ) * pseqdesc->numframes; + else + m_pPlayerInfo->gaitframe += pseqdesc->fps * dt; // do modulo - m_pPlayerInfo->gaitframe = m_pPlayerInfo->gaitframe - (int)(m_pPlayerInfo->gaitframe / pseqdesc->numframes) * pseqdesc->numframes; - if( m_pPlayerInfo->gaitframe < 0 ) m_pPlayerInfo->gaitframe += pseqdesc->numframes; + m_pPlayerInfo->gaitframe = m_pPlayerInfo->gaitframe - (int)( m_pPlayerInfo->gaitframe / pseqdesc->numframes ) * pseqdesc->numframes; + if( m_pPlayerInfo->gaitframe < 0 ) + m_pPlayerInfo->gaitframe += pseqdesc->numframes; } /* @@ -2848,9 +2929,9 @@ R_StudioDrawPlayer */ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) { - int m_nPlayerIndex; - alight_t lighting; - vec3_t dir; + int m_nPlayerIndex; + alight_t lighting; + vec3_t dir; m_nPlayerIndex = pplayer->number - 1; @@ -2954,10 +3035,14 @@ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) g_nTopColor = m_pPlayerInfo->topcolor; g_nBottomColor = m_pPlayerInfo->bottomcolor; - if( g_nTopColor < 0 ) g_nTopColor = 0; - if( g_nTopColor > 360 ) g_nTopColor = 360; - if( g_nBottomColor < 0 ) g_nBottomColor = 0; - if( g_nBottomColor > 360 ) g_nBottomColor = 360; + if( g_nTopColor < 0 ) + g_nTopColor = 0; + if( g_nTopColor > 360 ) + g_nTopColor = 360; + if( g_nBottomColor < 0 ) + g_nBottomColor = 0; + if( g_nBottomColor > 360 ) + g_nBottomColor = 360; R_StudioSetRemapColors( g_nTopColor, g_nBottomColor ); @@ -2966,8 +3051,8 @@ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) if( pplayer->weaponmodel ) { - cl_entity_t saveent = *RI.currententity; - model_t *pweaponmodel = CL_ModelHandle( pplayer->weaponmodel ); + cl_entity_t saveent = *RI.currententity; + model_t *pweaponmodel = CL_ModelHandle( pplayer->weaponmodel ); m_pStudioHeader = (studiohdr_t *)gEngfuncs.Mod_Extradata( mod_studio, pweaponmodel ); @@ -2991,16 +3076,16 @@ R_StudioDrawModel */ static int R_StudioDrawModel( int flags ) { - alight_t lighting; - vec3_t dir; + alight_t lighting; + vec3_t dir; if( RI.currententity->curstate.renderfx == kRenderFxDeadPlayer ) { - entity_state_t deadplayer; - int result; + entity_state_t deadplayer; + int result; - if( RI.currententity->curstate.renderamt <= 0 || - RI.currententity->curstate.renderamt > gp_cl->maxclients ) + if( RI.currententity->curstate.renderamt <= 0 + || RI.currententity->curstate.renderamt > gp_cl->maxclients ) return 0; // get copy of player @@ -3041,7 +3126,8 @@ static int R_StudioDrawModel( int flags ) if( RI.currententity->curstate.movetype == MOVETYPE_FOLLOW ) R_StudioMergeBones( RI.currententity, RI.currentmodel ); - else R_StudioSetupBones( RI.currententity ); + else + R_StudioSetupBones( RI.currententity ); R_StudioSaveBones(); @@ -3070,7 +3156,7 @@ static int R_StudioDrawModel( int flags ) // get remap colors g_nTopColor = RI.currententity->curstate.colormap & 0xFF; - g_nBottomColor = (RI.currententity->curstate.colormap & 0xFF00) >> 8; + g_nBottomColor = ( RI.currententity->curstate.colormap & 0xFF00 ) >> 8; R_StudioSetRemapColors( g_nTopColor, g_nBottomColor ); @@ -3091,14 +3177,16 @@ static void R_StudioDrawModelInternal( cl_entity_t *e, int flags ) { if( e->player ) R_StudioDrawPlayer( flags, &e->curstate ); - else R_StudioDrawModel( flags ); + else + R_StudioDrawModel( flags ); } else { // select the properly method if( e->player ) pStudioDraw->StudioDrawPlayer( flags, R_StudioGetPlayerState( e->index - 1 )); - else pStudioDraw->StudioDrawModel( flags ); + else + pStudioDraw->StudioDrawModel( flags ); } } @@ -3129,7 +3217,7 @@ void R_DrawStudioModel( cl_entity_t *e ) if( e->player ) { - R_StudioDrawModelInternal( e, STUDIO_RENDER|STUDIO_EVENTS ); + R_StudioDrawModelInternal( e, STUDIO_RENDER | STUDIO_EVENTS ); } else if( e->curstate.movetype == MOVETYPE_FOLLOW ) { @@ -3151,12 +3239,12 @@ void R_DrawStudioModel( cl_entity_t *e ) VectorCopy( RI.currententity->origin, e->origin ); RI.currententity = e; - R_StudioDrawModelInternal( e, STUDIO_RENDER|STUDIO_EVENTS ); + R_StudioDrawModelInternal( e, STUDIO_RENDER | STUDIO_EVENTS ); } } else { - R_StudioDrawModelInternal( e, STUDIO_RENDER|STUDIO_EVENTS ); + R_StudioDrawModelInternal( e, STUDIO_RENDER | STUDIO_EVENTS ); } } @@ -3168,7 +3256,7 @@ R_RunViewmodelEvents */ void R_RunViewmodelEvents( void ) { - int i; + int i; vec3_t simorg; if( r_drawviewmodel->value == 0 ) @@ -3203,11 +3291,11 @@ R_GatherPlayerLight */ void R_GatherPlayerLight( void ) { - cl_entity_t *view = tr.viewent; - colorVec c; + cl_entity_t *view = tr.viewent; + colorVec c; c = R_LightPoint( view->origin ); - gEngfuncs.SetLocalLightLevel( ( c.r + c.g + c.b ) / 3 ); + gEngfuncs.SetLocalLightLevel(( c.r + c.g + c.b ) / 3 ); } /* @@ -3217,7 +3305,7 @@ R_DrawViewModel */ void R_DrawViewModel( void ) { - cl_entity_t *view = tr.viewent; + cl_entity_t *view = tr.viewent; R_GatherPlayerLight(); @@ -3241,7 +3329,7 @@ void R_DrawViewModel( void ) return; // adjust the depth range to prevent view model from poking into walls - //pglDepthRange( gldepthmin, gldepthmin + 0.3f * ( gldepthmax - gldepthmin )); + // pglDepthRange( gldepthmin, gldepthmin + 0.3f * ( gldepthmax - gldepthmin )); s_ziscale = (float)0x8000 * (float)0x10000 * 3.0f; RI.currentmodel = RI.currententity->model; @@ -3249,13 +3337,13 @@ void R_DrawViewModel( void ) if( R_AllowFlipViewModel( RI.currententity )) { tr.fFlipViewModel = true; - //pglFrontFace( GL_CW ); + // pglFrontFace( GL_CW ); } switch( RI.currententity->model->type ) { case mod_alias: - // R_DrawAliasModel( RI.currententity ); + // R_DrawAliasModel( RI.currententity ); break; case mod_studio: R_StudioSetupTimings(); @@ -3264,14 +3352,14 @@ void R_DrawViewModel( void ) } // restore depth range - //pglDepthRange( gldepthmin, gldepthmax ); + // pglDepthRange( gldepthmin, gldepthmax ); s_ziscale = (float)0x8000 * (float)0x10000; // backface culling for left-handed weapons if( R_AllowFlipViewModel( RI.currententity )) { tr.fFlipViewModel = false; - //pglFrontFace( GL_CCW ); + // pglFrontFace( GL_CCW ); } } @@ -3284,23 +3372,23 @@ load model texture with unique name */ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture_t *ptexture ) { - size_t size; - int flags = 0; - char texname[128], name[128], mdlname[128]; - texture_t *tx = NULL; + size_t size; + int flags = 0; + char texname[128], name[128], mdlname[128]; + texture_t *tx = NULL; if( ptexture->flags & STUDIO_NF_NORMALMAP ) - flags |= (TF_NORMALMAP); + flags |= ( TF_NORMALMAP ); // store some textures for remapping if( !Q_strnicmp( ptexture->name, "DM_Base", 7 ) || !Q_strnicmp( ptexture->name, "remap", 5 )) { - int i, size; - char val[6]; - byte *pixels; + int i, size; + char val[6]; + byte *pixels; i = mod->numtextures; - mod->textures = (texture_t **)Mem_Realloc( mod->mempool, mod->textures, ( i + 1 ) * sizeof( texture_t* )); + mod->textures = (texture_t **)Mem_Realloc( mod->mempool, mod->textures, ( i + 1 ) * sizeof( texture_t * )); size = ptexture->width * ptexture->height + 768; tx = Mem_Calloc( mod->mempool, sizeof( *tx ) + size ); mod->textures[i] = tx; @@ -3310,9 +3398,9 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture { Q_strncpy( tx->name, "DM_Base", sizeof( tx->name )); tx->anim_min = PLATE_HUE_START; // topcolor start - tx->anim_max = PLATE_HUE_END; // topcolor end + tx->anim_max = PLATE_HUE_END; // topcolor end // bottomcolor start always equal is (topcolor end + 1) - tx->anim_total = SUIT_HUE_END;// bottomcolor end + tx->anim_total = SUIT_HUE_END; // bottomcolor end } else { @@ -3331,12 +3419,12 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture // the pixels immediately follow the structures pixels = (byte *)phdr + ptexture->index; - memcpy( tx+1, pixels, size ); + memcpy( tx + 1, pixels, size ); - ptexture->flags |= STUDIO_NF_COLORMAP; // yes, this is colormap image + ptexture->flags |= STUDIO_NF_COLORMAP; // yes, this is colormap image flags |= TF_FORCE_COLOR; - mod->numtextures++; // done + mod->numtextures++; // done } Q_strncpy( mdlname, mod->name, sizeof( mdlname )); @@ -3347,8 +3435,8 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture SetBits( flags, TF_NOMIPMAP ); // NOTE: replace index with pointer to start of imagebuffer, ImageLib expected it - //ptexture->index = (int)((byte *)phdr) + ptexture->index; - gEngfuncs.Image_SetMDLPointer((byte *)phdr + ptexture->index); + // ptexture->index = (int)((byte *)phdr) + ptexture->index; + gEngfuncs.Image_SetMDLPointer((byte *)phdr + ptexture->index ); size = sizeof( mstudiotexture_t ) + ptexture->width * ptexture->height + 768; if( FBitSet( gp_host->features, ENGINE_LOAD_DELUXEDATA ) && FBitSet( ptexture->flags, STUDIO_NF_MASKED )) @@ -3376,14 +3464,14 @@ Mod_StudioLoadTextures */ void GAME_EXPORT Mod_StudioLoadTextures( model_t *mod, void *data ) { - studiohdr_t *phdr = (studiohdr_t *)data; - mstudiotexture_t *ptexture; - int i; + studiohdr_t *phdr = (studiohdr_t *)data; + mstudiotexture_t *ptexture; + int i; if( !phdr ) return; - ptexture = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); + ptexture = (mstudiotexture_t *)(((byte *)phdr ) + phdr->textureindex ); if( phdr->textureindex > 0 && phdr->numtextures <= MAXSTUDIOSKINS ) { for( i = 0; i < phdr->numtextures; i++ ) @@ -3398,14 +3486,14 @@ Mod_StudioUnloadTextures */ void Mod_StudioUnloadTextures( void *data ) { - studiohdr_t *phdr = (studiohdr_t *)data; - mstudiotexture_t *ptexture; - int i; + studiohdr_t *phdr = (studiohdr_t *)data; + mstudiotexture_t *ptexture; + int i; if( !phdr ) return; - ptexture = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); + ptexture = (mstudiotexture_t *)(((byte *)phdr ) + phdr->textureindex ); // release all textures for( i = 0; i < phdr->numtextures; i++ ) @@ -3438,7 +3526,7 @@ static void pfnMod_LoadCacheFile( const char *path, struct cache_user_s *cu ) static cvar_t *pfnGetCvarPointer( const char *name ) { - return (cvar_t*)gEngfuncs.pfnGetCvarPointer( name, 0 ); + return (cvar_t *)gEngfuncs.pfnGetCvarPointer( name, 0 ); } static void *pfnMod_Calloc( int number, size_t size ) @@ -3446,7 +3534,7 @@ static void *pfnMod_Calloc( int number, size_t size ) return gEngfuncs.Mod_Calloc( number, size ); } -static engine_studio_api_t gStudioAPI = +static engine_studio_api_t gStudioAPI = { pfnMod_Calloc, pfnMod_CacheCheck, @@ -3477,13 +3565,13 @@ static engine_studio_api_t gStudioAPI = R_StudioDrawHulls, R_StudioDrawAbsBBox, R_StudioDrawBones, - (void*)R_StudioSetupSkin, + (void *)R_StudioSetupSkin, R_StudioSetRemapColors, R_StudioSetupPlayerModel, R_StudioClientEvents, R_StudioGetForceFaceFlags, R_StudioSetForceFaceFlags, - (void*)R_StudioSetHeader, + (void *)R_StudioSetHeader, R_StudioSetRenderModel, R_StudioSetupRenderer, R_StudioRestoreRenderer, diff --git a/ref/soft/r_surf.c b/ref/soft/r_surf.c index 44f8b9bf..3a08f1b4 100644 --- a/ref/soft/r_surf.c +++ b/ref/soft/r_surf.c @@ -22,47 +22,47 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" #include "mod_local.h" -drawsurf_t r_drawsurf; +drawsurf_t r_drawsurf; -uint lightleft, sourcesstep, blocksize, sourcetstep; -uint lightdelta, lightdeltastep; -uint lightright, lightleftstep, lightrightstep, blockdivshift; -unsigned blockdivmask; -void *prowdestbase; -pixel_t *pbasesource; -int surfrowbytes; // used by ASM files -unsigned *r_lightptr; -int r_stepback; -int r_lightwidth; -int r_numhblocks, r_numvblocks; -pixel_t *r_source, *r_sourcemax; +uint lightleft, sourcesstep, blocksize, sourcetstep; +uint lightdelta, lightdeltastep; +uint lightright, lightleftstep, lightrightstep, blockdivshift; +unsigned blockdivmask; +void *prowdestbase; +pixel_t *pbasesource; +int surfrowbytes; // used by ASM files +unsigned *r_lightptr; +int r_stepback; +int r_lightwidth; +int r_numhblocks, r_numvblocks; +pixel_t *r_source, *r_sourcemax; -void R_DrawSurfaceBlock8_mip0 (void); -void R_DrawSurfaceBlock8_mip1 (void); -void R_DrawSurfaceBlock8_mip2 (void); -void R_DrawSurfaceBlock8_mip3 (void); -void R_DrawSurfaceBlock8_Generic (void); -void R_DrawSurfaceBlock8_World (void); +void R_DrawSurfaceBlock8_mip0( void ); +void R_DrawSurfaceBlock8_mip1( void ); +void R_DrawSurfaceBlock8_mip2( void ); +void R_DrawSurfaceBlock8_mip3( void ); +void R_DrawSurfaceBlock8_Generic( void ); +void R_DrawSurfaceBlock8_World( void ); -static float worldlux_s, worldlux_t; +static float worldlux_s, worldlux_t; -static void (*surfmiptable[4])(void) = { +static void (*surfmiptable[4])( void ) = { R_DrawSurfaceBlock8_mip0, R_DrawSurfaceBlock8_mip1, R_DrawSurfaceBlock8_mip2, R_DrawSurfaceBlock8_mip3 }; -//void R_BuildLightMap (void); -extern unsigned blocklights[10240]; // allow some very large lightmaps +// void R_BuildLightMap (void); +extern unsigned blocklights[10240]; // allow some very large lightmaps float surfscale; qboolean r_cache_thrash; // set if surface cache is thrashing -int sc_size; -surfcache_t *sc_rover, *sc_base; +int sc_size; +surfcache_t *sc_rover, *sc_base; -static int rtable[MOD_FRAMES][MOD_FRAMES]; +static int rtable[MOD_FRAMES][MOD_FRAMES]; static void R_BuildLightMap( void ); /* @@ -73,9 +73,9 @@ R_AddDynamicLights static void R_AddDynamicLights( const msurface_t *surf ) { const mextrasurf_t *info = surf->info; - int lnum, smax, tmax; - int sample_frac = 1.0; - float sample_size; + int lnum, smax, tmax; + int sample_frac = 1.0; + float sample_size; mtexinfo_t *tex; // no dlighted surfaces here @@ -83,8 +83,8 @@ static void R_AddDynamicLights( const msurface_t *surf ) return; sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - smax = (info->lightextents[0] / sample_size) + 1; - tmax = (info->lightextents[1] / sample_size) + 1; + smax = ( info->lightextents[0] / sample_size ) + 1; + tmax = ( info->lightextents[1] / sample_size ) + 1; tex = surf->texinfo; if( FBitSet( tex->flags, TEX_WORLD_LUXELS )) @@ -93,26 +93,28 @@ static void R_AddDynamicLights( const msurface_t *surf ) sample_frac = surf->texinfo->faceinfo->texture_step; else if( FBitSet( surf->texinfo->flags, TEX_EXTRA_LIGHTMAP )) sample_frac = LM_SAMPLE_EXTRASIZE; - else sample_frac = LM_SAMPLE_SIZE; + else + sample_frac = LM_SAMPLE_SIZE; } for( lnum = 0; lnum < MAX_DLIGHTS; lnum++ ) { dlight_t *dl; - vec3_t impact, origin_l; - float dist, rad, minlight; - float sl, tl; - int t, monolight; + vec3_t impact, origin_l; + float dist, rad, minlight; + float sl, tl; + int t, monolight; if( !FBitSet( surf->dlightbits, BIT( lnum ))) - continue; // not lit by this light + continue; // not lit by this light dl = &tr.dlights[lnum]; // transform light origin to local bmodel space if( !tr.modelviewIdentity ) Matrix4x4_VectorITransform( RI.objectMatrix, dl->origin, origin_l ); - else VectorCopy( dl->origin, origin_l ); + else + VectorCopy( dl->origin, origin_l ); rad = dl->radius; dist = PlaneDiff( origin_l, surf->plane ); @@ -130,7 +132,8 @@ static void R_AddDynamicLights( const msurface_t *surf ) VectorCopy( origin_l, impact ); impact[surf->plane->type] -= dist; } - else VectorMA( origin_l, -dist, surf->plane->normal, impact ); + else + VectorMA( origin_l, -dist, surf->plane->normal, impact ); sl = DotProduct( impact, info->lmvecs[0] ) + info->lmvecs[0][3] - info->lightmapmins[0]; tl = DotProduct( impact, info->lmvecs[1] ) + info->lmvecs[1][3] - info->lightmapmins[1]; @@ -139,7 +142,7 @@ static void R_AddDynamicLights( const msurface_t *surf ) for( t = 0; t < tmax; t++ ) { - int td = (tl - sample_size * t) * sample_frac; + int td = ( tl - sample_size * t ) * sample_frac; int s; if( td < 0 ) @@ -147,20 +150,20 @@ static void R_AddDynamicLights( const msurface_t *surf ) for( s = 0; s < smax; s++ ) { - int sd = (sl - sample_size * s) * sample_frac; + int sd = ( sl - sample_size * s ) * sample_frac; float dist; if( sd < 0 ) sd = -sd; if( sd > td ) - dist = sd + (td >> 1); + dist = sd + ( td >> 1 ); else - dist = td + (sd >> 1); + dist = td + ( sd >> 1 ); if( dist < minlight ) { - blocklights[(s + (t * smax))] += ((int)((rad - dist) * 256) * monolight ) / 256; + blocklights[( s + ( t * smax ))] += ((int)(( rad - dist ) * 256 ) * monolight ) / 256; } } } @@ -178,13 +181,13 @@ format in r_blocklights */ static void R_BuildLightMap( void ) { - int map, t, i; - const msurface_t *surf = r_drawsurf.surf; + int map, t, i; + const msurface_t *surf = r_drawsurf.surf; const mextrasurf_t *info = surf->info; - const int sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - int smax = ( info->lightextents[0] / sample_size ) + 1; - int tmax = ( info->lightextents[1] / sample_size ) + 1; - int size = smax * tmax; + const int sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); + int smax = ( info->lightextents[0] / sample_size ) + 1; + int tmax = ( info->lightextents[1] / sample_size ) + 1; + int size = smax * tmax; if( FBitSet( surf->flags, SURF_CONVEYOR )) { @@ -200,8 +203,8 @@ static void R_BuildLightMap( void ) for( map = 0; map < MAXLIGHTMAPS && surf->samples; map++ ) { const color24 *lm = &surf->samples[map * size]; - uint scale; - int i; + uint scale; + int i; if( surf->styles[map] >= 255 ) break; @@ -221,13 +224,14 @@ static void R_BuildLightMap( void ) { if( blocklights[i] < 65280 ) t = LightToTexGamma( blocklights[i] >> 6 ) << 6; - else t = (int)blocklights[i]; + else + t = (int)blocklights[i]; t = bound( 0, t, 65535 * 3 ); - t = t / 2048 / 3;//(255*256 - t) >> (8 - VID_CBITS); + t = t / 2048 / 3; // (255*256 - t) >> (8 - VID_CBITS); - //if (t < (1 << 6)) - //t = (1 << 6); + // if (t < (1 << 6)) + // t = (1 << 6); t = t << 8; blocklights[i] = t; @@ -236,7 +240,7 @@ static void R_BuildLightMap( void ) void GL_InitRandomTable( void ) { - int tu, tv; + int tu, tv; for( tu = 0; tu < MOD_FRAMES; tu++ ) { @@ -259,7 +263,7 @@ Returns the proper texture for a given time and base texture, do not process ran static texture_t *R_TextureAnim( texture_t *b ) { texture_t *base = b; - int count, reletive; + int count, reletive; if( RI.currententity->curstate.frame ) { @@ -275,14 +279,15 @@ static texture_t *R_TextureAnim( texture_t *b ) } else { - int speed; + int speed; // Quake1 textures uses 10 frames per second if( FBitSet( R_GetTexture( base->gl_texturenum )->flags, TF_QUAKEPAL )) speed = 10; - else speed = 20; + else + speed = 20; - reletive = (int)(gp_cl->time * speed) % base->anim_total; + reletive = (int)( gp_cl->time * speed ) % base->anim_total; } @@ -308,8 +313,8 @@ Returns the proper texture for a given time and surface */ static texture_t *R_TextureAnimation( msurface_t *s ) { - texture_t *base = s->texinfo->texture; - int count, reletive; + texture_t *base = s->texinfo->texture; + int count, reletive; if( RI.currententity && RI.currententity->curstate.frame ) { @@ -322,21 +327,22 @@ static texture_t *R_TextureAnimation( msurface_t *s ) if( base->name[0] == '-' ) { - int tx = (int)((s->texturemins[0] + (base->width << 16)) / base->width) % MOD_FRAMES; - int ty = (int)((s->texturemins[1] + (base->height << 16)) / base->height) % MOD_FRAMES; + int tx = (int)(( s->texturemins[0] + ( base->width << 16 )) / base->width ) % MOD_FRAMES; + int ty = (int)(( s->texturemins[1] + ( base->height << 16 )) / base->height ) % MOD_FRAMES; reletive = rtable[tx][ty] % base->anim_total; } else { - int speed; + int speed; // Quake1 textures uses 10 frames per second if( FBitSet( R_GetTexture( base->gl_texturenum )->flags, TF_QUAKEPAL )) speed = 10; - else speed = 20; + else + speed = 20; - reletive = (int)(gp_cl->time * speed) % base->anim_total; + reletive = (int)( gp_cl->time * speed ) % base->anim_total; } count = 0; @@ -357,21 +363,21 @@ static texture_t *R_TextureAnimation( msurface_t *s ) R_DrawSurface =============== */ -void R_DrawSurface (void) +void R_DrawSurface( void ) { - pixel_t *basetptr; - int smax, tmax, twidth; - int u; - int soffset, basetoffset, texwidth; - int horzblockstep; - pixel_t *pcolumndest; - void (*pblockdrawer)(void); - image_t *mt; - uint sample_size, sample_bits, sample_pot; + pixel_t *basetptr; + int smax, tmax, twidth; + int u; + int soffset, basetoffset, texwidth; + int horzblockstep; + pixel_t *pcolumndest; + void (*pblockdrawer)( void ); + image_t *mt; + uint sample_size, sample_bits, sample_pot; surfrowbytes = r_drawsurf.rowbytes; - sample_size = LM_SAMPLE_SIZE_AUTO(r_drawsurf.surf); + sample_size = LM_SAMPLE_SIZE_AUTO( r_drawsurf.surf ); if( sample_size == 16 ) sample_bits = 4, sample_pot = sample_size; else @@ -381,7 +387,8 @@ void R_DrawSurface (void) if( sample_bits == -1 ) { sample_bits = 0; - for( sample_pot = 1; sample_pot < sample_size; sample_pot <<= 1, sample_bits++ ); + for( sample_pot = 1; sample_pot < sample_size; sample_pot <<= 1, sample_bits++ ) + ; } else sample_pot = 1 << sample_bits; @@ -397,10 +404,10 @@ void R_DrawSurface (void) blocksize = sample_pot >> r_drawsurf.surfmip; blockdivshift = sample_bits - r_drawsurf.surfmip; - blockdivmask = (1 << blockdivshift) - 1; + blockdivmask = ( 1 << blockdivshift ) - 1; if( sample_size == 16 ) - r_lightwidth = ( r_drawsurf.surf->info->lightextents[0]>>4)+1; + r_lightwidth = ( r_drawsurf.surf->info->lightextents[0] >> 4 ) + 1; else r_lightwidth = ( r_drawsurf.surf->info->lightextents[0] / sample_size ) + 1; @@ -408,7 +415,7 @@ void R_DrawSurface (void) r_numvblocks = r_drawsurf.surfheight >> blockdivshift; -//============================== +// ============================== if( sample_size == 16 ) pblockdrawer = surfmiptable[r_drawsurf.surfmip]; @@ -424,7 +431,7 @@ void R_DrawSurface (void) sourcetstep = texwidth; r_stepback = tmax * twidth; - r_sourcemax = r_source + (tmax * smax); + r_sourcemax = r_source + ( tmax * smax ); // glitchy and slow way to draw some lightmap if( r_drawsurf.surf->texinfo->flags & TEX_WORLD_LUXELS ) @@ -438,18 +445,18 @@ void R_DrawSurface (void) soffset = r_drawsurf.surf->texturemins[0]; basetoffset = r_drawsurf.surf->texturemins[1]; - //soffset = r_drawsurf.surf->info->lightmapmins[0] * worldlux_s; - //basetoffset = r_drawsurf.surf->info->lightmapmins[1] * worldlux_t; + // soffset = r_drawsurf.surf->info->lightmapmins[0] * worldlux_s; + // basetoffset = r_drawsurf.surf->info->lightmapmins[1] * worldlux_t; // << 16 components are to guarantee positive values for % - soffset = ((soffset >> r_drawsurf.surfmip) + (smax << 16)) % smax; - basetptr = &r_source[((((basetoffset >> r_drawsurf.surfmip) - + (tmax << 16)) % tmax) * twidth)]; + soffset = (( soffset >> r_drawsurf.surfmip ) + ( smax << 16 )) % smax; + basetptr = &r_source[(((( basetoffset >> r_drawsurf.surfmip ) + + ( tmax << 16 )) % tmax ) * twidth )]; pcolumndest = r_drawsurf.surfdat; - for (u=0 ; u= smax) + if( soffset >= smax ) soffset = 0; pcolumndest += horzblockstep; @@ -466,17 +473,17 @@ void R_DrawSurface (void) return; } - soffset = r_drawsurf.surf->info->lightmapmins[0]; + soffset = r_drawsurf.surf->info->lightmapmins[0]; basetoffset = r_drawsurf.surf->info->lightmapmins[1]; // << 16 components are to guarantee positive values for % - soffset = ((soffset >> r_drawsurf.surfmip) + (smax << 16)) % smax; - basetptr = &r_source[((((basetoffset >> r_drawsurf.surfmip) - + (tmax << 16)) % tmax) * twidth)]; + soffset = (( soffset >> r_drawsurf.surfmip ) + ( smax << 16 )) % smax; + basetptr = &r_source[(((( basetoffset >> r_drawsurf.surfmip ) + + ( tmax << 16 )) % tmax ) * twidth )]; pcolumndest = r_drawsurf.surfdat; - for (u=0 ; u= smax) + if( soffset >= smax ) soffset = 0; pcolumndest += horzblockstep; } - // test what if we have very slow cache building - //usleep(10000); + // test what if we have very slow cache building + // usleep(10000); } -//============================================================================= +// ============================================================================= -#define BLEND_LM(pix, light) vid.colormap[(pix >> 3) | ((light & 0x1f00) << 5)] | ( pix & 7 ); +#define BLEND_LM( pix, light ) vid.colormap[( pix >> 3 ) | (( light & 0x1f00 ) << 5 )] | ( pix & 7 ); /* ================ @@ -508,42 +515,42 @@ R_DrawSurfaceBlock8_World Does not draw lightmap correclty, but scale it correctly. Better than nothing ================ */ -void R_DrawSurfaceBlock8_World (void) +void R_DrawSurfaceBlock8_World( void ) { - int v, i, b; - uint lightstep, lighttemp, light; - pixel_t pix, *psource, *prowdest; - int lightpos = 0; + int v, i, b; + uint lightstep, lighttemp, light; + pixel_t pix, *psource, *prowdest; + int lightpos = 0; psource = pbasesource; prowdest = prowdestbase; - for (v=0 ; v> (4-r_drawsurf.surfmip); - lightrightstep =(r_lightptr[(lightpos/r_lightwidth) * r_lightwidth+1] - lightright) >> (4-r_drawsurf.surfmip); + lightleftstep = ( r_lightptr[( lightpos / r_lightwidth ) * r_lightwidth] - lightleft ) >> ( 4 - r_drawsurf.surfmip ); + lightrightstep = ( r_lightptr[( lightpos / r_lightwidth ) * r_lightwidth + 1] - lightright ) >> ( 4 - r_drawsurf.surfmip ); - for (i=0 ; i> (4-r_drawsurf.surfmip); + lightstep = lighttemp >> ( 4 - r_drawsurf.surfmip ); light = lightright; - for (b=blocksize-1; b>=0; b--) + for( b = blocksize - 1; b >= 0; b-- ) { - //pix = psource[(uint)(b * worldlux_s)]; + // pix = psource[(uint)(b * worldlux_s)]; pix = psource[b]; - prowdest[b] = BLEND_LM(pix, light); + prowdest[b] = BLEND_LM( pix, light ); if( pix == TRANSPARENT_COLOR ) prowdest[b] = TRANSPARENT_COLOR; - //((unsigned char *)vid.colormap) - //[(light & 0xFF00) + pix]; + // ((unsigned char *)vid.colormap) + // [(light & 0xFF00) + pix]; light += lightstep; } @@ -553,7 +560,7 @@ void R_DrawSurfaceBlock8_World (void) prowdest += surfrowbytes; } - if (psource >= r_sourcemax) + if( psource >= r_sourcemax ) psource -= r_stepback; } } @@ -564,40 +571,40 @@ void R_DrawSurfaceBlock8_World (void) R_DrawSurfaceBlock8_Generic ================ */ -void R_DrawSurfaceBlock8_Generic (void) +void R_DrawSurfaceBlock8_Generic( void ) { - int v, i, b; - uint lightstep, lighttemp, light; - pixel_t pix, *psource, *prowdest; + int v, i, b; + uint lightstep, lighttemp, light; + pixel_t pix, *psource, *prowdest; psource = pbasesource; prowdest = prowdestbase; - for (v=0 ; v> (4-r_drawsurf.surfmip); - lightrightstep = (r_lightptr[1] - lightright) >> (4-r_drawsurf.surfmip); + lightleftstep = ( r_lightptr[0] - lightleft ) >> ( 4 - r_drawsurf.surfmip ); + lightrightstep = ( r_lightptr[1] - lightright ) >> ( 4 - r_drawsurf.surfmip ); - for (i=0 ; i> (4-r_drawsurf.surfmip); + lightstep = lighttemp >> ( 4 - r_drawsurf.surfmip ); light = lightright; - for (b=blocksize-1; b>=0; b--) + for( b = blocksize - 1; b >= 0; b-- ) { pix = psource[b]; - prowdest[b] = BLEND_LM(pix, light); + prowdest[b] = BLEND_LM( pix, light ); if( pix == TRANSPARENT_COLOR ) prowdest[b] = TRANSPARENT_COLOR; - //((unsigned char *)vid.colormap) - //[(light & 0xFF00) + pix]; + // ((unsigned char *)vid.colormap) + // [(light & 0xFF00) + pix]; light += lightstep; } @@ -607,7 +614,7 @@ void R_DrawSurfaceBlock8_Generic (void) prowdest += surfrowbytes; } - if (psource >= r_sourcemax) + if( psource >= r_sourcemax ) psource -= r_stepback; } } @@ -618,42 +625,42 @@ void R_DrawSurfaceBlock8_Generic (void) R_DrawSurfaceBlock8_mip0 ================ */ -void R_DrawSurfaceBlock8_mip0 (void) +void R_DrawSurfaceBlock8_mip0( void ) { - int v, i, b; - uint lightstep, lighttemp, light; - pixel_t pix, *psource, *prowdest; + int v, i, b; + uint lightstep, lighttemp, light; + pixel_t pix, *psource, *prowdest; psource = pbasesource; prowdest = prowdestbase; - for (v=0 ; v> 4; - lightrightstep = (r_lightptr[1] - lightright) >> 4; + lightleftstep = ( r_lightptr[0] - lightleft ) >> 4; + lightrightstep = ( r_lightptr[1] - lightright ) >> 4; - for (i=0 ; i<16 ; i++) + for( i = 0; i < 16; i++ ) { lighttemp = lightleft - lightright; lightstep = lighttemp >> 4; light = lightright; - for (b=15; b>=0; b--) + for( b = 15; b >= 0; b-- ) { pix = psource[b]; - prowdest[b] = BLEND_LM(pix, light); + prowdest[b] = BLEND_LM( pix, light ); if( pix == TRANSPARENT_COLOR ) prowdest[b] = TRANSPARENT_COLOR; - // pix; - //((unsigned char *)vid.colormap) - //[(light & 0xFF00) + pix]; + // pix; + // ((unsigned char *)vid.colormap) + // [(light & 0xFF00) + pix]; light += lightstep; } @@ -663,7 +670,7 @@ void R_DrawSurfaceBlock8_mip0 (void) prowdest += surfrowbytes; } - if (psource >= r_sourcemax) + if( psource >= r_sourcemax ) psource -= r_stepback; } } @@ -674,38 +681,38 @@ void R_DrawSurfaceBlock8_mip0 (void) R_DrawSurfaceBlock8_mip1 ================ */ -void R_DrawSurfaceBlock8_mip1 (void) +void R_DrawSurfaceBlock8_mip1( void ) { - int v, i, b; - uint lightstep, lighttemp, light; - pixel_t pix, *psource, *prowdest; + int v, i, b; + uint lightstep, lighttemp, light; + pixel_t pix, *psource, *prowdest; psource = pbasesource; prowdest = prowdestbase; - for (v=0 ; v> 3; - lightrightstep = (r_lightptr[1] - lightright) >> 3; + lightleftstep = ( r_lightptr[0] - lightleft ) >> 3; + lightrightstep = ( r_lightptr[1] - lightright ) >> 3; - for (i=0 ; i<8 ; i++) + for( i = 0; i < 8; i++ ) { lighttemp = lightleft - lightright; lightstep = lighttemp >> 3; light = lightright; - for (b=7; b>=0; b--) + for( b = 7; b >= 0; b-- ) { pix = psource[b]; - prowdest[b] = BLEND_LM(pix, light); - //((unsigned char *)vid.colormap) - //[(light & 0xFF00) + pix]; + prowdest[b] = BLEND_LM( pix, light ); + // ((unsigned char *)vid.colormap) + // [(light & 0xFF00) + pix]; light += lightstep; } @@ -715,7 +722,7 @@ void R_DrawSurfaceBlock8_mip1 (void) prowdest += surfrowbytes; } - if (psource >= r_sourcemax) + if( psource >= r_sourcemax ) psource -= r_stepback; } } @@ -726,38 +733,38 @@ void R_DrawSurfaceBlock8_mip1 (void) R_DrawSurfaceBlock8_mip2 ================ */ -void R_DrawSurfaceBlock8_mip2 (void) +void R_DrawSurfaceBlock8_mip2( void ) { - int v, i, b; - uint lightstep, lighttemp, light; - pixel_t pix, *psource, *prowdest; + int v, i, b; + uint lightstep, lighttemp, light; + pixel_t pix, *psource, *prowdest; psource = pbasesource; prowdest = prowdestbase; - for (v=0 ; v> 2; - lightrightstep = (r_lightptr[1] - lightright) >> 2; + lightleftstep = ( r_lightptr[0] - lightleft ) >> 2; + lightrightstep = ( r_lightptr[1] - lightright ) >> 2; - for (i=0 ; i<4 ; i++) + for( i = 0; i < 4; i++ ) { lighttemp = lightleft - lightright; lightstep = lighttemp >> 2; light = lightright; - for (b=3; b>=0; b--) + for( b = 3; b >= 0; b-- ) { pix = psource[b]; - prowdest[b] = BLEND_LM(pix, light);; - //((unsigned char *)vid.colormap) - //[(light & 0xFF00) + pix]; + prowdest[b] = BLEND_LM( pix, light );; + // ((unsigned char *)vid.colormap) + // [(light & 0xFF00) + pix]; light += lightstep; } @@ -767,7 +774,7 @@ void R_DrawSurfaceBlock8_mip2 (void) prowdest += surfrowbytes; } - if (psource >= r_sourcemax) + if( psource >= r_sourcemax ) psource -= r_stepback; } } @@ -778,38 +785,38 @@ void R_DrawSurfaceBlock8_mip2 (void) R_DrawSurfaceBlock8_mip3 ================ */ -void R_DrawSurfaceBlock8_mip3 (void) +void R_DrawSurfaceBlock8_mip3( void ) { - int v, i, b; - uint lightstep, lighttemp, light; - pixel_t pix, *psource, *prowdest; + int v, i, b; + uint lightstep, lighttemp, light; + pixel_t pix, *psource, *prowdest; psource = pbasesource; prowdest = prowdestbase; - for (v=0 ; v> 1; - lightrightstep = (r_lightptr[1] - lightright) >> 1; + lightleftstep = ( r_lightptr[0] - lightleft ) >> 1; + lightrightstep = ( r_lightptr[1] - lightright ) >> 1; - for (i=0 ; i<2 ; i++) + for( i = 0; i < 2; i++ ) { lighttemp = lightleft - lightright; lightstep = lighttemp >> 1; light = lightright; - for (b=1; b>=0; b--) + for( b = 1; b >= 0; b-- ) { pix = psource[b]; - prowdest[b] = BLEND_LM(pix, light);; - //((unsigned char *)vid.colormap) - //[(light & 0xFF00) + pix]; + prowdest[b] = BLEND_LM( pix, light );; + // ((unsigned char *)vid.colormap) + // [(light & 0xFF00) + pix]; light += lightstep; } @@ -819,25 +826,25 @@ void R_DrawSurfaceBlock8_mip3 (void) prowdest += surfrowbytes; } - if (psource >= r_sourcemax) + if( psource >= r_sourcemax ) psource -= r_stepback; } } -//============================================================================ +// ============================================================================ /* ================ R_InitCaches ================ */ -void R_InitCaches (void) +void R_InitCaches( void ) { - int size; - int pix; + int size; + int pix; // calculate size to allocate - if (sw_surfcacheoverride.value) + if( sw_surfcacheoverride.value ) { size = sw_surfcacheoverride.value; } @@ -846,14 +853,14 @@ void R_InitCaches (void) size = SURFCACHE_SIZE_AT_320X240 * 2; pix = vid.width * vid.height * 2; - if (pix > 64000) - size += (pix-64000)*3; + if( pix > 64000 ) + size += ( pix - 64000 ) * 3; } // round up to page size - size = (size + 8191) & ~8191; + size = ( size + 8191 ) & ~8191; - gEngfuncs.Con_Printf ("%s surface cache\n", Q_memprint(size)); + gEngfuncs.Con_Printf( "%s surface cache\n", Q_memprint( size )); sc_size = size; if( sc_base ) @@ -861,7 +868,7 @@ void R_InitCaches (void) D_FlushCaches( ); Mem_Free( sc_base ); } - sc_base = (surfcache_t *)Mem_Calloc(r_temppool,size); + sc_base = (surfcache_t *)Mem_Calloc( r_temppool, size ); sc_rover = sc_base; sc_base->next = NULL; @@ -877,14 +884,14 @@ D_FlushCaches */ void D_FlushCaches( void ) { - surfcache_t *c; + surfcache_t *c; // if newmap, surfaces already freed if( !tr.map_unload ) { - for(c = sc_base ; c ; c = c->next ) + for( c = sc_base; c; c = c->next ) { - if ( c->owner ) + if( c->owner ) *c->owner = NULL; } } @@ -900,28 +907,28 @@ void D_FlushCaches( void ) D_SCAlloc ================= */ -static surfcache_t *D_SCAlloc (int width, int size) +static surfcache_t *D_SCAlloc( int width, int size ) { - surfcache_t *new; - qboolean wrapped_this_time; + surfcache_t *new; + qboolean wrapped_this_time; - if ((width < 0) )// || (width > 256)) - gEngfuncs.Host_Error ("%s: bad cache width %d\n", __func__, width); + if(( width < 0 ))// || (width > 256)) + gEngfuncs.Host_Error( "%s: bad cache width %d\n", __func__, width ); - if ((size <= 0) || (size > 0x10000000)) - gEngfuncs.Host_Error ("%s: bad cache size %d\n", __func__, size); + if(( size <= 0 ) || ( size > 0x10000000 )) + gEngfuncs.Host_Error( "%s: bad cache size %d\n", __func__, size ); - size = (int)&((surfcache_t *)0)->data[size]; - size = (size + 3) & ~3; - if (size > sc_size) - gEngfuncs.Host_Error ("%s: %i > cache size of %i", __func__, size, sc_size); + size = (int)&((surfcache_t *)0 )->data[size]; + size = ( size + 3 ) & ~3; + if( size > sc_size ) + gEngfuncs.Host_Error( "%s: %i > cache size of %i", __func__, size, sc_size ); // if there is not size bytes after the rover, reset to the start wrapped_this_time = false; - if ( !sc_rover || (byte *)sc_rover - (byte *)sc_base > sc_size - size) + if( !sc_rover || (byte *)sc_rover - (byte *)sc_base > sc_size - size ) { - if (sc_rover) + if( sc_rover ) { wrapped_this_time = true; } @@ -930,16 +937,16 @@ static surfcache_t *D_SCAlloc (int width, int size) // colect and free surfcache_t blocks until the rover block is large enough new = sc_rover; - if (sc_rover->owner) + if( sc_rover->owner ) *sc_rover->owner = NULL; - while (new->size < size) + while( new->size < size ) { - // free another + // free another sc_rover = sc_rover->next; - if (!sc_rover) - gEngfuncs.Host_Error ("%s: hit the end of memory", __func__); - if (sc_rover->owner) + if( !sc_rover ) + gEngfuncs.Host_Error( "%s: hit the end of memory", __func__ ); + if( sc_rover->owner ) *sc_rover->owner = NULL; new->size += sc_rover->size; @@ -947,9 +954,9 @@ static surfcache_t *D_SCAlloc (int width, int size) } // create a fragment out of any leftovers - if (new->size - size > 256) + if( new->size - size > 256 ) { - sc_rover = (surfcache_t *)( (byte *)new + size); + sc_rover = (surfcache_t *)((byte *)new + size ); sc_rover->size = new->size - size; sc_rover->next = new->next; sc_rover->width = 0; @@ -962,17 +969,17 @@ static surfcache_t *D_SCAlloc (int width, int size) new->width = width; // DEBUG - if (width > 0) - new->height = (size - sizeof(*new) + sizeof(new->data)) / width; + if( width > 0 ) + new->height = ( size - sizeof( *new ) + sizeof( new->data )) / width; - new->owner = NULL; // should be set properly after return + new->owner = NULL; // should be set properly after return - if (d_roverwrapped) + if( d_roverwrapped ) { - if (wrapped_this_time || (sc_rover >= d_initial_rover)) + if( wrapped_this_time || ( sc_rover >= d_initial_rover )) r_cache_thrash = true; } - else if (wrapped_this_time) + else if( wrapped_this_time ) { d_roverwrapped = true; } @@ -980,139 +987,139 @@ static surfcache_t *D_SCAlloc (int width, int size) return new; } -//============================================================================= +// ============================================================================= static void R_DrawSurfaceDecals( void ) { msurface_t *fa = r_drawsurf.surf; - decal_t *p; + decal_t *p; - for( p = fa->pdecals; p; p = p->pnext) + for( p = fa->pdecals; p; p = p->pnext ) { - pixel_t *dest, *source; - vec4_t textureU, textureV; - image_t *tex = R_GetTexture( p->texture ); - int s1 = 0,t1 = 0, s2 = tex->width, t2 = tex->height; - unsigned int height; - unsigned int f, fstep; - int skip; - pixel_t *buffer; - qboolean transparent; - int x, y, u,v, sv, w, h; - vec3_t basis[3]; + pixel_t *dest, *source; + vec4_t textureU, textureV; + image_t *tex = R_GetTexture( p->texture ); + int s1 = 0, t1 = 0, s2 = tex->width, t2 = tex->height; + unsigned int height; + unsigned int f, fstep; + int skip; + pixel_t *buffer; + qboolean transparent; + int x, y, u, v, sv, w, h; + vec3_t basis[3]; - Vector4Copy( fa->texinfo->vecs[0], textureU ); - Vector4Copy( fa->texinfo->vecs[1], textureV ); + Vector4Copy( fa->texinfo->vecs[0], textureU ); + Vector4Copy( fa->texinfo->vecs[1], textureV ); - R_DecalComputeBasis( fa, 0, basis ); + R_DecalComputeBasis( fa, 0, basis ); - w = fabs( tex->width * DotProduct( textureU, basis[0] )) + - fabs( tex->height * DotProduct( textureU, basis[1] )); - h = fabs( tex->width * DotProduct( textureV, basis[0] )) + - fabs( tex->height * DotProduct( textureV, basis[1] )); + w = fabs( tex->width * DotProduct( textureU, basis[0] )) + + fabs( tex->height * DotProduct( textureU, basis[1] )); + h = fabs( tex->width * DotProduct( textureV, basis[0] )) + + fabs( tex->height * DotProduct( textureV, basis[1] )); - // project decal center into the texture space of the surface - x = DotProduct( p->position, textureU ) + textureU[3] - fa->texturemins[0] - w/2; - y = DotProduct( p->position, textureV ) + textureV[3] - fa->texturemins[1] - h/2; + // project decal center into the texture space of the surface + x = DotProduct( p->position, textureU ) + textureU[3] - fa->texturemins[0] - w / 2; + y = DotProduct( p->position, textureV ) + textureV[3] - fa->texturemins[1] - h / 2; - x = x >> r_drawsurf.surfmip; - y = y >> r_drawsurf.surfmip; - w = w >> r_drawsurf.surfmip; - h = h >> r_drawsurf.surfmip; + x = x >> r_drawsurf.surfmip; + y = y >> r_drawsurf.surfmip; + w = w >> r_drawsurf.surfmip; + h = h >> r_drawsurf.surfmip; - if( w < 1 || h < 1 ) - continue; + if( w < 1 || h < 1 ) + continue; + + if( x < 0 ) + { + s1 += ( -x ) * ( s2 - s1 ) / w; + x = 0; + } + if( x + w > r_drawsurf.surfwidth ) + { + s2 -= ( x + w - r_drawsurf.surfwidth ) * ( s2 - s1 ) / w; + w = r_drawsurf.surfwidth - x; + } + if( y + h > r_drawsurf.surfheight ) + { + t2 -= ( y + h - r_drawsurf.surfheight ) * ( t2 - t1 ) / h; + h = r_drawsurf.surfheight - y; + } + + if( s1 < 0 ) + s1 = 0; + if( t1 < 0 ) + t1 = 0; + + if( s2 > tex->width ) + s2 = tex->width; + if( t2 > tex->height ) + t2 = tex->height; + + if( !tex->pixels[0] || s1 >= s2 || t1 >= t2 || !w ) + continue; + + if( tex->alpha_pixels ) + { + buffer = tex->alpha_pixels; + transparent = true; + } + else + buffer = tex->pixels[0]; + + height = h; + if( y < 0 ) + { + skip = -y; + height += y; + y = 0; + } + else + skip = 0; + + dest = ((pixel_t *)r_drawsurf.surfdat ) + y * r_drawsurf.rowbytes + x; + + for( v = 0; v < height; v++ ) + { + // int alpha1 = vid.alpha; + sv = ( skip + v ) * ( t2 - t1 ) / h + t1; + source = buffer + sv * tex->width + s1; - if( x < 0 ) { - s1 += (-x)*(s2-s1) / w; - x = 0; - } - if( x + w > r_drawsurf.surfwidth ) - { - s2 -= (x + w - r_drawsurf.surfwidth) * (s2 - s1)/ w ; - w = r_drawsurf.surfwidth - x; - } - if( y + h > r_drawsurf.surfheight ) - { - t2 -= (y + h - r_drawsurf.surfheight) * (t2 - t1) / h; - h = r_drawsurf.surfheight - y; - } - - if( s1 < 0 ) - s1 = 0; - if( t1 < 0 ) - t1 = 0; - - if( s2 > tex->width ) - s2 = tex->width; - if( t2 > tex->height ) - t2 = tex->height; - - if( !tex->pixels[0] || s1 >= s2 || t1 >= t2 || !w ) - continue; - - if( tex->alpha_pixels ) - { - buffer = tex->alpha_pixels; - transparent = true; - } - else - buffer = tex->pixels[0]; - - height = h; - if (y < 0) - { - skip = -y; - height += y; - y = 0; - } - else - skip = 0; - - dest = ((pixel_t*)r_drawsurf.surfdat) + y * r_drawsurf.rowbytes + x; - - for (v=0 ; vwidth + s1; + f = 0; + fstep = ( s2 - s1 ) * 0x10000 / w; + if( w == s2 - s1 ) + fstep = 0x10000; + for( u = 0; u < w; u++ ) { - f = 0; - fstep = (s2-s1)*0x10000/w; - if( w == s2 - s1 ) - fstep = 0x10000; + pixel_t src = source[f >> 16]; + int alpha = 7; + f += fstep; - for (u=0 ; u>16]; - int alpha = 7; - f += fstep; + alpha &= src >> ( 16 - 3 ); + src = src << 3; + } - if( transparent ) - { - alpha &= src >> (16 - 3); - src = src << 3; - } + if( alpha <= 0 ) + continue; - if( alpha <= 0 ) + if( alpha < 7 ) // && (vid.rendermode == kRenderTransAlpha || vid.rendermode == kRenderTransTexture ) ) + { + pixel_t screen = dest[u]; // | 0xff & screen & src ; + if( screen == TRANSPARENT_COLOR ) continue; - - if( alpha < 7) // && (vid.rendermode == kRenderTransAlpha || vid.rendermode == kRenderTransTexture ) ) - { - pixel_t screen = dest[u]; // | 0xff & screen & src ; - if( screen == TRANSPARENT_COLOR ) - continue; - dest[u] = BLEND_ALPHA( alpha, src, screen); - - } - else - dest[u] = src; + dest[u] = BLEND_ALPHA( alpha, src, screen ); } + else + dest[u] = src; + } - dest += r_drawsurf.rowbytes; } + dest += r_drawsurf.rowbytes; + } } } @@ -1122,42 +1129,42 @@ static void R_DrawSurfaceDecals( void ) D_CacheSurface ================ */ -surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel) +surfcache_t *D_CacheSurface( msurface_t *surface, int miplevel ) { - surfcache_t *cache; - int maps; + surfcache_t *cache; + int maps; // // if the surface is animating or flashing, flush the cache // - r_drawsurf.image = R_GetTexture(R_TextureAnimation (surface)->gl_texturenum); + r_drawsurf.image = R_GetTexture( R_TextureAnimation( surface )->gl_texturenum ); // does not support conveyors with world luxels now if( surface->texinfo->flags & TEX_WORLD_LUXELS ) surface->flags &= ~SURF_CONVEYOR; - if( surface->flags & SURF_CONVEYOR) + if( surface->flags & SURF_CONVEYOR ) { - if( miplevel >= 1) + if( miplevel >= 1 ) { - surface->extents[0] = surface->info->lightextents[0] * LM_SAMPLE_SIZE_AUTO( r_drawsurf.surf ) * 2 ; + surface->extents[0] = surface->info->lightextents[0] * LM_SAMPLE_SIZE_AUTO( r_drawsurf.surf ) * 2; surface->info->lightmapmins[0] = -surface->info->lightextents[0] * LM_SAMPLE_SIZE_AUTO( r_drawsurf.surf ); } else { - surface->extents[0] = surface->info->lightextents[0] * LM_SAMPLE_SIZE_AUTO( r_drawsurf.surf ) ; - surface->info->lightmapmins[0] = -surface->info->lightextents[0] * LM_SAMPLE_SIZE_AUTO( r_drawsurf.surf )/2; + surface->extents[0] = surface->info->lightextents[0] * LM_SAMPLE_SIZE_AUTO( r_drawsurf.surf ); + surface->info->lightmapmins[0] = -surface->info->lightextents[0] * LM_SAMPLE_SIZE_AUTO( r_drawsurf.surf ) / 2; } } /// todo: port this - //r_drawsurf.lightadj[0] = r_newrefdef.lightstyles[surface->styles[0]].white*128; - //r_drawsurf.lightadj[1] = r_newrefdef.lightstyles[surface->styles[1]].white*128; - //r_drawsurf.lightadj[2] = r_newrefdef.lightstyles[surface->styles[2]].white*128; - //r_drawsurf.lightadj[3] = r_newrefdef.lightstyles[surface->styles[3]].white*128; + // r_drawsurf.lightadj[0] = r_newrefdef.lightstyles[surface->styles[0]].white*128; + // r_drawsurf.lightadj[1] = r_newrefdef.lightstyles[surface->styles[1]].white*128; + // r_drawsurf.lightadj[2] = r_newrefdef.lightstyles[surface->styles[2]].white*128; + // r_drawsurf.lightadj[3] = r_newrefdef.lightstyles[surface->styles[3]].white*128; // // see if the cache holds apropriate data // - cache = CACHESPOT(surface)[miplevel]; + cache = CACHESPOT( surface )[miplevel]; // check for lightmap modification for( maps = 0; maps < MAXLIGHTMAPS && surface->styles[maps] != 255; maps++ ) @@ -1169,28 +1176,28 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel) } - if (cache && !cache->dlight && surface->dlightframe != tr.framecount - && cache->image == r_drawsurf.image - && cache->lightadj[0] == r_drawsurf.lightadj[0] - && cache->lightadj[1] == r_drawsurf.lightadj[1] - && cache->lightadj[2] == r_drawsurf.lightadj[2] - && cache->lightadj[3] == r_drawsurf.lightadj[3] ) + if( cache && !cache->dlight && surface->dlightframe != tr.framecount + && cache->image == r_drawsurf.image + && cache->lightadj[0] == r_drawsurf.lightadj[0] + && cache->lightadj[1] == r_drawsurf.lightadj[1] + && cache->lightadj[2] == r_drawsurf.lightadj[2] + && cache->lightadj[3] == r_drawsurf.lightadj[3] ) return cache; if( surface->dlightframe == tr.framecount ) { int i; // invalidate dlight cache - for( i = 0; i < 4; i++) + for( i = 0; i < 4; i++ ) { - if( CACHESPOT(surface)[i] ) - CACHESPOT(surface)[i]->image = NULL; + if( CACHESPOT( surface )[i] ) + CACHESPOT( surface )[i]->image = NULL; } } // // determine shape of surface // - surfscale = 1.0 / (1<flags & SURF_CONVEYOR ) r_drawsurf.surfwidth = surface->extents[0] >> miplevel; @@ -1211,16 +1218,16 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel) // // allocate memory if needed // - if (!cache) // if a texture just animated, don't reallocate it + if( !cache ) // if a texture just animated, don't reallocate it { - cache = D_SCAlloc (r_drawsurf.surfwidth, - r_drawsurf.surfwidth * r_drawsurf.surfheight * 2); - CACHESPOT(surface)[miplevel] = cache; - cache->owner = &CACHESPOT(surface)[miplevel]; + cache = D_SCAlloc( r_drawsurf.surfwidth, + r_drawsurf.surfwidth * r_drawsurf.surfheight * 2 ); + CACHESPOT( surface )[miplevel] = cache; + cache->owner = &CACHESPOT( surface )[miplevel]; cache->mipscale = surfscale; } - if (surface->dlightframe == tr.framecount) + if( surface->dlightframe == tr.framecount ) cache->dlight = 1; else cache->dlight = 0; @@ -1241,13 +1248,13 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel) // r_drawsurf.surf = surface; - //c_surf++; + // c_surf++; // calculate the lightings - R_BuildLightMap ( ); + R_BuildLightMap( ); // rasterize the surface into the cache - R_DrawSurface (); + R_DrawSurface(); R_DrawSurfaceDecals(); return cache; diff --git a/ref/soft/r_trialias.c b/ref/soft/r_trialias.c index 4e84642d..07c43539 100644 --- a/ref/soft/r_trialias.c +++ b/ref/soft/r_trialias.c @@ -3,29 +3,29 @@ // not really draw alias models here, but use this to draw triangles -affinetridesc_t r_affinetridesc; +affinetridesc_t r_affinetridesc; -int r_aliasblendcolor; +int r_aliasblendcolor; -float aliastransform[3][4]; -float aliasworldtransform[3][4]; -float aliasoldworldtransform[3][4]; +float aliastransform[3][4]; +float aliasworldtransform[3][4]; +float aliasoldworldtransform[3][4]; -float s_ziscale; -static vec3_t s_alias_forward, s_alias_right, s_alias_up; +float s_ziscale; +static vec3_t s_alias_forward, s_alias_right, s_alias_up; -#define NUMVERTEXNORMALS 162 +#define NUMVERTEXNORMALS 162 -float r_avertexnormals[NUMVERTEXNORMALS][3] = { +float r_avertexnormals[NUMVERTEXNORMALS][3] = { #include "anorms.h" }; -void R_AliasSetUpTransform (void); -void R_AliasProjectAndClipTestFinalVert (finalvert_t *fv); +void R_AliasSetUpTransform( void ); +void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ); void R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv ); @@ -41,7 +41,7 @@ R_AliasCheckBBox #define BBOX_MUST_CLIP_Z 2 #define BBOX_TRIVIAL_REJECT 8 -static void VectorInverse (vec3_t v) +static void VectorInverse( vec3_t v ) { v[0] = -v[0]; v[1] = -v[1]; @@ -53,11 +53,11 @@ static void VectorInverse (vec3_t v) R_SetUpWorldTransform ================ */ -void R_SetUpWorldTransform (void) +void R_SetUpWorldTransform( void ) { - int i; - static float viewmatrix[3][4]; - vec3_t angles; + int i; + static float viewmatrix[3][4]; + vec3_t angles; // TODO: should really be stored with the entity instead of being reconstructed // TODO: should use a look-up table @@ -72,23 +72,23 @@ void R_SetUpWorldTransform (void) // TODO: can do this with simple matrix rearrangement - memset( aliasworldtransform, 0, sizeof( aliasworldtransform ) ); - memset( aliasoldworldtransform, 0, sizeof( aliasworldtransform ) ); + memset( aliasworldtransform, 0, sizeof( aliasworldtransform )); + memset( aliasoldworldtransform, 0, sizeof( aliasworldtransform )); - for (i=0 ; i<3 ; i++) + for( i = 0; i < 3; i++ ) { - aliasoldworldtransform[i][0] = aliasworldtransform[i][0] = s_alias_forward[i]; + aliasoldworldtransform[i][0] = aliasworldtransform[i][0] = s_alias_forward[i]; aliasoldworldtransform[i][0] = aliasworldtransform[i][1] = -s_alias_right[i]; - aliasoldworldtransform[i][0] = aliasworldtransform[i][2] = s_alias_up[i]; + aliasoldworldtransform[i][0] = aliasworldtransform[i][2] = s_alias_up[i]; } aliasworldtransform[0][3] = -RI.vieworg[0]; aliasworldtransform[1][3] = -RI.vieworg[1]; aliasworldtransform[2][3] = -RI.vieworg[2]; - //aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]-r_origin[0]; - //aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]-r_origin[1]; - //aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]-r_origin[2]; + // aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]-r_origin[0]; + // aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]-r_origin[1]; + // aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]-r_origin[2]; // FIXME: can do more efficiently than full concatenation // memcpy( rotationmatrix, t2matrix, sizeof( rotationmatrix ) ); @@ -96,11 +96,11 @@ void R_SetUpWorldTransform (void) // R_ConcatTransforms (t2matrix, tmatrix, rotationmatrix); // TODO: should be global, set when vright, etc., set - VectorCopy (RI.vright, viewmatrix[0]); - VectorCopy (RI.vup, viewmatrix[1]); - VectorInverse (viewmatrix[1]); - //VectorScale(viewmatrix[1], -1, viewmatrix[1]); - VectorCopy (RI.vforward, viewmatrix[2]); + VectorCopy( RI.vright, viewmatrix[0] ); + VectorCopy( RI.vup, viewmatrix[1] ); + VectorInverse( viewmatrix[1] ); + // VectorScale(viewmatrix[1], -1, viewmatrix[1]); + VectorCopy( RI.vforward, viewmatrix[2] ); viewmatrix[0][3] = 0; viewmatrix[1][3] = 0; @@ -108,16 +108,16 @@ void R_SetUpWorldTransform (void) // memcpy( aliasworldtransform, rotationmatrix, sizeof( aliastransform ) ); - //R_ConcatTransforms (viewmatrix, aliasworldtransform, aliastransform); - Matrix3x4_ConcatTransforms(aliastransform, viewmatrix, aliasworldtransform ); + // R_ConcatTransforms (viewmatrix, aliasworldtransform, aliastransform); + Matrix3x4_ConcatTransforms( aliastransform, viewmatrix, aliasworldtransform ); aliasworldtransform[0][3] = 0; aliasworldtransform[1][3] = 0; aliasworldtransform[2][3] = 0; - //aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]; - //aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]; - //aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]; + // aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]; + // aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]; + // aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]; } @@ -126,11 +126,11 @@ void R_SetUpWorldTransform (void) R_AliasSetUpTransform ================ */ -void R_AliasSetUpTransform (void) +void R_AliasSetUpTransform( void ) { - int i; - static float viewmatrix[3][4]; - vec3_t angles; + int i; + static float viewmatrix[3][4]; + vec3_t angles; // TODO: should really be stored with the entity instead of being reconstructed // TODO: should use a look-up table @@ -145,23 +145,23 @@ void R_AliasSetUpTransform (void) // TODO: can do this with simple matrix rearrangement - memset( aliasworldtransform, 0, sizeof( aliasworldtransform ) ); - memset( aliasoldworldtransform, 0, sizeof( aliasworldtransform ) ); + memset( aliasworldtransform, 0, sizeof( aliasworldtransform )); + memset( aliasoldworldtransform, 0, sizeof( aliasworldtransform )); - for (i=0 ; i<3 ; i++) + for( i = 0; i < 3; i++ ) { - aliasoldworldtransform[i][0] = aliasworldtransform[i][0] = s_alias_forward[i]; + aliasoldworldtransform[i][0] = aliasworldtransform[i][0] = s_alias_forward[i]; aliasoldworldtransform[i][0] = aliasworldtransform[i][1] = -s_alias_right[i]; - aliasoldworldtransform[i][0] = aliasworldtransform[i][2] = s_alias_up[i]; + aliasoldworldtransform[i][0] = aliasworldtransform[i][2] = s_alias_up[i]; } - aliasworldtransform[0][3] = RI.currententity->origin[0]-RI.vieworg[0]; - aliasworldtransform[1][3] = RI.currententity->origin[1]-RI.vieworg[1]; - aliasworldtransform[2][3] = RI.currententity->origin[2]-RI.vieworg[2]; + aliasworldtransform[0][3] = RI.currententity->origin[0] - RI.vieworg[0]; + aliasworldtransform[1][3] = RI.currententity->origin[1] - RI.vieworg[1]; + aliasworldtransform[2][3] = RI.currententity->origin[2] - RI.vieworg[2]; - //aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]-r_origin[0]; - //aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]-r_origin[1]; - //aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]-r_origin[2]; + // aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]-r_origin[0]; + // aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]-r_origin[1]; + // aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]-r_origin[2]; // FIXME: can do more efficiently than full concatenation // memcpy( rotationmatrix, t2matrix, sizeof( rotationmatrix ) ); @@ -169,11 +169,11 @@ void R_AliasSetUpTransform (void) // R_ConcatTransforms (t2matrix, tmatrix, rotationmatrix); // TODO: should be global, set when vright, etc., set - VectorCopy (RI.vright, viewmatrix[0]); - VectorCopy (RI.vup, viewmatrix[1]); - VectorInverse (viewmatrix[1]); - //VectorScale(viewmatrix[1], -1, viewmatrix[1]); - VectorCopy (RI.vforward, viewmatrix[2]); + VectorCopy( RI.vright, viewmatrix[0] ); + VectorCopy( RI.vup, viewmatrix[1] ); + VectorInverse( viewmatrix[1] ); + // VectorScale(viewmatrix[1], -1, viewmatrix[1]); + VectorCopy( RI.vforward, viewmatrix[2] ); viewmatrix[0][3] = 0; viewmatrix[1][3] = 0; @@ -181,16 +181,16 @@ void R_AliasSetUpTransform (void) // memcpy( aliasworldtransform, rotationmatrix, sizeof( aliastransform ) ); - //R_ConcatTransforms (viewmatrix, aliasworldtransform, aliastransform); - Matrix3x4_ConcatTransforms(aliastransform, viewmatrix, aliasworldtransform ); + // R_ConcatTransforms (viewmatrix, aliasworldtransform, aliastransform); + Matrix3x4_ConcatTransforms( aliastransform, viewmatrix, aliasworldtransform ); aliasworldtransform[0][3] = RI.currententity->origin[0]; aliasworldtransform[1][3] = RI.currententity->origin[1]; aliasworldtransform[2][3] = RI.currententity->origin[2]; - //aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]; - //aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]; - //aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]; + // aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]; + // aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]; + // aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]; } /* @@ -200,8 +200,8 @@ R_AliasProjectAndClipTestFinalVert */ void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ) { - float zi; - float x, y, z; + float zi; + float x, y, z; // project points x = fv->xyz[0]; @@ -211,16 +211,16 @@ void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ) fv->zi = zi * s_ziscale; - fv->u = (x * aliasxscale * zi) + aliasxcenter; - fv->v = (y * aliasyscale * zi) + aliasycenter; + fv->u = ( x * aliasxscale * zi ) + aliasxcenter; + fv->v = ( y * aliasyscale * zi ) + aliasycenter; - if (fv->u < RI.aliasvrect.x) + if( fv->u < RI.aliasvrect.x ) fv->flags |= ALIAS_LEFT_CLIP; - if (fv->v < RI.aliasvrect.y) + if( fv->v < RI.aliasvrect.y ) fv->flags |= ALIAS_TOP_CLIP; - if (fv->u > RI.aliasvrectright) + if( fv->u > RI.aliasvrectright ) fv->flags |= ALIAS_RIGHT_CLIP; - if (fv->v > RI.aliasvrectbottom) + if( fv->v > RI.aliasvrectbottom ) fv->flags |= ALIAS_BOTTOM_CLIP; } @@ -228,15 +228,15 @@ void R_SetupFinalVert( finalvert_t *fv, float x, float y, float z, int light, in { vec3_t v = {x, y, z}; - fv->xyz[0] = DotProduct(v, aliastransform[0]) + aliastransform[0][3]; - fv->xyz[1] = DotProduct(v, aliastransform[1]) + aliastransform[1][3]; - fv->xyz[2] = DotProduct(v, aliastransform[2]) + aliastransform[2][3]; + fv->xyz[0] = DotProduct( v, aliastransform[0] ) + aliastransform[0][3]; + fv->xyz[1] = DotProduct( v, aliastransform[1] ) + aliastransform[1][3]; + fv->xyz[2] = DotProduct( v, aliastransform[2] ) + aliastransform[2][3]; fv->flags = 0; fv->l = light; - if ( fv->xyz[2] < ALIAS_Z_CLIP_PLANE ) + if( fv->xyz[2] < ALIAS_Z_CLIP_PLANE ) { fv->flags |= ALIAS_Z_CLIP; } @@ -249,14 +249,14 @@ void R_SetupFinalVert( finalvert_t *fv, float x, float y, float z, int light, in fv->t = t << 16; } -void R_RenderTriangle( finalvert_t *fv1, finalvert_t *fv2, finalvert_t *fv3 ) +void R_RenderTriangle( finalvert_t *fv1, finalvert_t *fv2, finalvert_t *fv3 ) { - if ( fv1->flags & fv2->flags & fv3->flags ) - return ; // completely clipped + if( fv1->flags & fv2->flags & fv3->flags ) + return; // completely clipped - if ( ! (fv1->flags | fv2->flags | fv3->flags) ) - { // totally unclipped + if( !( fv1->flags | fv2->flags | fv3->flags )) + { // totally unclipped aliastriangleparms.a = fv1; aliastriangleparms.b = fv2; aliastriangleparms.c = fv3; @@ -264,8 +264,8 @@ void R_RenderTriangle( finalvert_t *fv1, finalvert_t *fv2, finalvert_t *fv3 ) R_DrawTriangle(); } else - { // partially clipped - R_AliasClipTriangle (fv1, fv2, fv3); + { // partially clipped + R_AliasClipTriangle( fv1, fv2, fv3 ); } } diff --git a/ref/soft/r_triapi.c b/ref/soft/r_triapi.c index bc105c6b..cbcdcecd 100644 --- a/ref/soft/r_triapi.c +++ b/ref/soft/r_triapi.c @@ -19,15 +19,15 @@ GNU General Public License for more details. static struct { - int renderMode; // override kRenderMode from TriAPI - vec4_t triRGBA; + int renderMode; // override kRenderMode from TriAPI + vec4_t triRGBA; } ds; static finalvert_t triv[3]; -static int vertcount, n; -static int mode; -static short s, t; -static uint light; +static int vertcount, n; +static int mode; +static short s, t; +static uint light; /* =============================================================== @@ -82,16 +82,16 @@ _TriColor4f */ void GAME_EXPORT _TriColor4f( float rr, float gg, float bb, float aa ) { - //pglColor4f( r, g, b, a ); - unsigned short r,g,b; - unsigned int major, minor; + // pglColor4f( r, g, b, a ); + unsigned short r, g, b; + unsigned int major, minor; if( vid.rendermode == kRenderTransAdd || vid.rendermode == kRenderGlow ) rr *= aa, gg *= aa, bb *= aa; - //gEngfuncs.Con_Printf("%d\n", vid.alpha); + // gEngfuncs.Con_Printf("%d\n", vid.alpha); - light = (rr + gg + bb) * 31 / 3; + light = ( rr + gg + bb ) * 31 / 3; if( light > 31 ) light = 31; @@ -116,12 +116,12 @@ void GAME_EXPORT _TriColor4f( float rr, float gg, float bb, float aa ) b = 31; - major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2))); + major = ((( r >> 2 ) & MASK( 3 )) << 5 ) | (((( g >> 3 ) & MASK( 3 )) << 2 )) | ((( b >> 3 ) & MASK( 2 ))); // save minor GBRGBRGB - minor = MOVE_BIT(r,1,5) | MOVE_BIT(r,0,2) | MOVE_BIT(g,2,7) | MOVE_BIT(g,1,4) | MOVE_BIT(g,0,1) | MOVE_BIT(b,2,6)| MOVE_BIT(b,1,3)|MOVE_BIT(b,0,0); + minor = MOVE_BIT( r, 1, 5 ) | MOVE_BIT( r, 0, 2 ) | MOVE_BIT( g, 2, 7 ) | MOVE_BIT( g, 1, 4 ) | MOVE_BIT( g, 0, 1 ) | MOVE_BIT( b, 2, 6 ) | MOVE_BIT( b, 1, 3 ) | MOVE_BIT( b, 0, 0 ); - vid.color = major << 8 | (minor & 0xFF); + vid.color = major << 8 | ( minor & 0xFF ); } /* @@ -132,10 +132,10 @@ TriColor4ub */ void TriColor4ub( byte r, byte g, byte b, byte a ) { - ds.triRGBA[0] = r * (1.0f / 255.0f); - ds.triRGBA[1] = g * (1.0f / 255.0f); - ds.triRGBA[2] = b * (1.0f / 255.0f); - ds.triRGBA[3] = a * (1.0f / 255.0f); + ds.triRGBA[0] = r * ( 1.0f / 255.0f ); + ds.triRGBA[1] = g * ( 1.0f / 255.0f ); + ds.triRGBA[2] = b * ( 1.0f / 255.0f ); + ds.triRGBA[3] = a * ( 1.0f / 255.0f ); _TriColor4f( ds.triRGBA[0], ds.triRGBA[1], ds.triRGBA[2], 1.0f ); } @@ -148,10 +148,10 @@ TriColor4ub */ void GAME_EXPORT _TriColor4ub( byte r, byte g, byte b, byte a ) { - _TriColor4f( r * (1.0f / 255.0f), - g * (1.0f / 255.0f), - b * (1.0f / 255.0f), - a * (1.0f / 255.0f)); + _TriColor4f( r * ( 1.0f / 255.0f ), + g * ( 1.0f / 255.0f ), + b * ( 1.0f / 255.0f ), + a * ( 1.0f / 255.0f )); } /* @@ -161,11 +161,12 @@ TriColor4f */ void TriColor4f( float r, float g, float b, float a ) { - //if( a < 0.5 ) + // if( a < 0.5 ) // a = 1; if( ds.renderMode == kRenderTransAlpha ) TriColor4ub( r * 255.0f, g * 255.0f, b * 255.0f, a * 255.0f ); - else _TriColor4f( r * a, g * a, b * a, 1.0 ); + else + _TriColor4f( r * a, g * a, b * a, 1.0 ); ds.triRGBA[0] = r; ds.triRGBA[1] = g; @@ -182,8 +183,8 @@ TriTexCoord2f void GAME_EXPORT TriTexCoord2f( float u, float v ) { double u1 = 0, v1 = 0; - u = fmodf(u, 10); - v = fmodf(v, 10); + u = fmodf( u, 10 ); + v = fmodf( v, 10 ); if( u < 1000 && u > -1000 ) u1 = u; if( v < 1000 && v > -1000 ) @@ -199,8 +200,8 @@ void GAME_EXPORT TriTexCoord2f( float u, float v ) v1 = v1 - 1; - s = r_affinetridesc.skinwidth * bound(0.01,u1,0.99); - t = r_affinetridesc.skinheight * bound(0.01,v1,0.99); + s = r_affinetridesc.skinwidth * bound( 0.01, u1, 0.99 ); + t = r_affinetridesc.skinheight * bound( 0.01, v1, 0.99 ); } /* @@ -224,35 +225,35 @@ void GAME_EXPORT TriVertex3f( float x, float y, float z ) { if( mode == TRI_TRIANGLES ) { - R_SetupFinalVert( &triv[vertcount], x, y, z, light << 8,s,t); + R_SetupFinalVert( &triv[vertcount], x, y, z, light << 8, s, t ); vertcount++; if( vertcount == 3 ) { R_RenderTriangle( &triv[0], &triv[1], &triv[2] ); - //R_RenderTriangle( &triv[2], &triv[1], &triv[0] ); + // R_RenderTriangle( &triv[2], &triv[1], &triv[0] ); vertcount = 0; } } if( mode == TRI_TRIANGLE_FAN ) { - R_SetupFinalVert( &triv[vertcount], x, y, z, light << 8,s,t); + R_SetupFinalVert( &triv[vertcount], x, y, z, light << 8, s, t ); vertcount++; if( vertcount >= 3 ) { R_RenderTriangle( &triv[0], &triv[1], &triv[2] ); - //R_RenderTriangle( &triv[2], &triv[1], &triv[0] ); + // R_RenderTriangle( &triv[2], &triv[1], &triv[0] ); triv[1] = triv[2]; vertcount = 2; } } if( mode == TRI_TRIANGLE_STRIP ) { - R_SetupFinalVert( &triv[n], x, y, z, light << 8,s,t); + R_SetupFinalVert( &triv[n], x, y, z, light << 8, s, t ); n++; vertcount++; if( n == 3 ) n = 0; - if (vertcount >= 3) + if( vertcount >= 3 ) { if( vertcount & 1 ) R_RenderTriangle( &triv[0], &triv[1], &triv[2] ); @@ -283,7 +284,7 @@ bind current texture */ int TriSpriteTexture( model_t *pSpriteModel, int frame ) { - int gl_texturenum; + int gl_texturenum; if(( gl_texturenum = R_GetSpriteTexture( pSpriteModel, frame )) == 0 ) return 0; @@ -345,7 +346,7 @@ TriBrightness */ void TriBrightness( float brightness ) { - float r, g, b; + float r, g, b; r = ds.triRGBA[0] * ds.triRGBA[3] * brightness; g = ds.triRGBA[1] * ds.triRGBA[3] * brightness;