summaryrefslogtreecommitdiff
path: root/src/sw_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw_main.c')
-rw-r--r--src/sw_main.c632
1 files changed, 301 insertions, 331 deletions
diff --git a/src/sw_main.c b/src/sw_main.c
index 7b9f01e..59390f6 100644
--- a/src/sw_main.c
+++ b/src/sw_main.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.
@@ -87,7 +87,7 @@ int r_drawnpolycount;
int r_wholepolycount;
int *pfrustum_indexes[4];
-int r_frustum_indexes[4*6];
+int r_frustum_indexes[4 * 6];
mleaf_t *r_viewleaf;
int r_viewcluster, r_oldviewcluster;
@@ -95,7 +95,7 @@ int r_viewcluster, r_oldviewcluster;
float da_time1, da_time2, dp_time1, dp_time2, db_time1, db_time2, rw_time1, rw_time2;
float se_time1, se_time2, de_time1, de_time2;
-void R_MarkLeaves (void);
+void R_MarkLeaves(void);
cvar_t *sw_aliasstats;
cvar_t *sw_allow_modex;
@@ -162,74 +162,74 @@ unsigned int d_zwidth;
#endif // !USE_ASM
-int sintable[CYCLE*2];
-int intsintable[CYCLE*2];
-int blanktable[CYCLE*2]; // PGM
+int sintable[CYCLE * 2];
+int intsintable[CYCLE * 2];
+int blanktable[CYCLE * 2]; // PGM
/*
================
R_InitTurb
================
*/
-void R_InitTurb (void)
+void R_InitTurb(void)
{
int i;
-
- for (i=0 ; i<CYCLE*2 ; i++)
- {
- sintable[i] = AMP + sin(i*M_PI*2/CYCLE)*AMP;
- intsintable[i] = AMP2 + sin(i*M_PI*2/CYCLE)*AMP2; // AMP2, not 20
+
+ for (i = 0; i < CYCLE * 2; i++) {
+ sintable[i] = AMP + sin(i * M_PI * 2 / CYCLE) * AMP;
+ intsintable[i] = AMP2 + sin(i * M_PI * 2 / CYCLE) * AMP2; // AMP2, not 20
blanktable[i] = 0; //PGM
}
}
-void D_SCDump_f (void);
+void D_SCDump_f(void);
-void R_Register (void)
+void R_Register(void)
{
- sw_aliasstats = Cvar_Get ("sw_polymodelstats", "0", 0);
- sw_allow_modex = Cvar_Get( "sw_allow_modex", "1", CVAR_ARCHIVE );
- sw_clearcolor = Cvar_Get ("sw_clearcolor", "2", 0);
- sw_drawflat = Cvar_Get ("sw_drawflat", "0", CVAR_CHEAT);
- sw_draworder = Cvar_Get ("sw_draworder", "0", CVAR_CHEAT);
- sw_maxedges = Cvar_Get ("sw_maxedges", va( "%i", NUMSTACKEDGES ), 0);
- sw_maxsurfs = Cvar_Get ("sw_maxsurfs", va( "%i", NUMSTACKSURFACES ), 0);
- sw_mipcap = Cvar_Get ("sw_mipcap", "0", 0);
- sw_mipscale = Cvar_Get ("sw_mipscale", "1", 0);
- sw_reportedgeout = Cvar_Get ("sw_reportedgeout", "0", 0);
- sw_reportsurfout = Cvar_Get ("sw_reportsurfout", "0", 0);
- sw_stipplealpha = Cvar_Get( "sw_stipplealpha", "0", CVAR_ARCHIVE );
- sw_waterwarp = Cvar_Get ("sw_waterwarp", "1", 0);
+ sw_aliasstats = Cvar_Get("sw_polymodelstats", "0", 0);
+ sw_allow_modex = Cvar_Get("sw_allow_modex", "1", CVAR_ARCHIVE);
+ sw_clearcolor = Cvar_Get("sw_clearcolor", "2", 0);
+ sw_drawflat = Cvar_Get("sw_drawflat", "0", CVAR_CHEAT);
+ sw_draworder = Cvar_Get("sw_draworder", "0", CVAR_CHEAT);
+ sw_maxedges = Cvar_Get("sw_maxedges", va("%i", NUMSTACKEDGES), 0);
+ sw_maxsurfs = Cvar_Get("sw_maxsurfs", va("%i", NUMSTACKSURFACES), 0);
+ sw_mipcap = Cvar_Get("sw_mipcap", "0", 0);
+ sw_mipscale = Cvar_Get("sw_mipscale", "1", 0);
+ sw_reportedgeout = Cvar_Get("sw_reportedgeout", "0", 0);
+ sw_reportsurfout = Cvar_Get("sw_reportsurfout", "0", 0);
+ sw_stipplealpha = Cvar_Get("sw_stipplealpha", "0", CVAR_ARCHIVE);
+ sw_waterwarp = Cvar_Get("sw_waterwarp", "1", 0);
//Start Added by Lewey
- sw_drawsird = Cvar_Get ("sw_drawsird", "0", 0);
+ sw_drawsird = Cvar_Get("sw_drawsird", "0", 0);
//End Added by Lewey
- r_speeds = Cvar_Get ("r_speeds", "0", 0);
- r_fullbright = Cvar_Get ("r_fullbright", "0", CVAR_CHEAT);
- r_drawentities = Cvar_Get ("r_drawentities", "1", 0);
- r_drawworld = Cvar_Get ("r_drawworld", "1", CVAR_CHEAT);
- r_dspeeds = Cvar_Get ("r_dspeeds", "0", 0);
- r_lerpmodels = Cvar_Get( "r_lerpmodels", "1", 0 );
- r_novis = Cvar_Get( "r_novis", "0", 0 );
+ r_speeds = Cvar_Get("r_speeds", "0", 0);
+ r_fullbright = Cvar_Get("r_fullbright", "0", CVAR_CHEAT);
+ r_drawentities = Cvar_Get("r_drawentities", "1", 0);
+ r_drawworld = Cvar_Get("r_drawworld", "1", CVAR_CHEAT);
+ r_dspeeds = Cvar_Get("r_dspeeds", "0", 0);
+ r_lerpmodels = Cvar_Get("r_lerpmodels", "1", 0);
+ r_novis = Cvar_Get("r_novis", "0", 0);
- vid_gamma = Cvar_Get( "vid_gamma", "1.0", CVAR_ARCHIVE );
+ vid_gamma = Cvar_Get("vid_gamma", "1.0", CVAR_ARCHIVE);
- Cmd_AddCommand( "scdump", D_SCDump_f );
+ Cmd_AddCommand("scdump", D_SCDump_f);
//PGM
- sw_lockpvs = Cvar_Get ("sw_lockpvs", "0", 0);
+ sw_lockpvs = Cvar_Get("sw_lockpvs", "0", 0);
//PGM
}
-void R_UnRegister (void)
+void R_UnRegister(void)
{
- Cmd_RemoveCommand( "screenshot" );
- Cmd_RemoveCommand( "scdump" );
+ Cmd_RemoveCommand("screenshot");
+ Cmd_RemoveCommand("scdump");
}
-void R_ModeChanged( int width, int height, int flags, int rowbytes, void *pixels ) {
+void R_ModeChanged(int width, int height, int flags, int rowbytes, void *pixels)
+{
vid.width = width > MAXWIDTH ? MAXWIDTH : width;
vid.height = height > MAXHEIGHT ? MAXHEIGHT : height;
vid.buffer = pixels;
@@ -239,26 +239,26 @@ void R_ModeChanged( int width, int height, int flags, int rowbytes, void *pixels
r_config.height = vid.height;
r_config.flags = flags;
- sw_surfcacheoverride = Cvar_Get ("sw_surfcacheoverride", "0", 0);
+ sw_surfcacheoverride = Cvar_Get("sw_surfcacheoverride", "0", 0);
D_FlushCaches();
- if( d_pzbuffer ) {
- Z_Free( d_pzbuffer );
+ if (d_pzbuffer) {
+ Z_Free(d_pzbuffer);
d_pzbuffer = NULL;
}
// free surface cache
- if( sc_base ) {
- Z_Free( sc_base );
+ if (sc_base) {
+ Z_Free(sc_base);
sc_base = NULL;
}
- d_pzbuffer = R_Mallocz( vid.width * vid.height * 2 );
+ d_pzbuffer = R_Mallocz(vid.width * vid.height * 2);
R_InitCaches();
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
}
/*
@@ -266,27 +266,28 @@ void R_ModeChanged( int width, int height, int flags, int rowbytes, void *pixels
R_Init
===============
*/
-qboolean R_Init( qboolean total ) {
- Com_DPrintf( "R_Init( %i )\n", total );
+qboolean R_Init(qboolean total)
+{
+ Com_DPrintf("R_Init( %i )\n", total);
- if( !total ) {
+ if (!total) {
R_InitImages();
R_InitDraw();
MOD_Init();
return qtrue;
}
- Com_Printf( "ref_soft " VERSION ", " __DATE__ "\n" );
+ Com_Printf("ref_soft " VERSION ", " __DATE__ "\n");
// TODO: collect 386-specific code in one place
#if USE_ASM
- Sys_MakeCodeWriteable( ( long )R_EdgeCodeStart, ( long )R_EdgeCodeEnd - ( long )R_EdgeCodeStart );
+ Sys_MakeCodeWriteable((long)R_EdgeCodeStart, (long)R_EdgeCodeEnd - (long)R_EdgeCodeStart);
#endif // USE_ASM
r_aliasuvscale = 1.0;
// create the window
- if( !VID_Init() ) {
+ if (!VID_Init()) {
return qfalse;
}
@@ -303,18 +304,18 @@ qboolean R_Init( qboolean total ) {
view_clipplanes[0].leftedge = qtrue;
view_clipplanes[1].rightedge = qtrue;
view_clipplanes[1].leftedge =
- view_clipplanes[2].leftedge =
- view_clipplanes[3].leftedge = qfalse;
+ view_clipplanes[2].leftedge =
+ view_clipplanes[3].leftedge = qfalse;
view_clipplanes[0].rightedge =
- view_clipplanes[2].rightedge =
- view_clipplanes[3].rightedge = qfalse;
+ view_clipplanes[2].rightedge =
+ view_clipplanes[3].rightedge = qfalse;
r_refdef.xOrigin = XCENTERING;
r_refdef.yOrigin = YCENTERING;
R_InitTurb();
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
vid_gamma->modified = qfalse;
return qtrue;
@@ -325,8 +326,9 @@ qboolean R_Init( qboolean total ) {
R_Shutdown
===============
*/
-void R_Shutdown( qboolean total ) {
- Com_DPrintf( "R_Shutdown( %i )\n", total );
+void R_Shutdown(qboolean total)
+{
+ Com_DPrintf("R_Shutdown( %i )\n", total);
D_FlushCaches();
@@ -335,30 +337,30 @@ void R_Shutdown( qboolean total ) {
R_ShutdownImages();
// free world model
- if( r_worldmodel ) {
- BSP_Free( r_worldmodel );
+ if (r_worldmodel) {
+ BSP_Free(r_worldmodel);
r_worldmodel = NULL;
}
- if( !total ) {
+ if (!total) {
return;
}
// free z buffer
- if( d_pzbuffer ) {
- Z_Free( d_pzbuffer );
+ if (d_pzbuffer) {
+ Z_Free(d_pzbuffer);
d_pzbuffer = NULL;
}
// free surface cache
- if( sc_base ) {
- Z_Free( sc_base );
+ if (sc_base) {
+ Z_Free(sc_base);
sc_base = NULL;
}
// free colormap
- if( vid.colormap ) {
- Z_Free( vid.colormap );
+ if (vid.colormap) {
+ Z_Free(vid.colormap);
vid.colormap = NULL;
}
@@ -374,7 +376,7 @@ void R_Shutdown( qboolean total ) {
R_NewMap
===============
*/
-void R_NewMap (void)
+void R_NewMap(void)
{
r_viewcluster = -1;
@@ -383,19 +385,16 @@ void R_NewMap (void)
if (r_cnumsurfs <= MINSURFACES)
r_cnumsurfs = MINSURFACES;
- if (r_cnumsurfs > NUMSTACKSURFACES)
- {
- surfaces = R_Mallocz (r_cnumsurfs * sizeof(surf_t));
+ if (r_cnumsurfs > NUMSTACKSURFACES) {
+ surfaces = R_Mallocz(r_cnumsurfs * sizeof(surf_t));
surface_p = surfaces;
surf_max = &surfaces[r_cnumsurfs];
r_surfsonstack = qfalse;
- // surface 0 doesn't really exist; it's just a dummy because index 0
- // is used to indicate no edge attached to surface
+ // 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_SurfacePatch();
+ } else {
r_surfsonstack = qtrue;
}
@@ -407,13 +406,10 @@ void R_NewMap (void)
if (r_numallocatededges < MINEDGES)
r_numallocatededges = MINEDGES;
- if (r_numallocatededges <= NUMSTACKEDGES)
- {
+ if (r_numallocatededges <= NUMSTACKEDGES) {
auxedges = NULL;
- }
- else
- {
- auxedges = R_Mallocz (r_numallocatededges * sizeof(edge_t));
+ } else {
+ auxedges = R_Mallocz(r_numallocatededges * sizeof(edge_t));
}
}
@@ -426,7 +422,7 @@ Mark the leaves and nodes that are in the PVS for the current
cluster
===============
*/
-void R_MarkLeaves (void)
+void R_MarkLeaves(void)
{
byte vis[VIS_MAX_BYTES];
mnode_t *node;
@@ -435,11 +431,10 @@ void R_MarkLeaves (void)
int cluster;
if (r_oldviewcluster == r_viewcluster && !r_novis->integer &&
- r_viewcluster != -1)
- {
+ r_viewcluster != -1) {
return;
}
-
+
// development aid to let you run around and see exactly where
// the pvs ends
if (sw_lockpvs->integer)
@@ -448,28 +443,24 @@ void R_MarkLeaves (void)
r_visframecount++;
r_oldviewcluster = r_viewcluster;
- if (r_novis->integer || r_viewcluster == -1 || !r_worldmodel->vis)
- {
+ if (r_novis->integer || r_viewcluster == -1 || !r_worldmodel->vis) {
// mark everything
- for (i=0 ; i<r_worldmodel->numleafs ; i++)
+ for (i = 0; i < r_worldmodel->numleafs; i++)
r_worldmodel->leafs[i].visframe = r_visframecount;
- for (i=0 ; i<r_worldmodel->numnodes ; i++)
+ for (i = 0; i < r_worldmodel->numnodes; i++)
r_worldmodel->nodes[i].visframe = r_visframecount;
return;
}
- BSP_ClusterVis (r_worldmodel, vis, r_viewcluster, DVIS_PVS);
-
- for (i=0,leaf=r_worldmodel->leafs ; i<r_worldmodel->numleafs ; i++, leaf++)
- {
+ BSP_ClusterVis(r_worldmodel, vis, r_viewcluster, DVIS_PVS);
+
+ for (i = 0, leaf = r_worldmodel->leafs; i < r_worldmodel->numleafs; i++, leaf++) {
cluster = leaf->cluster;
if (cluster == -1)
continue;
- if (Q_IsBitSet( vis, cluster ))
- {
+ if (Q_IsBitSet(vis, cluster)) {
node = (mnode_t *)leaf;
- do
- {
+ do {
if (node->visframe == r_visframecount)
break;
node->visframe = r_visframecount;
@@ -485,41 +476,43 @@ void R_MarkLeaves (void)
**
** IMPLEMENT THIS!
*/
-static void R_DrawNullModel( void ) {
+static void R_DrawNullModel(void)
+{
}
-static int R_DrawEntities( int translucent ) {
+static int R_DrawEntities(int translucent)
+{
int i;
qboolean translucent_entities = 0;
// all bmodels have already been drawn by the edge list
- for( i = 0; i < r_newrefdef.num_entities; i++ ){
+ for (i = 0; i < r_newrefdef.num_entities; i++) {
currententity = &r_newrefdef.entities[i];
- if( ( currententity->flags & RF_TRANSLUCENT ) == translucent ) {
+ if ((currententity->flags & RF_TRANSLUCENT) == translucent) {
translucent_entities++;
continue;
}
- if( currententity->flags & RF_BEAM ) {
+ if (currententity->flags & RF_BEAM) {
modelorg[0] = -r_origin[0];
modelorg[1] = -r_origin[1];
modelorg[2] = -r_origin[2];
- VectorCopy( vec3_origin, r_entorigin );
- R_DrawBeam( currententity );
+ VectorCopy(vec3_origin, r_entorigin);
+ R_DrawBeam(currententity);
} else {
- if( currententity->model & 0x80000000 ) {
+ if (currententity->model & 0x80000000) {
continue;
}
- currentmodel = MOD_ForHandle( currententity->model );
- if( !currentmodel ) {
+ currentmodel = MOD_ForHandle(currententity->model);
+ if (!currentmodel) {
R_DrawNullModel();
continue;
}
- VectorCopy (currententity->origin, r_entorigin);
- VectorSubtract (r_origin, r_entorigin, modelorg);
+ VectorCopy(currententity->origin, r_entorigin);
+ VectorSubtract(r_origin, r_entorigin, modelorg);
- switch( currentmodel->type ) {
+ switch (currentmodel->type) {
case MOD_ALIAS:
R_AliasDrawModel();
break;
@@ -529,7 +522,7 @@ static int R_DrawEntities( int translucent ) {
case MOD_EMPTY:
break;
default:
- Com_Error( ERR_FATAL, "%s: bad model type", __func__ );
+ Com_Error(ERR_FATAL, "%s: bad model type", __func__);
}
}
}
@@ -541,15 +534,16 @@ static int R_DrawEntities( int translucent ) {
R_DrawEntitiesOnList
=============
*/
-static void R_DrawEntitiesOnList( void ) {
+static void R_DrawEntitiesOnList(void)
+{
int translucent_entities;
- if( !r_drawentities->integer )
+ if (!r_drawentities->integer)
return;
- translucent_entities = R_DrawEntities( RF_TRANSLUCENT );
- if( translucent_entities ) {
- R_DrawEntities( 0 );
+ translucent_entities = R_DrawEntities(RF_TRANSLUCENT);
+ if (translucent_entities) {
+ R_DrawEntities(0);
}
}
@@ -559,7 +553,7 @@ static void R_DrawEntitiesOnList( void ) {
R_BmodelCheckBBox
=============
*/
-int R_BmodelCheckBBox (float *minmaxs)
+int R_BmodelCheckBBox(float *minmaxs)
{
int i, *pindex, clipflags;
vec3_t acceptpt, rejectpt;
@@ -567,33 +561,32 @@ int R_BmodelCheckBBox (float *minmaxs)
clipflags = 0;
- 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
+ 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
pindex = pfrustum_indexes[i];
rejectpt[0] = minmaxs[pindex[0]];
rejectpt[1] = minmaxs[pindex[1]];
rejectpt[2] = minmaxs[pindex[2]];
-
- d = DotProduct (rejectpt, view_clipplanes[i].normal);
+
+ d = DotProduct(rejectpt, view_clipplanes[i].normal);
d -= view_clipplanes[i].dist;
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, view_clipplanes[i].normal);
+ d = DotProduct(acceptpt, view_clipplanes[i].normal);
d -= view_clipplanes[i].dist;
if (d <= 0)
- clipflags |= (1<<i);
+ clipflags |= (1 << i);
}
return clipflags;
@@ -607,27 +600,27 @@ R_FindTopnode
Find the first node that splits the given box
===================
*/
-mnode_t *R_FindTopnode (vec3_t mins, vec3_t maxs)
+mnode_t *R_FindTopnode(vec3_t mins, vec3_t maxs)
{
int sides;
mnode_t *node;
node = r_worldmodel->nodes;
- while (node->visframe == r_visframecount) {
+ while (node->visframe == r_visframecount) {
if (!node->plane) {
- if (((mleaf_t * )node)->contents != CONTENTS_SOLID)
+ if (((mleaf_t *)node)->contents != CONTENTS_SOLID)
return node; // we've reached a non-solid leaf, so it's
- // visible and not BSP clipped
+ // visible and not BSP clipped
return NULL; // in solid, so not visible
}
-
+
sides = BoxOnPlaneSideFast(mins, maxs, node->plane);
-
+
if (sides == 3)
return node; // this is the splitter
-
- // not split yet; recurse down the contacted side
+
+ // not split yet; recurse down the contacted side
if (sides & 1)
node = node->children[0];
else
@@ -645,52 +638,48 @@ 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;
- if (!angles[0] && !angles[1] && !angles[2])
- {
- VectorCopy (mins, tmins);
- VectorCopy (maxs, tmaxs);
+ if (!angles[0] && !angles[1] && !angles[2]) {
+ 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++ )
- {
- if ( i & 1 )
+ for (i = 0; i < 8; i++) {
+ 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])
tmins[j] = v[j];
if (v[j] > tmaxs[j])
@@ -704,7 +693,7 @@ void RotatedBBox (vec3_t mins, vec3_t maxs, vec3_t angles,
R_DrawBEntitiesOnList
=============
*/
-void R_DrawBEntitiesOnList (void)
+void R_DrawBEntitiesOnList(void)
{
int i, index, clipflags;
vec3_t oldorigin;
@@ -716,72 +705,68 @@ void R_DrawBEntitiesOnList (void)
if (!r_drawentities->value)
return;
- VectorCopy (modelorg, oldorigin);
+ VectorCopy(modelorg, oldorigin);
insubmodel = qtrue;
r_dlightframecount = r_framecount;
- for (i=0 ; i<r_newrefdef.num_entities ; i++)
- {
+ for (i = 0; i < r_newrefdef.num_entities; i++) {
currententity = &r_newrefdef.entities[i];
index = currententity->model;
- if( !( index & 0x80000000 ) ) {
+ if (!(index & 0x80000000)) {
continue;
}
index = ~index;
- if( index < 1 || index >= r_worldmodel->nummodels ) {
- Com_Error( ERR_DROP, "%s: inline model %d out of range",
- __func__, index );
+ if (index < 1 || index >= r_worldmodel->nummodels) {
+ Com_Error(ERR_DROP, "%s: inline model %d out of range",
+ __func__, index);
}
model = &r_worldmodel->models[index];
if (model->numfaces == 0)
continue; // clip brush only
- if ( currententity->flags & RF_BEAM )
+ if (currententity->flags & RF_BEAM)
continue;
- // see if the bounding box lets us trivially reject, also sets
- // trivial accept status
- RotatedBBox (model->mins, model->maxs,
- currententity->angles, mins, maxs);
- VectorAdd (mins, currententity->origin, minmaxs);
- VectorAdd (maxs, currententity->origin, (minmaxs+3));
-
- clipflags = R_BmodelCheckBBox (minmaxs);
+ // see if the bounding box lets us trivially reject, also sets
+ // trivial accept status
+ RotatedBBox(model->mins, model->maxs,
+ currententity->angles, mins, maxs);
+ VectorAdd(mins, currententity->origin, minmaxs);
+ VectorAdd(maxs, currententity->origin, (minmaxs + 3));
+
+ clipflags = R_BmodelCheckBBox(minmaxs);
if (clipflags == BMODEL_FULLY_CLIPPED)
continue; // off the edge of the screen
- topnode = R_FindTopnode (minmaxs, minmaxs+3);
+ topnode = R_FindTopnode(minmaxs, minmaxs + 3);
if (!topnode)
continue; // no part in a visible leaf
- VectorCopy (currententity->origin, r_entorigin);
- VectorSubtract (r_origin, r_entorigin, modelorg);
+ VectorCopy(currententity->origin, r_entorigin);
+ VectorSubtract(r_origin, r_entorigin, modelorg);
- // FIXME: stop transforming twice
- R_RotateBmodel ();
+ // FIXME: stop transforming twice
+ R_RotateBmodel();
- // calculate dynamic lighting for bmodel
- R_PushDlights (model->headnode);
+ // calculate dynamic lighting for bmodel
+ R_PushDlights(model->headnode);
- if (topnode->plane)
- {
- // not a leaf; has to be clipped to the world BSP
+ if (topnode->plane) {
+ // not a leaf; has to be clipped to the world BSP
r_clipflags = clipflags;
- R_DrawSolidClippedSubmodelPolygons (model, 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 (model, clipflags, topnode);
+ R_DrawSolidClippedSubmodelPolygons(model, 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(model, clipflags, topnode);
}
- // put back world rotation and frustum clipping
- // FIXME: R_RotateBmodel should just work off base_vxx
- VectorCopy (base_vpn, vpn);
- VectorCopy (base_vup, vup);
- VectorCopy (base_vright, vright);
- VectorCopy (oldorigin, modelorg);
- R_TransformFrustum ();
+ // put back world rotation and frustum clipping
+ // FIXME: R_RotateBmodel should just work off base_vxx
+ VectorCopy(base_vpn, vpn);
+ VectorCopy(base_vup, vup);
+ VectorCopy(base_vright, vright);
+ VectorCopy(oldorigin, modelorg);
+ R_TransformFrustum();
}
insubmodel = qfalse;
@@ -793,61 +778,54 @@ void R_DrawBEntitiesOnList (void)
R_EdgeDrawing
================
*/
-void R_EdgeDrawing (void)
+void R_EdgeDrawing(void)
{
edge_t ledges[NUMSTACKEDGES +
- ((CACHE_SIZE - 1) / sizeof(edge_t)) + 1];
+ ((CACHE_SIZE - 1) / sizeof(edge_t)) + 1];
surf_t lsurfs[NUMSTACKSURFACES +
- ((CACHE_SIZE - 1) / sizeof(surf_t)) + 1];
+ ((CACHE_SIZE - 1) / sizeof(surf_t)) + 1];
- if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
+ if (r_newrefdef.rdflags & RDF_NOWORLDMODEL)
return;
- if (auxedges)
- {
+ if (auxedges) {
r_edges = auxedges;
- }
- else
- {
- r_edges = (edge_t *)
- (((long)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ } else {
+ r_edges = (edge_t *)
+ (((long)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
}
- if (r_surfsonstack)
- {
- surfaces = (surf_t *)
- (((long)&lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ if (r_surfsonstack) {
+ surfaces = (surf_t *)
+ (((long)&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
+ // 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 ();
+ R_SurfacePatch();
}
- R_BeginEdgeFrame ();
+ R_BeginEdgeFrame();
- if (r_dspeeds->integer)
- {
- rw_time1 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ rw_time1 = Sys_Milliseconds();
}
- R_RenderWorld ();
+ R_RenderWorld();
- if (r_dspeeds->integer)
- {
- rw_time2 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ rw_time2 = Sys_Milliseconds();
db_time1 = rw_time2;
}
- R_DrawBEntitiesOnList ();
+ R_DrawBEntitiesOnList();
- if (r_dspeeds->integer)
- {
- db_time2 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ db_time2 = Sys_Milliseconds();
se_time1 = db_time2;
}
- R_ScanEdges ();
+ R_ScanEdges();
}
//=======================================================================
@@ -859,21 +837,21 @@ R_CalcPalette
=============
*/
-void R_CalcPalette (void)
+void R_CalcPalette(void)
{
static qboolean modified;
- byte palette[256*4], *in, *out;
+ byte palette[256 * 4], *in, *out;
int i;
float alpha, one_minus_alpha;
vec3_t premult;
int r, g, b;
alpha = r_newrefdef.blend[3];
- if( alpha <= 0 ) {
+ if (alpha <= 0) {
if (modified) {
// set back to default
modified = qfalse;
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
}
return;
}
@@ -882,31 +860,32 @@ void R_CalcPalette (void)
if (alpha > 1)
alpha = 1;
- premult[0] = r_newrefdef.blend[0]*alpha*255;
- premult[1] = r_newrefdef.blend[1]*alpha*255;
- premult[2] = r_newrefdef.blend[2]*alpha*255;
+ premult[0] = r_newrefdef.blend[0] * alpha * 255;
+ premult[1] = r_newrefdef.blend[1] * alpha * 255;
+ premult[2] = r_newrefdef.blend[2] * alpha * 255;
one_minus_alpha = (1.0 - alpha);
- in = ( byte * )d_8to24table;
+ in = (byte *)d_8to24table;
out = palette;
- for( i = 0; i < 256; i++, in += 4, out += 4 ) {
+ for (i = 0; i < 256; i++, in += 4, out += 4) {
r = premult[0] + one_minus_alpha * in[0];
g = premult[1] + one_minus_alpha * in[1];
b = premult[2] + one_minus_alpha * in[2];
- if ( r > 255 ) r = 255;
- if ( g > 255 ) g = 255;
- if ( b > 255 ) b = 255;
+ if (r > 255) r = 255;
+ if (g > 255) g = 255;
+ if (b > 255) b = 255;
out[0] = r;
out[1] = g;
out[2] = b;
out[3] = 255;
}
- R_GammaCorrectAndSetPalette( palette );
+ R_GammaCorrectAndSetPalette(palette);
}
-byte *IMG_ReadPixels( byte **palette, int *width, int *height, int *rowbytes ) {
+byte *IMG_ReadPixels(byte **palette, int *width, int *height, int *rowbytes)
+{
*palette = sw_state.currentpalette;
*width = vid.width;
*height = vid.height;
@@ -922,78 +901,73 @@ R_RenderFrame
@@@@@@@@@@@@@@@@
*/
-void R_RenderFrame (refdef_t *fd)
+void R_RenderFrame(refdef_t *fd)
{
r_newrefdef = *fd;
- if (!r_worldmodel && !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) )
- Com_Error (ERR_FATAL,"R_RenderView: NULL worldmodel");
+ if (!r_worldmodel && !(r_newrefdef.rdflags & RDF_NOWORLDMODEL))
+ Com_Error(ERR_FATAL, "R_RenderView: NULL worldmodel");
- VectorCopy (fd->vieworg, r_refdef.vieworg);
- VectorCopy (fd->viewangles, r_refdef.viewangles);
+ VectorCopy(fd->vieworg, r_refdef.vieworg);
+ VectorCopy(fd->viewangles, r_refdef.viewangles);
if (r_speeds->integer || r_dspeeds->integer)
- r_time1 = Sys_Milliseconds ();
+ r_time1 = Sys_Milliseconds();
- R_SetupFrame ();
+ R_SetupFrame();
- R_MarkLeaves (); // done here so we know if we're in water
+ R_MarkLeaves(); // done here so we know if we're in water
- R_PushDlights (r_worldmodel->nodes);
+ R_PushDlights(r_worldmodel->nodes);
- R_EdgeDrawing ();
+ R_EdgeDrawing();
- if (r_dspeeds->integer)
- {
- se_time2 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ se_time2 = Sys_Milliseconds();
de_time1 = se_time2;
}
- R_DrawEntitiesOnList ();
+ R_DrawEntitiesOnList();
- if (r_dspeeds->integer)
- {
- de_time2 = Sys_Milliseconds ();
- dp_time1 = Sys_Milliseconds ();
+ if (r_dspeeds->integer) {
+ de_time2 = Sys_Milliseconds();
+ dp_time1 = Sys_Milliseconds();
}
- R_DrawParticles ();
+ R_DrawParticles();
if (r_dspeeds->integer)
- dp_time2 = Sys_Milliseconds ();
+ dp_time2 = Sys_Milliseconds();
R_DrawAlphaSurfaces();
//Start Replaced by Lewey
- if( sw_drawsird->integer && !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) )
- {
+ if (sw_drawsird->integer && !(r_newrefdef.rdflags & RDF_NOWORLDMODEL)) {
R_ApplySIRDAlgorithum();
- }
- else
- {
+ } else {
//don't do warp if we are doing SIRD because the warp
//would make the SIRD impossible to see.
if (r_dowarp)
- D_WarpScreen ();
+ D_WarpScreen();
}
//End Replaced by Lewey
if (r_dspeeds->integer)
- da_time1 = Sys_Milliseconds ();
+ da_time1 = Sys_Milliseconds();
if (r_dspeeds->integer)
- da_time2 = Sys_Milliseconds ();
+ da_time2 = Sys_Milliseconds();
- R_CalcPalette ();
+ R_CalcPalette();
if (sw_aliasstats->integer)
- R_PrintAliasStats ();
-
+ R_PrintAliasStats();
+
if (r_speeds->integer)
- R_PrintTimes ();
+ R_PrintTimes();
if (r_dspeeds->integer)
- R_PrintDSpeeds ();
+ R_PrintDSpeeds();
if (sw_reportsurfout->integer && r_outofsurfaces)
Com_Printf("Short %d surfaces\n", r_outofsurfaces);
@@ -1005,14 +979,16 @@ void R_RenderFrame (refdef_t *fd)
/*
** R_BeginFrame
*/
-void R_BeginFrame( void ) {
+void R_BeginFrame(void)
+{
VID_BeginFrame();
}
-void R_EndFrame( void ) {
- if( vid_gamma->modified ) {
+void R_EndFrame(void)
+{
+ if (vid_gamma->modified) {
R_BuildGammaTable();
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
vid_gamma->modified = qfalse;
}
@@ -1022,57 +998,53 @@ void R_EndFrame( void ) {
/*
** R_GammaCorrectAndSetPalette
*/
-void R_GammaCorrectAndSetPalette( const byte *palette ) {
+void R_GammaCorrectAndSetPalette(const byte *palette)
+{
int i;
byte *dest;
dest = sw_state.currentpalette;
- for( i = 0; i < 256; i++ ) {
- dest[0] = sw_state.gammatable[ palette[0] ];
- dest[1] = sw_state.gammatable[ palette[1] ];
- dest[2] = sw_state.gammatable[ palette[2] ];
+ for (i = 0; i < 256; i++) {
+ dest[0] = sw_state.gammatable[palette[0]];
+ dest[1] = sw_state.gammatable[palette[1]];
+ dest[2] = sw_state.gammatable[palette[2]];
palette += 4; dest += 4;
}
- VID_UpdatePalette( sw_state.currentpalette );
+ VID_UpdatePalette(sw_state.currentpalette);
}
#if 0
/*
** R_CinematicSetPalette
*/
-void R_CinematicSetPalette( const byte *palette )
+void R_CinematicSetPalette(const byte *palette)
{
byte palette32[1024];
int i, j, w;
int *d;
// clear screen to black to avoid any palette flash
- w = abs(vid.rowbytes)>>2; // stupid negative pitch win32 stuff...
- for (i=0 ; i<vid.height ; i++, d+=w)
- {
- d = (int *)(vid.buffer + i*vid.rowbytes);
- for (j=0 ; j<w ; j++)
+ w = abs(vid.rowbytes) >> 2; // stupid negative pitch win32 stuff...
+ for (i = 0; i < vid.height; i++, d += w) {
+ d = (int *)(vid.buffer + i * vid.rowbytes);
+ for (j = 0; j < w; j++)
d[j] = 0;
}
// flush it to the screen
- R_EndFrame ();
-
- if ( palette )
- {
- for ( i = 0; i < 256; i++ )
- {
- palette32[i*4+0] = palette[i*3+0];
- palette32[i*4+1] = palette[i*3+1];
- palette32[i*4+2] = palette[i*3+2];
- palette32[i*4+3] = 0xFF;
+ R_EndFrame();
+
+ if (palette) {
+ for (i = 0; i < 256; i++) {
+ palette32[i * 4 + 0] = palette[i * 3 + 0];
+ palette32[i * 4 + 1] = palette[i * 3 + 1];
+ palette32[i * 4 + 2] = palette[i * 3 + 2];
+ palette32[i * 4 + 3] = 0xFF;
}
- R_GammaCorrectAndSetPalette( palette32 );
- }
- else
- {
- R_GammaCorrectAndSetPalette( ( const byte * ) d_8to24table );
+ R_GammaCorrectAndSetPalette(palette32);
+ } else {
+ R_GammaCorrectAndSetPalette((const byte *) d_8to24table);
}
}
#endif
@@ -1080,7 +1052,7 @@ void R_CinematicSetPalette( const byte *palette )
/*
** R_DrawBeam
*/
-void R_DrawBeam( entity_t *e )
+void R_DrawBeam(entity_t *e)
{
#define NUM_BEAM_SEGS 6
@@ -1103,28 +1075,26 @@ void R_DrawBeam( entity_t *e )
normalized_direction[1] = direction[1] = oldorigin[1] - origin[1];
normalized_direction[2] = direction[2] = oldorigin[2] - origin[2];
- if ( VectorNormalize( normalized_direction ) == 0 )
+ if (VectorNormalize(normalized_direction) == 0)
return;
- PerpendicularVector( perpvec, normalized_direction );
- VectorScale( perpvec, e->frame / 2, perpvec );
+ PerpendicularVector(perpvec, normalized_direction);
+ VectorScale(perpvec, e->frame / 2, perpvec);
- for ( i = 0; i < NUM_BEAM_SEGS; i++ )
- {
- R_RotatePointAroundVector( start_points[i], normalized_direction,
- perpvec, (360.0/NUM_BEAM_SEGS)*i );
- VectorAdd( start_points[i], origin, start_points[i] );
- VectorAdd( start_points[i], direction, end_points[i] );
+ for (i = 0; i < NUM_BEAM_SEGS; i++) {
+ R_RotatePointAroundVector(start_points[i], normalized_direction,
+ perpvec, (360.0 / NUM_BEAM_SEGS)*i);
+ VectorAdd(start_points[i], origin, start_points[i]);
+ VectorAdd(start_points[i], direction, end_points[i]);
}
- for ( i = 0; i < NUM_BEAM_SEGS; i++ )
- {
- R_IMFlatShadedQuad( start_points[i],
- end_points[i],
- end_points[(i+1)%NUM_BEAM_SEGS],
- start_points[(i+1)%NUM_BEAM_SEGS],
- e->skinnum & 0xFF,
- e->alpha );
+ for (i = 0; i < NUM_BEAM_SEGS; i++) {
+ R_IMFlatShadedQuad(start_points[i],
+ end_points[i],
+ end_points[(i + 1) % NUM_BEAM_SEGS],
+ start_points[(i + 1) % NUM_BEAM_SEGS],
+ e->skinnum & 0xFF,
+ e->alpha);
}
}