From 05fa0538aba184eb9368998ccbdb76796ded0e9b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 27 Jul 2021 11:34:17 +0900 Subject: [PATCH] [qw] Count leafs correctly for PHS This fixes some out-by-one bugs caused by there being an obo bug in the original SV_CalcPHS: space was being allocated for numleafs leafs, but numleafs does not count the world-surrounding solid leaf 0, but SV_CalcPHS generates pvs and phs data (just the "everything" set) for leaf 0, which is later used for broadcasts and the like. --- qw/source/sv_init.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/qw/source/sv_init.c b/qw/source/sv_init.c index b63ea71cd..a5cd05aac 100644 --- a/qw/source/sv_init.c +++ b/qw/source/sv_init.c @@ -217,12 +217,14 @@ SV_SaveSpawnparms (void) static set_t * sv_alloc_vis_array (unsigned numleafs) { - unsigned size = SET_SIZE (numleafs); + // the passed in numleafs is the true number of leafs in the map and thus + // does include leaf 0, but pvs bits do not include leaf 0 + unsigned size = SET_SIZE (numleafs - 1); if (size > SET_DEFMAP_SIZE * SET_BITS) { set_t *sets = Hunk_Alloc (numleafs * (sizeof (set_t) + size / 8)); unsigned words = size / SET_BITS; - set_bits_t *bits = (set_bits_t *) (&sets[numleafs] + 1); + set_bits_t *bits = (set_bits_t *) (&sets[numleafs]); for (unsigned i = 0; i < numleafs; i++) { sets[i].size = size; sets[i].map = bits; @@ -230,7 +232,7 @@ sv_alloc_vis_array (unsigned numleafs) } return sets; } else { - set_t *sets = Hunk_Alloc (numleafs * (sizeof (set_t) + size / 8)); + set_t *sets = Hunk_Alloc (numleafs * sizeof (set_t)); for (unsigned i = 0; i < numleafs; i++) { sets[i].size = size; sets[i].map = sets[i].defmap; @@ -252,7 +254,12 @@ SV_CalcPHS (void) int num, i; SV_Printf ("Building PHS...\n"); - num = sv.worldmodel->brush.numleafs; + //numleafs does NOT include the world-surrounding solid leaf at + //brush.leafs[0], so brush.leafs is actually [0]..[numleafs] + //however, pvs bits also do not include leaf 0 as it should not be + //able to see anything (but instead sees everything) + //FIXME make numleafs actual number of leafs? + num = sv.worldmodel->brush.numleafs + 1; sv.pvs = sv_alloc_vis_array (num); vcount = 0;