summaryrefslogtreecommitdiff
path: root/src/sw_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw_misc.c')
-rw-r--r--src/sw_misc.c274
1 files changed, 129 insertions, 145 deletions
diff --git a/src/sw_misc.c b/src/sw_misc.c
index 0a00d04..5e0ede5 100644
--- a/src/sw_misc.c
+++ b/src/sw_misc.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -29,9 +29,9 @@ cvar_t *sw_mipscale;
surfcache_t *d_initial_rover;
qboolean d_roverwrapped;
int d_minmip;
-float d_scalemip[NUM_MIPS-1];
+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};
extern int d_aflatcolor;
@@ -40,30 +40,29 @@ int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
int d_pix_min, d_pix_max, d_pix_shift;
int d_scantable[MAXHEIGHT];
-short *zspantable[MAXHEIGHT];
+short *zspantable[MAXHEIGHT];
/*
================
D_Patch
================
*/
-void D_Patch (void)
+void D_Patch(void)
{
#if USE_ASM
- extern void D_Aff8Patch( void );
+ extern void D_Aff8Patch(void);
static qboolean protectset8 = qfalse;
- extern void D_PolysetAff8Start( void );
-
- if (!protectset8)
- {
- Sys_MakeCodeWriteable ((int)D_PolysetAff8Start,
- (int)D_Aff8Patch - (int)D_PolysetAff8Start);
- Sys_MakeCodeWriteable ((long)R_Surf8Start,
- (long)R_Surf8End - (long)R_Surf8Start);
+ extern void D_PolysetAff8Start(void);
+
+ if (!protectset8) {
+ Sys_MakeCodeWriteable((int)D_PolysetAff8Start,
+ (int)D_Aff8Patch - (int)D_PolysetAff8Start);
+ Sys_MakeCodeWriteable((long)R_Surf8Start,
+ (long)R_Surf8End - (long)R_Surf8Start);
protectset8 = qtrue;
}
- R_Surf8Patch ();
+ R_Surf8Patch();
D_Aff8Patch();
#endif
}
@@ -72,7 +71,7 @@ void D_Patch (void)
D_ViewChanged
================
*/
-void D_ViewChanged (void)
+void D_ViewChanged(void)
{
int i;
@@ -96,24 +95,22 @@ void D_ViewChanged (void)
d_vrecty = r_refdef.vrect.y;
d_vrectright_particle = r_refdef.vrectright - d_pix_max;
d_vrectbottom_particle =
- r_refdef.vrectbottom - d_pix_max;
+ r_refdef.vrectbottom - d_pix_max;
- for (i=0 ; i<vid.height; i++)
- {
- d_scantable[i] = i*r_screenwidth;
- zspantable[i] = d_pzbuffer + i*d_zwidth;
+ for (i = 0; i < vid.height; i++) {
+ d_scantable[i] = i * r_screenwidth;
+ zspantable[i] = d_pzbuffer + i * d_zwidth;
}
/*
** clear Z-buffer and color-buffers if we're doing the gallery
*/
- if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
- {
- memset( d_pzbuffer, 0xff, vid.width * vid.height * sizeof( d_pzbuffer[0] ) );
- R_DrawFill8( r_newrefdef.x, r_newrefdef.y, r_newrefdef.width, r_newrefdef.height, /*( int ) sw_clearcolor->value & 0xff*/0 );
+ if (r_newrefdef.rdflags & RDF_NOWORLDMODEL) {
+ memset(d_pzbuffer, 0xff, vid.width * vid.height * sizeof(d_pzbuffer[0]));
+ R_DrawFill8(r_newrefdef.x, r_newrefdef.y, r_newrefdef.width, r_newrefdef.height, /*(int)sw_clearcolor->value & 0xff*/0);
}
- D_Patch ();
+ D_Patch();
}
@@ -123,17 +120,17 @@ void D_ViewChanged (void)
R_PrintTimes
=============
*/
-void R_PrintTimes (void)
+void R_PrintTimes(void)
{
int r_time2;
int ms;
- r_time2 = Sys_Milliseconds ();
+ r_time2 = Sys_Milliseconds();
ms = r_time2 - r_time1;
-
+
Com_Printf("%5i ms %3i/%3i/%3i poly %3i surf\n",
- ms, c_faceclip, r_polycount, r_drawnpolycount, c_surf);
+ ms, c_faceclip, r_polycount, r_drawnpolycount, c_surf);
c_surf = 0;
}
@@ -143,11 +140,11 @@ void R_PrintTimes (void)
R_PrintDSpeeds
=============
*/
-void R_PrintDSpeeds (void)
+void R_PrintDSpeeds(void)
{
int ms, dp_time, r_time2, rw_time, db_time, se_time, de_time, da_time;
- r_time2 = Sys_Milliseconds ();
+ r_time2 = Sys_Milliseconds();
da_time = (da_time2 - da_time1);
dp_time = (dp_time2 - dp_time1);
@@ -158,7 +155,7 @@ void R_PrintDSpeeds (void)
ms = (r_time2 - r_time1);
Com_Printf("%3i %2ip %2iw %2ib %2is %2ie %2ia\n",
- ms, dp_time, rw_time, db_time, se_time, de_time, da_time);
+ ms, dp_time, rw_time, db_time, se_time, de_time, da_time);
}
@@ -167,7 +164,7 @@ void R_PrintDSpeeds (void)
R_PrintAliasStats
=============
*/
-void R_PrintAliasStats (void)
+void R_PrintAliasStats(void)
{
Com_Printf("%3i polygon model drawn\n", r_amodels_drawn);
}
@@ -179,24 +176,23 @@ void R_PrintAliasStats (void)
R_TransformFrustum
===================
*/
-void R_TransformFrustum (void)
+void R_TransformFrustum(void)
{
int i;
vec3_t v, v2;
-
- for (i=0 ; i<4 ; i++)
- {
+
+ for (i = 0; i < 4; i++) {
v[0] = screenedge[i].normal[2];
v[1] = -screenedge[i].normal[0];
v[2] = screenedge[i].normal[1];
- v2[0] = v[1]*vright[0] + v[2]*vup[0] + v[0]*vpn[0];
- v2[1] = v[1]*vright[1] + v[2]*vup[1] + v[0]*vpn[1];
- v2[2] = v[1]*vright[2] + v[2]*vup[2] + v[0]*vpn[2];
+ v2[0] = v[1] * vright[0] + v[2] * vup[0] + v[0] * vpn[0];
+ v2[1] = v[1] * vright[1] + v[2] * vup[1] + v[0] * vpn[1];
+ v2[2] = v[1] * vright[2] + v[2] * vup[2] + v[0] * vpn[2];
- VectorCopy (v2, view_clipplanes[i].normal);
+ VectorCopy(v2, view_clipplanes[i].normal);
- view_clipplanes[i].dist = DotProduct (modelorg, v2);
+ view_clipplanes[i].dist = DotProduct(modelorg, v2);
}
}
@@ -206,11 +202,11 @@ void R_TransformFrustum (void)
TransformVector
================
*/
-void TransformVector (vec3_t in, vec3_t out)
+void TransformVector(vec3_t in, vec3_t out)
{
- out[0] = DotProduct(in,vright);
- out[1] = DotProduct(in,vup);
- out[2] = DotProduct(in,vpn);
+ out[0] = DotProduct(in, vright);
+ out[1] = DotProduct(in, vup);
+ out[2] = DotProduct(in, vpn);
}
/*
@@ -218,14 +214,14 @@ void TransformVector (vec3_t in, vec3_t out)
R_TransformPlane
================
*/
-void R_TransformPlane (cplane_t *p, float *normal, float *dist)
+void R_TransformPlane(cplane_t *p, float *normal, float *dist)
{
float d;
-
- d = DotProduct (r_origin, p->normal);
+
+ d = DotProduct(r_origin, p->normal);
*dist = p->dist - d;
// TODO: when we have rotating entities, this will need to use the view matrix
- TransformVector (p->normal, normal);
+ TransformVector(p->normal, normal);
}
@@ -234,29 +230,24 @@ void R_TransformPlane (cplane_t *p, float *normal, float *dist)
R_SetUpFrustumIndexes
===============
*/
-void R_SetUpFrustumIndexes (void)
+void R_SetUpFrustumIndexes(void)
{
int i, j, *pindex;
pindex = r_frustum_indexes;
- for (i=0 ; i<4 ; i++)
- {
- for (j=0 ; j<3 ; j++)
- {
- if (view_clipplanes[i].normal[j] < 0)
- {
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 3; j++) {
+ if (view_clipplanes[i].normal[j] < 0) {
pindex[j] = j;
- pindex[j+3] = j+3;
- }
- else
- {
- pindex[j] = j+3;
- pindex[j+3] = j;
+ pindex[j + 3] = j + 3;
+ } else {
+ pindex[j] = j + 3;
+ pindex[j + 3] = j;
}
}
- // FIXME: do just once at start
+ // FIXME: do just once at start
pfrustum_indexes[i] = pindex;
pindex += 6;
}
@@ -270,22 +261,22 @@ Called every time the vid structure or r_refdef changes.
Guaranteed to be called before the first refresh
===============
*/
-void R_ViewChanged (vrectSoft_t *vr)
+void R_ViewChanged(vrectSoft_t *vr)
{
int i;
r_refdef.vrect = *vr;
- r_refdef.horizontalFieldOfView = 2*tan((float)r_newrefdef.fov_x/360*M_PI);;
- verticalFieldOfView = 2*tan((float)r_newrefdef.fov_y/360*M_PI);
+ r_refdef.horizontalFieldOfView = 2 * tan((float)r_newrefdef.fov_x / 360 * M_PI);
+ verticalFieldOfView = 2 * tan((float)r_newrefdef.fov_y / 360 * M_PI);
r_refdef.fvrectx = (float)r_refdef.vrect.x;
r_refdef.fvrectx_adj = (float)r_refdef.vrect.x - 0.5;
- r_refdef.vrect_x_adj_shift20 = (r_refdef.vrect.x<<20) + (1<<19) - 1;
+ r_refdef.vrect_x_adj_shift20 = (r_refdef.vrect.x << 20) + (1 << 19) - 1;
r_refdef.fvrecty = (float)r_refdef.vrect.y;
r_refdef.fvrecty_adj = (float)r_refdef.vrect.y - 0.5;
r_refdef.vrectright = r_refdef.vrect.x + r_refdef.vrect.width;
- r_refdef.vrectright_adj_shift20 = (r_refdef.vrectright<<20) + (1<<19) - 1;
+ r_refdef.vrectright_adj_shift20 = (r_refdef.vrectright << 20) + (1 << 19) - 1;
r_refdef.fvrectright = (float)r_refdef.vrectright;
r_refdef.fvrectright_adj = (float)r_refdef.vrectright - 0.5;
r_refdef.vrectrightedge = (float)r_refdef.vrectright - 0.99;
@@ -298,13 +289,13 @@ void R_ViewChanged (vrectSoft_t *vr)
r_refdef.aliasvrect.width = (int)(r_refdef.vrect.width * r_aliasuvscale);
r_refdef.aliasvrect.height = (int)(r_refdef.vrect.height * r_aliasuvscale);
r_refdef.aliasvrectright = r_refdef.aliasvrect.x +
- r_refdef.aliasvrect.width;
+ r_refdef.aliasvrect.width;
r_refdef.aliasvrectbottom = r_refdef.aliasvrect.y +
- r_refdef.aliasvrect.height;
+ r_refdef.aliasvrect.height;
xOrigin = r_refdef.xOrigin;
yOrigin = r_refdef.yOrigin;
-
+
// values for perspective projection
// if math were exact, the values would range from 0.5 to to range+0.5
// hopefully they wll be in the 0.000001 to range+.999999 and truncate
@@ -312,10 +303,10 @@ void R_ViewChanged (vrectSoft_t *vr)
// but will definately render in the [range] row and column, so adjust the
// buffer origin to get an exact edge to edge fill
xcenter = ((float)r_refdef.vrect.width * XCENTERING) +
- r_refdef.vrect.x - 0.5;
+ r_refdef.vrect.x - 0.5;
aliasxcenter = xcenter * r_aliasuvscale;
ycenter = ((float)r_refdef.vrect.height * YCENTERING) +
- r_refdef.vrect.y - 0.5;
+ r_refdef.vrect.y - 0.5;
aliasycenter = ycenter * r_aliasuvscale;
xscale = r_refdef.vrect.width / r_refdef.horizontalFieldOfView;
@@ -325,38 +316,38 @@ void R_ViewChanged (vrectSoft_t *vr)
yscale = xscale;
aliasyscale = yscale * r_aliasuvscale;
yscaleinv = 1.0 / yscale;
- xscaleshrink = (r_refdef.vrect.width-6)/r_refdef.horizontalFieldOfView;
+ xscaleshrink = (r_refdef.vrect.width - 6) / r_refdef.horizontalFieldOfView;
yscaleshrink = xscaleshrink;
// left side clip
- screenedge[0].normal[0] = -1.0 / (xOrigin*r_refdef.horizontalFieldOfView);
+ screenedge[0].normal[0] = -1.0 / (xOrigin * r_refdef.horizontalFieldOfView);
screenedge[0].normal[1] = 0;
screenedge[0].normal[2] = 1;
screenedge[0].type = PLANE_ANYZ;
-
+
// right side clip
screenedge[1].normal[0] =
- 1.0 / ((1.0-xOrigin)*r_refdef.horizontalFieldOfView);
+ 1.0 / ((1.0 - xOrigin) * r_refdef.horizontalFieldOfView);
screenedge[1].normal[1] = 0;
screenedge[1].normal[2] = 1;
screenedge[1].type = PLANE_ANYZ;
-
+
// top side clip
screenedge[2].normal[0] = 0;
- screenedge[2].normal[1] = -1.0 / (yOrigin*verticalFieldOfView);
+ screenedge[2].normal[1] = -1.0 / (yOrigin * verticalFieldOfView);
screenedge[2].normal[2] = 1;
screenedge[2].type = PLANE_ANYZ;
-
+
// bottom side clip
screenedge[3].normal[0] = 0;
- screenedge[3].normal[1] = 1.0 / ((1.0-yOrigin)*verticalFieldOfView);
- screenedge[3].normal[2] = 1;
+ screenedge[3].normal[1] = 1.0 / ((1.0 - yOrigin) * verticalFieldOfView);
+ screenedge[3].normal[2] = 1;
screenedge[3].type = PLANE_ANYZ;
-
- for (i=0 ; i<4 ; i++)
- VectorNormalize (screenedge[i].normal);
- D_ViewChanged ();
+ for (i = 0; i < 4; i++)
+ VectorNormalize(screenedge[i].normal);
+
+ D_ViewChanged();
}
@@ -365,40 +356,38 @@ void R_ViewChanged (vrectSoft_t *vr)
R_SetupFrame
===============
*/
-void R_SetupFrame (void)
+void R_SetupFrame(void)
{
int i;
vrectSoft_t vrect;
- if (r_fullbright->modified)
- {
+ if (r_fullbright->modified) {
r_fullbright->modified = qfalse;
- D_FlushCaches (); // so all lighting changes
+ D_FlushCaches(); // so all lighting changes
}
-
+
r_framecount++;
// build the transformation matrix for the given view angles
- VectorCopy (r_refdef.vieworg, modelorg);
- VectorCopy (r_refdef.vieworg, r_origin);
+ VectorCopy(r_refdef.vieworg, modelorg);
+ VectorCopy(r_refdef.vieworg, r_origin);
- AngleVectors (r_refdef.viewangles, vpn, vright, vup);
+ AngleVectors(r_refdef.viewangles, vpn, vright, vup);
// current viewleaf
- if ( !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) )
- {
- r_viewleaf = BSP_PointLeaf (r_worldmodel->nodes, r_origin);
+ if (!(r_newrefdef.rdflags & RDF_NOWORLDMODEL)) {
+ r_viewleaf = BSP_PointLeaf(r_worldmodel->nodes, r_origin);
r_viewcluster = r_viewleaf->cluster;
}
- if (sw_waterwarp->integer && (r_newrefdef.rdflags & RDF_UNDERWATER) )
+ if (sw_waterwarp->integer && (r_newrefdef.rdflags & RDF_UNDERWATER))
r_dowarp = qtrue;
else
r_dowarp = qfalse;
- if (r_dowarp)
- { // warp into off screen buffer
+ if (r_dowarp) {
+ // warp into off screen buffer
vrect.x = 0;
vrect.y = 0;
vrect.width = r_newrefdef.width < WARP_WIDTH ? r_newrefdef.width : WARP_WIDTH;
@@ -406,9 +395,7 @@ void R_SetupFrame (void)
d_viewbuffer = r_warpbuffer;
r_screenwidth = WARP_WIDTH;
- }
- else
- {
+ } else {
vrect.x = r_newrefdef.x;
vrect.y = r_newrefdef.y;
vrect.width = r_newrefdef.width;
@@ -417,17 +404,17 @@ void R_SetupFrame (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 (vpn, base_vpn);
- VectorCopy (vright, base_vright);
- VectorCopy (vup, base_vup);
+ VectorCopy(vpn, base_vpn);
+ VectorCopy(vright, base_vright);
+ VectorCopy(vup, base_vup);
// clear frame counts
c_faceclip = 0;
@@ -449,26 +436,26 @@ void R_SetupFrame (void)
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;
}
-/*
-==============================================================================
-
+/*
+==============================================================================
+
MATH
-
-==============================================================================
-*/
+
+==============================================================================
+*/
/*
================
R_ConcatRotations
================
*/
-void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3])
+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];
@@ -496,7 +483,7 @@ void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3])
R_ConcatTransforms
================
*/
-void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4])
+void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4])
{
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
in1[0][2] * in2[2][0];
@@ -524,7 +511,7 @@ void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4])
in1[2][2] * in2[2][3] + in1[2][3];
}
-void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees )
+void R_RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
{
float m[3][3];
float im[3][3];
@@ -538,8 +525,8 @@ void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point
vf[1] = dir[1];
vf[2] = dir[2];
- PerpendicularVector( vr, dir );
- CrossProduct( vr, vf, vup );
+ PerpendicularVector(vr, dir);
+ CrossProduct(vr, vf, vup);
m[0][0] = vr[0];
m[1][0] = vr[1];
@@ -553,7 +540,7 @@ void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point
m[1][2] = vf[1];
m[2][2] = vf[2];
- memcpy( im, m, sizeof( im ) );
+ memcpy(im, m, sizeof(im));
im[0][1] = m[1][0];
im[0][2] = m[2][0];
@@ -562,32 +549,31 @@ void R_RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point
im[2][0] = m[0][2];
im[2][1] = m[1][2];
- memset( zrot, 0, sizeof( zrot ) );
+ memset(zrot, 0, sizeof(zrot));
zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
- zrot[0][0] = cos( DEG2RAD( degrees ) );
- zrot[0][1] = sin( DEG2RAD( degrees ) );
- zrot[1][0] = -sin( DEG2RAD( degrees ) );
- zrot[1][1] = cos( DEG2RAD( degrees ) );
+ zrot[0][0] = cos(DEG2RAD(degrees));
+ zrot[0][1] = sin(DEG2RAD(degrees));
+ zrot[1][0] = -sin(DEG2RAD(degrees));
+ zrot[1][1] = cos(DEG2RAD(degrees));
- R_ConcatRotations( m, zrot, tmpmat );
- R_ConcatRotations( tmpmat, im, rot );
+ R_ConcatRotations(m, zrot, tmpmat);
+ R_ConcatRotations(tmpmat, im, rot);
- for ( i = 0; i < 3; i++ )
- {
+ for (i = 0; i < 3; i++) {
dst[i] = rot[i][0] * point[0] + rot[i][1] * point[1] + rot[i][2] * point[2];
}
}
-void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal )
+void ProjectPointOnPlane(vec3_t dst, const vec3_t p, const vec3_t normal)
{
float d;
vec3_t n;
float inv_denom;
- inv_denom = 1.0F / DotProduct( normal, normal );
+ inv_denom = 1.0F / DotProduct(normal, normal);
- d = DotProduct( normal, p ) * inv_denom;
+ d = DotProduct(normal, p) * inv_denom;
n[0] = normal[0] * inv_denom;
n[1] = normal[1] * inv_denom;
@@ -601,7 +587,7 @@ void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal )
/*
** assumes "src" is normalized
*/
-void PerpendicularVector( vec3_t dst, const vec3_t src )
+void PerpendicularVector(vec3_t dst, const vec3_t src)
{
int pos;
int i;
@@ -611,12 +597,10 @@ void PerpendicularVector( vec3_t dst, const vec3_t src )
/*
** find the smallest magnitude axially aligned vector
*/
- for ( pos = 0, i = 0; i < 3; i++ )
- {
- if ( fabs( src[i] ) < minelem )
- {
+ for (pos = 0, i = 0; i < 3; i++) {
+ if (fabs(src[i]) < minelem) {
pos = i;
- minelem = fabs( src[i] );
+ minelem = fabs(src[i]);
}
}
tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
@@ -625,11 +609,11 @@ void PerpendicularVector( vec3_t dst, const vec3_t src )
/*
** project the point onto the plane defined by src
*/
- ProjectPointOnPlane( dst, tempvec, src );
+ ProjectPointOnPlane(dst, tempvec, src);
/*
** normalize the result
*/
- VectorNormalize( dst );
+ VectorNormalize(dst);
}