diff --git a/src/m_fixed.h b/src/m_fixed.h index 689c06e7a..894e2b1cc 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -20,7 +20,6 @@ extern "C" { #endif #include "doomtype.h" - #ifdef __GNUC__ #include #endif @@ -72,14 +71,6 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t DoubleToFixed(double f) #define FIXED_TO_FLOAT(x) FixedToFloat(x) // (((float)(x)) / ((float)FRACUNIT)) #define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT)) -FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FixedClamp(INT64 val) -{ -// stoopid includes -#define FCLAMP(x, y, z) ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))) - return (fixed_t)(FCLAMP(val, (INT64)INT32_MIN, (INT64)INT32_MAX)); -#undef FCLAMP -} - /** \brief The FixedMul function \param a fixed_t number diff --git a/src/r_main.cpp b/src/r_main.cpp index e9a3317c4..2b318858a 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -519,10 +519,10 @@ void R_GetRenderBlockMapDimensions(fixed_t drawdist, INT32 *xl, INT32 *xh, INT32 const fixed_t vyright = viewy + FixedMul(drawdist, FSIN(right)); // Try to narrow the search to within only the field of view - *xl = (unsigned)(FixedClamp((INT64)std::min(viewx, std::min(vxleft, vxright)) - bmaporgx))>>MAPBLOCKSHIFT; - *xh = (unsigned)(FixedClamp((INT64)std::max(viewx, std::max(vxleft, vxright)) - bmaporgx))>>MAPBLOCKSHIFT; - *yl = (unsigned)(FixedClamp((INT64)std::min(viewy, std::min(vyleft, vyright)) - bmaporgy))>>MAPBLOCKSHIFT; - *yh = (unsigned)(FixedClamp((INT64)std::max(viewy, std::max(vyleft, vyright)) - bmaporgy))>>MAPBLOCKSHIFT; + *xl = (unsigned)(std::min(viewx, std::min(vxleft, vxright)) - bmaporgx)>>MAPBLOCKSHIFT; + *xh = (unsigned)(std::max(viewx, std::max(vxleft, vxright)) - bmaporgx)>>MAPBLOCKSHIFT; + *yl = (unsigned)(std::min(viewy, std::min(vyleft, vyright)) - bmaporgy)>>MAPBLOCKSHIFT; + *yh = (unsigned)(std::max(viewy, std::max(vyleft, vyright)) - bmaporgy)>>MAPBLOCKSHIFT; if (*xh >= bmapwidth) *xh = bmapwidth - 1; diff --git a/src/r_main.h b/src/r_main.h index 1b1096d35..e8b7393e3 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -152,8 +152,8 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); FUNCMATH FUNCINLINE static ATTRINLINE fixed_t R_QuickDist(fixed_t x1, fixed_t y1, fixed_t x, fixed_t y) { - const fixed_t absx = FixedClamp(labs((INT64)x - (INT64)x1)); - const fixed_t absy = FixedClamp(labs((INT64)y - (INT64)y1)); + const fixed_t absx = abs(x - x1); + const fixed_t absy = abs(y - y1); #ifdef __cplusplus return std::max(absx, absy); #else diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 4d11c190d..05c4d943a 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -228,8 +228,8 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, INT32 // to step from those to the proper texture coordinate to start drawing at. // That way, the texture coordinate is always calculated by its position // on the screen and not by its position relative to the edge of the visplane. - ds->xfrac = FixedClamp((INT64)ds->xoffs + (INT64)FixedMul(planecos, distance) + ((INT64)x1 - (INT64)centerx) * (INT64)ds->xstep); - ds->yfrac = FixedClamp((INT64)ds->yoffs - (INT64)FixedMul(planesin, distance) + ((INT64)x1 - (INT64)centerx) * (INT64)ds->ystep); + ds->xfrac = ds->xoffs + FixedMul(planecos, distance) + (x1 - centerx) * ds->xstep; + ds->yfrac = ds->yoffs - FixedMul(planesin, distance) + (x1 - centerx) * ds->ystep; if (ds->planeripple.active) { @@ -1012,7 +1012,7 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle levelflat_t *levelflat; void (*mapfunc)(drawspandata_t*, void(*)(drawspandata_t*), INT32, INT32, INT32, boolean) = R_MapPlane; - if (!(pl->minx <= pl->maxx)) + if (pl->minx > pl->maxx) return; // sky flat diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 25e4caf3e..a53d40ec4 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -226,11 +226,10 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 leftheight -= viewz; rightheight -= viewz; - rlight->height = FixedClamp((INT64)centeryfrac - FixedMul(leftheight, drawseg->scale1)); - rlight->heightstep = FixedClamp((INT64)centeryfrac - FixedMul(rightheight, drawseg->scale2)); - rlight->heightstep = (FixedClamp((INT64)rlight->heightstep - rlight->height))/(range); - rlight->startheight = rlight->height; // keep starting value here to reset for each repeat - + rlight->height = (centeryfrac) - FixedMul(leftheight, drawseg->scale1); + rlight->heightstep = (centeryfrac) - FixedMul(rightheight, drawseg->scale2); + rlight->heightstep = (rlight->heightstep-rlight->height)/(range); + rlight->startheight = rlight->height; // keep starting value here to reset for each repeat rlight->lightlevel = *light->lightlevel; rlight->extra_colormap = light->extra_colormap; rlight->flags = static_cast(light->flags); @@ -356,9 +355,9 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 lighttable_t **xwalllights; sprbotscreen = INT32_MAX; - sprtopscreen = windowtop = FixedClamp((INT64)centeryfrac - FixedMul(dc->texturemid, spryscale)); + sprtopscreen = windowtop = (centeryfrac - FixedMul(dc->texturemid, spryscale)); - realbot = windowbottom = FixedClamp((INT64)FixedMul(textureheight[texnum], spryscale) + sprtopscreen); + realbot = windowbottom = FixedMul(textureheight[texnum], spryscale) + sprtopscreen; dc->iscale = 0xffffffffu / (unsigned)spryscale; // draw the texture @@ -408,8 +407,7 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 set_light_vars(i); height = rlight->height; - - rlight->height = FixedClamp((INT64)rlight->height + rlight->heightstep); + rlight->height += rlight->heightstep; if (height <= windowtop) { @@ -457,7 +455,7 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 if (frontsector->extra_colormap) dc->colormap = frontsector->extra_colormap->colormap + (dc->colormap - colormaps); - sprtopscreen = FixedClamp((INT64)centeryfrac - FixedMul(dc->texturemid, spryscale)); + sprtopscreen = centeryfrac - FixedMul(dc->texturemid, spryscale); dc->iscale = 0xffffffffu / (unsigned)spryscale; // draw the texture @@ -772,7 +770,7 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf overflow_test = (INT64)centeryfrac - (((INT64)rightheight*drawseg->scale2)>>FRACBITS); rlight->heightstep = overflow_clamp(overflow_test); - rlight->heightstep = (FixedClamp((INT64)rlight->heightstep - rlight->height))/(range); + rlight->heightstep = (rlight->heightstep-rlight->height)/(range); rlight->flags = static_cast(light->flags); if (light->flags & FF_CUTLEVEL) @@ -789,7 +787,7 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf overflow_test = (INT64)centeryfrac - (((INT64)rightheight*drawseg->scale2)>>FRACBITS); rlight->botheightstep = overflow_clamp(overflow_test); - rlight->botheightstep = (FixedClamp((INT64)rlight->botheightstep - rlight->botheight))/(range); + rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range); } rlight->lightlevel = *light->lightlevel; @@ -937,11 +935,9 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf for (i = 0; i < dc->numlights; i++) { rlight = &dc->lightlist[i]; - - rlight->height = FixedClamp((INT64)rlight->height + rlight->heightstep); - + rlight->height += rlight->heightstep; if (rlight->flags & FF_CUTLEVEL) - rlight->botheight = FixedClamp((INT64)rlight->botheight + rlight->botheightstep); + rlight->botheight += rlight->botheightstep; } } @@ -1049,12 +1045,12 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf solid = 0; height = rlight->height; - rlight->height = FixedClamp((INT64)rlight->height + rlight->heightstep); + rlight->height += rlight->heightstep; if (solid) { - bheight = FixedClamp((INT64)rlight->botheight - (FRACUNIT >> 1)); - rlight->botheight = FixedClamp((INT64)rlight->botheight + rlight->botheightstep); + bheight = rlight->botheight - (FRACUNIT >> 1); + rlight->botheight += rlight->botheightstep; } if (height <= windowtop) @@ -1216,7 +1212,7 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) for (; rw_x < rw_stopx; rw_x++) { // mark floor / ceiling areas - yl = (FixedClamp((INT64)topfrac + HEIGHTUNIT-1))>>HEIGHTBITS; + yl = (topfrac+HEIGHTUNIT-1)>>HEIGHTBITS; yh = bottomfrac>>HEIGHTBITS; // Mark ceiling @@ -1376,17 +1372,15 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) //SoM: Calculate offsets for Thick fake floors. // calculate texture offset angle = (rw_centerangle + xtoviewangle[rw_x])>>ANGLETOFINESHIFT; - // Mask 4095 to guarantee this index is within bounds - texturecolumn = FixedClamp((INT64)rw_offset - FixedMul(FINETANGENT(angle & 4095), rw_distance)); + texturecolumn = rw_offset-FixedMul(FINETANGENT(angle & 4095), rw_distance); if (oldtexturecolumn != -1) { - const fixed_t coloff = FixedClamp((INT64)oldtexturecolumn - texturecolumn); - rw_bottomtexturemid += FixedMul(rw_bottomtextureslide, coloff); - rw_midtexturemid += FixedMul(rw_midtextureslide, coloff); - rw_toptexturemid += FixedMul(rw_toptextureslide, coloff); - rw_midtextureback += FixedMul(rw_midtexturebackslide, coloff); + rw_bottomtexturemid += FixedMul(rw_bottomtextureslide, oldtexturecolumn-texturecolumn); + rw_midtexturemid += FixedMul(rw_midtextureslide, oldtexturecolumn-texturecolumn); + rw_toptexturemid += FixedMul(rw_toptextureslide, oldtexturecolumn-texturecolumn); + rw_midtextureback += FixedMul(rw_midtexturebackslide, oldtexturecolumn-texturecolumn); } oldtexturecolumn = texturecolumn; @@ -1560,10 +1554,10 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) { for (i = 0; i < dc->numlights; i++) { - dc->lightlist[i].height = FixedClamp((INT64)dc->lightlist[i].height + dc->lightlist[i].heightstep); + dc->lightlist[i].height += dc->lightlist[i].heightstep; if (dc->lightlist[i].flags & FF_CUTSOLIDS) - dc->lightlist[i].botheight = FixedClamp((INT64)dc->lightlist[i].botheight + dc->lightlist[i].botheightstep);; + dc->lightlist[i].botheight += dc->lightlist[i].botheightstep; } } @@ -1584,10 +1578,9 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) visffloor[i].b_frac += visffloor[i].b_step; } - rw_scale = FixedClamp((INT64)rw_scale + rw_scalestep); - - topfrac = FixedClamp((INT64)topfrac + topstep); - bottomfrac = FixedClamp((INT64)bottomfrac + bottomstep); + rw_scale += rw_scalestep; + topfrac += topstep; + bottomfrac += bottomstep; } } @@ -2221,8 +2214,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) } } - rw_toptexturemid = FixedClamp((INT64)rw_toptexturemid + sidedef->rowoffset); - rw_bottomtexturemid = FixedClamp((INT64)rw_bottomtexturemid + sidedef->rowoffset); + rw_toptexturemid += sidedef->rowoffset; + rw_bottomtexturemid += sidedef->rowoffset; R_AllocTextureColumnTables(rw_stopx - start); @@ -2507,9 +2500,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) rw_offset = -rw_offset; /// don't use texture offset for splats - rw_offset2 = FixedClamp((INT64)rw_offset + curline->offset); - rw_offset = FixedClamp((INT64)rw_offset + (INT64)sidedef->textureoffset + curline->offset); - + rw_offset2 = rw_offset + curline->offset; + rw_offset += sidedef->textureoffset + curline->offset; rw_centerangle = ANGLE_90 + viewangle - rw_normalangle; // calculate light table @@ -2662,7 +2654,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) rlight->height = (centeryfrac>>4) - FixedMul(leftheight, rw_scale); rlight->heightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2); - rlight->heightstep = (FixedClamp((INT64)rlight->heightstep - rlight->height))/(range); + rlight->heightstep = (rlight->heightstep-rlight->height)/(range); rlight->flags = static_cast(light->flags); if (light->caster && light->caster->flags & FF_CUTSOLIDS) diff --git a/src/r_things.cpp b/src/r_things.cpp index 8d4f3ce9c..d41a0d00c 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -11,7 +11,6 @@ /// \file r_things.c /// \brief Refresh of things, i.e. objects represented by sprites -#include "m_fixed.h" #include "r_main.h" // stplyr #include "r_fps.h" #include "r_things.h" @@ -617,11 +616,10 @@ void R_DrawMaskedColumn(drawcolumndata_t* dc, column_t *column) if (topdelta <= prevdelta) topdelta += prevdelta; prevdelta = topdelta; + topscreen = sprtopscreen + spryscale*topdelta; + bottomscreen = topscreen + spryscale*column->length; - topscreen = FixedClamp((INT64)sprtopscreen + (INT64)spryscale * (INT64)topdelta); - bottomscreen = FixedClamp((INT64)topscreen + (INT64)spryscale * (INT64)column->length); - - dc->yl = FixedClamp((INT64)topscreen + (FRACUNIT-1))>>FRACBITS; + dc->yl = (topscreen+FRACUNIT-1)>>FRACBITS; dc->yh = (bottomscreen-1)>>FRACBITS; if (windowtop != INT32_MAX && windowbottom != INT32_MAX) @@ -887,7 +885,7 @@ static void R_DrawVisSprite(vissprite_t *vis) for (dc.x = vis->x1; dc.x <= vis->x2; dc.x++, spryscale += scalestep) { angle_t angle = ((vis->centerangle + xtoviewangle[dc.x]) >> ANGLETOFINESHIFT) & 0xFFF; - texturecolumn = FixedClamp((INT64)vis->paperoffset - FixedMul(FINETANGENT(angle), vis->paperdistance)) / horzscale; + texturecolumn = (vis->paperoffset - FixedMul(FINETANGENT(angle), vis->paperdistance)) / horzscale; if (texturecolumn < 0 || texturecolumn >= pwidth) continue;