diff --git a/src/p_setup.c b/src/p_setup.c index 2361d1efd..5cc7279c5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2937,7 +2937,6 @@ boolean P_SetupLevel(boolean skipprecip) // Important: take care of the ordering of the next functions. if (!loadedbm) P_CreateBlockMap(); // Graue 02-29-2004 - R_MakeColormaps(); P_LoadLineDefs2(); P_GroupLines(); numdmstarts = numredctfstarts = numbluectfstarts = 0; @@ -2974,7 +2973,6 @@ boolean P_SetupLevel(boolean skipprecip) // Important: take care of the ordering of the next functions. if (!loadedbm) P_CreateBlockMap(); // Graue 02-29-2004 - R_MakeColormaps(); P_LoadLineDefs2(); P_GroupLines(); numdmstarts = numredctfstarts = numbluectfstarts = 0; diff --git a/src/r_data.c b/src/r_data.c index 6aede0396..18c93787c 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1313,9 +1313,6 @@ void R_ReInitColormaps(UINT16 num) static lumpnum_t foundcolormaps[MAXCOLORMAPS]; -static char colormapFixingArray[MAXCOLORMAPS][3][9]; -static size_t carrayindex; - // // R_ClearColormaps // @@ -1327,8 +1324,6 @@ void R_ClearColormaps(void) num_extra_colormaps = 0; - carrayindex = 0; - for (i = 0; i < MAXCOLORMAPS; i++) foundcolormaps[i] = LUMPERROR; @@ -1385,7 +1380,7 @@ static int RoundUp(double number); INT32 R_CreateColormap(char *p1, char *p2, char *p3) { double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb; - double r, g, b, cbrightness, maskamt = 0, othermask = 0; + double maskamt = 0, othermask = 0; int mask, fog = 0; size_t mapnum = num_extra_colormaps; size_t i; @@ -1438,7 +1433,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) fadedist = fadeend - fadestart; fog = NUMFROMCHAR(p2[1]); } -#undef getnum +#undef NUMFROMCHAR if (p3[0] == '#') { @@ -1469,14 +1464,31 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) if (num_extra_colormaps == MAXCOLORMAPS) I_Error("R_CreateColormap: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); - strncpy(colormapFixingArray[num_extra_colormaps][0], p1, 8); - strncpy(colormapFixingArray[num_extra_colormaps][1], p2, 8); - strncpy(colormapFixingArray[num_extra_colormaps][2], p3, 8); - num_extra_colormaps++; + foundcolormaps[mapnum] = LUMPERROR; + + // aligned on 8 bit for asm code + extra_colormaps[mapnum].colormap = NULL; + extra_colormaps[mapnum].maskcolor = (UINT16)maskcolor; + extra_colormaps[mapnum].fadecolor = (UINT16)fadecolor; + extra_colormaps[mapnum].maskamt = maskamt; + extra_colormaps[mapnum].fadestart = (UINT16)fadestart; + extra_colormaps[mapnum].fadeend = (UINT16)fadeend; + extra_colormaps[mapnum].fog = fog; + + // This code creates the colormap array used by software renderer if (rendermode == render_soft) { + double r, g, b, cbrightness; + int p; + char *colormap_p; + + // Initialise the map and delta arrays + // map[i] stores an RGB color (as double) for index i, + // which is then converted to SRB2's palette later + // deltas[i] stores a corresponding fade delta between the RGB color and the final fade color; + // map[i]'s values are decremented by after each use for (i = 0; i < 256; i++) { r = pMasterPalette[i].s.red; @@ -1499,168 +1511,13 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) map[i][2] = 255.0l; deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist; } - } - foundcolormaps[mapnum] = LUMPERROR; - - // aligned on 8 bit for asm code - extra_colormaps[mapnum].colormap = NULL; - extra_colormaps[mapnum].maskcolor = (UINT16)maskcolor; - extra_colormaps[mapnum].fadecolor = (UINT16)fadecolor; - extra_colormaps[mapnum].maskamt = maskamt; - extra_colormaps[mapnum].fadestart = (UINT16)fadestart; - extra_colormaps[mapnum].fadeend = (UINT16)fadeend; - extra_colormaps[mapnum].fog = fog; - - return (INT32)mapnum; -} - -void R_MakeColormaps(void) -{ - size_t i; - - carrayindex = num_extra_colormaps; - num_extra_colormaps = 0; - - for (i = 0; i < carrayindex; i++) - R_CreateColormap2(colormapFixingArray[i][0], colormapFixingArray[i][1], - colormapFixingArray[i][2]); -} - -void R_CreateColormap2(char *p1, char *p2, char *p3) -{ - double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb; - double r, g, b, cbrightness; - double maskamt = 0, othermask = 0; - int mask, p, fog = 0; - size_t mapnum = num_extra_colormaps; - size_t i; - char *colormap_p; - UINT32 cr, cg, cb, maskcolor, fadecolor; - UINT32 fadestart = 0, fadeend = 31, fadedist = 31; - -#define HEX2INT(x) (UINT32)(x >= '0' && x <= '9' ? x - '0' : x >= 'a' && x <= 'f' ? x - 'a' + 10 : x >= 'A' && x <= 'F' ? x - 'A' + 10 : 0) - if (p1[0] == '#') - { - cr = ((HEX2INT(p1[1]) * 16) + HEX2INT(p1[2])); - cmaskr = cr; - cg = ((HEX2INT(p1[3]) * 16) + HEX2INT(p1[4])); - cmaskg = cg; - cb = ((HEX2INT(p1[5]) * 16) + HEX2INT(p1[6])); - cmaskb = cb; - // Create a rough approximation of the color (a 16 bit color) - maskcolor = ((cb) >> 3) + (((cg) >> 2) << 5) + (((cr) >> 3) << 11); - if (p1[7] >= 'a' && p1[7] <= 'z') - mask = (p1[7] - 'a'); - else if (p1[7] >= 'A' && p1[7] <= 'Z') - mask = (p1[7] - 'A'); - else - mask = 24; - - maskamt = (double)(mask/24.0l); - - othermask = 1 - maskamt; - maskamt /= 0xff; - cmaskr *= maskamt; - cmaskg *= maskamt; - cmaskb *= maskamt; - } - else - { - cmaskr = cmaskg = cmaskb = 0xff; - maskamt = 0; - maskcolor = ((0xff) >> 3) + (((0xff) >> 2) << 5) + (((0xff) >> 3) << 11); - } - -#define NUMFROMCHAR(c) (c >= '0' && c <= '9' ? c - '0' : 0) - if (p2[0] == '#') - { - // Get parameters like fadestart, fadeend, and the fogflag - fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10); - fadeend = NUMFROMCHAR(p2[5]) + (NUMFROMCHAR(p2[4]) * 10); - if (fadestart > 30) - fadestart = 0; - if (fadeend > 31 || fadeend < 1) - fadeend = 31; - fadedist = fadeend - fadestart; - fog = NUMFROMCHAR(p2[1]); - } -#undef getnum - - if (p3[0] == '#') - { - cdestr = cr = ((HEX2INT(p3[1]) * 16) + HEX2INT(p3[2])); - cdestg = cg = ((HEX2INT(p3[3]) * 16) + HEX2INT(p3[4])); - cdestb = cb = ((HEX2INT(p3[5]) * 16) + HEX2INT(p3[6])); - fadecolor = (((cb) >> 3) + (((cg) >> 2) << 5) + (((cr) >> 3) << 11)); - } - else - cdestr = cdestg = cdestb = fadecolor = 0; -#undef HEX2INT - - for (i = 0; i < num_extra_colormaps; i++) - { - if (foundcolormaps[i] != LUMPERROR) - continue; - if (maskcolor == extra_colormaps[i].maskcolor - && fadecolor == extra_colormaps[i].fadecolor - && (float)maskamt == (float)extra_colormaps[i].maskamt - && fadestart == extra_colormaps[i].fadestart - && fadeend == extra_colormaps[i].fadeend - && fog == extra_colormaps[i].fog) - { - return; - } - } - - if (num_extra_colormaps == MAXCOLORMAPS) - I_Error("R_CreateColormap: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); - - num_extra_colormaps++; - - if (rendermode == render_soft) - { - for (i = 0; i < 256; i++) - { - r = pMasterPalette[i].s.red; - g = pMasterPalette[i].s.green; - b = pMasterPalette[i].s.blue; - cbrightness = sqrt((r*r) + (g*g) + (b*b)); - - map[i][0] = (cbrightness * cmaskr) + (r * othermask); - if (map[i][0] > 255.0l) - map[i][0] = 255.0l; - deltas[i][0] = (map[i][0] - cdestr) / (double)fadedist; - - map[i][1] = (cbrightness * cmaskg) + (g * othermask); - if (map[i][1] > 255.0l) - map[i][1] = 255.0l; - deltas[i][1] = (map[i][1] - cdestg) / (double)fadedist; - - map[i][2] = (cbrightness * cmaskb) + (b * othermask); - if (map[i][2] > 255.0l) - map[i][2] = 255.0l; - deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist; - } - } - - foundcolormaps[mapnum] = LUMPERROR; - - // aligned on 8 bit for asm code - extra_colormaps[mapnum].colormap = NULL; - extra_colormaps[mapnum].maskcolor = (UINT16)maskcolor; - extra_colormaps[mapnum].fadecolor = (UINT16)fadecolor; - extra_colormaps[mapnum].maskamt = maskamt; - extra_colormaps[mapnum].fadestart = (UINT16)fadestart; - extra_colormaps[mapnum].fadeend = (UINT16)fadeend; - extra_colormaps[mapnum].fog = fog; - -#define ABS2(x) ((x) < 0 ? -(x) : (x)) - if (rendermode == render_soft) - { + // Now allocate memory for the actual colormap array itself! colormap_p = Z_MallocAlign((256 * 34) + 10, PU_LEVEL, NULL, 8); extra_colormaps[mapnum].colormap = (UINT8 *)colormap_p; + // Calculate the palette index for each palette index, for each light level + // (as well as the two unused colormap lines we inherited from Doom) for (p = 0; p < 34; p++) { for (i = 0; i < 256; i++) @@ -1672,7 +1529,7 @@ void R_CreateColormap2(char *p1, char *p2, char *p3) if ((UINT32)p < fadestart) continue; - +#define ABS2(x) ((x) < 0 ? -(x) : (x)) if (ABS2(map[i][0] - cdestr) > ABS2(deltas[i][0])) map[i][0] -= deltas[i][0]; else @@ -1687,12 +1544,12 @@ void R_CreateColormap2(char *p1, char *p2, char *p3) map[i][2] -= deltas[i][2]; else map[i][2] = cdestb; +#undef ABS2 } } } -#undef ABS2 - return; + return (INT32)mapnum; } // Thanks to quake2 source! diff --git a/src/r_data.h b/src/r_data.h index 53bf27835..250f4d7c2 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -100,8 +100,6 @@ void R_ReInitColormaps(UINT16 num); void R_ClearColormaps(void); INT32 R_ColormapNumForName(char *name); INT32 R_CreateColormap(char *p1, char *p2, char *p3); -void R_CreateColormap2(char *p1, char *p2, char *p3); -void R_MakeColormaps(void); const char *R_ColormapNameForNum(INT32 num); extern INT32 numtextures;