Skip to content

Commit

Permalink
Small reformat and update of drawing functions (#172)
Browse files Browse the repository at this point in the history
* Reformat R_PointToAngleSlope

* Reduce cope of `index` in R_MapPlane

* Update R_DrawPlanes and R_StoreWallRange

* Use local copy of SCREENWIDTH and ds_*step in drawing functions

* Simplify R_AddSprites

Co-Authored-By: Polina "Aura" N. <[email protected]>

* Simplify R_DrawPlayerSprites

Co-Authored-By: Polina "Aura" N. <[email protected]>

* Reformat R_PointToAngleSlope in Heretic and Hexen

* Update R_RenderMaskedSegRange

---------

Co-authored-by: pvictress <[email protected]>
  • Loading branch information
JNechaevsky and pvictress authored Jan 1, 2025
1 parent 15155ff commit a4a7d8c
Show file tree
Hide file tree
Showing 15 changed files with 607 additions and 771 deletions.
114 changes: 67 additions & 47 deletions src/doom/r_draw.c

Large diffs are not rendered by default.

111 changes: 38 additions & 73 deletions src/doom/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,90 +239,55 @@ int R_PointOnSegSide (fixed_t x, fixed_t y, const seg_t *line)
// [crispy] turned into a general R_PointToAngle() flavor
// called with either slope_div = SlopeDivCrispy() from R_PointToAngleCrispy()
// or slope_div = SlopeDiv() else
// [PN] Reformatted for readability and reduced nesting
angle_t
R_PointToAngleSlope
( fixed_t x,
fixed_t y,
int (*slope_div) (unsigned int num, unsigned int den))
{
{
// [PN] Shift to local player coordinates
x -= viewx;
y -= viewy;

if ( (!x) && (!y) )
return 0;

if (x>= 0)
// [PN] If the point matches the player's position
if (!x && !y)
return 0;

if (x >= 0)
{
// x >=0
if (y>= 0)
{
// y>= 0

if (x>y)
{
// octant 0
return tantoangle[slope_div(y,x)];
}
else
{
// octant 1
return ANG90-1-tantoangle[slope_div(x,y)];
}
}
else
{
// y<0
y = -y;

if (x>y)
{
// octant 8
return 0-tantoangle[slope_div(y,x)];
}
else
{
// octant 7
return ANG270+tantoangle[slope_div(x,y)];
}
}
if (y >= 0)
{
// [PN] First quadrant → octants 0 or 1
return (x > y)
? tantoangle[slope_div(y, x)]
: (ANG90 - 1 - tantoangle[slope_div(x, y)]);
}
else
{
// [PN] Fourth quadrant → octants 8 or 7
return (x > -y)
? (0 - tantoangle[slope_div(-y, x)])
: (ANG270 + tantoangle[slope_div(x, -y)]);
}
}
else
{
// x<0
x = -x;

if (y>= 0)
{
// y>= 0
if (x>y)
{
// octant 3
return ANG180-1-tantoangle[slope_div(y,x)];
}
else
{
// octant 2
return ANG90+ tantoangle[slope_div(x,y)];
}
}
else
{
// y<0
y = -y;

if (x>y)
{
// octant 4
return ANG180+tantoangle[slope_div(y,x)];
}
else
{
// octant 5
return ANG270-1-tantoangle[slope_div(x,y)];
}
}
if (y >= 0)
{
// [PN] Second quadrant → octants 3 or 2
return (-x > y)
? (ANG180 - 1 - tantoangle[slope_div(y, -x)])
: (ANG90 + tantoangle[slope_div(-x, y)]);
}
else
{
// [PN] Third quadrant → octants 4 or 5
return (-x > -y)
? (ANG180 + tantoangle[slope_div(-y, -x)])
: (ANG270 - 1 - tantoangle[slope_div(-x, -y)]);
}
}
return 0;
}

angle_t
Expand All @@ -341,8 +306,8 @@ R_PointToAngleCrispy
fixed_t y )
{
// [crispy] fix overflows for very long distances
int64_t y_viewy = (int64_t)y - viewy;
int64_t x_viewx = (int64_t)x - viewx;
const int64_t y_viewy = (int64_t)y - viewy;
const int64_t x_viewx = (int64_t)x - viewx;

// [crispy] the worst that could happen is e.g. INT_MIN-INT_MAX = 2*INT_MIN
if (x_viewx < INT_MIN || x_viewx > INT_MAX ||
Expand Down
7 changes: 3 additions & 4 deletions src/doom/r_plane.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ R_MapPlane
// angle_t angle;
fixed_t distance;
// fixed_t length;
unsigned index;
// unsigned index;
int dx, dy;

#ifdef RANGECHECK
Expand Down Expand Up @@ -188,7 +188,7 @@ R_MapPlane
ds_colormap[0] = ds_colormap[1] = fixedcolormap;
else
{
index = distance >> LIGHTZSHIFT;
unsigned int index = distance >> LIGHTZSHIFT;

if (index >= MAXLIGHTZ )
index = MAXLIGHTZ-1;
Expand Down Expand Up @@ -476,7 +476,6 @@ void R_DrawPlanes (void)
}
else // regular flat
{
int light = (pl->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT);
const boolean swirling = (flattranslation[pl->picnum] == -1);
const int stop = pl->maxx + 1;
const int lumpnum = firstflat + (swirling ? pl->picnum : flattranslation[pl->picnum]);
Expand All @@ -499,7 +498,7 @@ void R_DrawPlanes (void)

planeheight = abs(pl->height-viewz);
// [PN] Ensure 'light' is within the range [0, LIGHTLEVELS - 1] inclusively.
light = BETWEEN(0, LIGHTLEVELS-1, light);
const int light = BETWEEN(0, LIGHTLEVELS-1, (pl->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT));
planezlight = zlight[light];
pl->top[pl->minx-1] = pl->top[stop] = USHRT_MAX;

Expand Down
Loading

0 comments on commit a4a7d8c

Please sign in to comment.