Skip to content

Commit

Permalink
- fixed hires replacements for colorized font characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Jun 1, 2021
1 parent 4548162 commit f0d2aef
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 3 additions & 1 deletion source/common/fonts/font.cpp
Expand Up @@ -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<unsigned>(Chars.Size(), LastChar - FirstChar + 1);
uint32_t usedcolors[256] = {};
TArray<double> Luminosity;

if (count == 0) return;
for (unsigned int i = 0; i < count; i++)
{
if (Chars[i].OriginalPic)
Expand Down Expand Up @@ -1005,6 +1006,7 @@ void FFont::LoadTranslations()

FFont::FFont (int lump, FName nm)
{
FirstChar = LastChar = 0;
Next = FirstFont;
FirstFont = this;
Lump = lump;
Expand Down
1 change: 0 additions & 1 deletion source/common/fonts/specialfont.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/core/gamecontrol.cpp
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion source/core/razefont.cpp
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions source/core/textures/buildtiles.h
Expand Up @@ -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);

23 changes: 12 additions & 11 deletions source/core/textures/hightile.cpp
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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
{
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit f0d2aef

Please sign in to comment.