From 923833ccec692d7c165f1e6e5aefec542a34aeef Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 31 Aug 2020 19:56:13 +0200 Subject: [PATCH] - animated menus without frame rate cap The frame rate cap is only deactivated if there's actual animations running so that leaving the game in the menu won't make the engine run at high frame rates. Fixes #288. --- source/core/mainloop.cpp | 4 +--- source/core/menu/imagescroller.cpp | 1 + source/core/menu/menu.cpp | 10 ++++++++++ source/core/menu/menu.h | 5 +++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index d078c7165..3fbda02b3 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -331,9 +331,7 @@ void TryRunTics (void) // If paused, do not eat more CPU time than we need, because it // will all be wasted anyway. - if (pauseext) - r_NoInterpolate = true; - bool doWait = cl_capfps || r_NoInterpolate; + bool doWait = cl_capfps || pauseext || (r_NoInterpolate && !M_IsAnimated()); // get real tics if (doWait) diff --git a/source/core/menu/imagescroller.cpp b/source/core/menu/imagescroller.cpp index 882dbc7bf..47bfa7ff9 100644 --- a/source/core/menu/imagescroller.cpp +++ b/source/core/menu/imagescroller.cpp @@ -94,6 +94,7 @@ void DImageScrollerMenu::Init(DMenu* parent, FImageScrollerDescriptor* desc) mCurrent = newImageScreen(&mDesc->mItems[0]); mCurrent->canAnimate = canAnimate; + isAnimated = true; } bool DImageScrollerMenu::MenuEvent(int mkey, bool fromcontroller) diff --git a/source/core/menu/menu.cpp b/source/core/menu/menu.cpp index 4395b543a..623775e0c 100644 --- a/source/core/menu/menu.cpp +++ b/source/core/menu/menu.cpp @@ -1026,6 +1026,16 @@ void M_EnableMenu (bool on) } +bool M_IsAnimated() +{ + if (ConsoleState == c_down) return false; + if (!CurrentMenu) return false; + if (CurrentMenu->IsAnimated()) return true; + if(transition.previous) return true; + return false; +} + + //============================================================================= // // [RH] Most menus can now be accessed directly diff --git a/source/core/menu/menu.h b/source/core/menu/menu.h index 819c7e459..453ebe885 100644 --- a/source/core/menu/menu.h +++ b/source/core/menu/menu.h @@ -325,6 +325,7 @@ public: DVector2 origin = { 0,0 }; int scriptID = INT_MAX; bool canAnimate = false; + bool isAnimated = false; // set to true when uncapped frame rate is needed. DMenu(DMenu *parent = NULL); virtual ~DMenu() = default; @@ -339,6 +340,7 @@ public: virtual void Close(); virtual bool MouseEvent(int type, int x, int y); virtual void Destroy() {} + bool IsAnimated() const { return isAnimated; } bool MouseEventBack(int type, int x, int y); void SetCapture(); void ReleaseCapture(); @@ -836,4 +838,7 @@ public: extern FSavegameManager savegameManager; extern DMenu* CurrentMenu; +bool M_IsAnimated(); + + #endif