- palette code cleanup.

This commit is contained in:
Christoph Oelckers 2020-05-27 22:19:02 +02:00
parent d52600663d
commit 193b940eef
22 changed files with 204 additions and 191 deletions

View file

@ -80,13 +80,10 @@ void scrLoadPLUs(void)
auto data = fileSystem.GetFileData(lump); auto data = fileSystem.GetFileData(lump);
if (data.Size() != 64 * 256) if (data.Size() != 64 * 256)
I_FatalError("Incorrect PLU size"); I_FatalError("Incorrect PLU size");
paletteSetLookupTable(i, data.Data()); lookups.setTable(i, data.Data());
} }
palookupfog[1].r = 255; lookups.setFadeColor(1, 255, 255, 255);
palookupfog[1].g = 255;
palookupfog[1].b = 255;
palookupfog[1].f = 1;
} }
glblend_t const bloodglblend = glblend_t const bloodglblend =

View file

@ -28,24 +28,65 @@
#define NORMALPAL (MAXPALOOKUPS - 4) #define NORMALPAL (MAXPALOOKUPS - 4)
#define BRIGHTPAL (MAXPALOOKUPS) #define BRIGHTPAL (MAXPALOOKUPS)
extern FString LookupTables[MAXPALOOKUPS]; struct LookupTable
inline const uint8_t *paletteGetLookupTable(int num)
{ {
return (const uint8_t*)LookupTables[num].GetChars(); FString Shades;
} PalEntry FadeColor = 0;
float Visibility = 0;
bool hasBrightmap = false;
bool noFloorPal = false;
};
inline void paletteCopyLookupTable(int dest, int src) struct LookupTableInfo
{ {
LookupTables[dest] = LookupTables[src]; LookupTable tables[MAXPALOOKUPS];
}
inline bool paletteCheckLookupTable(int num) const uint8_t* getTable(int num)
{ {
return LookupTables[num].Len() > 0; if (tables[num].Shades.Len() == 0) num = 0;
} return (const uint8_t*)tables[num].Shades.GetChars();
inline void paletteClearLookupTable(int num) }
{
LookupTables[num] = ""; bool checkTable(int num)
} {
return tables[num].Shades.IsNotEmpty();
}
void copyTable(int dest, int src)
{
tables[dest].Shades = tables[src].Shades;
}
void clearTable(int dest)
{
tables[dest].Shades = "";
}
void makeTable(int palnum, const uint8_t* remapbuf, int r, int g, int b, bool noFloorPal);
int setTable(int palnum, const uint8_t* remap);
void postLoadTables();
int loadTable(FileReader& fp);
void postLoadLookups();
void setupDefaultFog();
void setFadeColor(int num, int r, int g, int b)
{
tables[num].FadeColor = PalEntry(1, r, g, b);
}
PalEntry getFade(int num)
{
return tables[num].FadeColor;
}
bool noFloorPal(int num) const
{
return tables[num].noFloorPal;
}
};
extern LookupTableInfo lookups;
enum enum
{ {
@ -63,9 +104,7 @@ struct palette_t
extern PalEntry palfadergb; extern PalEntry palfadergb;
void paletteMakeLookupTable(int32_t palnum, const uint8_t *remapbuf, uint8_t r, uint8_t g, uint8_t b, char noFloorPal);
void paletteSetColorTable(int32_t id, uint8_t const* table, bool notransparency, bool twodonly); void paletteSetColorTable(int32_t id, uint8_t const* table, bool notransparency, bool twodonly);
int32_t paletteSetLookupTable(int32_t palnum, const uint8_t *shtab);
#include "tflags.h" #include "tflags.h"
enum ESetPalFlag enum ESetPalFlag
@ -98,20 +137,9 @@ void videoTintBlood(int32_t r, int32_t g, int32_t b);
extern int32_t globalpal; extern int32_t globalpal;
extern int32_t globalblend; extern int32_t globalblend;
extern void paletteLoadFromDisk(void); extern void paletteLoadFromDisk(void);
extern void palettePostLoadTables(void);
extern int32_t paletteLoadLookupTable(FileReader &fp);
extern void paletteSetupDefaultFog(void);
void paletteFreeLookups();
extern void palettePostLoadLookups(void);
extern void paletteFixTranslucencyMask(void);
extern int8_t g_noFloorPal[MAXPALOOKUPS];
extern char britable[16][256];
#ifdef USE_OPENGL #ifdef USE_OPENGL
extern palette_t palookupfog[MAXPALOOKUPS];
typedef struct glblenddef_ typedef struct glblenddef_
{ {

View file

@ -469,7 +469,7 @@ static int32_t defsparser(scriptfile *script)
g = clamp(g, 0, 63); g = clamp(g, 0, 63);
b = clamp(b, 0, 63); b = clamp(b, 0, 63);
paletteMakeLookupTable(p, NULL, r<<2, g<<2, b<<2, 1); lookups.makeTable(p, NULL, r<<2, g<<2, b<<2, 1);
} }
break; break;
case T_NOFLOORPALRANGE: case T_NOFLOORPALRANGE:
@ -482,8 +482,8 @@ static int32_t defsparser(scriptfile *script)
b = max(b, 1); b = max(b, 1);
e = min(e, MAXPALOOKUPS-1); e = min(e, MAXPALOOKUPS-1);
for (i=b; i<=e; i++) for (i = b; i <= e; i++)
g_noFloorPal[i] = 1; lookups.tables[i].noFloorPal = true;
} }
break; break;
case T_LOADGRP: case T_LOADGRP:
@ -2059,8 +2059,8 @@ static int32_t defsparser(scriptfile *script)
// NOTE: all palookups are initialized, i.e. non-NULL! // NOTE: all palookups are initialized, i.e. non-NULL!
// NOTE2: aliasing (pal==remappal) is OK // NOTE2: aliasing (pal==remappal) is OK
paletteMakeLookupTable(pal, paletteGetLookupTable(remappal), red<<2, green<<2, blue<<2, lookups.makeTable(pal, lookups.getTable(remappal), red<<2, green<<2, blue<<2,
remappal==0 ? 1 : (nofloorpal == -1 ? g_noFloorPal[remappal] : nofloorpal)); remappal==0 ? 1 : (nofloorpal == -1 ? lookups.tables[remappal].noFloorPal : nofloorpal));
} }
break; break;
case T_TEXTURE: case T_TEXTURE:
@ -2847,7 +2847,7 @@ static int32_t defsparser(scriptfile *script)
{ {
didLoadShade = 1; didLoadShade = 1;
numshades = 32; numshades = 32;
paletteSetLookupTable(id, palookupbuf.Data()); lookups.setTable(id, palookupbuf.Data());
} }
else else
{ {
@ -2858,7 +2858,7 @@ static int32_t defsparser(scriptfile *script)
break; break;
} }
paletteMakeLookupTable(id, palookupbuf.Data(), 0,0,0, g_noFloorPal[id]); lookups.makeTable(id, palookupbuf.Data(), 0,0,0, lookups.tables[id].noFloorPal);
} }
break; break;
} }
@ -2881,8 +2881,8 @@ static int32_t defsparser(scriptfile *script)
break; break;
} }
if (paletteCheckLookupTable(source) || id > 0) // do not overwrite the base with an empty table. if (lookups.checkTable(source) || id > 0) // do not overwrite the base with an empty table.
paletteCopyLookupTable(id, source); lookups.copyTable(id, source);
didLoadShade = 1; didLoadShade = 1;
break; break;
} }
@ -2928,7 +2928,7 @@ static int32_t defsparser(scriptfile *script)
break; break;
} }
paletteMakeLookupTable(id, NULL, red, green, blue, 1); lookups.makeTable(id, NULL, red, green, blue, 1);
break; break;
} }
case T_MAKEPALOOKUP: case T_MAKEPALOOKUP:
@ -2989,23 +2989,23 @@ static int32_t defsparser(scriptfile *script)
break; break;
} }
paletteMakeLookupTable(id, NULL, red, green, blue, g_noFloorPal[id]); lookups.makeTable(id, NULL, red, green, blue, lookups.tables[id].noFloorPal);
break; break;
} }
case T_NOFLOORPAL: case T_NOFLOORPAL:
{ {
g_noFloorPal[id] = 1; lookups.tables[id].noFloorPal = 1;
break; break;
} }
case T_FLOORPAL: case T_FLOORPAL:
{ {
g_noFloorPal[id] = 0; lookups.tables[id].noFloorPal = 0;
break; break;
} }
case T_UNDEF: case T_UNDEF:
{ {
paletteClearLookupTable(id); lookups.clearTable(id);
didLoadShade = 0; didLoadShade = 0;
if (id == 0) if (id == 0)
paletteloaded &= ~PALETTE_SHADE; paletteloaded &= ~PALETTE_SHADE;
@ -3360,7 +3360,7 @@ static int32_t defsparser(scriptfile *script)
} }
for (bssize_t i = id0; i <= id1; i++) for (bssize_t i = id0; i <= id1; i++)
paletteClearLookupTable(i); lookups.clearTable(i);
if (id0 == 0) if (id0 == 0)
paletteloaded &= ~PALETTE_SHADE; paletteloaded &= ~PALETTE_SHADE;

