From 13ab00e45a1e52b4668a472130eb83cdf45850ca Mon Sep 17 00:00:00 2001 From: dahlia Date: Tue, 3 May 2011 19:47:50 -0700 Subject: [PATCH 1/4] adjust terse avatar update filtering to send updates when distance traveled does not match expected distance, rather than at a fixed time period. this should smooth avatar motion somewhat when moving in a straight line and velocity is constant. --- .../Region/Framework/Scenes/ScenePresence.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 5b86735ef3..feab35cbd7 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2395,6 +2395,7 @@ namespace OpenSim.Region.Framework.Scenes // vars to support reduced update frequency when velocity is unchanged private Vector3 lastVelocitySentToAllClients = Vector3.Zero; + private Vector3 lastPositionSentToAllClients = Vector3.Zero; private int lastTerseUpdateToAllClientsTick = Util.EnvironmentTickCount(); /// @@ -2404,14 +2405,27 @@ namespace OpenSim.Region.Framework.Scenes { int currentTick = Util.EnvironmentTickCount(); - // decrease update frequency when avatar is moving but velocity is not changing + // Decrease update frequency when avatar is moving but velocity is + // not changing. + // If there is a mismatch between distance travelled and expected + // distance based on last velocity sent and velocity hasnt changed, + // then send a new terse update + + float timeSinceLastUpdate = (currentTick - lastTerseUpdateToAllClientsTick) * 0.001f; + + Vector3 expectedPosition = lastPositionSentToAllClients + lastVelocitySentToAllClients * timeSinceLastUpdate; + + float absoluteDistanceError = (float)Math.Abs(Vector3.Distance(m_pos, expectedPosition)); + + if (m_velocity.Length() < 0.01f - || Vector3.Distance(lastVelocitySentToAllClients, m_velocity) > 0.01f - || currentTick - lastTerseUpdateToAllClientsTick > 1500) + || absoluteDistanceError > 0.25f // arbitrary distance error threshold + || Vector3.Distance(lastVelocitySentToAllClients, m_velocity) > 0.01f) { m_perfMonMS = currentTick; lastVelocitySentToAllClients = m_velocity; lastTerseUpdateToAllClientsTick = currentTick; + lastPositionSentToAllClients = m_pos; m_scene.ForEachClient(SendTerseUpdateToClient); From 4c59d57596d8c955a3634d9ffc35b4557e0b56fe Mon Sep 17 00:00:00 2001 From: dahlia Date: Wed, 4 May 2011 03:29:06 -0700 Subject: [PATCH 2/4] use getters instead of member variables in velocity network filter code and add some more descriptive comments. --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index feab35cbd7..1e90d564a2 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2415,17 +2415,19 @@ namespace OpenSim.Region.Framework.Scenes Vector3 expectedPosition = lastPositionSentToAllClients + lastVelocitySentToAllClients * timeSinceLastUpdate; - float absoluteDistanceError = (float)Math.Abs(Vector3.Distance(m_pos, expectedPosition)); + float distanceError = Vector3.Distance(OffsetPosition, expectedPosition); + float speed = Velocity.Length(); + float velocidyDiff = Vector3.Distance(lastVelocitySentToAllClients, Velocity); - if (m_velocity.Length() < 0.01f - || absoluteDistanceError > 0.25f // arbitrary distance error threshold - || Vector3.Distance(lastVelocitySentToAllClients, m_velocity) > 0.01f) + if (speed < 0.01f // allow rotation updates if avatar position is unchanged + || Math.Abs(distanceError) > 0.25f // arbitrary distance error threshold + || velocidyDiff > 0.01f) // did velocity change from last update? { m_perfMonMS = currentTick; - lastVelocitySentToAllClients = m_velocity; + lastVelocitySentToAllClients = Velocity; lastTerseUpdateToAllClientsTick = currentTick; - lastPositionSentToAllClients = m_pos; + lastPositionSentToAllClients = OffsetPosition; m_scene.ForEachClient(SendTerseUpdateToClient); From df7dacd004de3742f183656f2ce44a11e30a7224 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 4 May 2011 11:34:18 -0700 Subject: [PATCH 3/4] Fixes mantis #5461. --- .../Framework/InventoryAccess/InventoryAccessModule.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index 6b3df9ddd6..1370b1fe8e 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs @@ -371,7 +371,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } // This is a hook to do some per-asset post-processing for subclasses that need that - ExportAsset(remoteClient.AgentId, assetID); + if (remoteClient != null) + ExportAsset(remoteClient.AgentId, assetID); return assetID; } From 6c503e75acb459e4cdda423bbfbf4cb22611315e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 4 May 2011 12:04:35 -0700 Subject: [PATCH 4/4] Put the previous state back in the attachments in case the agent transfer fails. --- .../EntityTransfer/EntityTransferModule.cs | 4 ++++ OpenSim/Region/Framework/Scenes/ScenePresence.cs | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index b985fbb371..e38006752a 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -1759,11 +1759,15 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer protected void ReInstantiateScripts(ScenePresence sp) { + int i = 0; sp.Attachments.ForEach(delegate(SceneObjectGroup sog) { + sog.SetState(sp.InTransitScriptStates[i++], sp.Scene); sog.CreateScriptInstances(0, false, sp.Scene.DefaultScriptEngine, 0); sog.ResumeScripts(); }); + + sp.InTransitScriptStates.Clear(); } #endregion diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 1e90d564a2..631c91b29e 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -231,6 +231,16 @@ namespace OpenSim.Region.Framework.Scenes // holds the seed cap for the child agent in that region private Dictionary m_knownChildRegions = new Dictionary(); + /// + /// Copy of the script states while the agent is in transit. This state may + /// need to be placed back in case of transfer fail. + /// + public List InTransitScriptStates + { + get { return m_InTransitScriptStates; } + } + private List m_InTransitScriptStates = new List(); + /// /// Implemented Control Flags /// @@ -3142,6 +3152,7 @@ namespace OpenSim.Region.Framework.Scenes cAgent.AttachmentObjects = new List(); cAgent.AttachmentObjectStates = new List(); IScriptModule se = m_scene.RequestModuleInterface(); + m_InTransitScriptStates.Clear(); foreach (SceneObjectGroup sog in m_attachments) { // We need to make a copy and pass that copy @@ -3151,7 +3162,9 @@ namespace OpenSim.Region.Framework.Scenes ((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos; ((SceneObjectGroup)clone).RootPart.IsAttachment = false; cAgent.AttachmentObjects.Add(clone); - cAgent.AttachmentObjectStates.Add(sog.GetStateSnapshot()); + string state = sog.GetStateSnapshot(); + cAgent.AttachmentObjectStates.Add(state); + m_InTransitScriptStates.Add(state); // Let's remove the scripts of the original object here sog.RemoveScriptInstances(true); }