diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 8520d3227..3d145c07f 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -2965,19 +2965,10 @@ void DrawFullscreenBlends(); // void videoNextPage(void) { - static bool recursion; - - if (!recursion) - { - // This protection is needed because the menu can call scripts from inside its drawers and the scripts can call the busy-looping Screen_Play script event - // which calls videoNextPage for page flipping again. In this loop the UI drawers may not get called again. - // Ideally this stuff should be moved out of videoNextPage so that all those busy loops won't call UI overlays at all. - recursion = true; - FStat::PrintStat(twod); - C_DrawConsole(); - M_Drawer(); - recursion = false; - } + // Draw overlay elements to the 2D drawer + FStat::PrintStat(twod); + C_DrawConsole(); + M_Drawer(); // Handle the final 2D overlays. DrawFullscreenBlends(); @@ -2999,8 +2990,10 @@ void videoNextPage(void) beforedrawrooms = 1; numframes++; + // This should be in the main loop but with some of the games still having multiple render loops it cannot be moved out of here twod->SetSize(screen->GetWidth(), screen->GetHeight()); twodpsp.SetSize(screen->GetWidth(), screen->GetHeight()); + I_SetFrameTime(); } // diff --git a/source/common/utility/i_time.cpp b/source/common/utility/i_time.cpp index 8797ebdee..2db0d4918 100644 --- a/source/common/utility/i_time.cpp +++ b/source/common/utility/i_time.cpp @@ -150,6 +150,11 @@ uint64_t I_msTimeFS() // from "start" return (FirstFrameStartTime == 0) ? 0 : NSToMS(I_nsTime() - FirstFrameStartTime); } +uint64_t I_GetTimeNS() +{ + return CurrentFrameStartTime - FirstFrameStartTime; +} + int I_GetTime() { return NSToTic(CurrentFrameStartTime - FirstFrameStartTime); diff --git a/source/common/utility/i_time.h b/source/common/utility/i_time.h index b0ff122f4..71f436dbf 100644 --- a/source/common/utility/i_time.h +++ b/source/common/utility/i_time.h @@ -9,6 +9,8 @@ void I_SetFrameTime(); // Called by D_DoomLoop, returns current time in tics. int I_GetTime(); +// same, but using nanoseconds +uint64_t I_GetTimeNS(); double I_GetTimeFrac(); diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index f1e56e4b0..0f080054e 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1038,7 +1038,7 @@ void S_SetSoundPaused(int state) } } -int CalcSmoothRatio(const ClockTicks &totalclk, const ClockTicks &ototalclk, int realgameticspersec) +int CalcSmoothRatio(ClockTicks totalclk, ClockTicks ototalclk, int realgameticspersec) { double ratio; int result; @@ -1051,7 +1051,7 @@ int CalcSmoothRatio(const ClockTicks &totalclk, const ClockTicks &ototalclk, int if (!cl_legacyintrpl) { double const gametics = 1'000'000'000. / realgameticspersec; - uint64_t currentTime = I_nsTime(); + uint64_t currentTime = I_GetTimeNS(); if ((lastototalclk == ototalclk) && (lastTime != 0)) { diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 61b2de7d0..d4ead5fda 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -192,7 +192,7 @@ void S_ResumeSound(bool notsfx); void S_SetSoundPaused(int state); void G_FatalEngineError(void); -int CalcSmoothRatio(const ClockTicks& totalclk, const ClockTicks& ototalclk, int realgameticspersec); +int CalcSmoothRatio(ClockTicks totalclk, ClockTicks ototalclk, int realgameticspersec); enum { MaxSmoothRatio = FRACUNIT