2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
2020-02-19 22:08:45 +00:00
|
|
|
// Copyright (C) 1999-2020 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file r_data.c
|
2019-10-28 18:28:42 +00:00
|
|
|
/// \brief Preparation of data for rendering, generation of lookups, caching, retrieval by name
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "g_game.h"
|
|
|
|
#include "i_video.h"
|
|
|
|
#include "r_local.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "m_misc.h"
|
|
|
|
#include "r_data.h"
|
2020-01-07 15:35:10 +00:00
|
|
|
#include "r_textures.h"
|
2019-10-28 18:28:42 +00:00
|
|
|
#include "r_patch.h"
|
2020-01-06 21:22:23 +00:00
|
|
|
#include "r_picformats.h"
|
2014-03-15 16:59:03 +00:00
|
|
|
#include "w_wad.h"
|
|
|
|
#include "z_zone.h"
|
|
|
|
#include "p_setup.h" // levelflats
|
2017-04-29 15:40:07 +00:00
|
|
|
#include "v_video.h" // pMasterPalette
|
2019-09-10 19:54:40 +00:00
|
|
|
#include "f_finale.h" // wipes
|
2019-09-20 01:40:23 +00:00
|
|
|
#include "byteptr.h"
|
2014-03-15 16:59:03 +00:00
|
|
|
#include "dehacked.h"
|
|
|
|
|
2017-09-29 22:25:34 +00:00
|
|
|
#ifdef _WIN32
|
2014-03-15 16:59:03 +00:00
|
|
|
#include <malloc.h> // alloca(sizeof)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// Graphics.
|
|
|
|
// SRB2 graphics for walls and sprites
|
|
|
|
// is stored in vertical runs of opaque pixels (posts).
|
|
|
|
// A column is composed of zero or more posts,
|
|
|
|
// a patch or sprite is composed of zero or more columns.
|
|
|
|
//
|
|
|
|
|
|
|
|
size_t numspritelumps, max_spritelumps;
|
|
|
|
|
|
|
|
// needed for pre rendering
|
|
|
|
sprcache_t *spritecachedinfo;
|
|
|
|
|
|
|
|
lighttable_t *colormaps;
|
2019-09-10 19:54:40 +00:00
|
|
|
lighttable_t *fadecolormap;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// for debugging/info purposes
|
2019-08-18 17:16:48 +00:00
|
|
|
size_t flatmemory, spritememory, texturememory;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// highcolor stuff
|
|
|
|
INT16 color8to16[256]; // remap color index to highcolor rgb value
|
|
|
|
INT16 *hicolormaps; // test a 32k colormap remaps high -> high
|
|
|
|
|
2020-05-16 16:51:10 +00:00
|
|
|
// Blends two pixels together, using the equation
|
|
|
|
// that matches the specified alpha style.
|
2019-09-18 01:29:53 +00:00
|
|
|
UINT32 ASTBlendPixel(RGBA_t background, RGBA_t foreground, int style, UINT8 alpha)
|
2019-09-08 16:21:00 +00:00
|
|
|
{
|
|
|
|
RGBA_t output;
|
2020-02-02 01:25:48 +00:00
|
|
|
INT16 fullalpha = (alpha - (0xFF - foreground.s.alpha));
|
2019-09-08 16:21:00 +00:00
|
|
|
if (style == AST_TRANSLUCENT)
|
|
|
|
{
|
2020-02-02 01:25:48 +00:00
|
|
|
if (fullalpha <= 0)
|
2019-09-08 16:21:00 +00:00
|
|
|
output.rgba = background.rgba;
|
2020-02-02 01:25:48 +00:00
|
|
|
else
|
2019-09-08 16:21:00 +00:00
|
|
|
{
|
2020-02-02 01:25:48 +00:00
|
|
|
// don't go too high
|
|
|
|
if (fullalpha >= 0xFF)
|
|
|
|
fullalpha = 0xFF;
|
|
|
|
alpha = (UINT8)fullalpha;
|
|
|
|
|
2020-02-02 01:25:48 +00:00
|
|
|
// if the background pixel is empty,
|
|
|
|
// match software and don't blend anything
|
2020-02-02 01:25:48 +00:00
|
|
|
if (!background.s.alpha)
|
2020-05-15 19:41:39 +00:00
|
|
|
{
|
|
|
|
// ...unless the foreground pixel ISN'T actually translucent.
|
|
|
|
if (alpha == 0xFF)
|
|
|
|
output.rgba = foreground.rgba;
|
|
|
|
else
|
|
|
|
output.rgba = 0;
|
|
|
|
}
|
2020-02-02 01:25:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
UINT8 beta = (0xFF - alpha);
|
|
|
|
output.s.red = ((background.s.red * beta) + (foreground.s.red * alpha)) / 0xFF;
|
|
|
|
output.s.green = ((background.s.green * beta) + (foreground.s.green * alpha)) / 0xFF;
|
|
|
|
output.s.blue = ((background.s.blue * beta) + (foreground.s.blue * alpha)) / 0xFF;
|
|
|
|
output.s.alpha = 0xFF;
|
|
|
|
}
|
2019-09-08 16:21:00 +00:00
|
|
|
}
|
2019-09-23 21:25:16 +00:00
|
|
|
return output.rgba;
|
2019-09-08 16:21:00 +00:00
|
|
|
}
|
|
|
|
#define clamp(c) max(min(c, 0xFF), 0x00);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float falpha = ((float)alpha / 256.0f);
|
|
|
|
float fr = ((float)foreground.s.red * falpha);
|
|
|
|
float fg = ((float)foreground.s.green * falpha);
|
|
|
|
float fb = ((float)foreground.s.blue * falpha);
|
|
|
|
if (style == AST_ADD)
|
|
|
|
{
|
|
|
|
output.s.red = clamp((int)(background.s.red + fr));
|
|
|
|
output.s.green = clamp((int)(background.s.green + fg));
|
|
|
|
output.s.blue = clamp((int)(background.s.blue + fb));
|
|
|
|
}
|
|
|
|
else if (style == AST_SUBTRACT)
|
|
|
|
{
|
|
|
|
output.s.red = clamp((int)(background.s.red - fr));
|
|
|
|
output.s.green = clamp((int)(background.s.green - fg));
|
|
|
|
output.s.blue = clamp((int)(background.s.blue - fb));
|
|
|
|
}
|
|
|
|
else if (style == AST_REVERSESUBTRACT)
|
|
|
|
{
|
|
|
|
output.s.red = clamp((int)((-background.s.red) + fr));
|
|
|
|
output.s.green = clamp((int)((-background.s.green) + fg));
|
|
|
|
output.s.blue = clamp((int)((-background.s.blue) + fb));
|
|
|
|
}
|
|
|
|
else if (style == AST_MODULATE)
|
|
|
|
{
|
|
|
|
fr = ((float)foreground.s.red / 256.0f);
|
|
|
|
fg = ((float)foreground.s.green / 256.0f);
|
|
|
|
fb = ((float)foreground.s.blue / 256.0f);
|
|
|
|
output.s.red = clamp((int)(background.s.red * fr));
|
|
|
|
output.s.green = clamp((int)(background.s.green * fg));
|
|
|
|
output.s.blue = clamp((int)(background.s.blue * fb));
|
|
|
|
}
|
|
|
|
// just copy the pixel
|
|
|
|
else if (style == AST_COPY)
|
2019-09-18 01:29:53 +00:00
|
|
|
output.rgba = foreground.rgba;
|
|
|
|
|
|
|
|
output.s.alpha = 0xFF;
|
|
|
|
return output.rgba;
|
2019-09-08 16:21:00 +00:00
|
|
|
}
|
|
|
|
#undef clamp
|
2019-09-18 01:29:53 +00:00
|
|
|
return 0;
|
2019-09-08 16:21:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 16:51:10 +00:00
|
|
|
INT32 ASTTextureBlendingThreshold[2] = {255/11, (10*255/11)};
|
|
|
|
|
|
|
|
// Blends a pixel for a texture patch.
|
|
|
|
UINT32 ASTBlendTexturePixel(RGBA_t background, RGBA_t foreground, int style, UINT8 alpha)
|
2019-09-08 16:21:00 +00:00
|
|
|
{
|
2019-09-23 21:25:16 +00:00
|
|
|
// Alpha style set to translucent?
|
|
|
|
if (style == AST_TRANSLUCENT)
|
2019-09-08 16:21:00 +00:00
|
|
|
{
|
2019-09-23 21:25:16 +00:00
|
|
|
// Is the alpha small enough for translucency?
|
2020-05-16 16:51:10 +00:00
|
|
|
if (alpha <= ASTTextureBlendingThreshold[1])
|
|
|
|
{
|
|
|
|
// Is the patch way too translucent? Don't blend then.
|
|
|
|
if (alpha < ASTTextureBlendingThreshold[0])
|
2020-05-16 17:01:42 +00:00
|
|
|
return background.rgba;
|
2020-05-16 16:51:10 +00:00
|
|
|
|
2020-05-16 17:01:42 +00:00
|
|
|
return ASTBlendPixel(background, foreground, style, alpha);
|
2020-05-16 16:51:10 +00:00
|
|
|
}
|
|
|
|
else // just copy the pixel
|
2020-05-16 17:01:42 +00:00
|
|
|
return foreground.rgba;
|
2020-05-16 16:51:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return ASTBlendPixel(background, foreground, style, alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blends two palette indexes for a texture patch, then
|
|
|
|
// finds the nearest palette index from the blended output.
|
|
|
|
UINT8 ASTBlendPaletteIndexes(UINT8 background, UINT8 foreground, int style, UINT8 alpha)
|
2019-09-08 16:21:00 +00:00
|
|
|
{
|
2019-09-23 21:25:16 +00:00
|
|
|
// Alpha style set to translucent?
|
|
|
|
if (style == AST_TRANSLUCENT)
|
2019-09-08 16:21:00 +00:00
|
|
|
{
|
2019-09-23 21:25:16 +00:00
|
|
|
// Is the alpha small enough for translucency?
|
2020-05-16 16:51:10 +00:00
|
|
|
if (alpha <= ASTTextureBlendingThreshold[1])
|
2019-09-23 21:25:16 +00:00
|
|
|
{
|
|
|
|
UINT8 *mytransmap;
|
2020-05-16 16:51:10 +00:00
|
|
|
|
2019-09-23 21:25:16 +00:00
|
|
|
// Is the patch way too translucent? Don't blend then.
|
2020-05-16 16:51:10 +00:00
|
|
|
if (alpha < ASTTextureBlendingThreshold[0])
|
2019-09-23 21:25:16 +00:00
|
|
|
return background;
|
2020-05-16 16:51:10 +00:00
|
|
|
|
2019-09-23 21:25:16 +00:00
|
|
|
// The equation's not exact but it works as intended. I'll call it a day for now.
|
|
|
|
mytransmap = transtables + ((8*(alpha) + 255/8)/(255 - 255/11) << FF_TRANSSHIFT);
|
|
|
|
if (background != 0xFF)
|
|
|
|
return *(mytransmap + (background<<8) + foreground);
|
|
|
|
}
|
|
|
|
else // just copy the pixel
|
|
|
|
return foreground;
|
2019-09-08 16:21:00 +00:00
|
|
|
}
|
|
|
|
// just copy the pixel
|
|
|
|
else if (style == AST_COPY)
|
2019-09-18 01:29:53 +00:00
|
|
|
return foreground;
|
2019-09-08 16:21:00 +00:00
|
|
|
// use ASTBlendPixel for all other blend modes
|
|
|
|
// and find the nearest colour in the palette
|
|
|
|
else if (style != AST_TRANSLUCENT)
|
|
|
|
{
|
|
|
|
RGBA_t texel;
|
2020-01-05 01:19:30 +00:00
|
|
|
RGBA_t bg = V_GetMasterColor(background);
|
|
|
|
RGBA_t fg = V_GetMasterColor(foreground);
|
2019-09-18 01:29:53 +00:00
|
|
|
texel.rgba = ASTBlendPixel(bg, fg, style, alpha);
|
2019-09-08 16:21:00 +00:00
|
|
|
return NearestColor(texel.s.red, texel.s.green, texel.s.blue);
|
|
|
|
}
|
|
|
|
// fallback if all above fails, somehow
|
|
|
|
// return the background pixel
|
|
|
|
return background;
|
|
|
|
}
|
|
|
|
|
2018-09-15 06:10:17 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
|
|
|
static lumplist_t *colormaplumps = NULL; ///\todo free leak
|
|
|
|
static size_t numcolormaplumps = 0;
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
static inline lumpnum_t R_CheckNumForNameList(const char *name, lumplist_t *list, size_t listsize)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
UINT16 lump;
|
|
|
|
|
|
|
|
for (i = listsize - 1; i < INT16_MAX; i--)
|
|
|
|
{
|
|
|
|
lump = W_CheckNumForNamePwad(name, list[i].wadfile, list[i].firstlump);
|
|
|
|
if (lump == INT16_MAX || lump > (list[i].firstlump + list[i].numlumps))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return (list[i].wadfile<<16)+lump;
|
|
|
|
}
|
|
|
|
return LUMPERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void R_InitExtraColormaps(void)
|
|
|
|
{
|
|
|
|
lumpnum_t startnum, endnum;
|
|
|
|
UINT16 cfile, clump;
|
|
|
|
static size_t maxcolormaplumps = 16;
|
|
|
|
|
|
|
|
for (cfile = clump = 0; cfile < numwadfiles; cfile++, clump = 0)
|
|
|
|
{
|
|
|
|
startnum = W_CheckNumForNamePwad("C_START", cfile, clump);
|
2017-05-15 13:29:31 +00:00
|
|
|
if (startnum == INT16_MAX)
|
2014-03-15 16:59:03 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
endnum = W_CheckNumForNamePwad("C_END", cfile, clump);
|
|
|
|
|
2017-05-15 13:29:31 +00:00
|
|
|
if (endnum == INT16_MAX)
|
2014-03-15 16:59:03 +00:00
|
|
|
I_Error("R_InitExtraColormaps: C_START without C_END\n");
|
|
|
|
|
2017-05-15 13:38:55 +00:00
|
|
|
// This shouldn't be possible when you use the Pwad function, silly
|
|
|
|
//if (WADFILENUM(startnum) != WADFILENUM(endnum))
|
|
|
|
//I_Error("R_InitExtraColormaps: C_START and C_END in different wad files!\n");
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
if (numcolormaplumps >= maxcolormaplumps)
|
|
|
|
maxcolormaplumps *= 2;
|
|
|
|
colormaplumps = Z_Realloc(colormaplumps,
|
|
|
|
sizeof (*colormaplumps) * maxcolormaplumps, PU_STATIC, NULL);
|
2017-05-15 13:38:55 +00:00
|
|
|
colormaplumps[numcolormaplumps].wadfile = cfile;
|
|
|
|
colormaplumps[numcolormaplumps].firstlump = startnum+1;
|
2014-03-15 16:59:03 +00:00
|
|
|
colormaplumps[numcolormaplumps].numlumps = endnum - (startnum + 1);
|
|
|
|
numcolormaplumps++;
|
|
|
|
}
|
|
|
|
CONS_Printf(M_GetText("Number of Extra Colormaps: %s\n"), sizeu1(numcolormaplumps));
|
|
|
|
}
|
2018-09-11 00:36:34 +00:00
|
|
|
#endif
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// R_InitSpriteLumps
|
|
|
|
// Finds the width and hoffset of all sprites in the wad, so the sprite does not need to be
|
|
|
|
// cached completely, just for having the header info ready during rendering.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate sprite lookup tables
|
|
|
|
//
|
|
|
|
static void R_InitSpriteLumps(void)
|
|
|
|
{
|
|
|
|
numspritelumps = 0;
|
|
|
|
max_spritelumps = 8192;
|
|
|
|
|
|
|
|
Z_Malloc(max_spritelumps*sizeof(*spritecachedinfo), PU_STATIC, &spritecachedinfo);
|
|
|
|
}
|
|
|
|
|
2019-09-10 02:31:48 +00:00
|
|
|
//
|
|
|
|
// R_CreateFadeColormaps
|
|
|
|
//
|
2019-09-10 19:54:40 +00:00
|
|
|
|
2019-11-15 21:53:32 +00:00
|
|
|
static void R_CreateFadeColormaps(void)
|
2019-09-10 02:31:48 +00:00
|
|
|
{
|
|
|
|
UINT8 px, fade;
|
|
|
|
RGBA_t rgba;
|
|
|
|
INT32 r, g, b;
|
2019-09-10 19:54:40 +00:00
|
|
|
size_t len, i;
|
2019-09-10 02:31:48 +00:00
|
|
|
|
2019-09-10 19:54:40 +00:00
|
|
|
len = (256 * FADECOLORMAPROWS);
|
2019-09-10 02:31:48 +00:00
|
|
|
fadecolormap = Z_MallocAlign(len*2, PU_STATIC, NULL, 8);
|
2019-09-10 19:54:40 +00:00
|
|
|
for (i = 0; i < len*2; i++)
|
|
|
|
fadecolormap[i] = (i%256);
|
|
|
|
|
|
|
|
// Load in the light tables, now 64k aligned for smokie...
|
|
|
|
{
|
|
|
|
lumpnum_t lump = W_CheckNumForName("FADECMAP");
|
|
|
|
lumpnum_t wlump = W_CheckNumForName("FADEWMAP");
|
|
|
|
|
|
|
|
// to black
|
|
|
|
if (lump != LUMPERROR)
|
|
|
|
W_ReadLumpHeader(lump, fadecolormap, len, 0U);
|
|
|
|
// to white
|
|
|
|
if (wlump != LUMPERROR)
|
|
|
|
W_ReadLumpHeader(wlump, fadecolormap+len, len, 0U);
|
|
|
|
|
|
|
|
// missing "to white" colormap lump
|
|
|
|
if (lump != LUMPERROR && wlump == LUMPERROR)
|
|
|
|
goto makewhite;
|
|
|
|
// missing "to black" colormap lump
|
|
|
|
else if (lump == LUMPERROR && wlump != LUMPERROR)
|
|
|
|
goto makeblack;
|
|
|
|
// both lumps found
|
|
|
|
else if (lump != LUMPERROR && wlump != LUMPERROR)
|
|
|
|
return;
|
|
|
|
}
|
2019-09-10 02:31:48 +00:00
|
|
|
|
|
|
|
#define GETCOLOR \
|
|
|
|
px = colormaps[i%256]; \
|
2019-09-10 19:54:40 +00:00
|
|
|
fade = (i/256) * (256 / FADECOLORMAPROWS); \
|
2020-01-05 01:19:30 +00:00
|
|
|
rgba = V_GetMasterColor(px);
|
2019-09-10 02:31:48 +00:00
|
|
|
|
|
|
|
// to black
|
2019-09-10 19:54:40 +00:00
|
|
|
makeblack:
|
2019-09-10 02:31:48 +00:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
// find pixel and fade amount
|
|
|
|
GETCOLOR;
|
|
|
|
|
|
|
|
// subtractive color blending
|
2019-09-10 19:54:40 +00:00
|
|
|
r = rgba.s.red - FADEREDFACTOR*fade/10;
|
|
|
|
g = rgba.s.green - FADEGREENFACTOR*fade/10;
|
|
|
|
b = rgba.s.blue - FADEBLUEFACTOR*fade/10;
|
2019-09-10 02:31:48 +00:00
|
|
|
|
|
|
|
// clamp values
|
|
|
|
if (r < 0) r = 0;
|
|
|
|
if (g < 0) g = 0;
|
|
|
|
if (b < 0) b = 0;
|
|
|
|
|
|
|
|
// find nearest color in palette
|
|
|
|
fadecolormap[i] = NearestColor(r,g,b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// to white
|
2019-09-10 19:54:40 +00:00
|
|
|
makewhite:
|
2019-09-10 02:31:48 +00:00
|
|
|
for (i = len; i < len*2; i++)
|
|
|
|
{
|
|
|
|
// find pixel and fade amount
|
|
|
|
GETCOLOR;
|
|
|
|
|
|
|
|
// additive color blending
|
2019-09-10 19:54:40 +00:00
|
|
|
r = rgba.s.red + FADEREDFACTOR*fade/10;
|
|
|
|
g = rgba.s.green + FADEGREENFACTOR*fade/10;
|
|
|
|
b = rgba.s.blue + FADEBLUEFACTOR*fade/10;
|
2019-09-10 02:31:48 +00:00
|
|
|
|
|
|
|
// clamp values
|
|
|
|
if (r > 255) r = 255;
|
|
|
|
if (g > 255) g = 255;
|
|
|
|
if (b > 255) b = 255;
|
|
|
|
|
|
|
|
// find nearest color in palette
|
|
|
|
fadecolormap[i] = NearestColor(r,g,b);
|
|
|
|
}
|
|
|
|
#undef GETCOLOR
|
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// R_InitColormaps
|
|
|
|
//
|
|
|
|
static void R_InitColormaps(void)
|
|
|
|
{
|
2019-09-10 02:31:48 +00:00
|
|
|
size_t len;
|
2014-03-15 16:59:03 +00:00
|
|
|
lumpnum_t lump;
|
|
|
|
|
|
|
|
// Load in the light tables
|
|
|
|
lump = W_GetNumForName("COLORMAP");
|
2019-09-10 02:31:48 +00:00
|
|
|
len = W_LumpLength(lump);
|
|
|
|
colormaps = Z_MallocAlign(len, PU_STATIC, NULL, 8);
|
2014-03-15 16:59:03 +00:00
|
|
|
W_ReadLump(lump, colormaps);
|
|
|
|
|
2019-09-10 02:31:48 +00:00
|
|
|
// Make colormap for fades
|
2019-09-10 19:54:40 +00:00
|
|
|
R_CreateFadeColormaps();
|
2019-09-10 02:31:48 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// Init Boom colormaps.
|
|
|
|
R_ClearColormaps();
|
2018-09-11 00:36:34 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2014-03-15 16:59:03 +00:00
|
|
|
R_InitExtraColormaps();
|
2018-09-11 00:36:34 +00:00
|
|
|
#endif
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void R_ReInitColormaps(UINT16 num)
|
|
|
|
{
|
|
|
|
char colormap[9] = "COLORMAP";
|
|
|
|
lumpnum_t lump;
|
2019-06-23 14:02:32 +00:00
|
|
|
const lumpnum_t basecolormaplump = W_GetNumForName(colormap);
|
2014-08-04 03:49:33 +00:00
|
|
|
if (num > 0 && num <= 10000)
|
2014-03-15 16:59:03 +00:00
|
|
|
snprintf(colormap, 8, "CLM%04u", num-1);
|
|
|
|
|
|
|
|
// Load in the light tables, now 64k aligned for smokie...
|
|
|
|
lump = W_GetNumForName(colormap);
|
|
|
|
if (lump == LUMPERROR)
|
2019-06-23 14:02:32 +00:00
|
|
|
lump = basecolormaplump;
|
2019-06-23 11:26:52 +00:00
|
|
|
else
|
|
|
|
{
|
2019-06-23 14:02:32 +00:00
|
|
|
if (W_LumpLength(lump) != W_LumpLength(basecolormaplump))
|
2019-06-23 11:26:52 +00:00
|
|
|
{
|
2019-06-23 14:02:32 +00:00
|
|
|
CONS_Alert(CONS_WARNING, "%s lump size does not match COLORMAP, results may be unexpected.\n", colormap);
|
2019-06-23 11:26:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-23 14:02:32 +00:00
|
|
|
W_ReadLumpHeader(lump, colormaps, W_LumpLength(basecolormaplump), 0U);
|
2019-09-10 02:31:48 +00:00
|
|
|
if (fadecolormap)
|
|
|
|
Z_Free(fadecolormap);
|
2019-09-10 19:54:40 +00:00
|
|
|
R_CreateFadeColormaps();
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// Init Boom colormaps.
|
|
|
|
R_ClearColormaps();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_ClearColormaps
|
|
|
|
//
|
|
|
|
// Clears out extra colormaps between levels.
|
|
|
|
//
|
|
|
|
void R_ClearColormaps(void)
|
|
|
|
{
|
2018-09-11 17:46:34 +00:00
|
|
|
// Purged by PU_LEVEL, just overwrite the pointer
|
|
|
|
extra_colormaps = R_CreateDefaultColormap(true);
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-11 17:46:34 +00:00
|
|
|
//
|
|
|
|
// R_CreateDefaultColormap()
|
2018-09-11 19:50:12 +00:00
|
|
|
// NOTE: The result colormap is not added to the extra_colormaps chain. You must do that yourself!
|
2018-09-11 17:46:34 +00:00
|
|
|
//
|
|
|
|
extracolormap_t *R_CreateDefaultColormap(boolean lighttable)
|
|
|
|
{
|
|
|
|
extracolormap_t *exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL);
|
2018-09-11 01:56:09 +00:00
|
|
|
exc->fadestart = 0;
|
|
|
|
exc->fadeend = 31;
|
2020-02-16 19:19:24 +00:00
|
|
|
exc->flags = 0;
|
2018-09-11 01:56:09 +00:00
|
|
|
exc->rgba = 0;
|
|
|
|
exc->fadergba = 0x19000000;
|
2018-09-11 17:46:34 +00:00
|
|
|
exc->colormap = lighttable ? R_CreateLightTable(exc) : NULL;
|
2018-09-11 01:56:09 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
|
|
|
exc->lump = LUMPERROR;
|
|
|
|
exc->lumpname[0] = 0;
|
|
|
|
#endif
|
|
|
|
exc->next = exc->prev = NULL;
|
2018-09-11 17:46:34 +00:00
|
|
|
return exc;
|
2018-09-10 19:59:31 +00:00
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-11 19:01:05 +00:00
|
|
|
//
|
|
|
|
// R_GetDefaultColormap()
|
|
|
|
//
|
|
|
|
extracolormap_t *R_GetDefaultColormap(void)
|
|
|
|
{
|
|
|
|
#ifdef COLORMAPREVERSELIST
|
|
|
|
extracolormap_t *exc;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!extra_colormaps)
|
|
|
|
return (extra_colormaps = R_CreateDefaultColormap(true));
|
|
|
|
|
|
|
|
#ifdef COLORMAPREVERSELIST
|
|
|
|
for (exc = extra_colormaps; exc->next; exc = exc->next);
|
|
|
|
return exc;
|
|
|
|
#else
|
|
|
|
return extra_colormaps;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2018-09-11 19:20:30 +00:00
|
|
|
// R_CopyColormap()
|
2018-09-11 19:50:12 +00:00
|
|
|
// NOTE: The result colormap is not added to the extra_colormaps chain. You must do that yourself!
|
2018-09-11 19:01:05 +00:00
|
|
|
//
|
2018-09-11 19:20:30 +00:00
|
|
|
extracolormap_t *R_CopyColormap(extracolormap_t *extra_colormap, boolean lighttable)
|
2018-09-11 19:01:05 +00:00
|
|
|
{
|
2018-09-11 19:20:30 +00:00
|
|
|
extracolormap_t *exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL);
|
|
|
|
|
2018-09-11 19:01:05 +00:00
|
|
|
if (!extra_colormap)
|
2018-09-11 19:20:30 +00:00
|
|
|
extra_colormap = R_GetDefaultColormap();
|
|
|
|
|
|
|
|
*exc = *extra_colormap;
|
|
|
|
exc->next = exc->prev = NULL;
|
|
|
|
|
2018-09-11 19:01:05 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2018-09-11 19:20:30 +00:00
|
|
|
strncpy(exc->lumpname, extra_colormap->lumpname, 9);
|
|
|
|
|
|
|
|
if (exc->lump != LUMPERROR && lighttable)
|
|
|
|
{
|
|
|
|
// aligned on 8 bit for asm code
|
|
|
|
exc->colormap = Z_MallocAlign(W_LumpLength(lump), PU_LEVEL, NULL, 16);
|
|
|
|
W_ReadLump(lump, exc->colormap);
|
|
|
|
}
|
|
|
|
else
|
2018-09-11 19:01:05 +00:00
|
|
|
#endif
|
2018-09-11 19:20:30 +00:00
|
|
|
if (lighttable)
|
|
|
|
exc->colormap = R_CreateLightTable(exc);
|
|
|
|
else
|
|
|
|
exc->colormap = NULL;
|
|
|
|
|
|
|
|
return exc;
|
2018-09-11 19:01:05 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 19:59:31 +00:00
|
|
|
//
|
|
|
|
// R_AddColormapToList
|
|
|
|
//
|
|
|
|
// Sets prev/next chain for extra_colormaps var
|
|
|
|
// Copypasta from P_AddFFloorToList
|
|
|
|
//
|
|
|
|
void R_AddColormapToList(extracolormap_t *extra_colormap)
|
|
|
|
{
|
2018-09-11 02:35:03 +00:00
|
|
|
#ifndef COLORMAPREVERSELIST
|
2018-09-10 19:59:31 +00:00
|
|
|
extracolormap_t *exc;
|
2018-09-11 02:35:03 +00:00
|
|
|
#endif
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-10 19:59:31 +00:00
|
|
|
if (!extra_colormaps)
|
|
|
|
{
|
|
|
|
extra_colormaps = extra_colormap;
|
|
|
|
extra_colormap->next = 0;
|
|
|
|
extra_colormap->prev = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-11 02:35:03 +00:00
|
|
|
#ifdef COLORMAPREVERSELIST
|
|
|
|
extra_colormaps->prev = extra_colormap;
|
|
|
|
extra_colormap->next = extra_colormaps;
|
|
|
|
extra_colormaps = extra_colormap;
|
|
|
|
extra_colormap->prev = 0;
|
|
|
|
#else
|
2018-09-10 19:59:31 +00:00
|
|
|
for (exc = extra_colormaps; exc->next; exc = exc->next);
|
|
|
|
|
|
|
|
exc->next = extra_colormap;
|
|
|
|
extra_colormap->prev = exc;
|
|
|
|
extra_colormap->next = 0;
|
2018-09-11 02:35:03 +00:00
|
|
|
#endif
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 19:20:30 +00:00
|
|
|
//
|
2018-09-11 21:06:44 +00:00
|
|
|
// R_CheckDefaultColormapByValues()
|
2018-09-11 19:20:30 +00:00
|
|
|
//
|
2018-09-11 21:06:44 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
|
|
|
boolean R_CheckDefaultColormapByValues(boolean checkrgba, boolean checkfadergba, boolean checkparams,
|
2020-02-16 19:19:24 +00:00
|
|
|
INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags, lumpnum_t lump)
|
2018-09-11 21:06:44 +00:00
|
|
|
#else
|
|
|
|
boolean R_CheckDefaultColormapByValues(boolean checkrgba, boolean checkfadergba, boolean checkparams,
|
2020-02-16 19:19:24 +00:00
|
|
|
INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags)
|
2018-09-11 21:06:44 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(!checkparams ? true :
|
|
|
|
(fadestart == 0
|
|
|
|
&& fadeend == 31
|
2020-02-16 19:19:24 +00:00
|
|
|
&& !flags)
|
2018-09-11 21:06:44 +00:00
|
|
|
)
|
|
|
|
&& (!checkrgba ? true : rgba == 0)
|
|
|
|
&& (!checkfadergba ? true : fadergba == 0x19000000)
|
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
|
|
|
&& lump == LUMPERROR
|
|
|
|
&& extra_colormap->lumpname[0] == 0
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean R_CheckDefaultColormap(extracolormap_t *extra_colormap, boolean checkrgba, boolean checkfadergba, boolean checkparams)
|
2018-09-11 19:20:30 +00:00
|
|
|
{
|
|
|
|
if (!extra_colormap)
|
|
|
|
return true;
|
2018-09-11 21:06:44 +00:00
|
|
|
|
2018-09-11 19:20:30 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2020-02-16 19:19:24 +00:00
|
|
|
return R_CheckDefaultColormapByValues(checkrgba, checkfadergba, checkparams, extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags, extra_colormap->lump);
|
2018-09-11 21:06:44 +00:00
|
|
|
#else
|
2020-02-16 19:19:24 +00:00
|
|
|
return R_CheckDefaultColormapByValues(checkrgba, checkfadergba, checkparams, extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags);
|
2018-09-11 19:20:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-09-12 02:34:29 +00:00
|
|
|
boolean R_CheckEqualColormaps(extracolormap_t *exc_a, extracolormap_t *exc_b, boolean checkrgba, boolean checkfadergba, boolean checkparams)
|
|
|
|
{
|
|
|
|
// Treat NULL as default colormap
|
|
|
|
// We need this because what if one exc is a default colormap, and the other is NULL? They're really both equal.
|
|
|
|
if (!exc_a)
|
|
|
|
exc_a = R_GetDefaultColormap();
|
|
|
|
if (!exc_b)
|
|
|
|
exc_b = R_GetDefaultColormap();
|
|
|
|
|
|
|
|
if (exc_a == exc_b)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return (
|
|
|
|
(!checkparams ? true :
|
|
|
|
(exc_a->fadestart == exc_b->fadestart
|
|
|
|
&& exc_a->fadeend == exc_b->fadeend
|
2020-02-16 19:19:24 +00:00
|
|
|
&& exc_a->flags == exc_b->flags)
|
2018-09-12 02:34:29 +00:00
|
|
|
)
|
|
|
|
&& (!checkrgba ? true : exc_a->rgba == exc_b->rgba)
|
|
|
|
&& (!checkfadergba ? true : exc_a->fadergba == exc_b->fadergba)
|
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
|
|
|
&& exc_a->lump == exc_b->lump
|
|
|
|
&& !strncmp(exc_a->lumpname, exc_b->lumpname, 9)
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-11 19:50:12 +00:00
|
|
|
//
|
|
|
|
// R_GetColormapFromListByValues()
|
|
|
|
// NOTE: Returns NULL if no match is found
|
|
|
|
//
|
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2020-02-16 19:19:24 +00:00
|
|
|
extracolormap_t *R_GetColormapFromListByValues(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags, lumpnum_t lump)
|
2018-09-11 19:50:12 +00:00
|
|
|
#else
|
2020-02-16 19:19:24 +00:00
|
|
|
extracolormap_t *R_GetColormapFromListByValues(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags)
|
2018-09-11 19:50:12 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
extracolormap_t *exc;
|
2018-09-15 05:47:56 +00:00
|
|
|
UINT32 dbg_i = 0;
|
2018-09-11 19:50:12 +00:00
|
|
|
|
|
|
|
for (exc = extra_colormaps; exc; exc = exc->next)
|
|
|
|
{
|
|
|
|
if (rgba == exc->rgba
|
|
|
|
&& fadergba == exc->fadergba
|
|
|
|
&& fadestart == exc->fadestart
|
|
|
|
&& fadeend == exc->fadeend
|
2020-02-16 19:19:24 +00:00
|
|
|
&& flags == exc->flags
|
2018-09-11 19:50:12 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
|
|
|
&& (lump != LUMPERROR && lump == exc->lump)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CONS_Debug(DBG_RENDER, "Found Colormap %d: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n",
|
2018-09-15 05:47:56 +00:00
|
|
|
dbg_i, R_GetRgbaR(rgba), R_GetRgbaG(rgba), R_GetRgbaB(rgba), R_GetRgbaA(rgba),
|
|
|
|
R_GetRgbaR(fadergba), R_GetRgbaG(fadergba), R_GetRgbaB(fadergba), R_GetRgbaA(fadergba));
|
2018-09-11 19:50:12 +00:00
|
|
|
return exc;
|
|
|
|
}
|
|
|
|
dbg_i++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
extracolormap_t *R_GetColormapFromList(extracolormap_t *extra_colormap)
|
|
|
|
{
|
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2020-02-16 19:19:24 +00:00
|
|
|
return R_GetColormapFromListByValues(extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags, extra_colormap->lump);
|
2018-09-11 19:59:13 +00:00
|
|
|
#else
|
2020-02-16 19:19:24 +00:00
|
|
|
return R_GetColormapFromListByValues(extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags);
|
2018-09-11 19:50:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-09-11 00:36:34 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2018-09-10 20:28:39 +00:00
|
|
|
extracolormap_t *R_ColormapForName(char *name)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2018-09-10 19:59:31 +00:00
|
|
|
lumpnum_t lump;
|
|
|
|
extracolormap_t *exc;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
lump = R_CheckNumForNameList(name, colormaplumps, numcolormaplumps);
|
|
|
|
if (lump == LUMPERROR)
|
2018-09-10 20:28:39 +00:00
|
|
|
I_Error("R_ColormapForName: Cannot find colormap lump %.8s\n", name);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-11 19:50:12 +00:00
|
|
|
exc = R_GetColormapFromListByValues(0, 0x19000000, 0, 31, 0, lump);
|
|
|
|
if (exc)
|
|
|
|
return exc;
|
2018-09-10 19:59:31 +00:00
|
|
|
|
|
|
|
exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-10 19:59:31 +00:00
|
|
|
exc->lump = lump;
|
2018-09-11 00:36:34 +00:00
|
|
|
strncpy(exc->lumpname, name, 9);
|
|
|
|
exc->lumpname[8] = 0;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// aligned on 8 bit for asm code
|
2018-09-10 19:59:31 +00:00
|
|
|
exc->colormap = Z_MallocAlign(W_LumpLength(lump), PU_LEVEL, NULL, 16);
|
|
|
|
W_ReadLump(lump, exc->colormap);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// We set all params of the colormap to normal because there
|
|
|
|
// is no real way to tell how GL should handle a colormap lump anyway..
|
2018-09-10 19:59:31 +00:00
|
|
|
exc->fadestart = 0;
|
|
|
|
exc->fadeend = 31;
|
2020-02-16 19:19:24 +00:00
|
|
|
exc->flags = 0;
|
2018-09-11 00:36:34 +00:00
|
|
|
exc->rgba = 0;
|
|
|
|
exc->fadergba = 0x19000000;
|
|
|
|
|
|
|
|
R_AddColormapToList(exc);
|
2018-09-10 19:59:31 +00:00
|
|
|
|
|
|
|
return exc;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2018-09-11 00:36:34 +00:00
|
|
|
#endif
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
//
|
2020-03-15 08:55:57 +00:00
|
|
|
// R_CreateColormapFromLinedef
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This is a more GL friendly way of doing colormaps: Specify colormap
|
|
|
|
// data in a special linedef's texture areas and use that to generate
|
|
|
|
// custom colormaps at runtime. NOTE: For GL mode, we only need to color
|
|
|
|
// data and not the colormap data.
|
|
|
|
//
|
|
|
|
static double deltas[256][3], map[256][3];
|
|
|
|
|
|
|
|
static int RoundUp(double number);
|
|
|
|
|
2018-09-10 19:59:31 +00:00
|
|
|
lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2018-09-11 00:36:34 +00:00
|
|
|
double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb;
|
|
|
|
double maskamt = 0, othermask = 0;
|
|
|
|
|
2018-09-11 21:06:44 +00:00
|
|
|
UINT8 cr = R_GetRgbaR(extra_colormap->rgba),
|
|
|
|
cg = R_GetRgbaG(extra_colormap->rgba),
|
|
|
|
cb = R_GetRgbaB(extra_colormap->rgba),
|
|
|
|
ca = R_GetRgbaA(extra_colormap->rgba),
|
|
|
|
cfr = R_GetRgbaR(extra_colormap->fadergba),
|
|
|
|
cfg = R_GetRgbaG(extra_colormap->fadergba),
|
|
|
|
cfb = R_GetRgbaB(extra_colormap->fadergba);
|
|
|
|
// cfa = R_GetRgbaA(extra_colormap->fadergba); // unused in software
|
2018-09-11 00:36:34 +00:00
|
|
|
|
2018-09-11 01:56:09 +00:00
|
|
|
UINT8 fadestart = extra_colormap->fadestart,
|
|
|
|
fadedist = extra_colormap->fadeend - extra_colormap->fadestart;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-10 20:28:39 +00:00
|
|
|
lighttable_t *lighttable = NULL;
|
|
|
|
size_t i;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-11 00:36:34 +00:00
|
|
|
/////////////////////
|
|
|
|
// Calc the RGBA mask
|
|
|
|
/////////////////////
|
|
|
|
cmaskr = cr;
|
|
|
|
cmaskg = cg;
|
|
|
|
cmaskb = cb;
|
|
|
|
|
|
|
|
maskamt = (double)(ca/24.0l);
|
|
|
|
othermask = 1 - maskamt;
|
|
|
|
maskamt /= 0xff;
|
|
|
|
|
|
|
|
cmaskr *= maskamt;
|
|
|
|
cmaskg *= maskamt;
|
|
|
|
cmaskb *= maskamt;
|
|
|
|
|
|
|
|
/////////////////////
|
|
|
|
// Calc the RGBA fade mask
|
|
|
|
/////////////////////
|
|
|
|
cdestr = cfr;
|
|
|
|
cdestg = cfg;
|
|
|
|
cdestb = cfb;
|
|
|
|
|
|
|
|
// fade alpha unused in software
|
|
|
|
// maskamt = (double)(cfa/24.0l);
|
|
|
|
// othermask = 1 - maskamt;
|
|
|
|
// maskamt /= 0xff;
|
|
|
|
|
|
|
|
// cdestr *= maskamt;
|
|
|
|
// cdestg *= maskamt;
|
|
|
|
// cdestb *= maskamt;
|
|
|
|
|
|
|
|
/////////////////////
|
2018-09-09 21:48:09 +00:00
|
|
|
// This code creates the colormap array used by software renderer
|
2018-09-11 00:36:34 +00:00
|
|
|
/////////////////////
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2018-09-09 21:48:09 +00:00
|
|
|
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
|
2014-03-15 16:59:03 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
2017-04-29 15:40:07 +00:00
|
|
|
r = pMasterPalette[i].s.red;
|
|
|
|
g = pMasterPalette[i].s.green;
|
|
|
|
b = pMasterPalette[i].s.blue;
|
2014-03-15 16:59:03 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-09-09 21:48:09 +00:00
|
|
|
// Now allocate memory for the actual colormap array itself!
|
2018-09-10 19:59:31 +00:00
|
|
|
// aligned on 8 bit for asm code
|
2014-03-15 16:59:03 +00:00
|
|
|
colormap_p = Z_MallocAlign((256 * 34) + 10, PU_LEVEL, NULL, 8);
|
2018-09-10 19:59:31 +00:00
|
|
|
lighttable = (UINT8 *)colormap_p;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-09 21:48:09 +00:00
|
|
|
// Calculate the palette index for each palette index, for each light level
|
|
|
|
// (as well as the two unused colormap lines we inherited from Doom)
|
2014-03-15 16:59:03 +00:00
|
|
|
for (p = 0; p < 34; p++)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
*colormap_p = NearestColor((UINT8)RoundUp(map[i][0]),
|
|
|
|
(UINT8)RoundUp(map[i][1]),
|
|
|
|
(UINT8)RoundUp(map[i][2]));
|
|
|
|
colormap_p++;
|
|
|
|
|
|
|
|
if ((UINT32)p < fadestart)
|
|
|
|
continue;
|
2018-09-09 21:48:09 +00:00
|
|
|
#define ABS2(x) ((x) < 0 ? -(x) : (x))
|
2014-03-15 16:59:03 +00:00
|
|
|
if (ABS2(map[i][0] - cdestr) > ABS2(deltas[i][0]))
|
|
|
|
map[i][0] -= deltas[i][0];
|
|
|
|
else
|
|
|
|
map[i][0] = cdestr;
|
|
|
|
|
|
|
|
if (ABS2(map[i][1] - cdestg) > ABS2(deltas[i][1]))
|
|
|
|
map[i][1] -= deltas[i][1];
|
|
|
|
else
|
|
|
|
map[i][1] = cdestg;
|
|
|
|
|
|
|
|
if (ABS2(map[i][2] - cdestb) > ABS2(deltas[i][1]))
|
|
|
|
map[i][2] -= deltas[i][2];
|
|
|
|
else
|
|
|
|
map[i][2] = cdestb;
|
2018-09-09 21:48:09 +00:00
|
|
|
#undef ABS2
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-10 19:59:31 +00:00
|
|
|
return lighttable;
|
|
|
|
}
|
|
|
|
|
2020-03-15 08:55:57 +00:00
|
|
|
extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3)
|
2018-09-10 19:59:31 +00:00
|
|
|
{
|
2018-09-11 19:01:05 +00:00
|
|
|
// default values
|
|
|
|
UINT8 cr = 0, cg = 0, cb = 0, ca = 0, cfr = 0, cfg = 0, cfb = 0, cfa = 25;
|
2018-09-11 01:56:09 +00:00
|
|
|
UINT32 fadestart = 0, fadeend = 31;
|
2020-02-16 19:19:24 +00:00
|
|
|
UINT8 flags = 0;
|
2018-09-11 19:01:05 +00:00
|
|
|
INT32 rgba = 0, fadergba = 0x19000000;
|
2018-09-10 19:59:31 +00:00
|
|
|
|
|
|
|
#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)
|
2018-09-10 20:28:39 +00:00
|
|
|
#define ALPHA2INT(x) (x >= 'a' && x <= 'z' ? x - 'a' : x >= 'A' && x <= 'Z' ? x - 'A' : x >= '0' && x <= '9' ? 25 : 0)
|
2018-09-11 19:01:05 +00:00
|
|
|
|
|
|
|
// Get base colormap value
|
|
|
|
// First alpha-only, then full value
|
|
|
|
if (p1[0] >= 'a' && p1[0] <= 'z' && !p1[1])
|
|
|
|
ca = (p1[0] - 'a');
|
|
|
|
else if (p1[0] == '#' && p1[1] >= 'a' && p1[1] <= 'z' && !p1[2])
|
|
|
|
ca = (p1[1] - 'a');
|
|
|
|
else if (p1[0] >= 'A' && p1[0] <= 'Z' && !p1[1])
|
|
|
|
ca = (p1[0] - 'A');
|
|
|
|
else if (p1[0] == '#' && p1[1] >= 'A' && p1[1] <= 'Z' && !p1[2])
|
|
|
|
ca = (p1[1] - 'A');
|
|
|
|
else if (p1[0] == '#')
|
2018-09-10 19:59:31 +00:00
|
|
|
{
|
2018-09-11 19:01:05 +00:00
|
|
|
// For each subsequent value, the value before it must exist
|
|
|
|
// If we don't get every value, then set alpha to max
|
|
|
|
if (p1[1] && p1[2])
|
|
|
|
{
|
|
|
|
cr = ((HEX2INT(p1[1]) * 16) + HEX2INT(p1[2]));
|
|
|
|
if (p1[3] && p1[4])
|
|
|
|
{
|
|
|
|
cg = ((HEX2INT(p1[3]) * 16) + HEX2INT(p1[4]));
|
|
|
|
if (p1[5] && p1[6])
|
|
|
|
{
|
|
|
|
cb = ((HEX2INT(p1[5]) * 16) + HEX2INT(p1[6]));
|
|
|
|
|
|
|
|
if (p1[7] >= 'a' && p1[7] <= 'z')
|
|
|
|
ca = (p1[7] - 'a');
|
|
|
|
else if (p1[7] >= 'A' && p1[7] <= 'Z')
|
|
|
|
ca = (p1[7] - 'A');
|
|
|
|
else
|
|
|
|
ca = 25;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ca = 25;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ca = 25;
|
|
|
|
}
|
2018-09-10 19:59:31 +00:00
|
|
|
else
|
2018-09-11 17:10:14 +00:00
|
|
|
ca = 25;
|
2018-09-10 19:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NUMFROMCHAR(c) (c >= '0' && c <= '9' ? c - '0' : 0)
|
2018-09-11 19:01:05 +00:00
|
|
|
|
2020-02-16 19:19:24 +00:00
|
|
|
// Get parameters like fadestart, fadeend, and flags
|
2018-09-10 19:59:31 +00:00
|
|
|
if (p2[0] == '#')
|
|
|
|
{
|
2018-09-11 19:01:05 +00:00
|
|
|
if (p2[1])
|
|
|
|
{
|
2020-02-16 19:19:24 +00:00
|
|
|
flags = NUMFROMCHAR(p2[1]);
|
2018-09-11 19:01:05 +00:00
|
|
|
if (p2[2] && p2[3])
|
|
|
|
{
|
|
|
|
fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10);
|
|
|
|
if (p2[4] && p2[5])
|
|
|
|
fadeend = NUMFROMCHAR(p2[5]) + (NUMFROMCHAR(p2[4]) * 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-10 19:59:31 +00:00
|
|
|
if (fadestart > 30)
|
|
|
|
fadestart = 0;
|
|
|
|
if (fadeend > 31 || fadeend < 1)
|
|
|
|
fadeend = 31;
|
|
|
|
}
|
2018-09-11 19:01:05 +00:00
|
|
|
|
2018-09-10 19:59:31 +00:00
|
|
|
#undef NUMFROMCHAR
|
|
|
|
|
2018-09-11 19:01:05 +00:00
|
|
|
// Get fade (dark) colormap value
|
|
|
|
// First alpha-only, then full value
|
|
|
|
if (p3[0] >= 'a' && p3[0] <= 'z' && !p3[1])
|
|
|
|
cfa = (p3[0] - 'a');
|
|
|
|
else if (p3[0] == '#' && p3[1] >= 'a' && p3[1] <= 'z' && !p3[2])
|
|
|
|
cfa = (p3[1] - 'a');
|
|
|
|
else if (p3[0] >= 'A' && p3[0] <= 'Z' && !p3[1])
|
|
|
|
cfa = (p3[0] - 'A');
|
|
|
|
else if (p3[0] == '#' && p3[1] >= 'A' && p3[1] <= 'Z' && !p3[2])
|
|
|
|
cfa = (p3[1] - 'A');
|
|
|
|
else if (p3[0] == '#')
|
2018-09-10 19:59:31 +00:00
|
|
|
{
|
2018-09-11 19:01:05 +00:00
|
|
|
// For each subsequent value, the value before it must exist
|
|
|
|
// If we don't get every value, then set alpha to max
|
|
|
|
if (p3[1] && p3[2])
|
|
|
|
{
|
|
|
|
cfr = ((HEX2INT(p3[1]) * 16) + HEX2INT(p3[2]));
|
|
|
|
if (p3[3] && p3[4])
|
|
|
|
{
|
|
|
|
cfg = ((HEX2INT(p3[3]) * 16) + HEX2INT(p3[4]));
|
|
|
|
if (p3[5] && p3[6])
|
|
|
|
{
|
|
|
|
cfb = ((HEX2INT(p3[5]) * 16) + HEX2INT(p3[6]));
|
|
|
|
|
|
|
|
if (p3[7] >= 'a' && p3[7] <= 'z')
|
|
|
|
cfa = (p3[7] - 'a');
|
|
|
|
else if (p3[7] >= 'A' && p3[7] <= 'Z')
|
|
|
|
cfa = (p3[7] - 'A');
|
|
|
|
else
|
|
|
|
cfa = 25;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cfa = 25;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cfa = 25;
|
|
|
|
}
|
2018-09-11 00:36:34 +00:00
|
|
|
else
|
2018-09-11 17:10:14 +00:00
|
|
|
cfa = 25;
|
2018-09-10 19:59:31 +00:00
|
|
|
}
|
2018-09-10 20:28:39 +00:00
|
|
|
#undef ALPHA2INT
|
2018-09-10 19:59:31 +00:00
|
|
|
#undef HEX2INT
|
|
|
|
|
2018-09-11 19:01:05 +00:00
|
|
|
// Pack rgba values into combined var
|
|
|
|
// OpenGL also uses this instead of lighttables for rendering
|
2018-09-11 21:30:43 +00:00
|
|
|
rgba = R_PutRgbaRGBA(cr, cg, cb, ca);
|
|
|
|
fadergba = R_PutRgbaRGBA(cfr, cfg, cfb, cfa);
|
2018-09-11 19:01:05 +00:00
|
|
|
|
2020-03-15 08:55:57 +00:00
|
|
|
return R_CreateColormap(rgba, fadergba, fadestart, fadeend, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
extracolormap_t *R_CreateColormap(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags)
|
|
|
|
{
|
|
|
|
extracolormap_t *extra_colormap;
|
|
|
|
|
2018-09-11 21:06:44 +00:00
|
|
|
// Did we just make a default colormap?
|
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2020-02-16 19:19:24 +00:00
|
|
|
if (R_CheckDefaultColormapByValues(true, true, true, rgba, fadergba, fadestart, fadeend, flags, LUMPERROR))
|
2018-09-11 21:06:44 +00:00
|
|
|
return NULL;
|
|
|
|
#else
|
2020-02-16 19:19:24 +00:00
|
|
|
if (R_CheckDefaultColormapByValues(true, true, true, rgba, fadergba, fadestart, fadeend, flags))
|
2018-09-11 21:06:44 +00:00
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
|
2018-09-11 19:01:05 +00:00
|
|
|
// Look for existing colormaps
|
2018-09-11 00:36:34 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2020-03-15 08:55:57 +00:00
|
|
|
extra_colormap = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, flags, LUMPERROR);
|
2018-09-11 19:50:12 +00:00
|
|
|
#else
|
2020-03-15 08:55:57 +00:00
|
|
|
extra_colormap = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, flags);
|
2018-09-11 00:36:34 +00:00
|
|
|
#endif
|
2020-03-15 08:55:57 +00:00
|
|
|
if (extra_colormap)
|
|
|
|
return extra_colormap;
|
2018-09-10 19:59:31 +00:00
|
|
|
|
2020-03-15 08:55:57 +00:00
|
|
|
CONS_Debug(DBG_RENDER, "Creating Colormap: rgba(%x) fadergba(%x)\n", rgba, fadergba);
|
2018-09-11 00:52:37 +00:00
|
|
|
|
2020-03-15 08:55:57 +00:00
|
|
|
extra_colormap = Z_Calloc(sizeof(*extra_colormap), PU_LEVEL, NULL);
|
2018-09-10 19:59:31 +00:00
|
|
|
|
|
|
|
extra_colormap->fadestart = (UINT16)fadestart;
|
|
|
|
extra_colormap->fadeend = (UINT16)fadeend;
|
2020-02-16 19:19:24 +00:00
|
|
|
extra_colormap->flags = flags;
|
2018-09-10 19:59:31 +00:00
|
|
|
|
|
|
|
extra_colormap->rgba = rgba;
|
|
|
|
extra_colormap->fadergba = fadergba;
|
|
|
|
|
2018-09-11 00:36:34 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
2018-09-10 19:59:31 +00:00
|
|
|
extra_colormap->lump = LUMPERROR;
|
2018-09-11 00:36:34 +00:00
|
|
|
extra_colormap->lumpname[0] = 0;
|
|
|
|
#endif
|
2018-09-10 19:59:31 +00:00
|
|
|
|
2018-09-11 19:01:05 +00:00
|
|
|
// Having lighttables for alpha-only entries is kind of pointless,
|
|
|
|
// but if there happens to be a matching rgba entry that is NOT alpha-only (but has same rgb values),
|
|
|
|
// then it needs this lighttable because we share matching entries.
|
2018-09-10 19:59:31 +00:00
|
|
|
extra_colormap->colormap = R_CreateLightTable(extra_colormap);
|
|
|
|
|
|
|
|
R_AddColormapToList(extra_colormap);
|
|
|
|
|
|
|
|
return extra_colormap;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 01:02:58 +00:00
|
|
|
//
|
|
|
|
// R_AddColormaps()
|
2018-09-12 11:24:22 +00:00
|
|
|
// NOTE: The result colormap is not added to the extra_colormaps chain. You must do that yourself!
|
2018-09-12 01:02:58 +00:00
|
|
|
//
|
|
|
|
extracolormap_t *R_AddColormaps(extracolormap_t *exc_augend, extracolormap_t *exc_addend,
|
|
|
|
boolean subR, boolean subG, boolean subB, boolean subA,
|
|
|
|
boolean subFadeR, boolean subFadeG, boolean subFadeB, boolean subFadeA,
|
2020-02-16 19:19:24 +00:00
|
|
|
boolean subFadeStart, boolean subFadeEnd, boolean ignoreFlags,
|
2018-09-12 01:02:58 +00:00
|
|
|
boolean lighttable)
|
|
|
|
{
|
2018-09-15 04:48:34 +00:00
|
|
|
INT16 red, green, blue, alpha;
|
|
|
|
|
2018-09-12 01:02:58 +00:00
|
|
|
// exc_augend is added (or subtracted) onto by exc_addend
|
|
|
|
// In Rennaisance times, the first number was considered the augend, the second number the addend
|
|
|
|
// But since the commutative property was discovered, today they're both called addends!
|
|
|
|
// So let's be Olde English for a hot second.
|
|
|
|
|
|
|
|
exc_augend = R_CopyColormap(exc_augend, false);
|
|
|
|
if(!exc_addend)
|
|
|
|
exc_addend = R_GetDefaultColormap();
|
|
|
|
|
2018-09-12 11:06:45 +00:00
|
|
|
///////////////////
|
2018-09-12 01:02:58 +00:00
|
|
|
// base rgba
|
2018-09-12 11:06:45 +00:00
|
|
|
///////////////////
|
|
|
|
|
2018-09-12 01:02:58 +00:00
|
|
|
red = max(min(
|
|
|
|
R_GetRgbaR(exc_augend->rgba)
|
|
|
|
+ (subR ? -1 : 1) // subtract R
|
|
|
|
* R_GetRgbaR(exc_addend->rgba)
|
|
|
|
, 255), 0);
|
|
|
|
|
|
|
|
green = max(min(
|
|
|
|
R_GetRgbaG(exc_augend->rgba)
|
|
|
|
+ (subG ? -1 : 1) // subtract G
|
|
|
|
* R_GetRgbaG(exc_addend->rgba)
|
|
|
|
, 255), 0);
|
|
|
|
|
|
|
|
blue = max(min(
|
|
|
|
R_GetRgbaB(exc_augend->rgba)
|
|
|
|
+ (subB ? -1 : 1) // subtract B
|
|
|
|
* R_GetRgbaB(exc_addend->rgba)
|
|
|
|
, 255), 0);
|
|
|
|
|
2020-03-20 10:19:30 +00:00
|
|
|
alpha = R_GetRgbaA(exc_addend->rgba);
|
2018-09-12 01:02:58 +00:00
|
|
|
alpha = max(min(R_GetRgbaA(exc_augend->rgba) + (subA ? -1 : 1) * alpha, 25), 0);
|
|
|
|
|
|
|
|
exc_augend->rgba = R_PutRgbaRGBA(red, green, blue, alpha);
|
|
|
|
|
2018-09-12 11:06:45 +00:00
|
|
|
///////////////////
|
|
|
|
// fade/dark rgba
|
|
|
|
///////////////////
|
|
|
|
|
2018-09-12 01:02:58 +00:00
|
|
|
red = max(min(
|
|
|
|
R_GetRgbaR(exc_augend->fadergba)
|
|
|
|
+ (subFadeR ? -1 : 1) // subtract R
|
|
|
|
* R_GetRgbaR(exc_addend->fadergba)
|
|
|
|
, 255), 0);
|
|
|
|
|
|
|
|
green = max(min(
|
|
|
|
R_GetRgbaG(exc_augend->fadergba)
|
|
|
|
+ (subFadeG ? -1 : 1) // subtract G
|
|
|
|
* R_GetRgbaG(exc_addend->fadergba)
|
|
|
|
, 255), 0);
|
|
|
|
|
|
|
|
blue = max(min(
|
|
|
|
R_GetRgbaB(exc_augend->fadergba)
|
|
|
|
+ (subFadeB ? -1 : 1) // subtract B
|
|
|
|
* R_GetRgbaB(exc_addend->fadergba)
|
|
|
|
, 255), 0);
|
|
|
|
|
2020-03-20 10:19:30 +00:00
|
|
|
alpha = R_GetRgbaA(exc_addend->fadergba);
|
|
|
|
if (alpha == 25 && !R_GetRgbaRGB(exc_addend->fadergba))
|
2018-09-12 01:02:58 +00:00
|
|
|
alpha = 0; // HACK: fadergba A defaults at 25, so don't add anything in this case
|
|
|
|
alpha = max(min(R_GetRgbaA(exc_augend->fadergba) + (subFadeA ? -1 : 1) * alpha, 25), 0);
|
|
|
|
|
|
|
|
exc_augend->fadergba = R_PutRgbaRGBA(red, green, blue, alpha);
|
|
|
|
|
2018-09-12 11:06:45 +00:00
|
|
|
///////////////////
|
|
|
|
// parameters
|
|
|
|
///////////////////
|
|
|
|
|
|
|
|
exc_augend->fadestart = max(min(
|
|
|
|
exc_augend->fadestart
|
|
|
|
+ (subFadeStart ? -1 : 1) // subtract fadestart
|
|
|
|
* exc_addend->fadestart
|
|
|
|
, 31), 0);
|
|
|
|
|
|
|
|
exc_augend->fadeend = max(min(
|
|
|
|
exc_augend->fadeend
|
|
|
|
+ (subFadeEnd ? -1 : 1) // subtract fadeend
|
2018-09-12 11:14:23 +00:00
|
|
|
* (exc_addend->fadeend == 31 && !exc_addend->fadestart ? 0 : exc_addend->fadeend)
|
|
|
|
// HACK: fadeend defaults to 31, so don't add anything in this case
|
2018-09-12 11:06:45 +00:00
|
|
|
, 31), 0);
|
|
|
|
|
2020-02-16 19:19:24 +00:00
|
|
|
if (!ignoreFlags) // overwrite flags with new value
|
|
|
|
exc_augend->flags = exc_addend->flags;
|
2018-09-12 11:06:45 +00:00
|
|
|
|
|
|
|
///////////////////
|
|
|
|
// put it together
|
|
|
|
///////////////////
|
|
|
|
|
2018-09-12 11:24:22 +00:00
|
|
|
exc_augend->colormap = lighttable ? R_CreateLightTable(exc_augend) : NULL;
|
|
|
|
exc_augend->next = exc_augend->prev = NULL;
|
|
|
|
return exc_augend;
|
2018-09-12 01:02:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// Thanks to quake2 source!
|
|
|
|
// utils3/qdata/images.c
|
2020-01-27 16:55:13 +00:00
|
|
|
UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
int dr, dg, db;
|
|
|
|
int distortion, bestdistortion = 256 * 256 * 4, bestcolor = 0, i;
|
|
|
|
|
2020-01-27 16:55:13 +00:00
|
|
|
// Use master palette if none specified
|
|
|
|
if (palette == NULL)
|
|
|
|
palette = pMasterPalette;
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
2020-01-27 16:55:13 +00:00
|
|
|
dr = r - palette[i].s.red;
|
|
|
|
dg = g - palette[i].s.green;
|
|
|
|
db = b - palette[i].s.blue;
|
2014-03-15 16:59:03 +00:00
|
|
|
distortion = dr*dr + dg*dg + db*db;
|
|
|
|
if (distortion < bestdistortion)
|
|
|
|
{
|
|
|
|
if (!distortion)
|
|
|
|
return (UINT8)i;
|
|
|
|
|
|
|
|
bestdistortion = distortion;
|
|
|
|
bestcolor = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UINT8)bestcolor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rounds off floating numbers and checks for 0 - 255 bounds
|
|
|
|
static int RoundUp(double number)
|
|
|
|
{
|
|
|
|
if (number > 255.0l)
|
|
|
|
return 255;
|
|
|
|
if (number < 0.0l)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((int)number <= (int)(number - 0.5f))
|
|
|
|
return (int)number + 1;
|
|
|
|
|
|
|
|
return (int)number;
|
|
|
|
}
|
|
|
|
|
2018-09-11 00:36:34 +00:00
|
|
|
#ifdef EXTRACOLORMAPLUMPS
|
|
|
|
const char *R_NameForColormap(extracolormap_t *extra_colormap)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2018-09-10 20:28:39 +00:00
|
|
|
if (!extra_colormap)
|
2014-03-15 16:59:03 +00:00
|
|
|
return "NONE";
|
|
|
|
|
2018-09-10 20:28:39 +00:00
|
|
|
if (extra_colormap->lump == LUMPERROR)
|
2014-03-15 16:59:03 +00:00
|
|
|
return "INLEVEL";
|
|
|
|
|
2018-09-11 00:36:34 +00:00
|
|
|
return extra_colormap->lumpname;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2018-09-11 00:36:34 +00:00
|
|
|
#endif
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// build a table for quick conversion from 8bpp to 15bpp
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// added "static inline" keywords, linking with the debug version
|
|
|
|
// of allegro, it have a makecol15 function of it's own, now
|
|
|
|
// with "static inline" keywords,it sloves this problem ;)
|
|
|
|
//
|
|
|
|
FUNCMATH static inline int makecol15(int r, int g, int b)
|
|
|
|
{
|
|
|
|
return (((r >> 3) << 10) | ((g >> 3) << 5) | ((b >> 3)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void R_Init8to16(void)
|
|
|
|
{
|
|
|
|
UINT8 *palette;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
palette = W_CacheLumpName("PLAYPAL",PU_CACHE);
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
// PLAYPAL uses 8 bit values
|
|
|
|
color8to16[i] = (INT16)makecol15(palette[0], palette[1], palette[2]);
|
|
|
|
palette += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// test a big colormap
|
|
|
|
hicolormaps = Z_Malloc(16384*sizeof(*hicolormaps), PU_STATIC, NULL);
|
|
|
|
for (i = 0; i < 16384; i++)
|
|
|
|
hicolormaps[i] = (INT16)(i<<1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_InitData
|
|
|
|
//
|
|
|
|
// Locates all the lumps that will be used by all views
|
|
|
|
// Must be called after W_Init.
|
|
|
|
//
|
|
|
|
void R_InitData(void)
|
|
|
|
{
|
|
|
|
if (highcolor)
|
|
|
|
{
|
|
|
|
CONS_Printf("InitHighColor...\n");
|
|
|
|
R_Init8to16();
|
|
|
|
}
|
|
|
|
|
|
|
|
CONS_Printf("R_LoadTextures()...\n");
|
|
|
|
R_LoadTextures();
|
|
|
|
|
2016-10-19 07:22:11 +00:00
|
|
|
CONS_Printf("P_InitPicAnims()...\n");
|
|
|
|
P_InitPicAnims();
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
CONS_Printf("R_InitSprites()...\n");
|
|
|
|
R_InitSpriteLumps();
|
|
|
|
R_InitSprites();
|
|
|
|
|
|
|
|
CONS_Printf("R_InitColormaps()...\n");
|
|
|
|
R_InitColormaps();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_PrecacheLevel
|
|
|
|
//
|
|
|
|
// Preloads all relevant graphics for the level.
|
|
|
|
//
|
|
|
|
void R_PrecacheLevel(void)
|
|
|
|
{
|
|
|
|
char *texturepresent, *spritepresent;
|
|
|
|
size_t i, j, k;
|
|
|
|
lumpnum_t lump;
|
|
|
|
|
|
|
|
thinker_t *th;
|
|
|
|
spriteframe_t *sf;
|
|
|
|
|
|
|
|
if (demoplayback)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// do not flush the memory, Z_Malloc twice with same user will cause error in Z_CheckHeap()
|
|
|
|
if (rendermode != render_soft)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Precache flats.
|
|
|
|
flatmemory = P_PrecacheLevelFlats();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Precache textures.
|
|
|
|
//
|
|
|
|
// no need to precache all software textures in 3D mode
|
|
|
|
// (note they are still used with the reference software view)
|
2016-05-10 19:19:42 +00:00
|
|
|
texturepresent = calloc(numtextures, sizeof (*texturepresent));
|
2014-03-15 16:59:03 +00:00
|
|
|
if (texturepresent == NULL) I_Error("%s: Out of memory looking up textures", "R_PrecacheLevel");
|
|
|
|
|
|
|
|
for (j = 0; j < numsides; j++)
|
|
|
|
{
|
|
|
|
// huh, a potential bug here????
|
2016-05-10 19:19:42 +00:00
|
|
|
if (sides[j].toptexture >= 0 && sides[j].toptexture < numtextures)
|
2014-03-15 16:59:03 +00:00
|
|
|
texturepresent[sides[j].toptexture] = 1;
|
2016-05-10 19:19:42 +00:00
|
|
|
if (sides[j].midtexture >= 0 && sides[j].midtexture < numtextures)
|
2014-03-15 16:59:03 +00:00
|
|
|
texturepresent[sides[j].midtexture] = 1;
|
2016-05-10 19:19:42 +00:00
|
|
|
if (sides[j].bottomtexture >= 0 && sides[j].bottomtexture < numtextures)
|
2014-03-15 16:59:03 +00:00
|
|
|
texturepresent[sides[j].bottomtexture] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sky texture is always present.
|
|
|
|
// Note that F_SKY1 is the name used to indicate a sky floor/ceiling as a flat,
|
|
|
|
// while the sky texture is stored like a wall texture, with a skynum dependent name.
|
|
|
|
texturepresent[skytexture] = 1;
|
|
|
|
|
|
|
|
texturememory = 0;
|
|
|
|
for (j = 0; j < (unsigned)numtextures; j++)
|
|
|
|
{
|
|
|
|
if (!texturepresent[j])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!texturecache[j])
|
|
|
|
R_GenerateTexture(j);
|
|
|
|
// pre-caching individual patches that compose textures became obsolete,
|
|
|
|
// since we cache entire composite textures
|
|
|
|
}
|
|
|
|
free(texturepresent);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Precache sprites.
|
|
|
|
//
|
|
|
|
spritepresent = calloc(numsprites, sizeof (*spritepresent));
|
|
|
|
if (spritepresent == NULL) I_Error("%s: Out of memory looking up sprites", "R_PrecacheLevel");
|
|
|
|
|
2019-04-20 21:29:20 +00:00
|
|
|
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
|
2019-07-12 23:42:03 +00:00
|
|
|
if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed)
|
|
|
|
spritepresent[((mobj_t *)th)->sprite] = 1;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
spritememory = 0;
|
|
|
|
for (i = 0; i < numsprites; i++)
|
|
|
|
{
|
|
|
|
if (!spritepresent[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < sprites[i].numframes; j++)
|
|
|
|
{
|
|
|
|
sf = &sprites[i].spriteframes[j];
|
2020-01-08 20:49:14 +00:00
|
|
|
#define cacheang(a) {\
|
|
|
|
lump = sf->lumppat[a];\
|
|
|
|
if (devparm)\
|
|
|
|
spritememory += W_LumpLength(lump);\
|
|
|
|
W_CachePatchNum(lump, PU_PATCH);\
|
|
|
|
}
|
|
|
|
// see R_InitSprites for more about lumppat,lumpid
|
|
|
|
switch (sf->rotate)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2020-01-08 20:49:14 +00:00
|
|
|
case SRF_SINGLE:
|
|
|
|
cacheang(0);
|
|
|
|
break;
|
|
|
|
case SRF_2D:
|
|
|
|
cacheang(2);
|
|
|
|
cacheang(6);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
k = (sf->rotate & SRF_3DGE ? 16 : 8);
|
|
|
|
while (k--)
|
|
|
|
cacheang(k);
|
|
|
|
break;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2020-01-08 20:49:14 +00:00
|
|
|
#undef cacheang
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(spritepresent);
|
|
|
|
|
|
|
|
// FIXME: this is no longer correct with OpenGL render mode
|
|
|
|
CONS_Debug(DBG_SETUP, "Precache level done:\n"
|
|
|
|
"flatmemory: %s k\n"
|
|
|
|
"texturememory: %s k\n"
|
|
|
|
"spritememory: %s k\n", sizeu1(flatmemory>>10), sizeu2(texturememory>>10), sizeu3(spritememory>>10));
|
|
|
|
}
|