View file

@ -128,8 +128,6 @@ static int32_t qradarang[10240];
uint16_t ATTRIBUTE((used)) sqrtable[4096], ATTRIBUTE((used)) shlookup[4096+256], ATTRIBUTE((used)) sqrtable_old[2048]; uint16_t ATTRIBUTE((used)) sqrtable[4096], ATTRIBUTE((used)) shlookup[4096+256], ATTRIBUTE((used)) sqrtable_old[2048];
char britable[16][256]; // JBF 20040207: full 8bit precision
static char kensmessage[128]; static char kensmessage[128];
const char *engineerrstr = "No error"; const char *engineerrstr = "No error";
@ -1570,24 +1568,6 @@ static void dosetaspect(void)
} }
//
// loadtables (internal)
//
static inline void calcbritable(void)
{
int32_t i, j;
float a, b;
for (i=0; i<16; i++)
{
a = 8.f / ((float)i+8.f);
b = 255.f / powf(255.f, a);
for (j=0; j<256; j++) // JBF 20040207: full 8bit precision
britable[i][j] = (uint8_t) (powf((float)j, a) * b);
}
}
static int32_t engineLoadTables(void) static int32_t engineLoadTables(void)
{ {
static char tablesloaded = 0; static char tablesloaded = 0;
@ -1618,8 +1598,6 @@ static int32_t engineLoadTables(void)
for (i=0; i<5120; i++) for (i=0; i<5120; i++)
qradarang[10239-i] = -qradarang[i]; qradarang[10239-i] = -qradarang[i];
calcbritable();
tablesloaded = 1; tablesloaded = 1;
} }
@ -2126,7 +2104,7 @@ int32_t enginePostInit(void)
I_FatalError("No translucency table found."); I_FatalError("No translucency table found.");
V_LoadTranslations(); // loading the translations must be delayed until the palettes have been fully set up. V_LoadTranslations(); // loading the translations must be delayed until the palettes have been fully set up.
palettePostLoadTables(); lookups.postLoadTables();
TileFiles.SetupReverseTileMap(); TileFiles.SetupReverseTileMap();
return 0; return 0;
} }

