- Backend update from Raze.

This commit is contained in:
Christoph Oelckers 2021-07-11 09:51:59 +02:00
parent 250fac5b7e
commit e453f97872
15 changed files with 157 additions and 81 deletions

View file

@ -185,7 +185,7 @@ void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double
{
return;
}
bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0);
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
PalEntry color = 0xffffffff;
if (!palettetrans) parms.TranslationId = 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);
@ -210,7 +210,7 @@ void DrawChar(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double
uint32_t tag = ListGetInt(args);
bool res = ParseDrawTextureTags(drawer, pic, x, y, tag, args, &parms, false);
if (!res) return;
bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0);
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
PalEntry color = 0xffffffff;
if (!palettetrans) parms.TranslationId = 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);
@ -265,7 +265,7 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d
if (parms.celly == 0) parms.celly = font->GetHeight() + 1;
parms.celly = int (parms.celly * scaley);
bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0);
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
if (normalcolor >= NumTextColors)
normalcolor = CR_UNTRANSLATED;

View file

@ -613,17 +613,20 @@ static void CheckReplayGain(const char *musicname, EMidiDevice playertype, const
ZMusic_Close(handle);
GainAnalyzer analyzer;
analyzer.InitGainAnalysis(fmt.mSampleRate);
int result = analyzer.AnalyzeSamples(lbuffer.Data(), rbuffer.Size() == 0 ? nullptr : rbuffer.Data(), lbuffer.Size(), rbuffer.Size() == 0? 1: 2);
int result = analyzer.InitGainAnalysis(fmt.mSampleRate);
if (result == GAIN_ANALYSIS_OK)
{
auto gain = analyzer.GetTitleGain();
Printf("Calculated replay gain for %s at %f dB\n", hash.GetChars(), gain);
result = analyzer.AnalyzeSamples(lbuffer.Data(), rbuffer.Size() == 0 ? nullptr : rbuffer.Data(), lbuffer.Size(), rbuffer.Size() == 0 ? 1 : 2);
if (result == GAIN_ANALYSIS_OK)
{
auto gain = analyzer.GetTitleGain();
Printf("Calculated replay gain for %s at %f dB\n", hash.GetChars(), gain);
gainMap.Insert(hash, gain);
mus_playing.replayGain = gain;
mus_playing.replayGainFactor = dBToAmplitude(mus_playing.replayGain + mus_gainoffset);
SaveGains();
gainMap.Insert(hash, gain);
mus_playing.replayGain = gain;
mus_playing.replayGainFactor = dBToAmplitude(mus_playing.replayGain + mus_gainoffset);
SaveGains();
}
}
}

View file

@ -31,7 +31,7 @@ struct SystemCallbacks
bool (*CheckMenudefOption)(const char* opt);
void (*ConsoleToggled)(int state);
bool (*PreBindTexture)(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& scaleflags, int& clampmode, int& translation, int& overrideshader);
void (*FontCharCreated)(FGameTexture* base, FGameTexture* untranslated, FGameTexture* translated);
void (*FontCharCreated)(FGameTexture* base, FGameTexture* untranslated);
};
extern SystemCallbacks sysCallbacks;

View file

