diff --git a/src/d_clisrv.c b/src/d_clisrv.c index e654512c0..c8041d431 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1358,7 +1358,7 @@ static void CL_ReloadReceivedSavegame(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); + camera[i].subsector = R_PointInSubsectorFast(camera[i].x, camera[i].y); } cl_redownloadinggamestate = false; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 7d8efb29e..4e8261e68 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3076,7 +3076,7 @@ static void HWR_RenderBSPNode(INT32 bspnum) bsp = &nodes[bspnum]; // Decide which side the view point is on. - side = R_PointOnSide(viewx, viewy, bsp); + side = R_PointOnSideFast(viewx, viewy, bsp); // Recursively divide front space. HWR_RenderBSPNode(bsp->children[side]); diff --git a/src/p_mobj.c b/src/p_mobj.c index 566600230..cfc99ad13 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3660,7 +3660,7 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled } } - thiscam->subsector = R_PointInSubsector(thiscam->x, thiscam->y); + thiscam->subsector = R_PointInSubsectorFast(thiscam->x, thiscam->y); thiscam->floorz = tm.floorz; thiscam->ceilingz = tm.ceilingz; @@ -10372,12 +10372,12 @@ void P_PrecipitationEffects(void) for (y = yl; y <= yh; y += RADIUSSTEP) for (x = xl; x <= xh; x += RADIUSSTEP) { - if (R_PointInSubsector((fixed_t)x, (fixed_t)y)->sector->ceilingpic == skyflatnum) // Found the outdoors! - { - newdist = S_CalculateSoundDistance(players[g_localplayers[0]].mo->x, players[g_localplayers[0]].mo->y, 0, (fixed_t)x, (fixed_t)y, 0); - if (newdist < closedist) - closedist = newdist; - } + if (R_PointInSubsectorFast((fixed_t)x, (fixed_t)y)->sector->ceilingpic != skyflatnum) // Found the outdoors! + continue; + + newdist = S_CalculateSoundDistance(players[g_localplayers[0]].mo->x, players[g_localplayers[0]].mo->y, 0, (fixed_t)x, (fixed_t)y, 0); + if (newdist < closedist) + closedist = newdist; } #undef RADIUSSTEP diff --git a/src/p_setup.c b/src/p_setup.c index 4f7737b44..094e35602 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -8065,7 +8065,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_PointInSubsector(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) + cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) } else { @@ -8082,7 +8082,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_PointInSubsector(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) + cam->subsector = R_PointInSubsectorFast(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 99443976b..beab7153d 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2941,7 +2941,7 @@ void P_DemoCameraMovement(camera_t *cam) democam.soundmobj = awayviewmobj_hack; // update subsector to avoid crashes; - cam->subsector = R_PointInSubsector(cam->x, cam->y); + cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); } void P_ResetCamera(player_t *player, camera_t *thiscam) @@ -2975,7 +2975,7 @@ void P_ResetCamera(player_t *player, camera_t *thiscam) thiscam->aiming = 0; thiscam->relativex = 0; - thiscam->subsector = R_PointInSubsector(thiscam->x,thiscam->y); + thiscam->subsector = R_PointInSubsectorFast(thiscam->x,thiscam->y); thiscam->radius = 20*FRACUNIT; thiscam->height = 16*FRACUNIT; diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index ccac34d31..2a93c5d92 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -1453,7 +1453,7 @@ void R_RenderBSPNode(INT32 bspnum) bsp = &nodes[bspnum]; // Decide which side the view point is on. - side = R_PointOnSide(viewx, viewy, bsp); + side = R_PointOnSideFast(viewx, viewy, bsp); // Recursively divide front space. R_RenderBSPNode(bsp->children[side]); diff --git a/src/r_fps.c b/src/r_fps.c index dc894dd5f..a60adf520 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -184,7 +184,7 @@ void R_InterpolateView(fixed_t frac) viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); viewplayer = newview->player; - viewsector = R_PointInSubsector(viewx, viewy)->sector; + viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; R_SetupFreelook(newview->player, newview->sky); } diff --git a/src/r_main.cpp b/src/r_main.cpp index bb628c543..a80b17f2e 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1427,7 +1427,7 @@ static void R_PortalFrame(portal_t *portal) { portalclipline = NULL; portalcullsector = NULL; - viewsector = R_PointInSubsector(viewx, viewy)->sector; + viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; } } diff --git a/src/r_main.h b/src/r_main.h index b23bdff06..fbf3484f2 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -74,6 +74,15 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; #define R_PointOnSide(x,y,node) udmf ? R_PointOnSideUDMF(x,y,node) : R_PointOnSideKart(x,y,node) INT32 R_PointOnSideUDMF(fixed_t x, fixed_t y, const node_t *node); INT32 R_PointOnSideKart(fixed_t x, fixed_t y, const node_t *node); + +// This is not as accurate +// SHOULD NOT BE USED FOR ANYTHING GAMEPLAY RELATED!! +FUNCINLINE static ATTRINLINE INT32 R_PointOnSideFast(fixed_t x, fixed_t y, const node_t *node) +{ + // use cross product to determine side quickly + return ((INT64)y - node->y) * node->dx - ((INT64)x - node->x) * node->dy > 0; +} + INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line); #define R_PointToAngle(x, y) R_PointToAngle2(viewx, viewy, x, y) angle_t R_PointToAnglePlayer(player_t *player, fixed_t x, fixed_t y); @@ -86,6 +95,18 @@ fixed_t R_ScaleFromGlobalAngle(angle_t visangle); subsector_t *R_PointInSubsector(fixed_t x, fixed_t y); subsector_t *R_PointInSubsectorOrNull(fixed_t x, fixed_t y); +// 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]; +} + boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixed_t bottomh, fixed_t toph); void R_GetRenderBlockMapDimensions(fixed_t drawdist, INT32 *xl, INT32 *xh, INT32 *yl, INT32 *yh); diff --git a/src/s_sound.c b/src/s_sound.c index 215786b0d..8feb3a3eb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1100,7 +1100,7 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 { fixed_t x, y, yl, yh, xl, xh, newdist; - if (R_PointInSubsector(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) + if (R_PointInSubsectorFast(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) approx_dist = 0; else { @@ -1113,7 +1113,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_PointInSubsector(x, y)->sector->ceilingpic == skyflatnum) + if (R_PointInSubsectorFast(x, y)->sector->ceilingpic == skyflatnum) { // Found the outdoors! newdist = S_CalculateSoundDistance(listensource.x, listensource.y, 0, x, y, 0);