From ff6820aa92b441155fe5462cf5659adf234b8c98 Mon Sep 17 00:00:00 2001 From: nukeykt Date: Sun, 27 Oct 2019 22:53:20 +0900 Subject: [PATCH] Rework green palette and torch effects to not modify palookup array In other words make these effects polymost friendly --- source/exhumed/src/gun.cpp | 7 ++-- source/exhumed/src/light.cpp | 59 +++++++++++++++++++++++++++------ source/exhumed/src/light.h | 4 +++ source/exhumed/src/lighting.cpp | 32 +++++++++--------- source/exhumed/src/lighting.h | 2 ++ source/exhumed/src/sequence.cpp | 5 ++- source/exhumed/src/view.cpp | 37 +++++++++++++++++++++ 7 files changed, 117 insertions(+), 29 deletions(-) diff --git a/source/exhumed/src/gun.cpp b/source/exhumed/src/gun.cpp index 484109396..a366dfb1d 100644 --- a/source/exhumed/src/gun.cpp +++ b/source/exhumed/src/gun.cpp @@ -14,6 +14,7 @@ #include "snake.h" #include "grenade.h" #include "lighting.h" +#include "light.h" #include "input.h" #include "util.h" #include "anims.h" @@ -931,17 +932,19 @@ void DrawWeapons() int8_t nShade = sector[initsect].ceilingshade; int nDouble = nPlayerDouble[nLocalPlayer]; - int nPal = 0; + int nPal = kPalNormal; if (nDouble) { if (word_96E26) { - nPal = 5; + nPal = kPalRedBrite; } word_96E26 = word_96E26 == 0; } + nPal = RemapPLU(nPal); + int nVal = totalvel[nLocalPlayer] >> 1; // CHECKME - not & 0x7FF? diff --git a/source/exhumed/src/light.cpp b/source/exhumed/src/light.cpp index ca0202ce6..4c3b295e0 100644 --- a/source/exhumed/src/light.cpp +++ b/source/exhumed/src/light.cpp @@ -4,6 +4,7 @@ #include "exhumed.h" #include "view.h" #include "cd.h" +#include "lighting.h" #include #include #include @@ -28,7 +29,7 @@ const char *GradList[kMaxGrads] = { int rtint = 0; int gtint = 0; int btint = 0; -char *origpalookup[kMaxPalookups]; +//char *origpalookup[kMaxPalookups]; //unsigned char curpal[768]; //unsigned char kenpal[768]; palette_t *fadedestpal; @@ -36,6 +37,7 @@ palette_t *fadecurpal; short nPalDelay; short nPalDiff; short overscanindex; +int bGreenPal = 0; // keep a local copy of the palette that would have been sent to the VGA display adapter uint8_t vgaPalette[768]; @@ -77,7 +79,8 @@ int LoadPaletteLookups() paletteSetLookupTable(i, buffer); kclose(hFile); - origpalookup[i] = palookup[i]; + // origpalookup[i] = palookup[i]; + bGreenPal = 0; } return 1; @@ -85,20 +88,56 @@ int LoadPaletteLookups() void SetGreenPal() { - for (int i = 0; i < 12; i++) - { - palookup[i] = palookup[6]; - } - - palookup[5] = origpalookup[5]; + bGreenPal = 1; + // for (int i = 0; i < kMaxGrads; i++) + // { + // palookup[i] = palookup[6]; + // } + // + // palookup[5] = origpalookup[5]; } void RestoreGreenPal() { - for (int i = 0; i < 12; i++) + bGreenPal = 0; + // for (int i = 0; i < kMaxGrads; i++) + // { + // palookup[i] = origpalookup[i]; + // } +} + +int HavePLURemap() +{ + return bGreenPal || bTorch; +} + +uint8_t RemapPLU(uint8_t pal) +{ + if (bGreenPal) { - palookup[i] = origpalookup[i]; + if (pal != kPalRedBrite) + pal = kPalGreenBrite; + return pal; } + else if (bTorch) + { + switch (pal) + { + case kPalTorch: + pal = kPalNoTorch; + break; + case kPalNoTorch: + pal = kPalTorch; + break; + case kPalTorch2: + pal = kPalNoTorch2; + break; + case kPalNoTorch2: + pal = kPalTorch2; + break; + } + } + return pal; } void WaitVBL() diff --git a/source/exhumed/src/light.h b/source/exhumed/src/light.h index 753c7536d..ac036b30e 100644 --- a/source/exhumed/src/light.h +++ b/source/exhumed/src/light.h @@ -2,6 +2,8 @@ #ifndef __light_h__ #define __light_h__ +#include "compat.h" + void MyLoadPalette(); int LoadPaletteLookups(); void WaitVBL(); @@ -9,6 +11,8 @@ void SetGreenPal(); void RestoreGreenPal(); void FixPalette(); void FadeToWhite(); +int HavePLURemap(); +uint8_t RemapPLU(uint8_t pal); extern void DoOverscanSet(short someval); void SetOverscan(int id); diff --git a/source/exhumed/src/lighting.cpp b/source/exhumed/src/lighting.cpp index 36cfae8b8..e06ff7d5b 100644 --- a/source/exhumed/src/lighting.cpp +++ b/source/exhumed/src/lighting.cpp @@ -712,24 +712,24 @@ void SetTorch(int nPlayer, int bTorchOnOff) return; } - char *pTempPal = origpalookup[kPalTorch]; - palookup[kPalTorch] = palookup[kPalNoTorch]; - palookup[kPalNoTorch] = pTempPal; - - pTempPal = origpalookup[kPalTorch]; - origpalookup[kPalTorch] = origpalookup[kPalNoTorch]; - origpalookup[kPalNoTorch] = pTempPal; - - pTempPal = origpalookup[kPalTorch2]; - origpalookup[kPalTorch2] = origpalookup[kPalNoTorch2]; - origpalookup[kPalNoTorch2] = pTempPal; - - pTempPal = palookup[kPalTorch2]; - palookup[kPalNoTorch2] = palookup[kPalTorch2]; - palookup[kPalTorch2] = pTempPal; + // char *pTempPal = origpalookup[kPalTorch]; + // palookup[kPalTorch] = palookup[kPalNoTorch]; + // palookup[kPalNoTorch] = pTempPal; + // + // pTempPal = origpalookup[kPalTorch]; + // origpalookup[kPalTorch] = origpalookup[kPalNoTorch]; + // origpalookup[kPalNoTorch] = pTempPal; + // + // pTempPal = origpalookup[kPalTorch2]; + // origpalookup[kPalTorch2] = origpalookup[kPalNoTorch2]; + // origpalookup[kPalNoTorch2] = pTempPal; + // + // pTempPal = palookup[kPalTorch2]; + // palookup[kPalNoTorch2] = palookup[kPalTorch2]; + // palookup[kPalTorch2] = pTempPal; if (bTorchOnOff == 2) { - bTorch = bTorch == 0; + bTorch = !bTorch; } else { bTorch = bTorchOnOff; diff --git a/source/exhumed/src/lighting.h b/source/exhumed/src/lighting.h index 35e24c0ae..0d024570b 100644 --- a/source/exhumed/src/lighting.h +++ b/source/exhumed/src/lighting.h @@ -14,4 +14,6 @@ void BuildFlash(short nPlayer, short nSector, int nVal); void AddGlow(short nSector, int nVal); void AddFlicker(short nSector, int nVal); +extern short bTorch; + #endif \ No newline at end of file diff --git a/source/exhumed/src/sequence.cpp b/source/exhumed/src/sequence.cpp index 61e861b1f..134de073f 100644 --- a/source/exhumed/src/sequence.cpp +++ b/source/exhumed/src/sequence.cpp @@ -9,6 +9,7 @@ #include "move.h" #include "view.h" #include "init.h" +#include "light.h" #ifndef __WATCOMC__ #include #include // for printf @@ -333,6 +334,8 @@ void seq_DrawStatusSequence(short nSequence, uint16_t edx, short ebx) short nFrameBase = FrameBase[edx]; int16_t nFrameSize = FrameSize[edx]; + int const nPal = RemapPLU(kPalNormal); + while (1) { nFrameSize--; @@ -360,7 +363,7 @@ void seq_DrawStatusSequence(short nSequence, uint16_t edx, short ebx) nStat |= 0x2; // scale and clip to viewing window } - overwritesprite(laststatusx, laststatusy, laststatustile, 0, nStat, kPalNormal); + overwritesprite(laststatusx, laststatusy, laststatustile, 0, nStat, nPal); nFrameBase++; } } diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index ee0c25f36..af74a14bb 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -104,6 +104,8 @@ static void analyzesprites() pTSprite->shade = clamp(nShade, -128, 127); } + pTSprite->pal = RemapPLU(pTSprite->pal); + if (pSprite->statnum > 0) { runlist_SignalRun(pSprite->lotag - 1, nTSprite | 0x90000); @@ -371,6 +373,9 @@ void DrawView() if (nFreeze != 3) { + static uint8_t sectorFloorPal[MAXSECTORS]; + static uint8_t sectorCeilingPal[MAXSECTORS]; + static uint8_t wallPal[MAXWALLS]; int const viewingRange = viewingrange; if (r_usenewaspect) @@ -379,10 +384,42 @@ void DrawView() videoSetCorrectedAspect(); } + if (HavePLURemap()) + { + for (int i = 0; i < numsectors; i++) + { + sectorFloorPal[i] = sector[i].floorpal; + sectorCeilingPal[i] = sector[i].ceilingpal; + if (sector[i].floorpal != kPalRedBrite) + sector[i].floorpal = kPalGreenBrite; + if (sector[i].ceilingpal != kPalRedBrite) + sector[i].ceilingpal = kPalGreenBrite; + } + for (int i = 0; i < numwalls; i++) + { + wallPal[i] = wall[i].pal; + if (wall[i].pal != kPalRedBrite) + wall[i].pal = kPalGreenBrite; + } + } + drawrooms(nCamerax, nCameray, viewz, nCameraa, nCamerapan, nSector); analyzesprites(); renderDrawMasks(); + if (HavePLURemap()) + { + for (int i = 0; i < numsectors; i++) + { + sector[i].floorpal = sectorFloorPal[i]; + sector[i].ceilingpal = sectorCeilingPal[i]; + } + for (int i = 0; i < numwalls; i++) + { + wall[i].pal = wallPal[i]; + } + } + if (r_usenewaspect) { newaspect_enable = 0;