Skip to content

Commit

Permalink
Update truecolor code (#1153)
Browse files Browse the repository at this point in the history
* Doom & Heretic: generate HSV tables only once at startup

* Doom & Heretic: generate pal_color[] array from original palette

* Doom: replace truecolor-only occurences of colormaps[] with pal_color[]

* Heretic: replace truecolor-only occurences of colormaps[] with pal_color[]

* Hexen: replace truecolor-only occurences of colormaps[] with pal_color[]

* Add comment(s) for introduced pal_color[] array
  • Loading branch information
JNechaevsky authored Feb 2, 2024
1 parent 66633a2 commit 7c1cef4
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/doom/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ AM_drawFline_Vanilla
#ifndef CRISPY_TRUECOLOR
#define PUTDOT(xx,yy,cc) PUTDOT_RAW(xx,yy,cc)
#else
#define PUTDOT(xx,yy,cc) PUTDOT_RAW(xx,yy,(colormaps[(cc)]))
#define PUTDOT(xx,yy,cc) PUTDOT_RAW(xx,yy,(pal_color[(cc)]))
#endif

dx = fl->b.x - fl->a.x;
Expand Down Expand Up @@ -2104,7 +2104,7 @@ static void AM_drawCrosshair(int color, boolean force)
#ifndef CRISPY_TRUECOLOR
fb[(f_w*(f_h+1))/2] = color; // single point for now
#else
fb[(f_w*(f_h+1))/2] = colormaps[color]; // single point for now
fb[(f_w*(f_h+1))/2] = pal_color[color]; // single point for now
#endif
*/

Expand Down
2 changes: 1 addition & 1 deletion src/doom/f_finale.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ F_DrawPatchCol
#ifndef CRISPY_TRUECOLOR
*dest = source[srccol >> FRACBITS];
#else
*dest = colormaps[source[srccol >> FRACBITS]];
*dest = pal_color[source[srccol >> FRACBITS]];
#endif
srccol += dyi;
dest += SCREENWIDTH;
Expand Down
12 changes: 6 additions & 6 deletions src/doom/hu_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "dstrings.h"
#include "sounds.h"

#include "r_state.h" // [crispy] colormaps
#include "r_state.h" // [crispy] pal_color
#include "v_video.h" // [crispy] V_DrawPatch() et al.
#include "v_trans.h" // [crispy] colored kills/items/secret/etc. messages

Expand Down Expand Up @@ -782,12 +782,12 @@ void HU_DemoProgressBar (void)
// V_DrawHorizLine(0, SCREENHEIGHT - 2, 1, 4); // [crispy] white start
// V_DrawHorizLine(i - 1, SCREENHEIGHT - 2, 1, 4); // [crispy] white end
#else
// V_DrawHorizLine(0, SCREENHEIGHT - 3, i, colormaps[4]); // [crispy] white
V_DrawHorizLine(0, SCREENHEIGHT - 2, i, colormaps[0]); // [crispy] black
V_DrawHorizLine(0, SCREENHEIGHT - 1, i, colormaps[4]); // [crispy] white
// V_DrawHorizLine(0, SCREENHEIGHT - 3, i, pal_color[4]); // [crispy] white
V_DrawHorizLine(0, SCREENHEIGHT - 2, i, pal_color[0]); // [crispy] black
V_DrawHorizLine(0, SCREENHEIGHT - 1, i, pal_color[4]); // [crispy] white

// V_DrawHorizLine(0, SCREENHEIGHT - 2, 1, colormaps[4]); // [crispy] white start
// V_DrawHorizLine(i - 1, SCREENHEIGHT - 2, 1, colormaps[4]); // [crispy] white end
// V_DrawHorizLine(0, SCREENHEIGHT - 2, 1, pal_color[4]); // [crispy] white start
// V_DrawHorizLine(i - 1, SCREENHEIGHT - 2, 1, pal_color[4]); // [crispy] white end
#endif
}

Expand Down
46 changes: 32 additions & 14 deletions src/doom/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ fixed_t* spritewidth;
fixed_t* spriteoffset;
fixed_t* spritetopoffset;

