2019-11-20 16:21:32 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 sirlemonhead, Nuke.YKT
|
|
|
|
This file is part of PCExhumed.
|
|
|
|
PCExhumed is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-11-22 23:11:37 +00:00
|
|
|
#include "ns.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "light.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "exhumed.h"
|
|
|
|
#include "view.h"
|
|
|
|
#include "cd.h"
|
2019-10-27 13:53:20 +00:00
|
|
|
#include "lighting.h"
|
2019-12-31 21:53:03 +00:00
|
|
|
#include "../glbackend/glbackend.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
#define kMaxGrads 12
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
const char *GradList[kMaxGrads] = {
|
|
|
|
"normal.rmp",
|
|
|
|
"nodim.rmp",
|
|
|
|
"torch.rmp",
|
|
|
|
"notorch.rmp",
|
|
|
|
"brite.rmp",
|
|
|
|
"redbrite.rmp",
|
|
|
|
"grnbrite.rmp",
|
|
|
|
"normal.rmp",
|
|
|
|
"nodim.rmp",
|
|
|
|
"torch.rmp",
|
|
|
|
"notorch.rmp",
|
|
|
|
"brite.rmp"
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int rtint = 0;
|
|
|
|
int gtint = 0;
|
|
|
|
int btint = 0;
|
2019-10-27 13:53:20 +00:00
|
|
|
//char *origpalookup[kMaxPalookups];
|
2019-10-12 21:09:55 +00:00
|
|
|
//unsigned char curpal[768];
|
|
|
|
//unsigned char kenpal[768];
|
|
|
|
palette_t *fadedestpal;
|
|
|
|
palette_t *fadecurpal;
|
2019-08-26 03:59:14 +00:00
|
|
|
short nPalDelay;
|
|
|
|
short nPalDiff;
|
|
|
|
short overscanindex;
|
2019-10-27 13:53:20 +00:00
|
|
|
int bGreenPal = 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
// keep a local copy of the palette that would have been sent to the VGA display adapter
|
2019-08-31 07:47:15 +00:00
|
|
|
uint8_t vgaPalette[768];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MyLoadPalette()
|
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
//int hFile = kopen4load("PALETTE.DAT", 1);
|
|
|
|
//if (hFile == -1)
|
|
|
|
//{
|
2020-04-11 21:45:45 +00:00
|
|
|
// Printf("Error reading palette 'PALETTE.DAT'\n");
|
2019-10-12 21:09:55 +00:00
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//kread(hFile, kenpal, sizeof(kenpal));
|
|
|
|
//kclose(hFile);
|
|
|
|
videoSetPalette(0, BASEPAL, 0);
|
|
|
|
SetOverscan(BASEPAL);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int LoadPaletteLookups()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
uint8_t buffer[256*64];
|
2019-08-27 06:08:18 +00:00
|
|
|
numshades = 64;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
for (int i = 0; i < kMaxGrads; i++)
|
|
|
|
{
|
2019-12-13 20:01:14 +00:00
|
|
|
auto hFile = fileSystem.OpenFileReader(GradList[i], 1);
|
2019-11-24 12:59:36 +00:00
|
|
|
if (!hFile.isOpen())
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-04-11 21:45:45 +00:00
|
|
|
Printf("Error reading palette lookup '%s'\n", GradList[i]);
|
2019-08-31 07:47:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-24 12:59:36 +00:00
|
|
|
hFile.Read(buffer, 256*64);
|
2019-08-31 10:36:26 +00:00
|
|
|
// TODO: dumb hack
|
|
|
|
if (palookup[i])
|
|
|
|
ALIGNED_FREE_AND_NULL(palookup[i]);
|
2019-08-31 07:47:15 +00:00
|
|
|
paletteSetLookupTable(i, buffer);
|
2019-11-24 12:59:36 +00:00
|
|
|
|
2019-10-27 13:53:20 +00:00
|
|
|
// origpalookup[i] = palookup[i];
|
|
|
|
bGreenPal = 0;
|
2019-10-29 14:01:30 +00:00
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
2019-12-31 21:53:03 +00:00
|
|
|
// These 3 tables do not have normal gradients. The others work without adjustment.
|
|
|
|
// Other changes than altering the fog gradient are not necessary.
|
|
|
|
shadediv[kPalTorch] = shadediv[kPalTorch2] = 1 / 20.f;
|
|
|
|
shadediv[kPalNoTorch] = shadediv[kPalNoTorch2] = 0.25f;
|
|
|
|
shadediv[kPalBrite] = shadediv[kPalBrite] = 1 / 128.f;
|
2019-10-29 14:01:30 +00:00
|
|
|
#endif
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
return 1;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetGreenPal()
|
|
|
|
{
|
2019-10-27 13:53:20 +00:00
|
|
|
bGreenPal = 1;
|
|
|
|
// for (int i = 0; i < kMaxGrads; i++)
|
|
|
|
// {
|
|
|
|
// palookup[i] = palookup[6];
|
|
|
|
// }
|
2019-11-20 16:21:32 +00:00
|
|
|
//
|
2019-10-27 13:53:20 +00:00
|
|
|
// palookup[5] = origpalookup[5];
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreGreenPal()
|
|
|
|
{
|
2019-10-27 13:53:20 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (pal != kPalRedBrite)
|
|
|
|
pal = kPalGreenBrite;
|
|
|
|
}
|
|
|
|
else if (bTorch)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-10-27 13:53:20 +00:00
|
|
|
switch (pal)
|
|
|
|
{
|
|
|
|
case kPalTorch:
|
|
|
|
pal = kPalNoTorch;
|
|
|
|
break;
|
|
|
|
case kPalNoTorch:
|
|
|
|
pal = kPalTorch;
|
|
|
|
break;
|
|
|
|
case kPalTorch2:
|
|
|
|
pal = kPalNoTorch2;
|
|
|
|
break;
|
|
|
|
case kPalNoTorch2:
|
|
|
|
pal = kPalTorch2;
|
|
|
|
break;
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-10-27 13:53:20 +00:00
|
|
|
return pal;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaitVBL()
|
|
|
|
{
|
|
|
|
#ifdef __WATCOMC__
|
2019-08-31 07:47:15 +00:00
|
|
|
while (!(inp(0x3da) & 8));
|
2019-08-26 03:59:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
//void MySetPalette(unsigned char *palette)
|
|
|
|
//{
|
|
|
|
// WaitVBL();
|
|
|
|
//
|
|
|
|
// // TODO
|
|
|
|
// kensetpalette(palette);
|
|
|
|
//
|
|
|
|
// memcpy(vgaPalette, palette, sizeof(vgaPalette));
|
|
|
|
//}
|
|
|
|
|
|
|
|
//void GetCurPal(unsigned char *palette)
|
|
|
|
//{
|
|
|
|
// if (!palette) {
|
|
|
|
// memcpy(curpal, vgaPalette, sizeof(curpal));
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// memcpy(palette, vgaPalette, sizeof(curpal));
|
|
|
|
// }
|
|
|
|
//}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
void GrabPalette()
|
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
SetOverscan(BASEPAL);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-01-26 09:58:00 +00:00
|
|
|
videoSetPalette(0, BASEPAL, 0);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
nPalDiff = 0;
|
|
|
|
nPalDelay = 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
btint = 0;
|
|
|
|
gtint = 0;
|
|
|
|
rtint = 0;
|
2019-10-12 22:27:12 +00:00
|
|
|
videoTintBlood(0, 0, 0);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BlackOut()
|
|
|
|
{
|
2019-11-22 08:13:27 +00:00
|
|
|
g_lastpalettesum = -1;
|
2019-10-12 22:27:12 +00:00
|
|
|
videoTintBlood(0, 0, 0);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestorePalette()
|
|
|
|
{
|
2020-01-26 09:58:00 +00:00
|
|
|
videoSetPalette(0, BASEPAL, 0);
|
2019-10-12 22:27:12 +00:00
|
|
|
videoTintBlood(0, 0, 0);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaitTicks(int nTicks)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (htimer)
|
|
|
|
{
|
2019-09-06 05:18:12 +00:00
|
|
|
nTicks += (int)totalclock;
|
|
|
|
while (nTicks > (int)totalclock) { HandleAsync(); }
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (nTicks > 0) {
|
|
|
|
nTicks--;
|
|
|
|
WaitVBL();
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// unused
|
|
|
|
void DoFadeToRed()
|
|
|
|
{
|
2020-03-29 14:59:49 +00:00
|
|
|
// fixme
|
|
|
|
videoTintBlood(-255, -255, -255);
|
|
|
|
videoNextPage();
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FadeToWhite()
|
|
|
|
{
|
2020-03-29 14:59:49 +00:00
|
|
|
// fixme
|
|
|
|
videoTintBlood(255, 255, 255);
|
|
|
|
videoNextPage();
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FadeOut(int bFadeMusic)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (bFadeMusic) {
|
|
|
|
StartfadeCDaudio();
|
|
|
|
}
|
|
|
|
|
2019-10-12 22:27:12 +00:00
|
|
|
|
2020-03-29 14:59:49 +00:00
|
|
|
videoTintBlood(-255, -255, -255);
|
|
|
|
videoNextPage();
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (bFadeMusic) {
|
|
|
|
while (StepFadeCDaudio() != 0) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
EraseScreen(overscanindex);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StartFadeIn()
|
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
//fadedestpal = curpalette;
|
|
|
|
//fadecurpal = curpal;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DoFadeIn()
|
|
|
|
{
|
2020-03-29 14:59:49 +00:00
|
|
|
paletteSetColorTable(curbasepal, basepaltable[BASEPAL]);
|
|
|
|
videoSetPalette(0, curbasepal, 0);
|
|
|
|
videoNextPage();
|
|
|
|
return 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FadeIn()
|
|
|
|
{
|
2020-03-29 14:59:49 +00:00
|
|
|
videoSetPalette(0, BASEPAL, 0);
|
|
|
|
videoNextPage();
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void FixPalette()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (!nPalDiff) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nPalDelay > 0)
|
|
|
|
{
|
|
|
|
nPalDelay--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nPalDelay = 5;
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
nPalDiff -= 20;
|
|
|
|
gtint -= 20;
|
|
|
|
rtint -= 20;
|
2019-10-12 21:40:48 +00:00
|
|
|
btint -= 20;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (gtint < 0) {
|
|
|
|
gtint = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtint < 0) {
|
|
|
|
rtint = 0;
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:40:48 +00:00
|
|
|
if (btint < 0) {
|
|
|
|
btint = 0;
|
|
|
|
}
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nPalDiff < 0) {
|
|
|
|
nPalDiff = 0;
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:40:48 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
if (videoGetRenderMode() >= REND_POLYMOST) videoTintBlood(rtint, gtint, btint);
|
|
|
|
else
|
|
|
|
#endif
|
2019-11-22 08:13:27 +00:00
|
|
|
{
|
2019-12-25 23:21:04 +00:00
|
|
|
|
|
|
|
//videoUpdatePalette(0, 256);
|
2019-11-22 08:13:27 +00:00
|
|
|
g_lastpalettesum = -1;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TintPalette(int r, int g, int b)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (bCamera) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
// range limit R between 20 and 255 if positive
|
|
|
|
if (r > 255)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
r = 255;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
if (r && r < 20) {
|
|
|
|
r = 20;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
// range limit G between 20 and 255 if positive
|
|
|
|
if (g > 255)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
g = 255;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
if (g && g < 20) {
|
|
|
|
g = 20;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
// range limit B between 20 and 255 if positive
|
|
|
|
if (b > 255)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
b = 255;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-12 21:09:55 +00:00
|
|
|
if (b && b < 20) {
|
|
|
|
b = 20;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// loc_17EFA
|
2019-10-12 21:09:55 +00:00
|
|
|
if (g && gtint > 32) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtint += g;
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
if (r && rtint > 256) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtint += r;
|
|
|
|
|
2019-10-12 21:40:48 +00:00
|
|
|
btint += b;
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
// do not modify r, g or b variables from this point on
|
|
|
|
int nVal;
|
|
|
|
|
|
|
|
// loc_17F49
|
2019-10-12 21:09:55 +00:00
|
|
|
if (klabs(r) > klabs(g)) {
|
|
|
|
nVal = klabs(r);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-10-12 21:09:55 +00:00
|
|
|
nVal = klabs(g);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
if (nVal < klabs(b)) {
|
|
|
|
nVal = klabs(b);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nPalDiff += nVal;
|
|
|
|
|
2020-03-29 14:59:49 +00:00
|
|
|
videoTintBlood(rtint, gtint, btint);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
nPalDelay = 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoOverscanSet(short someval)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// unused
|
|
|
|
void SetWhiteOverscan()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
void SetOverscan(int id)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|