From b0ccd3a7dfd0e2cba76dffd5f143cff74d78b2c3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 29 May 2021 15:24:05 +0200 Subject: [PATCH] - moved Doom specific font init code out of the backend. --- src/common/fonts/v_font.cpp | 147 +----------------------------------- src/common/fonts/v_font.h | 2 + src/d_main.cpp | 2 + src/gamedata/doomfont.h | 147 ++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 145 deletions(-) create mode 100644 src/gamedata/doomfont.h diff --git a/src/common/fonts/v_font.cpp b/src/common/fonts/v_font.cpp index 8313b18e5..37dd1f46f 100644 --- a/src/common/fonts/v_font.cpp +++ b/src/common/fonts/v_font.cpp @@ -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() diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 0b17b77e1..99f8afb9f 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -133,6 +133,8 @@ public: int GetDisplacement() const { return Displacement; } static int GetLuminosity(uint32_t* colorsused, TArray& Luminosity, int* minlum = nullptr, int* maxlum = nullptr); + EFontType GetType() const { return Type; } + protected: FFont (int lump); diff --git a/src/d_main.cpp b/src/d_main.cpp index 6d5bf3063..007c1adce 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -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); diff --git a/src/gamedata/doomfont.h b/src/gamedata/doomfont.h new file mode 100644 index 000000000..c960a9b35 --- /dev/null +++ b/src/gamedata/doomfont.h @@ -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; +}