From 35a8938892a16c17da8ef7707227f4494bb41eb5 Mon Sep 17 00:00:00 2001
From: andreykproductengine <akleshchev@productengine.com>
Date: Tue, 25 Nov 2014 16:29:40 +0200
Subject: [PATCH] MAINT-4690 FIXED forced send_agent_update(TRUE) in idle()
 results in large amounts of useless UDP traffic

---
 indra/newview/llappviewer.cpp | 36 +++++++++++++++++++----------------
 indra/newview/llappviewer.h   |  3 +++
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index f6b6c71cfc0..67007bc4cdc 100755
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -685,6 +685,8 @@ LLAppViewer::LLAppViewer()
 	mQuitRequested(false),
 	mLogoutRequestSent(false),
 	mYieldTime(-1),
+	mLastAgentControlFlags(0),
+	mLastAgentForceUpdate(0),
 	mMainloopTimeout(NULL),
 	mAgentRegionLastAlive(false),
 	mRandomizeFramerate(LLCachedControl<bool>(gSavedSettings,"Randomize Framerate", FALSE)),
@@ -4811,22 +4813,24 @@ void LLAppViewer::idle()
 			gAgentPilot.updateTarget();
 			gAgent.autoPilot(&yaw);
 		}
-    
-	    static LLFrameTimer agent_update_timer;
-	    static U32 				last_control_flags;
-    
-	    //	When appropriate, update agent location to the simulator.
-	    F32 agent_update_time = agent_update_timer.getElapsedTimeF32();
-	    BOOL flags_changed = gAgent.controlFlagsDirty() || (last_control_flags != gAgent.getControlFlags());
-		    
-	    if (flags_changed || (agent_update_time > (1.0f / (F32) AGENT_UPDATES_PER_SECOND)))
-	    {
-		    LL_RECORD_BLOCK_TIME(FTM_AGENT_UPDATE);
-		    // Send avatar and camera info
-		    last_control_flags = gAgent.getControlFlags();
-		    send_agent_update(TRUE);
-		    agent_update_timer.reset();
-	    }
+
+		static LLFrameTimer agent_update_timer;
+
+		// When appropriate, update agent location to the simulator.
+		F32 agent_update_time = agent_update_timer.getElapsedTimeF32();
+		F32 agent_force_update_time = mLastAgentForceUpdate + agent_update_time;
+		BOOL force_update = gAgent.controlFlagsDirty()
+							|| (mLastAgentControlFlags != gAgent.getControlFlags())
+							|| (agent_force_update_time > (1.0f / (F32) AGENT_FORCE_UPDATES_PER_SECOND));
+		if (force_update || (agent_update_time > (1.0f / (F32) AGENT_UPDATES_PER_SECOND)))
+		{
+			LL_RECORD_BLOCK_TIME(FTM_AGENT_UPDATE);
+			// Send avatar and camera info
+			mLastAgentControlFlags = gAgent.getControlFlags();
+			mLastAgentForceUpdate = force_update ? 0 : agent_force_update_time;
+			send_agent_update(force_update);
+			agent_update_timer.reset();
+		}
 	}
 
 	//////////////////////////////////////
diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h
index e0f3f326c7a..e8a1ca036b8 100755
--- a/indra/newview/llappviewer.h
+++ b/indra/newview/llappviewer.h
@@ -275,6 +275,8 @@ class LLAppViewer : public LLApp
     bool mQuitRequested;				// User wants to quit, may have modified documents open.
     bool mLogoutRequestSent;			// Disconnect message sent to simulator, no longer safe to send messages to the sim.
     S32 mYieldTime;
+	U32 mLastAgentControlFlags;
+	F32 mLastAgentForceUpdate;
 	struct SettingsFiles* mSettingsLocationList;
 
 	LLWatchdogTimeout* mMainloopTimeout;
@@ -314,6 +316,7 @@ class LLAppViewer : public LLApp
 
 // consts from viewer.h
 const S32 AGENT_UPDATES_PER_SECOND  = 10;
+const S32 AGENT_FORCE_UPDATES_PER_SECOND  = 1;
 
 // Globals with external linkage. From viewer.h
 // *NOTE:Mani - These will be removed as the Viewer App Cleanup project continues.
-- 
GitLab