Skip to content

Commit

Permalink
Fine-tune thick line drawing
Browse files Browse the repository at this point in the history
Co-Authored-By: Julia Nechaevskaya <[email protected]>
  • Loading branch information
pvictress and JNechaevsky committed Jan 4, 2025
1 parent d7a4238 commit dabf781
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 72 deletions.
53 changes: 28 additions & 25 deletions src/doom/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ static void AM_transformPoint (mpoint_t *pt);
static mpoint_t mapcenter;
static angle_t mapangle;

static void AM_drawCrosshair(boolean force);

// -----------------------------------------------------------------------------
// AM_Init
// [JN] Predefine some variables at program startup.
Expand Down Expand Up @@ -718,7 +716,6 @@ void AM_LevelInit (boolean reinit)
if (reinit && f_h_old)
{
scale_mtof = scale_mtof * f_h / f_h_old;
AM_drawCrosshair(true);
}
else
{
Expand Down Expand Up @@ -1387,6 +1384,13 @@ static inline void PUTDOT_THICK (int x, int y, pixel_t color)
if (ny < 0 || ny >= f_h)
continue;

// Calculate the squared distance from the center.
const int distance2 = dx * dx + dy * dy;

// Skip pixels outside the desired radius.
if (distance2 > thickness * thickness)
continue;

// Draw the pixel with or without smoothing based on the setting.
if (smooth)
PUTDOT_RAW(nx, ny, color);
Expand Down Expand Up @@ -2470,28 +2474,27 @@ static void AM_drawMarks (void)
// AM_drawCrosshair
// -----------------------------------------------------------------------------

static void AM_drawCrosshair (boolean force)
static void AM_drawCrosshair (void)
{
// [crispy] draw an actual crosshair
if (!followplayer || force)
{
static fline_t h, v;

if (!h.a.x || force)
{
h.a.x = h.b.x = v.a.x = v.b.x = f_x + f_w / 2;
h.a.y = h.b.y = v.a.y = v.b.y = f_y + f_h / 2;
h.a.x -= 2; h.b.x += 2;
v.a.y -= 2; v.b.y += 2;
}

// [JN] Do not draw crosshair while video re-init functions.
if (!force)
{
AM_drawFline(&h, doom_96);
AM_drawFline(&v, doom_96);
}
}
// [JN] Draw the crosshair as a graphical patch to keep it unaffected by
// map line thickness, following the logic of mark drawing. Coloring via
// dp_translation is still needed to ensure it won't be affected much
// by possible custom PLAYPAL palette and modified color index.
//
// Patch drawing coordinates are the center of the screen:
// x: 159 = (ORIGWIDTH / 2) - 1
// y: 84 = (ORIGHEIGHT / 2) - 16

static const byte am_xhair[] =
{
3,0,3,0,0,0,0,0,20,0,0,0,26,0,0,0,
34,0,0,0,1,1,90,90,90,255,0,3,90,90,90,90,
90,255,1,1,90,90,90,255
};

dp_translation = cr[CR_LIGHTGRAY];
V_DrawPatch(159, 84, (patch_t*)&am_xhair);
dp_translation = NULL;
}

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -2586,7 +2589,7 @@ void AM_Drawer (void)
// [JN] Do not draw in following mode.
if (!followplayer)
{
AM_drawCrosshair(false);
AM_drawCrosshair();
}

AM_drawMarks();
Expand Down
52 changes: 28 additions & 24 deletions src/heretic/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ static void AM_transformPoint (mpoint_t *pt);
static mpoint_t mapcenter;
static angle_t mapangle;

static void AM_drawCrosshair(boolean force);
static void DrawWuLine(fline_t* fl, byte *BaseColor);


Expand Down Expand Up @@ -685,7 +684,6 @@ void AM_LevelInit (boolean reinit)
if (reinit && f_h_old)
{
scale_mtof = scale_mtof * f_h / f_h_old;
AM_drawCrosshair(true);
}
else
{
Expand Down Expand Up @@ -1347,6 +1345,13 @@ static inline void PUTDOT_THICK(int x, int y, pixel_t color)
if (ny < 0 || ny >= f_h)
continue;

// Calculate the squared distance from the center.
const int distance2 = dx * dx + dy * dy;

// Skip pixels outside the desired radius.
if (distance2 > thickness * thickness)
continue;

DOT(nx, ny, color);
}
}
Expand Down Expand Up @@ -2240,28 +2245,27 @@ static void AM_drawkeys (void)
// AM_drawCrosshair
// -----------------------------------------------------------------------------

