- Blood font refactoring.

This commit is contained in:
Christoph Oelckers 2020-07-31 21:05:09 +02:00
parent 5bae2fcef5
commit 7bf3d5186f
9 changed files with 65 additions and 109 deletions

View file

@ -248,13 +248,6 @@ void PreloadTiles(void)
int skyTile = -1; int skyTile = -1;
memset(gotpic,0,sizeof(gotpic)); memset(gotpic,0,sizeof(gotpic));
// Fonts // Fonts
for (int i = 0; i < kFontNum; i++)
{
for (int j = 0; j < 96; j++)
{
tilePrecacheTile(gFont[i].tile + j, 0);
}
}
for (int i = 0; i < numsectors; i++) for (int i = 0; i < numsectors; i++)
{ {
tilePrecacheTile(sector[i].floorpicnum, 0); tilePrecacheTile(sector[i].floorpicnum, 0);
@ -976,7 +969,7 @@ static void gameTicker()
static void drawBackground() static void drawBackground()
{ {
twod->ClearScreen(); twod->ClearScreen();
DrawTexture(twod, tileGetTexture(2518), 0, 0, DTA_FullscreenEx, 3, TAG_DONE); DrawTexture(twod, tileGetTexture(2518, true), 0, 0, DTA_FullscreenEx, 3, TAG_DONE);
if (gQuitRequest && !gQuitGame) if (gQuitRequest && !gQuitGame)
netBroadcastMyLogoff(gQuitRequest == 2); netBroadcastMyLogoff(gQuitRequest == 2);
} }

View file

@ -25,20 +25,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "build.h" #include "build.h"
#include "compat.h" #include "compat.h"
#include "common_game.h"
#include "blood.h"
#include "globals.h"
#include "inifile.h"
#include "levels.h"
#include "qav.h"
#include "view.h"
#include "network.h"
#include "mmulti.h" #include "mmulti.h"
#include "c_bind.h" #include "c_bind.h"
#include "menu.h" #include "menu.h"
#include "sound.h"
#include "gamestate.h" #include "gamestate.h"
#include "blood.h"
#include "globals.h"
#include "qav.h"
#include "view.h"
#include "sound.h"
bool ShowOptionMenu(); bool ShowOptionMenu();
BEGIN_BLD_NS BEGIN_BLD_NS
@ -220,19 +217,14 @@ void GameInterface::DrawNativeMenuText(int fontnum, int state, double xpos, doub
int shade = (state != NIT_InactiveState) ? 32 : 48; int shade = (state != NIT_InactiveState) ? 32 : 48;
int pal = (state != NIT_InactiveState) ? 5 : 5; int pal = (state != NIT_InactiveState) ? 5 : 5;
if (state == NIT_SelectedState) shade = 32 - ((int)totalclock & 63); if (state == NIT_SelectedState) shade = 32 - ((int)totalclock & 63);
int width, height; auto gamefont = fontnum == NIT_BigFont ? BigFont : fontnum == NIT_SmallFont ? SmallFont : SmallFont2;
int gamefont = fontnum == NIT_BigFont ? 1 : fontnum == NIT_SmallFont ? 2 : 3;
int x = int(xpos);
int y = int(ypos);
viewGetFontInfo(gamefont, text, &width, &height);
if (flags & LMF_Centered) if (flags & LMF_Centered)
{ {
x -= width / 2; int width = gamefont->StringWidth(text);
xpos -= width / 2;
} }
DrawText(twod, gamefont, CR_UNDEFINED, xpos, ypos, text, DTA_TranslationIndex, TRANSLATION(Translation_Remap, pal), DTA_Color, shadeToLight(shade), TAG_DONE);
viewDrawText(gamefont, text, x, y, shade, pal, 0, true);
} }
@ -269,35 +261,28 @@ FSavegameInfo GameInterface::GetSaveSig()
void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text) void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text)
{ {
int height, width;
// font #1, tile #2038.
viewGetFontInfo(1, text, &width, &height);
double scalex = 1.; // Expand the box if the text is longer double scalex = 1.; // Expand the box if the text is longer
int width = BigFont->StringWidth(text);
int boxwidth = tileWidth(2038); int boxwidth = tileWidth(2038);
if (boxwidth - 10 < width) scalex = double(width) / (boxwidth - 10); if (boxwidth - 10 < width) scalex = double(width) / (boxwidth - 10);
DrawTexture(twod, tileGetTexture(2038), 160, 20, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_CenterOffsetRel, true, DTA_ScaleX, scalex, TAG_DONE); DrawTexture(twod, tileGetTexture(2038, true), 160, 20, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_CenterOffsetRel, true, DTA_ScaleX, scalex, TAG_DONE);
DrawText(twod, BigFont, CR_UNDEFINED, 160, 29, text, TAG_DONE);
viewDrawText(1, text, 160, 20 - height / 2, -128, 0, 1, false);
} }
void GameInterface::DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) void GameInterface::DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg)
{ {
if (text) if (text)
{ {
int width, height = 0; int height = SmallFont->GetHeight();
viewGetFontInfo(0, "T", &width, &height);
auto lines = FString(text).Split("\n"); auto lines = FString(text).Split("\n");
int y = 100 - (height * lines.Size() / 2); int y = 100 - (height * lines.Size() / 2);
for (auto& l : lines) for (auto& l : lines)
{ {
int lheight = 0; int width = SmallFont->StringWidth(text);
viewGetFontInfo(0, l, &width, &lheight);
int x = 160 - width / 2; int x = 160 - width / 2;
viewDrawText(0, l, x, y, 0, 0, 0, false); DrawText(twod, SmallFont, CR_UNTRANSLATED, y, y, text, TAG_DONE);
y += height; y += height;
} }
} }

View file

@ -55,7 +55,7 @@ void CEndGameMgr::Draw(void)
viewLoadingScreenWide(); viewLoadingScreenWide();
int nHeight; int nHeight;
viewGetFontInfo(1, NULL, NULL, &nHeight); viewGetFontInfo(1, NULL, NULL, &nHeight);
DrawTexture(twod, tileGetTexture(2038), 160, 20, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_CenterOffsetRel, true, TAG_DONE); DrawTexture(twod, tileGetTexture(2038, true), 160, 20, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_CenterOffsetRel, true, TAG_DONE);
int nY = 20 - nHeight / 2; int nY = 20 - nHeight / 2;
if (gGameOptions.nGameType == 0) if (gGameOptions.nGameType == 0)
{ {

View file

@ -160,7 +160,7 @@ void sub_2541C(int x, int y, int z, short a)
double x = xdim/2. + x1 / double(1<<12); double x = xdim/2. + x1 / double(1<<12);
double y = ydim/2. + y1 / double(1<<12); double y = ydim/2. + y1 / double(1<<12);
// This very likely needs fixing later // This very likely needs fixing later
DrawTexture(twod, tileGetTexture(nTile), x, y, DTA_FullscreenScale, 3, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DrawTexture(twod, tileGetTexture(nTile, true), x, y, DTA_FullscreenScale, 3, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y,
DTA_ViewportWidth, windowxy2.x - windowxy1.x+1, DTA_ViewportHeight, windowxy2.y - windowxy1.y+1, DTA_Alpha, (pSprite->cstat&2? 0.5:1.), TAG_DONE); DTA_ViewportWidth, windowxy2.x - windowxy1.x+1, DTA_ViewportHeight, windowxy2.y - windowxy1.y+1, DTA_Alpha, (pSprite->cstat&2? 0.5:1.), TAG_DONE);
} }
} }
@ -216,9 +216,9 @@ void CViewMap::sub_25C74(void)
#if 0 // needs to be generalized #if 0 // needs to be generalized
if (gViewMap.bFollowMode) if (gViewMap.bFollowMode)
viewDrawText(3, "MAP FOLLOW MODE", gViewX1S, nViewY+8, -128, 0, 2, 0, 256); Printf(PRINT_NOTIFY, "MAP FOLLOW MODE\n");
else else
viewDrawText(3, "MAP SCROLL MODE", gViewX1S, nViewY+8, -128, 0, 2, 0, 256); Printf(PRINT_NOTIFY, "MAP SCROLL MODE\n");
#endif #endif
if (tm) if (tm)
viewResizeView(viewSize); viewResizeView(viewSize);

