From f0d2aef9d97fd4faf474f616396d18abe5bfdc89 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 1 Jun 2021 11:29:39 +0200 Subject: [PATCH] - fixed hires replacements for colorized font characters. --- source/common/fonts/font.cpp | 4 +++- source/common/fonts/specialfont.cpp | 1 - source/core/gamecontrol.cpp | 2 +- source/core/razefont.cpp | 2 +- source/core/textures/buildtiles.h | 3 +-- source/core/textures/hightile.cpp | 23 ++++++++++++----------- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/source/common/fonts/font.cpp b/source/common/fonts/font.cpp index f24ddbb87..3324a14e4 100644 --- a/source/common/fonts/font.cpp +++ b/source/common/fonts/font.cpp @@ -968,10 +968,11 @@ int FFont::GetMaxAscender(const uint8_t* string) const void FFont::LoadTranslations() { - unsigned int count = LastChar - FirstChar + 1; + unsigned int count = min(Chars.Size(), LastChar - FirstChar + 1); uint32_t usedcolors[256] = {}; TArray Luminosity; + if (count == 0) return; for (unsigned int i = 0; i < count; i++) { if (Chars[i].OriginalPic) @@ -1005,6 +1006,7 @@ void FFont::LoadTranslations() FFont::FFont (int lump, FName nm) { + FirstChar = LastChar = 0; Next = FirstFont; FirstFont = this; Lump = lump; diff --git a/source/common/fonts/specialfont.cpp b/source/common/fonts/specialfont.cpp index 8bde8499e..b00a19ad3 100644 --- a/source/common/fonts/specialfont.cpp +++ b/source/common/fonts/specialfont.cpp @@ -105,7 +105,6 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture auto pic = charlumps[i]; Chars[i].OriginalPic = MakeGameTexture(pic->GetTexture(), nullptr, ETextureType::FontChar); Chars[i].OriginalPic->CopySize(pic, true); - Chars[i].OriginalPic->SetName(FStringf("@@%s.%d", name, i)); TexMan.AddGameTexture(Chars[i].OriginalPic); Chars[i].XMove = (int)Chars[i].OriginalPic->GetDisplayWidth(); if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic); diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 0bc074ba3..fca81ca83 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1547,7 +1547,7 @@ DEFINE_ACTION_FUNCTION(_Raze, PickTexture) PARAM_PROLOGUE; PARAM_INT(texid); TexturePick pick; - if (PickTexture(nullptr, TexMan.GetGameTexture(FSetTextureID(texid)), TRANSLATION(Translation_Remap, 0), pick)) + if (PickTexture(TexMan.GetGameTexture(FSetTextureID(texid)), TRANSLATION(Translation_Remap, 0), pick)) { ACTION_RETURN_INT(pick.texture->GetID().GetIndex()); } diff --git a/source/core/razefont.cpp b/source/core/razefont.cpp index 489730f21..1172cf282 100644 --- a/source/core/razefont.cpp +++ b/source/core/razefont.cpp @@ -121,7 +121,7 @@ static int compareChar(int code, FFont* gamefont, FFont* myfont) // If there's a hires version attached to the base, treat this as the base being different. TexturePick pick; - if (PickTexture(nullptr, c1, 0, pick) && pick.texture != c1) return 0; + if (PickTexture(c1, 0, pick) && pick.texture != c1) return 0; auto t1 = c1->GetTexture(); auto t2 = c2->GetTexture(); diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index 4f5e50aba..c84273328 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -489,7 +489,6 @@ struct SetAnim }; void processSetAnim(const char* cmd, FScriptPosition& pos, SetAnim& imp); -class FRenderState; class FGameTexture; -bool PickTexture(FRenderState* state, FGameTexture* tex, int paletteid, TexturePick& pick); +bool PickTexture(FGameTexture* tex, int paletteid, TexturePick& pick, bool wantindexed = false); diff --git a/source/core/textures/hightile.cpp b/source/core/textures/hightile.cpp index d5e6259b1..b8520dc95 100644 --- a/source/core/textures/hightile.cpp +++ b/source/core/textures/hightile.cpp @@ -322,18 +322,22 @@ int tileSetSkybox(int picnum, int palnum, FString* facenames) // //=========================================================================== -bool PickTexture(FRenderState *state, FGameTexture* tex, int paletteid, TexturePick& pick) +bool PickTexture(FGameTexture* tex, int paletteid, TexturePick& pick, bool wantindexed) { if (!tex->isValid() || tex->GetTexelWidth() <= 0 || tex->GetTexelHeight() <= 0) return false; + if (tex->GetUseType() == ETextureType::FontChar && paletteid != 0) + { + int a = 0; + } + int usepalette = 0, useremap = 0; if (!IsLuminosityTranslation(paletteid)) { usepalette = paletteid == 0 ? 0 : GetTranslationType(paletteid) - Translation_Remap; useremap = GetTranslationIndex(paletteid); } - bool foggy = state && (state->GetFogColor() & 0xffffff); - int TextureType = hw_int_useindexedcolortextures && !foggy? TT_INDEXED : TT_TRUECOLOR; + int TextureType = wantindexed? TT_INDEXED : TT_TRUECOLOR; pick.translation = paletteid; pick.basepalTint = 0xffffff; @@ -344,11 +348,7 @@ bool PickTexture(FRenderState *state, FGameTexture* tex, int paletteid, TextureP int hipalswap = usepalette >= 0 ? useremap : 0; auto rep = (hw_hightile && !(h.tintFlags & TINTF_ALWAYSUSEART)) ? FindReplacement(tex->GetID(), hipalswap, false) : nullptr; - if (IsLuminosityTranslation(paletteid)) - { - // For a luminosity translation we only want the plain texture as-is. - } - else if (rep || tex->GetTexture()->isHardwareCanvas()) + if (rep || tex->GetTexture()->isHardwareCanvas()) { if (usepalette > 0) { @@ -364,7 +364,7 @@ bool PickTexture(FRenderState *state, FGameTexture* tex, int paletteid, TextureP } if (!rep || rep->palnum != hipalswap || (h.tintFlags & TINTF_APPLYOVERALTPAL)) applytint = true; - pick.translation = 0; + if (!IsLuminosityTranslation(paletteid)) pick.translation = 0; } else { @@ -376,7 +376,7 @@ bool PickTexture(FRenderState *state, FGameTexture* tex, int paletteid, TextureP applytint = true; if (!(h.tintFlags & TINTF_APPLYOVERPALSWAP)) useremap = 0; } - pick.translation = paletteid == 0? 0 : TRANSLATION(usepalette + Translation_Remap, useremap); + pick.translation = IsLuminosityTranslation(paletteid)? paletteid : paletteid == 0? 0 : TRANSLATION(usepalette + Translation_Remap, useremap); } else pick.translation |= 0x80000000; } @@ -403,7 +403,8 @@ bool PreBindTexture(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flag if (tex->GetUseType() == ETextureType::Special) return true; - if (PickTexture(state, tex, translation, pick)) + bool foggy = state && (state->GetFogColor() & 0xffffff); + if (PickTexture(tex, translation, pick, hw_int_useindexedcolortextures && !foggy)) { int TextureType = (pick.translation & 0x80000000) ? TT_INDEXED : TT_TRUECOLOR; int lookuppal = pick.translation & 0x7fffffff;