[renderer] Separate core of R_MarkLeaves

I needed to mark leaves based on an arbitrary PVS (for lighting) that is
independent of the camera position. Also cleaned up some const
correctness.
This commit is contained in:
Bill Currie 2023-07-27 15:43:47 +09:00
parent f7fce957e8
commit 2790972cb0
4 changed files with 40 additions and 34 deletions

View file

@ -56,7 +56,7 @@ typedef struct visstate_s {
int *leaf_visframes;
int *face_visframes;
int visframecount;
struct mod_brush_s *brush;
const struct mod_brush_s *brush;
} visstate_t;
extern visstate_t r_visstate;//FIXME
@ -88,6 +88,8 @@ struct animation_s;
struct transform_s;
void R_DrawAliasModel (struct entity_s *e);
struct set_s;
void R_MarkLeavesPVS (visstate_t *state, const struct set_s *pvs);
void R_MarkLeaves (visstate_t *state, const struct mleaf_s *viewleaf);
void GL_SetPalette (void *data, const byte *palette);

View file

@ -308,7 +308,7 @@ void R_SetupFrame (void);
void R_cshift_f (void);
void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1);
void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip);
void R_RecursiveMarkLights (mod_brush_t *brush, vec4f_t lightorigin,
void R_RecursiveMarkLights (const mod_brush_t *brush, vec4f_t lightorigin,
struct dlight_s *light, int bit, int node_id);
void R_LoadSkys (const char *);

View file

@ -46,43 +46,20 @@
static set_t *solid;
void
R_MarkLeaves (visstate_t *visstate, const mleaf_t *viewleaf)
R_MarkLeavesPVS (visstate_t *visstate, const set_t *pvs)
{
set_t *vis;
int c;
mleaf_t *leaf;
msurface_t **mark;
int visframecount = ++visstate->visframecount;
auto brush = visstate->brush;
auto node_visframes = visstate->node_visframes;
auto leaf_visframes = visstate->leaf_visframes;
auto face_visframes = visstate->face_visframes;
auto brush = visstate->brush;
if (visstate->viewleaf == viewleaf && !r_novis)
return;
int visframecount = ++visstate->visframecount;
visstate->viewleaf = viewleaf;
if (!viewleaf)
return;
if (r_novis) {
// so vis will be recalculated when novis gets turned off
visstate->viewleaf = 0;
if (!solid) {
solid = set_new ();
set_everything (solid);
}
vis = solid;
} else {
vis = Mod_LeafPVS (viewleaf, brush);
}
for (auto li = set_first (vis); li; li = set_next (li)) {
for (auto li = set_first (pvs); li; li = set_next (li)) {
unsigned i = li->element;
if (set_is_member (vis, i)) {
leaf = &brush->leafs[i + 1];
if (set_is_member (pvs, i)) {
auto leaf = &brush->leafs[i + 1];
int c;
if ((c = leaf->nummarksurfaces)) {
mark = brush->marksurfaces + leaf->firstmarksurface;
auto mark = brush->marksurfaces + leaf->firstmarksurface;
do {
face_visframes[*mark - brush->surfaces] = visframecount;
mark++;
@ -100,6 +77,33 @@ R_MarkLeaves (visstate_t *visstate, const mleaf_t *viewleaf)
}
}
void
R_MarkLeaves (visstate_t *visstate, const mleaf_t *viewleaf)
{
set_t *vis;
auto brush = visstate->brush;
if (visstate->viewleaf == viewleaf && !r_novis)
return;
visstate->viewleaf = viewleaf;
if (!viewleaf)
return;
if (r_novis) {
// so vis will be recalculated when novis gets turned off
visstate->viewleaf = 0;
if (!solid) {
solid = set_new ();
set_everything (solid);
}
vis = solid;
} else {
vis = Mod_LeafPVS (viewleaf, brush);
}
R_MarkLeavesPVS (visstate, vis);
}
/*
R_TextureAnimation

View file

@ -208,7 +208,7 @@ mark_surfaces (msurface_t *surf, vec4f_t lightorigin, dlight_t *light,
// LordHavoc: heavily modified, to eliminate unnecessary texture uploads,
// and support bmodel lighting better
void
R_RecursiveMarkLights (mod_brush_t *brush, vec4f_t lightorigin,
R_RecursiveMarkLights (const mod_brush_t *brush, vec4f_t lightorigin,
dlight_t *light, int lightnum, int node_id)
{
unsigned i;