summaryrefslogtreecommitdiff
path: root/src/sw_bsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw_bsp.c')
-rw-r--r--src/sw_bsp.c292
1 files changed, 133 insertions, 159 deletions
diff --git a/src/sw_bsp.c b/src/sw_bsp.c
index 05d1189..9e55361 100644
--- a/src/sw_bsp.c
+++ b/src/sw_bsp.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.
@@ -27,16 +27,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
qboolean insubmodel;
entity_t *currententity;
vec3_t modelorg; // modelorg is the viewpoint reletive to
- // the currently rendering entity
+// the currently rendering entity
vec3_t r_entorigin; // the currently rendering entity in world
- // coordinates
+// coordinates
float entity_rotation[3][3];
int r_currentbkey;
-typedef enum {touchessolid, drawnode, nodrawnode} solidstate_t;
-
#define MAX_BMODEL_VERTS 500 // 6K
#define MAX_BMODEL_EDGES 1000 // 12K
@@ -56,14 +54,14 @@ static qboolean makeclippededge;
R_EntityRotate
================
*/
-void R_EntityRotate (vec3_t vec)
+void R_EntityRotate(vec3_t vec)
{
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);
}
@@ -72,7 +70,7 @@ 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];
@@ -82,8 +80,8 @@ void R_RotateBmodel (void)
// TODO: share work with R_SetUpAliasTransform
// yaw
- angle = currententity->angles[YAW];
- angle = angle * M_PI*2 / 360;
+ angle = currententity->angles[YAW];
+ angle = angle * M_PI * 2 / 360;
s = sin(angle);
c = cos(angle);
@@ -99,8 +97,8 @@ void R_RotateBmodel (void)
// pitch
- angle = currententity->angles[PITCH];
- angle = angle * M_PI*2 / 360;
+ angle = currententity->angles[PITCH];
+ angle = angle * M_PI * 2 / 360;
s = sin(angle);
c = cos(angle);
@@ -114,11 +112,11 @@ void R_RotateBmodel (void)
temp2[2][1] = 0;
temp2[2][2] = c;
- R_ConcatRotations (temp2, temp1, temp3);
+ R_ConcatRotations(temp2, temp1, temp3);
// roll
- angle = currententity->angles[ROLL];
- angle = angle * M_PI*2 / 360;
+ angle = currententity->angles[ROLL];
+ angle = angle * M_PI * 2 / 360;
s = sin(angle);
c = cos(angle);
@@ -132,17 +130,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 (modelorg);
- R_EntityRotate (vpn);
- R_EntityRotate (vright);
- R_EntityRotate (vup);
+ R_EntityRotate(modelorg);
+ R_EntityRotate(vpn);
+ R_EntityRotate(vright);
+ R_EntityRotate(vup);
- R_TransformFrustum ();
+ R_TransformFrustum();
}
@@ -153,7 +151,7 @@ R_RecursiveClipBPoly
Clip a bmodel poly down the world bsp tree
================
*/
-void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
+void R_RecursiveClipBPoly(bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
{
bedge_t *psideedges[2], *pnextedge, *ptedge;
int i, side, lastside;
@@ -171,19 +169,18 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
// FIXME: cache these?
splitplane = pnode->plane;
tplane.dist = -PlaneDiff(r_entorigin, splitplane);
- 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.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 = PlaneDiff (plastvert->point, &tplane);
+ lastdist = PlaneDiff(plastvert->point, &tplane);
if (lastdist > 0)
lastside = 0;
@@ -191,37 +188,35 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
lastside = 1;
pvert = pedges->v[1];
- dist = PlaneDiff (pvert->point, &tplane);
+ dist = PlaneDiff(pvert->point, &tplane);
if (dist > 0)
side = 0;
else
side = 1;
- if (side != lastside)
- {
- // clipped
+ if (side != lastside) {
+ // clipped
if (numbverts >= MAX_BMODEL_VERTS)
return;
- // generate the clipped vertex
+ // generate the clipped vertex
frac = lastdist / (lastdist - dist);
ptvert = &pbverts[numbverts++];
ptvert->point[0] = plastvert->point[0] +
- frac * (pvert->point[0] -
- plastvert->point[0]);
+ frac * (pvert->point[0] -
+ plastvert->point[0]);
ptvert->point[1] = plastvert->point[1] +
- frac * (pvert->point[1] -
- plastvert->point[1]);
+ frac * (pvert->point[1] -
+ plastvert->point[1]);
ptvert->point[2] = plastvert->point[2] +
- frac * (pvert->point[2] -
- plastvert->point[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))
- {
+ frac * (pvert->point[2] -
+ plastvert->point[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)) {
Com_Printf("Out of edges for bmodel\n");
return;
}
@@ -240,21 +235,16 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
numbedges += 2;
- if (side == 0)
- {
- // entering for front, exiting for back
+ if (side == 0) {
+ // entering for front, exiting for back
pfrontenter = ptvert;
makeclippededge = qtrue;
- }
- else
- {
+ } else {
pfrontexit = ptvert;
makeclippededge = qtrue;
}
- }
- else
- {
- // add the edge to the appropriate side
+ } else {
+ // add the edge to the appropriate side
pedges->pnext = psideedges[side];
psideedges[side] = pedges;
}
@@ -262,11 +252,9 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
// if anything was clipped, reconstitute and add the edges along the clip
// plane to both sides (but in opposite directions)
- if (makeclippededge)
- {
- if (numbedges >= (MAX_BMODEL_EDGES - 2))
- {
- Com_Error( ERR_DROP, "Out of edges for bmodel" );
+ if (makeclippededge) {
+ if (numbedges >= (MAX_BMODEL_EDGES - 2)) {
+ Com_Error(ERR_DROP, "Out of edges for bmodel");
}
ptedge = &pbedges[numbedges];
@@ -285,37 +273,29 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, mface_t *psurf)
}
// draw or recurse further
- for (i=0 ; i<2 ; 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
+ for (i = 0; i < 2; 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
pn = pnode->children[i];
- // we're done with this branch if the node or leaf isn't in the PVS
- if (pn->visframe == r_visframecount)
- {
- if (!pn->plane)
- {
- mleaf_t *pl = ( mleaf_t * )pn;
- if (pl->contents != CONTENTS_SOLID)
- {
- if (r_newrefdef.areabits)
- {
+ // we're done with this branch if the node or leaf isn't in the PVS
+ if (pn->visframe == r_visframecount) {
+ if (!pn->plane) {
+ mleaf_t *pl = (mleaf_t *)pn;
+ if (pl->contents != CONTENTS_SOLID) {
+ if (r_newrefdef.areabits) {
area = pl->area;
- if (!Q_IsBitSet(r_newrefdef.areabits, area) )
+ if (!Q_IsBitSet(r_newrefdef.areabits, area))
continue; // not visible
}
r_currentbkey = pl->key;
- R_RenderBmodelFace (psideedges[i], psurf);
+ R_RenderBmodelFace(psideedges[i], psurf);
}
- }
- else
- {
- R_RecursiveClipBPoly (psideedges[i], pnode->children[i],
- psurf);
+ } else {
+ R_RecursiveClipBPoly(psideedges[i], pnode->children[i],
+ psurf);
}
}
}
@@ -330,7 +310,7 @@ R_DrawSolidClippedSubmodelPolygons
Bmodel crosses multiple leafs
================
*/
-void R_DrawSolidClippedSubmodelPolygons (mmodel_t *pmodel, mnode_t *topnode)
+void R_DrawSolidClippedSubmodelPolygons(mmodel_t *pmodel, mnode_t *topnode)
{
int i, j;
vec_t dot;
@@ -346,24 +326,23 @@ void R_DrawSolidClippedSubmodelPolygons (mmodel_t *pmodel, mnode_t *topnode)
psurf = pmodel->firstface;
numsurfaces = pmodel->numfaces;
- for (i=0 ; i<numsurfaces ; i++, psurf++)
- {
- // find which side of the node we are on
+ for (i = 0; i < numsurfaces; i++, psurf++) {
+ // find which side of the node we are on
pplane = psurf->plane;
- dot = PlaneDiff (modelorg, pplane);
+ dot = PlaneDiff(modelorg, pplane);
- // draw the polygon
- if (( !(psurf->drawflags & DSURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
+ // draw the polygon
+ if ((!(psurf->drawflags & DSURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
((psurf->drawflags & DSURF_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;
@@ -371,19 +350,18 @@ void R_DrawSolidClippedSubmodelPolygons (mmodel_t *pmodel, mnode_t *topnode)
numbedges += psurf->numsurfedges;
surfedge = psurf->firstsurfedge;
- for (j=0 ; j<psurf->numsurfedges ; j++, surfedge++)
- {
+ for (j = 0; j < psurf->numsurfedges; j++, surfedge++) {
pbedge[j].v[0] = surfedge->edge->v[surfedge->vert ];
pbedge[j].v[1] = surfedge->edge->v[surfedge->vert ^ 1];
- 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->c.flags & ( SURF_TRANS66 | SURF_TRANS33 ) ) )
- R_RecursiveClipBPoly (pbedge, topnode, psurf);
+ if (!(psurf->texinfo->c.flags & (SURF_TRANS66 | SURF_TRANS33)))
+ R_RecursiveClipBPoly(pbedge, topnode, psurf);
else
- R_RenderBmodelFace( pbedge, psurf );
+ R_RenderBmodelFace(pbedge, psurf);
}
}
@@ -395,7 +373,7 @@ R_DrawSubmodelPolygons
All in one leaf
================
*/
-void R_DrawSubmodelPolygons (mmodel_t *pmodel, int clipflags, mnode_t *topnode)
+void R_DrawSubmodelPolygons(mmodel_t *pmodel, int clipflags, mnode_t *topnode)
{
int i;
vec_t dot;
@@ -408,21 +386,19 @@ void R_DrawSubmodelPolygons (mmodel_t *pmodel, int clipflags, mnode_t *topnode)
psurf = pmodel->firstface;
numsurfaces = pmodel->numfaces;
- for (i=0 ; i<numsurfaces ; i++, psurf++)
- {
- // find which side of the node we are on
+ for (i = 0; i < numsurfaces; i++, psurf++) {
+ // find which side of the node we are on
pplane = psurf->plane;
- dot = PlaneDiff (modelorg, pplane);
+ dot = PlaneDiff(modelorg, pplane);
- // draw the polygon
+ // draw the polygon
if (((psurf->drawflags & DSURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
- (!(psurf->drawflags & DSURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
- {
+ (!(psurf->drawflags & DSURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
r_currentkey = ((mleaf_t *)topnode)->key;
- // FIXME: use bounding-box-based frustum clipping info?
- R_RenderFace (psurf, clipflags);
+ // FIXME: use bounding-box-based frustum clipping info?
+ R_RenderFace(psurf, clipflags);
}
}
}
@@ -435,7 +411,8 @@ int c_drawnode;
R_RecursiveWorldNode
================
*/
-void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
+void R_RecursiveWorldNode(mnode_t *node, int clipflags)
+{
int i, c, side, *pindex;
vec3_t acceptpt, rejectpt;
cplane_t *plane;
@@ -443,42 +420,42 @@ void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
float d, dot;
mleaf_t *pleaf;
- while( node->visframe == r_visframecount) {
- // 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
+ while (node->visframe == r_visframecount) {
+ // 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) {
- for (i=0 ; i<4 ; i++) {
- if (! (clipflags & (1<<i)) )
+ for (i = 0; i < 4; i++) {
+ if (!(clipflags & (1 << i)))
continue; // don't need to clip against it
- // 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 = pfrustum_indexes[i];
rejectpt[0] = (float)node->minmaxs[pindex[0]];
rejectpt[1] = (float)node->minmaxs[pindex[1]];
rejectpt[2] = (float)node->minmaxs[pindex[2]];
-
+
d = PlaneDiff(rejectpt, &view_clipplanes[i]);
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 = PlaneDiff (acceptpt, &view_clipplanes[i]);
+ d = PlaneDiff(acceptpt, &view_clipplanes[i]);
if (d >= 0)
- clipflags &= ~(1<<i); // node is entirely on screen
+ clipflags &= ~(1 << i); // node is entirely on screen
}
}
c_drawnode++;
- // if a leaf node, draw stuff
+ // if a leaf node, draw stuff
if (!node->plane) {
pleaf = (mleaf_t *)node;
@@ -487,15 +464,14 @@ void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
// check for door connected areas
if (r_newrefdef.areabits) {
- if (! Q_IsBitSet(r_newrefdef.areabits, pleaf->area ) )
+ if (! Q_IsBitSet(r_newrefdef.areabits, pleaf->area))
return; // not visible
}
mark = pleaf->firstleafface;
c = pleaf->numleaffaces;
if (c) {
- do
- {
+ do {
(*mark)->drawframe = r_framecount;
mark++;
} while (--c);
@@ -505,51 +481,49 @@ void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
r_currentkey++; // all bmodels in a leaf share the same key
return;
}
- // 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;
- dot = PlaneDiffFast( modelorg, plane );
-
+ dot = PlaneDiffFast(modelorg, plane);
+
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->numfaces;
if (c) {
surf = node->firstface;
if (dot < -BACKFACE_EPSILON) {
do {
if ((surf->drawflags & DSURF_PLANEBACK) &&
- (surf->drawframe == r_framecount))
- {
- R_RenderFace (surf, clipflags);
+ (surf->drawframe == r_framecount)) {
+ R_RenderFace(surf, clipflags);
}
surf++;
} while (--c);
} else if (dot > BACKFACE_EPSILON) {
do {
if (!(surf->drawflags & DSURF_PLANEBACK) &&
- (surf->drawframe == r_framecount))
- {
- R_RenderFace (surf, clipflags);
+ (surf->drawframe == r_framecount)) {
+ R_RenderFace(surf, clipflags);
}
surf++;
} 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
- node = node->children[side^1];
+ // recurse down the back side
+ node = node->children[side ^ 1];
}
}
@@ -560,23 +534,23 @@ void R_RecursiveWorldNode (mnode_t *node, int clipflags) {
R_RenderWorld
================
*/
-void R_RenderWorld (void)
+void R_RenderWorld(void)
{
if (!r_drawworld->integer)
return;
- if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
+ if (r_newrefdef.rdflags & RDF_NOWORLDMODEL)
return;
- c_drawnode=0;
+ c_drawnode = 0;
// auto cycle the world frame for texture animation
- r_worldentity.frame = (int)(r_newrefdef.time*2);
+ r_worldentity.frame = (int)(r_newrefdef.time * 2);
currententity = &r_worldentity;
- VectorCopy (r_origin, modelorg);
+ VectorCopy(r_origin, modelorg);
- R_RecursiveWorldNode (r_worldmodel->nodes, 15);
+ R_RecursiveWorldNode(r_worldmodel->nodes, 15);
}