From 4c680808c1f9e67e50be6736776bc8ac7d6e5011 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 04:21:50 +0100 Subject: [PATCH 01/11] dont always call R_PointInSubsector if thing has not moved R_PointInSubsector is quite expensive needs alot of testing --- src/p_map.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/p_map.c b/src/p_map.c index 6c141eb16..782aac138 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1721,7 +1721,10 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmbbox[BOXRIGHT] = x + tmthing->radius; tmbbox[BOXLEFT] = x - tmthing->radius; - newsubsec = R_PointInSubsector(x, y); + if (thing->x != x || thing->y != y || thing->subsector == NULL) + newsubsec = R_PointInSubsector(x, y); + else + newsubsec = thing->subsector; ceilingline = blockingline = NULL; From 7edce19c9c0e2c4cda8e0d6f9b420c1c59096ef5 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 13 Dec 2024 16:36:37 +0100 Subject: [PATCH 02/11] 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 03/11] 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 04/11] 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 05/11] 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 06/11] 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 07/11] 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 08/11] 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; From 0bc95e4b5e256d5324314f8321b6779d1fe74a19 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 23:28:48 +0100 Subject: [PATCH 09/11] speed up camera position checks --- src/p_map.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index ecaf322d2..9b201bab9 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2003,7 +2003,11 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) tmbbox[BOXRIGHT] = x + thiscam->radius; tmbbox[BOXLEFT] = x - thiscam->radius; - newsubsec = R_PointInSubsector(x, y); + if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) + newsubsec = R_PointInSubsectorFast(x, y); + else + newsubsec = thiscam->subsector; + ceilingline = blockingline = NULL; mapcampointer = thiscam; @@ -2175,7 +2179,13 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) // boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) { - subsector_t *s = R_PointInSubsector(x, y); + subsector_t *s; + + if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) + s = R_PointInSubsectorFast(x, y); + else + s = thiscam->subsector; + boolean retval = true; boolean itsatwodlevel = false; UINT8 i; @@ -2378,10 +2388,13 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) radius = MAXRADIUS/2; do { - if (thing->flags & MF_NOCLIP) { + if (thing->flags & MF_NOCLIP) + { tryx = x; tryy = y; - } else { + } + else + { if (x-tryx > radius) tryx += radius; else if (x-tryx < -radius) @@ -2525,14 +2538,16 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) if (!(thing->flags & MF_NOCLIPHEIGHT)) { // Assign thing's standingslope if needed - if (thing->z <= tmfloorz && !(thing->eflags & MFE_VERTICALFLIP)) { + if (thing->z <= tmfloorz && !(thing->eflags & MFE_VERTICALFLIP)) + { if (!startingonground && tmfloorslope) P_HandleSlopeLanding(thing, tmfloorslope); if (thing->momz <= 0) thing->standingslope = tmfloorslope; } - else if (thing->z+thing->height >= tmceilingz && (thing->eflags & MFE_VERTICALFLIP)) { + else if (thing->z+thing->height >= tmceilingz && (thing->eflags & MFE_VERTICALFLIP)) + { if (!startingonground && tmceilingslope) P_HandleSlopeLanding(thing, tmceilingslope); From f9f7090b633075c5e5217713b713284125273100 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 23:30:16 +0100 Subject: [PATCH 10/11] save subsector checks for dedi --- 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 9b201bab9..41ed6895a 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2181,11 +2181,6 @@ boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) { subsector_t *s; - if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) - s = R_PointInSubsectorFast(x, y); - else - s = thiscam->subsector; - boolean retval = true; boolean itsatwodlevel = false; UINT8 i; @@ -2195,6 +2190,11 @@ boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) if (dedicated) // this crashes so don't even try it return false; + if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) + s = R_PointInSubsectorFast(x, y); + else + s = thiscam->subsector; + if (twodlevel) itsatwodlevel = true; else From 2f014bb505375a4d92e27c04301d1b4d99e6ec4e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 3 Jan 2025 15:56:46 +0100 Subject: [PATCH 11/11] apparently this is slower for everything but rendering --- src/d_clisrv.c | 2 +- src/hardware/hw_main.c | 2 +- src/hardware/hw_portal.c | 2 +- src/p_map.c | 4 ++-- src/p_mobj.c | 4 ++-- src/p_setup.c | 4 ++-- src/p_user.c | 4 ++-- src/r_fps.c | 2 +- src/r_main.h | 11 ----------- src/s_sound.c | 4 ++-- 10 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5d04b98e0..4d9270853 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1959,7 +1959,7 @@ static void CL_ReloadReceivedSavegame(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - camera[i].subsector = R_PointInSubsectorFast(camera[i].x, camera[i].y); + camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); } cl_redownloadinggamestate = false; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5eefc9c7e..3737b537d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3172,7 +3172,7 @@ static gl_vissprite_t *HWR_NewVisSprite(void) // Finds a floor through which light does not pass. static fixed_t HWR_OpaqueFloorAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) { - const sector_t *sec = R_PointInSubsectorFast(x, y)->sector; + const sector_t *sec = R_PointInSubsector(x, y)->sector; fixed_t floorz = sec->floorheight; if (sec->ffloors) diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index f26e71331..27d77af2e 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -132,7 +132,7 @@ void HWR_PortalFrame(gl_portal_t* portal) { portalclipline = NULL; portalcullsector = NULL; - viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; + viewsector = R_PointInSubsector(viewx, viewy)->sector; } } diff --git a/src/p_map.c b/src/p_map.c index 41ed6895a..df03bcb76 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2004,7 +2004,7 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) tmbbox[BOXLEFT] = x - thiscam->radius; if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) - newsubsec = R_PointInSubsectorFast(x, y); + newsubsec = R_PointInSubsector(x, y); else newsubsec = thiscam->subsector; @@ -2191,7 +2191,7 @@ boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) return false; if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) - s = R_PointInSubsectorFast(x, y); + s = R_PointInSubsector(x, y); else s = thiscam->subsector; diff --git a/src/p_mobj.c b/src/p_mobj.c index 779546e2b..d0cbe6ae4 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3340,7 +3340,7 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled if (!itsatwodlevel) P_CheckCameraPosition(thiscam->x, thiscam->y, thiscam); - thiscam->subsector = R_PointInSubsectorFast(thiscam->x, thiscam->y); + thiscam->subsector = R_PointInSubsector(thiscam->x, thiscam->y); thiscam->floorz = tmfloorz; thiscam->ceilingz = tmceilingz; @@ -10418,7 +10418,7 @@ void P_PrecipitationEffects(void) for (y = yl; y <= yh; y += RADIUSSTEP) for (x = xl; x <= xh; x += RADIUSSTEP) { - if (R_PointInSubsectorFast((fixed_t)x, (fixed_t)y)->sector->ceilingpic != skyflatnum) // Found the outdoors! + if (R_PointInSubsector((fixed_t)x, (fixed_t)y)->sector->ceilingpic != skyflatnum) // Found the outdoors! continue; newdist = S_CalculateSoundDistance(players[displayplayers[0]].mo->x, players[displayplayers[0]].mo->y, 0, (fixed_t)x, (fixed_t)y, 0); diff --git a/src/p_setup.c b/src/p_setup.c index 0e7f89dcf..477b805db 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2437,7 +2437,7 @@ static void P_SetupCamera(UINT8 pnum, camera_t *cam) cam->y = players[pnum].mo->y; cam->z = players[pnum].mo->z; cam->angle = players[pnum].mo->angle; - cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) + cam->subsector = R_PointInSubsector(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) } else { @@ -2462,7 +2462,7 @@ static void P_SetupCamera(UINT8 pnum, camera_t *cam) cam->y = thing->y; cam->z = thing->z; cam->angle = FixedAngle((fixed_t)thing->angle << FRACBITS); - cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) + cam->subsector = R_PointInSubsector(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) } } diff --git a/src/p_user.c b/src/p_user.c index 3133ee49b..df5a859ab 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3352,7 +3352,7 @@ void P_DemoCameraMovement(camera_t *cam) democam.soundmobj = awayviewmobj_hack; // update subsector to avoid crashes; - cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); + cam->subsector = R_PointInSubsector(cam->x, cam->y); } void P_ResetCamera(player_t *player, camera_t *thiscam) @@ -3394,7 +3394,7 @@ void P_ResetCamera(player_t *player, camera_t *thiscam) thiscam->relativex = 0; - thiscam->subsector = R_PointInSubsectorFast(thiscam->x,thiscam->y); + thiscam->subsector = R_PointInSubsector(thiscam->x,thiscam->y); thiscam->radius = 20*FRACUNIT; thiscam->height = 16*FRACUNIT; diff --git a/src/r_fps.c b/src/r_fps.c index b861dea56..92eb37a32 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -198,7 +198,7 @@ void R_InterpolateView(fixed_t frac, boolean forceinvalid) viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); viewplayer = newview->player; - viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; + viewsector = R_PointInSubsector(viewx, viewy)->sector; R_SetupFreelook(); } diff --git a/src/r_main.h b/src/r_main.h index 523e924d5..c66c9bf55 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -140,17 +140,6 @@ FUNCINLINE static ATTRINLINE subsector_t *R_PointInSubsector(fixed_t x, fixed_t return &subsectors[nodenum & ~NF_SUBSECTOR]; } -// uses R_PointOnSideFast -// SHOULD NOT BE USED FOR ANYTHING GAMEPLAY RELATED!! -FUNCINLINE static ATTRINLINE subsector_t *R_PointInSubsectorFast(fixed_t x, fixed_t y) -{ - size_t nodenum = numnodes-1; - - while (!(nodenum & NF_SUBSECTOR)) - nodenum = nodes[nodenum].children[R_PointOnSideFast(x, y, nodes+nodenum)]; - - return &subsectors[nodenum & ~NF_SUBSECTOR]; -} #define R_PointToDist(x, y) R_PointToDist2(viewx, viewy, x, y) #define R_PointToDist2(px2, py2, px1, py1) FixedHypot((px1) - (px2), (py1) - (py2)) diff --git a/src/s_sound.c b/src/s_sound.c index c770957b6..acd066420 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1031,7 +1031,7 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 INT64 x, y, yl, yh, xl, xh; fixed_t newdist; - if (R_PointInSubsectorFast(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) + if (R_PointInSubsector(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) approx_dist = 0; else { @@ -1044,7 +1044,7 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 for (y = yl; y <= yh; y += FRACUNIT*64) for (x = xl; x <= xh; x += FRACUNIT*64) { - if (R_PointInSubsectorFast(x, y)->sector->ceilingpic == skyflatnum) + if (R_PointInSubsector(x, y)->sector->ceilingpic == skyflatnum) { // Found the outdoors! newdist = S_CalculateSoundDistance(listensource.x, listensource.y, 0, x, y, 0);