mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 08:51:24 +00:00
- 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:
parent
5d55f768e0
commit
0e1eeea037
7 changed files with 25 additions and 37 deletions
|
@ -40,22 +40,20 @@
|
||||||
namespace ImageHelpers
|
namespace ImageHelpers
|
||||||
{
|
{
|
||||||
uint8_t GrayMap[256];
|
uint8_t GrayMap[256];
|
||||||
PalEntry BasePalette[256];
|
|
||||||
int WhiteIndex, BlackIndex;
|
int WhiteIndex, BlackIndex;
|
||||||
int alphaThreshold;
|
int alphaThreshold;
|
||||||
ColorTable256k RGB256k;
|
ColorTable256k RGB256k;
|
||||||
|
|
||||||
int BestColor(int r, int g, int b, int first, int num)
|
int BestColor(int r, int g, int b, int first, int num)
|
||||||
{
|
{
|
||||||
const PalEntry* pal = BasePalette;
|
|
||||||
int bestcolor = first;
|
int bestcolor = first;
|
||||||
int bestdist = 257 * 257 + 257 * 257 + 257 * 257;
|
int bestdist = 257 * 257 + 257 * 257 + 257 * 257;
|
||||||
|
|
||||||
for (int color = first; color < num; color++)
|
for (int color = first; color < num; color++)
|
||||||
{
|
{
|
||||||
int x = r - pal[color].r;
|
int x = r - palette[color * 3 + 0];
|
||||||
int y = g - pal[color].g;
|
int y = g - palette[color * 3 + 1];
|
||||||
int z = b - pal[color].b;
|
int z = b - palette[color * 3 + 2];
|
||||||
int dist = x * x + y * y + z * z;
|
int dist = x * x + y * y + z * z;
|
||||||
if (dist < bestdist)
|
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)
|
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 double powtable[256];
|
||||||
static bool firstTime = true;
|
static bool firstTime = true;
|
||||||
static float trackpowtable = 0.;
|
static float trackpowtable = 0.;
|
||||||
|
@ -91,9 +88,9 @@ namespace ImageHelpers
|
||||||
|
|
||||||
for (int color = first; color < num; color++)
|
for (int color = first; color < num; color++)
|
||||||
{
|
{
|
||||||
double x = powtable[abs(r - pal[color].r)];
|
double x = powtable[abs(r - palette[color * 3 + 0])];
|
||||||
double y = powtable[abs(g - pal[color].g)];
|
double y = powtable[abs(g - palette[color * 3 + 1])];
|
||||||
double z = powtable[abs(b - pal[color].b)];
|
double z = powtable[abs(b - palette[color * 3 + 2])];
|
||||||
fdist = x + y + z;
|
fdist = x + y + z;
|
||||||
if (color == first || (reverselookup ? (fdist <= fbestdist) : (fdist < fbestdist)))
|
if (color == first || (reverselookup ? (fdist <= fbestdist) : (fdist < fbestdist)))
|
||||||
{
|
{
|
||||||
|
@ -109,13 +106,6 @@ namespace ImageHelpers
|
||||||
|
|
||||||
void SetPalette(const PalEntry* colors)
|
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
|
// Find white and black from the original palette so that they can be
|
||||||
// used to make an educated guess of the translucency % for a
|
// used to make an educated guess of the translucency % for a
|
||||||
// translucency map.
|
// translucency map.
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
#include "palentry.h"
|
#include "palentry.h"
|
||||||
#include "textures/bitmap.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
|
namespace ImageHelpers
|
||||||
{
|
{
|
||||||
union ColorTable256k
|
union ColorTable256k
|
||||||
|
@ -51,7 +54,6 @@ namespace ImageHelpers
|
||||||
};
|
};
|
||||||
|
|
||||||
extern uint8_t GrayMap[256];
|
extern uint8_t GrayMap[256];
|
||||||
extern PalEntry BasePalette[256];
|
|
||||||
extern int WhiteIndex, BlackIndex;
|
extern int WhiteIndex, BlackIndex;
|
||||||
extern ColorTable256k RGB256k;
|
extern ColorTable256k RGB256k;
|
||||||
extern int alphaThreshold;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5749,8 +5749,7 @@ int GameInterface::app_main()
|
||||||
|
|
||||||
cacheAllSounds();
|
cacheAllSounds();
|
||||||
|
|
||||||
if (enginePostInit())
|
enginePostInit();
|
||||||
G_FatalEngineError();
|
|
||||||
|
|
||||||
G_PostLoadPalette();
|
G_PostLoadPalette();
|
||||||
|
|
||||||
|
|
|
@ -1949,13 +1949,8 @@ int GameInterface::app_main()
|
||||||
loaddefinitions_game(defsfile, FALSE);
|
loaddefinitions_game(defsfile, FALSE);
|
||||||
|
|
||||||
|
|
||||||
if (enginePostInit())
|
enginePostInit();
|
||||||
ShutDown();
|
|
||||||
|
|
||||||
// loc_11745:
|
|
||||||
// FadeOut(0);
|
|
||||||
// InstallEngine();
|
|
||||||
//KB_Startup();
|
|
||||||
InitView();
|
InitView();
|
||||||
myloadconfig();
|
myloadconfig();
|
||||||
InitFX();
|
InitFX();
|
||||||
|
|
|
@ -7215,8 +7215,7 @@ int GameInterface::app_main()
|
||||||
|
|
||||||
userConfig.AddDefs.reset();
|
userConfig.AddDefs.reset();
|
||||||
|
|
||||||
if (enginePostInit())
|
enginePostInit();
|
||||||
G_FatalEngineError();
|
|
||||||
|
|
||||||
G_PostLoadPalette();
|
G_PostLoadPalette();
|
||||||
|
|
||||||
|
|
|
@ -738,11 +738,6 @@ void COVERsetbrightness(int bright, unsigned char *pal)
|
||||||
static int firstnet = 0; // JBF
|
static int firstnet = 0; // JBF
|
||||||
|
|
||||||
|
|
||||||
static void SW_FatalEngineError(void)
|
|
||||||
{
|
|
||||||
I_Error("There was a problem initialising the Build engine: %s", engineerrstr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool InitGame()
|
bool InitGame()
|
||||||
{
|
{
|
||||||
extern int MovesPerPacket;
|
extern int MovesPerPacket;
|
||||||
|
@ -752,8 +747,7 @@ bool InitGame()
|
||||||
DSPRINTF(ds,"InitGame...");
|
DSPRINTF(ds,"InitGame...");
|
||||||
MONO_PRINT(ds);
|
MONO_PRINT(ds);
|
||||||
|
|
||||||
if (engineInit())
|
engineInit();
|
||||||
SW_FatalEngineError();
|
|
||||||
|
|
||||||
InitAutoNet();
|
InitAutoNet();
|
||||||
|
|
||||||
|
@ -866,8 +860,7 @@ bool InitGame()
|
||||||
|
|
||||||
userConfig.AddDefs.reset();
|
userConfig.AddDefs.reset();
|
||||||
|
|
||||||
if (enginePostInit())
|
enginePostInit();
|
||||||
SW_FatalEngineError();
|
|
||||||
|
|
||||||
palettePostLoadLookups();
|
palettePostLoadLookups();
|
||||||
V_Init2();
|
V_Init2();
|
||||||
|
|
|
@ -2096,7 +2096,6 @@ int _PlaySound(int num, SPRITEp sprite, PLAYERp player, vec3_t *pos, Voc3D_Flags
|
||||||
void InitAmbient(int num, SPRITEp sprite);
|
void InitAmbient(int num, SPRITEp sprite);
|
||||||
inline void PlaySound(int num, SPRITEp sprite, Voc3D_Flags flags, int channel = 8)
|
inline void PlaySound(int num, SPRITEp sprite, Voc3D_Flags flags, int channel = 8)
|
||||||
{
|
{
|
||||||
assert(num != DIGI_NINJAPAIN);
|
|
||||||
_PlaySound(num, sprite, nullptr, nullptr, flags, channel);
|
_PlaySound(num, sprite, nullptr, nullptr, flags, channel);
|
||||||
}
|
}
|
||||||
inline void PlaySound(int num, PLAYERp player, Voc3D_Flags flags, int channel = 8)
|
inline void PlaySound(int num, PLAYERp player, Voc3D_Flags flags, int channel = 8)
|
||||||
|
|
Loading…
Reference in a new issue