- backport some fixes from Raze - mostly redundant includes.

This commit is contained in:
Christoph Oelckers 2020-04-11 19:10:22 +02:00
parent d586ffa79c
commit 2dcf63c57d
15 changed files with 190 additions and 89 deletions

View file

@ -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

View file

@ -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];
}

View file

@ -0,0 +1,28 @@
#pragma once
#include "textures.h"
class AnimTexture : public FTexture
{
uint8_t Palette[768];
TArray<uint8_t> 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();
};

View file

@ -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"

View file

@ -33,7 +33,6 @@
**
*/
#include "doomtype.h"
#include "files.h"
#include "filesystem.h"
#include "templates.h"

View file

@ -35,8 +35,8 @@
*/
#include <ctype.h>
#include "doomtype.h"
#include "files.h"
#include "printf.h"
#include "filesystem.h"
#include "engineerrors.h"
#include "bitmap.h"

View file

@ -20,7 +20,6 @@
//--------------------------------------------------------------------------
//
#include "doomtype.h"
#include "filesystem.h"
#include "textures.h"
#include "skyboxtexture.h"

View file

@ -34,7 +34,7 @@
**
*/
#include "doomtype.h"
#include "printf.h"
#include "files.h"
#include "filesystem.h"
#include "templates.h"

View file

@ -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);
}
}

View file

@ -41,25 +41,20 @@
#include <math.h>
#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;
}
}

View file

@ -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];

View file

@ -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;

View file

@ -40,22 +40,19 @@
#include <math.h>
#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");
}

View file

@ -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;

View file

@ -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
//