@ -70,6 +70,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, GlyphSet *baseGlyphs)
: FFont(fdlump, name)
{
int i;
FTextureID lump;
@ -77,17 +78,9 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
DVector2 Scale = { 1, 1 };
noTranslate = notranslate;
Lump = fdlump;
GlobalKerning = false;
FontName = name;
Next = FirstFont;
FirstFont = this;
Cursor = '_';
SpaceWidth = 0;
FontHeight = 0;
uint8_t pp = 0;
for (auto &p : PatchRemap) p = pp++;
translateUntranslated = false;
int FixedWidth = 0;
TMap<int, FGameTexture*> charMap;
@ -126,6 +119,11 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
sc.MustGetValue(false);
GlobalKerning = sc.Number;
}
if (sc.Compare("Altfont"))
{
sc.MustGetString();
AltFontName = sc.String;
}
else if (sc.Compare("Scale"))
{
sc.MustGetValue(true);
@ -154,6 +152,16 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
sc.MustGetValue(false);
FontHeight = sc.Number;
}
else if (sc.Compare("minluminosity"))
{
sc.MustGetValue(false);
MinLum = (int16_t)clamp(sc.Number, 0, 255);
}
else if (sc.Compare("maxluminosity"))
{
sc.MustGetValue(false);
MaxLum = (int16_t)clamp(sc.Number, 0, 255);
}
else if (sc.Compare("Translationtype"))
{
sc.MustGetToken(TK_Identifier);
@ -302,7 +310,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
auto count = maxchar - minchar + 1;
Chars.Resize(count);
int fontheight = 0;
int asciiheight = 0;
for (i = 0; i < count; i++)
{
@ -320,10 +327,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
{
fontheight = height;
}
if (height > asciiheight && FirstChar + 1 < 128)
{
asciiheight = height;
}
}
auto orig = pic->GetTexture();
@ -332,7 +335,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
TexMan.AddGameTexture(tex);
Chars[i].OriginalPic = tex;
if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].OriginalPic);
if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic);
Chars[i].XMove = (int)Chars[i].OriginalPic->GetDisplayWidth();
}
@ -359,7 +362,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
}
}
if (FontHeight == 0) FontHeight = fontheight;
if (AsciiHeight == 0) AsciiHeight = asciiheight;
FixXMoves();
}
@ -656,7 +658,7 @@ int FFont::GetLuminosity (uint32_t *colorsused, TArray<double> &Luminosity, int*
int FFont::GetColorTranslation (EColorRange range, PalEntry *color) const
{
// Single pic fonts don not set up their translation table and must always return 0.
// Single pic fonts do not set up their translation table and must always return 0.
if (Translations.Size() == 0) return 0;
assert(Translations.Size() == NumTextColors);
@ -966,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)
@ -981,6 +984,8 @@ void FFont::LoadTranslations()
int minlum = 0, maxlum = 0;
GetLuminosity (usedcolors, Luminosity, &minlum, &maxlum);
if (MinLum >= 0 && MinLum < minlum) minlum = MinLum;
if (MaxLum > maxlum) maxlum = MaxLum;
// Here we can set everything to a luminosity translation.
@ -999,14 +1004,15 @@ void FFont::LoadTranslations()
//
//==========================================================================
FFont::FFont (int lump)
FFont::FFont (int lump, FName nm)
{
FirstChar = LastChar = 0;
Next = FirstFont;
FirstFont = this;
Lump = lump;
FontName = NAME_None;
FontName = nm;
Cursor = '_';
noTranslate = false;
uint8_t pp = 0;
for (auto &p : PatchRemap) p = pp++;
}
//==========================================================================
@ -1070,3 +1076,7 @@ void FFont::FixXMoves()
}
void FFont::ClearOffsets()
{
for (auto& c : Chars) if (c.OriginalPic) c.OriginalPic->SetOffsets(0, 0);
}

View file

@ -287,13 +287,10 @@ public:
FirstChar = hexdata.FirstChar;
LastChar = hexdata.LastChar;
Next = FirstFont;
FirstFont = this;
FontHeight = 16;
SpaceWidth = 9;
GlobalKerning = 0;
translateUntranslated = true;
Chars.Resize(LastChar - FirstChar + 1);
for (int i = FirstChar; i <= LastChar; i++)
{
@ -355,12 +352,9 @@ public:
FirstChar = hexdata.FirstChar;
LastChar = hexdata.LastChar;
Next = FirstFont;
FirstFont = this;
FontHeight = 18;
SpaceWidth = 9;
GlobalKerning = -1;
translateUntranslated = true;
Chars.Resize(LastChar - FirstChar + 1);
for (int i = FirstChar; i <= LastChar; i++)
{

View file

@ -151,9 +151,6 @@ FSingleLumpFont::FSingleLumpFont (const char *name, int lump) : FFont(lump)
break;
}
}
Next = FirstFont;
FirstFont = this;
}
//==========================================================================
@ -227,7 +224,6 @@ void FSingleLumpFont::LoadFON1 (int lump, const uint8_t *data)
FirstChar = 0;
LastChar = 255; // This is to allow LoadTranslations to function. The way this is all set up really needs to be changed.
GlobalKerning = 0;
translateUntranslated = true;
LastChar = 0x2122;
// Move the Windows-1252 characters to their proper place.

