From 5f54eac297b94b22f1e658317d5f3dcfd2755860 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 10 Nov 2020 22:07:45 +0100 Subject: [PATCH] - made palette loader part of the game interface. This gets rid of the Blood 'replace' hook for thus. --- source/blood/CMakeLists.txt | 1 - source/blood/src/blood.cpp | 68 ++++++++++++++++++++++ source/blood/src/blood.h | 1 + source/blood/src/map2d.cpp | 37 ------------ source/blood/src/misc.h | 2 - source/blood/src/replace.cpp | 1 - source/blood/src/screen.cpp | 109 ----------------------------------- source/build/include/build.h | 1 - source/build/src/engine.cpp | 12 +--- source/core/gamecontrol.cpp | 5 ++ source/core/gamestruct.h | 1 + 11 files changed, 77 insertions(+), 161 deletions(-) delete mode 100644 source/blood/src/map2d.cpp delete mode 100644 source/blood/src/screen.cpp diff --git a/source/blood/CMakeLists.txt b/source/blood/CMakeLists.txt index 78f88be81..bc17cb20f 100644 --- a/source/blood/CMakeLists.txt +++ b/source/blood/CMakeLists.txt @@ -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 diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 019aba8aa..3334a8186 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -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(); diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index c1bbc48ce..e8d704ae0 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -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; diff --git a/source/blood/src/map2d.cpp b/source/blood/src/map2d.cpp deleted file mode 100644 index d0bd4ff4e..000000000 --- a/source/blood/src/map2d.cpp +++ /dev/null @@ -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 diff --git a/source/blood/src/misc.h b/source/blood/src/misc.h index d25f692c2..d6e942ca1 100644 --- a/source/blood/src/misc.h +++ b/source/blood/src/misc.h @@ -142,6 +142,4 @@ void tilePrecacheTile(int nTile, int nType, HitList& hits); char tileGetSurfType(int hit); -void scrLoadPalette(void); - END_BLD_NS diff --git a/source/blood/src/replace.cpp b/source/blood/src/replace.cpp index fc74d7950..663c00368 100644 --- a/source/blood/src/replace.cpp +++ b/source/blood/src/replace.cpp @@ -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; diff --git a/source/blood/src/screen.cpp b/source/blood/src/screen.cpp deleted file mode 100644 index 05e111496..000000000 --- a/source/blood/src/screen.cpp +++ /dev/null @@ -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 -#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 diff --git a/source/build/include/build.h b/source/build/include/build.h index 56a5669d0..33b788329 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -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); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 3b90f2075..d3c135ad6 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -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(); diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index e75f84080..9b370ed00 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1235,6 +1235,11 @@ CCMD(taunt) } } + +void GameInterface::loadPalette() +{ + paletteLoadFromDisk(); +} //--------------------------------------------------------------------------- // // diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index e7fd4bf3f..13024630a 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -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();