ref: e7f55e32736cd1360a7135fda5a7ca4d97c45520
parent: 7f9c4b6c2d5017d10b370b4e55691b5a2631eb75
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Jan 5 19:43:03 EST 2024
rearrange and clean up surf_t fields
--- a/d_edge.c
+++ b/d_edge.c
@@ -121,7 +121,7 @@
dvars.zistepv = s->d_zistepv;
dvars.ziorigin = s->d_ziorigin;
- if(s->insubmodel){
+ if(insubmodel(s)){
currententity = s->entity;
VectorSubtract(r_origin, currententity->origin, local_modelorg);
TransformVector(local_modelorg, transformed_modelorg);
@@ -148,7 +148,7 @@
);
}
- if(s->insubmodel){
+ if(insubmodel(s)){
currententity = cl_entities;
VectorCopy(world_transformed_modelorg, transformed_modelorg);
VectorCopy(base_vpn, vpn);
--- a/model.h
+++ b/model.h
@@ -74,7 +74,10 @@
SURF_LAVA = 1<<10,
SURF_SLIME = 1<<11,
SURF_TELE = 1<<12,
+ SURF_IN_SUBMODEL = 1<<31, /* makes surf->flags negative */
};
+
+#define insubmodel(s) ((s)->flags < 0)
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct
--- a/r_bsp.c
+++ b/r_bsp.c
@@ -3,7 +3,7 @@
//
// current entity info
//
-bool insubmodel;
+
entity_t *currententity;
vec3_t modelorg, base_modelorg;
// modelorg is the viewpoint reletive to
--- a/r_draw.c
+++ b/r_draw.c
@@ -389,7 +389,7 @@
r_pedge = &pedges[lindex];
// if the edge is cached, we can just reuse the edge
- if (!insubmodel)
+ if (currententity == cl_entities)
{
if (r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED)
{
@@ -429,7 +429,7 @@
lindex = -lindex;
r_pedge = &pedges[lindex];
// if the edge is cached, we can just reuse the edge
- if (!insubmodel)
+ if (currententity == cl_entities)
{
if (r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED)
{
@@ -494,8 +494,7 @@
surface_p->data = (void *)fa;
surface_p->nearzi = r_nearzi;
- surface_p->flags = fa->flags;
- surface_p->insubmodel = insubmodel;
+ surface_p->flags = fa->flags | (currententity == cl_entities ? 0 : SURF_IN_SUBMODEL);
surface_p->spanstate = 0;
surface_p->entity = currententity;
surface_p->key = r_currentkey++;
@@ -608,8 +607,7 @@
surface_p->data = (void *)psurf;
surface_p->nearzi = r_nearzi;
- surface_p->flags = psurf->flags;
- surface_p->insubmodel = true;
+ surface_p->flags = psurf->flags | SURF_IN_SUBMODEL;
surface_p->spanstate = 0;
surface_p->entity = currententity;
surface_p->key = r_currentbkey;
--- a/r_edge.c
+++ b/r_edge.c
@@ -293,7 +293,7 @@
// if it's two surfaces on the same plane, the one that's already
// active is in front, so keep going unless it's a bmodel
- if (surf->insubmodel && (surf->key == surf2->key))
+ if (insubmodel(surf) && (surf->key == surf2->key))
{
// must be two bmodels in the same leaf; sort on 1/z
fu = (float)(edge->u - 0xFFFFF) * (1.0 / 0x100000);
@@ -330,7 +330,7 @@
{
// if it's two surfaces on the same plane, the one that's already
// active is in front, so keep going unless it's a bmodel
- if (!surf->insubmodel)
+ if (!insubmodel(surf))
goto continue_search;
// must be two bmodels in the same leaf; sort on 1/z
--- a/r_local.h
+++ b/r_local.h
@@ -104,11 +104,6 @@
void R_ResetFog(void);
void R_InitFog(void);
-//
-// current entity info
-//
-extern bool insubmodel;
-
void R_DrawSprite (void);
int R_RenderFace (msurface_t *fa, int clipflags);
void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf);
--- a/r_main.c
+++ b/r_main.c
@@ -521,7 +521,6 @@
break;
case mod_brush:
- insubmodel = true;
r_dlightframecount = r_framecount;
clmodel = e->model;
--- a/r_shared.h
+++ b/r_shared.h
@@ -61,27 +61,22 @@
struct espan_s *pnext;
} espan_t;
-// FIXME: compress, make a union if that will help
-// insubmodel is only 1, flags is fewer than 32, spanstate could be a byte
typedef struct surf_s
{
- struct surf_s *next; // active surface stack in r_edge.c
- struct surf_s *prev; // used in r_edge.c for active surf stack
- struct espan_s *spans; // pointer to linked list of spans to draw
int key; // sorting key (BSP order)
+ int flags;
int last_u; // set during tracing
- int spanstate; // 0 = not in span
+ byte spanstate; // 0 = not in span
// 1 = in span
// -1 = in inverted span (end before
// start)
- int flags; // currentface flags
- void *data; // associated data like msurface_t
- entity_t *entity;
float nearzi; // nearest 1/z on surface, for mipmapping
- bool insubmodel;
float d_ziorigin, d_zistepu, d_zistepv;
-
- int pad[2]; // to 64 bytes
+ struct surf_s *next; // active surface stack in r_edge.c
+ struct surf_s *prev; // used in r_edge.c for active surf stack
+ struct espan_s *spans; // pointer to linked list of spans to draw
+ void *data; // associated data like msurface_t
+ entity_t *entity;
} surf_t;
extern int r_numallocatedbasespans;