View file

@ -24,24 +24,12 @@
#include "v_font.h" #include "v_font.h"
#include "../../glbackend/glbackend.h" #include "../../glbackend/glbackend.h"
// FString is a nice and convenient way to have automatically managed shared storage. LookupTableInfo lookups;
FString LookupTables[MAXPALOOKUPS];
uint8_t curbasepal; uint8_t curbasepal;
int32_t globalblend; int32_t globalblend;
PalEntry palfadergb; PalEntry palfadergb;
#if defined(USE_OPENGL)
palette_t palookupfog[MAXPALOOKUPS];
#endif
// For every pal number, whether tsprite pal should not be taken over from
// floor pal.
// NOTE: g_noFloorPal[0] is irrelevant as it's never checked.
int8_t g_noFloorPal[MAXPALOOKUPS];
//========================================================================== //==========================================================================
// //
// Adds a palette to the global list of base palettes // Adds a palette to the global list of base palettes
@ -136,7 +124,7 @@ void paletteLoadFromDisk(void)
int length = numshades * 256; int length = numshades * 256;
auto buffer = fil.Read(length); auto buffer = fil.Read(length);
if (buffer.Size() != length) return; if (buffer.Size() != length) return;
LookupTables[0] = FString((char*)buffer.Data(), length); lookups.setTable(0, buffer.Data());
paletteloaded |= PALETTE_SHADE; paletteloaded |= PALETTE_SHADE;
paletteloaded |= PALETTE_TRANSLUC; paletteloaded |= PALETTE_TRANSLUC;
@ -148,30 +136,53 @@ void paletteLoadFromDisk(void)
// //
//========================================================================== //==========================================================================
void palettePostLoadTables(void) void LookupTableInfo::postLoadTables(void)
{ {
globalpal = 0; globalpal = 0;
GPalette.GenerateGlobalBrightmapFromColormap(paletteGetLookupTable(0), numshades); GPalette.GenerateGlobalBrightmapFromColormap(getTable(0), numshades);
}
//========================================================================== // Try to detect fullbright translations. Unfortunately this cannot be used to detect fade strength because of loss of color precision in the palette map.
// for (int j = 0; j < MAXPALOOKUPS; j++)
// Ensure that all lookups map 255 to itself to preserve transparency.
//
//==========================================================================
void paletteFixTranslucencyMask(void)
{
for (auto &thispalookup : LookupTables)
{ {
if (thispalookup.IsEmpty()) auto lookup = tables[j].Shades;
continue; if (lookup.Len() > 0)
for (int j = 0; j < numshades; j++)
{ {
auto p = thispalookup.LockBuffer(); auto basetable = (uint8_t*)lookup.GetChars();
p[(j << 8) + 255] = 255; auto midtable = basetable + ((numshades / 2) - 1) * 256;
thispalookup.UnlockBuffer(); int lumibase = 0, lumimid = 0;
for (int i = 1; i < 255; i++) // intentionally leave out 0 and 255, because the table here is not translucency adjusted to the palette.
{
lumibase += GPalette.BaseColors[basetable[i]].Amplitude();
lumimid += GPalette.BaseColors[midtable[i]].Amplitude();
}
float divider = float(lumimid) / float(lumibase);
bool isbright = false;
if (divider > 0.9)
{
shadediv[j] = 1 / 10000.f; // this translation is fullbright.
}
else
{
// Fullbright lookups do not need brightmaps.
auto fog = tables[j].FadeColor;
if (GPalette.HasGlobalBrightmap && fog.r == 0 && fog.g == 0 && fog.b == 0)
{
isbright = true;
// A translation is fullbright only if all fullbright colors in the base table are mapped to another fullbright color.
auto brightmap = GPalette.GlobalBrightmap.Remap;
for (int i = 1; i < 255; i++) // This also ignores entries 0 and 255 for the same reason as above.
{
int map = basetable[i];
if (brightmap[i] == GPalette.WhiteIndex && brightmap[map] != GPalette.WhiteIndex)
{
isbright = false;
break;
}
}
}
}
tables[j].hasBrightmap = isbright;
DPrintf(DMSG_NOTIFY, "Lookup %d is %sbright\n", j, isbright ? "" : "not ");
} }
} }
} }
@ -182,7 +193,7 @@ void paletteFixTranslucencyMask(void)
// //
//========================================================================== //==========================================================================
int32_t paletteLoadLookupTable(FileReader &fp) int32_t LookupTableInfo::loadTable(FileReader &fp)
{ {
uint8_t remapbuf[256]; uint8_t remapbuf[256];
int numlookups = fp.ReadUInt8(); int numlookups = fp.ReadUInt8();
@ -201,7 +212,7 @@ int32_t paletteLoadLookupTable(FileReader &fp)
Printf("ERROR: attempt to load lookup at reserved pal %d\n", palnum); Printf("ERROR: attempt to load lookup at reserved pal %d\n", palnum);
} }
else else
paletteMakeLookupTable(palnum, remapbuf, 0, 0, 0, 0); makeTable(palnum, remapbuf, 0, 0, 0, 0);
} }
return 0; return 0;
@ -213,17 +224,16 @@ int32_t paletteLoadLookupTable(FileReader &fp)
// //
//========================================================================== //==========================================================================
void paletteSetupDefaultFog(void) void LookupTableInfo::setupDefaultFog(void)
{ {
for (int j = 1; j <= 255 - 3; j++) for (int j = 1; j <= 255 - 3; j++)
{ {
if (LookupTables[j].IsEmpty() && LookupTables[j + 1].IsEmpty() && LookupTables[j + 2].IsEmpty() && LookupTables[j + 3].IsEmpty()) if (tables[j].Shades.IsEmpty() && tables[j+1].Shades.IsEmpty() && tables[j + 2].Shades.IsEmpty() && tables[j + 3].Shades.IsEmpty())
{ {
paletteMakeLookupTable(j, NULL, 60, 60, 60, 1); makeTable(j, NULL, 60, 60, 60, 1);
paletteMakeLookupTable(j + 1, NULL, 60, 0, 0, 1); makeTable(j + 1, NULL, 60, 0, 0, 1);
paletteMakeLookupTable(j + 2, NULL, 0, 60, 0, 1); makeTable(j + 2, NULL, 0, 60, 0, 1);
paletteMakeLookupTable(j + 3, NULL, 0, 0, 60, 1); makeTable(j + 3, NULL, 0, 0, 60, 1);
break; break;
} }
} }
@ -235,7 +245,7 @@ void paletteSetupDefaultFog(void)
// //
//========================================================================== //==========================================================================
void palettePostLoadLookups(void) void LookupTableInfo::postLoadLookups()
{ {
int numpalettes = GPalette.NumTranslations(Translation_BasePalettes); int numpalettes = GPalette.NumTranslations(Translation_BasePalettes);
if (numpalettes == 0) return; if (numpalettes == 0) return;
@ -255,9 +265,9 @@ void palettePostLoadLookups(void)
{ {
for (int l = 0; l < MAXPALOOKUPS; l++) for (int l = 0; l < MAXPALOOKUPS; l++)
{ {
if (!LookupTables[l].IsEmpty()) if (!tables[l].Shades.IsEmpty())
{ {
const uint8_t* lookup = (uint8_t*)LookupTables[l].GetChars(); const uint8_t* lookup = (uint8_t*)tables[l].Shades.GetChars();
FRemapTable remap; FRemapTable remap;
if (i == 0 || (palette != basepalette && !palette->Inactive)) if (i == 0 || (palette != basepalette && !palette->Inactive))
{ {
@ -274,20 +284,23 @@ void palettePostLoadLookups(void)
} }
} }
} }
// Swap colors 0 and 255 in all tables so that all paletted images have their transparent color at index 0. // Assuming that color 255 is always transparent, do the following:
// This means: // Copy color 0 to color 255
// - Swap palette and remap entries in all stored remap tables // Set color 0 to transparent black
// - change all remap entries of 255 to 0 and vice versa // Swap all remap entries from 0 to 255 and vice versa
// Always map 0 to 0.
auto colorswap = [](FRemapTable* remap) auto colorswap = [](FRemapTable* remap)
{ {
std::swap(remap->Palette[0], remap->Palette[255]); remap->Palette[255] = remap->Palette[0];
std::swap(remap->Remap[0], remap->Remap[255]); remap->Palette[0] = 0;
remap->Remap[255] = remap->Remap[0];
for (auto& c : remap->Remap) for (auto& c : remap->Remap)
{ {
if (c == 0) c = 255; if (c == 0) c = 255;
else if (c == 255) c = 0; else if (c == 255) c = 0;
} }
remap->Remap[0] = 0;
}; };
for (auto remap : GPalette.uniqueRemaps) for (auto remap : GPalette.uniqueRemaps)
@ -304,12 +317,12 @@ void palettePostLoadLookups(void)
// //
//========================================================================== //==========================================================================
int32_t paletteSetLookupTable(int32_t palnum, const uint8_t *shtab) int32_t LookupTableInfo::setTable(int palnum, const uint8_t *shtab)
{ {
if (shtab != NULL) if (shtab != NULL)
{ {
int length = numshades * 256; int length = numshades * 256;
LookupTables[palnum] = FString((const char*)shtab, length); tables[palnum].Shades = FString((const char*)shtab, length);
} }
return 0; return 0;
@ -321,7 +334,7 @@ int32_t paletteSetLookupTable(int32_t palnum, const uint8_t *shtab)
// //
//========================================================================== //==========================================================================
void paletteMakeLookupTable(int32_t palnum, const uint8_t *remapbuf, uint8_t r, uint8_t g, uint8_t b, char noFloorPal) void LookupTableInfo::makeTable(int palnum, const uint8_t *remapbuf, int r, int g, int b, bool noFloorPal)
{ {
uint8_t idmap[256]; uint8_t idmap[256];
@ -329,13 +342,13 @@ void paletteMakeLookupTable(int32_t palnum, const uint8_t *remapbuf, uint8_t r,
if (paletteloaded == 0 || (unsigned)palnum >= MAXPALOOKUPS) if (paletteloaded == 0 || (unsigned)palnum >= MAXPALOOKUPS)
return; return;
g_noFloorPal[palnum] = noFloorPal; tables[palnum].noFloorPal = noFloorPal;
if (remapbuf == nullptr) if (remapbuf == nullptr)
{ {
if (r == 0 || g == 0 || b == 0) if (r == 0 || g == 0 || b == 0)
{ {
paletteClearLookupTable(palnum); clearTable(palnum);
return; return;
} }
@ -344,12 +357,12 @@ void paletteMakeLookupTable(int32_t palnum, const uint8_t *remapbuf, uint8_t r,
} }
int length = numshades * 256; int length = numshades * 256;
auto p = LookupTables[palnum].LockNewBuffer(length); auto p = tables[palnum].Shades.LockNewBuffer(length);
if (r == 0 || g == 0 || b == 0) if (r == 0 || g == 0 || b == 0)
{ {
// "black fog"/visibility case -- only remap color indices // "black fog"/visibility case -- only remap color indices
auto src = paletteGetLookupTable(0); auto src = getTable(0);
for (int j = 0; j < numshades; j++) for (int j = 0; j < numshades; j++)
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
@ -374,12 +387,10 @@ void paletteMakeLookupTable(int32_t palnum, const uint8_t *remapbuf, uint8_t r,
} }
} }
#if defined(USE_OPENGL) tables[palnum].FadeColor.r = r;
palookupfog[palnum].r = r; tables[palnum].FadeColor.g = g;
palookupfog[palnum].g = g; tables[palnum].FadeColor.b = b;
palookupfog[palnum].b = b; tables[palnum].FadeColor.a = 1;
palookupfog[palnum].f = 1;
#endif
} }

View file

@ -373,7 +373,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
return; return;
} }
if (!paletteCheckLookupTable(globalpal)) if (!lookups.checkTable(globalpal))
globalpal = 0; globalpal = 0;
//Load texture (globalpicnum) //Load texture (globalpicnum)
@ -4568,7 +4568,7 @@ static void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype
// while sprites are clamped // while sprites are clamped
if (videoGetRenderMode() < REND_POLYMOST) return; if (videoGetRenderMode() < REND_POLYMOST) return;
if ((dapalnum < (MAXPALOOKUPS - RESERVEDPALS)) && (!paletteCheckLookupTable(dapalnum))) return;//dapalnum = 0; if ((dapalnum < (MAXPALOOKUPS - RESERVEDPALS)) && (!lookups.checkTable(dapalnum))) return;//dapalnum = 0;
//Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype); //Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype);
hicprecaching = 1; hicprecaching = 1;

View file

@ -361,7 +361,7 @@ void V_InitScreen()
void V_Init2() void V_Init2()
{ {
palettePostLoadLookups(); lookups.postLoadLookups();
twod = &twodgen; twod = &twodgen;
float gamma = static_cast<DDummyFrameBuffer *>(screen)->Gamma; float gamma = static_cast<DDummyFrameBuffer *>(screen)->Gamma;

View file

@ -600,7 +600,7 @@ void tileCopy(int tile, int source, int pal, int xoffset, int yoffset, int flags
if (pal != -1) if (pal != -1)
{ {
auto remap = paletteGetLookupTable(pal); auto remap = lookups.getTable(pal);
for (auto& pixel : buffer) for (auto& pixel : buffer)
{ {
pixel = remap[pixel]; pixel = remap[pixel];

View file

@ -110,7 +110,7 @@ void G_LoadLookups(void)
if (!fr.isOpen()) if (!fr.isOpen())
return; return;
j = paletteLoadLookupTable(fr); j = lookups.loadTable(fr);
if (j < 0) if (j < 0)
{ {

View file

@ -3252,7 +3252,7 @@ static int G_MaybeTakeOnFloorPal(tspriteptr_t pSprite, int sectNum)
{ {
int const floorPal = sector[sectNum].floorpal; int const floorPal = sector[sectNum].floorpal;
if (floorPal && !g_noFloorPal[floorPal] && !A_CheckSpriteFlags(pSprite->owner, SFLAG_NOPAL)) if (floorPal && !lookups.noFloorPal(floorPal) && !A_CheckSpriteFlags(pSprite->owner, SFLAG_NOPAL))
{ {
pSprite->pal = floorPal; pSprite->pal = floorPal;
return 1; return 1;
@ -5258,10 +5258,7 @@ static inline void G_CheckGametype(void)
static void G_PostLoadPalette(void) static void G_PostLoadPalette(void)
{ {
if (!(duke3d_globalflags & DUKE3D_NO_HARDCODED_FOGPALS)) if (!(duke3d_globalflags & DUKE3D_NO_HARDCODED_FOGPALS))
paletteSetupDefaultFog(); lookups.setupDefaultFog();
if (!(duke3d_globalflags & DUKE3D_NO_PALETTE_CHANGES))
paletteFixTranslucencyMask();
} }
#define SETFLAG(Tilenum, Flag) g_tile[Tilenum].flags |= Flag #define SETFLAG(Tilenum, Flag) g_tile[Tilenum].flags |= Flag

View file

@ -1917,7 +1917,7 @@ int32_t __fastcall VM_GetPalData(int const palNum, int32_t labelNum)
switch (labelNum) switch (labelNum)
{ {
case PALDATA_NOFLOORPAL: labelNum = g_noFloorPal[palNum]; break; case PALDATA_NOFLOORPAL: labelNum = lookups.noFloorPal(palNum); break;
default: EDUKE32_UNREACHABLE_SECTION(labelNum = -1; break); default: EDUKE32_UNREACHABLE_SECTION(labelNum = -1; break);
} }

View file

@ -1803,7 +1803,7 @@ int P_GetHudPal(const DukePlayer_t *p)
if (p->cursectnum >= 0) if (p->cursectnum >= 0)
{ {
int const hudPal = sector[p->cursectnum].floorpal; int const hudPal = sector[p->cursectnum].floorpal;
if (!g_noFloorPal[hudPal]) if (!lookups.noFloorPal(hudPal))
return hudPal; return hudPal;
} }

View file

@ -98,8 +98,6 @@ void cacheAllSounds(void)
for(auto &snd : sfx) for(auto &snd : sfx)
{ {
soundEngine->CacheSound(&snd); soundEngine->CacheSound(&snd);
if (((++i)&31) == 0)
gameHandleEvents();
} }
} }

View file

@ -93,7 +93,7 @@ int LoadPaletteLookups()
} }
hFile.Read(buffer, 256*64); hFile.Read(buffer, 256*64);
paletteSetLookupTable(i, buffer); lookups.setTable(i, buffer);
bGreenPal = 0; bGreenPal = 0;

View file

@ -120,8 +120,8 @@ void PaletteManager::BindPalette(int index)
void PaletteManager::BindPalswap(int index) void PaletteManager::BindPalswap(int index)
{ {
if (LookupTables[index].Len() == 0) index = 0; if (!lookups.checkTable(index)) index = 0;
if (LookupTables[index].Len() > 0) if (lookups.checkTable(index))
{ {
if (index != lastsindex) if (index != lastsindex)
{ {
@ -130,12 +130,22 @@ void PaletteManager::BindPalswap(int index)
{ {
auto p = GLInterface.NewTexture(); auto p = GLInterface.NewTexture();
p->CreateTexture(256, numshades, FHardwareTexture::Indexed, false); p->CreateTexture(256, numshades, FHardwareTexture::Indexed, false);
p->LoadTexture((uint8_t*)LookupTables[index].GetChars());
// Perform a 0<->255 index swap. The lookup tables are still the original data.
TArray<uint8_t> lookup(numshades * 256, true);
memcpy(lookup.Data(), lookups.getTable(index), lookup.Size());
for (int i = 0; i < numshades; i++)
{
auto p = &lookup[i * 256];
p[255] = p[0];
p[0] = 0;
}
p->LoadTexture(lookup.Data());
p->SetSampler(SamplerNoFilterClampXY); p->SetSampler(SamplerNoFilterClampXY);
palswaptextures[index] = p; palswaptextures[index] = p;
} }
inst->BindTexture(1, palswaptextures[index]); inst->BindTexture(1, palswaptextures[index]);
inst->SetFadeColor(PalEntry(palookupfog[index].r, palookupfog[index].g, palookupfog[index].b)); inst->SetFadeColor(lookups.getFade(index));
} }
} }

View file

@ -109,7 +109,7 @@ void G_LoadLookups(void)
if (!fr.isOpen()) if (!fr.isOpen())
return; return;
j = paletteLoadLookupTable(fr); j = lookups.loadTable(fr);
if (j < 0) if (j < 0)
{ {
@ -152,16 +152,16 @@ void G_LoadLookups(void)
for (bssize_t i = 0; i < 32; i++) for (bssize_t i = 0; i < 32; i++)
table[i] = i+32; table[i] = i+32;
paletteMakeLookupTable(7, table, 0, 0, 0, 0); lookups.makeTable(7, table, 0, 0, 0, 0);
for (bssize_t i = 0; i < 256; i++) for (bssize_t i = 0; i < 256; i++)
table[i] = i; table[i] = i;
paletteMakeLookupTable(30, table, 0, 0, 0, 0); lookups.makeTable(30, table, 0, 0, 0, 0);
paletteMakeLookupTable(31, table, 0, 0, 0, 0); lookups.makeTable(31, table, 0, 0, 0, 0);
paletteMakeLookupTable(32, table, 0, 0, 0, 0); lookups.makeTable(32, table, 0, 0, 0, 0);
paletteMakeLookupTable(33, table, 0, 0, 0, 0); lookups.makeTable(33, table, 0, 0, 0, 0);
if (RRRA) if (RRRA)
paletteMakeLookupTable(105, table, 0, 0, 0, 0); lookups.makeTable(105, table, 0, 0, 0, 0);
j = 63; j = 63;
for (bssize_t i = 64; i < 80; i++) for (bssize_t i = 64; i < 80; i++)
@ -174,19 +174,19 @@ void G_LoadLookups(void)
table[81] = 81; table[81] = 81;
for (bssize_t i = 0; i < 32; i++) for (bssize_t i = 0; i < 32; i++)
table[i] = i+32; table[i] = i+32;
paletteMakeLookupTable(34, table, 0, 0, 0, 0); lookups.makeTable(34, table, 0, 0, 0, 0);
for (bssize_t i = 0; i < 256; i++) for (bssize_t i = 0; i < 256; i++)
table[i] = i; table[i] = i;
for (bssize_t i = 0; i < 16; i++) for (bssize_t i = 0; i < 16; i++)
table[i] = i+129; table[i] = i+129;
for (bssize_t i = 16; i < 32; i++) for (bssize_t i = 16; i < 32; i++)
table[i] = i+192; table[i] = i+192;
paletteMakeLookupTable(35, table, 0, 0, 0, 0); lookups.makeTable(35, table, 0, 0, 0, 0);
if (RRRA) if (RRRA)
{ {
paletteMakeLookupTable(50, NULL, 12 * 4, 12 * 4, 12 * 4, 0); lookups.makeTable(50, NULL, 12 * 4, 12 * 4, 12 * 4, 0);
paletteMakeLookupTable(51, NULL, 12 * 4, 12 * 4, 12 * 4, 0); lookups.makeTable(51, NULL, 12 * 4, 12 * 4, 12 * 4, 0);
paletteMakeLookupTable(54, paletteGetLookupTable(8), 32 * 4, 32 * 4, 32 * 4, 0); lookups.makeTable(54, lookups.getTable(8), 32 * 4, 32 * 4, 32 * 4, 0);
} }
} }
} }

View file

@ -4357,7 +4357,7 @@ static int G_MaybeTakeOnFloorPal(tspritetype *pSprite, int sectNum)
{ {
int const floorPal = sector[sectNum].floorpal; int const floorPal = sector[sectNum].floorpal;
if (floorPal && !g_noFloorPal[floorPal] && !A_CheckSpriteFlags(pSprite->owner, SFLAG_NOPAL)) if (floorPal && !lookups.noFloorPal(floorPal) && !A_CheckSpriteFlags(pSprite->owner, SFLAG_NOPAL))
{ {
pSprite->pal = floorPal; pSprite->pal = floorPal;
return 1; return 1;
@ -6603,9 +6603,6 @@ static void G_PostLoadPalette(void)
{ {
//if (!(duke3d_globalflags & DUKE3D_NO_HARDCODED_FOGPALS)) //if (!(duke3d_globalflags & DUKE3D_NO_HARDCODED_FOGPALS))
// paletteSetupDefaultFog(); // paletteSetupDefaultFog();
if (!(duke3d_globalflags & DUKE3D_NO_PALETTE_CHANGES))
paletteFixTranslucencyMask();
} }
#define SETFLAG(Tilenum, Flag) g_tile[Tilenum].flags |= Flag #define SETFLAG(Tilenum, Flag) g_tile[Tilenum].flags |= Flag

View file

@ -1423,7 +1423,7 @@ int P_GetHudPal(const DukePlayer_t *p)
if (p->cursectnum >= 0) if (p->cursectnum >= 0)
{ {
int const hudPal = sector[p->cursectnum].floorpal; int const hudPal = sector[p->cursectnum].floorpal;
if (!g_noFloorPal[hudPal]) if (!lookups.noFloorPal(hudPal))
return hudPal; return hudPal;
} }

View file

@ -4335,7 +4335,7 @@ void sub_59C20(void)
} }
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
table[i] = i; table[i] = i;
paletteMakeLookupTable(2, table, 10*4, 10*4, 24*4, 0); lookups.makeTable(2, table, 10*4, 10*4, 24*4, 0);
} }
int dword_2BEA20, dword_2BEA24; int dword_2BEA20, dword_2BEA24;

View file

@ -97,8 +97,6 @@ void cacheAllSounds(void)
for(auto &snd : sfx) for(auto &snd : sfx)
{ {
soundEngine->CacheSound(&snd); soundEngine->CacheSound(&snd);
if (((++i)&31) == 0)
G_HandleAsync();
} }
} }

View file

@ -228,31 +228,31 @@ InitPalette(void)
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
tempbuf[i] = i; tempbuf[i] = i;
// palette for underwater // palette for underwater
paletteMakeLookupTable(PALETTE_DIVE, tempbuf, 0, 0, FOG_AMT, TRUE); lookups.makeTable(PALETTE_DIVE, tempbuf, 0, 0, FOG_AMT, TRUE);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
tempbuf[i] = i; tempbuf[i] = i;
paletteMakeLookupTable(PALETTE_FOG, tempbuf, FOG_AMT, FOG_AMT, FOG_AMT, TRUE); lookups.makeTable(PALETTE_FOG, tempbuf, FOG_AMT, FOG_AMT, FOG_AMT, TRUE);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
tempbuf[i] = i; tempbuf[i] = i;
paletteMakeLookupTable(PALETTE_DIVE_LAVA, tempbuf, LAVA_AMT, 0, 0, TRUE); lookups.makeTable(PALETTE_DIVE_LAVA, tempbuf, LAVA_AMT, 0, 0, TRUE);
// //
// 1 Range changes // 1 Range changes
// //
MapColors(PALETTE_BROWN_RIPPER, BrownRipper, TRUE, tempbuf); MapColors(PALETTE_BROWN_RIPPER, BrownRipper, TRUE, tempbuf);
paletteMakeLookupTable(PALETTE_BROWN_RIPPER, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_BROWN_RIPPER, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_SKEL_GORE, SkelGore, TRUE, tempbuf); MapColors(PALETTE_SKEL_GORE, SkelGore, TRUE, tempbuf);
paletteMakeLookupTable(PALETTE_SKEL_GORE, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_SKEL_GORE, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_ELECTRO_GORE, ElectroGore, TRUE, tempbuf); MapColors(PALETTE_ELECTRO_GORE, ElectroGore, TRUE, tempbuf);
paletteMakeLookupTable(PALETTE_ELECTRO_GORE, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_ELECTRO_GORE, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_MENU_HIGHLIGHT, MenuHighlight, TRUE, tempbuf); MapColors(PALETTE_MENU_HIGHLIGHT, MenuHighlight, TRUE, tempbuf);
paletteMakeLookupTable(PALETTE_MENU_HIGHLIGHT, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_MENU_HIGHLIGHT, tempbuf, 0, 0, 0, TRUE);
// //
// Multiple range changes // Multiple range changes
@ -261,44 +261,44 @@ InitPalette(void)
MapColors(PALETTE_BASIC_NINJA, NinjaBasic[0], TRUE, tempbuf); MapColors(PALETTE_BASIC_NINJA, NinjaBasic[0], TRUE, tempbuf);
for (i = 1; i < SIZ(NinjaBasic); i++) for (i = 1; i < SIZ(NinjaBasic); i++)
MapColors(PALETTE_BASIC_NINJA, NinjaBasic[i], FALSE, tempbuf); MapColors(PALETTE_BASIC_NINJA, NinjaBasic[i], FALSE, tempbuf);
paletteMakeLookupTable(PALETTE_BASIC_NINJA, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_BASIC_NINJA, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_RED_NINJA, NinjaRed[0], TRUE, tempbuf); MapColors(PALETTE_RED_NINJA, NinjaRed[0], TRUE, tempbuf);
for (i = 1; i < SIZ(NinjaRed); i++) for (i = 1; i < SIZ(NinjaRed); i++)
MapColors(PALETTE_RED_NINJA, NinjaRed[i], FALSE, tempbuf); MapColors(PALETTE_RED_NINJA, NinjaRed[i], FALSE, tempbuf);
paletteMakeLookupTable(PALETTE_RED_NINJA, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_RED_NINJA, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_GREEN_NINJA, NinjaGreen[0], TRUE, tempbuf); MapColors(PALETTE_GREEN_NINJA, NinjaGreen[0], TRUE, tempbuf);
for (i = 1; i < SIZ(NinjaGreen); i++) for (i = 1; i < SIZ(NinjaGreen); i++)
MapColors(PALETTE_GREEN_NINJA, NinjaGreen[i], FALSE, tempbuf); MapColors(PALETTE_GREEN_NINJA, NinjaGreen[i], FALSE, tempbuf);
paletteMakeLookupTable(PALETTE_GREEN_NINJA, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_GREEN_NINJA, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_GREEN_LIGHTING, AllToGreen[0], TRUE, tempbuf); MapColors(PALETTE_GREEN_LIGHTING, AllToGreen[0], TRUE, tempbuf);
for (i = 1; i < SIZ(AllToGreen); i++) for (i = 1; i < SIZ(AllToGreen); i++)
MapColors(PALETTE_GREEN_LIGHTING, AllToGreen[i], FALSE, tempbuf); MapColors(PALETTE_GREEN_LIGHTING, AllToGreen[i], FALSE, tempbuf);
paletteMakeLookupTable(PALETTE_GREEN_LIGHTING, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_GREEN_LIGHTING, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_RED_LIGHTING, AllToRed[0], TRUE, tempbuf); MapColors(PALETTE_RED_LIGHTING, AllToRed[0], TRUE, tempbuf);
for (i = 1; i < SIZ(AllToRed); i++) for (i = 1; i < SIZ(AllToRed); i++)
MapColors(PALETTE_RED_LIGHTING, AllToRed[i], FALSE, tempbuf); MapColors(PALETTE_RED_LIGHTING, AllToRed[i], FALSE, tempbuf);
paletteMakeLookupTable(PALETTE_RED_LIGHTING, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_RED_LIGHTING, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_BLUE_LIGHTING, AllToBlue[0], TRUE, tempbuf); MapColors(PALETTE_BLUE_LIGHTING, AllToBlue[0], TRUE, tempbuf);
for (i = 1; i < SIZ(AllToBlue); i++) for (i = 1; i < SIZ(AllToBlue); i++)
MapColors(PALETTE_BLUE_LIGHTING, AllToBlue[i], FALSE, tempbuf); MapColors(PALETTE_BLUE_LIGHTING, AllToBlue[i], FALSE, tempbuf);
paletteMakeLookupTable(PALETTE_BLUE_LIGHTING, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_BLUE_LIGHTING, tempbuf, 0, 0, 0, TRUE);
MapColors(PALETTE_ILLUMINATE, Illuminate[0], TRUE, tempbuf); MapColors(PALETTE_ILLUMINATE, Illuminate[0], TRUE, tempbuf);
for (i = 1; i < SIZ(Illuminate); i++) for (i = 1; i < SIZ(Illuminate); i++)
MapColors(PALETTE_ILLUMINATE, Illuminate[i], FALSE, tempbuf); MapColors(PALETTE_ILLUMINATE, Illuminate[i], FALSE, tempbuf);
paletteMakeLookupTable(PALETTE_ILLUMINATE, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_ILLUMINATE, tempbuf, 0, 0, 0, TRUE);
// PLAYER COLORS - ALSO USED FOR OTHER THINGS // PLAYER COLORS - ALSO USED FOR OTHER THINGS
for (play = 0; play < PLAYER_COLOR_MAPS; play++) for (play = 0; play < PLAYER_COLOR_MAPS; play++)
{ {
MapColors(PALETTE_PLAYER0 + play, PlayerColorMap[play][0], TRUE, tempbuf); MapColors(PALETTE_PLAYER0 + play, PlayerColorMap[play][0], TRUE, tempbuf);
MapColors(PALETTE_PLAYER0 + play, PlayerColorMap[play][0], FALSE, tempbuf); MapColors(PALETTE_PLAYER0 + play, PlayerColorMap[play][0], FALSE, tempbuf);
paletteMakeLookupTable(PALETTE_PLAYER0 + play, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_PLAYER0 + play, tempbuf, 0, 0, 0, TRUE);
} }
// //
@ -310,7 +310,7 @@ InitPalette(void)
// invert the brown palette // invert the brown palette
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
tempbuf[LT_BROWN + i] = (LT_BROWN + 32) - i; tempbuf[LT_BROWN + i] = (LT_BROWN + 32) - i;
paletteMakeLookupTable(PALETTE_SLUDGE, tempbuf, 0, 0, 0, TRUE); lookups.makeTable(PALETTE_SLUDGE, tempbuf, 0, 0, 0, TRUE);
} }

View file

@ -816,7 +816,6 @@ bool InitGame()
enginePostInit(); enginePostInit();
paletteFixTranslucencyMask();
V_Init2(); V_Init2();
DemoModeMenuInit = TRUE; DemoModeMenuInit = TRUE;