Skip to content

Commit

Permalink
Heretic: true color - automap (line drawing)
Browse files Browse the repository at this point in the history
This is, hopefully, as small diff as possible, which could be useful for custom COLORMAPs (but are there any existing?). Note that unlike Doom, REINDEX is using lesser color range to be as close to original smoothing as possible.

At this point, only background is not working on automap.
  • Loading branch information
JNechaevsky committed Nov 19, 2023
1 parent f6276d1 commit f7ad2c1
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions src/heretic/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
vertex_t KeyPoints[NUM_KEY_TYPES];

#define NUMALIAS 3 // Number of antialiased lines.
// [crispy] precalculated color LUT for antialiased line drawing using COLORMAP
#define NUMSHADES 8

Check warning on line 37 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:37:9 [modernize-macro-to-enum]

macro 'NUMSHADES' defines an integral constant; prefer an enum instead
static pixel_t color_shades[NUMSHADES * 256];

Check warning on line 38 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:38:16 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'color_shades' is non-const and globally accessible, consider making it const

const char *LevelNames[] = {
// EPISODE 1 - THE CITY OF THE DAMNED
Expand Down Expand Up @@ -102,7 +105,7 @@ static int finit_height;// = SCREENHEIGHT - (42 << crispy->hires);
static int f_x, f_y; // location of window on screen
static int f_w, f_h; // size of window on screen
static int lightlev; // used for funky strobing effect
static byte *fb; // pseudo-frame buffer
static pixel_t *fb; // pseudo-frame buffer

Check warning on line 108 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:108:17 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'fb' is non-const and globally accessible, consider making it const

Check warning on line 108 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:108:17 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'fb' provides global access to a non-const object; consider making the pointed-to data 'const'

Check warning on line 108 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:108:17 [readability-identifier-length]

variable name 'fb' is too short, expected at least 3 characters
static int amclock;

static mpoint_t m_paninc; // how far the window pans each tic (map coords)
Expand Down Expand Up @@ -155,20 +158,20 @@ static char cheat_amap[] = { 'r', 'a', 'v', 'm', 'a', 'p' };
static byte cheatcount = 0;

// [crispy] gradient table for map normal mode
static byte antialias_normal[NUMALIAS][8] = {
static pixel_t antialias_normal[NUMALIAS][8] = {

Check warning on line 161 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:161:16 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'antialias_normal' is non-const and globally accessible, consider making it const
{96, 97, 98, 99, 100, 101, 102, 103},
{110, 109, 108, 107, 106, 105, 104, 103},
{75, 76, 77, 78, 79, 80, 81, 103}
};

// [crispy] gradient table for map overlay mode
static byte antialias_overlay[NUMALIAS][8] = {
static pixel_t antialias_overlay[NUMALIAS][8] = {

Check warning on line 168 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:168:16 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'antialias_overlay' is non-const and globally accessible, consider making it const
{100, 99, 98, 97, 96, 95, 95, 95},
{110, 109, 108, 105, 102, 99, 97, 95},
{75, 74, 73, 72, 71, 70, 69, 95}
};

static byte (*antialias)[NUMALIAS][8]; // [crispy]
static pixel_t (*antialias)[NUMALIAS][8]; // [crispy]

Check warning on line 174 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:174:18 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'antialias' is non-const and globally accessible, consider making it const

Check warning on line 174 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:174:18 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'antialias' provides global access to a non-const object; consider making the pointed-to data 'const'
/*
static byte *aliasmax[NUMALIAS] = {
&antialias[0][7], &antialias[1][7], &antialias[2][7]
Expand Down Expand Up @@ -199,7 +202,7 @@ extern fixed_t fractionaltic;

// Functions

void DrawWuLine(int X0, int Y0, int X1, int Y1, byte * BaseColor,
void DrawWuLine(int X0, int Y0, int X1, int Y1, int Color,

Check warning on line 205 in src/heretic/am_map.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

/src/heretic/am_map.c:205:21 [readability-identifier-length]

parameter name 'X0' is too short, expected at least 3 characters
int NumLevels, unsigned short IntensityBits);

// Calculates the slope and slope according to the x-axis of a line
Expand Down Expand Up @@ -545,6 +548,8 @@ void AM_LevelInit(boolean reinit)
{
// [crispy] Used for reinit
static int f_h_old;
// [crispy] Only need to precalculate color lookup tables once
static boolean precalc_once;

leveljuststarted = 0;

Expand Down Expand Up @@ -578,6 +583,26 @@ void AM_LevelInit(boolean reinit)
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);

f_h_old = f_h;

// [crispy] Precalculate color lookup tables for antialiased line drawing using COLORMAP
if (!precalc_once)
{
precalc_once = true;
for (int color = 0; color < 256; ++color)
{
#define REINDEX(I) (color + I * 256)
// Pick a range of shades for a steep gradient to keep lines thin
int shade_index[NUMSHADES] =
{
REINDEX(0), REINDEX(1), REINDEX(2), REINDEX(3), REINDEX(4), REINDEX(5), REINDEX(6), REINDEX(7),
};
#undef REINDEX
for (int shade = 0; shade < NUMSHADES; ++shade)
{
color_shades[color * NUMSHADES + shade] = colormaps[shade_index[shade]];
}
}
}
}

static boolean stopped = true;
Expand Down Expand Up @@ -1231,15 +1256,15 @@ void AM_drawFline(fline_t * fl, int color)
switch (color)
{
case WALLCOLORS:
DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, &(*antialias)[0][0],
DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, (*antialias)[0][0],
8, 3);
break;
case FDWALLCOLORS:
DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, &(*antialias)[1][0],
DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, (*antialias)[1][0],
8, 3);
break;
case CDWALLCOLORS:
DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, &(*antialias)[2][0],
DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, (*antialias)[2][0],
8, 3);
break;
default:
Expand All @@ -1254,7 +1279,11 @@ void AM_drawFline(fline_t * fl, int color)
return;
}

#ifndef CRISPY_TRUECOLOR
#define DOT(xx,yy,cc) fb[(yy)*f_w+(xx)]=(cc) //the MACRO!
#else
#define DOT(xx,yy,cc) fb[(yy)*f_w+(xx)]=(colormaps[cc])
#endif

dx = fl->b.x - fl->a.x;
ax = 2 * (dx < 0 ? -dx : dx);
Expand Down Expand Up @@ -1314,11 +1343,11 @@ void AM_drawFline(fline_t * fl, int color)
* IntensityBits = log base 2 of NumLevels; the # of bits used to describe
* the intensity of the drawing color. 2**IntensityBits==NumLevels
*/
void PUTDOT(short xx, short yy, byte * cc, byte * cm)
void PUTDOT(short xx, short yy, pixel_t * cc, pixel_t * cm)
{
static int oldyy;
static int oldyyshifted;
byte *oldcc = cc;
pixel_t *oldcc = cc;

if (xx < 32)
cc += 7 - (xx >> 2);
Expand Down Expand Up @@ -1358,12 +1387,13 @@ void PUTDOT(short xx, short yy, byte * cc, byte * cm)
// fb[(yy)*f_w+(xx)]=*(cc);
}

void DrawWuLine(int X0, int Y0, int X1, int Y1, byte * BaseColor,
void DrawWuLine(int X0, int Y0, int X1, int Y1, int Color,
int NumLevels, unsigned short IntensityBits)
{
unsigned short IntensityShift, ErrorAdj, ErrorAcc;
unsigned short ErrorAccTemp, Weighting, WeightingComplementMask;
short DeltaX, DeltaY, Temp, XDir;
pixel_t *BaseColor = &color_shades[Color * NUMSHADES];

/* Make sure the line runs top to bottom */
if (Y0 > Y1)
Expand Down

0 comments on commit f7ad2c1

Please sign in to comment.