Skip to content

Commit

Permalink
- changed translation management so that the fonts also use translati…
Browse files Browse the repository at this point in the history
…on IDs.
  • Loading branch information
coelckers committed Mar 16, 2020
1 parent b7970ed commit 828cba1
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 98 deletions.
27 changes: 14 additions & 13 deletions src/gamedata/fonts/font.cpp
Expand Up @@ -666,7 +666,7 @@ void FFont::SetDefaultTranslation(uint32_t *othercolors)
}
}
}
Ranges[CR_UNTRANSLATED] = remap;
Translations[CR_UNTRANSLATED] = remap.StoreTranslation(TRANSLATION_Font);
forceremap = true;
}

Expand Down Expand Up @@ -769,40 +769,40 @@ int FFont::SimpleTranslation (uint32_t *colorsused, uint8_t *translation, uint8_
//==========================================================================

void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity,
const void *ranges, int total_colors, const PalEntry *palette)
const void *ranges, int total_colors, const PalEntry *palette, std::function<void(FRemapTable*)> post)
{
int i, j;
const TranslationParm *parmstart = (const TranslationParm *)ranges;

FRemapTable remap(total_colors);

// Create different translations for different color ranges
Ranges.Clear();
Translations.Clear();
for (i = 0; i < NumTextColors; i++)
{
if (i == CR_UNTRANSLATED)
{
if (identity != nullptr)
{
memcpy (remap.Remap, identity, ActiveColors);
memcpy(remap.Remap, identity, ActiveColors);
if (palette != nullptr)
{
memcpy (remap.Palette, palette, ActiveColors*sizeof(PalEntry));
memcpy(remap.Palette, palette, ActiveColors * sizeof(PalEntry));
}
else
{
remap.Palette[0] = GPalette.BaseColors[identity[0]] & MAKEARGB(0,255,255,255);
remap.Palette[0] = GPalette.BaseColors[identity[0]] & MAKEARGB(0, 255, 255, 255);
for (j = 1; j < ActiveColors; ++j)
{
remap.Palette[j] = GPalette.BaseColors[identity[j]] | MAKEARGB(255,0,0,0);
remap.Palette[j] = GPalette.BaseColors[identity[j]] | MAKEARGB(255, 0, 0, 0);
}
}
Translations.Push(remap.StoreTranslation(TRANSLATION_Font));
}
else
{
remap = Ranges[0];
Translations.Push(Translations[0]);
}
Ranges.Push(remap);
continue;
}

Expand Down Expand Up @@ -836,7 +836,8 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity
remap.Remap[j] = ColorMatcher.Pick(r, g, b);
remap.Palette[j] = PalEntry(255,r,g,b);
}
Ranges.Push(remap);
if (post) post(&remap);
Translations.Push(remap.StoreTranslation(TRANSLATION_Font));

// Advance to the next color range.
while (parmstart[1].RangeStart > parmstart[0].RangeEnd)
Expand All @@ -853,7 +854,7 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity
//
//==========================================================================

FRemapTable *FFont::GetColorTranslation (EColorRange range, PalEntry *color) const
int FFont::GetColorTranslation (EColorRange range, PalEntry *color) const
{
if (noTranslate)
{
Expand All @@ -866,11 +867,11 @@ FRemapTable *FFont::GetColorTranslation (EColorRange range, PalEntry *color) con
if (color != nullptr) *color = retcolor;
}
if (ActiveColors == 0)
return nullptr;
return -1;
else if (range >= NumTextColors)
range = CR_UNTRANSLATED;
//if (range == CR_UNTRANSLATED && !translateUntranslated) return nullptr;
return &Ranges[range];
return Translations[range];
}

//==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/gamedata/fonts/hexfont.cpp
Expand Up @@ -417,7 +417,7 @@ class FHexFont2 : public FFont
}
}
}
Ranges[CR_UNTRANSLATED] = remap;
Translations[CR_UNTRANSLATED] = remap.StoreTranslation(TRANSLATION_Font);
forceremap = true;

}
Expand Down
26 changes: 12 additions & 14 deletions src/gamedata/fonts/specialfont.cpp
Expand Up @@ -160,7 +160,7 @@ void FSpecialFont::LoadTranslations()
uint8_t identity[256];
TArray<double> Luminosity;
int TotalColors;
int i, j;
int i;

for (i = 0; i < count; i++)
{
Expand Down Expand Up @@ -199,22 +199,20 @@ void FSpecialFont::LoadTranslations()
static_cast<FFontChar1 *>(Chars[i].TranslatedPic->GetImage())->SetSourceRemap(PatchRemap);
}

BuildTranslations (Luminosity.Data(), identity, &TranslationParms[0][0], TotalColors, nullptr);