View file

@ -21,8 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#pragma once #pragma once
#include "common_game.h" #include "build.h"
#include "db.h" #include "fix16.h"
BEGIN_BLD_NS BEGIN_BLD_NS

View file

@ -442,7 +442,7 @@ void CGameMessageMgr::SetMaxMessages(int nMessages)
void CGameMessageMgr::SetFont(int nFont) void CGameMessageMgr::SetFont(int nFont)
{ {
this->nFont = nFont; this->nFont = nFont;
fontHeight = gFont[nFont].ySize; fontHeight = gFont[nFont]->GetHeight();
} }
void CGameMessageMgr::SetCoordinates(int x, int y) void CGameMessageMgr::SetCoordinates(int x, int y)

View file

@ -67,13 +67,13 @@ void DrawFrame(F2DDrawer *twod, int x, int y, TILE_FRAME *pTile, int stat, int s
if (!to3dview) if (!to3dview)
{ {
DrawTexture(twod, tex, x, y, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Rotate, angle, DTA_LegacyRenderStyle, renderstyle, DTA_Alpha, alpha, DTA_Pin, pin, DTA_TranslationIndex, translation, DrawTexture(twod, tex, x, y, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Rotate, angle, DTA_LegacyRenderStyle, renderstyle, DTA_Alpha, alpha, DTA_Pin, pin, DTA_TranslationIndex, translation,
DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_FlipOffsets, !topleft, DTA_Color, color, DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_FlipOffsets, true, DTA_Color, color,
DTA_FlipX, xflip, DTA_FlipY, yflip, TAG_DONE); DTA_FlipX, xflip, DTA_FlipY, yflip, TAG_DONE);
} }
else else
{ {
DrawTexture(twod, tex, x, y, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Rotate, angle, DTA_LegacyRenderStyle, renderstyle, DTA_Alpha, alpha, DTA_Pin, pin, DTA_TranslationIndex, translation, DrawTexture(twod, tex, x, y, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Rotate, angle, DTA_LegacyRenderStyle, renderstyle, DTA_Alpha, alpha, DTA_Pin, pin, DTA_TranslationIndex, translation,
DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_FlipOffsets, !topleft, DTA_Color, color, DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_FlipOffsets, true, DTA_Color, color,
DTA_FlipX, xflip, DTA_FlipY, yflip, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DTA_ViewportWidth, windowxy2.x - windowxy1.x+1, DTA_ViewportHeight, windowxy2.y - windowxy1.y+1, TAG_DONE); DTA_FlipX, xflip, DTA_FlipY, yflip, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DTA_ViewportWidth, windowxy2.x - windowxy1.x+1, DTA_ViewportHeight, windowxy2.y - windowxy1.y+1, TAG_DONE);
} }
} }

