From f3768e3dfba675fb8a2dc1d8677e96d573f02a89 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 11 Mar 2022 16:39:08 +0900 Subject: [PATCH] [renderer] Remove currententity One more global in the trash :) --- include/d_iface.h | 4 ++-- include/d_local.h | 4 +++- include/r_local.h | 15 +++++++------ include/r_shared.h | 1 - libs/video/renderer/r_light.c | 2 -- libs/video/renderer/r_main.c | 2 -- libs/video/renderer/sw/d_edge.c | 22 +++++++----------- libs/video/renderer/sw/d_surf.c | 6 ++--- libs/video/renderer/sw/sw_rbsp.c | 37 +++++++++++++++++-------------- libs/video/renderer/sw/sw_rdraw.c | 18 +++++++-------- libs/video/renderer/sw/sw_redge.c | 6 ++--- libs/video/renderer/sw/sw_rmain.c | 15 ++++++------- libs/video/renderer/sw/sw_rsurf.c | 14 ++++++------ 13 files changed, 69 insertions(+), 77 deletions(-) diff --git a/include/d_iface.h b/include/d_iface.h index 279a10baf..9536f1725 100644 --- a/include/d_iface.h +++ b/include/d_iface.h @@ -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 !!! diff --git a/include/d_local.h b/include/d_local.h index f67dcea74..1ff077d82 100644 --- a/include/d_local.h +++ b/include/d_local.h @@ -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)); diff --git a/include/r_local.h b/include/r_local.h index 6efd16c3d..fe8c19713 100644 --- a/include/r_local.h +++ b/include/r_local.h @@ -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 =========================================== diff --git a/include/r_shared.h b/include/r_shared.h index b04e129f1..84616a77c 100644 --- a/include/r_shared.h +++ b/include/r_shared.h @@ -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 diff --git a/libs/video/renderer/r_light.c b/libs/video/renderer/r_light.c index 8ecf947de..8de8f2738 100644 --- a/libs/video/renderer/r_light.c +++ b/libs/video/renderer/r_light.c @@ -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: diff --git a/libs/video/renderer/r_main.c b/libs/video/renderer/r_main.c index dd9860c4c..ba3b260a3 100644 --- a/libs/video/renderer/r_main.c +++ b/libs/video/renderer/r_main.c @@ -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; diff --git a/libs/video/renderer/sw/d_edge.c b/libs/video/renderer/sw/d_edge.c index a4ddcfb5d..91c0b2f53 100644 --- a/libs/video/renderer/sw/d_edge.c +++ b/libs/video/renderer/sw/d_edge.c @@ -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; } } } diff --git a/libs/video/renderer/sw/d_surf.c b/libs/video/renderer/sw/d_surf.c index 8e6e53c75..33b4b399f 100644 --- a/libs/video/renderer/sw/d_surf.c +++ b/libs/video/renderer/sw/d_surf.c @@ -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]; } diff --git a/libs/video/renderer/sw/sw_rbsp.c b/libs/video/renderer/sw/sw_rbsp.c index ac9028209..1fbab1168 100644 --- a/libs/video/renderer/sw/sw_rbsp.c +++ b/libs/video/renderer/sw/sw_rbsp.c @@ -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 = ¤tentity->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); } } } diff --git a/libs/video/renderer/sw/sw_rdraw.c b/libs/video/renderer/sw/sw_rdraw.c index b466d1b61..48c8489df 100644 --- a/libs/video/renderer/sw/sw_rdraw.c +++ b/libs/video/renderer/sw/sw_rdraw.c @@ -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 = ¤tentity->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 = ¤tentity->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); } } } diff --git a/libs/video/renderer/sw/sw_redge.c b/libs/video/renderer/sw/sw_redge.c index 8efc09753..92499477a 100644 --- a/libs/video/renderer/sw/sw_redge.c +++ b/libs/video/renderer/sw/sw_redge.c @@ -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); } } } diff --git a/libs/video/renderer/sw/sw_rmain.c b/libs/video/renderer/sw/sw_rmain.c index c6b7ddf1f..98e98f4d6 100644 --- a/libs/video/renderer/sw/sw_rmain.c +++ b/libs/video/renderer/sw/sw_rmain.c @@ -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); } } } diff --git a/libs/video/renderer/sw/sw_rsurf.c b/libs/video/renderer/sw/sw_rsurf.c index 106dd8f29..819293d1b 100644 --- a/libs/video/renderer/sw/sw_rsurf.c +++ b/libs/video/renderer/sw/sw_rsurf.c @@ -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;