attempt to optimize some p_maputl stuff

This commit is contained in:
Alug committed 2024-10-15 23:31:46 +02:00
1 parent 3bbafe8fc1
commit 4af35d623c
2 files changed
+27 -64

No files matched your search

+24 -56
View File
@@ -35,33 +35,23 @@ void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result)
fixed_t dy = line->dy;
// Determine t (the length of the vector from �Line[0]� to �p�)
fixed_t cx, cy;
fixed_t vx, vy;
fixed_t magnitude;
fixed_t t;
//Sub (p, &Line[0], &c);
cx = x - startx;
cy = y - starty;
//Sub (&Line[1], &Line[0], &V);
vx = dx;
vy = dy;
//Normalize (&V, &V);
magnitude = R_PointToDist2(line->v2->x, line->v2->y, startx, starty);
vx = FixedDiv(vx, magnitude);
vy = FixedDiv(vy, magnitude);
dx = FixedDiv(dx, magnitude);
dy = FixedDiv(dy, magnitude);
t = (FixedMul(vx, cx) + FixedMul(vy, cy));
t = (FixedMul(dx, (x - startx)) + FixedMul(dy, (y - starty)));
// Return the point between �Line[0]� and �Line[1]�
vx = FixedMul(vx, t);
vy = FixedMul(vy, t);
dx = FixedMul(dx, t);
dy = FixedMul(dy, t);
//Add (&Line[0], &V, out);
result->x = startx + vx;
result->y = starty + vy;
result->x = startx + dx;
result->y = starty + dy;
return;
}
@@ -79,28 +69,15 @@ void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, verte
fixed_t dz = line->v2->z - line->v1->z;
// Determine t (the length of the vector from �Line[0]� to �p�)
fixed_t cx, cy, cz;
fixed_t vx, vy, vz;
fixed_t magnitude;
fixed_t t;
//Sub (p, &Line[0], &c);
cx = x - startx;
cy = y - starty;
cz = z - startz;
//Sub (&Line[1], &Line[0], &V);
vx = dx;
vy = dy;
vz = dz;
//Normalize (&V, &V);
magnitude = R_PointToDist2(0, line->v2->z, R_PointToDist2(line->v2->x, line->v2->y, startx, starty), startz);
vx = FixedDiv(vx, magnitude);
vy = FixedDiv(vy, magnitude);
vz = FixedDiv(vz, magnitude);
dx = FixedDiv(dx, magnitude);
dy = FixedDiv(dy, magnitude);
dz = FixedDiv(dz, magnitude);
t = (FixedMul(vx, cx) + FixedMul(vy, cy) + FixedMul(vz, cz));
t = (FixedMul(dx, (x - startx)) + FixedMul(dy, (y - starty)) + FixedMul(dz, (z - startz)));
// Set closest point to the end if it extends past -Red
if (t <= 0)
@@ -119,14 +96,14 @@ void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, verte
}
// Return the point between �Line[0]� and �Line[1]�
vx = FixedMul(vx, t);
vy = FixedMul(vy, t);
vz = FixedMul(vz, t);
dx = FixedMul(dx, t);
dy = FixedMul(dy, t);
dz = FixedMul(dz, t);
//Add (&Line[0], &V, out);
result->x = startx + vx;
result->y = starty + vy;
result->z = startz + vz;
result->x = startx + dx;
result->y = starty + dy;
result->z = startz + dz;
return;
}
@@ -187,28 +164,22 @@ PUREFUNC INT32 P_BoxOnLineSide(fixed_t *tmbox, const line_t *ld)
//
FUNCINLINE static ATTRINLINE PUREFUNC INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, const divline_t *line)
{
fixed_t dx, dy, left, right;
if (!line->dx)
return x <= line->x ? line->dy > 0 : line->dy < 0;
if (!line->dy)
return y <= line->y ? line->dx < 0 : line->dx > 0;
dx = (x - line->x);
dy = (y - line->y);
x -= line->x;
y -= line->y;
// try to quickly decide by looking at sign bits
if ((line->dy ^ line->dx ^ dx ^ dy) & 0x80000000)
return ((line->dy ^ dx) & 0x80000000) ? 1 : 0;
if ((line->dy ^ line->dx ^ x ^ y) & 0x80000000)
return ((line->dy ^ x) & 0x80000000) ? 1 : 0;
left = FixedMul(line->dy>>8, dx>>8);
right = FixedMul(dy>>8, line->dx>>8);
return right < left ? 0 : 1;
return FixedMul(y>>8, line->dx>>8) < FixedMul(line->dy>>8, x>>8) ? 0 : 1;
}
//
// P_MakeDivline
//
@@ -227,17 +198,14 @@ void P_MakeDivline(line_t *li, divline_t *dl)
//
fixed_t P_InterceptVector(divline_t *v2, divline_t *v1)
{
fixed_t frac, num, den;
fixed_t den;
den = FixedMul(v1->dy>>8, v2->dx) - FixedMul(v1->dx>>8, v2->dy);
if (!den)
return 0;
num = FixedMul((v1->x - v2->x)>>8, v1->dy) + FixedMul((v2->y - v1->y)>>8, v1->dx);
frac = FixedDiv(num, den);
return frac;
return (FixedDiv(FixedMul((v1->x - v2->x)>>8, v1->dy) + FixedMul((v2->y - v1->y)>>8, v1->dx), den));
}
//
+3 -8
View File
@@ -51,21 +51,16 @@ void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, verte
//
FUNCINLINE static ATTRINLINE PUREFUNC INT32 P_PointOnLineSide(fixed_t x, fixed_t y, const line_t *line)
{
fixed_t dx, dy, left, right;
if (!line->dx)
return x <= line->v1->x ? line->dy > 0 : line->dy < 0;
if (!line->dy)
return y <= line->v1->y ? line->dx < 0 : line->dx > 0;
dx = (x - line->v1->x);
dy = (y - line->v1->y);
x -= line->v1->x;
y -= line->v1->y;
left = FixedMul(line->dy>>FRACBITS, dx);
right = FixedMul(dy, line->dx>>FRACBITS);
return right < left ? 0 : 1;
return FixedMul(y, line->dx>>FRACBITS) < FixedMul(line->dy>>FRACBITS, x) ? 0 : 1;
}
void P_MakeDivline(line_t *li, divline_t *dl);