- moved Doom specific font init code out of the backend.

This commit is contained in:
Christoph Oelckers 2021-05-29 15:24:05 +02:00
parent d9db8984af
commit b0ccd3a7df
4 changed files with 153 additions and 145 deletions

View file

@ -60,16 +60,6 @@
#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 --------------------------------------------
@ -158,7 +148,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
}
if (folderdata.Size() > 0)
{
font = new FFont(name, nullptr, name, HU_FONTSTART, HU_FONTSIZE, 1, -1);
font = new FFont(name, nullptr, name, 0, 0, 1, -1);
if (translationsLoaded) font->LoadTranslations();
return font;
}
@ -860,140 +850,7 @@ void V_InitFonts()
NewConsoleFont = CreateHexLumpFont("NewConsoleFont", lump);
NewSmallFont = CreateHexLumpFont2("NewSmallFont", lump);
CurrentConsoleFont = NewConsoleFont;
// load the heads-up font
if (!(SmallFont = V_GetFont("SmallFont", "SMALLFNT")))
{
if (fileSystem.CheckNumForName("FONTA_S") >= 0)
{
int wadfile = -1;
auto a = fileSystem.CheckNumForName("FONTA33", ns_graphics);
if (a != -1) wadfile = fileSystem.GetFileContainer(a);
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", "FONTA%02u", nullptr, HU_FONTSTART, HU_FONTSIZE, 1, -1);
SmallFont->SetCursor('[');
}
else
{
SmallFont = new FFont("SmallFont", "FONTA%02u", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, 1, -1);
SmallFont->SetCursor('[');
}
}
else if (fileSystem.CheckNumForName("STCFN033", ns_graphics) >= 0)
{
int wadfile = -1;
auto a = fileSystem.CheckNumForName("STCFN065", ns_graphics);
if (a != -1) wadfile = fileSystem.GetFileContainer(a);
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, -1, false, false, true);
}
else
{
SmallFont = new FFont("SmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, false, true);
}
}
}
// Create the original small font as a fallback for incomplete definitions.
if (fileSystem.CheckNumForName("FONTA_S") >= 0)
{
OriginalSmallFont = new FFont("OriginalSmallFont", "FONTA%02u", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true);
OriginalSmallFont->SetCursor('[');
}
else if (fileSystem.CheckNumForName("STCFN033", ns_graphics) >= 0)
{
OriginalSmallFont = new FFont("OriginalSmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, true);
}
if (!(SmallFont2 = V_GetFont("SmallFont2"))) // Only used by Strife
{
if (fileSystem.CheckNumForName("STBFN033", ns_graphics) >= 0)
{
SmallFont2 = new FFont("SmallFont2", "STBFN%.3d", "defsmallfont2", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1);
}
}
//This must be read before BigFont so that it can be properly substituted.
BigUpper = V_GetFont("BigUpper");
if (!(BigFont = V_GetFont("BigFont")))
{
if (fileSystem.CheckNumForName("FONTB_S") >= 0)
{
BigFont = new FFont("BigFont", "FONTB%02u", "defbigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1);
}
}
if (!BigFont)
{
// Load the generic fallback if no BigFont is found.
BigFont = V_GetFont("BigFont", "ZBIGFONT");
}
if (fileSystem.CheckNumForName("FONTB_S") >= 0)
{
OriginalBigFont = new FFont("OriginalBigFont", "FONTB%02u", "defbigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true);
}
else
{
OriginalBigFont = new FFont("OriginalBigFont", nullptr, "bigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true);
}
// let PWAD BIGFONTs override the stock BIGUPPER font. (This check needs to be made smarter.)
if (BigUpper && BigFont->Type != FFont::Folder && BigUpper->Type == FFont::Folder)
{
delete BigUpper;
BigUpper = BigFont;
}
if (BigUpper == nullptr)
{
BigUpper = BigFont;
}
if (!(ConFont = V_GetFont("ConsoleFont", "CONFONT")))
{
ConFont = SmallFont;
}
if (!(IntermissionFont = FFont::FindFont("IntermissionFont")))
{
if (TexMan.CheckForTexture("WINUM0", ETextureType::MiscPatch).isValid())
{
IntermissionFont = FFont::FindFont("IntermissionFont_Doom");
}
if (IntermissionFont == nullptr)
{
IntermissionFont = BigFont;
}
}
// This can only happen if gzdoom.pk3 is corrupted. ConFont should always be present.
if (ConFont == nullptr)
{
I_FatalError("Console font not found.");
}
// SmallFont and SmallFont2 have no default provided by the engine. BigFont only has in non-Raven games.
if (OriginalSmallFont == nullptr)
{
OriginalSmallFont = ConFont;
}
if (SmallFont == nullptr)
{
SmallFont = OriginalSmallFont;
}
if (SmallFont2 == nullptr)
{
SmallFont2 = SmallFont;
}
if (BigFont == nullptr)
{
BigFont = OriginalBigFont;
}
AlternativeSmallFont = OriginalSmallFont;
AlternativeBigFont = OriginalBigFont;
ConFont = V_GetFont("ConsoleFont", "CONFONT");
}
void V_LoadTranslations()

View file

@ -133,6 +133,8 @@ public:
int GetDisplacement() const { return Displacement; }
static int GetLuminosity(uint32_t* colorsused, TArray<double>& Luminosity, int* minlum = nullptr, int* maxlum = nullptr);
EFontType GetType() const { return Type; }
protected:
FFont (int lump);

View file

@ -117,6 +117,7 @@
#include "texturemanager.h"
#include "hw_clock.h"
#include "hwrenderer/scene/hw_drawinfo.h"
#include "doomfont.h"
#ifdef __unix__
#include "i_system.h" // for SHARE_DIR
@ -3409,6 +3410,7 @@ static int D_DoomMain_Internal (void)
StartScreen->Progress();
V_InitFonts();
InitDoomFonts();
V_LoadTranslations();
UpdateGenericUI(false);

147
src/gamedata/doomfont.h Normal file
View file

@ -0,0 +1,147 @@
//
// 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)
void InitDoomFonts()
{
// load the heads-up font
if (!(SmallFont = V_GetFont("SmallFont", "SMALLFNT")))
{
if (fileSystem.CheckNumForName("FONTA_S") >= 0)
{
int wadfile = -1;
auto a = fileSystem.CheckNumForName("FONTA33", ns_graphics);
if (a != -1) wadfile = fileSystem.GetFileContainer(a);
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", "FONTA%02u", nullptr, HU_FONTSTART, HU_FONTSIZE, 1, -1);
SmallFont->SetCursor('[');
}
else
{
SmallFont = new FFont("SmallFont", "FONTA%02u", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, 1, -1);
SmallFont->SetCursor('[');
}
}
else if (fileSystem.CheckNumForName("STCFN033", ns_graphics) >= 0)
{
int wadfile = -1;
auto a = fileSystem.CheckNumForName("STCFN065", ns_graphics);
if (a != -1) wadfile = fileSystem.GetFileContainer(a);
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, -1, false, false, true);
}
else
{
SmallFont = new FFont("SmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, false, true);
}
}
}
// Create the original small font as a fallback for incomplete definitions.
if (fileSystem.CheckNumForName("FONTA_S") >= 0)
{
OriginalSmallFont = new FFont("OriginalSmallFont", "FONTA%02u", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true);
OriginalSmallFont->SetCursor('[');
}
else if (fileSystem.CheckNumForName("STCFN033", ns_graphics) >= 0)
{
OriginalSmallFont = new FFont("OriginalSmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, true);
}
if (!(SmallFont2 = V_GetFont("SmallFont2"))) // Only used by Strife
{
if (fileSystem.CheckNumForName("STBFN033", ns_graphics) >= 0)
{
SmallFont2 = new FFont("SmallFont2", "STBFN%.3d", "defsmallfont2", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1);
}
}
//This must be read before BigFont so that it can be properly substituted.
BigUpper = V_GetFont("BigUpper");
if (!(BigFont = V_GetFont("BigFont")))
{
if (fileSystem.CheckNumForName("FONTB_S") >= 0)
{
BigFont = new FFont("BigFont", "FONTB%02u", "defbigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1);
}
}
if (!BigFont)
{
// Load the generic fallback if no BigFont is found.
BigFont = V_GetFont("BigFont", "ZBIGFONT");
}
if (fileSystem.CheckNumForName("FONTB_S") >= 0)
{
OriginalBigFont = new FFont("OriginalBigFont", "FONTB%02u", "defbigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true);
}
else
{
OriginalBigFont = new FFont("OriginalBigFont", nullptr, "bigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true);
}
// let PWAD BIGFONTs override the stock BIGUPPER font. (This check needs to be made smarter.)
if (BigUpper && BigFont->GetType() != FFont::Folder && BigUpper->GetType() == FFont::Folder)
{
delete BigUpper;
BigUpper = BigFont;
}
if (BigUpper == nullptr)
{
BigUpper = BigFont;
}
if (!ConFont)
{
ConFont = SmallFont;
}
if (!(IntermissionFont = FFont::FindFont("IntermissionFont")))
{
if (TexMan.CheckForTexture("WINUM0", ETextureType::MiscPatch).isValid())
{
IntermissionFont = FFont::FindFont("IntermissionFont_Doom");
}
if (IntermissionFont == nullptr)
{
IntermissionFont = BigFont;
}
}
// This can only happen if gzdoom.pk3 is corrupted. ConFont should always be present.
if (ConFont == nullptr)
{
I_FatalError("Console font not found.");
}
// SmallFont and SmallFont2 have no default provided by the engine. BigFont only has in non-Raven games.
if (OriginalSmallFont == nullptr)
{
OriginalSmallFont = ConFont;
}
if (SmallFont == nullptr)
{
SmallFont = OriginalSmallFont;
}
if (SmallFont2 == nullptr)
{
SmallFont2 = SmallFont;
}
if (BigFont == nullptr)
{
BigFont = OriginalBigFont;
}
AlternativeSmallFont = OriginalSmallFont;
AlternativeBigFont = OriginalBigFont;
}