From 34770cbf2ef34b7901552057a0823e502d42be1d Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Mon, 15 Oct 2018 16:41:47 +0100
Subject: [PATCH] SL-9805 - reduce frequency of dynamic box updates to every N
 frames, staggered. Currently N is 4.

---
 indra/newview/llvoavatar.cpp | 21 ++++++++++++++++++++-
 indra/newview/llvoavatar.h   |  1 +
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 02eae56643..321f774210 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -1271,8 +1271,18 @@ void LLVOAvatar::updateSpatialExtents(LLVector4a& newMin, LLVector4a &newMax)
         calculateSpatialExtents(newMin,newMax);
         mLastAnimExtents[0].set(newMin.getF32ptr());
         mLastAnimExtents[1].set(newMax.getF32ptr());
+		mLastAnimBasePos = mPelvisp->getWorldPosition();
         mNeedsExtentUpdate = false;
     }
+	else
+	{
+		LLVector3 new_base_pos = mPelvisp->getWorldPosition();
+		LLVector3 shift = new_base_pos-mLastAnimBasePos;
+		mLastAnimExtents[0] += shift;
+		mLastAnimExtents[1] += shift;
+		mLastAnimBasePos = new_base_pos;
+
+	}
           
 	if (isImpostor() && !needsImpostorUpdate())
 	{
@@ -2443,7 +2453,16 @@ void LLVOAvatar::idleUpdate(LLAgent &agent, const F64 &time)
 	}
 
     // Update should be happening max once per frame.
-    mNeedsExtentUpdate = true;
+	const S32 upd_freq = 4; // force update every upd_freq frames.
+	if ((mLastAnimExtents[0]==LLVector3())||
+		(mLastAnimExtents[1])==LLVector3())
+	{
+		mNeedsExtentUpdate = true;
+	}
+	else
+	{
+		mNeedsExtentUpdate = ((LLDrawable::getCurrentFrame()+mID.mData[0])%upd_freq==0);
+	}
     
     LLScopedContextString str("avatar_idle_update " + getFullname());
     
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 8c1242421e..deb22617a4 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -543,6 +543,7 @@ private:
 	F32			mImpostorDistance;
 	F32			mImpostorPixelArea;
 	LLVector3	mLastAnimExtents[2];  
+	LLVector3	mLastAnimBasePos;
 	
 	LLCachedControl<bool> mRenderUnloadedAvatar;
 
-- 
GitLab