lighttable_t *colormaps, *pal_color;
lighttable_t *colormaps;
lighttable_t *pal_color; // [crispy] array holding palette colors for true color mode

// [FG] check if the lump can be a Doom patch
// taken from PrBoom+ prboom2/src/r_patch.c:L350-L390
Expand Down Expand Up @@ -1189,19 +1190,17 @@ void R_InitColormaps (void)
lump = W_GetNumForName(DEH_String("COLORMAP"));
colormaps = W_CacheLumpNum(lump, PU_STATIC);
#else
byte *playpal;
int c, i, j = 0;
byte r, g, b;

playpal = W_CacheLumpName("PLAYPAL", PU_STATIC);
byte *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC);
byte *const colormap = W_CacheLumpName("COLORMAP", PU_STATIC);

if (!colormaps)
{
colormaps = (lighttable_t*) Z_Malloc((NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t), PU_STATIC, 0);
}

pal_color = colormaps;

if (crispy->truecolor)
{
for (c = 0; c < NUMCOLORMAPS; c++)
Expand All @@ -1210,9 +1209,11 @@ void R_InitColormaps (void)

for (i = 0; i < 256; i++)
{
r = gamma2table[crispy->gamma][playpal[3 * i + 0]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
g = gamma2table[crispy->gamma][playpal[3 * i + 1]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
b = gamma2table[crispy->gamma][playpal[3 * i + 2]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
const byte k = colormap[i];

r = gamma2table[crispy->gamma][playpal[3 * k + 0]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
g = gamma2table[crispy->gamma][playpal[3 * k + 1]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
b = gamma2table[crispy->gamma][playpal[3 * k + 2]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;

colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
Expand All @@ -1232,8 +1233,6 @@ void R_InitColormaps (void)
}
else
{
byte *const colormap = W_CacheLumpName("COLORMAP", PU_STATIC);

for (c = 0; c <= NUMCOLORMAPS; c++)
{
for (i = 0; i < 256; i++)
Expand All @@ -1245,13 +1244,31 @@ void R_InitColormaps (void)
colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
}

W_ReleaseLumpName("COLORMAP");

if (!pal_color)
{
pal_color = (pixel_t*) Z_Malloc(256 * sizeof(pixel_t), PU_STATIC, 0);
}

W_ReleaseLumpName("COLORMAP");
for (i = 0, j = 0; i < 256; i++)
{
r = gamma2table[crispy->gamma][playpal[3 * i + 0]];
g = gamma2table[crispy->gamma][playpal[3 * i + 1]];
b = gamma2table[crispy->gamma][playpal[3 * i + 2]];

pal_color[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}

W_ReleaseLumpName("PLAYPAL");
#endif
}

// [crispy] initialize color translation and color strings tables
{
// [crispy] initialize color translation and color string tables
static void R_InitHSVColors(void)
{
byte *playpal = W_CacheLumpName("PLAYPAL", PU_STATIC);
char c[3];
int i, j;
Expand Down Expand Up @@ -1291,7 +1308,6 @@ void R_InitColormaps (void)
{
cr[CR_RED2BLUE] = W_CacheLumpNum(i, PU_STATIC);
}
}
}


Expand Down Expand Up @@ -1320,6 +1336,8 @@ void R_InitData (void)
// [crispy] Initialize and generate gamma-correction levels.
I_SetGammaTable ();
R_InitColormaps ();
// [crispy] Initialize color translation and color string tables.
R_InitHSVColors ();
#ifndef CRISPY_TRUECOLOR
R_InitTranMap(); // [crispy] prints a mark itself
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/doom/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ void R_RenderPlayerView (player_t* player)
#ifndef CRISPY_TRUECOLOR
176 + (gametic % 16));
#else
colormaps[176 + (gametic % 16)]);
pal_color[176 + (gametic % 16)]);
#endif
}

Expand Down
1 change: 1 addition & 0 deletions src/doom/r_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern fixed_t* spriteoffset;
extern fixed_t* spritetopoffset;

extern lighttable_t* colormaps;
extern lighttable_t* pal_color;

extern int viewwidth;
extern int scaledviewwidth;
Expand Down
10 changes: 5 additions & 5 deletions src/heretic/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,21 +1101,21 @@ void AM_clearFB(int color)

for (z = 0; z < x3; z++)
{
dest[z] = colormaps[src[z]];
dest[z] = pal_color[src[z]];
}

dest += x3;
src += x3 - x2;
for (z = 0; z < x2; z++)
{
dest[z] = colormaps[src[z]];
dest[z] = pal_color[src[z]];
}

dest += x2;
src = maplump + j;
for (z = 0; z < x1; z++)
{
dest[z] = colormaps[src[z]];
dest[z] = pal_color[src[z]];
}
#endif
j += MAPBGROUNDWIDTH << crispy->hires;
Expand Down Expand Up @@ -1273,7 +1273,7 @@ void AM_drawFline(fline_t * fl, int color)
#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])
#define DOT(xx,yy,cc) fb[(yy)*f_w+(xx)]=(pal_color[cc])
#endif

dx = fl->b.x - fl->a.x;
Expand Down Expand Up @@ -1377,7 +1377,7 @@ void PUTDOT(short xx, short yy, byte * cc, byte * cm)
#ifndef CRISPY_TRUECOLOR
fb[oldyyshifted + xx] = *(cc);
#else
fb[oldyyshifted + xx] = colormaps[*(cc)];
fb[oldyyshifted + xx] = pal_color[*(cc)];
#endif
// fb[(yy)*f_w+(xx)]=*(cc);
}
Expand Down
45 changes: 32 additions & 13 deletions src/heretic/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fixed_t *spritewidth; // needed for pre rendering
fixed_t *spriteoffset;
fixed_t *spritetopoffset;

lighttable_t *colormaps, *pal_color;
lighttable_t *colormaps;
lighttable_t *pal_color; // [crispy] array holding palette colors for true color mode


/*
Expand Down Expand Up @@ -530,20 +531,17 @@ void R_InitColormaps(void)
colormaps = Z_Malloc(length, PU_STATIC, 0);
W_ReadLump(lump, colormaps);
#else
byte *playpal;
byte *const colormap = W_CacheLumpName("COLORMAP", PU_STATIC);
int c, i, j = 0;
byte r, g, b;

playpal = W_CacheLumpName("PLAYPAL", PU_STATIC);
byte *const playpal = W_CacheLumpName("PLAYPAL", PU_STATIC);
byte *const colormap = W_CacheLumpName("COLORMAP", PU_STATIC);

if (!colormaps)
{
colormaps = (lighttable_t*) Z_Malloc((NUMCOLORMAPS + 1) * 256 * sizeof(lighttable_t), PU_STATIC, 0);
}

pal_color = colormaps;

if (crispy->truecolor)
{
for (c = 0; c < NUMCOLORMAPS; c++)
Expand All @@ -552,9 +550,11 @@ void R_InitColormaps(void)

for (i = 0; i < 256; i++)
{
r = gamma2table[crispy->gamma][playpal[3 * i + 0]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
g = gamma2table[crispy->gamma][playpal[3 * i + 1]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
b = gamma2table[crispy->gamma][playpal[3 * i + 2]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
const byte k = colormap[i];

r = gamma2table[crispy->gamma][playpal[3 * k + 0]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
g = gamma2table[crispy->gamma][playpal[3 * k + 1]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;
b = gamma2table[crispy->gamma][playpal[3 * k + 2]] * (1. - scale) + gamma2table[crispy->gamma][0] * scale;

colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
Expand Down Expand Up @@ -586,10 +586,28 @@ void R_InitColormaps(void)
}

W_ReleaseLumpName("COLORMAP");

if (!pal_color)
{
pal_color = (pixel_t*) Z_Malloc(256 * sizeof(pixel_t), PU_STATIC, 0);
}

for (i = 0, j = 0; i < 256; i++)
{
r = gamma2table[crispy->gamma][playpal[3 * i + 0]];
g = gamma2table[crispy->gamma][playpal[3 * i + 1]];
b = gamma2table[crispy->gamma][playpal[3 * i + 2]];

pal_color[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}

W_ReleaseLumpName("PLAYPAL");
#endif
}

// [crispy] initialize color translation and color string tables
{
// [crispy] initialize color translation and color string tables
static void R_InitHSVColors(void)
{
byte *playpal = W_CacheLumpName("PLAYPAL", PU_STATIC);
char c[3];
int i, j;
Expand All @@ -610,7 +628,6 @@ void R_InitColormaps(void)
}

W_ReleaseLumpName("PLAYPAL");
}
}

#ifdef CRISPY_TRUECOLOR
Expand All @@ -628,7 +645,7 @@ void R_SetUnderwaterPalette(byte *palette)
g = gamma2table[crispy->gamma][palette[3 * i + 1]] + gamma2table[crispy->gamma][0];
b = gamma2table[crispy->gamma][palette[3 * i + 2]] + gamma2table[crispy->gamma][0];

colormaps[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
pal_color[j++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
#endif
Expand Down Expand Up @@ -667,6 +684,8 @@ void R_InitData(void)
// [crispy] Initialize and generate gamma-correction levels.
I_SetGammaTable();
R_InitColormaps();
// [crispy] Initialize color translation and color string tables.
R_InitHSVColors();
}


Expand Down
2 changes: 1 addition & 1 deletion src/heretic/r_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ extern fixed_t *textureheight; // needed for texture pegging
extern fixed_t *spritewidth; // needed for pre rendering (fracs)
extern fixed_t *spriteoffset;
extern fixed_t *spritetopoffset;
extern lighttable_t *colormaps;
extern lighttable_t *colormaps, *pal_color;
extern int firstflat;
extern int numflats;

Expand Down
4 changes: 2 additions & 2 deletions src/heretic/r_plane.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ void R_DrawPlanes(void)
#ifndef CRISPY_TRUECOLOR
*dest = dc_source[frac >> FRACBITS];
#else
*dest = colormaps[dc_source[frac >> FRACBITS]];
*dest = pal_color[dc_source[frac >> FRACBITS]];
#endif
dest += SCREENWIDTH;

Expand All @@ -540,7 +540,7 @@ void R_DrawPlanes(void)
#ifndef CRISPY_TRUECOLOR
*dest = dc_source[(frac >> FRACBITS) & heightmask];
#else
*dest = colormaps[dc_source[(frac >> FRACBITS) & heightmask]];
*dest = pal_color[dc_source[(frac >> FRACBITS) & heightmask]];
#endif
dest += SCREENWIDTH;
frac += fracstep;
Expand Down
10 changes: 5 additions & 5 deletions src/hexen/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,21 +1005,21 @@ void AM_clearFB(int color)

for (z = 0; z < x3; z++)
{
dest[z] = colormaps[src[z]];
dest[z] = pal_color[src[z]];
}

dest += x3;
src += x3 - x2;
for (z = 0; z < x2; z++)
{
dest[z] = colormaps[src[z]];
dest[z] = pal_color[src[z]];
}

dest += x2;
src = maplump + j;
for (z = 0; z < x1; z++)
{
dest[z] = colormaps[src[z]];
dest[z] = pal_color[src[z]];
}
#endif

Expand Down Expand Up @@ -1177,7 +1177,7 @@ void AM_drawFline(fline_t * fl, int color)
#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])
#define DOT(xx,yy,cc) fb[(yy)*f_w+(xx)]=(pal_color[cc])
#endif

dx = fl->b.x - fl->a.x;
Expand Down Expand Up @@ -1281,7 +1281,7 @@ void PUTDOT(short xx, short yy, byte * cc, byte * cm)
#ifndef CRISPY_TRUECOLOR
fb[oldyyshifted + xx] = *(cc);
#else
fb[oldyyshifted + xx] = colormaps[*(cc)];
fb[oldyyshifted + xx] = pal_color[*(cc)];
#endif
// fb[(yy)*f_w+(xx)]=*(cc);
}
Expand Down
Loading

1 comment on commit 7c1cef4

@kitchen-ace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job getting this working guys! Happy to help, though I really didn't do very much :p

Please sign in to comment.