[renderer] Remove currententity

One more global in the trash :)
This commit is contained in:
Bill Currie 2022-03-11 16:39:08 +09:00
parent 64666cfa5b
commit f3768e3dfb
13 changed files with 69 additions and 77 deletions

View file

@ -200,8 +200,8 @@ typedef struct
} drawsurf_t;
extern drawsurf_t r_drawsurf;
void R_DrawSurface (void);
struct transform_s;
void R_DrawSurface (struct transform_s *transform);
void R_GenTile (msurface_t *psurf, void *pdest);
// !!! if this is changed, it must be changed in d_iface.h too !!!

View file

@ -91,7 +91,9 @@ void D_DrawSkyScans (struct espan_s *pspan);
void R_ShowSubDiv (void);
extern void (*prealspandrawer)(void);
surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel);
struct entity_s;
surfcache_t *D_CacheSurface (struct entity_s *ent,
msurface_t *surface, int miplevel);
int D_MipLevelForScale (float scale) __attribute__((pure));

View file

@ -144,9 +144,9 @@ void R_SetFrustum (void);
void R_SpriteBegin (void);
void R_SpriteEnd (void);
void R_DrawSprite (entity_t *ent);
void R_RenderFace (msurface_t *fa, int clipflags);
void R_RenderPoly (msurface_t *fa, int clipflags);
void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf);
void R_RenderFace (entity_t *ent, msurface_t *fa, int clipflags);
void R_RenderPoly (entity_t *ent, msurface_t *fa, int clipflags);
void R_RenderBmodelFace (entity_t *ent, bedge_t *pedges, msurface_t *psurf);
void R_TransformFrustum (void);
void R_SetSkyFrame (void);
void R_DrawSurfaceBlock (void);
@ -154,8 +154,8 @@ texture_t *R_TextureAnimation (const entity_t *entity, msurface_t *surf) __attri
void R_GenSkyTile (void *pdest);
void R_SurfPatch (void);
void R_DrawSubmodelPolygons (model_t *pmodel, int clipflags);
void R_DrawSolidClippedSubmodelPolygons (model_t *pmodel);
void R_DrawSubmodelPolygons (entity_t *ent, model_t *pmodel, int clipflags, struct mnode_s *topnode);
void R_DrawSolidClippedSubmodelPolygons (entity_t *ent, model_t *pmodel, struct mnode_s *topnode);
void R_AddPolygonEdges (emitpoint_t *pverts, int numverts, int miplevel);
surf_t *R_GetSurf (void);
@ -188,7 +188,8 @@ extern void R_Surf8End (void);
extern void R_EdgeCodeStart (void);
extern void R_EdgeCodeEnd (void);
extern void R_RotateBmodel (void);
struct transform_s;
extern void R_RotateBmodel (struct transform_s *transform);
extern int c_faceclip;
extern int r_polycount;
@ -222,7 +223,7 @@ typedef struct btofpoly_s {
extern int numbtofpolys;
void R_InitTurb (void);
void R_ZDrawSubmodelPolys (model_t *clmodel);
void R_ZDrawSubmodelPolys (entity_t *ent, model_t *clmodel);
// Alias models ===========================================

View file

@ -72,7 +72,6 @@ extern byte color_black[4];
extern vec3_t vup, base_vup;
extern vec3_t vpn, base_vpn;
extern vec3_t vright, base_vright;
extern struct entity_s *currententity;
#define NUMSTACKEDGES 2400 //2000
#define MINEDGES NUMSTACKEDGES

View file

@ -210,9 +210,7 @@ R_RecursiveMarkLights (mod_brush_t *brush, const vec3_t lightorigin,
float ndist, maxdist;
plane_t *splitplane;
msurface_t *surf;
//XXX mvertex_t *vertices;
//XXX vertices = r_worldentity.model->vertexes;
maxdist = light->radius;
loc0:

View file

@ -65,14 +65,12 @@ vec3_t modelorg; // modelorg is the viewpoint relative to
vec3_t base_modelorg;
vec3_t r_entorigin; // the currently rendering entity in world
// coordinates
entity_t *currententity;
entity_t r_worldentity;
// view origin
vec3_t vup, base_vup;
vec3_t vpn, base_vpn;
vec3_t vright, base_vright;
vec3_t r_origin;
// screen size info
refdef_t r_refdef;

View file

@ -153,7 +153,6 @@ D_DrawSurfaces (void)
vec3_t world_transformed_modelorg;
vec3_t local_modelorg;
currententity = &r_worldentity;
TransformVector (modelorg, transformed_modelorg);
VectorCopy (transformed_modelorg, world_transformed_modelorg);
@ -207,14 +206,13 @@ D_DrawSurfaces (void)
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 ()
transform_t *transform = s->entity->transform;
transform = s->entity->transform;
VectorSubtract (r_refdef.viewposition,
Transform_GetWorldPosition (currententity->transform),
local_modelorg);
Transform_GetWorldPosition (transform), local_modelorg);
TransformVector (local_modelorg, transformed_modelorg);
R_RotateBmodel (); // FIXME: don't mess with the
R_RotateBmodel (transform); // FIXME: don't mess with the
// frustum, make entity passed in
}
@ -228,7 +226,6 @@ D_DrawSurfaces (void)
// FIXME: we don't want to do this every time!
// TODO: speed up
currententity = &r_worldentity;
VectorCopy (world_transformed_modelorg,
transformed_modelorg);
VectorCopy (base_vpn, vpn);
@ -241,14 +238,12 @@ D_DrawSurfaces (void)
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 ()
transform_t *transform = s->entity->transform;
VectorSubtract (r_refdef.viewposition,
Transform_GetWorldPosition (currententity->transform),
local_modelorg);
Transform_GetWorldPosition (transform), local_modelorg);
TransformVector (local_modelorg, transformed_modelorg);
R_RotateBmodel (); // FIXME: don't mess with the
R_RotateBmodel (transform); // FIXME: don't mess with the
// frustum, make entity passed in
}
@ -257,7 +252,7 @@ D_DrawSurfaces (void)
* pface->texinfo->mipadjust);
// FIXME: make this passed in to D_CacheSurface
pcurrentcache = D_CacheSurface (pface, miplevel);
pcurrentcache = D_CacheSurface (s->entity, pface, miplevel);
cacheblock = (byte *) pcurrentcache->data;
cachewidth = pcurrentcache->width;
@ -280,7 +275,6 @@ D_DrawSurfaces (void)
VectorCopy (base_vright, vright);
VectorCopy (base_modelorg, modelorg);
R_TransformFrustum ();
currententity = &r_worldentity;
}
}
}

