From ea53cb13077e4b05e1f5beafa1eee94e36c76255 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sun, 12 Apr 2020 13:27:24 -0400
Subject: [PATCH] Cache many more settings called in draw or heavy loops

---
 indra/newview/alcontrolcache.cpp        | 12 ++++++++
 indra/newview/alcontrolcache.h          |  6 ++++
 indra/newview/llagent.cpp               |  2 +-
 indra/newview/llfloateravatarpicker.cpp |  2 +-
 indra/newview/llfloaterimcontainer.cpp  |  2 +-
 indra/newview/llfloatersnapshot.cpp     |  4 +--
 indra/newview/llpanelpeople.cpp         |  5 ++--
 indra/newview/llsnapshotlivepreview.cpp |  4 +--
 indra/newview/lltexturectrl.cpp         |  2 +-
 indra/newview/lltextureview.cpp         |  4 +--
 indra/newview/llviewerjoystick.cpp      |  4 +--
 indra/newview/llviewerkeyboard.cpp      |  2 +-
 indra/newview/llviewertexlayer.cpp      |  2 +-
 indra/newview/llvoavatar.cpp            |  2 +-
 indra/newview/llworldmapview.cpp        | 38 ++++++++++++-------------
 15 files changed, 54 insertions(+), 37 deletions(-)

diff --git a/indra/newview/alcontrolcache.cpp b/indra/newview/alcontrolcache.cpp
index eaf05a3bfde..adfa6e435b6 100644
--- a/indra/newview/alcontrolcache.cpp
+++ b/indra/newview/alcontrolcache.cpp
@@ -3,6 +3,9 @@
 #include "alcontrolcache.h"
 #include "llviewercontrol.h"
 
+bool ALControlCache::AutoSnapshot = false;
+bool ALControlCache::AutomaticFly = true;
+bool ALControlCache::DebugAvatarRezTime = false;
 bool ALControlCache::EditLinkedParts = false;
 F32  ALControlCache::GridDrawSize;
 F32  ALControlCache::GridOpacity;
@@ -14,7 +17,10 @@ bool ALControlCache::MapShowLandForSale;
 bool ALControlCache::MapShowPeople;
 bool ALControlCache::MapShowTelehubs;
 bool ALControlCache::NavBarShowParcelProperties = true;
+F32	 ALControlCache::NearMeRange = 4096.f;
 U32  ALControlCache::PreferredMaturity;
+bool ALControlCache::ShowAdultEvents;
+bool ALControlCache::ShowMatureEvents;
 bool ALControlCache::SnapEnabled;
 S32  ALControlCache::ToastGap;
 
@@ -46,6 +52,9 @@ S32  ALControlCache::ToastGap;
 void ALControlCache::initControls()
 {
 	// Keep this list alphabatized.
+	DECLARE_CTRL_BOOL(AutoSnapshot);
+	DECLARE_CTRL_BOOL(AutomaticFly);
+	DECLARE_CTRL_BOOL(DebugAvatarRezTime);
 	DECLARE_CTRL_BOOL(EditLinkedParts);
 	DECLARE_CTRL_F32(GridDrawSize);
 	DECLARE_CTRL_F32(GridOpacity);
@@ -57,7 +66,10 @@ void ALControlCache::initControls()
 	DECLARE_CTRL_BOOL(MapShowPeople);
 	DECLARE_CTRL_BOOL(MapShowTelehubs);
 	DECLARE_CTRL_BOOL(NavBarShowParcelProperties);
+	DECLARE_CTRL_F32(NearMeRange);
 	DECLARE_CTRL_U32(PreferredMaturity);
+	DECLARE_CTRL_BOOL(ShowAdultEvents);
+	DECLARE_CTRL_BOOL(ShowMatureEvents);
 	DECLARE_CTRL_BOOL(SnapEnabled);
 	DECLARE_CTRL_S32(ToastGap);
 }