// add the untranslated colors to the Ranges tables
if (ActiveColors < TotalColors)
{
for (i = 0; i < NumTextColors; i++)
BuildTranslations(Luminosity.Data(), identity, &TranslationParms[0][0], TotalColors, nullptr, [=](FRemapTable* remap)
{
FRemapTable *remap = &Ranges[i];
for (j = ActiveColors; j < TotalColors; ++j)
// add the untranslated colors to the Ranges tables
if (ActiveColors < TotalColors)
{
remap->Remap[j] = identity[j];
remap->Palette[j] = GPalette.BaseColors[identity[j]];
remap->Palette[j].a = 0xff;
for (int j = ActiveColors; j < TotalColors; ++j)
{
remap->Remap[j] = identity[j];
remap->Palette[j] = GPalette.BaseColors[identity[j]];
remap->Palette[j].a = 0xff;
}
}
}
}
});

ActiveColors = TotalColors;
}

Expand Down
8 changes: 4 additions & 4 deletions src/gamedata/fonts/v_font.h
Expand Up @@ -39,8 +39,8 @@
#include "vectors.h"

class DCanvas;
struct FRemapTable;
class FTexture;
struct FRemapTable;

enum EColorRange : int
{
Expand Down Expand Up @@ -98,7 +98,7 @@ class FFont

virtual FTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const;
virtual int GetCharWidth (int code) const;
FRemapTable *GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const;
int GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const;
int GetLump() const { return Lump; }
int GetSpaceWidth () const { return SpaceWidth; }
int GetHeight () const { return FontHeight; }
Expand Down Expand Up @@ -137,7 +137,7 @@ class FFont
FFont (int lump);

void BuildTranslations (const double *luminosity, const uint8_t *identity,
const void *ranges, int total_colors, const PalEntry *palette);
const void *ranges, int total_colors, const PalEntry *palette, std::function<void(FRemapTable*)> post = nullptr);
void FixXMoves();

static int SimpleTranslation (uint32_t *colorsused, uint8_t *translation,
Expand Down Expand Up @@ -166,7 +166,7 @@ class FFont
};
TArray<CharData> Chars;
int ActiveColors;
TArray<FRemapTable> Ranges;
TArray<int> Translations;
uint8_t PatchRemap[256];

int Lump;
Expand Down
2 changes: 0 additions & 2 deletions src/intermission/intermission.cpp
Expand Up @@ -370,7 +370,6 @@ void DIntermissionScreenText::Drawer ()
int w;
size_t count;
int c;
const FRemapTable *range;
const uint8_t *ch = (const uint8_t*)mText.GetChars();

// Count number of rows in this text. Since it does not word-wrap, we just count
Expand Down Expand Up @@ -424,7 +423,6 @@ void DIntermissionScreenText::Drawer ()

// draw some of the text onto the screen
count = (mTicker - mTextDelay) / mTextSpeed;
range = font->GetColorTranslation (mTextColor);

for ( ; count > 0 ; count-- )
{
Expand Down
1 change: 1 addition & 0 deletions src/r_data/r_translate.h
Expand Up @@ -19,6 +19,7 @@ enum
TRANSLATION_Blood,
TRANSLATION_RainPillar,
TRANSLATION_Custom,
TRANSLATION_Font,

NUM_TRANSLATION_TABLES
};
Expand Down
12 changes: 6 additions & 6 deletions src/rendering/2d/v_2ddrawer.cpp
Expand Up @@ -393,12 +393,12 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms)
dg.mTexture = img;
if (img->isWarped()) dg.mFlags |= DTF_Wrap;

dg.mTranslation = 0;
dg.mTranslationId = 0;
SetStyle(img, parms, vertexcolor, dg);

if (!img->isHardwareCanvas() && parms.remap != nullptr && !parms.remap->Inactive)
if (!img->isHardwareCanvas() && parms.TranslationId != -1)
{
dg.mTranslation = parms.remap;
dg.mTranslationId = parms.TranslationId;
}
u1 = parms.srcx;
v1 = parms.srcy;
Expand Down Expand Up @@ -472,11 +472,11 @@ void F2DDrawer::AddShape( FTexture *img, DShape2D *shape, DrawParms &parms )
dg.mFlags |= DTF_Wrap;
dg.mTexture = img;

dg.mTranslation = 0;
dg.mTranslationId = 0;
SetStyle(img, parms, vertexcolor, dg);

if (!img->isHardwareCanvas() && parms.remap != nullptr && !parms.remap->Inactive)
dg.mTranslation = parms.remap;
if (!img->isHardwareCanvas() && parms.TranslationId != -1)
dg.mTranslationId = parms.TranslationId;

