Skip to content

Commit

Permalink
- export common formulae to functions instead of copy-pasting them
Browse files Browse the repository at this point in the history
- screen bevel now enlarges also when screenblocks <= 11

- make intermission and status bar scaling game-specific in the config

- add scaling customization for classic ui flat scaling

- make screen border flat scale up

- inter_classic_scaling now defaults to true
- fixed: last commit I accidentally left hardcoded testing values and did not change them back to check for the texture's original size

- implement cvar 'inter_classic_scaling' to render the intermission flat as if it were 320x200
  • Loading branch information
madame-rachelle committed May 7, 2020
1 parent 0f07686 commit 6e3ec96
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 24 deletions.
33 changes: 33 additions & 0 deletions src/common/2d/v_2ddrawer.cpp
Expand Up @@ -37,12 +37,15 @@
#include "vm.h"
#include "c_cvars.h"
#include "v_draw.h"
#include "v_video.h"
#include "fcolormap.h"

static F2DDrawer drawer;
F2DDrawer* twod = &drawer;

EXTERN_CVAR(Float, transsouls)
CVAR(Float, classic_scaling_factor, 1.0, CVAR_ARCHIVE)
CVAR(Float, classic_scaling_pixelaspect, 1.2, CVAR_ARCHIVE)

IMPLEMENT_CLASS(DShape2DTransform, false, false)

Expand Down Expand Up @@ -677,6 +680,19 @@ void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, unsigne
//
//==========================================================================

float F2DDrawer::GetClassicFlatScalarWidth()
{
float ar = 4.f / 3.f / (float)ActiveRatio((float)screen->GetWidth(), (float)screen->GetHeight());
float sw = 320.f * classic_scaling_factor / (float)screen->GetWidth() / ar;
return sw;
}

float F2DDrawer::GetClassicFlatScalarHeight()
{
float sh = 240.f / classic_scaling_pixelaspect * classic_scaling_factor / (float)screen->GetHeight();
return sh;
}

void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin, double flatscale)
{
float fU1, fU2, fV1, fV2;
Expand All @@ -692,6 +708,10 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu

float fs = 1.f / float(flatscale);
bool flipc = false;

float sw = GetClassicFlatScalarWidth();
float sh = GetClassicFlatScalarHeight();

switch (local_origin)
{
case 0:
Expand Down Expand Up @@ -752,6 +772,19 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu
fV1 = float(right - left) / (float)src->GetDisplayHeight() * fs;
break;

case -1: // classic flat scaling
fU1 = float(left) / (float)src->GetDisplayWidth() * fs * sw;
fV1 = float(top) / (float)src->GetDisplayHeight() * fs * sh;
fU2 = float(right) / (float)src->GetDisplayWidth() * fs * sw;
fV2 = float(bottom) / (float)src->GetDisplayHeight() * fs * sh;
break;

case -2: // classic scaling for screen bevel
fU1 = 0;
fV1 = 0;
fU2 = float(right - left) / (float)src->GetDisplayWidth() * fs * sw;
fV2 = float(bottom - top) / (float)src->GetDisplayHeight() * fs * sh;
break;
}
dg.mVertIndex = (int)mVertices.Reserve(4);
auto ptr = &mVertices[dg.mVertIndex];
Expand Down
2 changes: 2 additions & 0 deletions src/common/2d/v_2ddrawer.h
Expand Up @@ -174,6 +174,8 @@ class F2DDrawer
void SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcolor, PalEntry &overlaycolor);

public:
float GetClassicFlatScalarWidth();
float GetClassicFlatScalarHeight();
void AddTexture(FGameTexture* img, DrawParms& parms);
void AddShape(FGameTexture *img, DShape2D *shape, DrawParms &parms);
void AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
Expand Down
13 changes: 8 additions & 5 deletions src/common/2d/v_draw.cpp
Expand Up @@ -43,6 +43,7 @@

EXTERN_CVAR(Int, vid_aspect)
EXTERN_CVAR(Int, uiscale)
CVAR(Bool, ui_screenborder_classic_scaling, true, CVAR_ARCHIVE)

// Helper for ActiveRatio and CheckRatio. Returns the forced ratio type, or -1 if none.
int ActiveFakeRatio(int width, int height)
Expand Down Expand Up @@ -1161,10 +1162,11 @@ void FillBorder (F2DDrawer *drawer, FGameTexture *img)