View file

@ -226,12 +226,12 @@ D_SCDump (void)
#endif
surfcache_t *
D_CacheSurface (msurface_t *surface, int miplevel)
D_CacheSurface (entity_t *ent, msurface_t *surface, int miplevel)
{
surfcache_t *cache;
// if the surface is animating or flashing, flush the cache
r_drawsurf.texture = R_TextureAnimation (currententity, surface);
r_drawsurf.texture = R_TextureAnimation (ent, surface);
r_drawsurf.lightadj[0] = d_lightstylevalue[surface->styles[0]];
r_drawsurf.lightadj[1] = d_lightstylevalue[surface->styles[1]];
r_drawsurf.lightadj[2] = d_lightstylevalue[surface->styles[2]];
@ -282,7 +282,7 @@ D_CacheSurface (msurface_t *surface, int miplevel)
r_drawsurf.surf = surface;
c_surf++;
R_DrawSurface ();
R_DrawSurface (ent->transform);
return surface->cachespots[miplevel];
}

View file

@ -77,10 +77,10 @@ R_EntityRotate (vec3_t vec)
void
R_RotateBmodel (void)
R_RotateBmodel (transform_t *transform)
{
mat4f_t mat;
Transform_GetWorldMatrix (currententity->transform, mat);
Transform_GetWorldMatrix (transform, mat);
VectorCopy (mat[0], entity_rotation[0]);
VectorCopy (mat[1], entity_rotation[1]);
VectorCopy (mat[2], entity_rotation[2]);
@ -96,7 +96,8 @@ R_RotateBmodel (void)
static void
R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf)
R_RecursiveClipBPoly (entity_t *ent, bedge_t *pedges, mnode_t *pnode,
msurface_t *psurf)
{
bedge_t *psideedges[2], *pnextedge, *ptedge;
int i, side, lastside;
@ -228,11 +229,11 @@ R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf)
if (pn->contents < 0) {
if (pn->contents != CONTENTS_SOLID) {
r_currentbkey = ((mleaf_t *) pn)->key;
R_RenderBmodelFace (psideedges[i], psurf);
R_RenderBmodelFace (ent, psideedges[i], psurf);
}
} else {
R_RecursiveClipBPoly (psideedges[i], pnode->children[i],
psurf);
R_RecursiveClipBPoly (ent, psideedges[i],
pnode->children[i], psurf);
}
}
}
@ -241,7 +242,8 @@ R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf)
void
R_DrawSolidClippedSubmodelPolygons (model_t *model)
R_DrawSolidClippedSubmodelPolygons (entity_t *ent, model_t *model,
mnode_t *topnode)
{
int i, j, lindex;
vec_t dot;
@ -301,8 +303,7 @@ R_DrawSolidClippedSubmodelPolygons (model_t *model)
pbedge[j - 1].pnext = NULL; // mark end of edges
R_RecursiveClipBPoly (pbedge,
currententity->visibility.topnode, psurf);
R_RecursiveClipBPoly (ent, pbedge, topnode, psurf);
} else {
Sys_Error ("no edges in bmodel");
}
@ -312,7 +313,8 @@ R_DrawSolidClippedSubmodelPolygons (model_t *model)
void
R_DrawSubmodelPolygons (model_t *model, int clipflags)
R_DrawSubmodelPolygons (entity_t *ent, model_t *model, int clipflags,
mnode_t *topnode)
{
int i;
vec_t dot;
@ -335,10 +337,10 @@ R_DrawSubmodelPolygons (model_t *model, int clipflags)
// draw the polygon
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
r_currentkey = ((mleaf_t *) currententity->visibility.topnode)->key;
r_currentkey = ((mleaf_t *) topnode)->key;
// FIXME: use bounding-box-based frustum clipping info?
R_RenderFace (psurf, clipflags);
R_RenderFace (ent, psurf, clipflags);
}
}
}
@ -370,6 +372,7 @@ visit_node (mod_brush_t *brush, mnode_t *node, int side, int clipflags)
{
int c;
msurface_t *surf;
entity_t *ent = &r_worldentity;
// sneaky hack for side = side ? SURF_PLANEBACK : 0;
side = (~side + 1) & SURF_PLANEBACK;
@ -392,10 +395,10 @@ visit_node (mod_brush_t *brush, mnode_t *node, int side, int clipflags)
numbtofpolys++;
}
} else {
R_RenderPoly (surf, clipflags);
R_RenderPoly (ent, surf, clipflags);
}
} else {
R_RenderFace (surf, clipflags);
R_RenderFace (ent, surf, clipflags);
}
}
// all surfaces on the same node share the same sequence number
@ -512,11 +515,11 @@ R_RenderWorld (void)
int i;
btofpoly_t btofpolys[MAX_BTOFPOLYS];
mod_brush_t *brush;
entity_t *ent = &r_worldentity;
pbtofpolys = btofpolys;
currententity = &r_worldentity;
brush = &currententity->renderer.model->brush;
brush = &r_worldentity.renderer.model->brush;
r_pcurrentvertbase = brush->vertexes;
R_VisitWorldNodes (brush, 15);
@ -525,7 +528,7 @@ R_RenderWorld (void)
// back in that order
if (r_worldpolysbacktofront) {
for (i = numbtofpolys - 1; i >= 0; i--) {
R_RenderPoly (btofpolys[i].psurf, btofpolys[i].clipflags);
R_RenderPoly (ent, btofpolys[i].psurf, btofpolys[i].clipflags);
}
}
}

