From 9b37cc8eddb32946494af3448ca06130fe9a4f1f Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Mon, 13 Apr 2020 13:32:46 -0400
Subject: [PATCH] Cache MaxSelectDistance setting in global cache

---
 indra/newview/alcontrolcache.cpp   | 2 ++
 indra/newview/alcontrolcache.h     | 1 +
 indra/newview/llglsandbox.cpp      | 6 +++---
 indra/newview/llmaniprotate.cpp    | 2 +-
 indra/newview/llmanipscale.cpp     | 2 +-
 indra/newview/llmaniptranslate.cpp | 2 +-
 indra/newview/llselectmgr.cpp      | 4 ++--
 indra/newview/lltoolplacer.cpp     | 2 +-
 indra/newview/llviewercamera.cpp   | 2 +-
 9 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/indra/newview/alcontrolcache.cpp b/indra/newview/alcontrolcache.cpp
index adfa6e435b6..eb552aeb462 100644
--- a/indra/newview/alcontrolcache.cpp
+++ b/indra/newview/alcontrolcache.cpp
@@ -16,6 +16,7 @@ bool ALControlCache::MapShowEvents;
 bool ALControlCache::MapShowLandForSale;
 bool ALControlCache::MapShowPeople;
 bool ALControlCache::MapShowTelehubs;
+F32  ALControlCache::MaxSelectDistance = 512.f;
 bool ALControlCache::NavBarShowParcelProperties = true;
 F32	 ALControlCache::NearMeRange = 4096.f;
 U32  ALControlCache::PreferredMaturity;
@@ -65,6 +66,7 @@ void ALControlCache::initControls()
 	DECLARE_CTRL_BOOL(MapShowLandForSale);
 	DECLARE_CTRL_BOOL(MapShowPeople);
 	DECLARE_CTRL_BOOL(MapShowTelehubs);
+	DECLARE_CTRL_F32(MaxSelectDistance);
 	DECLARE_CTRL_BOOL(NavBarShowParcelProperties);
 	DECLARE_CTRL_F32(NearMeRange);
 	DECLARE_CTRL_U32(PreferredMaturity);
diff --git a/indra/newview/alcontrolcache.h b/indra/newview/alcontrolcache.h
index eb24ba7e230..30b6ac93778 100644
--- a/indra/newview/alcontrolcache.h
+++ b/indra/newview/alcontrolcache.h
@@ -18,6 +18,7 @@ struct ALControlCache
 	static bool		MapShowLandForSale;
 	static bool		MapShowPeople;
 	static bool		MapShowTelehubs;
+	static F32		MaxSelectDistance;
 	static bool		NavBarShowParcelProperties;
 	static F32		NearMeRange;
 	static U32		PreferredMaturity;
diff --git a/indra/newview/llglsandbox.cpp b/indra/newview/llglsandbox.cpp
index 0e5f252910c..fcdaa942b28 100644
--- a/indra/newview/llglsandbox.cpp
+++ b/indra/newview/llglsandbox.cpp
@@ -91,7 +91,7 @@ void LLToolSelectRect::handleRectangleSelection(S32 x, S32 y, MASK mask)
 // [/RLVa:KB]
 
 	LLVector3 av_pos = gAgent.getPositionAgent();
-	F32 select_dist_squared = gSavedSettings.getF32("MaxSelectDistance");
+	F32 select_dist_squared = ALControlCache::MaxSelectDistance;
 	select_dist_squared = select_dist_squared * select_dist_squared;
 
 	BOOL deselect = (mask == MASK_CONTROL);
@@ -146,8 +146,8 @@ void LLToolSelectRect::handleRectangleSelection(S32 x, S32 y, MASK mask)
 		LLVector3 relative_av_pos = av_pos;
 		relative_av_pos -= LLViewerCamera::getInstance()->getOrigin();
 
-		F32 new_far = relative_av_pos * LLViewerCamera::getInstance()->getAtAxis() + gSavedSettings.getF32("MaxSelectDistance");
-		F32 new_near = relative_av_pos * LLViewerCamera::getInstance()->getAtAxis() - gSavedSettings.getF32("MaxSelectDistance");
+		F32 new_far = relative_av_pos * LLViewerCamera::getInstance()->getAtAxis() + ALControlCache::MaxSelectDistance;
+		F32 new_near = relative_av_pos * LLViewerCamera::getInstance()->getAtAxis() - ALControlCache::MaxSelectDistance;
 
 		new_near = llmax(new_near, 0.1f);
 