if (img != NULL)
{
drawer->AddFlatFill(0, 0, Width, bordtop, img); // Top
drawer->AddFlatFill(0, bordtop, bordleft, Height - bordbottom, img); // Left
drawer->AddFlatFill(Width - bordright, bordtop, Width, Height - bordbottom, img); // Right
drawer->AddFlatFill(0, Height - bordbottom, Width, Height, img); // Bottom
int filltype = (ui_screenborder_classic_scaling) ? -1 : 0;
drawer->AddFlatFill(0, 0, Width, bordtop, img, filltype); // Top
drawer->AddFlatFill(0, bordtop, bordleft, Height - bordbottom, img, filltype); // Left
drawer->AddFlatFill(Width - bordright, bordtop, Width, Height - bordbottom, img, filltype); // Right
drawer->AddFlatFill(0, Height - bordbottom, Width, Height, img, filltype); // Bottom
}
else
{
Expand Down Expand Up @@ -1351,9 +1353,10 @@ DEFINE_ACTION_FUNCTION(_Screen, Dim)

void DrawBorder (F2DDrawer *drawer, FTextureID picnum, int x1, int y1, int x2, int y2)
{
int filltype = (ui_screenborder_classic_scaling) ? -1 : 0;
if (picnum.isValid())
{
drawer->AddFlatFill (x1, y1, x2, y2, TexMan.GetGameTexture(picnum, false));
drawer->AddFlatFill (x1, y1, x2, y2, TexMan.GetGameTexture(picnum, false), filltype);
}
else
{
Expand Down
79 changes: 61 additions & 18 deletions src/g_statusbar/shared_sbar.cpp
Expand Up @@ -89,6 +89,8 @@ EXTERN_CVAR (Bool, noisedebug)
EXTERN_CVAR (Int, con_scaletext)
EXTERN_CVAR(Bool, vid_fps)
EXTERN_CVAR(Bool, inter_subtitles)
EXTERN_CVAR(Bool, ui_screenborder_classic_scaling)

CVAR(Int, hud_scale, 0, CVAR_ARCHIVE);
CVAR(Bool, log_vgafont, false, CVAR_ARCHIVE)

Expand Down Expand Up @@ -162,23 +164,53 @@ void V_DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height)
int right = left + width;
int bottom = top + height;

// Draw top and bottom sides.
p = TexMan.GetGameTextureByName(border->t);
drawer->AddFlatFill(left, top - (int)p->GetDisplayHeight(), right, top, p, true);
p = TexMan.GetGameTextureByName(border->b);
drawer->AddFlatFill(left, bottom, right, bottom + (int)p->GetDisplayHeight(), p, true);
float sw = drawer->GetClassicFlatScalarWidth();
float sh = drawer->GetClassicFlatScalarHeight();

if (!ui_screenborder_classic_scaling)
{
// Draw top and bottom sides.
p = TexMan.GetGameTextureByName(border->t);
drawer->AddFlatFill(left, top - (int)p->GetDisplayHeight(), right, top, p, true);
p = TexMan.GetGameTextureByName(border->b);
drawer->AddFlatFill(left, bottom, right, bottom + (int)p->GetDisplayHeight(), p, true);

// Draw left and right sides.
p = TexMan.GetGameTextureByName(border->l);
drawer->AddFlatFill(left - (int)p->GetDisplayWidth(), top, left, bottom, p, true);
p = TexMan.GetGameTextureByName(border->r);
drawer->AddFlatFill(right, top, right + (int)p->GetDisplayWidth(), bottom, p, true);

// Draw beveled corners.
DrawTexture(drawer, TexMan.GetGameTextureByName(border->tl), left - offset, top - offset, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->tr), left + width, top - offset, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->bl), left - offset, top + height, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->br), left + width, top + height, TAG_DONE);
}
else
{
// Draw top and bottom sides.
p = TexMan.GetGameTextureByName(border->t);
drawer->AddFlatFill(left, top - (int)(p->GetDisplayHeight() / sh), right, top, p, -2);
p = TexMan.GetGameTextureByName(border->b);
drawer->AddFlatFill(left, bottom, right, bottom + (int)(p->GetDisplayHeight() / sh), p, -2);

// Draw left and right sides.
p = TexMan.GetGameTextureByName(border->l);
drawer->AddFlatFill(left - (int)p->GetDisplayWidth(), top, left, bottom, p, true);
p = TexMan.GetGameTextureByName(border->r);
drawer->AddFlatFill(right, top, right + (int)p->GetDisplayWidth(), bottom, p, true);
// Draw left and right sides.
p = TexMan.GetGameTextureByName(border->l);
drawer->AddFlatFill(left - (int)(p->GetDisplayWidth() / sw), top, left, bottom, p, -2);
p = TexMan.GetGameTextureByName(border->r);
drawer->AddFlatFill(right, top, right + (int)(p->GetDisplayWidth() / sw), bottom, p, -2);

// Draw beveled corners.
DrawTexture(drawer, TexMan.GetGameTextureByName(border->tl), left - offset, top - offset, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->tr), left + width, top - offset, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->bl), left - offset, top + height, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->br), left + width, top + height, TAG_DONE);
// Draw beveled corners.
p = TexMan.GetGameTextureByName(border->tl);
drawer->AddFlatFill(left - (int)(p->GetDisplayWidth() / sw), top - (int)(p->GetDisplayHeight() / sh), left, top, p, -2);
p = TexMan.GetGameTextureByName(border->tr);
drawer->AddFlatFill(right, top - (int)(p->GetDisplayHeight() / sh), right + (int)(p->GetDisplayWidth() / sw), top, p, -2);
p = TexMan.GetGameTextureByName(border->bl);
drawer->AddFlatFill(left - (int)(p->GetDisplayWidth() / sw), bottom, left, bottom + (int)(p->GetDisplayHeight() / sh), p, -2);
p = TexMan.GetGameTextureByName(border->br);
drawer->AddFlatFill(right, bottom, right + (int)(p->GetDisplayWidth() / sw), bottom + (int)(p->GetDisplayHeight() / sh), p, -2);
}
}