static void AM_drawCrosshair (boolean force)
static void AM_drawCrosshair (void)
{
// [crispy] draw an actual crosshair
if (!followplayer || force)
{
static fline_t h, v;

if (!h.a.x || force)
{
h.a.x = h.b.x = v.a.x = v.b.x = f_x + f_w / 2;
h.a.y = h.b.y = v.a.y = v.b.y = f_y + f_h / 2;
h.a.x -= 2; h.b.x += 2;
v.a.y -= 2; v.b.y += 2;
}

// [JN] Do not draw crosshair while video re-init functions.
if (!force)
{
AM_drawFline(&h, XHAIRCOLORS);
AM_drawFline(&v, XHAIRCOLORS);
}
}
// [JN] Draw the crosshair as a graphical patch to keep it unaffected by
// map line thickness, following the logic of mark drawing. Coloring via
// dp_translation is still needed to ensure it won't be affected much
// by possible custom PLAYPAL palette and modified color index.
//
// Patch drawing coordinates are the center of the screen:
// x: 159 = (ORIGWIDTH / 2) - 1
// y: 78 = (ORIGHEIGHT / 2) - 22

static const byte am_xhair[] =
{
3,0,3,0,0,0,0,0,20,0,0,0,26,0,0,0,
34,0,0,0,1,1,32,32,32,255,0,3,32,32,32,32,
32,255,1,1,32,32,32,255
};

dp_translation = cr[CR_WHITE];
V_DrawPatch(159, 78, (patch_t*)&am_xhair);
dp_translation = NULL;
}

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -2383,7 +2387,7 @@ void AM_Drawer (void)
// [JN] Do not draw in following mode.
if (!followplayer)
{
AM_drawCrosshair(false);
AM_drawCrosshair();
}

AM_drawMarks();
Expand Down
50 changes: 27 additions & 23 deletions src/hexen/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ static void AM_transformPoint (mpoint_t *pt);
static mpoint_t mapcenter;
static angle_t mapangle;

static void AM_drawCrosshair(boolean force);
static void DrawWuLine(fline_t *fl, byte *BaseColor);
void AM_DrawDeathmatchStats(void);
static void DrawWorldTimer(void);
Expand Down Expand Up @@ -561,7 +560,6 @@ void AM_LevelInit (boolean reinit)
if (reinit && f_h_old)
{
scale_mtof = scale_mtof * f_h / f_h_old;
AM_drawCrosshair(true);
}
else
{
Expand Down Expand Up @@ -1219,6 +1217,13 @@ static inline void PUTDOT_THICK(int x, int y, pixel_t color)
if (ny < 0 || ny >= f_h)
continue;

// Calculate the squared distance from the center.
const int distance2 = dx * dx + dy * dy;

// Skip pixels outside the desired radius.
if (distance2 > thickness * thickness)
continue;

DOT(nx, ny, color);
}
}
Expand Down Expand Up @@ -2017,28 +2022,27 @@ static void AM_drawMarks (void)
// AM_drawCrosshair
// -----------------------------------------------------------------------------

static void AM_drawCrosshair (boolean force)
static void AM_drawCrosshair (void)
{
// [crispy] draw an actual crosshair
if (!followplayer || force)
{
static fline_t h, v;

if (!h.a.x || force)
{
h.a.x = h.b.x = v.a.x = v.b.x = f_x + f_w / 2;
h.a.y = h.b.y = v.a.y = v.b.y = f_y + f_h / 2;
h.a.x -= 2; h.b.x += 2;
v.a.y -= 2; v.b.y += 2;
}
// [JN] Draw the crosshair as a graphical patch to keep it unaffected by
// map line thickness, following the logic of mark drawing. Coloring via
// dp_translation is still needed to ensure it won't be affected much
// by possible custom PLAYPAL palette and modified color index.
//
// Patch drawing coordinates are the center of the screen:
// x: 158 = (ORIGWIDTH / 2) - 2
// y: 80 = (ORIGHEIGHT / 2) - 20

static const byte am_xhair[] =
{
3,0,3,0,0,0,0,0,20,0,0,0,26,0,0,0,
34,0,0,0,1,1,32,32,32,255,0,3,32,32,32,32,
32,255,1,1,32,32,32,255
};

// [JN] Do not draw crosshair while video re-init functions.
if (!force)
{
AM_drawFline(&h, XHAIRCOLORS);
AM_drawFline(&v, XHAIRCOLORS);
}
}
dp_translation = cr[CR_WHITE];
V_DrawPatch(158, 80, (patch_t*)&am_xhair);
dp_translation = NULL;
}

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -2151,7 +2155,7 @@ void AM_Drawer (void)
// [JN] Do not draw in following mode.
if (!followplayer)
{
AM_drawCrosshair(false);
AM_drawCrosshair();
}

AM_drawMarks();
Expand Down

0 comments on commit dabf781

Please sign in to comment.