[renderer] Remove tinst from msurface_t

Its sole purpose was to pass the newly allocated instsurf when chaining
an instance model (ammo box, etc) surface, but using expresion
statements removes the need for such shenanigans, and even makes
msurface_t that little bit smaller (though a separate array would be
much better for cache coherence).

More importantly, the relevant code is actually easier to understand: I
spent way too long working out what tinst was for and why it was never
cleared.
This commit is contained in:
Bill Currie 2021-07-13 16:02:47 +09:00
parent 1078bd9efa
commit c8e6f71a30
4 changed files with 35 additions and 62 deletions

View File

@ -154,7 +154,6 @@ typedef struct msurface_s {
glpoly_t *polys; // multiple if warped
instsurf_t *instsurf; ///< null if not part of world model/sub-model
instsurf_t *tinst; ///< for instance models
mtexinfo_t *texinfo;
int ec_index;

View File

@ -66,25 +66,27 @@ static instsurf_t *sky_chain;
static instsurf_t **sky_chain_tail;
#define CHAIN_SURF_F2B(surf,chain) \
do { \
({ \
instsurf_t *inst = (surf)->instsurf; \
if (__builtin_expect(!inst, 1)) \
(surf)->tinst = inst = get_instsurf (); \
inst = get_instsurf (); \
inst->surface = (surf); \
*(chain##_tail) = inst; \
(chain##_tail) = &inst->tex_chain; \
*(chain##_tail) = 0; \
} while (0)
inst; \
})
#define CHAIN_SURF_B2F(surf,chain) \
do { \
({ \
instsurf_t *inst = (surf)->instsurf; \
if (__builtin_expect(!inst, 1)) \
(surf)->tinst = inst = get_instsurf (); \
inst = get_instsurf (); \
inst->surface = (surf); \
inst->tex_chain = (chain); \
(chain) = inst; \
} while (0)
inst; \
})
static gltex_t **r_texture_chains;
static int r_num_texture_chains;
@ -268,16 +270,12 @@ R_RenderBrushPoly_1 (msurface_t *fa)
}
static inline void
R_AddToLightmapChain (mod_brush_t *brush, msurface_t *fa)
R_AddToLightmapChain (mod_brush_t *brush, msurface_t *fa, instsurf_t *sc)
{
int maps, smax, tmax;
glRect_t *theRect;
instsurf_t *sc;
// add the poly to the proper lightmap chain
if (!(sc = fa->instsurf))
sc = fa->tinst;
sc->lm_chain = gl_lightmap_polys[fa->lightmaptexturenum];
gl_lightmap_polys[fa->lightmaptexturenum] = sc;
@ -497,9 +495,9 @@ chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
instsurf_t *sc;
if (surf->flags & SURF_DRAWTURB) {
CHAIN_SURF_B2F (surf, waterchain);
sc = CHAIN_SURF_B2F (surf, waterchain);
} else if (surf->flags & SURF_DRAWSKY) {
CHAIN_SURF_F2B (surf, sky_chain);
sc = CHAIN_SURF_F2B (surf, sky_chain);
} else {
texture_t *tx;
gltex_t *tex;
@ -509,12 +507,10 @@ chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
else
tx = R_TextureAnimation (surf);
tex = tx->render;
CHAIN_SURF_F2B (surf, tex->tex_chain);
sc = CHAIN_SURF_F2B (surf, tex->tex_chain);
R_AddToLightmapChain (brush, surf);
R_AddToLightmapChain (brush, surf, sc);
}
if (!(sc = surf->instsurf))
sc = surf->tinst;
sc->transform = transform;
sc->color = color;
}

View File

@ -238,25 +238,27 @@ static struct {
} sky_params;
#define CHAIN_SURF_F2B(surf,chain) \
do { \
({ \
instsurf_t *inst = (surf)->instsurf; \
if (__builtin_expect(!inst, 1)) \
(surf)->tinst = inst = get_instsurf (); \
inst = get_instsurf (); \
inst->surface = (surf); \
*(chain##_tail) = inst; \
(chain##_tail) = &inst->tex_chain; \
*(chain##_tail) = 0; \
} while (0)
inst; \
})
#define CHAIN_SURF_B2F(surf,chain) \
do { \
({ \
instsurf_t *inst = (surf)->instsurf; \
if (__builtin_expect(!inst, 1)) \
(surf)->tinst = inst = get_instsurf (); \
inst = get_instsurf (); \
inst->surface = (surf); \
inst->tex_chain = (chain); \
(chain) = inst; \
} while (0)
inst; \
})
#define GET_RELEASE(type,name) \
static inline type * \
@ -380,9 +382,9 @@ chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
instsurf_t *is;
if (surf->flags & SURF_DRAWSKY) {
CHAIN_SURF_F2B (surf, sky_chain);
is = CHAIN_SURF_F2B (surf, sky_chain);
} else if ((surf->flags & SURF_DRAWTURB) || (color && color[3] < 1.0)) {
CHAIN_SURF_B2F (surf, waterchain);
is = CHAIN_SURF_B2F (surf, waterchain);
} else {
texture_t *tx;
glsltex_t *tex;
@ -392,12 +394,10 @@ chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
else
tx = R_TextureAnimation (surf);
tex = tx->render;
CHAIN_SURF_F2B (surf, tex->tex_chain);
is = CHAIN_SURF_F2B (surf, tex->tex_chain);
update_lightmap (brush, surf);
}
if (!(is = surf->instsurf))
is = surf->tinst;
is->transform = transform;
is->color = color;
}

View File

@ -97,25 +97,27 @@ typedef struct bsppoly_s {
} bsppoly_t;
#define CHAIN_SURF_F2B(surf,chain) \
do { \
({ \
instsurf_t *inst = (surf)->instsurf; \
if (__builtin_expect(!inst, 1)) \
(surf)->tinst = inst = get_instsurf (bctx); \
inst = get_instsurf (bctx); \
inst->surface = (surf); \
*(chain##_tail) = inst; \
(chain##_tail) = &inst->tex_chain; \
*(chain##_tail) = 0; \
} while (0)
inst; \
})
#define CHAIN_SURF_B2F(surf,chain) \
do { \
({ \
instsurf_t *inst = (surf)->instsurf; \
if (__builtin_expect(!inst, 1)) \
(surf)->tinst = inst = get_instsurf (bctx); \
inst = get_instsurf (bctx); \
inst->surface = (surf); \
inst->tex_chain = (chain); \
(chain) = inst; \
} while (0)
inst; \
})
#define GET_RELEASE(type,name) \
static inline type * \
@ -234,9 +236,9 @@ chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
instsurf_t *is;
if (surf->flags & SURF_DRAWSKY) {
CHAIN_SURF_F2B (surf, bctx->sky_chain);
is = CHAIN_SURF_F2B (surf, bctx->sky_chain);
} else if ((surf->flags & SURF_DRAWTURB) || (color && color[3] < 1.0)) {
CHAIN_SURF_B2F (surf, bctx->waterchain);
is = CHAIN_SURF_B2F (surf, bctx->waterchain);
} else {
texture_t *tx;
vulktex_t *tex;
@ -246,12 +248,10 @@ chain_surface (mod_brush_t *brush, msurface_t *surf, vec_t *transform,
else
tx = R_TextureAnimation (surf);
tex = tx->render;
CHAIN_SURF_F2B (surf, tex->tex_chain);
is = CHAIN_SURF_F2B (surf, tex->tex_chain);
//update_lightmap (brush, surf, ctx);
}
if (!(is = surf->instsurf))
is = surf->tinst;
is->transform = transform;
is->color = color;
}
@ -1560,28 +1560,6 @@ is_pow2 (unsigned x)
return count == 1;
}
// NOTE: this expects the destination tex_t to be set up: memory allocated
// and dimentions/format etc already set. the size of the rect to be copied
// is taken from dst. Also, dst->format and src->format must be the same, and
// either 3 or 4, or bad things will happen. Also, no clipping is done, so if
// x < 0 or y < 0 or x + dst->width > src->width
// or y + dst->height > src->height, bad things will happen.
/*XXX static void
copy_sub_tex (tex_t *src, int x, int y, tex_t *dst)
{
int dstbytes;
int srcbytes;
int i;
srcbytes = src->width * src->format;
dstbytes = dst->width * dst->format;
x *= src->format;
for (i = 0; i < dst->height; i++)
memcpy (dst->data + i * dstbytes, src->data + (i + y) * srcbytes + x,
dstbytes);
}*/
void
Vulkan_LoadSkys (const char *sky, vulkan_ctx_t *ctx)
{