View file

@ -344,7 +344,7 @@ R_EmitCachedEdge (void)
void
R_RenderFace (msurface_t *fa, int clipflags)
R_RenderFace (entity_t *ent, msurface_t *fa, int clipflags)
{
int i, lindex;
unsigned int mask;
@ -353,7 +353,7 @@ R_RenderFace (msurface_t *fa, int clipflags)
vec3_t p_normal;
medge_t *pedges, tedge;
clipplane_t *pclip;
mod_brush_t *brush = &currententity->renderer.model->brush;
mod_brush_t *brush = &ent->renderer.model->brush;
// skip out if no more surfs
if ((surface_p) >= surf_max) {
@ -490,7 +490,7 @@ R_RenderFace (msurface_t *fa, int clipflags)
surface_p->flags = fa->flags;
surface_p->insubmodel = insubmodel;
surface_p->spanstate = 0;
surface_p->entity = currententity;
surface_p->entity = ent;
surface_p->key = r_currentkey++;
surface_p->spans = NULL;
@ -510,7 +510,7 @@ R_RenderFace (msurface_t *fa, int clipflags)
void
R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf)
R_RenderBmodelFace (entity_t *ent, bedge_t *pedges, msurface_t *psurf)
{
int i;
unsigned int mask;
@ -589,7 +589,7 @@ R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf)
surface_p->flags = psurf->flags;
surface_p->insubmodel = true;
surface_p->spanstate = 0;
surface_p->entity = currententity;
surface_p->entity = ent;
surface_p->key = r_currentbkey;
surface_p->spans = NULL;
@ -609,7 +609,7 @@ R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf)
void
R_RenderPoly (msurface_t *fa, int clipflags)
R_RenderPoly (entity_t *ent, msurface_t *fa, int clipflags)
{
int i, lindex, lnumverts, s_axis, t_axis;
float dist, lastdist, lzi, scale, u, v, frac;
@ -622,7 +622,7 @@ R_RenderPoly (msurface_t *fa, int clipflags)
polyvert_t pverts[100]; // FIXME: do real number, safely
int vertpage, newverts, newpage, lastvert;
qboolean visible;
mod_brush_t *brush = &currententity->renderer.model->brush;
mod_brush_t *brush = &ent->renderer.model->brush;
// FIXME: clean this up and make it faster
// FIXME: guard against running out of vertices
@ -777,7 +777,7 @@ R_RenderPoly (msurface_t *fa, int clipflags)
void
R_ZDrawSubmodelPolys (model_t *model)
R_ZDrawSubmodelPolys (entity_t *ent, model_t *model)
{
int i, numsurfaces;
msurface_t *psurf;
@ -798,7 +798,7 @@ R_ZDrawSubmodelPolys (model_t *model)
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
// FIXME: use bounding-box-based frustum clipping info?
R_RenderPoly (psurf, 15);
R_RenderPoly (ent, psurf, 15);
}
}
}