View file

@ -80,9 +80,6 @@ FSinglePicFont::FSinglePicFont(const char *picname) :
GlobalKerning = 0;
FirstChar = LastChar = 'A';
PicNum = picnum;
Next = FirstFont;
FirstFont = this;
}
//==========================================================================

View file

@ -78,8 +78,6 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture
LastChar = first + count - 1;
FontHeight = 0;
GlobalKerning = false;
Next = FirstFont;
FirstFont = this;
maxyoffs = 0;
@ -109,7 +107,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture
Chars[i].OriginalPic->CopySize(pic, true);
TexMan.AddGameTexture(Chars[i].OriginalPic);
Chars[i].XMove = (int)Chars[i].OriginalPic->GetDisplayWidth();
if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].OriginalPic);
if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic);
}
else
{

View file

@ -177,9 +177,11 @@ void V_InitCustomFonts()
int start;
int first;
int count;
int spacewidth;
int spacewidth = -1;
int kerning;
char cursor = '_';
bool ignoreoffsets = false;
int MinLum = -1, MaxLum = -1;
while ((llump = fileSystem.FindLump ("FONTDEFS", &lastlump)) != -1)
{
@ -236,10 +238,8 @@ void V_InitCustomFonts()
}
else if (sc.Compare ("SPACEWIDTH"))
{
if (format == 2) goto wrong;
sc.MustGetNumber();
spacewidth = sc.Number;
format = 1;
}
else if (sc.Compare("DONTTRANSLATE"))
{
@ -260,9 +260,26 @@ void V_InitCustomFonts()
sc.MustGetNumber();
kerning = sc.Number;
}
else if (sc.Compare("ignoreoffsets"))
{
ignoreoffsets = true;
}
else if (sc.Compare("minluminosity"))
{
sc.MustGetValue(false);
MinLum = (int16_t)clamp(sc.Number, 0, 255);
}
else if (sc.Compare("maxluminosity"))
{
sc.MustGetValue(false);
MaxLum = (int16_t)clamp(sc.Number, 0, 255);
}
else
{
if (format == 1) goto wrong;
// The braces must be filtered so because they'd be treated as block terminators otherwise.
if (!strcmp(sc.String, "-{")) strcpy(sc.String, "{");
if (!strcmp(sc.String, "-}")) strcpy(sc.String, "}");
FGameTexture **p = &lumplist[*(unsigned char*)sc.String];
sc.MustGetString();
FTextureID texid = TexMan.CheckForTexture(sc.String, ETextureType::MiscPatch);
@ -283,6 +300,7 @@ void V_InitCustomFonts()
FFont *fnt = new FFont (namebuffer, templatebuf, nullptr, first, count, start, llump, spacewidth, donttranslate);
fnt->SetCursor(cursor);
fnt->SetKerning(kerning);
if (ignoreoffsets) fnt->ClearOffsets();
}
else if (format == 2)
{
@ -308,6 +326,10 @@ void V_InitCustomFonts()
FFont *fnt = CreateSpecialFont (namebuffer, first, count, &lumplist[first], notranslate, llump, donttranslate);
fnt->SetCursor(cursor);
fnt->SetKerning(kerning);
if (spacewidth >= 0) fnt->SpaceWidth = spacewidth;
fnt->MinLum = MinLum;
fnt->MaxLum = MaxLum;
if (ignoreoffsets) fnt->ClearOffsets();
}
}
else goto wrong;
@ -317,7 +339,7 @@ void V_InitCustomFonts()
return;
wrong:
sc.ScriptError ("Invalid combination of properties in font '%s'", namebuffer.GetChars());
sc.ScriptError ("Invalid combination of properties in font '%s', %s not allowed", namebuffer.GetChars(), sc.String);
}
//==========================================================================

