From 0e1eeea037db309b5de25143328a81543d73b117 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 1 Feb 2020 23:05:43 +0100 Subject: [PATCH] - 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. --- source/common/textures/imagehelpers.cpp | 22 ++++++---------------- source/common/textures/imagehelpers.h | 15 ++++++++++++++- source/duke3d/src/game.cpp | 3 +-- source/exhumed/src/exhumed.cpp | 7 +------ source/rr/src/game.cpp | 3 +-- source/sw/src/game.cpp | 11 ++--------- source/sw/src/game.h | 1 - 7 files changed, 25 insertions(+), 37 deletions(-) diff --git a/source/common/textures/imagehelpers.cpp b/source/common/textures/imagehelpers.cpp index e1842956c..1009ce22d 100644 --- a/source/common/textures/imagehelpers.cpp +++ b/source/common/textures/imagehelpers.cpp @@ -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. diff --git a/source/common/textures/imagehelpers.h b/source/common/textures/imagehelpers.h index 69807042d..ca9bfca59 100644 --- a/source/common/textures/imagehelpers.h +++ b/source/common/textures/imagehelpers.h @@ -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; } diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 57e4f3465..f43dbf635 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -5749,8 +5749,7 @@ int GameInterface::app_main() cacheAllSounds(); - if (enginePostInit()) - G_FatalEngineError(); + enginePostInit(); G_PostLoadPalette(); diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 15f42a3bf..d535af0e7 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -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(); diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 16a33dcc7..061f79a05 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -7215,8 +7215,7 @@ int GameInterface::app_main() userConfig.AddDefs.reset(); - if (enginePostInit()) - G_FatalEngineError(); + enginePostInit(); G_PostLoadPalette(); diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 3c39401b0..556298855 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -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(); diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 4dcd136ea..ca2d9df26 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -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)