Remove fast_f2nat

FossilOrigin-Name: 51fb59fc934df4829a82f7992f10435519dc8deb7098c3be1b17642fc6c05a44
This commit is contained in:
Jonathan Schleifer 2025-03-23 17:45:28 +00:00
parent 6320094293
commit e995b95a84
5 changed files with 17 additions and 23 deletions

View file

@ -198,7 +198,7 @@ los(float lx, float ly, float lz, float bx, float by, float bz, OFVector3D *v)
float y = ly; float y = ly;
int i = 0; int i = 0;
for (;;) { for (;;) {
struct sqr *s = S(fast_f2nat(x), fast_f2nat(y)); struct sqr *s = S((int)x, (int)y);
if (SOLID(s)) if (SOLID(s))
break; break;
float floor = s->floor; float floor = s->floor;

View file

@ -100,10 +100,10 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
const float fy1 = d.origin.y - d.radius; const float fy1 = d.origin.y - d.radius;
const float fx2 = d.origin.x + d.radius; const float fx2 = d.origin.x + d.radius;
const float fy2 = d.origin.y + d.radius; const float fy2 = d.origin.y + d.radius;
const int x1 = fast_f2nat(fx1); const int x1 = fx1;
const int y1 = fast_f2nat(fy1); const int y1 = fy1;
const int x2 = fast_f2nat(fx2); const int x2 = fx2;
const int y2 = fast_f2nat(fy2); const int y2 = fy2;
float hi = 127, lo = -128; float hi = 127, lo = -128;
// big monsters are afraid of heights, unless angry :) // big monsters are afraid of heights, unless angry :)
float minfloor = float minfloor =

View file

@ -36,8 +36,6 @@
# define __cdecl # define __cdecl
#endif #endif
#define fast_f2nat(val) ((int)(val))
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View file

@ -31,9 +31,8 @@ lightray(float bx, float by, Entity *light)
int l = light.attr2 << PRECBITS; int l = light.attr2 << PRECBITS;
int stepx = (int)(dx / (float)steps * PRECF); int stepx = (int)(dx / (float)steps * PRECF);
int stepy = (int)(dy / (float)steps * PRECF); int stepy = (int)(dy / (float)steps * PRECF);
int stepl = // incorrect: light will fade quicker if near edge of the world
fast_f2nat(l / (float)steps); // incorrect: light will fade quicker int stepl = l / (float)steps;
// if near edge of the world
if (hasoverbright) { if (hasoverbright) {
l /= lightscale; l /= lightscale;
@ -54,9 +53,9 @@ lightray(float bx, float by, Entity *light)
return; return;
int g = light.attr3 << PRECBITS; int g = light.attr3 << PRECBITS;
int stepg = fast_f2nat(g / (float)steps); int stepg = g / (float)steps;
int b = light.attr4 << PRECBITS; int b = light.attr4 << PRECBITS;
int stepb = fast_f2nat(b / (float)steps); int stepb = b / (float)steps;
g /= lightscale; g /= lightscale;
stepg /= lightscale; stepg /= lightscale;
b /= lightscale; b /= lightscale;

View file

@ -35,15 +35,12 @@ computeraytable(float vx, float vy)
for (int i = 0; i < NUMRAYS; i++) { for (int i = 0; i < NUMRAYS; i++) {
float angle = i * PI2 / NUMRAYS; float angle = i * PI2 / NUMRAYS;
if ((apitch > 45 // must be bigger if fov>120 // try to avoid tracing ray if outside of frustrum
|| (angle < byaw && angle > syaw) || // apitch must be bigger if fov > 120
if ((apitch > 45 || (angle < byaw && angle > syaw) ||
(angle < byaw - PI2 && angle > syaw - PI2) || (angle < byaw - PI2 && angle > syaw - PI2) ||
(angle < byaw + PI2 && angle > syaw + PI2)) && (angle < byaw + PI2 && angle > syaw + PI2)) &&
!OUTBORD(vx, vy) && !OUTBORD(vx, vy) && !SOLID(S((int)vx, (int)vy))) {
!SOLID(S(fast_f2nat(vx),
fast_f2nat(vy)))) // try to avoid tracing ray if outside
// of frustrum
{
float ray = i * 8 / (float)NUMRAYS; float ray = i * 8 / (float)NUMRAYS;
float dx, dy; float dx, dy;
if (ray > 1 && ray < 3) { if (ray > 1 && ray < 3) {
@ -66,7 +63,7 @@ computeraytable(float vx, float vy)
sy += dy; sy += dy;
// 90% of time spend in this function is on this // 90% of time spend in this function is on this
// line // line
if (SOLID(S(fast_f2nat(sx), fast_f2nat(sy)))) { if (SOLID(S((int)sx, (int)sy))) {
rdist[i] = (float)(fabs(sx - vx) + rdist[i] = (float)(fabs(sx - vx) +
fabs(sy - vy)); fabs(sy - vy));
break; break;
@ -183,9 +180,9 @@ isoccluded(float vx, float vy, float cx, float cy,
l = ca(cx - vx, cy + csize - vy); l = ca(cx - vx, cy + csize - vy);
} // H } // H
} }
int si = fast_f2nat(h * (NUMRAYS / 8)) + // get indexes into occlusion map from angles
NUMRAYS; // get indexes into occlusion map from angles int si = h * (NUMRAYS / 8) + NUMRAYS;
int ei = fast_f2nat(l * (NUMRAYS / 8)) + NUMRAYS + 1; int ei = l * (NUMRAYS / 8) + NUMRAYS + 1;
if (ei <= si) if (ei <= si)
ei += NUMRAYS; ei += NUMRAYS;