diff --git a/src/heretic/am_map.c b/src/heretic/am_map.c index 345cc59b32..32a3f7b50b 100644 --- a/src/heretic/am_map.c +++ b/src/heretic/am_map.c @@ -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 +static pixel_t color_shades[NUMSHADES * 256]; const char *LevelNames[] = { // EPISODE 1 - THE CITY OF THE DAMNED @@ -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 static int amclock; static mpoint_t m_paninc; // how far the window pans each tic (map coords) @@ -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] = { {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] = { {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] /* static byte *aliasmax[NUMALIAS] = { &antialias[0][7], &antialias[1][7], &antialias[2][7] @@ -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, int NumLevels, unsigned short IntensityBits); // Calculates the slope and slope according to the x-axis of a line @@ -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; @@ -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; @@ -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: @@ -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); @@ -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); @@ -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)