From 5ff1b1b5d20a0402c571ebc9bba23d88fcfa93eb Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Wed, 11 Nov 2020 19:35:10 +0200
Subject: Revert "SL-13565, clean up now-orphaned throttling variable and
 handling code"

This reverts commit 6c1a15d936763dc14f368e10bd53c6e351bf0136.
---
 indra/newview/app_settings/settings.xml | 11 +++++++++++
 indra/newview/llappviewer.cpp           | 20 +++++++++++++++++++-
 indra/newview/llappviewer.h             |  7 ++++++-
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index c6cc93a8c3..c0166f158e 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -812,6 +812,17 @@
       <key>Value</key>
       <integer>0</integer>
     </map>
+    <key>FramePerSecondLimit</key>
+    <map>
+      <key>Comment</key>
+      <string>Controls upper limit of frames per second</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>U32</string>
+      <key>Value</key>
+      <integer>120</integer>
+    </map>
     <key>BackgroundYieldTime</key>
     <map>
       <key>Comment</key>
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 384b644dd5..60421899f7 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -689,7 +689,8 @@ LLAppViewer::LLAppViewer()
 	mPeriodicSlowFrame(LLCachedControl<bool>(gSavedSettings,"Periodic Slow Frame", FALSE)),
 	mFastTimerLogThread(NULL),
 	mSettingsLocationList(NULL),
-	mIsFirstRun(false)
+	mIsFirstRun(false),
+	mMinMicroSecPerFrame(0.f)
 {
 	if(NULL != sInstance)
 	{
@@ -1258,6 +1259,10 @@ bool LLAppViewer::init()
 
 	joystick = LLViewerJoystick::getInstance();
 	joystick->setNeedsReset(true);
+	/*----------------------------------------------------------------------*/
+
+	gSavedSettings.getControl("FramePerSecondLimit")->getSignal()->connect(boost::bind(&LLAppViewer::onChangeFrameLimit, this, _2));
+	onChangeFrameLimit(gSavedSettings.getLLSD("FramePerSecondLimit"));
 
 	return true;
 }
@@ -5432,6 +5437,19 @@ void LLAppViewer::disconnectViewer()
 	LLUrlEntryParcel::setDisconnected(gDisconnected);
 }
 
+bool LLAppViewer::onChangeFrameLimit(LLSD const & evt)
+{
+	if (evt.asInteger() > 0)
+	{
+		mMinMicroSecPerFrame = (U64)(1000000.0f / F32(evt.asInteger()));
+	}
+	else
+	{
+		mMinMicroSecPerFrame = 0;
+	}
+	return false;
+}
+
 void LLAppViewer::forceErrorLLError()
 {
    	LL_ERRS() << "This is a deliberate llerror" << LL_ENDL;
diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h
index 4352905f7d..eaebc896d0 100644
--- a/indra/newview/llappviewer.h
+++ b/indra/newview/llappviewer.h
@@ -257,6 +257,8 @@ private:
     void sendLogoutRequest();
     void disconnectViewer();
 
+	bool onChangeFrameLimit(LLSD const & evt);
+
 	// *FIX: the app viewer class should be some sort of singleton, no?
 	// Perhaps its child class is the singleton and this should be an abstract base.
 	static LLAppViewer* sInstance; 
@@ -313,7 +315,10 @@ private:
 	// llcorehttp library init/shutdown helper
 	LLAppCoreHttp mAppCoreHttp;
 
-    bool mIsFirstRun;
+        bool mIsFirstRun;
+	U64 mMinMicroSecPerFrame; // frame throttling
+
+
 };
 
 // consts from viewer.h
-- 
cgit v1.2.3