shithub: qk1

Download patch

ref: f636a9deaf4598ff7e48209b1a4b1f04f294a00a
parent: 4044c72c4298721bfb6a6121e9ff1e2b74a5ea85
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Nov 1 18:13:25 EDT 2023

remove a bunch of crap out of the renderer

--- a/d_edge.c
+++ b/d_edge.c
@@ -163,157 +163,139 @@
 	VectorCopy (transformed_modelorg, world_transformed_modelorg);
 
 // TODO: could preset a lot of this at mode set time
-	if (r_drawflat.value)
+	for (s = &surfaces[1] ; s<surface_p ; s++)
 	{
-		for (s = &surfaces[1] ; s<surface_p ; s++)
-		{
-			if (!s->spans)
-				continue;
+		if (!s->spans)
+			continue;
 
-			d_zistepu = s->d_zistepu;
-			d_zistepv = s->d_zistepv;
-			d_ziorigin = s->d_ziorigin;
+		if((surfdrawflags(s->flags) | entdrawflags(s->entity)) ^ r_drawflags)
+			continue;
+		alpha = 255;
+		if(enthasalpha(s->entity) && s->entity->alpha != 255)
+			alpha = s->entity->alpha;
+		else if(s->flags & SURF_TRANS)
+			alpha *= alphafor(s->flags);
+		if(alpha < 1)
+			alpha = 255;
 
-			D_DrawSolidSurface (s, (uintptr)s->data & 0xFF);
+		r_drawnpolycount++;
+
+		d_zistepu = s->d_zistepu;
+		d_zistepv = s->d_zistepv;
+		d_ziorigin = s->d_ziorigin;
+
+		if (s->flags & SURF_DRAWSKY)
+		{
+			D_DrawSkyScans8 (s->spans);
 			D_DrawZSpans (s->spans);
 		}
-	}
-	else
-	{
-		for (s = &surfaces[1] ; s<surface_p ; s++)
+		else if (s->flags & SURF_DRAWBACKGROUND)
 		{
-			if (!s->spans)
-				continue;
+		// set up a gradient for the background surface that places it
+		// effectively at infinity distance from the viewpoint
+			d_zistepu = 0;
+			d_zistepv = 0;
+			d_ziorigin = -0.9;
 
-			if((surfdrawflags(s->flags) | entdrawflags(s->entity)) ^ r_drawflags)
-				continue;
-			alpha = 255;
-			if(enthasalpha(s->entity) && s->entity->alpha != 255)
-				alpha = s->entity->alpha;
-			else if(s->flags & SURF_TRANS)
-				alpha *= alphafor(s->flags);
-			if(alpha < 1)
-				alpha = 255;
+			D_DrawSolidSurface (s, (int)r_clearcolor.value & 0xFF);
+			D_DrawZSpans (s->spans);
+		}
+		else if (s->flags & SURF_DRAWTURB)
+		{
+			pface = s->data;
+			miplevel = 0;
+			cacheblock = (pixel_t *)
+					((byte *)pface->texinfo->texture +
+					pface->texinfo->texture->offsets[0]);
+			cachewidth = 64;
 
-			r_drawnpolycount++;
+			if (s->insubmodel)
+			{
+			// FIXME: we don't want to do all this for every polygon!
+			// TODO: store once at start of frame
+				currententity = s->entity;	//FIXME: make this passed in to
+											// R_RotateBmodel ()
+				VectorSubtract (r_origin, currententity->origin,
+						local_modelorg);
+				TransformVector (local_modelorg, transformed_modelorg);
 
-			d_zistepu = s->d_zistepu;
-			d_zistepv = s->d_zistepv;
-			d_ziorigin = s->d_ziorigin;
+				R_RotateBmodel ();	// FIXME: don't mess with the frustum,
+									// make entity passed in
+			}
 
-			if (s->flags & SURF_DRAWSKY)
+			D_CalcGradients (pface);
+			Turbulent8 (s->spans, alpha);
+			D_DrawZSpans (s->spans);
+
+			if (s->insubmodel)
 			{
-				D_DrawSkyScans8 (s->spans);
-				D_DrawZSpans (s->spans);
+			//
+			// restore the old drawing state
+			// FIXME: we don't want to do this every time!
+			// TODO: speed up
+			//
+				currententity = &cl_entities[0];
+				VectorCopy (world_transformed_modelorg,
+							transformed_modelorg);
+				VectorCopy (base_vpn, vpn);
+				VectorCopy (base_vup, vup);
+				VectorCopy (base_vright, vright);
+				VectorCopy (base_modelorg, modelorg);
+				R_TransformFrustum ();
 			}
-			else if (s->flags & SURF_DRAWBACKGROUND)
+		}
+		else
+		{
+			if (s->insubmodel)
 			{
-			// set up a gradient for the background surface that places it
-			// effectively at infinity distance from the viewpoint
-				d_zistepu = 0;
-				d_zistepv = 0;
-				d_ziorigin = -0.9;
+			// FIXME: we don't want to do all this for every polygon!
+			// TODO: store once at start of frame
+				currententity = s->entity;	//FIXME: make this passed in to
+											// R_RotateBmodel ()
+				VectorSubtract (r_origin, currententity->origin, local_modelorg);
+				TransformVector (local_modelorg, transformed_modelorg);
 
-				D_DrawSolidSurface (s, (int)r_clearcolor.value & 0xFF);
-				D_DrawZSpans (s->spans);
+				R_RotateBmodel ();	// FIXME: don't mess with the frustum,
+									// make entity passed in
 			}
-			else if (s->flags & SURF_DRAWTURB)
-			{
-				pface = s->data;
+
+			pface = s->data;
+			if(s->flags & SURF_FENCE)
 				miplevel = 0;
-				cacheblock = (pixel_t *)
-						((byte *)pface->texinfo->texture +
-						pface->texinfo->texture->offsets[0]);
-				cachewidth = 64;
+			else
+				miplevel = D_MipLevelForScale (s->nearzi * scale_for_mip
+				* pface->texinfo->mipadjust);
 
-				if (s->insubmodel)
-				{
-				// FIXME: we don't want to do all this for every polygon!
-				// TODO: store once at start of frame
-					currententity = s->entity;	//FIXME: make this passed in to
-												// R_RotateBmodel ()
-					VectorSubtract (r_origin, currententity->origin,
-							local_modelorg);
-					TransformVector (local_modelorg, transformed_modelorg);
+		// FIXME: make this passed in to D_CacheSurface
+			pcurrentcache = D_CacheSurface (pface, miplevel);
 
-					R_RotateBmodel ();	// FIXME: don't mess with the frustum,
-										// make entity passed in
-				}
+			cacheblock = (pixel_t *)pcurrentcache->data;
+			cachewidth = pcurrentcache->width;
 
-				D_CalcGradients (pface);
-				Turbulent8 (s->spans, alpha);
-				D_DrawZSpans (s->spans);
+			D_CalcGradients (pface);
 
-				if (s->insubmodel)
-				{
-				//
-				// restore the old drawing state
-				// FIXME: we don't want to do this every time!
-				// TODO: speed up
-				//
-					currententity = &cl_entities[0];
-					VectorCopy (world_transformed_modelorg,
-								transformed_modelorg);
-					VectorCopy (base_vpn, vpn);
-					VectorCopy (base_vup, vup);
-					VectorCopy (base_vright, vright);
-					VectorCopy (base_modelorg, modelorg);
-					R_TransformFrustum ();
-				}
+			if(s->flags & SURF_FENCE)
+				D_DrawSpans16_Fence(s->spans, alpha);
+			else{
+				(*d_drawspans) (s->spans, alpha);
+				D_DrawZSpans (s->spans);
 			}
-			else
-			{
-				if (s->insubmodel)
-				{
-				// FIXME: we don't want to do all this for every polygon!
-				// TODO: store once at start of frame
-					currententity = s->entity;	//FIXME: make this passed in to
-												// R_RotateBmodel ()
-					VectorSubtract (r_origin, currententity->origin, local_modelorg);
-					TransformVector (local_modelorg, transformed_modelorg);
 
-					R_RotateBmodel ();	// FIXME: don't mess with the frustum,
-										// make entity passed in
-				}
-
-				pface = s->data;
-				if(s->flags & SURF_FENCE)
-					miplevel = 0;
-				else
-					miplevel = D_MipLevelForScale (s->nearzi * scale_for_mip
-					* pface->texinfo->mipadjust);
-
-			// FIXME: make this passed in to D_CacheSurface
-				pcurrentcache = D_CacheSurface (pface, miplevel);
-
-				cacheblock = (pixel_t *)pcurrentcache->data;
-				cachewidth = pcurrentcache->width;
-
-				D_CalcGradients (pface);
-
-				if(s->flags & SURF_FENCE)
-					D_DrawSpans16_Fence(s->spans, alpha);
-				else{
-					(*d_drawspans) (s->spans, alpha);
-					D_DrawZSpans (s->spans);
-				}
-
-				if (s->insubmodel)
-				{
-				//
-				// restore the old drawing state
-				// FIXME: we don't want to do this every time!
-				// TODO: speed up
-				//
-					currententity = &cl_entities[0];
-					VectorCopy (world_transformed_modelorg,
-								transformed_modelorg);
-					VectorCopy (base_vpn, vpn);
-					VectorCopy (base_vup, vup);
-					VectorCopy (base_vright, vright);
-					VectorCopy (base_modelorg, modelorg);
-					R_TransformFrustum ();
-				}
+			if (s->insubmodel)
+			{
+			//
+			// restore the old drawing state
+			// FIXME: we don't want to do this every time!
+			// TODO: speed up
+			//
+				currententity = &cl_entities[0];
+				VectorCopy (world_transformed_modelorg,
+							transformed_modelorg);
+				VectorCopy (base_vpn, vpn);
+				VectorCopy (base_vup, vup);
+				VectorCopy (base_vright, vright);
+				VectorCopy (base_modelorg, modelorg);
+				R_TransformFrustum ();
 			}
 		}
 	}
--- a/fns.h
+++ b/fns.h
@@ -52,8 +52,6 @@
 void*	emalloc(ulong);
 vlong	flen(int);
 double	dtime(void);
-void	fppsgl(void);
-void	fppdbl(void);
 void	shutdown(void);
 uvlong	nanosec(void);
 
--- a/qk1.c
+++ b/qk1.c
@@ -54,16 +54,6 @@
 }
 
 void
-fppdbl(void)
-{
-}
-
-void
-fppsgl(void)
-{
-}
-
-void
 shutdown(void)
 {
 	stopfb();
--- a/r_edge.c
+++ b/r_edge.c
@@ -45,10 +45,8 @@
 float	fv;
 
 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);
 
 //=============================================================================
@@ -118,19 +116,10 @@
 	surfaces[1].spans = nil;	// no background spans yet
 	surfaces[1].flags = SURF_DRAWBACKGROUND;
 
-// put the background behind everything in the world
-	if (r_draworder.value)
-	{
-		pdrawfunc = R_GenerateSpansBackward;
-		surfaces[1].key = 0;
-		r_currentkey = 1;
-	}
-	else
-	{
-		pdrawfunc = R_GenerateSpans;
-		surfaces[1].key = 0x7FFFFFFF;
-		r_currentkey = 0;
-	}
+	// put the background behind everything in the world
+	pdrawfunc = R_GenerateSpans;
+	surfaces[1].key = 0x7FFFFFFF;
+	r_currentkey = 0;
 
 	v = r_refdef.vrect.y;
 	n = r_refdef.vrectbottom - v;
@@ -578,35 +567,6 @@
 		}
 
 		R_LeadingEdge (edge);
-	}
-
-	R_CleanupSpan ();
-}
-
-
-/*
-==============
-R_GenerateSpansBackward
-==============
-*/
-void R_GenerateSpansBackward (void)
-{
-	edge_t			*edge;
-
-	r_bmodelactive = 0;
-
-// 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)
-	{			
-		if (edge->surfs[0])
-			R_TrailingEdge (&surfaces[edge->surfs[0]], edge);
-
-		if (edge->surfs[1])
-			R_LeadingEdgeBackwards (edge);
 	}
 
 	R_CleanupSpan ();
--- a/r_local.h
+++ b/r_local.h
@@ -42,17 +42,10 @@
 
 //===========================================================================
 
-extern cvar_t	r_draworder;
-extern cvar_t	r_speeds;
-extern cvar_t	r_timegraph;
-extern cvar_t	r_graphheight;
 extern cvar_t	r_clearcolor;
 extern cvar_t	r_waterwarp;
 extern cvar_t	r_fullbright;
 extern cvar_t	r_drawentities;
-extern cvar_t	r_aliasstats;
-extern cvar_t	r_dspeeds;
-extern cvar_t	r_drawflat;
 extern cvar_t	r_ambient;
 extern cvar_t	r_reportsurfout;
 extern cvar_t	r_numsurfs;
@@ -257,9 +250,6 @@
 
 void R_AliasClipTriangle (mtriangle_t *ptri);
 
-extern float	r_time1;
-extern float	dp_time1, dp_time2, db_time1, db_time2, rw_time1, rw_time2;
-extern float	se_time1, se_time2, de_time1, de_time2, dv_time1, dv_time2;
 extern int		r_frustum_indexes[4*6];
 extern int		r_maxsurfsseen, r_maxedgesseen, r_cnumsurfs;
 extern qboolean	r_surfsonstack;
@@ -274,10 +264,6 @@
 extern int		r_dlightframecount;
 
 void R_StoreEfrags (efrag_t **ppefrag);
-void R_TimeGraph (void);
-void R_PrintAliasStats (void);
-void R_PrintTimes (void);
-void R_PrintDSpeeds (void);
 void R_AnimateLight (void);
 int R_LightPoint (vec3_t p);
 void R_SetupFrame (void);
--- a/r_main.c
+++ b/r_main.c
@@ -97,18 +97,11 @@
 
 void R_MarkLeaves (void);
 
-cvar_t	r_draworder = {"r_draworder","0"};
-cvar_t	r_speeds = {"r_speeds","0"};
-cvar_t	r_timegraph = {"r_timegraph","0"};
-cvar_t	r_graphheight = {"r_graphheight","10"};
 cvar_t	r_clearcolor = {"r_clearcolor","2"};
 cvar_t	r_waterwarp = {"r_waterwarp","1"};
 cvar_t	r_fullbright = {"r_fullbright","0"};
 cvar_t	r_drawentities = {"r_drawentities","1"};
 cvar_t	r_drawviewmodel = {"r_drawviewmodel","1"};
-cvar_t	r_aliasstats = {"r_polymodelstats","0"};
-cvar_t	r_dspeeds = {"r_dspeeds","0"};
-cvar_t	r_drawflat = {"r_drawflat", "0"};
 cvar_t	r_ambient = {"r_ambient", "0"};
 cvar_t	r_reportsurfout = {"r_reportsurfout", "0"};
 cvar_t	r_numsurfs = {"r_numsurfs", "0"};
@@ -182,11 +175,6 @@
 	Cmd_AddCommand("pointfile", loadpoints);
 	Cmd_AddCommand("fog", fog);
 
-	Cvar_RegisterVariable (&r_draworder);
-	Cvar_RegisterVariable (&r_speeds);
-	Cvar_RegisterVariable (&r_timegraph);
-	Cvar_RegisterVariable (&r_graphheight);
-	Cvar_RegisterVariable (&r_drawflat);
 	Cvar_RegisterVariable (&r_ambient);
 	Cvar_RegisterVariable (&r_clearcolor);
 	Cvar_RegisterVariable (&r_waterwarp);
@@ -193,8 +181,6 @@
 	Cvar_RegisterVariable (&r_fullbright);
 	Cvar_RegisterVariable (&r_drawentities);
 	Cvar_RegisterVariable (&r_drawviewmodel);
-	Cvar_RegisterVariable (&r_aliasstats);
-	Cvar_RegisterVariable (&r_dspeeds);
 	Cvar_RegisterVariable (&r_reportsurfout);
 	Cvar_RegisterVariable (&r_numsurfs);
 	Cvar_RegisterVariable (&r_reportedgeout);
@@ -445,88 +431,204 @@
 	}
 }
 
