From 7edce19c9c0e2c4cda8e0d6f9b420c1c59096ef5 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 13 Dec 2024 16:36:37 +0100 Subject: [PATCH 1/7] add P_CheckPositionShadow just for shadow mobjs its basically just R_GetShadowZ from the render based shadows from srb2 lmao hope this is synchsafe --- src/p_map.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/src/p_map.c b/src/p_map.c index 782aac138..8786f2f90 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1665,6 +1665,8 @@ static boolean PIT_CheckLine(line_t *ld) // MOVEMENT CLIPPING // ========================================================================= +static boolean P_CheckPositionShadow(mobj_t *thing, fixed_t x, fixed_t y); + // // P_CheckPosition // This is purely informative, nothing is modified @@ -1710,6 +1712,12 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) I_Error("Previously-removed Thing of type %u crashes P_CheckPosition!", thing->type); #endif + // crappy optimization lmao hope this works out + if (thing->type == MT_SHADOW) + { + return P_CheckPositionShadow(thing, x, y); + } + P_SetTarget(&tmthing, thing); tmflags = thing->flags; @@ -1949,6 +1957,108 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) return blockval; } +// P_CheckPosition but its actually R_GetShadowZ from SRB2 +// this checks for less and keeps everything simpler +// since i dont want VISUAL shadows crapping by checking for a crapton of stuff +static boolean P_CheckPositionShadow(mobj_t *thing, fixed_t x, fixed_t y) +{ + subsector_t *newsubsec; + + P_SetTarget(&tmthing, thing); + tmflags = thing->flags; + + tmx = x; + tmy = y; + + tmbbox[BOXTOP] = y + tmthing->radius; + tmbbox[BOXBOTTOM] = y - tmthing->radius; + tmbbox[BOXRIGHT] = x + tmthing->radius; + tmbbox[BOXLEFT] = x - tmthing->radius; + + if (thing->x != x || thing->y != y || thing->subsector == NULL) + newsubsec = R_PointInSubsector(x, y); + else + newsubsec = thing->subsector; + + ceilingline = blockingline = NULL; + + // The base floor / ceiling is from the subsector + // that contains the point. + // Any contacted lines the step closer together + // will adjust them. + tmfloorz = tmdropoffz = P_GetFloorZ(thing, newsubsec->sector, x, y, NULL); //newsubsec->sector->floorheight; + tmceilingz = P_GetCeilingZ(thing, newsubsec->sector, x, y, NULL); //newsubsec->sector->ceilingheight; + tmfloorslope = newsubsec->sector->f_slope; + tmceilingslope = newsubsec->sector->c_slope; + + const fixed_t halfHeight = (thing->z + (thing->height >> 1)); + + // Check list of fake floors and see if tmfloorz/tmceilingz need to be altered. + if (newsubsec->sector->ffloors) + { + ffloor_t *rover; + + for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) + { + fixed_t topheight, bottomheight; + + if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES) || (rover->alpha < 90 && !(rover->flags & FF_SWIMMABLE))) + continue; + + topheight = P_GetFOFTopZ(thing, newsubsec->sector, rover, x, y, NULL); + bottomheight = P_GetFOFBottomZ(thing, newsubsec->sector, rover, x, y, NULL); + + if (topheight < halfHeight && topheight > tmfloorz) + { + tmfloorz = tmdropoffz = topheight; + tmfloorslope = *rover->t_slope; + } + if (bottomheight > halfHeight && bottomheight < tmfloorz) + { + tmceilingz = tmdrpoffceilz = bottomheight; + tmceilingslope = *rover->b_slope; + } + } + } + + tmfloorthing = NULL; + tmhitthing = NULL; + + // Check polyobjects and see if groundz needs to be altered + // This isn't very precise, but the precise method was far too slow. + // (Polies are just naturally pretty flickery anyway :P) + polyobj_t *po = newsubsec->polyList; + fixed_t z; + + while (po) + { + if (!(po->flags & POF_RENDERPLANES) || !P_MobjInsidePolyobj(po, tmthing)) + { + po = (polyobj_t *)(po->link.next); + continue; + } + + // We're inside it! Yess... + z = po->lines[0]->backsector->floorheight; + if (z < halfHeight && z > tmfloorz) + { + tmfloorz = z; + tmfloorslope = NULL; + } + + z = po->lines[0]->backsector->ceilingheight; + if (z > halfHeight && z < tmfloorz) + { + tmceilingz = z; + tmceilingslope = NULL; + } + + po = (polyobj_t *)(po->link.next); + } + + return true; +} + static const fixed_t hoopblockdist = 16*FRACUNIT + 8*FRACUNIT; static const fixed_t hoophalfheight = (56*FRACUNIT)/2; From 8611e70ba3a6234ce92869bd2e33b4284ed13ca9 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 13 Dec 2024 16:45:22 +0100 Subject: [PATCH 2/7] smol calc optimization P_Checkposition --- src/p_map.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 8786f2f90..cce61c67c 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1754,7 +1754,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) { - fixed_t topheight, bottomheight; + fixed_t topheight, bottomheight, midheight; if (!(rover->flags & FF_EXISTS)) continue; @@ -1819,10 +1819,10 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) continue; } - delta1 = thing->z - (bottomheight - + ((topheight - bottomheight)/2)); - delta2 = thingtop - (bottomheight - + ((topheight - bottomheight)/2)); + midheight = (bottomheight + ((topheight - bottomheight)/2)); + + delta1 = thing->z - midheight; + delta2 = thingtop - midheight; if (topheight > tmfloorz && abs(delta1) < abs(delta2) && !(rover->flags & FF_REVERSEPLATFORM)) From 6f6dff48972b30fe8a09640522b25289529b72f3 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 13 Dec 2024 16:46:49 +0100 Subject: [PATCH 3/7] only check for polyobjects in the blockmap if there even are polyobjects this saves the trouble of iterating through the blockmap every single time P_CheckPosition is called if there are no polyobjects present on the map --- src/p_map.c | 59 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index cce61c67c..71da1b24f 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1853,10 +1853,13 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) BMBOUNDFIX(xl, xh, yl, yh); // Check polyobjects and see if tmfloorz/tmceilingz need to be altered + // do we really have to iterate through the complete blockmap for polyobjects if there are no polyobjects on the map? + if (numPolyObjects) { validcount++; for (by = yl; by <= yh; by++) + { for (bx = xl; bx <= xh; bx++) { INT32 offset; @@ -1907,12 +1910,14 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) delta1 = thing->z - (polybottom + ((polytop - polybottom)/2)); delta2 = thingtop - (polybottom + ((polytop - polybottom)/2)); - if (polytop > tmfloorz && abs(delta1) < abs(delta2)) { + if (polytop > tmfloorz && abs(delta1) < abs(delta2)) + { tmfloorz = tmdropoffz = polytop; tmfloorslope = NULL; } - if (polybottom < tmceilingz && abs(delta1) >= abs(delta2)) { + if (polybottom < tmceilingz && abs(delta1) >= abs(delta2)) + { tmceilingz = tmdrpoffceilz = polybottom; tmceilingslope = NULL; } @@ -1920,6 +1925,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) plink = (polymaplink_t *)(plink->link.next); } } + } } // tmfloorthing is set when tmfloorz comes from a thing's top @@ -2027,33 +2033,38 @@ static boolean P_CheckPositionShadow(mobj_t *thing, fixed_t x, fixed_t y) // Check polyobjects and see if groundz needs to be altered // This isn't very precise, but the precise method was far too slow. // (Polies are just naturally pretty flickery anyway :P) - polyobj_t *po = newsubsec->polyList; - fixed_t z; - while (po) + // do we really have to iterate through the complete blockmap for polyobjects if there are no polyobjects on the map? + if (numPolyObjects) { - if (!(po->flags & POF_RENDERPLANES) || !P_MobjInsidePolyobj(po, tmthing)) + polyobj_t *po = newsubsec->polyList; + fixed_t z; + + while (po) { + if (!(po->flags & POF_RENDERPLANES) || !P_MobjInsidePolyobj(po, tmthing)) + { + po = (polyobj_t *)(po->link.next); + continue; + } + + // We're inside it! Yess... + z = po->lines[0]->backsector->floorheight; + if (z < halfHeight && z > tmfloorz) + { + tmfloorz = z; + tmfloorslope = NULL; + } + + z = po->lines[0]->backsector->ceilingheight; + if (z > halfHeight && z < tmfloorz) + { + tmceilingz = z; + tmceilingslope = NULL; + } + po = (polyobj_t *)(po->link.next); - continue; } - - // We're inside it! Yess... - z = po->lines[0]->backsector->floorheight; - if (z < halfHeight && z > tmfloorz) - { - tmfloorz = z; - tmfloorslope = NULL; - } - - z = po->lines[0]->backsector->ceilingheight; - if (z > halfHeight && z < tmfloorz) - { - tmceilingz = z; - tmceilingslope = NULL; - } - - po = (polyobj_t *)(po->link.next); } return true; From 7c7582f09b80a2ace2e91d7b92f105805f4c530e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 13 Dec 2024 16:50:10 +0100 Subject: [PATCH 4/7] forgor about cameracheckposition --- src/p_map.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_map.c b/src/p_map.c index 71da1b24f..a7461447a 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2192,6 +2192,8 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) BMBOUNDFIX(xl, xh, yl, yh); // Check polyobjects and see if tmfloorz/tmceilingz need to be altered + // do we really have to iterate through the complete blockmap for polyobjects if there are no polyobjects on the map? + if (numPolyObjects) { validcount++; From 909307f5ce074030b483116d7f40c67ab0e76529 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 14 Dec 2024 16:00:01 +0100 Subject: [PATCH 5/7] only check if polyobjcst are on the map --- src/p_mobj.c | 81 +++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index b7c86cbd5..72002a65d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -2472,55 +2472,58 @@ static void P_PlayerZMovement(mobj_t *mo) msecnode_t *node; boolean stopmovecut = false; - for (node = mo->touching_sectorlist; node; node = node->m_sectorlist_next) + if (numPolyObjects) { - sector_t *sec = node->m_sector; - subsector_t *newsubsec; - size_t i; - - for (i = 0; i < numsubsectors; i++) + for (node = mo->touching_sectorlist; node; node = node->m_sectorlist_next) { - newsubsec = &subsectors[i]; + sector_t *sec = node->m_sector; + subsector_t *newsubsec; + size_t i; - if (newsubsec->sector != sec) - continue; - - if (!newsubsec->polyList) - continue; - - polyobj_t *po = newsubsec->polyList; - sector_t *polysec; - - while(po) + for (i = 0; i < numsubsectors; i++) { - if (!P_MobjInsidePolyobj(po, mo) || !(po->flags & POF_SOLID)) - { - po = (polyobj_t *)(po->link.next); + newsubsec = &subsectors[i]; + + if (newsubsec->sector != sec) continue; - } - // We're inside it! Yess... - polysec = po->lines[0]->backsector; - - // Moving polyobjects should act like conveyors if the player lands on one. (I.E. none of the momentum cut thing below) -Red - if ((mo->z == polysec->ceilingheight || mo->z+mo->height == polysec->floorheight) && po->thinker) - stopmovecut = true; - - if (!(po->flags & POF_LDEXEC)) - { - po = (polyobj_t *)(po->link.next); + if (!newsubsec->polyList) continue; - } - if (mo->z == polysec->ceilingheight) + polyobj_t *po = newsubsec->polyList; + sector_t *polysec; + + while(po) { - // We're landing on a PO, so check for - // a linedef executor. - // Trigger tags are 32000 + the PO's ID number. - P_LinedefExecute((INT16)(32000 + po->id), mo, NULL); - } + if (!P_MobjInsidePolyobj(po, mo) || !(po->flags & POF_SOLID)) + { + po = (polyobj_t *)(po->link.next); + continue; + } - po = (polyobj_t *)(po->link.next); + // We're inside it! Yess... + polysec = po->lines[0]->backsector; + + // Moving polyobjects should act like conveyors if the player lands on one. (I.E. none of the momentum cut thing below) -Red + if ((mo->z == polysec->ceilingheight || mo->z+mo->height == polysec->floorheight) && po->thinker) + stopmovecut = true; + + if (!(po->flags & POF_LDEXEC)) + { + po = (polyobj_t *)(po->link.next); + continue; + } + + if (mo->z == polysec->ceilingheight) + { + // We're landing on a PO, so check for + // a linedef executor. + // Trigger tags are 32000 + the PO's ID number. + P_LinedefExecute((INT16)(32000 + po->id), mo, NULL); + } + + po = (polyobj_t *)(po->link.next); + } } } } From bbf4de4f5e034bd6b5eb2e1f0fd95732fc10d5d0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Dec 2024 18:25:03 +0100 Subject: [PATCH 6/7] Revert "add P_CheckPositionShadow just for shadow mobjs" This reverts commit 7edce19c9c0e2c4cda8e0d6f9b420c1c59096ef5. --- src/p_map.c | 115 ---------------------------------------------------- 1 file changed, 115 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index a7461447a..dae67b073 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1665,8 +1665,6 @@ static boolean PIT_CheckLine(line_t *ld) // MOVEMENT CLIPPING // ========================================================================= -static boolean P_CheckPositionShadow(mobj_t *thing, fixed_t x, fixed_t y); - // // P_CheckPosition // This is purely informative, nothing is modified @@ -1712,12 +1710,6 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) I_Error("Previously-removed Thing of type %u crashes P_CheckPosition!", thing->type); #endif - // crappy optimization lmao hope this works out - if (thing->type == MT_SHADOW) - { - return P_CheckPositionShadow(thing, x, y); - } - P_SetTarget(&tmthing, thing); tmflags = thing->flags; @@ -1963,113 +1955,6 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) return blockval; } -// P_CheckPosition but its actually R_GetShadowZ from SRB2 -// this checks for less and keeps everything simpler -// since i dont want VISUAL shadows crapping by checking for a crapton of stuff -static boolean P_CheckPositionShadow(mobj_t *thing, fixed_t x, fixed_t y) -{ - subsector_t *newsubsec; - - P_SetTarget(&tmthing, thing); - tmflags = thing->flags; - - tmx = x; - tmy = y; - - tmbbox[BOXTOP] = y + tmthing->radius; - tmbbox[BOXBOTTOM] = y - tmthing->radius; - tmbbox[BOXRIGHT] = x + tmthing->radius; - tmbbox[BOXLEFT] = x - tmthing->radius; - - if (thing->x != x || thing->y != y || thing->subsector == NULL) - newsubsec = R_PointInSubsector(x, y); - else - newsubsec = thing->subsector; - - ceilingline = blockingline = NULL; - - // The base floor / ceiling is from the subsector - // that contains the point. - // Any contacted lines the step closer together - // will adjust them. - tmfloorz = tmdropoffz = P_GetFloorZ(thing, newsubsec->sector, x, y, NULL); //newsubsec->sector->floorheight; - tmceilingz = P_GetCeilingZ(thing, newsubsec->sector, x, y, NULL); //newsubsec->sector->ceilingheight; - tmfloorslope = newsubsec->sector->f_slope; - tmceilingslope = newsubsec->sector->c_slope; - - const fixed_t halfHeight = (thing->z + (thing->height >> 1)); - - // Check list of fake floors and see if tmfloorz/tmceilingz need to be altered. - if (newsubsec->sector->ffloors) - { - ffloor_t *rover; - - for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) - { - fixed_t topheight, bottomheight; - - if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES) || (rover->alpha < 90 && !(rover->flags & FF_SWIMMABLE))) - continue; - - topheight = P_GetFOFTopZ(thing, newsubsec->sector, rover, x, y, NULL); - bottomheight = P_GetFOFBottomZ(thing, newsubsec->sector, rover, x, y, NULL); - - if (topheight < halfHeight && topheight > tmfloorz) - { - tmfloorz = tmdropoffz = topheight; - tmfloorslope = *rover->t_slope; - } - if (bottomheight > halfHeight && bottomheight < tmfloorz) - { - tmceilingz = tmdrpoffceilz = bottomheight; - tmceilingslope = *rover->b_slope; - } - } - } - - tmfloorthing = NULL; - tmhitthing = NULL; - - // Check polyobjects and see if groundz needs to be altered - // This isn't very precise, but the precise method was far too slow. - // (Polies are just naturally pretty flickery anyway :P) - - // do we really have to iterate through the complete blockmap for polyobjects if there are no polyobjects on the map? - if (numPolyObjects) - { - polyobj_t *po = newsubsec->polyList; - fixed_t z; - - while (po) - { - if (!(po->flags & POF_RENDERPLANES) || !P_MobjInsidePolyobj(po, tmthing)) - { - po = (polyobj_t *)(po->link.next); - continue; - } - - // We're inside it! Yess... - z = po->lines[0]->backsector->floorheight; - if (z < halfHeight && z > tmfloorz) - { - tmfloorz = z; - tmfloorslope = NULL; - } - - z = po->lines[0]->backsector->ceilingheight; - if (z > halfHeight && z < tmfloorz) - { - tmceilingz = z; - tmceilingslope = NULL; - } - - po = (polyobj_t *)(po->link.next); - } - } - - return true; -} - static const fixed_t hoopblockdist = 16*FRACUNIT + 8*FRACUNIT; static const fixed_t hoophalfheight = (56*FRACUNIT)/2; From b24c59ce5548e692749c62d3cd1245c2884cbf93 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Dec 2024 18:38:09 +0100 Subject: [PATCH 7/7] fix compile --- src/p_mobj.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 68217cd5e..779546e2b 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3237,7 +3237,6 @@ void P_DestroyRobots(void) // the below is chasecam only, if you're curious. check out P_CalcPostImg in p_user.c for first person static void P_CalcChasePostImg(player_t *player, camera_t *thiscam) { - boolean itsatwodlevel = false; const boolean flipcam = (player->pflags & PF_FLIPCAM && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); UINT16 postimgflags = 0; UINT8 i; @@ -3247,21 +3246,6 @@ static void P_CalcChasePostImg(player_t *player, camera_t *thiscam) if (flipcam) postimgflags |= POSTIMG_FLIP; - if (twodlevel) - itsatwodlevel = true; - else - { - for (i = 0; i <= splitscreen; i++) - { - if (thiscam == &camera[i] && players[displayplayers[i]].mo - && (players[displayplayers[i]].mo->flags2 & MF2_TWOD)) - { - itsatwodlevel = true; - break; - } - } - } - if (player->awayviewtics && player->awayviewmobj && !P_MobjWasRemoved(player->awayviewmobj)) // Camera must obviously exist { camera_t dummycam; @@ -3303,12 +3287,30 @@ static void P_CalcChasePostImg(player_t *player, camera_t *thiscam) // Process the mobj-ish required functions of the camera boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled) { + boolean itsatwodlevel = false; + UINT8 i; + // This can happen when joining if (thiscam->subsector == NULL || thiscam->subsector->sector == NULL) return true; P_CalcChasePostImg(player, thiscam); + if (twodlevel) + itsatwodlevel = true; + else + { + for (i = 0; i <= splitscreen; i++) + { + if (thiscam == &camera[i] && players[displayplayers[i]].mo + && (players[displayplayers[i]].mo->flags2 & MF2_TWOD)) + { + itsatwodlevel = true; + break; + } + } + } + if (thiscam->momx || thiscam->momy) { if (!P_TryCameraMove(thiscam->x + thiscam->momx, thiscam->y + thiscam->momy, thiscam)) // Never fails for 2D mode. @@ -3336,7 +3338,7 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled } if (!itsatwodlevel) - P_CheckCameraPosition(thiscam->x, thiscam->y, thiscam); + P_CheckCameraPosition(thiscam->x, thiscam->y, thiscam); thiscam->subsector = R_PointInSubsectorFast(thiscam->x, thiscam->y); thiscam->floorz = tmfloorz;