Add built-in translations 'AllWhite', 'AllBlack', and 'DashMode'

This commit is contained in:
Lactozilla 2023-10-31 15:30:20 -03:00
parent 2064c220a0
commit 61673fe615
4 changed files with 98 additions and 43 deletions

View file

@ -24,12 +24,11 @@
#include "screen.h" // MAXVIDWIDTH, MAXVIDHEIGHT
#ifdef HWRENDER
#include "m_aatree.h"
#endif
#include "taglist.h"
// Amount of colors in the palette
#define NUM_PALETTE_ENTRIES 256
//
// ClipWallSegment
// Clips the given range of columns

View file

@ -18,6 +18,7 @@
#include "doomdef.h"
#include "doomstat.h"
#include "r_local.h"
#include "r_translation.h"
#include "st_stuff.h" // need ST_HEIGHT
#include "i_video.h"
#include "v_video.h"
@ -133,7 +134,6 @@ UINT32 nflatxshift, nflatyshift, nflatshiftup, nflatmask;
#define BLINK_TT_CACHE_INDEX (MAXSKINS + 5)
#define DASHMODE_TT_CACHE_INDEX (MAXSKINS + 6)
#define DEFAULT_STARTTRANSCOLOR 96
#define NUM_PALETTE_ENTRIES 256
static UINT8 **translationtablecache[MAXSKINS + 7] = {NULL};
UINT8 skincolor_modified[MAXSKINCOLORS];
@ -453,8 +453,14 @@ static void R_GenerateTranslationColormap(UINT8 *dest_colormap, INT32 skinnum, U
switch (skinnum)
{
case TC_ALLWHITE:
memset(dest_colormap, 0, NUM_PALETTE_ENTRIES * sizeof(UINT8));
return;
case TC_DASHMODE:
remaptable_t *tr = R_GetBuiltInTranslation((SINT8)skinnum);
if (tr)
{
memcpy(dest_colormap, tr->remap, NUM_PALETTE_ENTRIES);
return;
}
break;
case TC_RAINBOW:
if (color >= numskincolors)
I_Error("Invalid skin color #%hu.", (UINT16)color);
@ -500,40 +506,6 @@ static void R_GenerateTranslationColormap(UINT8 *dest_colormap, INT32 skinnum, U
for (i = 0; i < 16; i++)
dest_colormap[96+i] = dest_colormap[skincolors[SKINCOLOR_COBALT].ramp[i]];
}
else if (skinnum == TC_DASHMODE) // This is a long one, because MotorRoach basically hand-picked the indices
{
// greens -> ketchups
dest_colormap[96] = dest_colormap[97] = 48;
dest_colormap[98] = 49;
dest_colormap[99] = 51;
dest_colormap[100] = 52;
dest_colormap[101] = dest_colormap[102] = 54;
dest_colormap[103] = 34;
dest_colormap[104] = 37;
dest_colormap[105] = 39;
dest_colormap[106] = 41;
for (i = 0; i < 5; i++)
dest_colormap[107 + i] = 43 + i;
// reds -> steel blues
dest_colormap[32] = 146;
dest_colormap[33] = 147;
dest_colormap[34] = dest_colormap[35] = 170;
dest_colormap[36] = 171;
dest_colormap[37] = dest_colormap[38] = 172;
dest_colormap[39] = dest_colormap[40] = dest_colormap[41] = 173;
dest_colormap[42] = dest_colormap[43] = dest_colormap[44] = 174;
dest_colormap[45] = dest_colormap[46] = dest_colormap[47] = 175;
dest_colormap[71] = 139;
// steel blues -> oranges
dest_colormap[170] = 52;
dest_colormap[171] = 54;
dest_colormap[172] = 56;
dest_colormap[173] = 42;
dest_colormap[174] = 45;
dest_colormap[175] = 47;
}
return;
}
else if (color == SKINCOLOR_NONE)

View file

@ -11,6 +11,7 @@
#include "r_translation.h"
#include "r_data.h"
#include "r_draw.h"
#include "v_video.h" // pMasterPalette
#include "z_zone.h"
#include "w_wad.h"
@ -21,22 +22,45 @@
static remaptable_t **paletteremaps = NULL;
static unsigned numpaletteremaps = 0;
static int allWhiteRemap = 0;
static int allBlackRemap = 0;
static int dashModeRemap = 0;
static void MakeDashModeRemap(void);
void PaletteRemap_Init(void)
{
// First translation must be the identity one.
remaptable_t *base = PaletteRemap_New();
PaletteRemap_SetIdentity(base);
PaletteRemap_Add(base);
// Grayscale translation
remaptable_t *grayscale = PaletteRemap_New();
PaletteRemap_SetIdentity(grayscale);
PaletteRemap_AddDesaturation(grayscale, 0, 255, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
R_AddCustomTranslation("Grayscale", PaletteRemap_Add(grayscale));
// All white (TC_ALLWHITE)
remaptable_t *allWhite = PaletteRemap_New();
memset(allWhite->remap, 0, NUM_PALETTE_ENTRIES * sizeof(UINT8));
allWhiteRemap = PaletteRemap_Add(allWhite);
R_AddCustomTranslation("AllWhite", allWhiteRemap);
// All black
remaptable_t *allBlack = PaletteRemap_New();
memset(allBlack->remap, 31, NUM_PALETTE_ENTRIES * sizeof(UINT8));
allBlackRemap = PaletteRemap_Add(allBlack);
R_AddCustomTranslation("AllBlack", allBlackRemap);
// Dash mode (TC_DASHMODE)
MakeDashModeRemap();
}
remaptable_t *PaletteRemap_New(void)
{
remaptable_t *tr = Z_Calloc(sizeof(remaptable_t), PU_STATIC, NULL);
tr->num_entries = 256;
tr->num_entries = NUM_PALETTE_ENTRIES;
return tr;
}
@ -65,7 +89,7 @@ void PaletteRemap_SetIdentity(remaptable_t *tr)
boolean PaletteRemap_IsIdentity(remaptable_t *tr)
{
for (unsigned i = 0; i < 256; i++)
for (unsigned i = 0; i < NUM_PALETTE_ENTRIES; i++)
{
if (tr->remap[i] != i)
return false;
@ -91,6 +115,52 @@ unsigned PaletteRemap_Add(remaptable_t *tr)
return numpaletteremaps - 1;
}
// This is a long one, because MotorRoach basically hand-picked the indices
static void MakeDashModeRemap(void)
{
remaptable_t *dashmode = PaletteRemap_New();
PaletteRemap_SetIdentity(dashmode);
UINT8 *dest_colormap = dashmode->remap;
// greens -> ketchups
dest_colormap[96] = dest_colormap[97] = 48;
dest_colormap[98] = 49;
dest_colormap[99] = 51;
dest_colormap[100] = 52;
dest_colormap[101] = dest_colormap[102] = 54;
dest_colormap[103] = 34;
dest_colormap[104] = 37;
dest_colormap[105] = 39;
dest_colormap[106] = 41;
for (unsigned i = 0; i < 5; i++)
dest_colormap[107 + i] = 43 + i;
// reds -> steel blues
dest_colormap[32] = 146;
dest_colormap[33] = 147;
dest_colormap[34] = dest_colormap[35] = 170;
dest_colormap[36] = 171;
dest_colormap[37] = dest_colormap[38] = 172;
dest_colormap[39] = dest_colormap[40] = dest_colormap[41] = 173;
dest_colormap[42] = dest_colormap[43] = dest_colormap[44] = 174;
dest_colormap[45] = dest_colormap[46] = dest_colormap[47] = 175;
dest_colormap[71] = 139;
// steel blues -> oranges
dest_colormap[170] = 52;
dest_colormap[171] = 54;
dest_colormap[172] = 56;
dest_colormap[173] = 42;
dest_colormap[174] = 45;
dest_colormap[175] = 47;
dashModeRemap = PaletteRemap_Add(dashmode);
R_AddCustomTranslation("DashMode", dashModeRemap);
}
static boolean PalIndexOutOfRange(int color)
{
return color < 0 || color > 255;
@ -811,3 +881,15 @@ boolean R_TranslationIsValid(int id)
return true;
}
remaptable_t *R_GetBuiltInTranslation(SINT8 tc)
{
switch (tc)
{
case TC_ALLWHITE:
return R_GetTranslationByID(allWhiteRemap);
case TC_DASHMODE:
return R_GetTranslationByID(dashModeRemap);
}
return NULL;
}

View file

@ -100,4 +100,6 @@ boolean R_TranslationIsValid(int id);
void R_ParseTrnslate(INT32 wadNum, UINT16 lumpnum);
void R_LoadParsedTranslations(void);
remaptable_t *R_GetBuiltInTranslation(SINT8 tc);
#endif