diff --git a/indra/newview/llmaniprotate.cpp b/indra/newview/llmaniprotate.cpp
index ed4e0fee3d1..d7cd143b535 100644
--- a/indra/newview/llmaniprotate.cpp
+++ b/indra/newview/llmaniprotate.cpp
@@ -1197,7 +1197,7 @@ BOOL LLManipRotate::updateVisiblity()
 			// Don't drag manip if object too far away
 			if (ALControlCache::LimitSelectDistance)
 			{
-				F32 max_select_distance = gSavedSettings.getF32("MaxSelectDistance");
+				F32 max_select_distance = ALControlCache::MaxSelectDistance;
 				if (dist_vec_squared(gAgent.getPositionAgent(), center) > (max_select_distance * max_select_distance))
 				{
 					visible = FALSE;
diff --git a/indra/newview/llmanipscale.cpp b/indra/newview/llmanipscale.cpp
index 0d6a6e36442..b99176edfcc 100644
--- a/indra/newview/llmanipscale.cpp
+++ b/indra/newview/llmanipscale.cpp
@@ -251,7 +251,7 @@ void LLManipScale::render()
 				// Don't draw manip if object too far away
 				if (ALControlCache::LimitSelectDistance)
 				{
-					F32 max_select_distance = gSavedSettings.getF32("MaxSelectDistance");
+					F32 max_select_distance = ALControlCache::MaxSelectDistance;
 					if (range_from_agent_squared > max_select_distance * max_select_distance)
 					{
 						return;
diff --git a/indra/newview/llmaniptranslate.cpp b/indra/newview/llmaniptranslate.cpp
index a0edbdf38b2..b40d8ab32da 100644
--- a/indra/newview/llmaniptranslate.cpp
+++ b/indra/newview/llmaniptranslate.cpp
@@ -1842,7 +1842,7 @@ void LLManipTranslate::renderTranslationHandles()
 		// Don't draw handles if you're too far away
 		if (ALControlCache::LimitSelectDistance)
 		{
-			if (range_from_agent > gSavedSettings.getF32("MaxSelectDistance"))
+			if (range_from_agent > ALControlCache::MaxSelectDistance)
 			{
 				return;
 			}
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp
index ba19a5d8b16..24cd09b3d9d 100644
--- a/indra/newview/llselectmgr.cpp
+++ b/indra/newview/llselectmgr.cpp
@@ -4501,9 +4501,9 @@ void LLSelectMgr::deselectAllIfTooFar()
 		&& !mSelectedObjects->isAttachment()
 		&& !selectionCenter.isExactlyZero())
 	{
-//		F32 deselect_dist = gSavedSettings.getF32("MaxSelectDistance");
+//		F32 deselect_dist = ALControlCache::MaxSelectDistance;
 // [RLVa:KB] - Checked: 2010-04-11 (RLVa-1.2.0e) | Modified: RLVa-0.2.0f
-		F32 deselect_dist = (!fRlvFartouch) ? gSavedSettings.getF32("MaxSelectDistance") : s_nFartouchDist;
+		F32 deselect_dist = (!fRlvFartouch) ? ALControlCache::MaxSelectDistance : s_nFartouchDist;
 // [/RLVa:KB]
 		F32 deselect_dist_sq = deselect_dist * deselect_dist;
 
diff --git a/indra/newview/lltoolplacer.cpp b/indra/newview/lltoolplacer.cpp
index a3d13ed8435..aabccb28926 100644
--- a/indra/newview/lltoolplacer.cpp
+++ b/indra/newview/lltoolplacer.cpp
@@ -80,7 +80,7 @@ LLToolPlacer::LLToolPlacer()
 BOOL LLToolPlacer::raycastForNewObjPos( S32 x, S32 y, LLViewerObject** hit_obj, S32* hit_face, 
 							 BOOL* b_hit_land, LLVector3* ray_start_region, LLVector3* ray_end_region, LLViewerRegion** region )
 {
-	F32 max_dist_from_camera = gSavedSettings.getF32( "MaxSelectDistance" ) - 1.f;
+	F32 max_dist_from_camera = ALControlCache::MaxSelectDistance - 1.f;
 
 	// Viewer-side pick to find the right sim to create the object on.  
 	// First find the surface the object will be created on.
diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp
index 74a6327f99d..f2898d334fb 100644
--- a/indra/newview/llviewercamera.cpp
+++ b/indra/newview/llviewercamera.cpp
@@ -332,7 +332,7 @@ void LLViewerCamera::setPerspective(BOOL for_selection,
 		if (limit_select_distance)
 		{
 			// ...select distance from control
-			z_far = gSavedSettings.getF32("MaxSelectDistance");
+			z_far = ALControlCache::MaxSelectDistance;
 		}
 		else
 		{
-- 
GitLab