diff --git a/include/QF/model.h b/include/QF/model.h index e8ad0cf47..842626447 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -432,13 +432,13 @@ model_t *Mod_ForName (const char *name, bool crash); void Mod_TouchModel (const char *name); void Mod_UnloadModel (model_t *model); // brush specific -mleaf_t *Mod_PointInLeaf (vec4f_t p, model_t *model) __attribute__((pure)); -struct set_s *Mod_LeafPVS (const mleaf_t *leaf, const model_t *model); +mleaf_t *Mod_PointInLeaf (vec4f_t p, const mod_brush_t *brush) __attribute__((pure)); +struct set_s *Mod_LeafPVS (const mleaf_t *leaf, const mod_brush_t *brush); -void Mod_LeafPVS_set (const mleaf_t *leaf, const model_t *model, byte defvis, - struct set_s *pvs); -void Mod_LeafPVS_mix (const mleaf_t *leaf, const model_t *model, byte defvis, - struct set_s *pvs); +void Mod_LeafPVS_set (const mleaf_t *leaf, const mod_brush_t *brush, + byte defvis, struct set_s *pvs); +void Mod_LeafPVS_mix (const mleaf_t *leaf, const mod_brush_t *brush, + byte defvis, struct set_s *pvs); void Mod_Print (void); diff --git a/libs/client/cl_screen.c b/libs/client/cl_screen.c index 4ae6e5296..4a0fc0d44 100644 --- a/libs/client/cl_screen.c +++ b/libs/client/cl_screen.c @@ -113,7 +113,7 @@ SCR_CShift (void) if (_vs->active && cl_world.scene->worldmodel) { vec4f_t origin; origin = Transform_GetWorldPosition (_vs->camera_transform); - leaf = Mod_PointInLeaf (origin, cl_world.scene->worldmodel); + leaf = Mod_PointInLeaf (origin, &cl_world.scene->worldmodel->brush); contents = leaf->contents; } V_SetContentsColor (_vs, contents); diff --git a/libs/models/brush/model_brush.c b/libs/models/brush/model_brush.c index b7f8d4fff..b22c6cd85 100644 --- a/libs/models/brush/model_brush.c +++ b/libs/models/brush/model_brush.c @@ -61,18 +61,18 @@ VISIBLE int mod_sky_divide; //FIXME visibility? VISIBLE int mod_lightmap_bytes = 1; //FIXME should this be visible? VISIBLE mleaf_t * -Mod_PointInLeaf (vec4f_t p, model_t *model) +Mod_PointInLeaf (vec4f_t p, const mod_brush_t *brush) { float d; - if (!model || !model->brush.nodes) - Sys_Error ("Mod_PointInLeaf: bad model"); + if (!brush || !brush->nodes) + Sys_Error ("Mod_PointInLeaf: bad brush"); int node_id = 0; while (1) { if (node_id < 0) - return model->brush.leafs + ~node_id; - mnode_t *node = model->brush.nodes + node_id; + return brush->leafs + ~node_id; + mnode_t *node = brush->nodes + node_id; d = dotf (p, node->plane)[0]; node_id = node->children[d < 0]; } @@ -148,14 +148,14 @@ Mod_DecompressVis_mix (const byte *in, const mod_brush_t *brush, byte defvis, } VISIBLE set_t * -Mod_LeafPVS (const mleaf_t *leaf, const model_t *model) +Mod_LeafPVS (const mleaf_t *leaf, const mod_brush_t *brush) { static set_t *novis; static set_t *decompressed; - unsigned numvis = model->brush.visleafs; + unsigned numvis = brush->visleafs; unsigned excess = SET_SIZE (numvis) - numvis; - if (leaf == model->brush.leafs) { + if (leaf == brush->leafs) { if (!novis) { novis = set_new_size (numvis); } @@ -171,38 +171,37 @@ Mod_LeafPVS (const mleaf_t *leaf, const model_t *model) decompressed = set_new (); } set_expand (decompressed, numvis); - Mod_DecompressVis_set (leaf->compressed_vis, &model->brush, 0xff, - decompressed); + Mod_DecompressVis_set (leaf->compressed_vis, brush, 0xff, decompressed); decompressed->map[SET_WORDS (decompressed) - 1] &= (~SET_ZERO) >> excess; return decompressed; } VISIBLE void -Mod_LeafPVS_set (const mleaf_t *leaf, const model_t *model, byte defvis, +Mod_LeafPVS_set (const mleaf_t *leaf, const mod_brush_t *brush, byte defvis, set_t *out) { - unsigned numvis = model->brush.visleafs; + unsigned numvis = brush->visleafs; unsigned excess = SET_SIZE (numvis) - numvis; set_expand (out, numvis); - if (leaf == model->brush.leafs) { + if (leaf == brush->leafs) { memset (out->map, defvis, SET_WORDS (out) * sizeof (*out->map)); out->map[SET_WORDS (out) - 1] &= (~SET_ZERO) >> excess; return; } - Mod_DecompressVis_set (leaf->compressed_vis, &model->brush, defvis, out); + Mod_DecompressVis_set (leaf->compressed_vis, brush, defvis, out); out->map[SET_WORDS (out) - 1] &= (~SET_ZERO) >> excess; } VISIBLE void -Mod_LeafPVS_mix (const mleaf_t *leaf, const model_t *model, byte defvis, +Mod_LeafPVS_mix (const mleaf_t *leaf, const mod_brush_t *brush, byte defvis, set_t *out) { - unsigned numvis = model->brush.visleafs; + unsigned numvis = brush->visleafs; unsigned excess = SET_SIZE (numvis) - numvis; set_expand (out, numvis); - if (leaf == model->brush.leafs) { + if (leaf == brush->leafs) { byte *o = (byte *) out->map; for (int i = SET_WORDS (out) * sizeof (*out->map); i-- > 0; ) { *o++ |= defvis; @@ -210,7 +209,7 @@ Mod_LeafPVS_mix (const mleaf_t *leaf, const model_t *model, byte defvis, out->map[SET_WORDS (out) - 1] &= (~SET_ZERO) >> excess; return; } - Mod_DecompressVis_mix (leaf->compressed_vis, &model->brush, defvis, out); + Mod_DecompressVis_mix (leaf->compressed_vis, brush, defvis, out); out->map[SET_WORDS (out) - 1] &= (~SET_ZERO) >> excess; } diff --git a/libs/scene/light.c b/libs/scene/light.c index dfbd026c9..afe7e716b 100644 --- a/libs/scene/light.c +++ b/libs/scene/light.c @@ -11,13 +11,13 @@ #include "QF/simd/vec4f.h" static void -expand_pvs (set_t *pvs, model_t *model) +expand_pvs (set_t *pvs, mod_brush_t *brush) { - set_t base_pvs = SET_STATIC_INIT (model->brush.visleafs, alloca); + set_t base_pvs = SET_STATIC_INIT (brush->visleafs, alloca); set_assign (&base_pvs, pvs); - for (unsigned i = 0; i < model->brush.visleafs; i++) { + for (unsigned i = 0; i < brush->visleafs; i++) { if (set_is_member (&base_pvs, i)) { - Mod_LeafPVS_mix (model->brush.leafs + i + 1, model, 0, pvs); + Mod_LeafPVS_mix (brush->leafs + i + 1, brush, 0, pvs); } } } @@ -78,7 +78,7 @@ Light_AddLight (lightingdata_t *ldata, const light_t *light, int style) int visleaf = -1; // directional light if (light->position[3]) { // positional light - mleaf_t *leaf = Mod_PointInLeaf (light->position, model); + mleaf_t *leaf = Mod_PointInLeaf (light->position, &model->brush); visleaf = leaf - model->brush.leafs - 1; } else if (!DotProduct (light->direction, light->direction)) { // ambient light @@ -92,24 +92,24 @@ void Light_EnableSun (lightingdata_t *ldata) { scene_t *scene = ldata->scene; - model_t *model = scene->worldmodel; + auto brush = &scene->worldmodel->brush; if (!ldata->sun_pvs) { - ldata->sun_pvs = set_new_size (model->brush.visleafs); + ldata->sun_pvs = set_new_size (brush->visleafs); } - set_expand (ldata->sun_pvs, model->brush.visleafs); + set_expand (ldata->sun_pvs, brush->visleafs); set_empty (ldata->sun_pvs); // Any leaf with sky surfaces can potentially see the sun, thus put // the sun "in" every leaf with a sky surface // however, skip leaf 0 as it is the exterior solid leaf - for (unsigned l = 1; l < model->brush.modleafs; l++) { - if (model->brush.leaf_flags[l] & SURF_DRAWSKY) { + for (unsigned l = 1; l < brush->modleafs; l++) { + if (brush->leaf_flags[l] & SURF_DRAWSKY) { set_add (ldata->sun_pvs, l - 1); //pvs is 1-based } } // any leaf visible from a leaf with a sky surface (and thus the sun) // can receive shadows from the sun - expand_pvs (ldata->sun_pvs, model); + expand_pvs (ldata->sun_pvs, brush); } void @@ -117,28 +117,28 @@ Light_FindVisibleLights (lightingdata_t *ldata) { scene_t *scene = ldata->scene; mleaf_t *leaf = scene->viewleaf; - model_t *model = scene->worldmodel; + auto brush = &scene->worldmodel->brush; if (!leaf) { return; } if (!ldata->pvs) { - ldata->pvs = set_new_size (model->brush.visleafs); + ldata->pvs = set_new_size (brush->visleafs); } if (leaf != ldata->leaf) { //double start = Sys_DoubleTime (); int flags = 0; - if (leaf == model->brush.leafs) { + if (leaf == brush->leafs) { set_everything (ldata->pvs); flags = SURF_DRAWSKY; } else { - Mod_LeafPVS_set (leaf, model, 0, ldata->pvs); + Mod_LeafPVS_set (leaf, brush, 0, ldata->pvs); if (set_is_intersecting (ldata->pvs, ldata->sun_pvs)) { flags |= SURF_DRAWSKY; } - expand_pvs (ldata->pvs, model); + expand_pvs (ldata->pvs, brush); } ldata->leaf = leaf; diff --git a/libs/video/renderer/r_bsp.c b/libs/video/renderer/r_bsp.c index 19b5475e9..a5dd98a3c 100644 --- a/libs/video/renderer/r_bsp.c +++ b/libs/video/renderer/r_bsp.c @@ -73,7 +73,7 @@ R_MarkLeaves (mleaf_t *viewleaf, int *node_visframes, int *leaf_visframes, } vis = solid; } else - vis = Mod_LeafPVS (viewleaf, r_refdef.worldmodel); + vis = Mod_LeafPVS (viewleaf, brush); for (unsigned i = 0; i < brush->visleafs; i++) { if (set_is_member (vis, i)) { diff --git a/libs/video/renderer/r_light.c b/libs/video/renderer/r_light.c index 1b9cae06c..d03c68576 100644 --- a/libs/video/renderer/r_light.c +++ b/libs/video/renderer/r_light.c @@ -264,7 +264,7 @@ R_MarkLights (vec4f_t lightorigin, dlight_t *light, int lightnum, model_t *model) { mod_brush_t *brush = &model->brush; - mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, model); + mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, brush); if (!pvsleaf->compressed_vis) { int node_id = brush->hulls[0].firstclipnode; diff --git a/libs/video/renderer/r_screen.c b/libs/video/renderer/r_screen.c index caf91dfd1..a8ac82c79 100644 --- a/libs/video/renderer/r_screen.c +++ b/libs/video/renderer/r_screen.c @@ -316,7 +316,8 @@ SCR_UpdateScreen (transform_t camera, double realtime, SCR_Func *scr_funcs) if (scr_scene && scr_scene->worldmodel) { scr_scene->viewleaf = 0; vec4f_t position = refdef->frame.position; - scr_scene->viewleaf = Mod_PointInLeaf (position, scr_scene->worldmodel); + auto brush = &scr_scene->worldmodel->brush; + scr_scene->viewleaf = Mod_PointInLeaf (position, brush); r_dowarpold = r_dowarp; if (r_waterwarp) { r_dowarp = scr_scene->viewleaf->contents <= CONTENTS_WATER; diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index 1316a051e..a1b7d4462 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -655,7 +655,7 @@ CL_Frame (void) vec4f_t origin; origin = Transform_GetWorldPosition (cl.viewstate.camera_transform); - l = Mod_PointInLeaf (origin, cl_world.scene->worldmodel); + l = Mod_PointInLeaf (origin, &cl_world.scene->worldmodel->brush); if (l) asl = l->ambient_sound_level; S_Update (cl.viewstate.camera_transform, asl); diff --git a/nq/source/sv_main.c b/nq/source/sv_main.c index b68af9659..fa2e49ea9 100644 --- a/nq/source/sv_main.c +++ b/nq/source/sv_main.c @@ -386,7 +386,7 @@ SV_AddToFatPVS (vec4f_t org, int node_id) if (node_id < 0) { mleaf_t *leaf = sv.worldmodel->brush.leafs + ~node_id; if (leaf->contents != CONTENTS_SOLID) { - set_union (fatpvs, Mod_LeafPVS (leaf, sv.worldmodel)); + set_union (fatpvs, Mod_LeafPVS (leaf, &sv.worldmodel->brush)); } return; } diff --git a/nq/source/sv_pr_cmds.c b/nq/source/sv_pr_cmds.c index 63c6fd3f0..6c1a78d2a 100644 --- a/nq/source/sv_pr_cmds.c +++ b/nq/source/sv_pr_cmds.c @@ -584,11 +584,11 @@ PF_newcheckclient (progs_t *pr, unsigned check) vec4f_t org; VectorAdd (SVvector (ent, origin), SVvector (ent, view_ofs), org); org[3] = 1; - leaf = Mod_PointInLeaf (org, sv.worldmodel); + leaf = Mod_PointInLeaf (org, &sv.worldmodel->brush); if (!checkpvs) { checkpvs = set_new_size (sv.worldmodel->brush.visleafs); } - set_assign (checkpvs, Mod_LeafPVS (leaf, sv.worldmodel)); + set_assign (checkpvs, Mod_LeafPVS (leaf, &sv.worldmodel->brush)); return i; } @@ -633,7 +633,7 @@ PF_checkclient (progs_t *pr, void *data) vec4f_t view; VectorAdd (SVvector (self, origin), SVvector (self, view_ofs), view); view[3] = 1; - leaf = Mod_PointInLeaf (view, sv.worldmodel); + leaf = Mod_PointInLeaf (view, &sv.worldmodel->brush); l = (leaf - sv.worldmodel->brush.leafs) - 1; if (!set_is_member (checkpvs, l)) { c_notvis++; diff --git a/qtv/source/client.c b/qtv/source/client.c index ff59fa443..b2dac6e41 100644 --- a/qtv/source/client.c +++ b/qtv/source/client.c @@ -982,17 +982,18 @@ emit_entities (client_t *client, packet_entities_t *to, sizebuf_t *msg) static void add_to_fat_pvs (vec4f_t org, int node_id, server_t *sv) { + auto brush = &sv->worldmodel->brush; while (1) { // if this is a leaf, accumulate the pvs bits if (node_id < 0) { mleaf_t *leaf = sv->worldmodel->brush.leafs + ~node_id; if (leaf->contents != CONTENTS_SOLID) { - set_union (sv->fatpvs, Mod_LeafPVS (leaf, sv->worldmodel)); + set_union (sv->fatpvs, Mod_LeafPVS (leaf, brush)); } return; } - mnode_t *node = sv->worldmodel->brush.nodes + node_id; + mnode_t *node = brush->nodes + node_id; float d = dotf (node->plane, org)[0]; if (d > 8) node_id = node->children[0]; diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index f6ada55eb..1461cd5fe 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1962,7 +1962,7 @@ Host_Frame (float time) vec4f_t origin; origin = Transform_GetWorldPosition (cl.viewstate.camera_transform); - l = Mod_PointInLeaf (origin, cl_world.scene->worldmodel); + l = Mod_PointInLeaf (origin, &cl_world.scene->worldmodel->brush); if (l) asl = l->ambient_sound_level; S_Update (cl.viewstate.camera_transform, asl); diff --git a/qw/source/sv_ents.c b/qw/source/sv_ents.c index d52401298..143e3a3eb 100644 --- a/qw/source/sv_ents.c +++ b/qw/source/sv_ents.c @@ -64,18 +64,19 @@ static void SV_AddToFatPVS (vec4f_t org, int node_id) { float d; + auto brush = &sv.worldmodel->brush; while (1) { // if this is a leaf, accumulate the pvs bits if (node_id < 0) { - mleaf_t *leaf = sv.worldmodel->brush.leafs + ~node_id; + mleaf_t *leaf = brush->leafs + ~node_id; if (leaf->contents != CONTENTS_SOLID) { - set_union (fatpvs, Mod_LeafPVS (leaf, sv.worldmodel)); + set_union (fatpvs, Mod_LeafPVS (leaf, brush)); } return; } - mnode_t *node = sv.worldmodel->brush.nodes + node_id; + mnode_t *node = brush->nodes + node_id; d = dotf (org, node->plane)[0]; if (d > 8) node_id = node->children[0]; diff --git a/qw/source/sv_init.c b/qw/source/sv_init.c index 26379b17c..1f0e1af6f 100644 --- a/qw/source/sv_init.c +++ b/qw/source/sv_init.c @@ -255,12 +255,12 @@ SV_CalcPHS (void) SV_Printf ("Building PHS...\n"); - num = sv.worldmodel->brush.modleafs; + auto brush = &sv.worldmodel->brush; + num = brush->modleafs; sv.pvs = sv_alloc_vis_array (num); vcount = 0; for (i = 0; i < num; i++) { - Mod_LeafPVS_set (sv.worldmodel->brush.leafs + i, sv.worldmodel, 0xff, - &sv.pvs[i]); + Mod_LeafPVS_set (brush->leafs + i, brush, 0xff, &sv.pvs[i]); if (i == 0) continue; vcount += set_count (&sv.pvs[i]); diff --git a/qw/source/sv_pr_cmds.c b/qw/source/sv_pr_cmds.c index 7075bc6cf..ca2f84ae9 100644 --- a/qw/source/sv_pr_cmds.c +++ b/qw/source/sv_pr_cmds.c @@ -505,11 +505,11 @@ PF_newcheckclient (progs_t *pr, int check) vec4f_t org; VectorAdd (SVvector (ent, origin), SVvector (ent, view_ofs), org); org[3] = 1; - leaf = Mod_PointInLeaf (org, sv.worldmodel); + leaf = Mod_PointInLeaf (org, &sv.worldmodel->brush); if (!checkpvs) { checkpvs = set_new_size (sv.worldmodel->brush.visleafs); } - set_assign (checkpvs, Mod_LeafPVS (leaf, sv.worldmodel)); + set_assign (checkpvs, Mod_LeafPVS (leaf, &sv.worldmodel->brush)); return i; } @@ -554,7 +554,7 @@ PF_checkclient (progs_t *pr, void *data) vec4f_t view; VectorAdd (SVvector (self, origin), SVvector (self, view_ofs), view); view[3] = 1; - leaf = Mod_PointInLeaf (view, sv.worldmodel); + leaf = Mod_PointInLeaf (view, &sv.worldmodel->brush); l = (leaf - sv.worldmodel->brush.leafs) - 1; if (!set_is_member (checkpvs, l)) { c_notvis++; diff --git a/qw/source/sv_send.c b/qw/source/sv_send.c index b53e37899..f20cdb158 100644 --- a/qw/source/sv_send.c +++ b/qw/source/sv_send.c @@ -302,7 +302,7 @@ SV_Multicast (const vec3_t origin, int to) mod_brush_t *brush = &sv.worldmodel->brush; vec4f_t org = { VectorExpand (origin), 1 }; - leaf = Mod_PointInLeaf (org, sv.worldmodel); + leaf = Mod_PointInLeaf (org, &sv.worldmodel->brush); if (!leaf) leafnum = 0; else @@ -347,7 +347,7 @@ SV_Multicast (const vec3_t origin, int to) } org = (vec4f_t) {VectorExpand (SVvector (client->edict, origin)), 1}; - leaf = Mod_PointInLeaf (org, sv.worldmodel); + leaf = Mod_PointInLeaf (org, &sv.worldmodel->brush); if (leaf) { // -1 is because pvs rows are 1 based, not 0 based like leafs leafnum = leaf - brush->leafs - 1;