- moved the scale overrider to v_draw.h.

This commit is contained in:
Christoph Oelckers 2020-04-21 21:23:04 +02:00
parent ce95d7379f
commit f17617706d
9 changed files with 65 additions and 61 deletions

View file

@ -1384,3 +1384,9 @@ void DrawFrame(F2DDrawer* twod, PalEntry color, int left, int top, int width, in
twod->AddColorOnlyQuad(right, top - offset, offset, height + 2 * offset, color);
}
void V_CalcCleanFacs(int designwidth, int designheight, int realwidth, int realheight, int* cleanx, int* cleany, int* _cx1, int* _cx2)
{
if (designheight < 240 && realheight >= 480) designheight = 240;
*cleanx = *cleany = std::min(realwidth / designwidth, realheight / designheight);
}

View file

@ -233,3 +233,39 @@ void VirtualToRealCoordsInt(F2DDrawer* drawer, int& x, int& y, int& w, int& h, i
extern int CleanWidth, CleanHeight, CleanXfac, CleanYfac;
extern int CleanWidth_1, CleanHeight_1, CleanXfac_1, CleanYfac_1;
void V_CalcCleanFacs(int designwidth, int designheight, int realwidth, int realheight, int* cleanx, int* cleany, int* cx1 = NULL, int* cx2 = NULL);
class ScaleOverrider
{
int savedxfac, savedyfac, savedwidth, savedheight;
public:
// This is to allow certain elements to use an optimal fullscreen scale which for the menu would be too large.
// The old code contained far too much mess to compensate for the menus which negatively affected everything else.
// However, for compatibility reasons the currently used variables cannot be changed so they have to be overridden temporarily.
// This class provides a safe interface for this because it ensures that the values get restored afterward.
// Currently, the intermission and the level summary screen use this.
ScaleOverrider(F2DDrawer *drawer)
{
savedxfac = CleanXfac;
savedyfac = CleanYfac;
savedwidth = CleanWidth;
savedheight = CleanHeight;
if (drawer)
{
V_CalcCleanFacs(320, 200, drawer->GetWidth(), drawer->GetHeight(), &CleanXfac, &CleanYfac);
CleanWidth = drawer->GetWidth() / CleanXfac;
CleanHeight = drawer->GetHeight() / CleanYfac;
}
}
~ScaleOverrider()
{
CleanXfac = savedxfac;
CleanYfac = savedyfac;
CleanWidth = savedwidth;
CleanHeight = savedheight;
}
};

View file

@ -88,8 +88,8 @@ FBitmap AnimTexture::GetBgraBitmap(const PalEntry* remap, int* trans)
AnimTextures::AnimTextures()
{
active = 1;
tex[0] = new AnimTexture;
tex[1] = new AnimTexture;
tex[0] = MakeGameTexture(new AnimTexture, "", ETextureType::Special);
tex[1] = MakeGameTexture(new AnimTexture, "", ETextureType::Special);
}
AnimTextures::~AnimTextures()
@ -100,17 +100,17 @@ AnimTextures::~AnimTextures()
void AnimTextures::SetSize(int width, int height)
{
tex[0]->SetFrameSize(width, height);
tex[1]->SetFrameSize(width, height);
static_cast<AnimTexture*>(tex[0]->GetTexture())->SetFrameSize(width, height);
static_cast<AnimTexture*>(tex[1]->GetTexture())->SetFrameSize(width, height);
}
void AnimTextures::SetFrame(const uint8_t *palette, const void* data)
{
active ^= 1;
tex[active]->SetFrame(palette, data);
static_cast<AnimTexture*>(tex[active]->GetTexture())->SetFrame(palette, data);
}
FTexture * AnimTextures::GetFrame()
FGameTexture * AnimTextures::GetFrame()
{
return tex[active];
}

View file

@ -17,12 +17,12 @@ public:
class AnimTextures
{
int active;
AnimTexture *tex[2];
FGameTexture *tex[2];
public:
AnimTextures();
~AnimTextures();
void SetSize(int width, int height);
void SetFrame(const uint8_t *palette, const void* data);
FTexture *GetFrame();
FGameTexture *GetFrame();
};

View file

@ -941,7 +941,7 @@ void DIntermissionController::OnDestroy ()
void F_StartIntermission(FIntermissionDescriptor *desc, bool deleteme, uint8_t state)
{
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
if (DIntermissionController::CurrentIntermission != NULL)
{
DIntermissionController::CurrentIntermission->Destroy();
@ -987,7 +987,7 @@ void F_StartIntermission(FName seq, uint8_t state)
bool F_Responder (event_t* ev)
{
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
if (DIntermissionController::CurrentIntermission != NULL)
{
return DIntermissionController::CurrentIntermission->Responder(ev);
@ -1003,7 +1003,7 @@ bool F_Responder (event_t* ev)
void F_Ticker ()
{
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
if (DIntermissionController::CurrentIntermission != NULL)
{
DIntermissionController::CurrentIntermission->Ticker();
@ -1018,7 +1018,7 @@ void F_Ticker ()
void F_Drawer ()
{
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
if (DIntermissionController::CurrentIntermission != NULL)
{
DIntermissionController::CurrentIntermission->Drawer();
@ -1034,7 +1034,7 @@ void F_Drawer ()
void F_EndFinale ()
{
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
if (DIntermissionController::CurrentIntermission != NULL)
{
DIntermissionController::CurrentIntermission->Destroy();
@ -1050,7 +1050,7 @@ void F_EndFinale ()
void F_AdvanceIntermission()
{
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
if (DIntermissionController::CurrentIntermission != NULL)
{
DIntermissionController::CurrentIntermission->mAdvance = true;

View file

@ -381,8 +381,12 @@ void M_StartControlPanel (bool makeSound, bool scaleoverride)
}
BackbuttonTime = 0;
BackbuttonAlpha = 0;
if (scaleoverride && !CurrentScaleOverrider) CurrentScaleOverrider = new ScaleOverrider;
else if (!scaleoverride && CurrentScaleOverrider) delete CurrentScaleOverrider;
if (scaleoverride && !CurrentScaleOverrider) CurrentScaleOverrider = new ScaleOverrider(&screen->m2DDrawer);
else if (!scaleoverride && CurrentScaleOverrider)
{
delete CurrentScaleOverrider;
CurrentScaleOverrider = nullptr;
}
}
//=============================================================================

View file

@ -336,12 +336,6 @@ void V_OutputResized (int width, int height)
primaryLevel->automap->NewResolution();
}
void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *_cx1, int *_cx2)
{
if (designheight < 240 && realheight >= 480) designheight = 240;
*cleanx = *cleany = std::min(realwidth / designwidth, realheight / designheight);
}
bool IVideo::SetResolution ()
{
DFrameBuffer *buff = CreateFrameBuffer();

View file

@ -117,7 +117,6 @@ extern int DisplayWidth, DisplayHeight;
void V_UpdateModeSize (int width, int height);
void V_OutputResized (int width, int height);
void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *cx1=NULL, int *cx2=NULL);
EXTERN_CVAR(Int, vid_rendermode)
EXTERN_CVAR(Bool, vid_fullscreen)
@ -193,8 +192,6 @@ public:
private:
int Width = 0;
int Height = 0;
public:
//int clipleft = 0, cliptop = 0, clipwidth = -1, clipheight = -1;
public:
// Hardware render state that needs to be exposed to the API independent part of the renderer. For ease of access this is stored in the base class.
@ -385,39 +382,6 @@ inline bool IsRatioWidescreen(int ratio) { return (ratio & 3) != 0; }
#include "v_draw.h"
class ScaleOverrider
{
int savedxfac, savedyfac, savedwidth, savedheight;
public:
// This is to allow certain elements to use an optimal fullscreen scale which for the menu would be too large.
// The old code contained far too much mess to compensate for the menus which negatively affected everything else.
// However, for compatibility reasons the currently used variables cannot be changed so they have to be overridden temporarily.
// This class provides a safe interface for this because it ensures that the values get restored afterward.
// Currently, the intermission and the level summary screen use this.
ScaleOverrider()
{
savedxfac = CleanXfac;
savedyfac = CleanYfac;
savedwidth = CleanWidth;
savedheight = CleanHeight;
if (screen)
{
V_CalcCleanFacs(320, 200, screen->GetWidth(), screen->GetHeight(), &CleanXfac, &CleanYfac);
CleanWidth = screen->GetWidth() / CleanXfac;
CleanHeight = screen->GetHeight() / CleanYfac;
}
}
~ScaleOverrider()
{
CleanXfac = savedxfac;
CleanYfac = savedyfac;
CleanWidth = savedwidth;
CleanHeight = savedheight;
}
};
#endif // __V_VIDEO_H__

View file

@ -701,7 +701,7 @@ void WI_Ticker()
{
if (WI_Screen)
{
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Ticker)
{
VMValue self = WI_Screen;
@ -721,7 +721,7 @@ void WI_Drawer()
{
if (WI_Screen)
{
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Drawer)
{
FillBorder(twod, nullptr);
@ -765,7 +765,7 @@ void WI_Start(wbstartstruct_t *wbstartstruct)
}
WI_Screen = cls->CreateNew();
ScaleOverrider s;
ScaleOverrider s(&screen->m2DDrawer);
IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Start)
{
VMValue val[2] = { WI_Screen, wbstartstruct };