View file

@ -85,8 +85,6 @@ R_DrawCulledPolys (void)
surf_t *s;
msurface_t *pface;
currententity = &r_worldentity;
if (r_worldpolysbacktofront) {
for (s = surface_p - 1; s > &surfaces[1]; s--) {
if (!s->spans)
@ -94,7 +92,7 @@ R_DrawCulledPolys (void)
if (!(s->flags & SURF_DRAWBACKGROUND)) {
pface = (msurface_t *) s->data;
R_RenderPoly (pface, 15);
R_RenderPoly (s->entity, pface, 15);
}
}
} else {
@ -104,7 +102,7 @@ R_DrawCulledPolys (void)
if (!(s->flags & SURF_DRAWBACKGROUND)) {
pface = (msurface_t *) s->data;
R_RenderPoly (pface, 15);
R_RenderPoly (s->entity, pface, 15);
}
}
}

View file

@ -495,7 +495,7 @@ R_DrawViewModel (void)
}
static int
R_BmodelCheckBBox (model_t *clmodel, float *minmaxs)
R_BmodelCheckBBox (entity_t *ent, model_t *clmodel, float *minmaxs)
{
int i, *pindex, clipflags;
vec3_t acceptpt, rejectpt;
@ -504,7 +504,7 @@ R_BmodelCheckBBox (model_t *clmodel, float *minmaxs)
clipflags = 0;
Transform_GetWorldMatrix (currententity->transform, mat);
Transform_GetWorldMatrix (ent->transform, mat);
if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) {
for (i = 0; i < 4; i++) {
d = DotProduct (mat[3], view_clipplanes[i].normal);
@ -565,7 +565,6 @@ R_DrawBrushEntitiesOnList (void)
for (size_t i = 0; i < r_ent_queue->ent_queues[mod_brush].size; i++) {
entity_t *ent = r_ent_queue->ent_queues[mod_brush].a[i];
currententity = ent;
VectorCopy (Transform_GetWorldPosition (ent->transform), origin);
clmodel = ent->renderer.model;
@ -577,7 +576,7 @@ R_DrawBrushEntitiesOnList (void)
minmaxs[3 + j] = origin[j] + clmodel->maxs[j];
}
clipflags = R_BmodelCheckBBox (clmodel, minmaxs);
clipflags = R_BmodelCheckBBox (ent, clmodel, minmaxs);
if (clipflags != BMODEL_FULLY_CLIPPED) {
mod_brush_t *brush = &clmodel->brush;
@ -587,7 +586,7 @@ R_DrawBrushEntitiesOnList (void)
r_pcurrentvertbase = brush->vertexes;
// FIXME: stop transforming twice
R_RotateBmodel ();
R_RotateBmodel (ent->transform);
// calculate dynamic lighting for bmodel if it's not an
// instanced model
@ -611,7 +610,7 @@ R_DrawBrushEntitiesOnList (void)
// 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);
R_ZDrawSubmodelPolys (ent, clmodel);
} else {
if (ent->visibility.topnode) {
mnode_t *topnode = ent->visibility.topnode;
@ -620,12 +619,12 @@ R_DrawBrushEntitiesOnList (void)
// not a leaf; has to be clipped to the world
// BSP
r_clipflags = clipflags;
R_DrawSolidClippedSubmodelPolygons (clmodel);
R_DrawSolidClippedSubmodelPolygons (ent, clmodel, 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 (clmodel, clipflags);
R_DrawSubmodelPolygons (ent, clmodel, clipflags, topnode);
}
}
}

View file

@ -73,7 +73,7 @@ static unsigned int blocklights[34 * 34]; //FIXME make dynamic
static void
R_AddDynamicLights (void)
R_AddDynamicLights (transform_t *transform)
{
msurface_t *surf;
unsigned int lnum;
@ -91,9 +91,9 @@ R_AddDynamicLights (void)
tmax = (surf->extents[1] >> 4) + 1;
tex = surf->texinfo;
if (currententity->transform) {
if (transform) {
//FIXME give world entity a transform
entorigin = Transform_GetWorldPosition (currententity->transform);
entorigin = Transform_GetWorldPosition (transform);
}
for (lnum = 0; lnum < r_maxdlights; lnum++) {
@ -144,7 +144,7 @@ R_AddDynamicLights (void)
Combine and scale multiple lightmaps into the 8.8 format in blocklights
*/
static void
R_BuildLightMap (void)
R_BuildLightMap (transform_t *transform)
{
int smax, tmax;
int t;
@ -180,7 +180,7 @@ R_BuildLightMap (void)
}
// add all the dynamic lights
if (surf->dlightframe == r_framecount)
R_AddDynamicLights ();
R_AddDynamicLights (transform);
// bound, invert, and shift
for (i = 0; i < size; i++) {
@ -194,7 +194,7 @@ R_BuildLightMap (void)
}
void
R_DrawSurface (void)
R_DrawSurface (transform_t *transform)
{
byte *basetptr;
int smax, tmax, twidth;
@ -206,7 +206,7 @@ R_DrawSurface (void)
texture_t *mt;
// calculate the lightings
R_BuildLightMap ();
R_BuildLightMap (transform);
surfrowbytes = r_drawsurf.rowbytes;