From 9925cc380eb4aa695830433814a2158441834321 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 23 Nov 2020 15:45:33 +0100 Subject: [PATCH] - backend update from Raze. --- src/common/2d/v_drawtext.cpp | 6 ++++-- src/common/engine/i_interface.h | 5 +++++ src/common/fonts/font.cpp | 2 ++ src/common/fonts/specialfont.cpp | 2 ++ src/common/objects/dobject.h | 2 +- .../rendering/hwrenderer/data/hw_renderstate.h | 12 ++++++++++-- src/common/scripting/interface/vmnatives.cpp | 5 +++-- src/common/scripting/vm/vmframe.cpp | 4 ++-- src/common/statusbar/base_sbar.cpp | 13 +++++++------ src/common/statusbar/base_sbar.h | 2 +- src/common/textures/gametexture.h | 2 +- 11 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/common/2d/v_drawtext.cpp b/src/common/2d/v_drawtext.cpp index 5c06457b4..9a778eb13 100644 --- a/src/common/2d/v_drawtext.cpp +++ b/src/common/2d/v_drawtext.cpp @@ -186,8 +186,9 @@ void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double { return; } + bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0); PalEntry color = 0xffffffff; - parms.TranslationId = redirected ? -1 : font->GetColorTranslation((EColorRange)normalcolor, &color); + if (!palettetrans) 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); drawer->AddTexture(pic, parms); } @@ -211,8 +212,9 @@ 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); PalEntry color = 0xffffffff; - parms.TranslationId = redirected ? -1 : font->GetColorTranslation((EColorRange)normalcolor, &color); + if (!palettetrans) 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); drawer->AddTexture(pic, parms); } diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index cd400f441..b66bfc67e 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -4,6 +4,9 @@ #include "intrect.h" struct event_t; +class FRenderState; +class FGameTexture; +enum EUpscaleFlags : int; struct SystemCallbacks { @@ -27,6 +30,8 @@ struct SystemCallbacks void (*MenuClosed)(); 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); }; extern SystemCallbacks sysCallbacks; diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 2a67aab37..755ef1129 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -55,6 +55,7 @@ #include "fontchars.h" #include "multipatchtexture.h" #include "texturemanager.h" +#include "i_interface.h" #include "fontinternals.h" @@ -342,6 +343,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla { Chars[i].TranslatedPic = tex; } + if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].TranslatedPic); Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth(); } diff --git a/src/common/fonts/specialfont.cpp b/src/common/fonts/specialfont.cpp index 7e9c0778d..637cbf866 100644 --- a/src/common/fonts/specialfont.cpp +++ b/src/common/fonts/specialfont.cpp @@ -38,6 +38,7 @@ #include "image.h" #include "fontchars.h" #include "texturemanager.h" +#include "i_interface.h" #include "fontinternals.h" @@ -116,6 +117,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture } else Chars[i].TranslatedPic = Chars[i].OriginalPic; Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth(); + if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].TranslatedPic); } else { diff --git a/src/common/objects/dobject.h b/src/common/objects/dobject.h index bb966b422..ce591b6d6 100644 --- a/src/common/objects/dobject.h +++ b/src/common/objects/dobject.h @@ -267,7 +267,7 @@ private: void *operator new(size_t len, nonew&) { - return M_Malloc(len); + return M_Calloc(len, 1); } public: diff --git a/src/common/rendering/hwrenderer/data/hw_renderstate.h b/src/common/rendering/hwrenderer/data/hw_renderstate.h index c52ef83ab..9cf1015d2 100644 --- a/src/common/rendering/hwrenderer/data/hw_renderstate.h +++ b/src/common/rendering/hwrenderer/data/hw_renderstate.h @@ -5,6 +5,7 @@ #include "hw_material.h" #include "texmanip.h" #include "version.h" +#include "i_interface.h" struct FColormap; class IVertexBuffer; @@ -569,6 +570,7 @@ public: mBias.mChanged = true; } +private: void SetMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader) { mMaterial.mMaterial = mat; @@ -581,10 +583,16 @@ public: mStreamData.uDetailParms = { scale.X, scale.Y, 2, 0 }; } +public: void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, int translation, int overrideshader) { - if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale; - SetMaterial(FMaterial::ValidateTexture(tex, scaleflags), clampmode, translation, overrideshader); + if (!sysCallbacks.PreBindTexture || !sysCallbacks.PreBindTexture(this, tex, upscalemask, scaleflags, clampmode, translation, overrideshader)) + { + if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale; + } + auto mat = FMaterial::ValidateTexture(tex, scaleflags); + assert(mat); + SetMaterial(mat, clampmode, translation, overrideshader); } void SetClipSplit(float bottom, float top) diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 3f34c3b2a..502d78de3 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -124,7 +124,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, DrawImage, SBar_DrawImage) return 0; } -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); +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 translation); DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, DrawString, SBar_DrawString) { @@ -140,7 +140,8 @@ DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, DrawString, SBar_DrawString) PARAM_INT(linespacing); PARAM_FLOAT(scaleX); PARAM_FLOAT(scaleY); - SBar_DrawString(self, font, string, x, y, flags, trans, alpha, wrapwidth, linespacing, scaleX, scaleY); + PARAM_INT(pt); + SBar_DrawString(self, font, string, x, y, flags, trans, alpha, wrapwidth, linespacing, scaleX, scaleY, pt); return 0; } diff --git a/src/common/scripting/vm/vmframe.cpp b/src/common/scripting/vm/vmframe.cpp index bc6b344e5..4b50f9b21 100644 --- a/src/common/scripting/vm/vmframe.cpp +++ b/src/common/scripting/vm/vmframe.cpp @@ -79,8 +79,8 @@ void VMFunction::CreateRegUse() int count = 0; if (!Proto) { - if (RegTypes) return; - Printf(TEXTCOLOR_ORANGE "Function without prototype needs register info manually set: %s\n", PrintableName.GetChars()); + //if (RegTypes) return; + //Printf(TEXTCOLOR_ORANGE "Function without prototype needs register info manually set: %s\n", PrintableName.GetChars()); return; } assert(Proto->isPrototype()); diff --git a/src/common/statusbar/base_sbar.cpp b/src/common/statusbar/base_sbar.cpp index 7457b39ce..18cbe778c 100644 --- a/src/common/statusbar/base_sbar.cpp +++ b/src/common/statusbar/base_sbar.cpp @@ -57,7 +57,7 @@ IMPLEMENT_CLASS(DHUDFont, false, false); CVAR(Color, crosshaircolor, 0xff0000, CVAR_ARCHIVE); CVAR(Int, crosshairhealth, 2, CVAR_ARCHIVE); -CVAR(Float, crosshairscale, 1.0, CVAR_ARCHIVE); +CVARD(Float, crosshairscale, 0.5, CVAR_ARCHIVE, "changes the size of the crosshair"); CVAR(Bool, crosshairgrow, false, CVAR_ARCHIVE); EXTERN_CVAR(Bool, vid_fps) @@ -602,7 +602,7 @@ void DStatusBarCore::DrawGraphic(FGameTexture* tex, double x, double y, int flag // //============================================================================ -void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY) +void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY, int pt) { bool monospaced = monospacing != EMonospacing::Off; double dx = 0; @@ -724,10 +724,11 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d DTA_FillColor, 0, TAG_DONE); } - DrawChar(twod, font, fontcolor, rx, ry, ch, + DrawChar(twod, font, pt == 0? fontcolor : CR_UNDEFINED, rx, ry, ch, DTA_DestWidthF, rw, DTA_DestHeightF, rh, DTA_Alpha, Alpha, + DTA_TranslationIndex, pt, TAG_DONE); dx = monospaced @@ -739,7 +740,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) +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) { if (font == nullptr) ThrowAbortException(X_READ_NIL, nullptr); if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); @@ -758,13 +759,13 @@ void SBar_DrawString(DStatusBarCore* self, DHUDFont* font, const FString& string auto brk = V_BreakLines(font->mFont, int(wrapwidth * scaleX), string, true); for (auto& line : brk) { - self->DrawString(font->mFont, line.Text, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY, scaleX, scaleY); + self->DrawString(font->mFont, line.Text, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY, scaleX, scaleY, pt); y += (font->mFont->GetHeight() + linespacing) * scaleY; } } else { - self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY, scaleX, scaleY); + self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY, scaleX, scaleY, pt); } } diff --git a/src/common/statusbar/base_sbar.h b/src/common/statusbar/base_sbar.h index 96fdd3d1b..75daeb826 100644 --- a/src/common/statusbar/base_sbar.h +++ b/src/common/statusbar/base_sbar.h @@ -186,7 +186,7 @@ public: void StatusbarToRealCoords(double& x, double& y, double& w, double& h) const; void DrawGraphic(FGameTexture* texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, double rotate = 0, ERenderStyle style = STYLE_Translucent); void DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, double rotate = 0, ERenderStyle style = STYLE_Translucent); - void DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY); + void DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY, int pt); void TransformRect(double& x, double& y, double& w, double& h, int flags = 0); void Fill(PalEntry color, double x, double y, double w, double h, int flags = 0); void SetClipRect(double x, double y, double w, double h, int flags = 0); diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 0720267c3..c7a753372 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -361,7 +361,7 @@ inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureTy return t; } -enum EUpscaleFlags +enum EUpscaleFlags : int { UF_None = 0, UF_Texture = 1,