From 010f41a3aad3719b1e5d4d8ce157a5d9b0077b44 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 1 May 2022 14:03:49 +0200 Subject: [PATCH] - load the hex font as early as possible. --- src/common/fonts/hexfont.cpp | 24 +++++++++++++++++------- src/d_main.cpp | 17 ++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/common/fonts/hexfont.cpp b/src/common/fonts/hexfont.cpp index e2bdbff7ad..8b50427f4e 100644 --- a/src/common/fonts/hexfont.cpp +++ b/src/common/fonts/hexfont.cpp @@ -58,11 +58,12 @@ struct HexDataSource // //========================================================================== - void ParseDefinition(int lumpnum) + void ParseDefinition(FResourceLump* font) { FScanner sc; - sc.OpenLumpNum(lumpnum); + auto data = font->Lock(); + sc.OpenMem("newconsolefont.hex", (const char*)data, font->Size()); sc.SetCMode(true); glyphdata.Push(0); // ensure that index 0 can be used as 'not present'. while (sc.GetString()) @@ -96,6 +97,7 @@ struct HexDataSource lumb = i * 255 / 17; SmallPal[i] = PalEntry(255, lumb, lumb, lumb); } + font->Unlock(); } }; @@ -400,7 +402,7 @@ public: FFont *CreateHexLumpFont (const char *fontname, int lump) { - if (hexdata.FirstChar == INT_MAX) hexdata.ParseDefinition(lump); + assert(hexdata.FirstChar != INT_MAX); return new FHexFont(fontname, lump); } @@ -412,7 +414,7 @@ FFont *CreateHexLumpFont (const char *fontname, int lump) FFont *CreateHexLumpFont2(const char *fontname, int lump) { - if (hexdata.FirstChar == INT_MAX) hexdata.ParseDefinition(lump); + assert(hexdata.FirstChar != INT_MAX); return new FHexFont2(fontname, lump); } @@ -424,8 +426,7 @@ FFont *CreateHexLumpFont2(const char *fontname, int lump) uint8_t* GetHexChar(int codepoint) { - auto lump = fileSystem.CheckNumForFullName("newconsolefont.hex", 0); // This is always loaded from gzdoom.pk3 to prevent overriding it with incomplete replacements. - if (hexdata.FirstChar == INT_MAX) hexdata.ParseDefinition(lump); + assert(hexdata.FirstChar != INT_MAX); if (hexdata.glyphmap[codepoint] > 0) { @@ -433,4 +434,13 @@ uint8_t* GetHexChar(int codepoint) return &hexdata.glyphdata[offset]; } return nullptr; -} \ No newline at end of file +} + +void LoadHexFont(const char* filename) +{ + auto resf = FResourceFile::OpenResourceFile(filename); + if (resf == nullptr) I_FatalError("Unable to open %s", filename); + auto hexfont = resf->FindLump("newconsolefont.hex"); + if (hexfont == nullptr) I_FatalError("Unable to find newconsolefont.hex in %s", filename); + hexdata.ParseDefinition(hexfont); +} diff --git a/src/d_main.cpp b/src/d_main.cpp index 9d2f1f0cbd..47fcc7d1d8 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -173,6 +173,7 @@ void FreeSBarInfoScript(); void I_UpdateWindowTitle(); void S_ParseMusInfo(); void D_GrabCVarDefaults(); +void LoadHexFont(const char* filename); // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- @@ -3474,6 +3475,15 @@ static int D_DoomMain_Internal (void) std::set_new_handler(NewFailure); const char *batchout = Args->CheckValue("-errorlog"); + // [RH] Make sure zdoom.pk3 is always loaded, + // as it contains magic stuff we need. + wad = BaseFileSearch(BASEWAD, NULL, true, GameConfig); + if (wad == NULL) + { + I_FatalError("Cannot find " BASEWAD); + } + LoadHexFont(wad); // load hex font early so we have it during startup. + C_InitConsole(80*8, 25*8, false); I_DetectOS(); @@ -3503,13 +3513,6 @@ static int D_DoomMain_Internal (void) extern void D_ConfirmSendStats(); D_ConfirmSendStats(); - // [RH] Make sure zdoom.pk3 is always loaded, - // as it contains magic stuff we need. - wad = BaseFileSearch (BASEWAD, NULL, true, GameConfig); - if (wad == NULL) - { - I_FatalError ("Cannot find " BASEWAD); - } FString basewad = wad; FString optionalwad = BaseFileSearch(OPTIONALWAD, NULL, true, GameConfig);