diff --git a/src/p_local.h b/src/p_local.h index eb55f5dd4..383469bcc 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -414,13 +414,7 @@ boolean P_DoSpring(mobj_t *spring, mobj_t *object); // // P_SETUP // -typedef struct -{ - UINT8* data; - size_t size; -} reject_t; - -extern reject_t rejectmatrix; // for fast sight rejection +extern UINT8 *rejectmatrix; // for fast sight rejection extern INT32 *blockmaplump; // offsets in blockmap are from here extern INT32 *blockmap; // Big blockmap extern INT32 bmapwidth; diff --git a/src/p_setup.c b/src/p_setup.c index c8403538a..e8e654c3c 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -145,7 +145,7 @@ precipmobj_t **precipblocklinks = NULL; // Speeds up enemy AI by skipping detailed LineOf Sight calculation. // Without special effect, this could be used as a PVS lookup as well. // -reject_t rejectmatrix = {}; +UINT8 *rejectmatrix = NULL; // Maintain single and multi player starting spots. INT32 numdmstarts = 0, numcoopstarts = 0, numredctfstarts = 0, numbluectfstarts = 0; @@ -1780,23 +1780,29 @@ static void P_GroupLines(void) } } - // PK3 version // -- Monster Iestyn 09/01/18 -static void P_LoadReject(UINT8 *data, size_t count) +static void P_LoadReject(UINT8 *data, size_t rejectsize) { - if (!count) // zero length, someone probably used ZDBSP + const size_t neededsize = (numsectors * numsectors + 7) >> 3; + size_t allocsize = rejectsize; + + if (!rejectsize) // zero length, someone probably used ZDBSP { - rejectmatrix.data = NULL; + rejectmatrix = NULL; CONS_Debug(DBG_SETUP, "P_LoadReject: REJECT lump has size 0, will not be loaded\n"); } else { - rejectmatrix.data = Z_Malloc(count, PU_LEVEL, NULL); // allocate memory for the reject matrix - memcpy(rejectmatrix.data, data, count); // copy the data into it - } + if (rejectsize < neededsize) + { + CONS_Alert(CONS_WARNING, "REJECT is %lu byte%s too small. REJECT might be invalid and might crash vanilla clients!\n", (neededsize - rejectsize), (neededsize - rejectsize) == 1 ? "" : "s"); + allocsize = neededsize; + } - rejectmatrix.size = count; + rejectmatrix = Z_Calloc(allocsize, PU_LEVEL, NULL); // allocate memory for the reject matrix + memcpy(rejectmatrix, data, rejectsize); // copy the data into it + } } static void P_LoadMapBSP(const virtres_t* virt) @@ -1833,11 +1839,12 @@ static void P_LoadMapLUT(const virtres_t* virt) // Lookup tables if (virtreject) + { P_LoadReject(virtreject->data, virtreject->size); + } else { - rejectmatrix.data = NULL; - rejectmatrix.size = 0; + rejectmatrix = NULL; } if (!(virtblockmap && P_LoadRawBlockMap(virtblockmap->data, virtblockmap->size))) diff --git a/src/p_sight.c b/src/p_sight.c index 63b87820e..7bde2d737 100644 --- a/src/p_sight.c +++ b/src/p_sight.c @@ -373,13 +373,10 @@ boolean P_CheckSight2(mobj_t *t1, mobj_t *t2, boolean fast) s2 = t2->subsector->sector; pnum = (s1-sectors)*numsectors + (s2-sectors); - if (rejectmatrix.data != NULL) + if (rejectmatrix != NULL) { - const size_t shiftnum = pnum>>3; - // Check in REJECT table. - if (shiftnum < rejectmatrix.size && // check for overflow - (rejectmatrix.data[shiftnum] & (1 << (pnum&7)))) // can't possibly be connected + if (rejectmatrix[pnum>>3] & (1 << (pnum&7))) // can't possibly be connected { return false; } diff --git a/src/y_inter.c b/src/y_inter.c index 19b696b0e..a92392f39 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -586,7 +586,7 @@ void Y_Ticker(void) if (data.rankingsmode && intertic > sorttic+16+(2*TICRATE)) { - INT32 q=0,r=0; + INT32 q = 0, r = 0; boolean kaching = true; for (q = 0; q < data.numplayers; q++)