Skip to content

Commit

Permalink
- backend update from Raze.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Nov 23, 2020
1 parent 58d8ce1 commit 9925cc3
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/common/2d/v_drawtext.cpp
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/common/engine/i_interface.h
Expand Up @@ -4,6 +4,9 @@
#include "intrect.h"

struct event_t;
class FRenderState;
class FGameTexture;
enum EUpscaleFlags : int;

struct SystemCallbacks
{
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/common/fonts/font.cpp
Expand Up @@ -55,6 +55,7 @@
#include "fontchars.h"
#include "multipatchtexture.h"
#include "texturemanager.h"
#include "i_interface.h"

#include "fontinternals.h"

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/fonts/specialfont.cpp
Expand Up @@ -38,6 +38,7 @@
#include "image.h"
#include "fontchars.h"
#include "texturemanager.h"
#include "i_interface.h"

#include "fontinternals.h"

Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/objects/dobject.h
Expand Up @@ -267,7 +267,7 @@ class DObject

void *operator new(size_t len, nonew&)
{
return M_Malloc(len);
return M_Calloc(len, 1);
}
public:

Expand Down
12 changes: 10 additions & 2 deletions src/common/rendering/hwrenderer/data/hw_renderstate.h
Expand Up @@ -5,6 +5,7 @@
#include "hw_material.h"
#include "texmanip.h"
#include "version.h"
#include "i_interface.h"

struct FColormap;
class IVertexBuffer;
Expand Down Expand Up @@ -569,6 +570,7 @@ class FRenderState
mBias.mChanged = true;
}

private:
void SetMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader)
{
mMaterial.mMaterial = mat;
Expand All @@ -581,10 +583,16 @@ class FRenderState
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)
Expand Down
5 changes: 3 additions & 2 deletions src/common/scripting/interface/vmnatives.cpp
Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/scripting/vm/vmframe.cpp
Expand Up @@ -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());
Expand Down
13 changes: 7 additions & 6 deletions src/common/statusbar/base_sbar.cpp
Expand Up @@ -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)

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/statusbar/base_sbar.h
Expand Up @@ -186,7 +186,7 @@ class DStatusBarCore : public DObject
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);
Expand Down
2 changes: 1 addition & 1 deletion src/common/textures/gametexture.h
Expand Up @@ -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,
Expand Down

0 comments on commit 9925cc3

Please sign in to comment.