- use the game palette directly for palette lookups.

The setup here is far too messy for having a copy in a better format - it can be changed in some non-obvious places.
This commit is contained in:
Christoph Oelckers 2020-02-01 23:05:43 +01:00
parent 5d55f768e0
commit 0e1eeea037
7 changed files with 25 additions and 37 deletions

View file

@ -40,22 +40,20 @@
namespace ImageHelpers
{
uint8_t GrayMap[256];
PalEntry BasePalette[256];
int WhiteIndex, BlackIndex;
int alphaThreshold;
ColorTable256k RGB256k;
int BestColor(int r, int g, int b, int first, int num)
{
const PalEntry* pal = BasePalette;
int bestcolor = first;
int bestdist = 257 * 257 + 257 * 257 + 257 * 257;
for (int color = first; color < num; color++)
{
int x = r - pal[color].r;
int y = g - pal[color].g;
int z = b - pal[color].b;
int x = r - palette[color * 3 + 0];
int y = g - palette[color * 3 + 1];
int z = b - palette[color * 3 + 2];
int dist = x * x + y * y + z * z;
if (dist < bestdist)
{
@ -73,7 +71,6 @@ namespace ImageHelpers
int PTM_BestColor(int r, int g, int b, bool reverselookup, float powtable_val, int first, int num)
{
const PalEntry* pal = BasePalette;
static double powtable[256];
static bool firstTime = true;
static float trackpowtable = 0.;
@ -91,9 +88,9 @@ namespace ImageHelpers
for (int color = first; color < num; color++)
{
double x = powtable[abs(r - pal[color].r)];
double y = powtable[abs(g - pal[color].g)];
double z = powtable[abs(b - pal[color].b)];
double x = powtable[abs(r - palette[color * 3 + 0])];
double y = powtable[abs(g - palette[color * 3 + 1])];
double z = powtable[abs(b - palette[color * 3 + 2])];
fdist = x + y + z;
if (color == first || (reverselookup ? (fdist <= fbestdist) : (fdist < fbestdist)))
{
@ -109,13 +106,6 @@ namespace ImageHelpers
void SetPalette(const PalEntry* colors)
{
for (int i = 0; i < 255; i++)
{
BasePalette[i] = colors[i];
BasePalette[i].a = 255;
}
BasePalette[255] = 0; // 255 is always translucent black - whatever color the original data has here
// Find white and black from the original palette so that they can be
// used to make an educated guess of the translucency % for a
// translucency map.

View file

@ -42,6 +42,9 @@
#include "palentry.h"
#include "textures/bitmap.h"
// we do not want to pull in the entirety of build.h here.
extern uint8_t palette[768];
namespace ImageHelpers
{
union ColorTable256k
@ -51,7 +54,6 @@ namespace ImageHelpers
};
extern uint8_t GrayMap[256];
extern PalEntry BasePalette[256];
extern int WhiteIndex, BlackIndex;
extern ColorTable256k RGB256k;
extern int alphaThreshold;
@ -142,4 +144,15 @@ namespace ImageHelpers
}
}
struct
{
PalEntry operator[](int index)
{
return PalEntry(
palette[index * 3 + 0],
palette[index * 3 + 1],
palette[index * 3 + 2]
);
}
} BasePalette;
}

View file

@ -5749,8 +5749,7 @@ int GameInterface::app_main()
cacheAllSounds();
if (enginePostInit())
G_FatalEngineError();
enginePostInit();
G_PostLoadPalette();

View file

@ -1949,13 +1949,8 @@ int GameInterface::app_main()
loaddefinitions_game(defsfile, FALSE);
if (enginePostInit())
ShutDown();
enginePostInit();
// loc_11745:
// FadeOut(0);
// InstallEngine();
//KB_Startup();
InitView();
myloadconfig();
InitFX();

View file

@ -7215,8 +7215,7 @@ int GameInterface::app_main()
userConfig.AddDefs.reset();
if (enginePostInit())
G_FatalEngineError();
enginePostInit();
G_PostLoadPalette();

View file

@ -738,11 +738,6 @@ void COVERsetbrightness(int bright, unsigned char *pal)
static int firstnet = 0; // JBF
static void SW_FatalEngineError(void)
{
I_Error("There was a problem initialising the Build engine: %s", engineerrstr);
}
bool InitGame()
{
extern int MovesPerPacket;
@ -752,8 +747,7 @@ bool InitGame()
DSPRINTF(ds,"InitGame...");
MONO_PRINT(ds);
if (engineInit())
SW_FatalEngineError();
engineInit();
InitAutoNet();
@ -866,8 +860,7 @@ bool InitGame()
userConfig.AddDefs.reset();
if (enginePostInit())
SW_FatalEngineError();
enginePostInit();
palettePostLoadLookups();
V_Init2();

View file

@ -2096,7 +2096,6 @@ int _PlaySound(int num, SPRITEp sprite, PLAYERp player, vec3_t *pos, Voc3D_Flags
void InitAmbient(int num, SPRITEp sprite);
inline void PlaySound(int num, SPRITEp sprite, Voc3D_Flags flags, int channel = 8)
{
assert(num != DIGI_NINJAPAIN);
_PlaySound(num, sprite, nullptr, nullptr, flags, channel);
}
inline void PlaySound(int num, PLAYERp player, Voc3D_Flags flags, int channel = 8)