From 2f672da7bae2a825390903ce3c18591f3fbed0ac Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 17:01:56 +0200 Subject: [PATCH] - the basics for creating font objects for the in-game bitmap fonts. Definitions were added to RedNukem frontend for testing, not used yet. --- source/common/fonts/font.cpp | 18 ++++++++++- source/common/fonts/v_font.h | 3 +- source/core/2d/drawparms.h | 2 +- source/core/2d/v_2ddrawer.cpp | 2 +- source/core/2d/v_draw.cpp | 4 +-- source/core/2d/v_drawtext.cpp | 6 ++-- source/rr/src/game.cpp | 5 +++ source/rr/src/sbar.cpp | 60 +++++++++++++++++++++++++++++++++-- 8 files changed, 89 insertions(+), 11 deletions(-) diff --git a/source/common/fonts/font.cpp b/source/common/fonts/font.cpp index 4f38b4794..d45e7a157 100644 --- a/source/common/fonts/font.cpp +++ b/source/common/fonts/font.cpp @@ -68,7 +68,7 @@ // //========================================================================== -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) +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, GlyphSet *baseGlyphs) { int i; FTextureID lump; @@ -185,6 +185,22 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla } else { + if (baseGlyphs) + { + // First insert everything from the given glyph set. + GlyphSet::Iterator it(*baseGlyphs); + GlyphSet::Pair* pair; + while (it.NextPair(pair)) + { + if (pair->Value && pair->Value->GetTexelWidth() > 0 && pair->Value->GetTexelHeight() > 0) + { + auto position = pair->Key; + if (position < minchar) minchar = position; + if (position > maxchar) maxchar = position; + charMap.Insert(position, pair->Value); + } + } + } if (nametemplate != nullptr) { if (!iwadonly) diff --git a/source/common/fonts/v_font.h b/source/common/fonts/v_font.h index 74d47d3da..59c87c125 100644 --- a/source/common/fonts/v_font.h +++ b/source/common/fonts/v_font.h @@ -78,6 +78,7 @@ enum EColorRange : int extern int NumTextColors; +using GlyphSet = TMap; class FFont { @@ -94,7 +95,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, bool doomtemplate = 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, GlyphSet *baseGlpyphs = nullptr); virtual ~FFont (); virtual FTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const; diff --git a/source/core/2d/drawparms.h b/source/core/2d/drawparms.h index 2f3c59ca6..afe34a126 100644 --- a/source/core/2d/drawparms.h +++ b/source/core/2d/drawparms.h @@ -149,7 +149,7 @@ struct DrawParms double top; double left; float Alpha; - int remap; + int TranslationId; PalEntry fillcolor; PalEntry colorOverlay; PalEntry color; diff --git a/source/core/2d/v_2ddrawer.cpp b/source/core/2d/v_2ddrawer.cpp index 3c9919a61..1d2eef0c3 100644 --- a/source/core/2d/v_2ddrawer.cpp +++ b/source/core/2d/v_2ddrawer.cpp @@ -261,7 +261,7 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms) dg.mVertCount = 4; dg.mTexture = img; - dg.mRemapIndex = parms.remap; + dg.mRemapIndex = parms.TranslationId; SetStyle(img, parms, vertexcolor, dg); u1 = parms.srcx; diff --git a/source/core/2d/v_draw.cpp b/source/core/2d/v_draw.cpp index 849e60b3a..62018b459 100644 --- a/source/core/2d/v_draw.cpp +++ b/source/core/2d/v_draw.cpp @@ -262,7 +262,7 @@ bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, Va_Li parms->burn = false; parms->monospace = EMonospacing::Off; parms->spacing = 0; - parms->remap = -1; + parms->TranslationId = -1; // Parse the tag list for attributes. (For floating point attributes, // consider that the C ABI dictates that all floats be promoted to @@ -412,7 +412,7 @@ bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, Va_Li break; case DTA_TranslationIndex: - parms->remap = ListGetInt(tags); + parms->TranslationId = ListGetInt(tags); break; case DTA_ColorOverlay: diff --git a/source/core/2d/v_drawtext.cpp b/source/core/2d/v_drawtext.cpp index a86629496..52dcb7b58 100644 --- a/source/core/2d/v_drawtext.cpp +++ b/source/core/2d/v_drawtext.cpp @@ -102,7 +102,7 @@ void DrawChar (F2DDrawer* drawer, FFont *font, int normalcolor, double x, double return; } PalEntry color = 0xffffffff; - parms.remap = font->GetColorTranslation((EColorRange)normalcolor, &color); + parms.TranslationId = redirected? -1 : font->GetColorTranslation((EColorRange)normalcolor, &color); parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255); drawer->AddTexture(pic, parms); } @@ -140,7 +140,7 @@ void DrawTextCommon(F2DDrawer* drawer, FFont *font, int normalcolor, double x, d PalEntry colorparm = parms.color; PalEntry color = 0xffffffff; - parms.remap = font->GetColorTranslation((EColorRange)normalcolor, &color); + parms.TranslationId = font->GetColorTranslation((EColorRange)normalcolor, &color); parms.color = PalEntry(colorparm.a, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255); kerning = font->GetDefaultKerning(); @@ -167,7 +167,7 @@ void DrawTextCommon(F2DDrawer* drawer, FFont *font, int normalcolor, double x, d EColorRange newcolor = V_ParseFontColor(ch, normalcolor, boldcolor); if (newcolor != CR_UNDEFINED) { - parms.remap = font->GetColorTranslation(newcolor, &color); + parms.TranslationId = font->GetColorTranslation(newcolor, &color); parms.color = PalEntry(colorparm.a, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255); currentcolor = newcolor; } diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 8e57538e6..73609f896 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -6752,6 +6752,8 @@ void G_PostCreateGameState(void) A_InitEnemyFlags(); } +void InitFonts(); + static void G_Startup(void) { int32_t i; @@ -6813,6 +6815,8 @@ static void G_Startup(void) if (TileFiles.artLoadFiles("tiles%03i.art") < 0) G_GameExit("Failed loading art."); + InitFonts(); + // Make the fullscreen nuke logo background non-fullbright. Has to be // after dynamic tile remapping (from C_Compile) and loading tiles. picanm[LOADSCREEN].sf |= PICANM_NOFULLBRIGHT_BIT; @@ -7020,6 +7024,7 @@ static const char* actions[] = { "Toggle_Crouch", // This is the last one used by EDuke32. }; + int GameInterface::app_main() { buttonMap.SetButtons(actions, NUM_ACTIONS); diff --git a/source/rr/src/sbar.cpp b/source/rr/src/sbar.cpp index 9520f4d75..a4e6026c8 100644 --- a/source/rr/src/sbar.cpp +++ b/source/rr/src/sbar.cpp @@ -21,12 +21,68 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //------------------------------------------------------------------------- #include "ns.h" // Must come before everything else! +#include "v_font.h" #include "duke3d.h" #include "compat.h" #include "sbar.h" BEGIN_RR_NS + +void InitFonts() +{ + GlyphSet fontdata; + + // Small font + for (int i = 0; i < 95; i++) + { + auto tile = TileFiles.GetTile(STARTALPHANUM + i); + if (tile && tile->GetTexelWidth() > 0 && tile->GetTexelHeight() > 0) + fontdata.Insert('!' + i, tile); + } + SmallFont = new ::FFont("SmallFont", nullptr, "defsmallfont", 0, 0, 0, -1, -1, false, false, false, &fontdata); + fontdata.Clear(); + + // Big font + + // This font is VERY messy... + fontdata.Insert('_', TileFiles.GetTile(BIGALPHANUM - 11)); + fontdata.Insert('-', TileFiles.GetTile(BIGALPHANUM - 11)); + for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, TileFiles.GetTile(BIGALPHANUM - 10 + i)); + for (int i = 0; i < 26; i++) fontdata.Insert('A' + i, TileFiles.GetTile(BIGALPHANUM + i)); + fontdata.Insert('.', TileFiles.GetTile(BIGPERIOD)); + fontdata.Insert(',', TileFiles.GetTile(BIGCOMMA)); + fontdata.Insert('!', TileFiles.GetTile(BIGX_)); + fontdata.Insert('?', TileFiles.GetTile(BIGQ)); + fontdata.Insert(';', TileFiles.GetTile(BIGSEMI)); + fontdata.Insert(':', TileFiles.GetTile(BIGCOLIN)); + fontdata.Insert('\\', TileFiles.GetTile(BIGALPHANUM + 68)); + fontdata.Insert('/', TileFiles.GetTile(BIGALPHANUM + 68)); + fontdata.Insert('%', TileFiles.GetTile(BIGALPHANUM + 69)); + fontdata.Insert('`', TileFiles.GetTile(BIGAPPOS)); + fontdata.Insert('"', TileFiles.GetTile(BIGAPPOS)); + fontdata.Insert('\'', TileFiles.GetTile(BIGAPPOS)); + BigFont = new ::FFont("BigFont", nullptr, "defbigfont", 0, 0, 0, -1, -1, false, false, false, &fontdata); + fontdata.Clear(); + + // Tiny font + for (int i = 0; i < 95; i++) + { + auto tile = TileFiles.GetTile(MINIFONT + i); + if (tile && tile->GetTexelWidth() > 0 && tile->GetTexelHeight() > 0) + fontdata.Insert('!' + i, tile); + } + SmallFont2 = new ::FFont("SmallFont2", nullptr, "defsmallfont2", 0, 0, 0, -1, -1, false, false, false, &fontdata); + fontdata.Clear(); + + // SBAR index font + for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, TileFiles.GetTile(THREEBYFIVE + i)); + fontdata.Insert(':', TileFiles.GetTile(THREEBYFIVE + 10)); + fontdata.Insert('/', TileFiles.GetTile(THREEBYFIVE + 11)); + new ::FFont("IndexFont", nullptr, nullptr, 0, 0, 0, -1, -1, false, false, false, &fontdata); + +} + static int32_t sbarx(int32_t x) { if (ud.screen_size == 4) return sbarsc(x<<16); @@ -42,7 +98,7 @@ static int32_t sbarxr(int32_t x) static int32_t sbary(int32_t y) { if (hud_position == 1 && ud.screen_size == 4 && ud.althud == 1) return sbarsc(y << 16); - else return (200<<16) - sbarsc(200<<16) + sbarsc(y<<16); + else return (100<<16) - sbarsc(200<<16) + sbarsc(y<<16); } int32_t sbarx16(int32_t x) @@ -67,7 +123,7 @@ static int32_t sbarxr16(int32_t x) int32_t sbary16(int32_t y) { - return (200<<16) - sbarsc(200<<16) + sbarsc(y); + return (100<<16) - sbarsc(200<<16) + sbarsc(y); } static void G_PatchStatusBar(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t aspectCorrect = 1)