diff --git a/indra/newview/alcontrolcache.h b/indra/newview/alcontrolcache.h
index 596ca5b1b4e..eb24ba7e230 100644
--- a/indra/newview/alcontrolcache.h
+++ b/indra/newview/alcontrolcache.h
@@ -5,6 +5,9 @@ struct ALControlCache
 {
 	static void initControls();
 
+	static bool		AutoSnapshot;
+	static bool		AutomaticFly;
+	static bool		DebugAvatarRezTime;
 	static bool		EditLinkedParts;
 	static F32		GridDrawSize;
 	static F32		GridOpacity;
@@ -16,7 +19,10 @@ struct ALControlCache
 	static bool		MapShowPeople;
 	static bool		MapShowTelehubs;
 	static bool		NavBarShowParcelProperties;
+	static F32		NearMeRange;
 	static U32		PreferredMaturity;
+	static bool		ShowAdultEvents;
+	static bool		ShowMatureEvents;
 	static bool		SnapEnabled;
 	static S32		ToastGap;
 };
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 147e7a291a6..d7937d861d5 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -1934,7 +1934,7 @@ void LLAgent::propagate(const F32 dt)
 		if (!in_air 
 			&& gAgentCamera.getUpKey() < 0 
 			&& land_vel.magVecSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED
-			&& gSavedSettings.getBOOL("AutomaticFly"))
+			&& ALControlCache::AutomaticFly)
 		{
 			// land automatically
 			setFlying(FALSE);
diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp
index f9f3f7921cd..8fb69c60ec5 100644
--- a/indra/newview/llfloateravatarpicker.cpp
+++ b/indra/newview/llfloateravatarpicker.cpp
@@ -312,7 +312,7 @@ void LLFloaterAvatarPicker::populateNearMe()
 	near_me_scroller->deleteAllItems();
 
 	uuid_vec_t avatar_ids;
-	LLWorld::getInstance()->getAvatars(&avatar_ids, NULL, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange"));
+	LLWorld::getInstance()->getAvatars(&avatar_ids, NULL, gAgent.getPositionGlobal(), ALControlCache::NearMeRange);
 	for(U32 i=0; i<avatar_ids.size(); i++)
 	{
 		LLUUID& av = avatar_ids[i];
diff --git a/indra/newview/llfloaterimcontainer.cpp b/indra/newview/llfloaterimcontainer.cpp
index 25e9cd50c5e..6abe6450434 100644
--- a/indra/newview/llfloaterimcontainer.cpp
+++ b/indra/newview/llfloaterimcontainer.cpp
@@ -1710,7 +1710,7 @@ void LLFloaterIMContainer::setNearbyDistances()
 		// Get the positions of the nearby avatars and their ids
 		std::vector<LLVector3d> positions;
 		uuid_vec_t avatar_ids;
-		LLWorld::getInstance()->getAvatars(&avatar_ids, &positions, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange"));
+		LLWorld::getInstance()->getAvatars(&avatar_ids, &positions, gAgent.getPositionGlobal(), ALControlCache::NearMeRange);
 		// Get the position of the agent
 		const LLVector3d& me_pos = gAgent.getPositionGlobal();
 		// For each nearby avatar, compute and update the distance
diff --git a/indra/newview/llfloatersnapshot.cpp b/indra/newview/llfloatersnapshot.cpp
index 5f89e868a42..19102fa5ab1 100644
--- a/indra/newview/llfloatersnapshot.cpp
+++ b/indra/newview/llfloatersnapshot.cpp
@@ -415,7 +415,7 @@ void LLFloaterSnapshotBase::ImplBase::setNeedRefresh(bool need)
 	if (!mFloater) return;
 
 	// Don't display the "Refresh to save" message if we're in auto-refresh mode.
-	if (gSavedSettings.getBOOL("AutoSnapshot"))
+	if (ALControlCache::AutoSnapshot)
 	{
 		need = false;
 	}
@@ -429,7 +429,7 @@ void LLFloaterSnapshotBase::ImplBase::checkAutoSnapshot(LLSnapshotLivePreview* p
 {
 	if (previewp)
 	{
-		BOOL autosnap = gSavedSettings.getBOOL("AutoSnapshot");
+		BOOL autosnap = ALControlCache::AutoSnapshot;
 		LL_DEBUGS() << "updating " << (autosnap ? "snapshot" : "thumbnail") << LL_ENDL;
 		previewp->updateSnapshot(autosnap, update_thumbnail, autosnap ? AUTO_SNAPSHOT_TIME_DELAY : 0.f);
 	}
diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp
index 9975119c569..325657745d5 100644
--- a/indra/newview/llpanelpeople.cpp
+++ b/indra/newview/llpanelpeople.cpp
@@ -834,7 +834,7 @@ void LLPanelPeople::updateNearbyList()
 	if (RlvActions::canShowNearbyAgents())
 	{
 // [/RLVa:KB]
-		LLWorld::getInstance()->getAvatars(&mNearbyList->getIDs(), &positions, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange"));
+		LLWorld::getInstance()->getAvatars(&mNearbyList->getIDs(), &positions, gAgent.getPositionGlobal(), ALControlCache::NearMeRange);
 // [RLVa:KB] - Checked: RLVa-2.0.3
 	}
 	else
@@ -1620,8 +1620,7 @@ bool LLPanelPeople::updateNearbyArrivalTime()
 {
 	std::vector<LLVector3d> positions;
 	std::vector<LLUUID> uuids;
-	static LLCachedControl<F32> range(gSavedSettings, "NearMeRange");
-	LLWorld::getInstance()->getAvatars(&uuids, &positions, gAgent.getPositionGlobal(), range);
+	LLWorld::getInstance()->getAvatars(&uuids, &positions, gAgent.getPositionGlobal(), ALControlCache::NearMeRange);
 	LLRecentPeople::instance().updateAvatarsArrivalTime(uuids);
 	return LLApp::isExiting();
 }
diff --git a/indra/newview/llsnapshotlivepreview.cpp b/indra/newview/llsnapshotlivepreview.cpp
index e35cb764f37..65d1b2f3391 100644
--- a/indra/newview/llsnapshotlivepreview.cpp
+++ b/indra/newview/llsnapshotlivepreview.cpp
@@ -671,14 +671,14 @@ BOOL LLSnapshotLivePreview::onIdle( void* snapshot_preview )
 	LLVector3 new_camera_pos = LLViewerCamera::getInstance()->getOrigin();
 	LLQuaternion new_camera_rot = LLViewerCamera::getInstance()->getQuaternion();
 	if (previewp->mForceUpdateSnapshot ||
-		(((gSavedSettings.getBOOL("AutoSnapshot") && LLView::isAvailable(previewp->mViewContainer)) ||
+		(((ALControlCache::AutoSnapshot && LLView::isAvailable(previewp->mViewContainer)) ||
 		(LLPipeline::FreezeTime && previewp->mAllowFullScreenPreview)) &&
 		(new_camera_pos != previewp->mCameraPos || dot(new_camera_rot, previewp->mCameraRot) < 0.995f)))
 	{
 		previewp->mCameraPos = new_camera_pos;
 		previewp->mCameraRot = new_camera_rot;
 		// request a new snapshot whenever the camera moves, with a time delay
-		BOOL new_snapshot = gSavedSettings.getBOOL("AutoSnapshot") || previewp->mForceUpdateSnapshot;
+		BOOL new_snapshot = ALControlCache::AutoSnapshot || previewp->mForceUpdateSnapshot;
 		LL_DEBUGS() << "camera moved, updating thumbnail" << LL_ENDL;
 		previewp->updateSnapshot(
 			new_snapshot, // whether a new snapshot is needed or merely invalidate the existing one
diff --git a/indra/newview/lltexturectrl.cpp b/indra/newview/lltexturectrl.cpp
index 1df0820e926..fe0134e9d31 100644
--- a/indra/newview/lltexturectrl.cpp
+++ b/indra/newview/lltexturectrl.cpp
@@ -1699,7 +1699,7 @@ void LLTextureCtrl::draw()
 		}
 
 		// Optionally show more detailed information.
-		if (gSavedSettings.getBOOL("DebugAvatarRezTime"))
+		if (ALControlCache::DebugAvatarRezTime)
 		{
 			LLFontGL* font = LLFontGL::getFontSansSerif();
 			std::string tdesc;
diff --git a/indra/newview/lltextureview.cpp b/indra/newview/lltextureview.cpp
index 0d2edc0268e..2a122fe8d12 100644
--- a/indra/newview/lltextureview.cpp
+++ b/indra/newview/lltextureview.cpp
@@ -409,7 +409,7 @@ class LLAvatarTexBar : public LLView
 
 void LLAvatarTexBar::draw()
 {	
-	if (!gSavedSettings.getBOOL("DebugAvatarRezTime")) return;
+	if (!ALControlCache::DebugAvatarRezTime) return;
 
 	LLVOAvatarSelf* avatarp = gAgentAvatarp;
 	if (!avatarp) return;
@@ -465,7 +465,7 @@ LLRect LLAvatarTexBar::getRequiredRect()
 {
 	LLRect rect;
 	rect.mTop = 100;
-	if (!gSavedSettings.getBOOL("DebugAvatarRezTime")) rect.mTop = 0;
+	if (!ALControlCache::DebugAvatarRezTime) rect.mTop = 0;
 	return rect;
 }
 
diff --git a/indra/newview/llviewerjoystick.cpp b/indra/newview/llviewerjoystick.cpp
index 06e1e643005..82cbcb86ac0 100644
--- a/indra/newview/llviewerjoystick.cpp
+++ b/indra/newview/llviewerjoystick.cpp
@@ -395,7 +395,7 @@ void LLViewerJoystick::agentFly(F32 inc)
 		if (! (gAgent.getFlying() ||
 		       !gAgent.canFly() ||
 		       gAgent.upGrabbed() ||
-		       !gSavedSettings.getBOOL("AutomaticFly")) )
+		       !ALControlCache::AutomaticFly) )
 		{
 			gAgent.setFlying(true);
 		}
@@ -625,7 +625,7 @@ void LLViewerJoystick::moveAvatar(bool reset)
 		// jump (as the up/down axis already controls flying) if on the
 		// ground, or cease flight if already flying.
 		// If AutomaticFly is disabled, then button1 toggles flying.
-		if (gSavedSettings.getBOOL("AutomaticFly"))
+		if (ALControlCache::AutomaticFly)
 		{
 			if (!gAgent.getFlying())
 			{
diff --git a/indra/newview/llviewerkeyboard.cpp b/indra/newview/llviewerkeyboard.cpp
index 952c80ad40f..9dc521c3563 100644
--- a/indra/newview/llviewerkeyboard.cpp
+++ b/indra/newview/llviewerkeyboard.cpp
@@ -76,7 +76,7 @@ void agent_jump( EKeystate s )
 	if( time < FLY_TIME 
 		|| frame_count <= FLY_FRAMES 
 		|| gAgent.upGrabbed()
-		|| !gSavedSettings.getBOOL("AutomaticFly"))
+		|| !ALControlCache::AutomaticFly)
 	{
 		gAgent.moveUp(1);
 	}
diff --git a/indra/newview/llviewertexlayer.cpp b/indra/newview/llviewertexlayer.cpp
index cdcaff8015c..6e630577792 100644
--- a/indra/newview/llviewertexlayer.cpp
+++ b/indra/newview/llviewertexlayer.cpp
@@ -237,7 +237,7 @@ void LLViewerTexLayerSetBuffer::doUpdate()
 	layer_set->getAvatar()->updateMeshTextures();
 	
 	// Print out notification that we updated this texture.
-	if (gSavedSettings.getBOOL("DebugAvatarRezTime"))
+	if (ALControlCache::DebugAvatarRezTime)
 	{
 		const BOOL highest_lod = layer_set->isLocalTextureDataFinal();
 		const std::string lod_str = highest_lod ? "HighRes" : "LowRes";
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 01777d63d5f..f60d318aa27 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -775,7 +775,7 @@ void LLVOAvatar::debugAvatarRezTime(std::string notification_name, std::string c
 					   << " : " << comment
 					   << LL_ENDL;
 
-	if (gSavedSettings.getBOOL("DebugAvatarRezTime"))
+	if (ALControlCache::DebugAvatarRezTime)
 	{
 		LLSD args;
 		args["EXISTENCE"] = llformat("%d",(U32)mDebugExistenceTimer.getElapsedTimeF32());
diff --git a/indra/newview/llworldmapview.cpp b/indra/newview/llworldmapview.cpp
index a4b68c6d01c..aa9920d9e9c 100644
--- a/indra/newview/llworldmapview.cpp
+++ b/indra/newview/llworldmapview.cpp
@@ -416,7 +416,7 @@ void LLWorldMapView::draw()
 			gGL.end();
 		}
 		 **********************/
-		else if (gSavedSettings.getBOOL("MapShowLandForSale") && (level <= DRAW_LANDFORSALE_THRESHOLD))
+		else if (ALControlCache::MapShowLandForSale && (level <= DRAW_LANDFORSALE_THRESHOLD))
 		{
 			// Draw the overlay image "Land for Sale / Land for Auction"
 			LLViewerFetchedTexture* overlayimage = info->getLandForSaleImage();
@@ -512,12 +512,12 @@ void LLWorldMapView::draw()
 	gGL.setSceneBlendType(LLRender::BT_ALPHA);
 
 	// Draw item infos if we're not zoomed out too much and there's something to draw
-	if ((level <= DRAW_SIMINFO_THRESHOLD) && (gSavedSettings.getBOOL("MapShowInfohubs") || 
-											  gSavedSettings.getBOOL("MapShowTelehubs") ||
-											  gSavedSettings.getBOOL("MapShowLandForSale") || 
-											  gSavedSettings.getBOOL("MapShowEvents") || 
-											  gSavedSettings.getBOOL("ShowMatureEvents") ||
-											  gSavedSettings.getBOOL("ShowAdultEvents")))
+	if ((level <= DRAW_SIMINFO_THRESHOLD) && (ALControlCache::MapShowInfohubs || 
+											  ALControlCache::MapShowTelehubs ||
+											  ALControlCache::MapShowLandForSale || 
+											  ALControlCache::MapShowEvents || 
+											  ALControlCache::ShowMatureEvents ||
+											  ALControlCache::ShowAdultEvents))
 	{
 		drawItems();
 	}
@@ -549,7 +549,7 @@ void LLWorldMapView::draw()
 
 	// Draw icons for the avatars in each region.
 	// Drawn this after the current agent avatar so one can see nearby people
-	if (gSavedSettings.getBOOL("MapShowPeople") && (level <= DRAW_SIMINFO_THRESHOLD))
+	if (ALControlCache::MapShowPeople && (level <= DRAW_SIMINFO_THRESHOLD))
 	{
 		drawAgents();
 	}
@@ -820,8 +820,8 @@ void LLWorldMapView::drawItems()
 	bool mature_enabled = gAgent.canAccessMature();
 	bool adult_enabled = gAgent.canAccessAdult();
 
-    BOOL show_mature = mature_enabled && gSavedSettings.getBOOL("ShowMatureEvents");
-	BOOL show_adult = adult_enabled && gSavedSettings.getBOOL("ShowAdultEvents");
+    BOOL show_mature = mature_enabled && ALControlCache::ShowMatureEvents;
+	BOOL show_adult = adult_enabled && ALControlCache::ShowAdultEvents;
 
 	for (handle_list_t::iterator iter = mVisibleRegions.begin(); iter != mVisibleRegions.end(); ++iter)
 	{
@@ -832,17 +832,17 @@ void LLWorldMapView::drawItems()
 			continue;
 		}
 		// Infohubs
-		if (gSavedSettings.getBOOL("MapShowInfohubs"))
+		if (ALControlCache::MapShowInfohubs)
 		{
 			drawGenericItems(info->getInfoHub(), sInfohubImage);
 		}
 		// Telehubs
-		if (gSavedSettings.getBOOL("MapShowTelehubs"))
+		if (ALControlCache::MapShowTelehubs)
 		{
 			drawGenericItems(info->getTeleHub(), sTelehubImage);
 		}
 		// Land for sale
-		if (gSavedSettings.getBOOL("MapShowLandForSale"))
+		if (ALControlCache::MapShowLandForSale)
 		{
 			drawGenericItems(info->getLandForSale(), sForSaleImage);
 			// for 1.23, we're showing normal land and adult land in the same UI; you don't
@@ -854,7 +854,7 @@ void LLWorldMapView::drawItems()
 			}
 		}
 		// PG Events
-		if (gSavedSettings.getBOOL("MapShowEvents"))
+		if (ALControlCache::MapShowEvents)
 		{
 			drawGenericItems(info->getPGEvent(), sEventImage);
 		}
@@ -1518,11 +1518,11 @@ void LLWorldMapView::handleClick(S32 x, S32 y, MASK mask,
 	// If the zoom level is not too far out already, test hits
 	if (level <= DRAW_SIMINFO_THRESHOLD)
 	{
-		bool show_mature = gAgent.canAccessMature() && gSavedSettings.getBOOL("ShowMatureEvents");
-		bool show_adult = gAgent.canAccessAdult() && gSavedSettings.getBOOL("ShowAdultEvents");
+		bool show_mature = gAgent.canAccessMature() && ALControlCache::ShowMatureEvents;
+		bool show_adult = gAgent.canAccessAdult() && ALControlCache::ShowAdultEvents;
 
 		// Test hits if trackable data are displayed, otherwise, we don't even bother
-		if (gSavedSettings.getBOOL("MapShowEvents") || show_mature || show_adult || gSavedSettings.getBOOL("MapShowLandForSale"))
+		if (ALControlCache::MapShowEvents || show_mature || show_adult || ALControlCache::MapShowLandForSale)
 		{
 			// Iterate through the visible regions
 			for (handle_list_t::iterator iter = mVisibleRegions.begin(); iter != mVisibleRegions.end(); ++iter)
@@ -1534,7 +1534,7 @@ void LLWorldMapView::handleClick(S32 x, S32 y, MASK mask,
 					continue;
 				}
 				// If on screen check hits with the visible item lists
-				if (gSavedSettings.getBOOL("MapShowEvents"))
+				if (ALControlCache::MapShowEvents)
 				{
 					LLSimInfo::item_info_list_t::const_iterator it = siminfo->getPGEvent().begin();
 					while (it != siminfo->getPGEvent().end())
@@ -1582,7 +1582,7 @@ void LLWorldMapView::handleClick(S32 x, S32 y, MASK mask,
 						++it;
 					}
 				}
-				if (gSavedSettings.getBOOL("MapShowLandForSale"))
+				if (ALControlCache::MapShowLandForSale)
 				{
 					LLSimInfo::item_info_list_t::const_iterator it = siminfo->getLandForSale().begin();
 					while (it != siminfo->getLandForSale().end())
-- 
GitLab