- made palette loader part of the game interface.

This gets rid of the Blood 'replace' hook for thus.
This commit is contained in:
Christoph Oelckers 2020-11-10 22:07:45 +01:00
parent 71e70f8d15
commit 5f54eac297
11 changed files with 77 additions and 161 deletions

View file

@ -56,7 +56,6 @@ set( PCH_SOURCES
src/qav.cpp
src/replace.cpp
src/sbar.cpp
src/screen.cpp
src/sectorfx.cpp
src/seq.cpp
src/sfx.cpp

View file

@ -407,6 +407,74 @@ static void SetTileNames()
void ReadAllRFS();
void GameInterface::loadPalette(void)
{
// in nearly typical Blood fashion it had to use an inverse of the original translucency settings...
static glblend_t const bloodglblend =
{
{
{ 1.f / 3.f, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 },
{ 2.f / 3.f, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 },
},
};
static const char* PLU[15] = {
"NORMAL.PLU",
"SATURATE.PLU",
"BEAST.PLU",
"TOMMY.PLU",
"SPIDER3.PLU",
"GRAY.PLU",
"GRAYISH.PLU",
"SPIDER1.PLU",
"SPIDER2.PLU",
"FLAME.PLU",
"COLD.PLU",
"P1.PLU",
"P2.PLU",
"P3.PLU",
"P4.PLU"
};
static const char* PAL[5] = {
"BLOOD.PAL",
"WATER.PAL",
"BEAST.PAL",
"SEWER.PAL",
"INVULN1.PAL"
};
for (auto& x : glblend) x = bloodglblend;
for (int i = 0; i < 5; i++)
{
auto pal = fileSystem.LoadFile(PAL[i]);
if (pal.Size() < 768) I_FatalError("%s: file too small", PAL[i]);
paletteSetColorTable(i, pal.Data(), false, false);
}
numshades = 64;
for (int i = 0; i < MAXPALOOKUPS; i++)
{
int lump = i < 15 ? fileSystem.FindFile(PLU[i]) : fileSystem.FindResource(i, "PLU");
if (lump < 0)
{
if (i < 15) I_FatalError("%s: file not found", PLU[i]);
else continue;
}
auto data = fileSystem.GetFileData(lump);
if (data.Size() != 64 * 256)
{
if (i < 15) I_FatalError("%s: Incorrect PLU size", PLU[i]);
else continue;
}
lookups.setTable(i, data.Data());
}
lookups.setFadeColor(1, 255, 255, 255);
paletteloaded = PALETTE_SHADE | PALETTE_TRANSLUC | PALETTE_MAIN;
}
void GameInterface::app_init()
{
InitCheats();

View file

@ -71,6 +71,7 @@ struct GameInterface : ::GameInterface
{
const char* Name() override { return "Blood"; }
void app_init() override;
void loadPalette() override;
void clearlocalinputstate() override;
bool GenerateSavePic() override;
void FreeLevelData() override;

View file

@ -1,37 +0,0 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 Nuke.YKT
This file is part of NBlood.
NBlood 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.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
#include "build.h"
#include "mmulti.h"
#include "common_game.h"
#include "levels.h"
#include "view.h"
#include "v_2ddrawer.h"
#include "v_draw.h"
#include "statusbar.h"
BEGIN_BLD_NS
END_BLD_NS

View file

@ -142,6 +142,4 @@ void tilePrecacheTile(int nTile, int nType, HitList& hits);
char tileGetSurfType(int hit);
void scrLoadPalette(void);
END_BLD_NS

View file

@ -80,7 +80,6 @@ int32_t qchangespritestat(int16_t nSprite, int16_t nStatus);
void HookReplaceFunctions(void)
{
animateoffs_replace = qanimateoffs;
paletteLoadFromDisk_replace = scrLoadPalette;
getpalookup_replace = qgetpalookup;
initspritelists_replace = qinitspritelists;
insertsprite_replace = qinsertsprite;

View file

@ -1,109 +0,0 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 Nuke.YKT
This file is part of NBlood.
NBlood 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.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
#include <string.h>
#include "build.h"
#include "common_game.h"
#include "globals.h"
#include "v_video.h"
#include "view.h"
BEGIN_BLD_NS
const char * PLU[15] = {
"NORMAL.PLU",
"SATURATE.PLU",
"BEAST.PLU",
"TOMMY.PLU",
"SPIDER3.PLU",
"GRAY.PLU",
"GRAYISH.PLU",
"SPIDER1.PLU",
"SPIDER2.PLU",
"FLAME.PLU",
"COLD.PLU",
"P1.PLU",
"P2.PLU",
"P3.PLU",
"P4.PLU"
};
const char *PAL[5] = {
"BLOOD.PAL",
"WATER.PAL",
"BEAST.PAL",
"SEWER.PAL",
"INVULN1.PAL"
};
static void scrLoadPLUs(void)
{
// load lookup tables
for (int i = 0; i < MAXPALOOKUPS; i++)
{
int lump = i < 15 ? fileSystem.FindFile(PLU[i]) : fileSystem.FindResource(i, "PLU");
if (lump < 0)
{
if (i < 15) I_FatalError("%s.PLU not found", PLU[i]);
else continue;
}
auto data = fileSystem.GetFileData(lump);
if (data.Size() != 64 * 256)
I_FatalError("Incorrect PLU size");
lookups.setTable(i, data.Data());
}
lookups.setFadeColor(1, 255, 255, 255);
}
glblend_t const bloodglblend =
{
{
{ 1.f/3.f, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 },
{ 2.f/3.f, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 },
},
};
void scrLoadPalette(void)
{
for (auto& x : glblend)
x = bloodglblend;
paletteloaded = 0;
Printf("Loading palettes\n");
for (int i = 0; i < 5; i++)
{
auto pal = fileSystem.LoadFile(PAL[i]);
if (pal.Size() < 768) I_FatalError("%s: file too small", PAL[i]);
paletteSetColorTable(i, pal.Data(), false, false);
}
numshades = 64;
paletteloaded |= PALETTE_MAIN;
scrLoadPLUs();
paletteloaded |= PALETTE_SHADE | PALETTE_TRANSLUC;
}
END_BLD_NS

View file

@ -910,7 +910,6 @@ void markTileForPrecache(int tilenum, int palnum);
void precacheMarkedTiles();
extern int32_t(*animateoffs_replace)(int const tilenum, int fakevar);
extern void(*paletteLoadFromDisk_replace)(void);
extern int32_t(*getpalookup_replace)(int32_t davis, int32_t dashade);
extern void(*initspritelists_replace)(void);
extern int32_t(*insertsprite_replace)(int16_t sectnum, int16_t statnum);

View file

@ -29,6 +29,7 @@
#include "gamestate.h"
#include "inputstate.h"
#include "printf.h"
#include "gamecontrol.h"
#ifdef USE_OPENGL
# include "mdsprite.h"
@ -878,8 +879,6 @@ int32_t enginePreInit(void)
}
void (*paletteLoadFromDisk_replace)(void) = NULL; // replacement hook for Blood.
//
// initengine
//
@ -915,14 +914,7 @@ int32_t engineInit(void)
maxspritesonscreen = MAXSPRITESONSCREEN;
GPalette.Init(MAXPALOOKUPS + 1); // one slot for each translation, plus a separate one for the base palettes.
if (paletteLoadFromDisk_replace)
{
paletteLoadFromDisk_replace();
}
else
{
paletteLoadFromDisk();
}
gi->loadPalette();
#ifdef USE_OPENGL
if (!mdinited) mdinit();

View file

@ -1235,6 +1235,11 @@ CCMD(taunt)
}
}
void GameInterface::loadPalette()
{
paletteLoadFromDisk();
}
//---------------------------------------------------------------------------
//
//

View file

@ -50,6 +50,7 @@ struct GameInterface
virtual ~GameInterface() {}
virtual bool GenerateSavePic() { return false; }
virtual void app_init() = 0;
virtual void loadPalette();
virtual void clearlocalinputstate() {}
virtual void UpdateScreenSize() {}
virtual void FreeLevelData();