View file

@ -40,10 +40,14 @@
class FGameTexture;
struct FRemapTable;
class FFont;
FFont* V_GetFont(const char* fontname, const char* fontlumpname = nullptr);
enum EColorRange : int
{
CR_UNDEFINED = -1,
CR_NATIVEPAL = -1,
CR_BRICK,
CR_TAN,
CR_GRAY,
@ -95,6 +99,7 @@ public:
};
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);
FFont(int lump, FName nm = NAME_None);
virtual ~FFont ();
virtual FGameTexture *GetChar (int code, int translation, int *const width) const;
@ -122,38 +127,66 @@ public:
inline bool CanPrint(const char *str) const { return CanPrint((const uint8_t *)str); }
inline bool CanPrint(const FString &str) const { return CanPrint((const uint8_t *)str.GetChars()); }
inline FFont* AltFont()
{
if (AltFontName != NAME_None) return V_GetFont(AltFontName.GetChars());
return nullptr;
}
int GetCharCode(int code, bool needpic) const;
char GetCursor() const { return Cursor; }
void SetCursor(char c) { Cursor = c; }
void SetKerning(int c) { GlobalKerning = c; }
void SetHeight(int c) { FontHeight = c; }
void ClearOffsets();
bool NoTranslate() const { return noTranslate; }
virtual void RecordAllTextureColors(uint32_t *usedcolors);
void CheckCase();
void SetName(FName nm) { FontName = nm; }
int GetDisplacement() const { return Displacement; }
static int GetLuminosity(uint32_t* colorsused, TArray<double>& Luminosity, int* minlum = nullptr, int* maxlum = nullptr);
EFontType GetType() const { return Type; }
friend void V_InitCustomFonts();
void CopyFrom(const FFont& other)
{
Type = other.Type;
FirstChar = other.FirstChar;
LastChar = other.LastChar;
SpaceWidth = other.SpaceWidth;
FontHeight = other.FontHeight;
GlobalKerning = other.GlobalKerning;
TranslationType = other.TranslationType;
Displacement = other.Displacement;
Cursor = other.Cursor;
noTranslate = other.noTranslate;
MixedCase = other.MixedCase;
forceremap = other.forceremap;
Chars = other.Chars;
Translations = other.Translations;
Lump = other.Lump;
}
protected:
FFont (int lump);
void FixXMoves();
void ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);
EFontType Type = EFontType::Unknown;
FName AltFontName = NAME_None;
int FirstChar, LastChar;
int SpaceWidth;
int FontHeight;
int AsciiHeight = 0;
int GlobalKerning;
int TranslationType = 0;
int Displacement = 0;
int16_t MinLum = -1, MaxLum = -1;
char Cursor;
bool noTranslate = false;
bool translateUntranslated;
bool MixedCase = false;
bool forceremap = false;
struct CharData
@ -163,7 +196,6 @@ protected:
};
TArray<CharData> Chars;
TArray<int> Translations;
uint8_t PatchRemap[256];
int Lump;
FName FontName = NAME_None;
@ -184,7 +216,6 @@ void V_ClearFonts();
EColorRange V_FindFontColor (FName name);
PalEntry V_LogColorFromColorRange (EColorRange range);
EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int boldcolor);
FFont *V_GetFont(const char *fontname, const char *fontlumpname = nullptr);
void V_InitFontColors();
char* CleanseString(char* str);
void V_ApplyLuminosityTranslation(int translation, uint8_t* pixel, int size);

View file

