From 7b2e763d07c480539d9eef7c625556b9d9d20b0c Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 03:34:19 +0100 Subject: [PATCH] inline those two smol speedup --- src/r_main.c | 39 --------------------------------------- src/r_main.h | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index b68bde658..ccf872bba 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -298,32 +298,6 @@ static void Precipstuff_OnChange(void) P_SpawnPrecipitation(); } -// -// R_PointOnSide -// Traverse BSP (sub) tree, -// check point against partition plane. -// Returns side 0 (front) or 1 (back). -// -// killough 5/2/98: reformatted -// -PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *restrict node) -{ - if (!node->dx) - return x <= node->x ? node->dy > 0 : node->dy < 0; - - if (!node->dy) - return y <= node->y ? node->dx < 0 : node->dx > 0; - - x -= node->x; - y -= node->y; - - // Try to quickly decide by looking at sign bits. - // also use a mask to avoid branch prediction - INT32 mask = (node->dy ^ node->dx ^ x ^ y) >> 31; - return (mask & ((node->dy ^ x) < 0)) | // (left is negative) - (~mask & (FixedMul(y, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, x))); -} - // // R_PointToAngle // To get a global angle from cartesian coordinates, @@ -1052,19 +1026,6 @@ void R_Init(void) framecount = 0; } -// -// R_PointInSubsector -// -subsector_t *R_PointInSubsector(fixed_t x, fixed_t y) -{ - size_t nodenum = numnodes-1; - - while (!(nodenum & NF_SUBSECTOR)) - nodenum = nodes[nodenum].children[R_PointOnSide(x, y, nodes+nodenum)]; - - return &subsectors[nodenum & ~NF_SUBSECTOR]; -} - // // R_IsPointInSubsector, same as above but returns 0 if not in subsector // diff --git a/src/r_main.h b/src/r_main.h index 553f6a79f..523e924d5 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -72,7 +72,32 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; #define COLORMAP_REMAPOFFSET COLORMAP_SIZE // Utility functions. -INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *node); + +// +// R_PointOnSide +// Traverse BSP (sub) tree, +// check point against partition plane. +// Returns side 0 (front) or 1 (back). +// +// killough 5/2/98: reformatted +// +FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *restrict node) +{ + if (!node->dx) + return x <= node->x ? node->dy > 0 : node->dy < 0; + + if (!node->dy) + return y <= node->y ? node->dx < 0 : node->dx > 0; + + x -= node->x; + y -= node->y; + + // Try to quickly decide by looking at sign bits. + // also use a mask to avoid branch prediction + INT32 mask = (node->dy ^ node->dx ^ x ^ y) >> 31; + return (mask & ((node->dy ^ x) < 0)) | // (left is negative) + (~mask & (FixedMul(y, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, x))); +} // This is not as accurate // SHOULD NOT BE USED FOR ANYTHING GAMEPLAY RELATED!! @@ -99,9 +124,22 @@ angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player); fixed_t R_ScaleFromGlobalAngle(angle_t visangle); -subsector_t *R_PointInSubsector(fixed_t x, fixed_t y); + subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); +// +// R_PointInSubsector +// +FUNCINLINE static ATTRINLINE subsector_t *R_PointInSubsector(fixed_t x, fixed_t y) +{ + size_t nodenum = numnodes-1; + + while (!(nodenum & NF_SUBSECTOR)) + nodenum = nodes[nodenum].children[R_PointOnSide(x, y, nodes+nodenum)]; + + 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)