optimize R_PointOnSegSide
its only used for 2 rendering functions, so being potentially inaccurate is not that dangerous and the speedup in some instances might be worth the tradeoff
This commit is contained in:
1 parent
7076c35521
commit
c6fbf405bf
2 files changed
+12
-24
No files matched your search
@@ -325,29 +325,6 @@ PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *restrict node)
|
||||
(~mask & (FixedMul(y, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, x)));
|
||||
}
|
||||
|
||||
// killough 5/2/98: reformatted
|
||||
PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line)
|
||||
{
|
||||
fixed_t lx = line->v1->x;
|
||||
fixed_t ly = line->v1->y;
|
||||
fixed_t ldx = line->v2->x - lx;
|
||||
fixed_t ldy = line->v2->y - ly;
|
||||
|
||||
if (!ldx)
|
||||
return x <= lx ? ldy > 0 : ldy < 0;
|
||||
|
||||
if (!ldy)
|
||||
return y <= ly ? ldx < 0 : ldx > 0;
|
||||
|
||||
x -= lx;
|
||||
y -= ly;
|
||||
|
||||
// Try to quickly decide by looking at sign bits.
|
||||
if ((ldy ^ ldx ^ x ^ y) < 0)
|
||||
return (ldy ^ x) < 0; // (left is negative)
|
||||
return FixedMul(y, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, x);
|
||||
}
|
||||
|
||||
//
|
||||
// R_PointToAngle
|
||||
// To get a global angle from cartesian coordinates,
|
||||
|
||||
+12
-1
@@ -73,7 +73,18 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
|
||||
|
||||
// Utility functions.
|
||||
INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *node);
|
||||
INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line);
|
||||
|
||||
FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line)
|
||||
{
|
||||
fixed_t lx = line->v1->x;
|
||||
fixed_t ly = line->v1->y;
|
||||
fixed_t ldx = line->v2->x - lx;
|
||||
fixed_t ldy = line->v2->y - ly;
|
||||
|
||||
// heavily optimized version of R_PointOnSide, stolen from GZDoom.
|
||||
return (INT64)(y - ly) * ldx + (INT64)(lx - x) * ldy > 0;
|
||||
}
|
||||
|
||||
angle_t R_PointToAngle(fixed_t x, fixed_t y);
|
||||
angle_t R_PointToAngle64(INT64 x, INT64 y);
|
||||
angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1);
|
||||
|
||||
Reference in new issue
Block a user