📄 r_main.c
字号:
if (!r_drawentities->value)
return;
for (i=0 ; i<cl_numvisedicts ; i++)
{
currententity = cl_visedicts[i];
if (currententity == &cl_entities[cl.viewentity])
// 2000-01-09 ChaseCam fix by FrikaC start
{
if (!chase_active->value)
{
// 2000-01-09 ChaseCam fix by FrikaC end
continue; // don't draw the player
// 2000-01-09 ChaseCam fix by FrikaC start
}
else
{
currententity->angles[0] *= 0.3;
}
}
// 2000-01-09 ChaseCam fix by FrikaC end
switch (currententity->model->type)
{
case mod_sprite:
VectorCopy (currententity->origin, r_entorigin);
VectorSubtract (r_origin, r_entorigin, modelorg);
R_DrawSprite ();
break;
case mod_alias:
VectorCopy (currententity->origin, r_entorigin);
VectorSubtract (r_origin, r_entorigin, modelorg);
// 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;
lighting.plightvec = lightvec;
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;
}
}
// 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;
default:
break;
}
}
}
/*
=============
R_DrawViewModel
=============
*/
void R_DrawViewModel (void)
{
// FIXME: remove and do real lighting
float lightvec[3] = {-1, 0, 0};
int j;
int lnum;
vec3_t dist;
float add;
dlight_t *dl;
if (!r_drawviewmodel->value || r_fov_greater_than_90)
return;
// 2000-01-09 ChaseCam fix by FrikaC start
if (chase_active->value)
{
return;
}
// 2000-01-09 ChaseCam fix by FrikaC end
if (cl.items & IT_INVISIBILITY)
return;
if (cl.stats[STAT_HEALTH] <= 0)
return;
currententity = &cl.viewent;
if (!currententity->model)
return;
VectorCopy (currententity->origin, r_entorigin);
VectorSubtract (r_origin, r_entorigin, modelorg);
VectorCopy (vup, viewlightvec);
VectorInverse (viewlightvec);
j = R_LightPoint (currententity->origin);
if (j < 24)
j = 24; // always give some light on gun
r_viewlighting.ambientlight = j;
r_viewlighting.shadelight = j;
// add dynamic lights
for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++)
{
dl = &cl_dlights[lnum];
if (!dl->radius)
continue;
if (!dl->radius)
continue;
if (dl->die < cl.time)
continue;
VectorSubtract (currententity->origin, dl->origin, dist);
add = dl->radius - Length(dist);
if (add > 0)
r_viewlighting.ambientlight += add;
}
// clamp lighting so it doesn't overbright as much
if (r_viewlighting.ambientlight > 128)
r_viewlighting.ambientlight = 128;
if (r_viewlighting.ambientlight + r_viewlighting.shadelight > 192)
r_viewlighting.shadelight = 192 - r_viewlighting.ambientlight;
r_viewlighting.plightvec = lightvec;
#ifdef QUAKE2
cl.light_level = r_viewlighting.ambientlight;
#endif
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];
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 = NULL;
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)
{
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 = NULL;
}
}
// 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)
{
edge_t ledges[NUMSTACKEDGES +
((CACHE_SIZE - 1) / sizeof(edge_t)) + 1];
surf_t lsurfs[NUMSTACKSURFACES +
((CACHE_SIZE - 1) / sizeof(surf_t)) + 1];
if (auxedges)
{
r_edges = auxedges;
}
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));
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
surfaces--;
R_SurfacePatch ();
}
R_BeginEdgeFrame ();
if (r_dspeeds->value)
{
rw_time1 = Sys_FloatTime ();
}
R_RenderWorld ();
if (r_drawculledpolys)
R_ScanEdges ();
// only the world can be drawn back to front with no z reads or compares, just
// z writes, so have the driver turn z compares on now
D_TurnZOn ();
if (r_dspeeds->value)
{
rw_time2 = Sys_FloatTime ();
db_time1 = rw_time2;
}
R_DrawBEntitiesOnList ();
if (r_dspeeds->value)
{
db_time2 = Sys_FloatTime ();
se_time1 = db_time2;
}
if (!r_dspeeds->value)
{
VID_UnlockBuffer ();
S_ExtraUpdate (); // don't let sound get messed up if going slow
VID_LockBuffer ();
}
if (!(r_drawpolys | r_drawculledpolys))
R_ScanEdges ();
}
/*
================
R_RenderView
r_refdef must be set before the first call
================
*/
void R_RenderView_ (void)
{
byte warpbuffer[WARP_WIDTH * WARP_HEIGHT];
r_warpbuffer = warpbuffer;
if (r_timegraph->value || r_speeds->value || r_dspeeds->value)
r_time1 = Sys_FloatTime ();
R_SetupFrame ();
#ifdef PASSAGES
SetVisibilityByPassages ();
#else
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
Sys_LowFPPrecision ();
if (!cl_entities[0].model || !cl.worldmodel)
Sys_Error ("R_RenderView: NULL worldmodel");
if (!r_dspeeds->value)
{
VID_UnlockBuffer ();
S_ExtraUpdate (); // don't let sound get messed up if going slow
VID_LockBuffer ();
}
R_EdgeDrawing ();
if (!r_dspeeds->value)
{
VID_UnlockBuffer ();
S_ExtraUpdate (); // don't let sound get messed up if going slow
VID_LockBuffer ();
}
if (r_dspeeds->value)
{
se_time2 = Sys_FloatTime ();
de_time1 = se_time2;
}
R_DrawEntitiesOnList ();
if (r_dspeeds->value)
{
de_time2 = Sys_FloatTime ();
dv_time1 = de_time2;
}
R_DrawViewModel ();
if (r_dspeeds->value)
{
dv_time2 = Sys_FloatTime ();
dp_time1 = Sys_FloatTime ();
}
R_DrawParticles ();
if (r_dspeeds->value)
dp_time2 = Sys_FloatTime ();
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
Sys_HighFPPrecision ();
}
void R_RenderView (void)
{
int dummy;
int delta;
delta = (byte *)&dummy - r_stack_start;
if (delta < -10000 || delta > 10000)
Sys_Error ("R_RenderView: called without enough stack");
if ( Hunk_LowMark() & 3 )
Sys_Error ("Hunk is missaligned");
if ( (long)(&dummy) & 3 )
Sys_Error ("Stack is missaligned");
if ( (long)(&r_warpbuffer) & 3 )
Sys_Error ("Globals are missaligned");
R_RenderView_ ();
}
/*
================
R_InitTurb
================
*/
void R_InitTurb (void)
{
int i;
for (i=0 ; i<(SIN_BUFFER_SIZE) ; i++)
{
sintable[i] = AMP + sin(i*3.14159*2/CYCLE)*AMP;
intsintable[i] = AMP2 + sin(i*3.14159*2/CYCLE)*AMP2; // AMP2, not 20
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -