From 8fa54c1ab4a5d21be0183def857948f6ab6a052a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 15 Aug 2019 14:20:52 +0100 Subject: [PATCH 1/5] Modify P_CheckSector with a modified version of Sal's attempted proper fix for polyobjects crushing, so that we only need to check the polyobject's control sector directly in the waypoints code. This time I've definitely fixed that teleport to ground issue I'm pretty sure, I don't get it in my tests at least. --- src/p_map.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++- src/p_polyobj.c | 8 ++-- 2 files changed, 99 insertions(+), 6 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 95ad02588..6540a99b2 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -3345,6 +3345,7 @@ static boolean PIT_ChangeSector(mobj_t *thing, boolean realcrush) boolean P_CheckSector(sector_t *sector, boolean crunch) { msecnode_t *n; + size_t i; nofit = false; crushchange = crunch; @@ -3359,9 +3360,57 @@ boolean P_CheckSector(sector_t *sector, boolean crunch) // First, let's see if anything will keep it from crushing. + + // Sal: This stupid function chain is required to fix polyobjects not being able to crush. + // Monster Iestyn: don't use P_CheckSector actually just look for objects in the blockmap instead + validcount++; + + for (i = 0; i < sector->linecount; i++) + { + if (sector->lines[i]->polyobj) + { + polyobj_t *po = sector->lines[i]->polyobj; + if (po->validcount == validcount) + continue; // skip if already checked + if (!(po->flags & POF_SOLID)) + continue; + if (po->lines[0]->backsector == sector) // Make sure you're currently checking the control sector + { + INT32 x, y; + po->validcount = validcount; + + for (y = po->blockbox[BOXBOTTOM]; y <= po->blockbox[BOXTOP]; ++y) + { + for (x = po->blockbox[BOXLEFT]; x <= po->blockbox[BOXRIGHT]; ++x) + { + mobj_t *mo; + + if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) + continue; + + mo = blocklinks[y * bmapwidth + x]; + + for (; mo; mo = mo->bnext) + { + // Monster Iestyn: do we need to check if a mobj has already been checked? ...probably not I suspect + + if (!P_MobjTouchingPolyobj(po, mo)) + continue; + + if (!PIT_ChangeSector(mo, false)) + { + nofit = true; + return nofit; + } + } + } + } + } + } + } + if (sector->numattached) { - size_t i; sector_t *sec; for (i = 0; i < sector->numattached; i++) { @@ -3421,9 +3470,53 @@ boolean P_CheckSector(sector_t *sector, boolean crunch) } while (n); // repeat from scratch until all things left are marked valid // Nothing blocked us, so lets crush for real! + + // Sal: This stupid function chain is required to fix polyobjects not being able to crush. + // Monster Iestyn: don't use P_CheckSector actually just look for objects in the blockmap instead + validcount++; + + for (i = 0; i < sector->linecount; i++) + { + if (sector->lines[i]->polyobj) + { + polyobj_t *po = sector->lines[i]->polyobj; + if (po->validcount == validcount) + continue; // skip if already checked + if (!(po->flags & POF_SOLID)) + continue; + if (po->lines[0]->backsector == sector) // Make sure you're currently checking the control sector + { + INT32 x, y; + po->validcount = validcount; + + for (y = po->blockbox[BOXBOTTOM]; y <= po->blockbox[BOXTOP]; ++y) + { + for (x = po->blockbox[BOXLEFT]; x <= po->blockbox[BOXRIGHT]; ++x) + { + mobj_t *mo; + + if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) + continue; + + mo = blocklinks[y * bmapwidth + x]; + + for (; mo; mo = mo->bnext) + { + // Monster Iestyn: do we need to check if a mobj has already been checked? ...probably not I suspect + + if (!P_MobjTouchingPolyobj(po, mo)) + continue; + + PIT_ChangeSector(mo, true); + return nofit; + } + } + } + } + } + } if (sector->numattached) { - size_t i; sector_t *sec; for (i = 0; i < sector->numattached; i++) { diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 82c57c85b..21d8af5f2 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1860,7 +1860,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th) po->lines[0]->backsector->floorheight = target->z - amtz; po->lines[0]->backsector->ceilingheight = target->z + amtz; // Sal: Remember to check your sectors! - P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); + //P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); // Apply action to mirroring polyobjects as well start = 0; @@ -1874,7 +1874,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th) po->lines[0]->backsector->floorheight += diffz; // move up/down by same amount as the parent did po->lines[0]->backsector->ceilingheight += diffz; // Sal: Remember to check your sectors! - P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); + //P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); } @@ -2037,7 +2037,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th) po->lines[0]->backsector->floorheight += momz; po->lines[0]->backsector->ceilingheight += momz; // Sal: Remember to check your sectors! - P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); // frontsector is NEEDED for crushing + //P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); // frontsector is NEEDED for crushing P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); // backsector may not be necessary, but just in case // Apply action to mirroring polyobjects as well @@ -2052,7 +2052,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th) po->lines[0]->backsector->floorheight += momz; po->lines[0]->backsector->ceilingheight += momz; // Sal: Remember to check your sectors! - P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); + //P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); } } From 27dd99ae72366c09cf884e45d6bc60238524ae69 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 3 Aug 2019 19:06:45 +0100 Subject: [PATCH 2/5] Remove commented out P_CheckSector calls and add extra comments explaining the situation --- src/p_polyobj.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 21d8af5f2..ba01ee442 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1860,7 +1860,8 @@ void T_PolyObjWaypoint(polywaypoint_t *th) po->lines[0]->backsector->floorheight = target->z - amtz; po->lines[0]->backsector->ceilingheight = target->z + amtz; // Sal: Remember to check your sectors! - //P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); + // Monster Iestyn: we only need to bother with the back sector, now that P_CheckSector automatically checks the blockmap + // updating objects in the front one too just added teleporting to ground bugs P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); // Apply action to mirroring polyobjects as well start = 0; @@ -1874,7 +1875,8 @@ void T_PolyObjWaypoint(polywaypoint_t *th) po->lines[0]->backsector->floorheight += diffz; // move up/down by same amount as the parent did po->lines[0]->backsector->ceilingheight += diffz; // Sal: Remember to check your sectors! - //P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); + // Monster Iestyn: we only need to bother with the back sector, now that P_CheckSector automatically checks the blockmap + // updating objects in the front one too just added teleporting to ground bugs P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); } @@ -2037,8 +2039,9 @@ void T_PolyObjWaypoint(polywaypoint_t *th) po->lines[0]->backsector->floorheight += momz; po->lines[0]->backsector->ceilingheight += momz; // Sal: Remember to check your sectors! - //P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); // frontsector is NEEDED for crushing - P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); // backsector may not be necessary, but just in case + // Monster Iestyn: we only need to bother with the back sector, now that P_CheckSector automatically checks the blockmap + // updating objects in the front one too just added teleporting to ground bugs + P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); // Apply action to mirroring polyobjects as well start = 0; @@ -2052,7 +2055,8 @@ void T_PolyObjWaypoint(polywaypoint_t *th) po->lines[0]->backsector->floorheight += momz; po->lines[0]->backsector->ceilingheight += momz; // Sal: Remember to check your sectors! - //P_CheckSector(po->lines[0]->frontsector, (boolean)(po->damage)); + // Monster Iestyn: we only need to bother with the back sector, now that P_CheckSector automatically checks the blockmap + // updating objects in the front one too just added teleporting to ground bugs P_CheckSector(po->lines[0]->backsector, (boolean)(po->damage)); } } From c8d1dd3be8558408cc82396e09ce35c0856d3936 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 7 Aug 2019 23:27:26 +0100 Subject: [PATCH 3/5] P_LineOpening: set int32 max/min as defaults for opentop, openbottom etc if a linedef you touched belongs to a polyobjetc. the only thing that really matters in this scenario is the polyobject itself after all! # Conflicts: # src/p_maputl.c --- src/p_maputl.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/p_maputl.c b/src/p_maputl.c index 1be57399c..bd17ecf4a 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -517,6 +517,20 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) I_Assert(front != NULL); I_Assert(back != NULL); +#ifdef POLYOBJECTS + if (linedef->polyobj) + { + // set these defaults so that polyobjects don't interfere with collision above or below them + opentop = INT32_MAX; + openbottom = INT32_MIN; + highceiling = INT32_MIN; + lowfloor = INT32_MAX; +#ifdef ESLOPE + opentopslope = openbottomslope = NULL; +#endif + } + else +#endif { // Set open and high/low values here fixed_t frontheight, backheight; From cda81cc1660cded2836e4b9130daadb0edb0c497 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Aug 2019 16:37:09 +0100 Subject: [PATCH 4/5] Edit a lot of the rest of the polyobject-related code in P_LineOpening to make more sense and be more optimised. * If you collide with a line belonging to a polyobject, you should NEVER have to care about any FOFs that might be present in either sector of the linedef. This could lead to colliding with ghostly FOFs that aren't actually there or something dumb, if someone decided to give either of the polyobject's control sectors FOFs for some reason. We don't want that, obviously. * Polyobjects without POF_CLIPPLANE apparently are supposed to have a top and bottom "physical" height of value INT32_MAX and _MIN respectively, according to P_CheckPosition ...let's be consistent with this. * Finally, there is no more need for that back = front nonsense hack anymore with my changes made. # Conflicts: # src/p_maputl.c --- src/p_maputl.c | 85 ++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index bd17ecf4a..a98cc0340 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -500,19 +500,8 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) return; } - // Treat polyobjects kind of like 3D Floors -#ifdef POLYOBJECTS - if (linedef->polyobj && (linedef->polyobj->flags & POF_TESTHEIGHT)) - { - front = linedef->frontsector; - back = linedef->frontsector; - } - else -#endif - { - front = linedef->frontsector; - back = linedef->backsector; - } + front = linedef->frontsector; + back = linedef->backsector; I_Assert(front != NULL); I_Assert(back != NULL); @@ -636,13 +625,46 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) } } } - - // Check for fake floors in the sector. - if (front->ffloors || back->ffloors #ifdef POLYOBJECTS - || linedef->polyobj + if (linedef->polyobj) + { + // Treat polyobj's backsector like a 3D Floor + if (linedef->polyobj->flags & POF_TESTHEIGHT) + { + const sector_t *polysec = linedef->backsector; + fixed_t polytop, polybottom; + fixed_t delta1, delta2; + + if (linedef->polyobj->flags & POF_CLIPPLANES) + { + polytop = polysec->ceilingheight; + polybottom = polysec->floorheight; + } + else + { + polytop = INT32_MAX; + polybottom = INT32_MIN; + } + + delta1 = abs(mobj->z - (polybottom + ((polytop - polybottom)/2))); + delta2 = abs(thingtop - (polybottom + ((polytop - polybottom)/2))); + + if (polybottom < opentop && delta1 >= delta2) + opentop = polybottom; + else if (polybottom < highceiling && delta1 >= delta2) + highceiling = polybottom; + + if (polytop > openbottom && delta1 < delta2) + openbottom = polytop; + else if (polytop > lowfloor && delta1 < delta2) + lowfloor = polytop; + } + // otherwise don't do anything special, pretend there's nothing else there + } + else #endif - ) + // Check for fake floors in the sector. + if (front->ffloors || back->ffloors) { ffloor_t *rover; @@ -744,33 +766,6 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) } } -#ifdef POLYOBJECTS - // Treat polyobj's backsector like a 3D Floor - if (linedef->polyobj && (linedef->polyobj->flags & POF_TESTHEIGHT)) - { - const sector_t *polysec = linedef->backsector; - - delta1 = abs(mobj->z - (polysec->floorheight + ((polysec->ceilingheight - polysec->floorheight)/2))); - delta2 = abs(thingtop - (polysec->floorheight + ((polysec->ceilingheight - polysec->floorheight)/2))); - if (polysec->floorheight < lowestceiling && delta1 >= delta2) { - lowestceiling = polysec->floorheight; -#ifdef ESLOPE - ceilingslope = NULL; -#endif - } - else if (polysec->floorheight < highestceiling && delta1 >= delta2) - highestceiling = polysec->floorheight; - - if (polysec->ceilingheight > highestfloor && delta1 < delta2) { - highestfloor = polysec->ceilingheight; -#ifdef ESLOPE - floorslope = NULL; -#endif - } - else if (polysec->ceilingheight > lowestfloor && delta1 < delta2) - lowestfloor = polysec->ceilingheight; - } -#endif if (highestceiling < highceiling) highceiling = highestceiling; From bbefc3b7f4c8d48b3b815c1e099f466ad7073631 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Aug 2019 23:04:47 +0100 Subject: [PATCH 5/5] After looking at the FOF part of P_LineOpening for a while I now realise many of these variables aren't even necessary, so I removed them all. (Naturally I did the same to the camera equivalent) # Conflicts: # src/p_maputl.c --- src/p_maputl.c | 117 +++++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 81 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index a98cc0340..5368c137e 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -418,10 +418,6 @@ void P_CameraLineOpening(line_t *linedef) if (front->ffloors || back->ffloors) { ffloor_t *rover; - fixed_t highestceiling = highceiling; - fixed_t lowestceiling = opentop; - fixed_t highestfloor = openbottom; - fixed_t lowestfloor = lowfloor; fixed_t delta1, delta2; // Check for frontsector's fake floors @@ -437,15 +433,15 @@ void P_CameraLineOpening(line_t *linedef) delta1 = abs(mapcampointer->z - (bottomheight + ((topheight - bottomheight)/2))); delta2 = abs(thingtop - (bottomheight + ((topheight - bottomheight)/2))); - if (bottomheight < lowestceiling && delta1 >= delta2) - lowestceiling = bottomheight; - else if (bottomheight < highestceiling && delta1 >= delta2) - highestceiling = bottomheight; + if (bottomheight < opentop && delta1 >= delta2) + opentop = bottomheight; + else if (bottomheight < highceiling && delta1 >= delta2) + highceiling = bottomheight; - if (topheight > highestfloor && delta1 < delta2) - highestfloor = topheight; - else if (topheight > lowestfloor && delta1 < delta2) - lowestfloor = topheight; + if (topheight > openbottom && delta1 < delta2) + openbottom = topheight; + else if (topheight > lowfloor && delta1 < delta2) + lowfloor = topheight; } // Check for backsectors fake floors @@ -461,28 +457,16 @@ void P_CameraLineOpening(line_t *linedef) delta1 = abs(mapcampointer->z - (bottomheight + ((topheight - bottomheight)/2))); delta2 = abs(thingtop - (bottomheight + ((topheight - bottomheight)/2))); - if (bottomheight < lowestceiling && delta1 >= delta2) - lowestceiling = bottomheight; - else if (bottomheight < highestceiling && delta1 >= delta2) - highestceiling = bottomheight; + if (bottomheight < opentop && delta1 >= delta2) + opentop = bottomheight; + else if (bottomheight < highceiling && delta1 >= delta2) + highceiling = bottomheight; - if (topheight > highestfloor && delta1 < delta2) - highestfloor = topheight; - else if (topheight > lowestfloor && delta1 < delta2) - lowestfloor = topheight; + if (topheight > openbottom && delta1 < delta2) + openbottom = topheight; + else if (topheight > lowfloor && delta1 < delta2) + lowfloor = topheight; } - - if (highestceiling < highceiling) - highceiling = highestceiling; - - if (highestfloor > openbottom) - openbottom = highestfloor; - - if (lowestceiling < opentop) - opentop = lowestceiling; - - if (lowestfloor > lowfloor) - lowfloor = lowestfloor; } openrange = opentop - openbottom; return; @@ -667,16 +651,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (front->ffloors || back->ffloors) { ffloor_t *rover; - - fixed_t highestceiling = highceiling; - fixed_t lowestceiling = opentop; - fixed_t highestfloor = openbottom; - fixed_t lowestfloor = lowfloor; fixed_t delta1, delta2; -#ifdef ESLOPE - pslope_t *ceilingslope = opentopslope; - pslope_t *floorslope = openbottomslope; -#endif // Check for frontsector's fake floors for (rover = front->ffloors; rover; rover = rover->next) @@ -699,26 +674,26 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (delta1 >= delta2 && !(rover->flags & FF_PLATFORM)) // thing is below FOF { - if (bottomheight < lowestceiling) { - lowestceiling = bottomheight; + if (bottomheight < opentop) { + opentop = bottomheight; #ifdef ESLOPE - ceilingslope = *rover->b_slope; + opentopslope = *rover->b_slope; #endif } - else if (bottomheight < highestceiling) - highestceiling = bottomheight; + else if (bottomheight < highceiling) + highceiling = bottomheight; } if (delta1 < delta2 && !(rover->flags & FF_REVERSEPLATFORM)) // thing is above FOF { - if (topheight > highestfloor) { - highestfloor = topheight; + if (topheight > openbottom) { + openbottom = topheight; #ifdef ESLOPE - floorslope = *rover->t_slope; + openbottomslope = *rover->t_slope; #endif } - else if (topheight > lowestfloor) - lowestfloor = topheight; + else if (topheight > lowfloor) + lowfloor = topheight; } } @@ -743,48 +718,28 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (delta1 >= delta2 && !(rover->flags & FF_PLATFORM)) // thing is below FOF { - if (bottomheight < lowestceiling) { - lowestceiling = bottomheight; + if (bottomheight < opentop) { + opentop = bottomheight; #ifdef ESLOPE - ceilingslope = *rover->b_slope; + opentopslope = *rover->b_slope; #endif } - else if (bottomheight < highestceiling) - highestceiling = bottomheight; + else if (bottomheight < highceiling) + highceiling = bottomheight; } if (delta1 < delta2 && !(rover->flags & FF_REVERSEPLATFORM)) // thing is above FOF { - if (topheight > highestfloor) { - highestfloor = topheight; + if (topheight > openbottom) { + openbottom = topheight; #ifdef ESLOPE - floorslope = *rover->t_slope; + openbottomslope = *rover->t_slope; #endif } - else if (topheight > lowestfloor) - lowestfloor = topheight; + else if (topheight > lowfloor) + lowfloor = topheight; } } - - if (highestceiling < highceiling) - highceiling = highestceiling; - - if (highestfloor > openbottom) { - openbottom = highestfloor; -#ifdef ESLOPE - openbottomslope = floorslope; -#endif - } - - if (lowestceiling < opentop) { - opentop = lowestceiling; -#ifdef ESLOPE - opentopslope = ceilingslope; -#endif - } - - if (lowestfloor > lowfloor) - lowfloor = lowestfloor; } }