From ccdf5fb23c42eef33a4509a6aab63be75dbd4913 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 Apr 2022 17:30:20 +0200 Subject: [PATCH] - moved the wipe loop out of d_main.cpp into f_wipe.cpp As preparation fior fully moving it into the backend --- src/common/rendering/i_video.h | 6 ---- src/common/utility/i_time.h | 5 +++ src/d_main.cpp | 66 ++++++++++------------------------ src/menu/doommenu.cpp | 2 +- src/rendering/2d/f_wipe.cpp | 43 ++++++++++++++++++++++ src/rendering/2d/f_wipe.h | 2 ++ 6 files changed, 70 insertions(+), 54 deletions(-) diff --git a/src/common/rendering/i_video.h b/src/common/rendering/i_video.h index d9a9b9701..f33d35caf 100644 --- a/src/common/rendering/i_video.h +++ b/src/common/rendering/i_video.h @@ -29,10 +29,4 @@ void I_PolyPresentUnlock(int x, int y, int w, int h); void I_PolyPresentDeinit(); -// Pause a bit. -// [RH] Despite the name, it apparently never waited for the VBL, even in -// the original DOS version (if the Heretic/Hexen source is any indicator). -void I_WaitVBL(int count); - - #endif // __I_VIDEO_H__ diff --git a/src/common/utility/i_time.h b/src/common/utility/i_time.h index dc0619c37..4e7874bb8 100644 --- a/src/common/utility/i_time.h +++ b/src/common/utility/i_time.h @@ -44,3 +44,8 @@ double I_GetInputFrac(bool const synchronised, double const ticrate = GameTicRat // Reset the last input check to after a lengthy operation void I_ResetInputTime(); + +// Pause a bit. +// [RH] Despite the name, it apparently never waited for the VBL, even in +// the original DOS version (if the Heretic/Hexen source is any indicator). +void I_WaitVBL(int count); diff --git a/src/d_main.cpp b/src/d_main.cpp index f1dd12c38..d534b9620 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -823,9 +823,18 @@ static void DrawRateStuff() } } +static void DrawOverlays() +{ + NetUpdate (); + C_DrawConsole (); + M_Drawer (); + DrawRateStuff(); + if (!hud_toggled) + FStat::PrintStat (twod); +} + static void End2DAndUpdate() { - DrawRateStuff(); twod->End(); CheckBench(); screen->Update(); @@ -842,7 +851,7 @@ static void End2DAndUpdate() void D_Display () { - FGameTexture *wipe = nullptr; + FTexture *wipestart = nullptr; int wipe_type; sector_t *viewsec; @@ -908,7 +917,7 @@ void D_Display () if (NoWipe) { NoWipe--; - wipe = nullptr; + wipestart = nullptr; wipegamestate = gamestate; } // No wipes when in a stereo3D VR mode @@ -917,7 +926,7 @@ void D_Display () if (vr_mode == 0 || vid_rendermode != 4) { // save the current screen if about to wipe - wipe = MakeGameTexture(screen->WipeStartScreen(), nullptr, ETextureType::SWCanvas); + wipestart = screen->WipeStartScreen(); switch (wipegamestate) { @@ -943,7 +952,7 @@ void D_Display () } else { - wipe = nullptr; + wipestart = nullptr; } screen->FrameTime = I_msTimeFS(); @@ -1089,54 +1098,17 @@ void D_Display () } } - if (!wipe || NoWipe < 0 || wipe_type == wipe_None || hud_toggled) + if (!wipestart || NoWipe < 0 || wipe_type == wipe_None || hud_toggled) { - if (wipe != nullptr) delete wipe; - wipe = nullptr; - NetUpdate (); // send out any new accumulation - // normal update - // draw ZScript UI stuff - C_DrawConsole (); // draw console - M_Drawer (); // menu is drawn even on top of everything - if (!hud_toggled) - FStat::PrintStat (twod); + if (wipestart != nullptr) wipestart->DecRef(); + wipestart = nullptr; + DrawOverlays(); End2DAndUpdate (); } else { - // wipe update - uint64_t wipestart, nowtime, diff; - bool done; - - GSnd->SetSfxPaused(true, 1); - I_FreezeTime(true); - twod->End(); - auto wipend = MakeGameTexture(screen->WipeEndScreen(), nullptr, ETextureType::SWCanvas); - auto wiper = Wiper::Create(wipe_type); - wiper->SetTextures(wipe, wipend); - - wipestart = I_msTime(); NetUpdate(); // send out any new accumulation - - do - { - do - { - I_WaitVBL(2); - nowtime = I_msTime(); - diff = (nowtime - wipestart) * 40 / 1000; // Using 35 here feels too slow. - } while (diff < 1); - wipestart = nowtime; - twod->Begin(screen->GetWidth(), screen->GetHeight()); - done = wiper->Run(1); - C_DrawConsole (); // console and - M_Drawer (); // menu are drawn even on top of wipes - End2DAndUpdate (); - NetUpdate (); // [RH] not sure this is needed anymore - } while (!done); - delete wiper; - I_FreezeTime(false); - GSnd->SetSfxPaused(false, 1); + PerformWipe(wipestart, screen->WipeEndScreen(), wipe_type, false, DrawOverlays); } cycles.Unclock(); FrameCycles = cycles; diff --git a/src/menu/doommenu.cpp b/src/menu/doommenu.cpp index 83e84896a..901012380 100644 --- a/src/menu/doommenu.cpp +++ b/src/menu/doommenu.cpp @@ -64,6 +64,7 @@ #include "gameconfigfile.h" #include "d_player.h" #include "teaminfo.h" +#include "i_time.h" #include "hwrenderer/scene/hw_drawinfo.h" EXTERN_CVAR(Int, cl_gfxlocalization) @@ -77,7 +78,6 @@ CVAR(Bool, m_simpleoptions, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) typedef void(*hfunc)(); DMenu* CreateMessageBoxMenu(DMenu* parent, const char* message, int messagemode, bool playsound, FName action = NAME_None, hfunc handler = nullptr); bool OkForLocalization(FTextureID texnum, const char* substitute); -void I_WaitVBL(int count); FNewGameStartup NewGameStartupInfo; diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index 5e345e945..ca0c86ae0 100644 --- a/src/rendering/2d/f_wipe.cpp +++ b/src/rendering/2d/f_wipe.cpp @@ -30,6 +30,8 @@ #include "bitmap.h" #include "hw_material.h" #include "v_draw.h" +#include "s_soundinternal.h" +#include "i_time.h" class FBurnTexture : public FTexture { @@ -396,3 +398,44 @@ bool Wiper_Burn::Run(int ticks) // after an arbitrary maximum time. return done || (BurnTime > 40); } + + +void PerformWipe(FTexture* startimg, FTexture* endimg, int wipe_type, bool stopsound, std::function overlaydrawer) +{ + // wipe update + uint64_t wipestart, nowtime, diff; + bool done; + + GSnd->SetSfxPaused(true, 1); + I_FreezeTime(true); + twod->End(); + assert(startimg != nullptr && endimg != nullptr); + auto starttex = MakeGameTexture(startimg, nullptr, ETextureType::SWCanvas); + auto endtex = MakeGameTexture(endimg, nullptr, ETextureType::SWCanvas); + auto wiper = Wiper::Create(wipe_type); + wiper->SetTextures(starttex, endtex); + + wipestart = I_msTime(); + + do + { + do + { + I_WaitVBL(2); + nowtime = I_msTime(); + diff = (nowtime - wipestart) * 40 / 1000; // Using 35 here feels too slow. + } while (diff < 1); + wipestart = nowtime; + twod->Begin(screen->GetWidth(), screen->GetHeight()); + done = wiper->Run(1); + if (overlaydrawer) overlaydrawer(); + twod->End(); + screen->Update(); + twod->OnFrameDone(); + + } while (!done); + delete wiper; + I_FreezeTime(false); + GSnd->SetSfxPaused(false, 1); + +} diff --git a/src/rendering/2d/f_wipe.h b/src/rendering/2d/f_wipe.h index 9b16b4d38..81452b8d0 100644 --- a/src/rendering/2d/f_wipe.h +++ b/src/rendering/2d/f_wipe.h @@ -56,5 +56,7 @@ public: static Wiper *Create(int type); }; +void PerformWipe(FTexture* startimg, FTexture* endimg, int wipe_type, bool stopsound, std::function overlaydrawer); + #endif