+static int
+R_BmodelCheckBBox(model_t *clmodel, float *minmaxs)
+{
+	int			i, *pindex, clipflags;
+	vec3_t		acceptpt, rejectpt;
+	double		d;
 
-/*
-=============
-R_DrawEntitiesOnList
-=============
-*/
-void R_DrawEntitiesOnList (void)
+	clipflags = 0;
+
+	if (currententity->angles[0] || currententity->angles[1]
+		|| currententity->angles[2])
+	{
+		for (i=0 ; i<4 ; i++)
+		{
+			d = DotProduct (currententity->origin, view_clipplanes[i].normal);
+			d -= view_clipplanes[i].dist;
+
+			if (d <= -clmodel->radius)
+				return BMODEL_FULLY_CLIPPED;
+
+			if (d <= clmodel->radius)
+				clipflags |= (1<<i);
+		}
+	}
+	else
+	{
+		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 -= 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]];
+
+			d = DotProduct (acceptpt, view_clipplanes[i].normal);
+			d -= view_clipplanes[i].dist;
+
+			if (d <= 0)
+				clipflags |= (1<<i);
+		}
+	}
+
+	return clipflags;
+}
+
+static int
+R_DrawEntity(entity_t *e)
 {
-	int			i, j;
-	int			lnum;
+	int			j, k, clipflags;
 	alight_t	lighting;
-// FIXME: remove and do real lighting
-	float		lightvec[3] = {-1, 0, 0};
-	vec3_t		dist;
+	float		lightvec[3] = {-1, 0, 0}; // FIXME: remove and do real lighting
+	float		minmaxs[6];
+	vec3_t		dist, oldorigin;
 	float		add;
+	model_t		*clmodel;
 
-	if (!r_drawentities.value)
-		return;
+	if(!r_drawentities.value || e == &cl_entities[cl.viewentity])
+		return 1;
+	if((entdrawflags(e) ^ r_drawflags) != 0)
+		return 0;
 
-	for (i=0 ; i<cl_numvisedicts ; i++)
-	{
-		currententity = cl_visedicts[i];
+	currententity = e;
 
-		if (currententity == &cl_entities[cl.viewentity])
-			continue;	// don't draw the player
+	switch(e->model->type){
+	case mod_sprite:
+		VectorCopy(e->origin, r_entorigin);
+		VectorSubtract(r_origin, r_entorigin, modelorg);
+		R_DrawSprite();
+		break;
 
-		// FIXME(sigrid): no trans-specific surfaces, hopefully?
-		if(entdrawflags(currententity) ^ r_drawflags)
-			continue;
+	case mod_alias:
+		VectorCopy(e->origin, r_entorigin);
+		VectorSubtract(r_origin, r_entorigin, modelorg);
 
-		switch (currententity->model->type)
-		{
-		case mod_sprite:
-			VectorCopy (currententity->origin, r_entorigin);
-			VectorSubtract (r_origin, r_entorigin, modelorg);
-			R_DrawSprite ();
+		// see if the bounding box lets us trivially reject, also sets
+		// trivial accept status
+		if(!R_AliasCheckBBox())
 			break;
 
-		case mod_alias:
-			VectorCopy (currententity->origin, r_entorigin);
-			VectorSubtract (r_origin, r_entorigin, modelorg);
+		j = R_LightPoint(currententity->origin);
+		lighting.ambientlight = j;
+		lighting.shadelight = j;
+		lighting.plightvec = lightvec;
 
+		add = 0;
+		for(k = 0; k < MAX_DLIGHTS; k++){
+			if(cl_dlights[k].die < cl.time || cl_dlights[k].radius == 0)
+				continue;
+			VectorSubtract(e->origin, cl_dlights[k].origin, dist);
+			add += cl_dlights[k].radius - Length(dist);
+			if(add > 0)
+				lighting.ambientlight += add;
+		}
+
+		// clamp lighting so it doesn't overbright as much
+		if(lighting.ambientlight > 128)
+			lighting.ambientlight = 128;
+		if(lighting.ambientlight + lighting.shadelight > 192)
+			lighting.shadelight = 192 - lighting.ambientlight;
+
+		R_AliasDrawModel(&lighting);
+		break;
+
+	case mod_brush:
+		VectorCopy(modelorg, oldorigin);
+		insubmodel = true;
+		r_dlightframecount = r_framecount;
+		clmodel = e->model;
+
 		// see if the bounding box lets us trivially reject, also sets
 		// trivial accept status
-			if (R_AliasCheckBBox ())
-			{
-				j = R_LightPoint (currententity->origin);
-	
-				lighting.ambientlight = j;
-				lighting.shadelight = j;
+		for(j = 0; j < 3; j++){
+			minmaxs[j] = currententity->origin[j] + clmodel->mins[j];
+			minmaxs[3+j] = currententity->origin[j] + clmodel->maxs[j];
+		}
 
-				lighting.plightvec = lightvec;
+		clipflags = R_BmodelCheckBBox(clmodel, minmaxs);
+		if(clipflags == BMODEL_FULLY_CLIPPED)
+			break;
 
-				for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++)
-				{
-					if (cl_dlights[lnum].die >= cl.time)
-					{
-						VectorSubtract (currententity->origin,
-										cl_dlights[lnum].origin,
-										dist);
-						add = cl_dlights[lnum].radius - Length(dist);
-	
-						if (add > 0)
-							lighting.ambientlight += add;
-					}
-				}
+		VectorCopy(e->origin, r_entorigin);
+		VectorSubtract(r_origin, r_entorigin, modelorg);
+		r_pcurrentvertbase = clmodel->vertexes;
+		R_RotateBmodel(); // FIXME: stop transforming twice
 
-			// clamp lighting so it doesn't overbright as much
-				if (lighting.ambientlight > 128)
-					lighting.ambientlight = 128;
-				if (lighting.ambientlight + lighting.shadelight > 192)
-					lighting.shadelight = 192 - lighting.ambientlight;
+		// calculate dynamic lighting for bmodel if it's not an
+		// instanced model
+		if(clmodel->firstmodelsurface != 0){
+			for(k = 0; k < MAX_DLIGHTS; k++){
+				if(cl_dlights[k].die < cl.time || cl_dlights[k].radius == 0)
+					continue;
+				R_MarkLights(&cl_dlights[k], 1<<k, clmodel->nodes + clmodel->hulls[0].firstclipnode);
+			}
+		}
 
-				R_AliasDrawModel (&lighting);
+		// if the driver wants polygons, deliver those. Z-buffering is on
+		// at this point, so no clipping to the world tree is needed, just
+		// frustum clipping
+		if(r_drawpolys || r_drawculledpolys){
+			R_ZDrawSubmodelPolys(clmodel);
+		}else{
+			r_pefragtopnode = nil;
+
+			for(j = 0; j < 3; j++){
+				r_emins[j] = minmaxs[j];
+				r_emaxs[j] = minmaxs[3+j];
 			}
 
-			break;
+			R_SplitEntityOnNode2(cl.worldmodel->nodes);
 
-		default:
-			break;
+			if(r_pefragtopnode){
+				e->topnode = r_pefragtopnode;
+
+				if(r_drawflags & DRAW_BLEND)
+					R_BeginEdgeFrame();
+				if(r_pefragtopnode->contents >= 0){
+					// not a leaf; has to be clipped to the world BSP
+					r_clipflags = clipflags;
+					R_DrawSolidClippedSubmodelPolygons(clmodel);
+				}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(clmodel, clipflags);
+				}
+				if(r_drawflags & DRAW_BLEND)
+					R_ScanEdges();
+
+				e->topnode = nil;
+			}
 		}
+
+		// 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(base_modelorg, modelorg);
+		VectorCopy(oldorigin, modelorg);
+		R_TransformFrustum();
+		break;
 	}
+
+	return 1;
 }
 
 /*
@@ -574,12 +676,8 @@
 	for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++)
 	{
 		dl = &cl_dlights[lnum];
-		if (!dl->radius)
+		if(dl->die < cl.time || !dl->radius)
 			continue;
-		if (!dl->radius)
-			continue;
-		if (dl->die < cl.time)
-			continue;
 
 		VectorSubtract (currententity->origin, dl->origin, dist);
 		add = dl->radius - Length(dist);
@@ -598,246 +696,24 @@
 	R_AliasDrawModel (&r_viewlighting);
 }
 
-
 /*
-=============
-R_BmodelCheckBBox
-=============
-*/
-int R_BmodelCheckBBox (model_t *clmodel, float *minmaxs)
-{
-	int			i, *pindex, clipflags;
-	vec3_t		acceptpt, rejectpt;
-	double		d;
-
-	clipflags = 0;
-
-	if (currententity->angles[0] || currententity->angles[1]
-		|| currententity->angles[2])
-	{
-		for (i=0 ; i<4 ; i++)
-		{
-			d = DotProduct (currententity->origin, view_clipplanes[i].normal);
-			d -= view_clipplanes[i].dist;
-
-			if (d <= -clmodel->radius)
-				return BMODEL_FULLY_CLIPPED;
-
-			if (d <= clmodel->radius)
-				clipflags |= (1<<i);
-		}
-	}
-	else
-	{
-		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 -= 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]];
-
-			d = DotProduct (acceptpt, view_clipplanes[i].normal);
-			d -= view_clipplanes[i].dist;
-
-			if (d <= 0)
-				clipflags |= (1<<i);
-		}
-	}
-
-	return clipflags;
-}
-
-
-/*
-=============
-R_DrawBEntitiesOnList
-=============
-*/
-void R_DrawBEntitiesOnList (void)
-{
-	int			i, j, k, clipflags;
-	vec3_t		oldorigin;
-	model_t		*clmodel;
-	float		minmaxs[6];
-
-	if (!r_drawentities.value)
-		return;
-
-	VectorCopy (modelorg, oldorigin);
-	insubmodel = true;
-	r_dlightframecount = r_framecount;
-
-	for (i=0 ; i<cl_numvisedicts ; i++)
-	{
-		currententity = cl_visedicts[i];
-
-		if(entdrawflags(currententity) ^ r_drawflags)
-			continue;
-
-		switch (currententity->model->type)
-		{
-		case mod_brush:
-
-			clmodel = currententity->model;
-
-		// see if the bounding box lets us trivially reject, also sets
-		// trivial accept status
-			for (j=0 ; j<3 ; j++)
-			{
-				minmaxs[j] = currententity->origin[j] +
-						clmodel->mins[j];
-				minmaxs[3+j] = currententity->origin[j] +
-						clmodel->maxs[j];
-			}
-
-			clipflags = R_BmodelCheckBBox (clmodel, minmaxs);
-
-			if (clipflags != BMODEL_FULLY_CLIPPED)
-			{
-				VectorCopy (currententity->origin, r_entorigin);
-				VectorSubtract (r_origin, r_entorigin, modelorg);
-			// FIXME: is this needed?
-				VectorCopy (modelorg, r_worldmodelorg);
-		
-				r_pcurrentvertbase = clmodel->vertexes;
-		
-			// FIXME: stop transforming twice
-				R_RotateBmodel ();
-
-			// calculate dynamic lighting for bmodel if it's not an
-			// instanced model
-				if (clmodel->firstmodelsurface != 0)
-				{
-					for (k=0 ; k<MAX_DLIGHTS ; k++)
-					{
-						if ((cl_dlights[k].die < cl.time) ||
-							(!cl_dlights[k].radius))
-						{
-							continue;
-						}
-
-						R_MarkLights (&cl_dlights[k], 1<<k,
-							clmodel->nodes + clmodel->hulls[0].firstclipnode);
-					}
-				}
-
-			// if the driver wants polygons, deliver those. Z-buffering is on
-			// at this point, so no clipping to the world tree is needed, just
-			// frustum clipping
-				if (r_drawpolys | r_drawculledpolys)
-				{
-					R_ZDrawSubmodelPolys (clmodel);
-				}
-				else
-				{
-					r_pefragtopnode = nil;
-
-					for (j=0 ; j<3 ; j++)
-					{
-						r_emins[j] = minmaxs[j];
-						r_emaxs[j] = minmaxs[3+j];
-					}
-
-					R_SplitEntityOnNode2 (cl.worldmodel->nodes);
-
-					if (r_pefragtopnode)
-					{
-						if(r_drawflags & DRAW_BLEND)
-							R_BeginEdgeFrame();
-						currententity->topnode = r_pefragtopnode;
-	
-						if (r_pefragtopnode->contents >= 0)
-						{
-						// not a leaf; has to be clipped to the world BSP
-							r_clipflags = clipflags;
-							R_DrawSolidClippedSubmodelPolygons (clmodel);
-						}
-						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 (clmodel, clipflags);
-						}
-	
-						currententity->topnode = nil;
-						if(r_drawflags & DRAW_BLEND)
-							R_ScanEdges();
-					}
-				}
-
-			// 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 (base_modelorg, modelorg);
-				VectorCopy (oldorigin, modelorg);
-				R_TransformFrustum ();
-			}
-
-			break;
-
-		default:
-			break;
-		}
-	}
-
-	insubmodel = false;
-}
-
-
-/*
-================
+================
 R_EdgeDrawing
 ================
 */
 void R_EdgeDrawing (void)
 {
-	R_BeginEdgeFrame ();
+	int i;
 
-	if (r_dspeeds.value)
-	{
-		rw_time1 = dtime ();
+	R_BeginEdgeFrame();
+	R_RenderWorld();
+	if((r_drawflags & DRAW_BLEND) == 0){
+		for(i = 0; i < cl_numvisedicts; i++){
+			if(cl_visedicts[i]->model->type == mod_brush)
+				R_DrawEntity(cl_visedicts[i]);
+		}
 	}
-
-	R_RenderWorld ();
-
-	if (r_drawculledpolys)
-		R_ScanEdges ();
-
-	if (r_dspeeds.value)
-	{
-		rw_time2 = dtime ();
-		db_time1 = rw_time2;
-	}
-
-	if((r_drawflags & DRAW_BLEND) == 0)
-		R_DrawBEntitiesOnList ();
-
-	if (r_dspeeds.value)
-	{
-		db_time2 = dtime ();
-		se_time1 = db_time2;
-	}
-	
-	if (!(r_drawpolys | r_drawculledpolys))
-		R_ScanEdges ();
+	R_ScanEdges();
 }
 
 /*
@@ -849,13 +725,11 @@
 */
 void R_RenderView (void)
 {
+	int i;
 	static byte	warpbuffer[WARP_WIDTH * WARP_HEIGHT];
 
 	r_warpbuffer = warpbuffer;
 
-	if (r_timegraph.value || r_speeds.value || r_dspeeds.value)
-		r_time1 = dtime ();
-
 	R_SetupFrame ();
 
 #ifdef PASSAGES
@@ -865,75 +739,36 @@
 	R_MarkLeaves ();	// done here so we know if we're in water
 #endif
 
-// make FDIV fast. This reduces timing precision after we've been running for a
-// while, so we don't do it globally.  This also sets chop mode, and we do it
-// here so that setup stuff like the refresh area calculations match what's
-// done in screen.c
-	fppsgl ();
-
 	if (!cl_entities[0].model || !cl.worldmodel)
 		fatal ("R_RenderView: NULL worldmodel");
 	R_EdgeDrawing ();
 
-	if (r_dspeeds.value)
-	{
-		se_time2 = dtime ();
-		de_time1 = se_time2;
+	for(i = 0; i < cl_numvisedicts; i++){
+		if(cl_visedicts[i]->model->type != mod_brush)
+			R_DrawEntity(cl_visedicts[i]);
 	}
 
-	R_DrawEntitiesOnList ();
-
-	if (r_dspeeds.value)
-	{
-		de_time2 = dtime ();
-		dv_time1 = de_time2;
-	}
-
 	R_DrawViewModel ();
 
-	if (r_dspeeds.value)
-	{
-		dv_time2 = dtime ();
-		dp_time1 = dtime ();
-	}
-
 	R_DrawParticles ();
 
 	r_drawflags = DRAW_BLEND;
 	r_worldpolysbacktofront = true;
-	R_EdgeDrawing ();
-	R_DrawBEntitiesOnList();
-	R_DrawEntitiesOnList ();
+	R_EdgeDrawing();
+	for(i = 0; i < cl_numvisedicts; i++)
+		R_DrawEntity(cl_visedicts[i]);
 	r_drawflags = 0;
 
-	if (r_dspeeds.value)
-		dp_time2 = dtime ();
-
 	if (r_dowarp)
 		D_WarpScreen ();
 
 	V_SetContentsColor (r_viewleaf->contents);
 
-	if (r_timegraph.value)
-		R_TimeGraph ();
-
-	if (r_aliasstats.value)
-		R_PrintAliasStats ();
-		
-	if (r_speeds.value)
-		R_PrintTimes ();
-
-	if (r_dspeeds.value)
-		R_PrintDSpeeds ();
-
 	if (r_reportsurfout.value && r_outofsurfaces)
 		Con_Printf ("Short %d surfaces\n", r_outofsurfaces);
 
 	if (r_reportedgeout.value && r_outofedges)
 		Con_Printf ("Short roughly %d edges\n", r_outofedges * 2 / 3);
-
-// back to high floating-point precision
-	fppdbl ();
 }
 
 /*
--- a/r_misc.c
+++ b/r_misc.c
@@ -20,147 +20,6 @@
 	}
 }
 
-/*
-================
-R_LineGraph
-
-Only called by R_DisplayTime
-================
-*/
-void R_LineGraph (int x, int y, int h)
-{
-	int		i;
-	byte	*dest;
-	int		s;
-
-// FIXME: should be disabled on no-buffer adapters, or should be in the driver
-	
-	x += r_refdef.vrect.x;
-	y += r_refdef.vrect.y;
-	
-	dest = vid.buffer + vid.rowbytes*y + x;
-	
-	s = r_graphheight.value;
-	
-	if (h>s)
-		h = s;
-		
-	for (i=0 ; i<h ; i++, dest -= vid.rowbytes*2)
-	{
-		dest[0] = 0xff;
-		*(dest-vid.rowbytes) = 0x30;
-	}
-	for ( ; i<s ; i++, dest -= vid.rowbytes*2)
-	{
-		dest[0] = 0x30;
-		*(dest-vid.rowbytes) = 0x30;
-	}
-}
-
-/*
-==============
-R_TimeGraph
-
-Performance monitoring tool
-==============
-*/
-#define	MAX_TIMINGS		100
-extern float mouse_x, mouse_y;
-void R_TimeGraph (void)
-{
-	static	int		timex;
-	int		a;
-	float	r_time2;
-	static byte	r_timings[MAX_TIMINGS];
-	int		x;
-	
-	r_time2 = dtime ();
-
-	a = (r_time2-r_time1)/0.01;
-//a = fabs(mouse_y * 0.05);
-//a = (int)((r_refdef.vieworg[2] + 1024)/1)%(int)r_graphheight.value;
-//a = fabs(velocity[0])/20;
-//a = ((int)fabs(origin[0])/8)%20;
-//a = (cl.idealpitch + 30)/5;
-	r_timings[timex] = a;
-	a = timex;
-
-	if (r_refdef.vrect.width <= MAX_TIMINGS)
-		x = r_refdef.vrect.width-1;
-	else
-		x = r_refdef.vrect.width -
-				(r_refdef.vrect.width - MAX_TIMINGS)/2;
-	do
-	{
-		R_LineGraph (x, r_refdef.vrect.height-2, r_timings[a]);
-		if (x==0)
-			break;		// screen too small to hold entire thing
-		x--;
-		a--;
-		if (a == -1)
-			a = MAX_TIMINGS-1;
-	} while (a != timex);
-
-	timex = (timex+1)%MAX_TIMINGS;
-}
-
-
-/*
-=============
-R_PrintTimes
-=============
-*/
-void R_PrintTimes (void)
-{
-	float	r_time2;
-	float		ms;
-
-	r_time2 = dtime ();
-
-	ms = 1000* (r_time2 - r_time1);
-	
-	Con_Printf ("%5.1f ms %3d/%3d/%3d poly %3d surf\n",
-				ms, c_faceclip, r_polycount, r_drawnpolycount, c_surf);
-	c_surf = 0;
-}
-
-
-/*
-=============
-R_PrintDSpeeds
-=============
-*/
-void R_PrintDSpeeds (void)
-{
-	float	ms, dp_time, r_time2, rw_time, db_time, se_time, de_time, dv_time;
-
-	r_time2 = dtime ();
-
-	dp_time = (dp_time2 - dp_time1) * 1000;
-	rw_time = (rw_time2 - rw_time1) * 1000;
-	db_time = (db_time2 - db_time1) * 1000;
-	se_time = (se_time2 - se_time1) * 1000;
-	de_time = (de_time2 - de_time1) * 1000;
-	dv_time = (dv_time2 - dv_time1) * 1000;
-	ms = (r_time2 - r_time1) * 1000;
-
-	Con_Printf ("%3d %4.1fp %3dw %4.1fb %3ds %4.1fe %4.1fv\n",
-				(int)ms, dp_time, (int)rw_time, db_time, (int)se_time, de_time,
-				dv_time);
-}
-
-
-/*
-=============
-R_PrintAliasStats
-=============
-*/
-void R_PrintAliasStats (void)
-{
-	Con_Printf ("%3d polygon model drawn\n", r_amodels_drawn);
-}
-
-
 void WarpPalette (void)
 {
 	int		i,j;
@@ -288,10 +147,8 @@
 // don't allow cheats in multiplayer
 	if (cl.maxclients > 1)
 	{
-		setcvar ("r_draworder", "0");
 		setcvar ("r_fullbright", "0");
 		setcvar ("r_ambient", "0");
-		setcvar ("r_drawflat", "0");
 	}
 
 	if (r_numsurfs.value)
@@ -319,9 +176,6 @@
 	if (r_refdef.ambientlight < 0)
 		r_refdef.ambientlight = 0;
 
-	if (!sv.active)
-		r_draworder.value = 0;	// don't let cheaters look behind walls
-		
 	R_CheckVariables ();
 	
 	R_AnimateLight ();