R_QuickCamDist & R_QuickDist: turn into function and make it fixed point
since we mostly use it in fixed point maths, this just makes alot more sense moving it into inline functions ensures that in C code this wont evaluate its arguments multiple times
This commit is contained in:
1 parent
d53ecd2817
commit
a77201bb20
4 files changed
+24
-17
No files matched your search
@@ -382,7 +382,7 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32
|
||||
extralight = FixedMul(extralight, std::min(std::max(0, *lightlevel), 255) * FRACUNIT / 255);
|
||||
|
||||
// simple OGL approximation
|
||||
fixed_t tr = R_QuickCamDist(spr->mobj->x, spr->mobj->y) << FRACBITS;
|
||||
fixed_t tr = R_QuickCamDist(spr->mobj->x, spr->mobj->y);
|
||||
fixed_t xscale = FixedDiv((vid.width / 2) << FRACBITS, tr);
|
||||
|
||||
// Less change in contrast at further distances, to counteract DOOM diminished light
|
||||
@@ -2537,18 +2537,18 @@ static boolean HWR_CheckBBox(const fixed_t *bspcoord)
|
||||
if (viewx < bspcoord[BOXLEFT]) // 1,4,6
|
||||
{
|
||||
if (viewy > bspcoord[BOXTOP]) // 1
|
||||
mindist = R_QuickCamDist(bspcoord[BOXLEFT], bspcoord[BOXTOP]) << FRACBITS;
|
||||
mindist = R_QuickCamDist(bspcoord[BOXLEFT], bspcoord[BOXTOP]);
|
||||
else if (viewy < bspcoord[BOXBOTTOM]) // 6
|
||||
mindist = R_QuickCamDist(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM]) << FRACBITS;
|
||||
mindist = R_QuickCamDist(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM]);
|
||||
else // 4
|
||||
mindist = bspcoord[BOXLEFT] - viewx;
|
||||
}
|
||||
else if (viewx > bspcoord[BOXRIGHT]) // 3,5,8
|
||||
{
|
||||
if (viewy > bspcoord[BOXTOP]) // 3
|
||||
mindist = R_QuickCamDist(bspcoord[BOXRIGHT], bspcoord[BOXTOP]) << FRACBITS;
|
||||
mindist = R_QuickCamDist(bspcoord[BOXRIGHT], bspcoord[BOXTOP]);
|
||||
else if (viewy < bspcoord[BOXBOTTOM]) // 8
|
||||
mindist = R_QuickCamDist(bspcoord[BOXRIGHT], bspcoord[BOXBOTTOM]) << FRACBITS;
|
||||
mindist = R_QuickCamDist(bspcoord[BOXRIGHT], bspcoord[BOXBOTTOM]);
|
||||
else // 5
|
||||
mindist = viewx - bspcoord[BOXRIGHT];
|
||||
}
|
||||
|
||||
+1
-1
@@ -3469,7 +3469,7 @@ boolean K_CheckSlopeRollDist(mobj_t *mobj)
|
||||
return true;
|
||||
|
||||
const fixed_t rolldist = (cv_sloperolldist.value * mapobjectscale);
|
||||
const fixed_t m_dist = (R_QuickCamDist(mobj->x, mobj->y) << FRACBITS);
|
||||
const fixed_t m_dist = R_QuickCamDist(mobj->x, mobj->y);
|
||||
|
||||
return (m_dist <= rolldist);
|
||||
}
|
||||
|
||||
+2
-2
@@ -2916,7 +2916,7 @@ boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist)
|
||||
{
|
||||
if (limit_dist)
|
||||
{
|
||||
if ((R_QuickCamDist(thing->x, thing->y) << FRACBITS)/mapobjectscale > limit_dist)
|
||||
if (R_QuickCamDist(thing->x, thing->y)/mapobjectscale > limit_dist)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -2960,7 +2960,7 @@ static boolean R_CheckInterpDist(T *thing)
|
||||
if (!R_UsingFrameInterpolation())
|
||||
return false;
|
||||
|
||||
const INT32 dist = R_QuickCamDist(thing->x, thing->y);
|
||||
const INT32 dist = R_QuickCamDist(thing->x, thing->y) >> FRACBITS;
|
||||
|
||||
return (dist < cv_maxinterpdist.value);
|
||||
}
|
||||
|
||||
+16
-9
@@ -35,18 +35,25 @@ extern "C" {
|
||||
|
||||
#define FEETADJUST (4<<FRACBITS) // R_AddSingleSpriteDef
|
||||
|
||||
FUNCINLINE static ATTRINLINE fixed_t R_QuickDist(fixed_t x1, fixed_t y1, fixed_t x, fixed_t y)
|
||||
{
|
||||
const fixed_t absx = abs(x - x1);
|
||||
const fixed_t absy = abs(y - y1);
|
||||
#ifdef __cplusplus
|
||||
return std::max<fixed_t>(absx, absy);
|
||||
#else
|
||||
return max(absx, absy);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Takes 2 fixed-point coordinates, returns "distance" between them and camera,
|
||||
// as an non-fixed-point integer.
|
||||
// as an fixed-point integer.
|
||||
// It is very rough, tho it is used only for optimizing out unnecessary
|
||||
// interpolation, so it is kinda ok on big distances.
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define R_QuickCamDist(x, y) std::max(std::abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), std::abs(((y)>>FRACBITS) - (viewy>>FRACBITS)))
|
||||
#define R_QuickDist(x1, y1, x, y) std::max(std::abs(((x)>>FRACBITS) - (x1>>FRACBITS)), std::abs(((y)>>FRACBITS) - (y1>>FRACBITS)))
|
||||
#else
|
||||
#define R_QuickCamDist(x, y) max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS)))
|
||||
#define R_QuickDist(x1, y1, x, y) max(abs(((x)>>FRACBITS) - (x1>>FRACBITS)), abs(((y)>>FRACBITS) - (y1>>FRACBITS)))
|
||||
#endif
|
||||
FUNCINLINE static ATTRINLINE fixed_t R_QuickCamDist(fixed_t x, fixed_t y)
|
||||
{
|
||||
return R_QuickDist(viewx, viewy, x, y);
|
||||
}
|
||||
|
||||
// Constant arrays used for psprite clipping
|
||||
// and initializing clipping.
|
||||
|
||||
Reference in new issue
Block a user