if (shape->dirty) {
if (shape->mVertices.Size() != shape->mTransformedVertices.Size())
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/2d/v_2ddrawer.h
Expand Up @@ -109,7 +109,7 @@ class F2DDrawer
int mIndexCount;

FTexture *mTexture;
FRemapTable *mTranslation;
int mTranslationId;
PalEntry mSpecialColormap[2];
int mScissor[4];
int mDesaturate;
Expand All @@ -128,7 +128,7 @@ class F2DDrawer
{
return mTexture == other.mTexture &&
mType == other.mType &&
mTranslation == other.mTranslation &&
mTranslationId == other.mTranslationId &&
mSpecialColormap[0].d == other.mSpecialColormap[0].d &&
mSpecialColormap[1].d == other.mSpecialColormap[1].d &&
!memcmp(mScissor, other.mScissor, sizeof(mScissor)) &&
Expand Down
9 changes: 2 additions & 7 deletions src/rendering/2d/v_draw.cpp
Expand Up @@ -558,7 +558,7 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
parms->destheight = INT_MAX;
parms->Alpha = 1.f;
parms->fillcolor = -1;
parms->remap = NULL;
parms->TranslationId = -1;
parms->colorOverlay = 0;
parms->alphaChannel = false;
parms->flipX = false;
Expand Down Expand Up @@ -756,7 +756,7 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
break;

case DTA_TranslationIndex:
parms->remap = TranslationToTable(ListGetInt(tags));
parms->TranslationId = ListGetInt(tags);
break;

case DTA_ColorOverlay:
Expand Down Expand Up @@ -971,11 +971,6 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
}
ListEnd(tags);

if (parms->remap != nullptr && parms->remap->Inactive)
{ // If it's inactive, pretend we were passed NULL instead.
parms->remap = nullptr;
}

// intersect with the canvas's clipping rectangle.
if (clipwidth >= 0 && clipheight >= 0)
{
Expand Down
20 changes: 10 additions & 10 deletions src/rendering/2d/v_drawtext.cpp
Expand Up @@ -59,14 +59,14 @@ int ListGetInt(VMVa_List &tags);
// Create a texture from a text in a given font.
//
//==========================================================================

#if 0
FTexture * BuildTextTexture(FFont *font, const char *string, int textcolor)
{
int w;
const uint8_t *ch;
int cx;
int cy;
FRemapTable *range;
int trans = -1;
int kerning;
FTexture *pic;

Expand Down Expand Up @@ -122,7 +122,7 @@ FTexture * BuildTextTexture(FFont *font, const char *string, int textcolor)
EColorRange newcolor = V_ParseFontColor(ch, textcolor, textcolor);
if (newcolor != CR_UNDEFINED)
{
range = font->GetColorTranslation(newcolor);
trans = font->GetColorTranslation(newcolor);
textcolor = newcolor;
}
continue;
Expand Down Expand Up @@ -158,7 +158,7 @@ FTexture * BuildTextTexture(FFont *font, const char *string, int textcolor)
TexMan.AddTexture(tex);
return tex;
}

#endif


//==========================================================================
Expand Down Expand Up @@ -193,7 +193,7 @@ void DFrameBuffer::DrawChar (FFont *font, int normalcolor, double x, double y, i
return;
}
PalEntry color = 0xffffffff;
parms.remap = redirected? nullptr : 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);
DrawTextureParms(pic, parms);
}
Expand All @@ -218,7 +218,7 @@ void DFrameBuffer::DrawChar(FFont *font, int normalcolor, double x, double y, in
bool res = ParseDrawTextureTags(pic, x, y, tag, args, &parms, false);
if (!res) return;
PalEntry color = 0xffffffff;
parms.remap = redirected ? nullptr : 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);
DrawTextureParms(pic, parms);
}
Expand Down Expand Up @@ -261,7 +261,7 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double
double cx;
double cy;
int boldcolor;
FRemapTable *range;
int trans = -1;
int kerning;
FTexture *pic;

Expand All @@ -274,7 +274,7 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double

PalEntry colorparm = parms.color;
PalEntry color = 0xffffffff;
range = font->GetColorTranslation((EColorRange)normalcolor, &color);
trans = 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();
Expand All @@ -301,7 +301,7 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double
EColorRange newcolor = V_ParseFontColor(ch, normalcolor, boldcolor);
if (newcolor != CR_UNDEFINED)
{
range = font->GetColorTranslation(newcolor, &color);
trans = 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;
}
Expand All @@ -318,7 +318,7 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double
bool redirected = false;
if (NULL != (pic = font->GetChar(c, currentcolor, &w, &redirected)))
{
parms.remap = redirected? nullptr : range;
parms.TranslationId = redirected? -1 : trans;
SetTextureParms(&parms, pic, cx, cy);
if (parms.cellx)
{
Expand Down
11 changes: 2 additions & 9 deletions src/rendering/gl/textures/gl_hwtexture.cpp
Expand Up @@ -317,15 +317,8 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i
{
int usebright = false;

if (translation <= 0)
{
translation = -translation;
}
else
{
auto remap = TranslationToTable(translation);
translation = remap == nullptr ? 0 : remap->GetUniqueIndex();
}
auto remap = TranslationToTable(translation);
translation = remap == nullptr ? 0 : remap->GetUniqueIndex();

bool needmipmap = (clampmode <= CLAMP_XY);

Expand Down

0 comments on commit 828cba1

Please sign in to comment.