View file

@ -29,23 +29,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "build.h" #include "build.h"
#include "pragmas.h" #include "pragmas.h"
#include "mmulti.h" #include "mmulti.h"
#include "common_game.h" #include "v_font.h"
#include "aistate.h"
#include "blood.h"
#include "choke.h"
#include "db.h"
#include "endgame.h" #include "endgame.h"
#include "gameutil.h" #include "aistate.h"
#include "globals.h"
#include "levels.h"
#include "loadsave.h"
#include "map2d.h" #include "map2d.h"
#include "messages.h" #include "loadsave.h"
#include "network.h" #include "screen.h"
#include "player.h"
#include "screen.h"
#include "sectorfx.h" #include "sectorfx.h"
#include "choke.h"
#include "view.h" #include "view.h"
#include "nnexts.h" #include "nnexts.h"
#include "zstring.h" #include "zstring.h"
@ -53,6 +45,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "gstrings.h" #include "gstrings.h"
#include "v_2ddrawer.h" #include "v_2ddrawer.h"
#include "v_video.h" #include "v_video.h"
#include "v_font.h"
#include "glbackend/glbackend.h" #include "glbackend/glbackend.h"
CVARD(Bool, hud_powerupduration, true, CVAR_ARCHIVE/*|CVAR_FRONTEND_BLOOD*/, "enable/disable displaying the remaining seconds for power-ups") CVARD(Bool, hud_powerupduration, true, CVAR_ARCHIVE/*|CVAR_FRONTEND_BLOOD*/, "enable/disable displaying the remaining seconds for power-ups")
@ -176,54 +169,47 @@ void RotateXY(int *pX, int *pY, int *pZ, int ang)
*pY = dmulscale30r(oX,angSin,oY,angCos); *pY = dmulscale30r(oX,angSin,oY,angCos);
} }
FONT gFont[kFontNum]; FFont *gFont[kFontNum];
void FontSet(int id, int tile, int space) void FontSet(int id, int tile, int space)
{ {
if (id < 0 || id >= kFontNum || tile < 0 || tile >= kMaxTiles) if (id < 0 || id >= kFontNum || tile < 0 || tile >= kMaxTiles)
return; return;
FONT *pFont = &gFont[id]; GlyphSet glyphs;
int xSize = 0; for (int i = 1; i < 96; i++)
int ySize = 0;
pFont->tile = tile;
for (int i = 0; i < 96; i++)
{ {
if (tilesiz[tile+i].x > xSize) auto tex = tileGetTexture(tile + i);
xSize = tilesiz[tile+i].x; if (tex->isValid() && tex->GetTexelWidth() > 0 && tex->GetTexelHeight() > 0)
if (tilesiz[tile+i].y > ySize) glyphs.Insert(i + 32, tex);
ySize = tilesiz[tile+i].y;
} }
pFont->xSize = xSize; const char *names[] = { "smallfont", "bigfont", "gothfont", "smallfont2", "digifont"};
pFont->ySize = ySize; const char *defs[] = { "defsmallfont", "defbigfont", nullptr, "defsmallfont2", nullptr};
pFont->space = space; const bool kerning[] = { 0, 1, 1, 1, 0};
FFont ** ptrs[] = { &SmallFont, &BigFont, nullptr, &SmallFont2, nullptr};
gFont[id] = new ::FFont(names[id], nullptr, defs[id], 0, 0, 0, kerning[id], tileWidth(tile), false, false, &glyphs);
if (ptrs[id]) *ptrs[id] = gFont[id];
} }
void viewGetFontInfo(int id, const char *unk1, int *pXSize, int *pYSize) void viewGetFontInfo(int id, const char *unk1, int *pXSize, int *pYSize)
{ {
if (id < 0 || id >= kFontNum) if (id < 0 || id >= kFontNum)
return; return;
FONT *pFont = &gFont[id]; FFont *pFont = gFont[id];
if (!unk1) if (!unk1)
{ {
if (pXSize) if (pXSize)
*pXSize = pFont->xSize; *pXSize = pFont->GetCharWidth('N');
if (pYSize) if (pYSize)
*pYSize = pFont->ySize; *pYSize = pFont->GetHeight();
} }
else else
{ {
int width = -pFont->space;
for (const char *pBuf = unk1; *pBuf != 0; pBuf++)
{
int tile = ((*pBuf-32)&127)+pFont->tile;
if (tileGetTexture(tile)->isValid())
width += tilesiz[tile].x+pFont->space;
}
if (pXSize) if (pXSize)
*pXSize = width; *pXSize = pFont->StringWidth(unk1);
if (pYSize) if (pYSize)
*pYSize = pFont->ySize; *pYSize = pFont->GetHeight();
} }
} }
@ -1015,29 +1001,25 @@ void RestoreInterpolations(void)
void viewDrawText(int nFont, const char *pString, int x, int y, int nShade, int nPalette, int position, char shadow, unsigned int nStat, uint8_t alpha) void viewDrawText(int nFont, const char *pString, int x, int y, int nShade, int nPalette, int position, char shadow, unsigned int nStat, uint8_t alpha)
{ {
if (nFont < 0 || nFont >= kFontNum || !pString) return; if (nFont < 0 || nFont >= kFontNum || !pString) return;
FONT *pFont = &gFont[nFont]; FFont *pFont = gFont[nFont];
//y += pFont->yoff; //y += pFont->yoff;
if (position) if (position) x -= pFont->StringWidth(pString) / 2;
{
const char *s = pString; if (shadow)
int width = -pFont->space; {
while (*s) DrawText(twod, pFont, CR_UNDEFINED, x, y, pString, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_Color, 0, DTA_Alpha, 0.5, TAG_DONE);
{ }
int nTile = ((*s-' ')&127)+pFont->tile; DrawText(twod, pFont, CR_UNDEFINED, x, y, pString, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_TranslationIndex, TRANSLATION(Translation_Remap, nPalette),
if (tilesiz[nTile].x && tilesiz[nTile].y) DTA_Color, shadeToLight(nShade), TAG_DONE);
width += tilesiz[nTile].x+pFont->space;
s++; // This is just for position comparison
}
if (position == 1)
width >>= 1;
x -= width;
}
const char *s = pString; const char *s = pString;
while (*s) while (*s)
{ {
int nTile = ((*s-' ')&127) + pFont->tile; int nTile = 'A' - 32 + 4096 + nFont*96;
//int nTile = ((*s-' ')&127) + ';
if (tilesiz[nTile].x && tilesiz[nTile].y) if (tilesiz[nTile].x && tilesiz[nTile].y)
{ {
if (shadow) if (shadow)
@ -1045,7 +1027,7 @@ void viewDrawText(int nFont, const char *pString, int x, int y, int nShade, int
rotatesprite_fs_alpha((x+1)<<16, (y+1)<<16, 65536, 0, nTile, 127, nPalette, 26|nStat, alpha); rotatesprite_fs_alpha((x+1)<<16, (y+1)<<16, 65536, 0, nTile, 127, nPalette, 26|nStat, alpha);
} }
rotatesprite_fs_alpha(x<<16, y<<16, 65536, 0, nTile, nShade, nPalette, 26|nStat, alpha); rotatesprite_fs_alpha(x<<16, y<<16, 65536, 0, nTile, nShade, nPalette, 26|nStat, alpha);
x += tilesiz[nTile].x+pFont->space; x += pFont->GetDefaultKerning();
} }
s++; s++;
} }

View file

@ -75,12 +75,8 @@ enum INTERPOLATE_TYPE {
#define kFontNum 5 #define kFontNum 5
struct FONT {
int tile, xSize, ySize, space;
};
extern int gZoom; extern int gZoom;
extern FONT gFont[kFontNum]; extern FFont *gFont[kFontNum];
extern int gViewMode; extern int gViewMode;
extern VIEWPOS gViewPos; extern VIEWPOS gViewPos;
extern int gViewIndex; extern int gViewIndex;