@ -817,7 +817,7 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d
DTA_FillColor, 0,
TAG_DONE);
}
DrawChar(twod, font, pt == 0? fontcolor : CR_UNDEFINED, rx, ry, ch,
DrawChar(twod, font, pt == 0? fontcolor : CR_NATIVEPAL, rx, ry, ch,
DTA_DestWidthF, rw,
DTA_DestHeightF, rh,
DTA_Alpha, Alpha,
@ -836,7 +836,7 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d
void SBar_DrawString(DStatusBarCore* self, DHUDFont* font, const FString& string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing, double scaleX, double scaleY, int pt, int style)
{
if (font == nullptr) ThrowAbortException(X_READ_NIL, nullptr);
if (font == nullptr || font->mFont == nullptr) ThrowAbortException(X_READ_NIL, nullptr);
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
// resolve auto-alignment before making any adjustments to the position values.

View file

@ -188,6 +188,9 @@ static void renderframe(anim_t *anim, uint16_t framenumber, uint16_t *pagepointe
while (frame--) offset += LittleShort(pagepointer[frame]);
if (offset >= anim->curlp->nBytes)
return;
uint8_t *ppointer = (uint8_t *)(pagepointer) + anim->curlp->nRecords*2 + offset + 4;
if ((ppointer-4)[1])

View file

@ -448,7 +448,13 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype)
if (lumpnum != -1)
{
FString str;
fileSystem.GetFileShortName(str, lumpnum);
if (!usefullnames)
fileSystem.GetFileShortName(str, lumpnum);
else
{
auto fn = fileSystem.GetFileFullName(lumpnum);
str = ExtractFileBase(fn);
}
auto out = MakeGameTexture(CreateTextureFromLump(lumpnum, usetype == ETextureType::Flat), str, usetype);
if (out != NULL)
@ -557,30 +563,44 @@ void FTextureManager::AddGroup(int wadnum, int ns, ETextureType usetype)
int lasttx = fileSystem.GetLastEntry(wadnum);
FString Name;
// Go from first to last so that ANIMDEFS work as expected. However,
// to avoid duplicates (and to keep earlier entries from overriding
// later ones), the texture is only inserted if it is the one returned
// by doing a check by name in the list of wads.
for (; firsttx <= lasttx; ++firsttx)
if (!usefullnames)
{
if (fileSystem.GetFileNamespace(firsttx) == ns)
{
fileSystem.GetFileShortName (Name, firsttx);
// Go from first to last so that ANIMDEFS work as expected. However,
// to avoid duplicates (and to keep earlier entries from overriding
// later ones), the texture is only inserted if it is the one returned
// by doing a check by name in the list of wads.
if (fileSystem.CheckNumForName (Name, ns) == firsttx)
{
CreateTexture (firsttx, usetype);
}
progressFunc();
}
else if (ns == ns_flats && fileSystem.GetFileFlags(firsttx) & LUMPF_MAYBEFLAT)
for (; firsttx <= lasttx; ++firsttx)
{
if (fileSystem.CheckNumForName (Name, ns) < firsttx)
if (fileSystem.GetFileNamespace(firsttx) == ns)
{
CreateTexture (firsttx, usetype);
fileSystem.GetFileShortName(Name, firsttx);
if (fileSystem.CheckNumForName(Name, ns) == firsttx)
{
CreateTexture(firsttx, usetype);
}
progressFunc();
}
else if (ns == ns_flats && fileSystem.GetFileFlags(firsttx) & LUMPF_MAYBEFLAT)
{
if (fileSystem.CheckNumForName(Name, ns) < firsttx)
{
CreateTexture(firsttx, usetype);
}
progressFunc();
}
}
}
else
{
// The duplicate check does not work with this (yet.)
for (; firsttx <= lasttx; ++firsttx)
{
if (fileSystem.GetFileNamespace(firsttx) == ns)
{
CreateTexture(firsttx, usetype);
}
progressFunc();
}
}
}

View file

@ -206,6 +206,7 @@ public:
FTextureID glPart2;
FTextureID glPart;
FTextureID mirrorTexture;
bool usefullnames;
};

View file

@ -251,6 +251,7 @@ GainAnalyzer::ResetSampleFrequency(int samplefreq) {
freqindex = 9;
break;
case 11025:
case 11111: // SW shareware tries to play a VOC with this frequency as music. This is close enough to 11025 to use the same table.
freqindex = 10;
break;
case 8000: