From f17617706d5a65954857c9abf9b9c2f003c3de2e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 21 Apr 2020 21:23:04 +0200 Subject: [PATCH] - moved the scale overrider to v_draw.h. --- src/common/2d/v_draw.cpp | 6 +++++ src/common/2d/v_draw.h | 36 +++++++++++++++++++++++++++++ src/common/textures/animtexture.cpp | 12 +++++----- src/common/textures/animtexture.h | 4 ++-- src/intermission/intermission.cpp | 12 +++++----- src/menu/menu.cpp | 8 +++++-- src/rendering/v_video.cpp | 6 ----- src/rendering/v_video.h | 36 ----------------------------- src/wi_stuff.cpp | 6 ++--- 9 files changed, 65 insertions(+), 61 deletions(-) diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index a85f1ac8a..bf33d6f6a 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -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); +} + diff --git a/src/common/2d/v_draw.h b/src/common/2d/v_draw.h index e42b6f306..fe76272f5 100644 --- a/src/common/2d/v_draw.h +++ b/src/common/2d/v_draw.h @@ -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; + } +}; diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp index e1ebd1b6c..a39624498 100644 --- a/src/common/textures/animtexture.cpp +++ b/src/common/textures/animtexture.cpp @@ -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(tex[0]->GetTexture())->SetFrameSize(width, height); + static_cast(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(tex[active]->GetTexture())->SetFrame(palette, data); } -FTexture * AnimTextures::GetFrame() +FGameTexture * AnimTextures::GetFrame() { return tex[active]; } diff --git a/src/common/textures/animtexture.h b/src/common/textures/animtexture.h index 668671a9d..74414fee4 100644 --- a/src/common/textures/animtexture.h +++ b/src/common/textures/animtexture.h @@ -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(); }; diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index be331a3a1..e8b578b19 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -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; diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 740c6f676..4a4b15ae2 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -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; + } } //============================================================================= diff --git a/src/rendering/v_video.cpp b/src/rendering/v_video.cpp index a4c59283e..958486e30 100644 --- a/src/rendering/v_video.cpp +++ b/src/rendering/v_video.cpp @@ -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(); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 29affa251..cdfbb7594 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -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__ diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index 4334d170d..2050683e4 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -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 };