diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3ffec49fa0..ab1cd4e9b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1088,10 +1088,10 @@ set (PCH_SOURCES common/textures/texturemanager.cpp common/textures/multipatchtexturebuilder.cpp common/textures/skyboxtexture.cpp + common/textures/animtexture.cpp common/textures/formats/automaptexture.cpp common/textures/formats/brightmaptexture.cpp common/textures/formats/buildtexture.cpp - common/textures/formats/canvastexture.cpp common/textures/formats/ddstexture.cpp common/textures/formats/flattexture.cpp common/textures/formats/fontchars.cpp diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp new file mode 100644 index 0000000000..4dbf2d111a --- /dev/null +++ b/src/common/textures/animtexture.cpp @@ -0,0 +1,116 @@ +/* +** animtexture.cpp +** +**--------------------------------------------------------------------------- +** Copyright 2020 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ +#include "animtexture.h" +#include "bitmap.h" + +//========================================================================== +// +// +// +//========================================================================== + +void AnimTexture::SetFrameSize(int width, int height) +{ + FTexture::SetSize(width, height); + Image.Resize(width*height); +} + +void AnimTexture::SetFrame(const uint8_t *palette, const void *data_) +{ + memcpy(Palette, palette, 768); + memcpy(Image.Data(), data_, Width * Height); + SystemTextures.Clean(true, true); +} + +//=========================================================================== +// +// FPNGTexture::CopyPixels +// +//=========================================================================== + +FBitmap AnimTexture::GetBgraBitmap(const PalEntry* remap, int* trans) +{ + FBitmap bmp; + + bmp.Create(Width, Height); + + auto spix = Image.Data(); + auto dpix = bmp.GetPixels(); + for (int i = 0; i < Width * Height; i++) + { + int p = i * 4; + int index = spix[i]; + dpix[p + 0] = Palette[index*3+2]; + dpix[p + 1] = Palette[index*3+1]; + dpix[p + 2] = Palette[index*3]; + dpix[p + 3] = 255; + } + return bmp; +} + +//========================================================================== +// +// +// +//========================================================================== + +AnimTextures::AnimTextures() +{ + active = 1; + tex[0] = new AnimTexture; + tex[1] = new AnimTexture; +} + +AnimTextures::~AnimTextures() +{ + delete tex[0]; + delete tex[1]; +} + +void AnimTextures::SetSize(int width, int height) +{ + tex[0]->SetFrameSize(width, height); + tex[1]->SetFrameSize(width, height); +} + +void AnimTextures::SetFrame(const uint8_t *palette, const void* data) +{ + active ^= 1; + tex[active]->SetFrame(palette, data); +} + +FTexture * AnimTextures::GetFrame() +{ + return tex[active]; +} diff --git a/src/common/textures/animtexture.h b/src/common/textures/animtexture.h new file mode 100644 index 0000000000..668671a9db --- /dev/null +++ b/src/common/textures/animtexture.h @@ -0,0 +1,28 @@ +#pragma once + +#include "textures.h" + + +class AnimTexture : public FTexture +{ + uint8_t Palette[768]; + TArray Image; +public: + AnimTexture() = default; + void SetFrameSize(int width, int height); + void SetFrame(const uint8_t *palette, const void* data); + virtual FBitmap GetBgraBitmap(const PalEntry* remap, int* trans) override; +}; + +class AnimTextures +{ + int active; + AnimTexture *tex[2]; + +public: + AnimTextures(); + ~AnimTextures(); + void SetSize(int width, int height); + void SetFrame(const uint8_t *palette, const void* data); + FTexture *GetFrame(); +}; diff --git a/src/common/textures/formats/canvastexture.cpp b/src/common/textures/formats/canvastexture.cpp deleted file mode 100644 index d2ddcea959..0000000000 --- a/src/common/textures/formats/canvastexture.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -** canvastexture.cpp -** Texture class for camera textures -** -**--------------------------------------------------------------------------- -** Copyright 2004-2006 Randy Heit -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions -** are met: -** -** 1. Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in the -** documentation and/or other materials provided with the distribution. -** 3. The name of the author may not be used to endorse or promote products -** derived from this software without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -**--------------------------------------------------------------------------- -** -** -*/ - -#include "doomtype.h" -#include "v_video.h" - - diff --git a/src/common/textures/imagetexture.cpp b/src/common/textures/imagetexture.cpp index 3586acae0f..95960a2930 100644 --- a/src/common/textures/imagetexture.cpp +++ b/src/common/textures/imagetexture.cpp @@ -33,7 +33,6 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "templates.h" diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index a048e7a86f..3380968b02 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -35,8 +35,8 @@ */ #include -#include "doomtype.h" #include "files.h" +#include "printf.h" #include "filesystem.h" #include "engineerrors.h" #include "bitmap.h" diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index 0d8a274147..2c212643f3 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -20,7 +20,6 @@ //-------------------------------------------------------------------------- // -#include "doomtype.h" #include "filesystem.h" #include "textures.h" #include "skyboxtexture.h" diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 112375ac90..fb75e854c3 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -34,7 +34,7 @@ ** */ -#include "doomtype.h" +#include "printf.h" #include "files.h" #include "filesystem.h" #include "templates.h" diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 5d95de5409..66a196a310 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -34,9 +34,9 @@ ** */ -#include "doomtype.h" -#include "doomstat.h" #include "filesystem.h" +#include "printf.h" +#include "c_cvars.h" #include "templates.h" #include "gstrings.h" #include "textures.h" @@ -44,6 +44,7 @@ #include "c_dispatch.h" #include "sc_man.h" #include "image.h" +#include "vectors.h" #include "formats/multipatchtexture.h" FTextureManager TexMan; @@ -61,7 +62,7 @@ FTextureManager::FTextureManager () for (int i = 0; i < 2048; ++i) { - sintable[i] = short(sin(i*(M_PI / 1024)) * 16384); + sintable[i] = short(sin(i*(pi::pi() / 1024)) * 16384); } } diff --git a/src/gamedata/fonts/font.cpp b/src/gamedata/fonts/font.cpp index d91cbb7438..98cbda51f1 100644 --- a/src/gamedata/fonts/font.cpp +++ b/src/gamedata/fonts/font.cpp @@ -41,25 +41,20 @@ #include #include "templates.h" -#include "doomtype.h" #include "m_swap.h" #include "v_font.h" -#include "v_video.h" +#include "printf.h" +#include "textures.h" #include "filesystem.h" -#include "gi.h" #include "cmdlib.h" #include "sc_man.h" -#include "hu_stuff.h" #include "gstrings.h" -#include "v_text.h" -#include "vm.h" #include "image.h" #include "utf8.h" #include "myiswalpha.h" #include "fontchars.h" #include "multipatchtexture.h" #include "texturemanager.h" -#include "r_translate.h" #include "fontinternals.h" @@ -73,13 +68,12 @@ // //========================================================================== -FFont::FFont (const char *name, const char *nametemplate, const char *filetemplate, int lfirst, int lcount, int start, int fdlump, int spacewidth, bool notranslate, bool iwadonly) +FFont::FFont (const char *name, const char *nametemplate, const char *filetemplate, int lfirst, int lcount, int start, int fdlump, int spacewidth, bool notranslate, bool iwadonly, bool doomtemplate) { int i; FTextureID lump; char buffer[12]; int maxyoffs; - bool doomtemplate = (nametemplate && (gameinfo.gametype & GAME_DoomChex)) ? strncmp (nametemplate, "STCFN", 5) == 0 : false; DVector2 Scale = { 1, 1 }; noTranslate = notranslate; @@ -207,8 +201,10 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla // Because a lot of wads with their own font seem to foolishly // copy STCFN121 and make it a '|' themselves, wads must // provide STCFN120 (x) and STCFN122 (z) for STCFN121 to load as a 'y'. - if (!TexMan.CheckForTexture("STCFN120", ETextureType::MiscPatch).isValid() || - !TexMan.CheckForTexture("STCFN122", ETextureType::MiscPatch).isValid()) + FStringf c120("%s120", nametemplate); + FStringf c122("%s122", nametemplate); + if (!TexMan.CheckForTexture(c120, ETextureType::MiscPatch).isValid() || + !TexMan.CheckForTexture(c122, ETextureType::MiscPatch).isValid()) { // insert the incorrectly named '|' graphic in its correct position. position = 124; @@ -799,7 +795,7 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity remap.Palette[j] = GPalette.BaseColors[identity[j]] | MAKEARGB(255, 0, 0, 0); } } - Translations.Push(GPalette.StoreTranslation(TRANSLATION_Font, &remap)); + Translations.Push(GPalette.StoreTranslation(TRANSLATION_Internal, &remap)); } else { @@ -839,7 +835,7 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity remap.Palette[j] = PalEntry(255,r,g,b); } if (post) post(&remap); - Translations.Push(GPalette.StoreTranslation(TRANSLATION_Font, &remap)); + Translations.Push(GPalette.StoreTranslation(TRANSLATION_Internal, &remap)); // Advance to the next color range. while (parmstart[1].RangeStart > parmstart[0].RangeEnd) @@ -1155,7 +1151,7 @@ int FFont::GetMaxAscender(const uint8_t* string) const auto ctex = GetChar(chr, CR_UNTRANSLATED, nullptr); if (ctex) { - auto offs = int(ctex->GetScaledTopOffset(0)); + auto offs = int(ctex->GetDisplayTopOffset()); if (offs > retval) retval = offs; } } @@ -1271,7 +1267,7 @@ void FFont::FixXMoves() } if (Chars[i].OriginalPic) { - int ofs = Chars[i].OriginalPic->GetScaledTopOffset(0); + int ofs = Chars[i].OriginalPic->GetDisplayTopOffset(); if (ofs > Displacement) Displacement = ofs; } } diff --git a/src/gamedata/fonts/hexfont.cpp b/src/gamedata/fonts/hexfont.cpp index a6a6d088fd..58a9a5cf4d 100644 --- a/src/gamedata/fonts/hexfont.cpp +++ b/src/gamedata/fonts/hexfont.cpp @@ -40,7 +40,6 @@ #include "utf8.h" #include "sc_man.h" #include "texturemanager.h" -#include "r_translate.h" #include "fontinternals.h" @@ -329,7 +328,7 @@ public: Next = FirstFont; FirstFont = this; FontHeight = 18; - SpaceWidth = 10; + SpaceWidth = 9; GlobalKerning = -1; translateUntranslated = true; @@ -342,7 +341,7 @@ public: // //========================================================================== - void LoadTranslations() + void LoadTranslations() override { const int spacing = 9; double luminosity[256]; diff --git a/src/gamedata/fonts/singlelumpfont.cpp b/src/gamedata/fonts/singlelumpfont.cpp index 70ebb08b53..4b4fc3d9ab 100644 --- a/src/gamedata/fonts/singlelumpfont.cpp +++ b/src/gamedata/fonts/singlelumpfont.cpp @@ -374,7 +374,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data) if (destSize < 0) { i += FirstChar; - I_FatalError ("Overflow decompressing char %d (%c) of %s", i, i, FontName.GetChars()); + I_Error ("Overflow decompressing char %d (%c) of %s", i, i, FontName.GetChars()); } } @@ -434,7 +434,7 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data) } if (LastChar < FirstChar) { - I_FatalError("BMF font defines no characters"); + I_Error("BMF font defines no characters"); } count = LastChar - FirstChar + 1; Chars.Resize(count); @@ -624,7 +624,7 @@ void FSingleLumpFont::FixupPalette (uint8_t *identity, double *luminosity, const int g = palette[1]; int b = palette[2]; double lum = r*0.299 + g*0.587 + b*0.114; - identity[i] = ColorMatcher.Pick (r, g, b); + identity[i] = ColorMatcher.Pick(r, g, b); luminosity[i] = lum; out_palette[i].r = r; out_palette[i].g = g; diff --git a/src/gamedata/fonts/v_font.cpp b/src/gamedata/fonts/v_font.cpp index a0639ed10c..f3067fea70 100644 --- a/src/gamedata/fonts/v_font.cpp +++ b/src/gamedata/fonts/v_font.cpp @@ -40,22 +40,19 @@ #include #include "templates.h" -#include "doomtype.h" #include "m_swap.h" #include "v_font.h" -#include "v_video.h" #include "filesystem.h" -#include "gi.h" #include "cmdlib.h" #include "sc_man.h" -#include "hu_stuff.h" #include "gstrings.h" -#include "v_text.h" -#include "vm.h" #include "image.h" #include "utf8.h" #include "fontchars.h" +#include "textures.h" #include "texturemanager.h" +#include "printf.h" +#include "palentry.h" #include "fontinternals.h" @@ -63,6 +60,16 @@ #define DEFAULT_LOG_COLOR PalEntry(223,223,223) +// +// Globally visible constants. +// +#define HU_FONTSTART uint8_t('!') // the first font characters +#define HU_FONTEND uint8_t('\377') // the last font characters + +// Calculate # of glyphs in font. +#define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1) + + // TYPES ------------------------------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- @@ -655,6 +662,9 @@ EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int // // V_InitFonts // +// Fixme: This really needs to be a bit more flexible +// and less rigidly tied to the original game data. +// //========================================================================== void V_InitFonts() @@ -698,11 +708,11 @@ void V_InitFonts() if (wadfile > fileSystem.GetIwadNum()) { // The font has been replaced, so we need to create a copy of the original as well. - SmallFont = new FFont("SmallFont", "STCFN%.3d", nullptr, HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1); + SmallFont = new FFont("SmallFont", "STCFN%.3d", nullptr, HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, false, true); } else { - SmallFont = new FFont("SmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1); + SmallFont = new FFont("SmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, false, true); } } } @@ -751,7 +761,7 @@ void V_InitFonts() BigFont = V_GetFont("BigFont", "ZBIGFONT"); } - if (gameinfo.gametype & GAME_Raven) + if (fileSystem.CheckNumForName("FONTB_S") >= 0) { OriginalBigFont = new FFont("OriginalBigFont", "FONTB%02u", "defbigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true); } @@ -784,7 +794,7 @@ void V_InitFonts() } if (!(IntermissionFont = FFont::FindFont("IntermissionFont"))) { - if (gameinfo.gametype & GAME_DoomChex) + if (fileSystem.CheckNumForName("WINUM0") >= 0) { IntermissionFont = FFont::FindFont("IntermissionFont_Doom"); } diff --git a/src/gamedata/fonts/v_font.h b/src/gamedata/fonts/v_font.h index 841add6d76..74d47d3da6 100644 --- a/src/gamedata/fonts/v_font.h +++ b/src/gamedata/fonts/v_font.h @@ -34,9 +34,10 @@ #ifndef __V_FONT_H__ #define __V_FONT_H__ -#include "doomtype.h" #include "filesystem.h" #include "vectors.h" +#include "palentry.h" +#include "name.h" class DCanvas; class FTexture; @@ -93,7 +94,7 @@ public: Custom }; - FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false); + FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false); virtual ~FFont (); virtual FTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 9003b53e31..cdaed2e9b1 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -32,15 +32,6 @@ struct event_t; class player_t; -// -// Globally visible constants. -// -#define HU_FONTSTART uint8_t('!') // the first font characters -#define HU_FONTEND uint8_t('\377') // the last font characters - -// Calculate # of glyphs in font. -#define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1) - // // Chat routines //