From 34556100319df5150d20fb5f587c6f320770dfb7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 14 Aug 2020 21:18:14 +0200 Subject: [PATCH] - base palette cleanup. Avoid passing this anywhere in the client code. It should only be set right before rendering the 3D view and the only code using the base palette should be the 3D renderer and hud_drawsprite. Also make the palette override CVARs 3D view only in debug mode. --- source/blood/src/choke.cpp | 4 ++-- source/blood/src/choke.h | 2 +- source/blood/src/d_menu.cpp | 4 ++-- source/blood/src/hudsprites.cpp | 6 +++--- source/blood/src/misc.h | 2 +- source/blood/src/nnexts.cpp | 6 +++--- source/blood/src/nnexts.h | 2 +- source/blood/src/qav.cpp | 12 +++++------ source/blood/src/qav.h | 4 ++-- source/blood/src/view.cpp | 2 +- source/blood/src/weapon.cpp | 4 ++-- source/build/src/engine.cpp | 4 +--- source/core/textures/buildtiles.cpp | 11 +++------- source/exhumed/src/exhumed.cpp | 1 - source/exhumed/src/init.cpp | 2 -- source/exhumed/src/light.cpp | 33 ----------------------------- source/exhumed/src/light.h | 4 ---- source/exhumed/src/view.cpp | 1 - source/games/duke/src/game.cpp | 1 - source/glbackend/gl_texture.cpp | 14 ++++++++++++ source/sw/src/game.cpp | 1 - 21 files changed, 42 insertions(+), 78 deletions(-) diff --git a/source/blood/src/choke.cpp b/source/blood/src/choke.cpp index 32c5db928..c2b44ee11 100644 --- a/source/blood/src/choke.cpp +++ b/source/blood/src/choke.cpp @@ -52,7 +52,7 @@ void CChoke::sub_83ff0(int a1, void(*a2)(PLAYER*)) } } -void CChoke::sub_84110(int x, int y, int basepal) +void CChoke::sub_84110(int x, int y) { if (!at8) return; @@ -69,7 +69,7 @@ void CChoke::sub_84110(int x, int y, int basepal) at8->Play(vdi-vd, vdi, -1, NULL); // This originally overlaid the HUD but that simply doesn't work right with the HUD being a genuine overlay. // It also never adjusted for a reduced 3D view - at8->Draw(vdi, 10, 0, 0, basepal, true); + at8->Draw(vdi, 10, 0, 0, true); gFrameClock = v4; } diff --git a/source/blood/src/choke.h b/source/blood/src/choke.h index 98821dc34..f72d253b7 100644 --- a/source/blood/src/choke.h +++ b/source/blood/src/choke.h @@ -42,7 +42,7 @@ public: at18 = 0; }; void sub_83ff0(int a1, void(*a2)(PLAYER*)); - void sub_84110(int x, int y, int basepal); + void sub_84110(int x, int y); void sub_84218(); char *at0; QAV *at8; diff --git a/source/blood/src/d_menu.cpp b/source/blood/src/d_menu.cpp index ed4be948e..20e23cc4a 100644 --- a/source/blood/src/d_menu.cpp +++ b/source/blood/src/d_menu.cpp @@ -104,13 +104,13 @@ void CGameMenuItemQAV::Draw(void) int backX = data->x; for (int i = 0; i < nCount; i++) { - data->Draw(data->at10 - at2c, 10 + kQavOrientationLeft, 0, 0, 0, false); + data->Draw(data->at10 - at2c, 10 + kQavOrientationLeft, 0, 0, false); data->x += 320; } data->x = backX; } else - data->Draw(data->at10 - at2c, 10, 0, 0, 0, false); + data->Draw(data->at10 - at2c, 10, 0, 0, false); gFrameClock = backFC; } diff --git a/source/blood/src/hudsprites.cpp b/source/blood/src/hudsprites.cpp index 9ec881eb2..0d7d39979 100644 --- a/source/blood/src/hudsprites.cpp +++ b/source/blood/src/hudsprites.cpp @@ -129,14 +129,14 @@ void hudDraw(PLAYER *gView, int nSectnum, int defaultHoriz, double bobx, double } #ifdef NOONE_EXTENSIONS - if (gView->sceneQav < 0) WeaponDraw(gView, nShade, cX, cY, nPalette, basepal); - else if (gView->pXSprite->health > 0) playerQavSceneDraw(gView, nShade, cX, cY, nPalette, basepal); + if (gView->sceneQav < 0) WeaponDraw(gView, nShade, cX, cY, nPalette); + else if (gView->pXSprite->health > 0) playerQavSceneDraw(gView, nShade, cX, cY, nPalette); else { gView->sceneQav = gView->weaponQav = -1; gView->weaponTimer = gView->curWeapon = 0; } #else - WeaponDraw(gView, nShade, cX, cY, nPalette, curbasepal); + WeaponDraw(gView, nShade, cX, cY, nPalette); #endif } if (gViewPos == 0 && gView->pXSprite->burnTime > 60) diff --git a/source/blood/src/misc.h b/source/blood/src/misc.h index 3e7863160..1afdcbf49 100644 --- a/source/blood/src/misc.h +++ b/source/blood/src/misc.h @@ -52,7 +52,7 @@ struct PLAYER; extern QAV* weaponQAV[]; void WeaponInit(void); -void WeaponDraw(PLAYER *pPlayer, int a2, double a3, double a4, int a5, int basepal); +void WeaponDraw(PLAYER *pPlayer, int a2, double a3, double a4, int a5); void WeaponRaise(PLAYER *pPlayer); void WeaponLower(PLAYER *pPlayer); char WeaponUpgrade(PLAYER *pPlayer, char newWeapon); diff --git a/source/blood/src/nnexts.cpp b/source/blood/src/nnexts.cpp index 89e8ef1da..03175a006 100644 --- a/source/blood/src/nnexts.cpp +++ b/source/blood/src/nnexts.cpp @@ -4793,7 +4793,7 @@ void playerQavSceneProcess(PLAYER* pPlayer, QAVSCENE* pQavScene) { } } -void playerQavSceneDraw(PLAYER* pPlayer, int a2, double a3, double a4, int a5, int basepal) { +void playerQavSceneDraw(PLAYER* pPlayer, int a2, double a3, double a4, int a5) { if (pPlayer == NULL || pPlayer->sceneQav == -1) return; QAVSCENE* pQavScene = &gPlayerCtrl[pPlayer->nPlayer].qavScene; @@ -4813,13 +4813,13 @@ void playerQavSceneDraw(PLAYER* pPlayer, int a2, double a3, double a4, int a5, i if (!(pSprite->flags & kModernTypeFlag1)) { pQAV->x = int(a3); pQAV->y = int(a4); - pQAV->Draw(a3, a4, v4, flags, a2, a5, basepal, true); + pQAV->Draw(a3, a4, v4, flags, a2, a5, true); // draw fullscreen (currently 4:3 only) } else { // What an awful hack. This throws proper ordering out of the window, but there is no way to reproduce this better with strict layering of elements. // From the above commit it seems to be incomplete anyway... - pQAV->Draw(v4, flags, a2, a5, basepal, false); + pQAV->Draw(v4, flags, a2, a5, false); } } diff --git a/source/blood/src/nnexts.h b/source/blood/src/nnexts.h index e428264be..c3304e324 100644 --- a/source/blood/src/nnexts.h +++ b/source/blood/src/nnexts.h @@ -314,7 +314,7 @@ void playerDeactivateShrooms(PLAYER* pPlayer); QAV* playerQavSceneLoad(int qavId); void playerQavSceneProcess(PLAYER* pPlayer, QAVSCENE* pQavScene); void playerQavScenePlay(PLAYER* pPlayer); -void playerQavSceneDraw(PLAYER* pPlayer, int a2, double a3, double a4, int a5, int basepal); +void playerQavSceneDraw(PLAYER* pPlayer, int a2, double a3, double a4, int a5); void playerQavSceneReset(PLAYER* pPlayer); // ------------------------------------------------------------------------- // void callbackUniMissileBurst(int nSprite); diff --git a/source/blood/src/qav.cpp b/source/blood/src/qav.cpp index 33bbe6c51..e54f6200e 100644 --- a/source/blood/src/qav.cpp +++ b/source/blood/src/qav.cpp @@ -46,7 +46,7 @@ int qavRegisterClient(void(*pClient)(int, void *)) return nClients++; } -void DrawFrame(double x, double y, TILE_FRAME *pTile, int stat, int shade, int palnum, int basepal, bool to3dview) +void DrawFrame(double x, double y, TILE_FRAME *pTile, int stat, int shade, int palnum, bool to3dview) { stat |= pTile->stat; x += pTile->x; @@ -61,7 +61,7 @@ void DrawFrame(double x, double y, TILE_FRAME *pTile, int stat, int shade, int p double alpha = (stat & RS_TRANS1)? glblend[0].def[!!(stat & RS_TRANS2)].alpha : 1.; int pin = (stat & kQavOrientationLeft)? -1 : (stat & RS_ALIGN_R)? 1:0; if (palnum <= 0) palnum = pTile->palnum; - auto translation = TRANSLATION(Translation_Remap + basepal, palnum); + auto translation = TRANSLATION(Translation_Remap, palnum); bool topleft = !!(stat & RS_TOPLEFT); bool xflip = !!(stat & 0x100); // repurposed flag @@ -83,7 +83,7 @@ void DrawFrame(double x, double y, TILE_FRAME *pTile, int stat, int shade, int p } } -void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, int basepal, bool to3dview) +void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool to3dview) { dassert(ticksPerFrame > 0); int nFrame = ticks / ticksPerFrame; @@ -92,13 +92,13 @@ void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, i for (int i = 0; i < 8; i++) { if (pFrame->tiles[i].picnum > 0) - DrawFrame(x, y, &pFrame->tiles[i], stat, shade, palnum, basepal, to3dview); + DrawFrame(x, y, &pFrame->tiles[i], stat, shade, palnum, to3dview); } } -void QAV::Draw(int ticks, int stat, int shade, int palnum, int basepal, bool to3dview) +void QAV::Draw(int ticks, int stat, int shade, int palnum, bool to3dview) { - Draw(x, y, ticks, stat, shade, palnum, basepal, to3dview); + Draw(x, y, ticks, stat, shade, palnum, to3dview); } diff --git a/source/blood/src/qav.h b/source/blood/src/qav.h index a169f3737..f67ffbfdf 100644 --- a/source/blood/src/qav.h +++ b/source/blood/src/qav.h @@ -81,8 +81,8 @@ struct QAV //SPRITE *pSprite; // 1c char pad3[4]; // 20 FRAMEINFO frames[1]; // 24 - void Draw(int ticks, int stat, int shade, int palnum, int basepal, bool inviewport); - void Draw(double x, double y, int ticks, int stat, int shade, int palnum, int basepal, bool inviewport); + void Draw(int ticks, int stat, int shade, int palnum, bool in3dscene); + void Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool in3dscene); void Play(int, int, int, void *); void Preload(void); void Precache(void); diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index 72bb6f2cb..7bf6c2724 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -1117,7 +1117,7 @@ void viewDrawScreen(bool sceneonly) if (IsPlayerSprite(gMe->pSprite) && pPSprite->hand == 1) { //static int lastClock; - gChoke.sub_84110(160, zn, 0); + gChoke.sub_84110(160, zn); //if ((gGameClock % 5) == 0 && gGameClock != lastClock) //{ // gChoke.swayV(pPSprite); diff --git a/source/blood/src/weapon.cpp b/source/blood/src/weapon.cpp index 1a8dbe8b3..2372b9b2c 100644 --- a/source/blood/src/weapon.cpp +++ b/source/blood/src/weapon.cpp @@ -232,7 +232,7 @@ void WeaponPrecache(void) } } -void WeaponDraw(PLAYER *pPlayer, int a2, double a3, double a4, int a5, int basepal) +void WeaponDraw(PLAYER *pPlayer, int a2, double a3, double a4, int a5) { dassert(pPlayer != NULL); if (pPlayer->weaponQav == -1) @@ -252,7 +252,7 @@ void WeaponDraw(PLAYER *pPlayer, int a2, double a3, double a4, int a5, int basep a2 = -128; flags |= 1; } - pQAV->Draw(a3, a4, v4, flags, a2, a5, basepal, true); + pQAV->Draw(a3, a4, v4, flags, a2, a5, true); } void WeaponPlay(PLAYER *pPlayer) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index efd1cc418..0954aecbb 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -2053,9 +2053,7 @@ void twod_rotatesprite(F2DDrawer *twod, int32_t sx, int32_t sy, int32_t z, int16 // todo: check for hires replacements. // The weapon drawer needs to use the global base palette. - if (twod == &twodpsp) dg.mTranslationId = TRANSLATION(Translation_Remap + curbasepal, dapalnum); - else if (basepal == 0 && dapalnum == 0 && pic) dg.mTranslationId = 0; - else dg.mTranslationId = TRANSLATION(Translation_Remap + basepal, dapalnum); + dg.mTranslationId = TRANSLATION(Translation_Remap + basepal, dapalnum); dg.mVertCount = 4; dg.mVertIndex = (int)twod->mVertices.Reserve(4); diff --git a/source/core/textures/buildtiles.cpp b/source/core/textures/buildtiles.cpp index 28b6c0f8a..47e8ab1bd 100644 --- a/source/core/textures/buildtiles.cpp +++ b/source/core/textures/buildtiles.cpp @@ -993,9 +993,6 @@ void tileCopySection(int tilenum1, int sx1, int sy1, int xsiz, int ysiz, int til // //=========================================================================== -// Test CVARs. -CVAR(Int, fixpalette, -1, 0) -CVAR(Int, fixpalswap, -1, 0) bool PickTexture(int picnum, FGameTexture* tex, int paletteid, TexturePick& pick) { @@ -1004,13 +1001,11 @@ bool PickTexture(int picnum, FGameTexture* tex, int paletteid, TexturePick& pick if (!tex->isValid() || tex->GetTexelWidth() <= 0 || tex->GetTexelHeight() <= 0) return false; pick.texture = tex; - int curbasepal = GetTranslationType(paletteid) - Translation_Remap; - int palette = GetTranslationIndex(paletteid); - int usepalette = fixpalette >= 0 ? fixpalette : curbasepal; - int usepalswap = fixpalswap >= 0 ? fixpalswap : palette; + int usepalette = GetTranslationType(paletteid) - Translation_Remap; + int usepalswap = GetTranslationIndex(paletteid); int TextureType = hw_int_useindexedcolortextures && picnum >= 0 ? TT_INDEXED : TT_TRUECOLOR; - pick.translation = TRANSLATION(usepalette + Translation_Remap, usepalswap); + pick.translation = paletteid; pick.basepalTint = 0xffffff; auto& h = lookups.tables[usepalswap]; diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 675064695..49d649c8f 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -2546,7 +2546,6 @@ void DoTitle() if (videoGetRenderMode() == REND_CLASSIC) FadeOut(0); - SetOverscan(BASEPAL); GrabPalette(); PlayLocalSound(StaticSound[59], 0, true, CHANF_UI); diff --git a/source/exhumed/src/init.cpp b/source/exhumed/src/init.cpp index 3080b27ae..639568ff5 100644 --- a/source/exhumed/src/init.cpp +++ b/source/exhumed/src/init.cpp @@ -184,8 +184,6 @@ uint8_t LoadLevel(int nMap) void ResetEngine() { - SetOverscan(BASEPAL); - EraseScreen(-1); resettiming(); diff --git a/source/exhumed/src/light.cpp b/source/exhumed/src/light.cpp index 07e897861..81879c3e9 100644 --- a/source/exhumed/src/light.cpp +++ b/source/exhumed/src/light.cpp @@ -62,22 +62,6 @@ int bGreenPal = 0; // keep a local copy of the palette that would have been sent to the VGA display adapter uint8_t vgaPalette[768]; - -void MyLoadPalette() -{ - //int hFile = kopen4load("PALETTE.DAT", 1); - //if (hFile == -1) - //{ - // Printf("Error reading palette 'PALETTE.DAT'\n"); - // return; - //} - // - //kread(hFile, kenpal, sizeof(kenpal)); - //kclose(hFile); - videoSetPalette(BASEPAL); - SetOverscan(BASEPAL); -} - int LoadPaletteLookups() { uint8_t buffer[256*64]; @@ -163,10 +147,6 @@ void WaitVBL() void GrabPalette() { - SetOverscan(BASEPAL); - - videoSetPalette(BASEPAL); - nPalDiff = 0; nPalDelay = 0; @@ -183,7 +163,6 @@ void BlackOut() void RestorePalette() { - videoSetPalette(BASEPAL); videoTintBlood(0, 0, 0); } @@ -368,17 +347,5 @@ void TintPalette(int r, int g, int b) nPalDelay = 0; } -void DoOverscanSet(short someval) -{ -} -// unused -void SetWhiteOverscan() -{ - -} - -void SetOverscan(int id) -{ -} END_PS_NS diff --git a/source/exhumed/src/light.h b/source/exhumed/src/light.h index 5c65fae0e..b1bc2f74b 100644 --- a/source/exhumed/src/light.h +++ b/source/exhumed/src/light.h @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS -void MyLoadPalette(); int LoadPaletteLookups(); void WaitVBL(); void SetGreenPal(); @@ -33,9 +32,6 @@ void FadeToWhite(); int HavePLURemap(); uint8_t RemapPLU(uint8_t pal); -extern void DoOverscanSet(short someval); -void SetOverscan(int id); - //extern unsigned char kenpal[]; extern short overscanindex; diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index 56d962363..9d5f9b843 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -242,7 +242,6 @@ static void analyzesprites() void ResetView() { //videoSetGameMode(gSetup.fullscreen, gSetup.xdim, gSetup.ydim, gSetup.bpp, 0); - DoOverscanSet(overscanindex); EraseScreen(overscanindex); //videoUpdatePalette(0, 256); #ifdef USE_OPENGL diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 52f71eb48..e1cd1d9b3 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -430,7 +430,6 @@ int GameInterface::app_main() enginePostInit(); videoInit(); updateviewport(); - videoSetPalette(BASEPAL); app_loop(); return 0; } diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index a5744c7fb..93aa667d9 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -50,8 +50,22 @@ // //=========================================================================== +// Test CVARs. +#ifdef _DEBUG +CVAR(Int, fixpalette, -1, 0) +CVAR(Int, fixpalswap, -1, 0) +#endif + bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sampler) { +#ifdef _DEBUG + int basepal = GetTranslationType(paletteid) - Translation_Remap; + int translation = GetTranslationIndex(paletteid); + int usepalette = fixpalette >= 0 ? fixpalette : basepal; + int usepalswap = fixpalswap >= 0 ? fixpalswap : translation; + paletteid = TRANSLATION(Translation_Remap + usepalette, usepalswap); +#endif + TexturePick texpick; if (!PickTexture(picnum, tex, paletteid, texpick)) return false; diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 7a778fe27..1e6e5e05d 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -1207,7 +1207,6 @@ void LogoLevel(void) twod->ClearScreen(); videoNextPage(); - videoSetPalette(BASEPAL); // put up a blank screen while loading