DEFINE_ACTION_FUNCTION(_Screen, DrawFrame)
Expand Down Expand Up @@ -1038,6 +1070,8 @@ void DBaseStatusBar::RefreshBackground () const

auto tex = GetBorderTexture(primaryLevel);

float sh = twod->GetClassicFlatScalarHeight();

if(!CompleteBorder)
{
if(y < twod->GetHeight())
Expand Down Expand Up @@ -1070,9 +1104,18 @@ void DBaseStatusBar::RefreshBackground () const
FGameTexture *p = TexMan.GetGameTextureByName(gameinfo.Border.b);
if (p != NULL)
{
int h = int(0.5 + p->GetDisplayHeight());
twod->AddFlatFill(0, y, x, y + h, p, true);
twod->AddFlatFill(x2, y, twod->GetWidth(), y + h, p, true);
if (!ui_screenborder_classic_scaling)
{
int h = int(0.5 + p->GetDisplayHeight());
twod->AddFlatFill(0, y, x, y + h, p, true);
twod->AddFlatFill(x2, y, twod->GetWidth(), y + h, p, true);
}
else
{
int h = (int)((0.5f + p->GetDisplayHeight()) / sh);
twod->AddFlatFill(0, y, x, y + h, p, -2);
twod->AddFlatFill(x2, y, twod->GetWidth(), y + h, p, -2);
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/intermission/intermission.cpp
Expand Up @@ -73,6 +73,8 @@ extern int NoWipe;
CVAR(Bool, nointerscrollabort, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, inter_subtitles, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);

CVAR(Bool, inter_classic_scaling, true, CVAR_ARCHIVE);

//==========================================================================
//
// This also gets used by the title loop.
Expand Down Expand Up @@ -221,7 +223,7 @@ void DIntermissionScreen::Drawer ()
}
else
{
twod->AddFlatFill(0,0, twod->GetWidth(), twod->GetHeight(), TexMan.GetGameTexture(mBackground));
twod->AddFlatFill(0,0, twod->GetWidth(), twod->GetHeight(), TexMan.GetGameTexture(mBackground), (inter_classic_scaling ? -1 : 0));
}
}
else
Expand Down

0 comments on commit 6e3ec96

Please sign in to comment.