From 82d784d9f854f082c0c8d095ad799569752dc35f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 27 Feb 2024 15:52:34 +0100 Subject: [PATCH] Toggle for R_Pointtoangle Ex or 64 Ex may perform better on 32bit clients and some cpus so lets just make it toggable --- src/hardware/hw_main.c | 37 +++++++++++++++++++++++++++++++------ src/m_menu.c | 5 +++++ src/r_bsp.c | 26 ++++++++++++++++++++++---- src/r_main.c | 33 ++++++++++++++++++++++++++++----- src/r_main.h | 1 + src/r_state.h | 2 ++ src/tables.h | 2 +- 7 files changed, 90 insertions(+), 16 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e01c6c64b..7160a8adf 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2888,8 +2888,16 @@ void HWR_AddLine(seg_t *line) } // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle64(v1x, v1y); - angle2 = R_PointToAngle64(v2x, v2y); + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(v1x, v1y); + angle2 = R_PointToAngle64(v2x, v2y); + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, v1x, v1y); + angle2 = R_PointToAngleEx(viewx, viewy, v2x, v2y); + } // PrBoom: Back side, i.e. backface culling - read: endAngle >= startAngle! if (angle2 - angle1 < ANGLE_180) @@ -3084,8 +3092,17 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) if (mindist > current_bsp_culling_distance) return false; } - angle1 = R_PointToAngle64(px1, py1); - angle2 = R_PointToAngle64(px2, py2); + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(px1, py1); + angle2 = R_PointToAngle64(px2, py2); + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, px1, py1); + angle2 = R_PointToAngleEx(viewx, viewy, px2, py2); + } + return gld_clipper_SafeCheckRange(angle2, angle1); } @@ -6057,8 +6074,16 @@ static void HWR_PortalClipping(gl_portal_t *portal) line_t *line = &lines[portal->clipline]; - angle1 = R_PointToAngle64(line->v1->x, line->v1->y); - angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(line->v1->x, line->v1->y); + angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); + } // clip things that are not inside the portal window from our viewpoint gld_clipper_SafeAddClipRange(angle2, angle1); diff --git a/src/m_menu.c b/src/m_menu.c index dad281090..294bb8000 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1421,6 +1421,8 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_vhseffect, 75}, + {IT_STRING | IT_CVAR, NULL, "Clipping R_PointToAngle Version", &cv_pointoangleexor64, 85}, + {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 95}, {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 105}, #ifdef HWRENDER @@ -1432,6 +1434,7 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 135}, {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 145}, {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 155}, + #endif }; @@ -1443,6 +1446,7 @@ static const char* OP_ExpTooltips[] = "Should weather be interpolated? Weather should look about the\nsame but perform a bit better when disabled.", "When weather is on this will cut the object amount used in half.", "Show a VHS-like effect when the game is paused\n or youre rewinding replays.", + "Which version of R_PointToAngle should\nbe used for Sector Clipping?\n64 may fix rendering issues on larger maps\nat the cost of performance.", "Hides 3DFloors which are not visible\npotentially resulting in a performance boost.", "Hides Sprites which are not visible\npotentially resulting in a performance boost.", #ifdef HWRENDER @@ -1463,6 +1467,7 @@ enum op_exp_precipinter, op_exp_lessprecip, op_exp_vhs, + op_exp_angleshit, op_exp_ffclip, op_exp_sprclip, #ifdef HWRENDER diff --git a/src/r_bsp.c b/src/r_bsp.c index 21478bd7f..8cb7f8760 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -323,8 +323,18 @@ static void R_AddLine(seg_t *line) return; // big room fix - angle1 = R_PointToAngle64(line->v1->x, line->v1->y); - angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(line->v1->x, line->v1->y); + angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); + } + curline = line; // Clip to view edges. @@ -539,8 +549,16 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) check = checkcoord[boxpos]; // big room fix - angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; - angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngleEx(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + } if ((signed)angle1 < (signed)angle2) { diff --git a/src/r_main.c b/src/r_main.c index 2478d82ec..17af2214e 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -145,8 +145,6 @@ static CV_PossibleValue_t drawdist_cons_t[] = { {3072, "3072"}, {4096, "4096"}, {6144, "6144"}, {8192, "8192"}, {0, "Infinite"}, {0, NULL}}; -//static CV_PossibleValue_t precipdensity_cons_t[] = {{0, "None"}, {1, "Light"}, {2, "Moderate"}, {4, "Heavy"}, {6, "Thick"}, {8, "V.Thick"}, {0, NULL}}; - static CV_PossibleValue_t drawdist_precip_cons_t[] = { {256, "256"}, {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, @@ -161,7 +159,6 @@ static CV_PossibleValue_t maxinterpdist_cons_t[] = { static CV_PossibleValue_t fov_cons_t[] = {{5*FRACUNIT, "MIN"}, {178*FRACUNIT, "MAX"}, {0, NULL}}; -//static CV_PossibleValue_t precipdensity_cons_t[] = {{0, "None"}, {1, "Light"}, {2, "Moderate"}, {4, "Heavy"}, {6, "Thick"}, {8, "V.Thick"}, {0, NULL}}; static CV_PossibleValue_t translucenthud_cons_t[] = {{0, "MIN"}, {10, "MAX"}, {0, NULL}}; static CV_PossibleValue_t maxportals_cons_t[] = {{0, "MIN"}, {12, "MAX"}, {0, NULL}}; // lmao rendering 32 portals, you're a card static CV_PossibleValue_t homremoval_cons_t[] = {{0, "No"}, {1, "Yes"}, {2, "Flash"}, {0, NULL}}; @@ -202,10 +199,8 @@ consvar_t cv_translucenthud = {"translucenthud", "10", CV_SAVE, translucenthud_c consvar_t cv_translucency = {"translucency", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_drawdist = {"drawdist", "Infinite", CV_SAVE, drawdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -//consvar_t cv_drawdist_nights = {"drawdist_nights", "2048", CV_SAVE, drawdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_drawdist_precip = {"drawdist_precip", "1024", CV_SAVE, drawdist_precip_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_lessprecip = {"lessweathereffects", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -//consvar_t cv_precipdensity = {"precipdensity", "Moderate", CV_SAVE, precipdensity_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grmaxinterpdist = {"gr_maxinterpdist", "Infinite", CV_SAVE, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -217,6 +212,9 @@ consvar_t cv_homremoval = {"homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL consvar_t cv_maxportals = {"maxportals", "2", CV_SAVE, maxportals_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t pointoangle_cons_t[] = {{0, "Ex"}, {1, "64"}, {0, NULL}}; +consvar_t cv_pointoangleexor64 = {"r_pointtoangle", "Ex", CV_SAVE, pointoangle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + void SplitScreen_OnChange(void) { UINT8 i; @@ -420,6 +418,29 @@ angle_t R_PointToAngle64(INT64 x, INT64 y) 0; } +angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1) +{ + INT64 dx = x1-x2; + INT64 dy = y1-y2; + if (dx < INT32_MIN || dx > INT32_MAX || dy < INT32_MIN || dy > INT32_MAX) + { + x1 = (int)(dx / 2 + x2); + y1 = (int)(dy / 2 + y2); + } + return (y1 -= y2, (x1 -= x2) || y1) ? + x1 >= 0 ? + y1 >= 0 ? + (x1 > y1) ? tantoangle[SlopeDivEx(y1,x1)] : // octant 0 + ANGLE_90-tantoangle[SlopeDivEx(x1,y1)] : // octant 1 + x1 > (y1 = -y1) ? 0-tantoangle[SlopeDivEx(y1,x1)] : // octant 8 + ANGLE_270+tantoangle[SlopeDivEx(x1,y1)] : // octant 7 + y1 >= 0 ? (x1 = -x1) > y1 ? ANGLE_180-tantoangle[SlopeDivEx(y1,x1)] : // octant 3 + ANGLE_90 + tantoangle[SlopeDivEx(x1,y1)] : // octant 2 + (x1 = -x1) > (y1 = -y1) ? ANGLE_180+tantoangle[SlopeDivEx(y1,x1)] : // octant 4 + ANGLE_270-tantoangle[SlopeDivEx(x1,y1)] : // octant 5 + 0; +} + angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) { return (y -= pviewy, (x -= pviewx) || y) ? @@ -1847,6 +1868,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_translucenthud); CV_RegisterVar(&cv_maxportals); + + CV_RegisterVar(&cv_pointoangleexor64); CV_RegisterVar(&cv_grmaxinterpdist); diff --git a/src/r_main.h b/src/r_main.h index 08117580e..8d00ba5ed 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -69,6 +69,7 @@ INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); angle_t R_PointToAngle64(INT64 x, INT64 y); +angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); fixed_t R_PointToDist(fixed_t x, fixed_t y); fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); diff --git a/src/r_state.h b/src/r_state.h index bf1a665b8..3c0f3cc49 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -102,6 +102,8 @@ extern INT32 portalclipstart, portalclipend; extern consvar_t cv_allowmlook; extern consvar_t cv_maxportals; +extern consvar_t cv_pointoangleexor64; + extern angle_t clipangle; extern angle_t doubleclipangle; diff --git a/src/tables.h b/src/tables.h index beea392ec..353bf591f 100644 --- a/src/tables.h +++ b/src/tables.h @@ -86,7 +86,7 @@ extern angle_t tantoangle[SLOPERANGE+1]; // Utility function, called by R_PointToAngle. FUNCMATH unsigned SlopeDiv(unsigned num, unsigned den); // Only called by R_PointToAngleEx -UINT64 SlopeDivEx(unsigned int num, unsigned int den); +FUNCMATH UINT64 SlopeDivEx(unsigned int num, unsigned int den); // 360 - angle_t(ANGLE_45) = ANGLE_315 FUNCMATH FUNCINLINE static ATTRINLINE angle_t InvAngle(angle_t a)