From b2ed348aa2746fbf034b713d006e40366c479d5a Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 22 Oct 2009 12:33:23 -0700 Subject: Implemented a Watchdog class. Do not manually create Thread objects anymore, use Watchdog.StartThread(). While your thread is running call Watchdog.UpdateThread(). When it is shutting down call Watchdog.RemoveThread(). Most of the threads in OpenSim have been updated --- OpenSim/Region/Framework/Scenes/Scene.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 5005ac9..4b87f92 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -81,8 +81,6 @@ namespace OpenSim.Region.Framework.Scenes protected Timer m_restartWaitTimer = new Timer(); - protected Thread m_updateEntitiesThread; - public SimStatsReporter StatsReporter; protected List m_regionRestartNotifyList = new List(); @@ -945,11 +943,8 @@ namespace OpenSim.Region.Framework.Scenes HeartbeatThread = null; } m_lastUpdate = Environment.TickCount; - HeartbeatThread = new Thread(new ParameterizedThreadStart(Heartbeat)); - HeartbeatThread.SetApartmentState(ApartmentState.MTA); - HeartbeatThread.Name = string.Format("Heartbeat for region {0}", RegionInfo.RegionName); - HeartbeatThread.Priority = ThreadPriority.AboveNormal; - HeartbeatThread.Start(); + + HeartbeatThread = Watchdog.StartThread(Heartbeat, "Heartbeat for region " + RegionInfo.RegionName, ThreadPriority.Normal, false); } /// @@ -976,12 +971,13 @@ namespace OpenSim.Region.Framework.Scenes /// /// Performs per-frame updates regularly /// - /// - /// - private void Heartbeat(object sender) + private void Heartbeat() { if (!Monitor.TryEnter(m_heartbeatLock)) + { + Watchdog.RemoveThread(); return; + } try { @@ -998,6 +994,8 @@ namespace OpenSim.Region.Framework.Scenes Monitor.Pulse(m_heartbeatLock); Monitor.Exit(m_heartbeatLock); } + + Watchdog.RemoveThread(); } /// @@ -1146,6 +1144,8 @@ namespace OpenSim.Region.Framework.Scenes if ((maintc < (m_timespan * 1000)) && maintc > 0) Thread.Sleep(maintc); + + Watchdog.UpdateThread(); } } -- cgit v1.1 From 167d8e39fa34c52593c640058287184026c95288 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 22 Oct 2009 13:14:41 -0700 Subject: * Sending (position - hipoffset) instead of position * Sending m_rotation instead of m_bodyRot in full updates to match terse updates (no idea which one is right!) --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index d7113bf..99fd86c 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2517,15 +2517,12 @@ namespace OpenSim.Region.Framework.Scenes if (m_appearance.Texture == null) return; - // Note: because Quaternion is a struct, it can't be null - Quaternion rot = m_bodyRot; - Vector3 pos = m_pos; pos.Z -= m_appearance.HipOffset; remoteAvatar.m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, - LocalId, m_pos, m_appearance.Texture.GetBytes(), - m_parentID, rot)); + LocalId, pos, m_appearance.Texture.GetBytes(), + m_parentID, m_bodyRot)); m_scene.StatsReporter.AddAgentUpdates(1); } -- cgit v1.1 From 4ba3842d712ccb47e1b7effe0fdf2ed7da531431 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 22 Oct 2009 13:24:24 -0700 Subject: Forgot to hit save in the last commit --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 99fd86c..cfd3fcc 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2522,7 +2522,7 @@ namespace OpenSim.Region.Framework.Scenes remoteAvatar.m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, pos, m_appearance.Texture.GetBytes(), - m_parentID, m_bodyRot)); + m_parentID, m_rotation)); m_scene.StatsReporter.AddAgentUpdates(1); } -- cgit v1.1 From ba2972eaf6d608fe4e6a6610089ab9fb8bae3f2d Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 22 Oct 2009 14:33:54 -0700 Subject: * Send out m_bodyRot everywhere instead of m_rotation. Still have no clue which is right * Fix WorldMapModule.process() to not trip the watchdog timer --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index cfd3fcc..ccfffe7 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2417,7 +2417,7 @@ namespace OpenSim.Region.Framework.Scenes pos.Z -= m_appearance.HipOffset; remoteClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_regionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, - pos, m_velocity, Vector3.Zero, m_rotation, Vector4.Zero, m_uuid, null, GetUpdatePriority(remoteClient))); + pos, m_velocity, Vector3.Zero, m_bodyRot, Vector4.UnitW, m_uuid, null, GetUpdatePriority(remoteClient))); m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); m_scene.StatsReporter.AddAgentUpdates(1); @@ -2522,7 +2522,7 @@ namespace OpenSim.Region.Framework.Scenes remoteAvatar.m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, pos, m_appearance.Texture.GetBytes(), - m_parentID, m_rotation)); + m_parentID, m_bodyRot)); m_scene.StatsReporter.AddAgentUpdates(1); } @@ -2585,14 +2585,11 @@ namespace OpenSim.Region.Framework.Scenes // the inventory arrives // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); - // Note: because Quaternion is a struct, it can't be null - Quaternion rot = m_bodyRot; - Vector3 pos = m_pos; pos.Z -= m_appearance.HipOffset; m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, - m_pos, m_appearance.Texture.GetBytes(), m_parentID, rot)); + pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot)); if (!m_isChildAgent) { @@ -2697,9 +2694,11 @@ namespace OpenSim.Region.Framework.Scenes m_startAnimationSet = true; } - Quaternion rot = m_bodyRot; + Vector3 pos = m_pos; + pos.Z -= m_appearance.HipOffset; + m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, - m_pos, m_appearance.Texture.GetBytes(), m_parentID, rot)); + pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot)); } -- cgit v1.1 From 588361e2a2398b963871762c2b5485c6a086cf47 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 23 Oct 2009 01:02:36 -0700 Subject: Experimental change to use an immutable array for iterating ScenePresences, avoiding locking and copying the list each time it is accessed --- OpenSim/Region/Framework/Scenes/Scene.cs | 25 ++-- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 160 +++++++++++---------- OpenSim/Region/Framework/Scenes/SceneManager.cs | 53 +++---- .../Region/Framework/Scenes/SceneObjectGroup.cs | 4 +- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 121 ++++++++-------- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 21 +-- 6 files changed, 198 insertions(+), 186 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 4b87f92..d5e3445 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -253,7 +253,7 @@ namespace OpenSim.Region.Framework.Scenes protected int m_fps = 10; protected int m_frame = 0; protected float m_timespan = 0.089f; - protected DateTime m_lastupdate = DateTime.Now; + protected DateTime m_lastupdate = DateTime.UtcNow; private int m_update_physics = 1; private int m_update_entitymovement = 1; @@ -1014,7 +1014,7 @@ namespace OpenSim.Region.Framework.Scenes //#endif maintc = Environment.TickCount; - TimeSpan SinceLastFrame = DateTime.Now - m_lastupdate; + TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastupdate; float physicsFPS = 0; frameMS = Environment.TickCount; @@ -1137,7 +1137,7 @@ namespace OpenSim.Region.Framework.Scenes } m_timedilation = tmpval; - m_lastupdate = DateTime.Now; + m_lastupdate = DateTime.UtcNow; } maintc = Environment.TickCount - maintc; maintc = (int)(m_timespan * 1000) - maintc; @@ -3496,9 +3496,7 @@ namespace OpenSim.Region.Framework.Scenes public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying) { ScenePresence presence; - - lock (m_sceneGraph.ScenePresences) - m_sceneGraph.ScenePresences.TryGetValue(agentID, out presence); + m_sceneGraph.TryGetAvatar(agentID, out presence); if (presence != null) { @@ -3709,8 +3707,7 @@ namespace OpenSim.Region.Framework.Scenes Vector3 lookAt, uint teleportFlags) { ScenePresence sp; - lock (m_sceneGraph.ScenePresences) - m_sceneGraph.ScenePresences.TryGetValue(remoteClient.AgentId, out sp); + m_sceneGraph.TryGetAvatar(remoteClient.AgentId, out sp); if (sp != null) { @@ -4112,7 +4109,7 @@ namespace OpenSim.Region.Framework.Scenes /// This list is a new object, so it can be iterated over without locking. /// /// - public List GetScenePresences() + public ScenePresence[] GetScenePresences() { return m_sceneGraph.GetScenePresences(); } @@ -4159,15 +4156,13 @@ namespace OpenSim.Region.Framework.Scenes public void ForEachScenePresence(Action action) { // We don't want to try to send messages if there are no avatars. - if (m_sceneGraph != null && m_sceneGraph.ScenePresences != null) + if (m_sceneGraph != null) { try { - List presenceList = GetScenePresences(); - foreach (ScenePresence presence in presenceList) - { - action(presence); - } + ScenePresence[] presences = GetScenePresences(); + for (int i = 0; i < presences.Length; i++) + action(presences[i]); } catch (Exception e) { diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index deee6c3..db055f9 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -66,7 +66,9 @@ namespace OpenSim.Region.Framework.Scenes #region Fields - protected internal Dictionary ScenePresences = new Dictionary(); + protected Dictionary m_scenePresences = new Dictionary(); + protected ScenePresence[] m_scenePresenceArray = new ScenePresence[0]; + // SceneObjects is not currently populated or used. //public Dictionary SceneObjects; protected internal EntityManager Entities = new EntityManager(); @@ -126,10 +128,12 @@ namespace OpenSim.Region.Framework.Scenes protected internal void Close() { - lock (ScenePresences) + lock (m_scenePresences) { - ScenePresences.Clear(); + m_scenePresences.Clear(); + m_scenePresenceArray = new ScenePresence[0]; } + lock (m_dictionary_lock) { SceneObjectGroupsByFullID.Clear(); @@ -157,11 +161,9 @@ namespace OpenSim.Region.Framework.Scenes protected internal void UpdatePresences() { - List updateScenePresences = GetScenePresences(); - foreach (ScenePresence pres in updateScenePresences) - { - pres.Update(); - } + ScenePresence[] updateScenePresences = GetScenePresences(); + for (int i = 0; i < updateScenePresences.Length; i++) + updateScenePresences[i].Update(); } protected internal float UpdatePhysics(double elapsed) @@ -190,15 +192,9 @@ namespace OpenSim.Region.Framework.Scenes protected internal void UpdateScenePresenceMovement() { - List moveEntities = GetScenePresences(); - - foreach (EntityBase entity in moveEntities) - { - //cfk. This throws occaisional exceptions on a heavily used region - //and I added this null check to try to preclude the exception. - if (entity != null) - entity.UpdateMovement(); - } + ScenePresence[] moveEntities = GetScenePresences(); + for (int i = 0; i < moveEntities.Length; i++) + moveEntities[i].UpdateMovement(); } #endregion @@ -645,9 +641,34 @@ namespace OpenSim.Region.Framework.Scenes Entities[presence.UUID] = presence; - lock (ScenePresences) + lock (m_scenePresences) { - ScenePresences[presence.UUID] = presence; + if (!m_scenePresences.ContainsKey(presence.UUID)) + { + m_scenePresences.Add(presence.UUID, presence); + + // Create a new array of ScenePresence references + int oldLength = m_scenePresenceArray.Length; + ScenePresence[] newArray = new ScenePresence[oldLength + 1]; + Array.Copy(m_scenePresenceArray, newArray, oldLength); + newArray[oldLength] = presence; + m_scenePresenceArray = newArray; + } + else + { + m_scenePresences[presence.UUID] = presence; + + // Do a linear search through the array of ScenePresence references + // and update the modified entry + for (int i = 0; i < m_scenePresenceArray.Length; i++) + { + if (m_scenePresenceArray[i].UUID == presence.UUID) + { + m_scenePresenceArray[i] = presence; + break; + } + } + } } } @@ -663,16 +684,30 @@ namespace OpenSim.Region.Framework.Scenes agentID); } - lock (ScenePresences) + lock (m_scenePresences) { - if (!ScenePresences.Remove(agentID)) + if (m_scenePresences.Remove(agentID)) + { + // Copy all of the elements from the previous array + // into the new array except the removed element + int oldLength = m_scenePresenceArray.Length; + ScenePresence[] newArray = new ScenePresence[oldLength - 1]; + int j = 0; + for (int i = 0; i < m_scenePresenceArray.Length; i++) + { + ScenePresence presence = m_scenePresenceArray[i]; + if (presence.UUID != agentID) + { + newArray[j] = presence; + ++j; + } + } + m_scenePresenceArray = newArray; + } + else { m_log.WarnFormat("[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); } -// else -// { -// m_log.InfoFormat("[SCENE] Removed scene presence {0} from scene presences list", agentID); -// } } } @@ -704,20 +739,21 @@ namespace OpenSim.Region.Framework.Scenes public void RecalculateStats() { - List SPList = GetScenePresences(); + ScenePresence[] presences = GetScenePresences(); int rootcount = 0; int childcount = 0; - foreach (ScenePresence user in SPList) + for (int i = 0; i < presences.Length; i++) { + ScenePresence user = presences[i]; if (user.IsChildAgent) - childcount++; + ++childcount; else - rootcount++; + ++rootcount; } + m_numRootAgents = rootcount; m_numChildAgents = childcount; - } public int GetChildAgentCount() @@ -767,12 +803,9 @@ namespace OpenSim.Region.Framework.Scenes /// locking is required to iterate over it. /// /// - protected internal List GetScenePresences() + protected internal ScenePresence[] GetScenePresences() { - lock (ScenePresences) - { - return new List(ScenePresences.Values); - } + return m_scenePresenceArray; } protected internal List GetAvatars() @@ -817,14 +850,13 @@ namespace OpenSim.Region.Framework.Scenes // No locking of scene presences here since we're passing back a list... List result = new List(); - List ScenePresencesList = GetScenePresences(); + ScenePresence[] scenePresences = GetScenePresences(); - foreach (ScenePresence avatar in ScenePresencesList) + for (int i = 0; i < scenePresences.Length; i++) { + ScenePresence avatar = scenePresences[i]; if (filter(avatar)) - { result.Add(avatar); - } } return result; @@ -839,9 +871,9 @@ namespace OpenSim.Region.Framework.Scenes { ScenePresence sp; - lock (ScenePresences) + lock (m_scenePresences) { - ScenePresences.TryGetValue(agentID, out sp); + m_scenePresences.TryGetValue(agentID, out sp); } return sp; @@ -1000,48 +1032,24 @@ namespace OpenSim.Region.Framework.Scenes protected internal bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) { - ScenePresence presence; - - lock (ScenePresences) - { - if (ScenePresences.TryGetValue(avatarId, out presence)) - { - avatar = presence; - return true; - - //if (!presence.IsChildAgent) - //{ - // avatar = presence; - // return true; - //} - //else - //{ - // m_log.WarnFormat( - // "[INNER SCENE]: Requested avatar {0} could not be found in scene {1} since it is only registered as a child agent!", - // avatarId, m_parentScene.RegionInfo.RegionName); - //} - } - } - - avatar = null; - return false; + lock (m_scenePresences) + return m_scenePresences.TryGetValue(avatarId, out avatar); } protected internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) { - lock (ScenePresences) + ScenePresence[] presences = GetScenePresences(); + + for (int i = 0; i < presences.Length; i++) { - foreach (ScenePresence presence in ScenePresences.Values) + ScenePresence presence = presences[i]; + + if (!presence.IsChildAgent) { - if (!presence.IsChildAgent) + if (String.Compare(avatarName, presence.ControllingClient.Name, true) == 0) { - string name = presence.ControllingClient.Name; - - if (String.Compare(avatarName, name, true) == 0) - { - avatar = presence; - return true; - } + avatar = presence; + return true; } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index 3097929..dfaa7ea 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs @@ -411,41 +411,46 @@ namespace OpenSim.Region.Framework.Scenes /// public void SetDebugPacketLevelOnCurrentScene(int newDebug) { - ForEachCurrentScene(delegate(Scene scene) - { - List scenePresences = scene.GetScenePresences(); + ForEachCurrentScene( + delegate(Scene scene) + { + ScenePresence[] scenePresences = scene.GetScenePresences(); + + for (int i = 0; i < scenePresences.Length; i++) + { + ScenePresence scenePresence = scenePresences[i]; - foreach (ScenePresence scenePresence in scenePresences) - { - if (!scenePresence.IsChildAgent) - { - m_log.ErrorFormat("Packet debug for {0} {1} set to {2}", - scenePresence.Firstname, - scenePresence.Lastname, - newDebug); + if (!scenePresence.IsChildAgent) + { + m_log.ErrorFormat("Packet debug for {0} {1} set to {2}", + scenePresence.Firstname, + scenePresence.Lastname, + newDebug); - scenePresence.ControllingClient.SetDebugPacketLevel(newDebug); - } - } - }); + scenePresence.ControllingClient.SetDebugPacketLevel(newDebug); + } + } + } + ); } public List GetCurrentSceneAvatars() { List avatars = new List(); - ForEachCurrentScene(delegate(Scene scene) - { - List scenePresences = scene.GetScenePresences(); - - foreach (ScenePresence scenePresence in scenePresences) + ForEachCurrentScene( + delegate(Scene scene) { - if (!scenePresence.IsChildAgent) + ScenePresence[] scenePresences = scene.GetScenePresences(); + + for (int i = 0; i < scenePresences.Length; i++) { - avatars.Add(scenePresence); + ScenePresence scenePresence = scenePresences[i]; + if (!scenePresence.IsChildAgent) + avatars.Add(scenePresence); } } - }); + ); return avatars; } @@ -456,7 +461,7 @@ namespace OpenSim.Region.Framework.Scenes ForEachCurrentScene(delegate(Scene scene) { - List scenePresences = scene.GetScenePresences(); + ScenePresence[] scenePresences = scene.GetScenePresences(); presences.AddRange(scenePresences); }); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 69b3ded..4f19761 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1182,8 +1182,8 @@ namespace OpenSim.Region.Framework.Scenes { // part.Inventory.RemoveScriptInstances(); - List avatars = Scene.GetScenePresences(); - for (int i = 0; i < avatars.Count; i++) + ScenePresence[] avatars = Scene.GetScenePresences(); + for (int i = 0; i < avatars.Length; i++) { if (avatars[i].ParentID == LocalId) { diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 32171a0..7193002 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1077,8 +1077,8 @@ if (m_shape != null) { private void SendObjectPropertiesToClient(UUID AgentID) { - List avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Count; i++) + ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); + for (int i = 0; i < avatars.Length; i++) { // Ugly reference :( if (avatars[i].UUID == AgentID) @@ -1140,8 +1140,8 @@ if (m_shape != null) { /// public void AddFullUpdateToAllAvatars() { - List avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Count; i++) + ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); + for (int i = 0; i < avatars.Length; i++) { avatars[i].SceneViewer.QueuePartForUpdate(this); } @@ -1165,8 +1165,8 @@ if (m_shape != null) { /// Terse updates public void AddTerseUpdateToAllAvatars() { - List avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Count; i++) + ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); + for (int i = 0; i < avatars.Length; i++) { avatars[i].SceneViewer.QueuePartForUpdate(this); } @@ -1894,24 +1894,24 @@ if (m_shape != null) { } else { - List avlist = m_parentGroup.Scene.GetScenePresences(); - if (avlist != null) + ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); + + for (int i = 0; i < avlist.Length; i++) { - foreach (ScenePresence av in avlist) + ScenePresence av = avlist[i]; + + if (av.LocalId == localId) { - if (av.LocalId == localId) - { - DetectedObject detobj = new DetectedObject(); - detobj.keyUUID = av.UUID; - detobj.nameStr = av.ControllingClient.Name; - detobj.ownerUUID = av.UUID; - detobj.posVector = av.AbsolutePosition; - detobj.rotQuat = av.Rotation; - detobj.velVector = av.Velocity; - detobj.colliderType = 0; - detobj.groupUUID = av.ControllingClient.ActiveGroupId; - colliding.Add(detobj); - } + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = av.UUID; + detobj.nameStr = av.ControllingClient.Name; + detobj.ownerUUID = av.UUID; + detobj.posVector = av.AbsolutePosition; + detobj.rotQuat = av.Rotation; + detobj.velVector = av.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = av.ControllingClient.ActiveGroupId; + colliding.Add(detobj); } } } @@ -1965,26 +1965,25 @@ if (m_shape != null) { } else { - List avlist = m_parentGroup.Scene.GetScenePresences(); - if (avlist != null) + ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); + + for (int i = 0; i < avlist.Length; i++) { - foreach (ScenePresence av in avlist) + ScenePresence av = avlist[i]; + + if (av.LocalId == localId) { - if (av.LocalId == localId) - { - DetectedObject detobj = new DetectedObject(); - detobj.keyUUID = av.UUID; - detobj.nameStr = av.Name; - detobj.ownerUUID = av.UUID; - detobj.posVector = av.AbsolutePosition; - detobj.rotQuat = av.Rotation; - detobj.velVector = av.Velocity; - detobj.colliderType = 0; - detobj.groupUUID = av.ControllingClient.ActiveGroupId; - colliding.Add(detobj); - } + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = av.UUID; + detobj.nameStr = av.Name; + detobj.ownerUUID = av.UUID; + detobj.posVector = av.AbsolutePosition; + detobj.rotQuat = av.Rotation; + detobj.velVector = av.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = av.ControllingClient.ActiveGroupId; + colliding.Add(detobj); } - } } } @@ -2035,24 +2034,24 @@ if (m_shape != null) { } else { - List avlist = m_parentGroup.Scene.GetScenePresences(); - if (avlist != null) + ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); + + for (int i = 0; i < avlist.Length; i++) { - foreach (ScenePresence av in avlist) + ScenePresence av = avlist[i]; + + if (av.LocalId == localId) { - if (av.LocalId == localId) - { - DetectedObject detobj = new DetectedObject(); - detobj.keyUUID = av.UUID; - detobj.nameStr = av.Name; - detobj.ownerUUID = av.UUID; - detobj.posVector = av.AbsolutePosition; - detobj.rotQuat = av.Rotation; - detobj.velVector = av.Velocity; - detobj.colliderType = 0; - detobj.groupUUID = av.ControllingClient.ActiveGroupId; - colliding.Add(detobj); - } + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = av.UUID; + detobj.nameStr = av.Name; + detobj.ownerUUID = av.UUID; + detobj.posVector = av.AbsolutePosition; + detobj.rotQuat = av.Rotation; + detobj.velVector = av.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = av.ControllingClient.ActiveGroupId; + colliding.Add(detobj); } } } @@ -2312,8 +2311,8 @@ if (m_shape != null) { /// public void SendFullUpdateToAllClients() { - List avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Count; i++) + ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); + for (int i = 0; i < avatars.Length; i++) { // Ugly reference :( m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this, @@ -2323,8 +2322,8 @@ if (m_shape != null) { public void SendFullUpdateToAllClientsExcept(UUID agentID) { - List avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Count; i++) + ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); + for (int i = 0; i < avatars.Length; i++) { // Ugly reference :( if (avatars[i].UUID != agentID) @@ -2467,8 +2466,8 @@ if (m_shape != null) { /// public void SendTerseUpdateToAllClients() { - List avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Count; i++) + ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); + for (int i = 0; i < avatars.Length; i++) { SendTerseUpdateToClient(avatars[i].ControllingClient); } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index ccfffe7..77706ac 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -869,14 +869,16 @@ namespace OpenSim.Region.Framework.Scenes m_isChildAgent = false; - List AnimAgents = m_scene.GetScenePresences(); - foreach (ScenePresence p in AnimAgents) + ScenePresence[] animAgents = m_scene.GetScenePresences(); + for (int i = 0; i < animAgents.Length; i++) { - if (p != this) - p.SendAnimPackToClient(ControllingClient); + ScenePresence presence = animAgents[i]; + + if (presence != this) + presence.SendAnimPackToClient(ControllingClient); } - m_scene.EventManager.TriggerOnMakeRootAgent(this); + m_scene.EventManager.TriggerOnMakeRootAgent(this); } /// @@ -2533,9 +2535,12 @@ namespace OpenSim.Region.Framework.Scenes { m_perfMonMS = Environment.TickCount; - List avatars = m_scene.GetScenePresences(); - foreach (ScenePresence avatar in avatars) + ScenePresence[] avatars = m_scene.GetScenePresences(); + + for (int i = 0; i < avatars.Length; i++) { + ScenePresence avatar = avatars[i]; + // only send if this is the root (children are only "listening posts" in a foreign region) if (!IsChildAgent) { @@ -2553,7 +2558,7 @@ namespace OpenSim.Region.Framework.Scenes } } - m_scene.StatsReporter.AddAgentUpdates(avatars.Count); + m_scene.StatsReporter.AddAgentUpdates(avatars.Length); m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); //SendAnimPack(); -- cgit v1.1 From 62f1a5e36d85b95e8f80bc073ba876873494963a Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 23 Oct 2009 02:38:59 -0700 Subject: Implemented a "FrontBack" prioritizer, using distance plus the plane equation to give double weight to prims/avatars in front of you --- OpenSim/Region/Framework/Scenes/Scene.cs | 4 ++ .../Region/Framework/Scenes/SceneObjectGroup.cs | 33 ++++++++++++++-- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 44 ++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index d5e3445..ee848bb 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -61,6 +61,7 @@ namespace OpenSim.Region.Framework.Scenes Time = 0, Distance = 1, SimpleAngularDistance = 2, + FrontBack = 3, } public delegate void SynchronizeSceneHandler(Scene scene); @@ -540,6 +541,9 @@ namespace OpenSim.Region.Framework.Scenes case "simpleangulardistance": m_update_prioritization_scheme = UpdatePrioritizationSchemes.SimpleAngularDistance; break; + case "frontback": + m_update_prioritization_scheme = UpdatePrioritizationSchemes.FrontBack; + break; default: m_log.Warn("[SCENE]: UpdatePrioritizationScheme was not recognized, setting to default settomg of Time"); m_update_prioritization_scheme = UpdatePrioritizationSchemes.Time; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 4f19761..dd8da20 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -493,8 +493,8 @@ namespace OpenSim.Region.Framework.Scenes public Vector3 GroupScale() { - Vector3 minScale = new Vector3(Constants.RegionSize,Constants.RegionSize,Constants.RegionSize); - Vector3 maxScale = new Vector3(0f,0f,0f); + Vector3 minScale = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionSize); + Vector3 maxScale = Vector3.Zero; Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); lock (m_parts) @@ -577,7 +577,6 @@ namespace OpenSim.Region.Framework.Scenes { foreach (SceneObjectPart part in m_parts.Values) { - Vector3 worldPos = part.GetWorldPosition(); Vector3 offset = worldPos - AbsolutePosition; Quaternion worldRot; @@ -3366,6 +3365,8 @@ namespace OpenSim.Region.Framework.Scenes return GetPriorityByDistance(client); case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: return GetPriorityBySimpleAngularDistance(client); + case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: + return GetPriorityByFrontBack(client); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); } @@ -3398,6 +3399,16 @@ namespace OpenSim.Region.Framework.Scenes return double.NaN; } + private double GetPriorityByFrontBack(IClientAPI client) + { + ScenePresence presence = Scene.GetScenePresence(client.AgentId); + if (presence != null) + { + return GetPriorityByFrontBack(presence.CameraPosition, presence.CameraAtAxis); + } + return double.NaN; + } + public double GetPriorityByDistance(Vector3 position) { return Vector3.Distance(AbsolutePosition, position); @@ -3427,5 +3438,21 @@ namespace OpenSim.Region.Framework.Scenes else return double.MinValue; } + + public double GetPriorityByFrontBack(Vector3 camPosition, Vector3 camAtAxis) + { + // Distance + double priority = Vector3.Distance(camPosition, AbsolutePosition); + + // Scale + //priority -= GroupScale().Length(); + + // Plane equation + float d = -Vector3.Dot(camPosition, camAtAxis); + float p = Vector3.Dot(camAtAxis, AbsolutePosition) + d; + if (p < 0.0f) priority *= 2.0f; + + return priority; + } } } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 77706ac..a610e42 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -297,6 +297,21 @@ namespace OpenSim.Region.Framework.Scenes get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); } } + public Vector3 CameraAtAxis + { + get { return m_CameraAtAxis; } + } + + public Vector3 CameraLeftAxis + { + get { return m_CameraLeftAxis; } + } + + public Vector3 CameraUpAxis + { + get { return m_CameraUpAxis; } + } + public Vector3 Lookat { get @@ -3867,6 +3882,8 @@ namespace OpenSim.Region.Framework.Scenes return GetPriorityByDistance(client); case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: return GetPriorityByDistance(client); + case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: + return GetPriorityByFrontBack(client); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined."); } @@ -3888,11 +3905,34 @@ namespace OpenSim.Region.Framework.Scenes return double.NaN; } + private double GetPriorityByFrontBack(IClientAPI client) + { + ScenePresence presence = Scene.GetScenePresence(client.AgentId); + if (presence != null) + { + return GetPriorityByFrontBack(presence.CameraPosition, presence.CameraAtAxis); + } + return double.NaN; + } + private double GetPriorityByDistance(Vector3 position) { return Vector3.Distance(AbsolutePosition, position); } + private double GetPriorityByFrontBack(Vector3 camPosition, Vector3 camAtAxis) + { + // Distance + double priority = Vector3.Distance(camPosition, AbsolutePosition); + + // Plane equation + float d = -Vector3.Dot(camPosition, camAtAxis); + float p = Vector3.Dot(camAtAxis, AbsolutePosition) + d; + if (p < 0.0f) priority *= 2.0f; + + return priority; + } + private double GetSOGUpdatePriority(SceneObjectGroup sog) { switch (Scene.UpdatePrioritizationScheme) @@ -3903,6 +3943,8 @@ namespace OpenSim.Region.Framework.Scenes return sog.GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: return sog.GetPriorityBySimpleAngularDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); + case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: + return sog.GetPriorityByFrontBack(CameraPosition, CameraAtAxis); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); } @@ -3929,6 +3971,8 @@ namespace OpenSim.Region.Framework.Scenes case Scene.UpdatePrioritizationSchemes.Distance: case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: return GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); + case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: + return GetPriorityByFrontBack(CameraPosition, CameraAtAxis); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); } -- cgit v1.1 From a41cd1d0695c01e4096fa0b7696b415a4c7455fc Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 23 Oct 2009 13:14:29 -0700 Subject: * Unregister Mono.Addins event handlers in PluginLoader.Dispose() and always handle PluginLoader with the using pattern. This freed up 121,634,796 bytes on my system * Avoid allocating an Action object every round of the OutgoingPacketHandler * Removed unnecessary semi-colon endings from OpenSim.ini.example [InterestManagement] section --- OpenSim/Region/Framework/Scenes/Scene.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index ee848bb..a3bc04b 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1223,10 +1223,7 @@ namespace OpenSim.Region.Framework.Scenes if (!m_backingup) { m_backingup = true; - - System.ComponentModel.BackgroundWorker backupWorker = new System.ComponentModel.BackgroundWorker(); - backupWorker.DoWork += delegate(object sender, System.ComponentModel.DoWorkEventArgs e) { Backup(); }; - backupWorker.RunWorkerAsync(); + Util.FireAndForget(BackupWaitCallback); } } @@ -1239,6 +1236,14 @@ namespace OpenSim.Region.Framework.Scenes } /// + /// Wrapper for Backup() that can be called with Util.FireAndForget() + /// + private void BackupWaitCallback(object o) + { + Backup(); + } + + /// /// Backup the scene. This acts as the main method of the backup thread. /// /// -- cgit v1.1 From 2c34619aea074446e53dde80d397973075914bac Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 23 Oct 2009 14:22:21 -0700 Subject: * Changed various modules to not initialize timers unless the module is initialized. Ideally, the timers would not initialize unless the module was actually enabled, but Melanie's work on configuring module loading from a config file should make that unnecessary * Wrapped the Bitmap class used to generate the world map tile in a using statement to dispose of it after the JPEG2000 data is created --- OpenSim/Region/Framework/Scenes/Scene.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index a3bc04b..47b13bd 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -891,6 +891,9 @@ namespace OpenSim.Region.Framework.Scenes { m_log.InfoFormat("[SCENE]: Closing down the single simulator: {0}", RegionInfo.RegionName); + m_restartTimer.Stop(); + m_restartTimer.Close(); + // Kick all ROOT agents with the message, 'The simulator is going down' ForEachScenePresence(delegate(ScenePresence avatar) { -- cgit v1.1 From 730930955a7edc0bfa69ff1cac93acd024cf8d24 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Sun, 25 Oct 2009 00:40:21 -0700 Subject: Changing Scene.ForEachClient to use the synchronous for loop instead of Parallel. This is quite possibly the source of some deadlocking, and at the very least the synchronous version gives better stack traces * Lock the LLUDPClient RTO math * Add a helper function for backing off the RTO, and follow the optional advice in RFC 2988 to clear existing SRTT and RTTVAR values during a backoff * Removing the unused PrimitiveBaseShape.SculptImage parameter * Improved performance of SceneObjectPart instantiation * ZeroMesher now drops SculptData bytes like Meshmerizer, to allow the texture data to be GCed * Improved typecasting speed in MySQLLegacyRegionData.BuildShape() * Improved the instantiation of PrimitiveBaseShape --- OpenSim/Region/Framework/Scenes/Scene.cs | 2 +- .../Region/Framework/Scenes/SceneObjectGroup.cs | 2 +- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 109 ++++++++++----------- 3 files changed, 56 insertions(+), 57 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 47b13bd..f052c65 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4246,7 +4246,7 @@ namespace OpenSim.Region.Framework.Scenes public void ForEachClient(Action action) { - ClientManager.ForEach(action); + ClientManager.ForEachSync(action); } public void ForEachSOG(Action action) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index dd8da20..34ada4c 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1334,7 +1334,7 @@ namespace OpenSim.Region.Framework.Scenes (parcel.LandData.GroupID != GroupID || parcel.LandData.GroupID == UUID.Zero)) { - if ((DateTime.Now - RootPart.Rezzed).TotalMinutes > + if ((DateTime.UtcNow - RootPart.Rezzed).TotalMinutes > parcel.LandData.OtherCleanTime) { DetachFromBackup(); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 7193002..d84c35c 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -102,16 +102,16 @@ namespace OpenSim.Region.Framework.Scenes #region Fields - public bool AllowedDrop = false; + public bool AllowedDrop; [XmlIgnore] - public bool DIE_AT_EDGE = false; + public bool DIE_AT_EDGE; // TODO: This needs to be persisted in next XML version update! [XmlIgnore] - public int[] PayPrice = {-2,-2,-2,-2,-2}; + public readonly int[] PayPrice = {-2,-2,-2,-2,-2}; [XmlIgnore] - public PhysicsActor PhysActor = null; + public PhysicsActor PhysActor; //Xantor 20080528 Sound stuff: // Note: This isn't persisted in the database right now, as the fields for that aren't just there yet. @@ -130,55 +130,56 @@ namespace OpenSim.Region.Framework.Scenes public double SoundRadius; [XmlIgnore] - public uint TimeStampFull = 0; + public uint TimeStampFull; [XmlIgnore] - public uint TimeStampLastActivity = 0; // Will be used for AutoReturn + public uint TimeStampLastActivity; // Will be used for AutoReturn [XmlIgnore] - public uint TimeStampTerse = 0; - + public uint TimeStampTerse; + [XmlIgnore] - public UUID FromItemID = UUID.Zero; + public UUID FromItemID; /// /// The UUID of the user inventory item from which this object was rezzed if this is a root part. /// If UUID.Zero then either this is not a root part or there is no connection with a user inventory item. /// - private UUID m_fromUserInventoryItemID = UUID.Zero; + private UUID m_fromUserInventoryItemID; [XmlIgnore] public UUID FromUserInventoryItemID { get { return m_fromUserInventoryItemID; } } - + [XmlIgnore] - public bool IsAttachment = false; - + public bool IsAttachment; + [XmlIgnore] - public scriptEvents AggregateScriptEvents = 0; - + public scriptEvents AggregateScriptEvents; + [XmlIgnore] - public UUID AttachedAvatar = UUID.Zero; - + public UUID AttachedAvatar; + [XmlIgnore] - public Vector3 AttachedPos = Vector3.Zero; - + public Vector3 AttachedPos; + [XmlIgnore] - public uint AttachmentPoint = (byte)0; + public uint AttachmentPoint; [XmlIgnore] - public PhysicsVector RotationAxis = new PhysicsVector(1f,1f,1f); + public PhysicsVector RotationAxis = new PhysicsVector(1f, 1f, 1f); [XmlIgnore] - public bool VolumeDetectActive = false; // XmlIgnore set to avoid problems with persistance until I come to care for this - // Certainly this must be a persistant setting finally + public bool VolumeDetectActive; // XmlIgnore set to avoid problems with persistance until I come to care for this + // Certainly this must be a persistant setting finally [XmlIgnore] - public bool IsWaitingForFirstSpinUpdatePacket = false; + public bool IsWaitingForFirstSpinUpdatePacket; + [XmlIgnore] - public Quaternion SpinOldOrientation = new Quaternion(); + public Quaternion SpinOldOrientation = Quaternion.Identity; /// /// This part's inventory @@ -191,34 +192,32 @@ namespace OpenSim.Region.Framework.Scenes protected SceneObjectPartInventory m_inventory; [XmlIgnore] - public bool Undoing = false; + public bool Undoing; [XmlIgnore] - private PrimFlags LocalFlags = 0; + private PrimFlags LocalFlags; [XmlIgnore] private float m_damage = -1.0f; private byte[] m_TextureAnimation; - private byte m_clickAction = 0; + private byte m_clickAction; private Color m_color = Color.Black; private string m_description = String.Empty; private readonly List m_lastColliders = new List(); - // private PhysicsVector m_lastRotationalVelocity = PhysicsVector.Zero; - private int m_linkNum = 0; + private int m_linkNum; [XmlIgnore] - private int m_scriptAccessPin = 0; + private int m_scriptAccessPin; [XmlIgnore] private readonly Dictionary m_scriptEvents = new Dictionary(); private string m_sitName = String.Empty; private Quaternion m_sitTargetOrientation = Quaternion.Identity; - private Vector3 m_sitTargetPosition = Vector3.Zero; + private Vector3 m_sitTargetPosition; private string m_sitAnimation = "SIT"; private string m_text = String.Empty; private string m_touchName = String.Empty; private readonly UndoStack m_undo = new UndoStack(5); private UUID _creatorID; - - private bool m_passTouches = false; + private bool m_passTouches; /// /// Only used internally to schedule client updates. @@ -236,28 +235,28 @@ namespace OpenSim.Region.Framework.Scenes //unkown if this will be kept, added as a way of removing the group position from the group class protected Vector3 m_groupPosition; protected uint m_localId; - protected Material m_material = (Material)3; // Wood + protected Material m_material = OpenMetaverse.Material.Wood; protected string m_name; protected Vector3 m_offsetPosition; // FIXME, TODO, ERROR: 'ParentGroup' can't be in here, move it out. protected SceneObjectGroup m_parentGroup; - protected byte[] m_particleSystem = new byte[0]; + protected byte[] m_particleSystem = Utils.EmptyBytes; protected ulong m_regionHandle; protected Quaternion m_rotationOffset; - protected PrimitiveBaseShape m_shape = null; + protected PrimitiveBaseShape m_shape; protected UUID m_uuid; protected Vector3 m_velocity; // TODO: Those have to be changed into persistent properties at some later point, // or sit-camera on vehicles will break on sim-crossing. - private Vector3 m_cameraEyeOffset = new Vector3(0.0f, 0.0f, 0.0f); - private Vector3 m_cameraAtOffset = new Vector3(0.0f, 0.0f, 0.0f); - private bool m_forceMouselook = false; + private Vector3 m_cameraEyeOffset; + private Vector3 m_cameraAtOffset; + private bool m_forceMouselook; // TODO: Collision sound should have default. - private UUID m_collisionSound = UUID.Zero; - private float m_collisionSoundVolume = 0.0f; + private UUID m_collisionSound; + private float m_collisionSoundVolume; #endregion Fields @@ -269,9 +268,9 @@ namespace OpenSim.Region.Framework.Scenes public SceneObjectPart() { // It's not necessary to persist this - m_TextureAnimation = new byte[0]; - m_particleSystem = new byte[0]; - Rezzed = DateTime.Now; + m_TextureAnimation = Utils.EmptyBytes; + m_particleSystem = Utils.EmptyBytes; + Rezzed = DateTime.UtcNow; m_inventory = new SceneObjectPartInventory(this); } @@ -290,8 +289,8 @@ namespace OpenSim.Region.Framework.Scenes { m_name = "Primitive"; - Rezzed = DateTime.Now; - _creationDate = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; + Rezzed = DateTime.UtcNow; + _creationDate = (int)Utils.DateTimeToUnixTime(Rezzed); _ownerID = ownerID; _creatorID = _ownerID; _lastOwnerID = UUID.Zero; @@ -299,19 +298,19 @@ namespace OpenSim.Region.Framework.Scenes Shape = shape; // Todo: Add More Object Parameter from above! _ownershipCost = 0; - _objectSaleType = (byte) 0; + _objectSaleType = 0; _salePrice = 0; - _category = (uint) 0; + _category = 0; _lastOwnerID = _creatorID; // End Todo: /// GroupPosition = groupPosition; OffsetPosition = offsetPosition; RotationOffset = rotationOffset; - Velocity = new Vector3(0, 0, 0); - AngularVelocity = new Vector3(0, 0, 0); - Acceleration = new Vector3(0, 0, 0); - m_TextureAnimation = new byte[0]; - m_particleSystem = new byte[0]; + Velocity = Vector3.Zero; + AngularVelocity = Vector3.Zero; + Acceleration = Vector3.Zero; + m_TextureAnimation = Utils.EmptyBytes; + m_particleSystem = Utils.EmptyBytes; // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol, // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from @@ -3548,7 +3547,7 @@ if (m_shape != null) { // in SL. // if (ParentGroup.RootPart != this) - ParentGroup.RootPart.Rezzed = DateTime.Now; + ParentGroup.RootPart.Rezzed = DateTime.UtcNow; ParentGroup.HasGroupChanged = true; ScheduleFullUpdate(); -- cgit v1.1 From de25dcfb7b28c81b7bce187165be81f65b849a7c Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Sun, 25 Oct 2009 01:01:26 -0700 Subject: Minor tweaks to get OpenSim compiling against both the current libomv and the upcoming 0.8.0 --- OpenSim/Region/Framework/Scenes/AnimationSet.cs | 2 ++ OpenSim/Region/Framework/Scenes/ScenePresence.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/AnimationSet.cs b/OpenSim/Region/Framework/Scenes/AnimationSet.cs index aa0c8b8..740d168 100644 --- a/OpenSim/Region/Framework/Scenes/AnimationSet.cs +++ b/OpenSim/Region/Framework/Scenes/AnimationSet.cs @@ -30,6 +30,8 @@ using System.Collections.Generic; using OpenSim.Framework; using OpenMetaverse; +using Animation = OpenSim.Framework.Animation; + namespace OpenSim.Region.Framework.Scenes { [Serializable] diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index a610e42..67384fb 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2693,7 +2693,7 @@ namespace OpenSim.Region.Framework.Scenes { if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) { - m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + (AppearanceManager.TextureIndex)j + ") for avatar " + this.Name); + m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + j + ") for avatar " + this.Name); this.ControllingClient.SendRebakeAvatarTextures(face.TextureID); } } -- cgit v1.1 From ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 26 Oct 2009 14:41:27 -0700 Subject: * Changed the watchdog timer to improve the speed of UpdateThread(), only track threads once the first call to UpdateThread() has been made, and allow re-tracking of threads that timed out but revived later * Added a commented out call to Watchdog.UpdateThread() in OdeScene. If it turns out that loading a large OAR file or some other operation is timing out the heartbeat thread, we'll need to uncomment it --- OpenSim/Region/Framework/Scenes/Scene.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index f052c65..95d69a1 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1025,6 +1025,7 @@ namespace OpenSim.Region.Framework.Scenes float physicsFPS = 0; frameMS = Environment.TickCount; + try { // Increment the frame counter @@ -1152,6 +1153,7 @@ namespace OpenSim.Region.Framework.Scenes if ((maintc < (m_timespan * 1000)) && maintc > 0) Thread.Sleep(maintc); + // Tell the watchdog that this thread is still alive Watchdog.UpdateThread(); } } -- cgit v1.1 From 119cf80e13e9fccea30147e3274f5d44958248b2 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 26 Oct 2009 15:52:59 -0700 Subject: Added calls to GC.AddMemoryPressure() when unmanaged memory is allocated for ODE (helps the GC make better scheduling choices), and a call to GC.Collect() right before logins are enabled for a region. Although this doesn't change actual memory usage, it improves the reported usage from OpenSim and the operating system --- OpenSim/Region/Framework/Scenes/Scene.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 95d69a1..4776bed 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1107,6 +1107,11 @@ namespace OpenSim.Region.Framework.Scenes } if (loginsdisabled && (m_frame > 20)) { + // In 99.9% of cases it is a bad idea to manually force garbage collection. However, + // this is a rare case where we know we have just went through a long cycle of heap + // allocations, and there is no more work to be done until someone logs in + GC.Collect(); + m_log.Debug("[REGION]: Enabling Logins"); loginsdisabled = false; } -- cgit v1.1 From 4847e62e9fd1cd473cc180220a379efba93f94a6 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 26 Oct 2009 16:33:04 -0700 Subject: * Switched all operations on the list of clients that could be either sync or async to use Scene.ForEachClient() instead of referencing ClientManager directly * Added a new [Startup] config option called use_async_when_possible to signal how to run operations that could be either sync or async * Changed Scene.ForEachClient to respect use_async_when_possible * Fixing a potential deadlock in Parallel.ForEach by locking on a temporary object instead of the enumerator (which may be shared across multiple invocations on ForEach). Thank you diva --- .../Framework/Scenes/Scene.PacketHandlers.cs | 2 +- OpenSim/Region/Framework/Scenes/Scene.cs | 48 ++++++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs index ac89f7b..cfe32d0 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs @@ -408,7 +408,7 @@ namespace OpenSim.Region.Framework.Scenes } ViewerEffectPacket.EffectBlock[] effectBlockArray = effectBlock.ToArray(); - ClientManager.ForEach( + ForEachClient( delegate(IClientAPI client) { if (client.AgentId != remoteClient.AgentId) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 4776bed..91367db 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -106,11 +106,11 @@ namespace OpenSim.Region.Framework.Scenes public bool m_physicalPrim; public float m_maxNonphys = 256; public float m_maxPhys = 10; - public bool m_clampPrimSize = false; - public bool m_trustBinaries = false; - public bool m_allowScriptCrossings = false; - public bool m_useFlySlow = false; - public bool m_usePreJump = false; + public bool m_clampPrimSize; + public bool m_trustBinaries; + public bool m_allowScriptCrossings; + public bool m_useFlySlow; + public bool m_usePreJump; public bool m_seeIntoRegionFromNeighbor; // TODO: need to figure out how allow client agents but deny // root agents when ACL denies access to root agent @@ -118,11 +118,11 @@ namespace OpenSim.Region.Framework.Scenes public int MaxUndoCount = 5; private int m_RestartTimerCounter; private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing - private int m_incrementsof15seconds = 0; - private volatile bool m_backingup = false; + private int m_incrementsof15seconds; + private volatile bool m_backingup; + private bool m_useAsyncWhenPossible = true; private Dictionary m_returns = new Dictionary(); - private Dictionary m_groupsWithTargets = new Dictionary(); protected string m_simulatorVersion = "OpenSimulator Server"; @@ -142,8 +142,8 @@ namespace OpenSim.Region.Framework.Scenes public IXfer XferManager; - protected IAssetService m_AssetService = null; - protected IAuthorizationService m_AuthorizationService = null; + protected IAssetService m_AssetService; + protected IAuthorizationService m_AuthorizationService; private Object m_heartbeatLock = new Object(); @@ -184,7 +184,7 @@ namespace OpenSim.Region.Framework.Scenes } } - protected IInventoryService m_InventoryService = null; + protected IInventoryService m_InventoryService; public IInventoryService InventoryService { @@ -204,7 +204,7 @@ namespace OpenSim.Region.Framework.Scenes } } - protected IGridService m_GridService = null; + protected IGridService m_GridService; public IGridService GridService { @@ -252,7 +252,7 @@ namespace OpenSim.Region.Framework.Scenes // Central Update Loop protected int m_fps = 10; - protected int m_frame = 0; + protected int m_frame; protected float m_timespan = 0.089f; protected DateTime m_lastupdate = DateTime.UtcNow; @@ -265,17 +265,17 @@ namespace OpenSim.Region.Framework.Scenes private int m_update_terrain = 50; private int m_update_land = 1; - private int frameMS = 0; - private int physicsMS2 = 0; - private int physicsMS = 0; - private int otherMS = 0; + private int frameMS; + private int physicsMS2; + private int physicsMS; + private int otherMS; private bool m_physics_enabled = true; private bool m_scripts_enabled = true; private string m_defaultScriptEngine; - private int m_LastLogin = 0; - private Thread HeartbeatThread = null; - private volatile bool shuttingdown = false; + private int m_LastLogin; + private Thread HeartbeatThread; + private volatile bool shuttingdown; private int m_lastUpdate = Environment.TickCount; private bool m_firstHeartbeat = true; @@ -479,6 +479,9 @@ namespace OpenSim.Region.Framework.Scenes // IConfig startupConfig = m_config.Configs["Startup"]; + // Should we try to run loops synchronously or asynchronously? + m_useAsyncWhenPossible = startupConfig.GetBoolean("use_async_when_possible", true); + //Animation states m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); // TODO: Change default to true once the feature is supported @@ -4253,7 +4256,10 @@ namespace OpenSim.Region.Framework.Scenes public void ForEachClient(Action action) { - ClientManager.ForEachSync(action); + if (m_useAsyncWhenPossible) + ClientManager.ForEach(action); + else + ClientManager.ForEachSync(action); } public void ForEachSOG(Action action) -- cgit v1.1 From 0b1726b524934c2020aaf2b1f130219fb87003fd Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 26 Oct 2009 16:48:43 -0700 Subject: Removing the ClientManager reference from IScene and hiding it entirely inside Scene as an implementation detail. This will reduce programming error and make it easier to refactor the avatar vs client vs presence mess later on --- OpenSim/Region/Framework/Scenes/Scene.cs | 25 ++++++++++++++++++++----- OpenSim/Region/Framework/Scenes/SceneBase.cs | 7 +------ 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 91367db..7eafef7 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2482,7 +2482,7 @@ namespace OpenSim.Region.Framework.Scenes /// public override void AddNewClient(IClientAPI client) { - ClientManager.Add(client); + m_clientManager.Add(client); CheckHeartbeat(); SubscribeToClientEvents(client); @@ -3121,7 +3121,7 @@ namespace OpenSim.Region.Framework.Scenes // Remove the avatar from the scene m_sceneGraph.RemoveScenePresence(agentID); - ClientManager.Remove(agentID); + m_clientManager.Remove(agentID); try { @@ -4256,10 +4256,25 @@ namespace OpenSim.Region.Framework.Scenes public void ForEachClient(Action action) { - if (m_useAsyncWhenPossible) - ClientManager.ForEach(action); + ForEachClient(action, m_useAsyncWhenPossible); + } + + public void ForEachClient(Action action, bool doAsynchronous) + { + if (doAsynchronous) + m_clientManager.ForEach(action); else - ClientManager.ForEachSync(action); + m_clientManager.ForEachSync(action); + } + + public bool TryGetClient(UUID avatarID, out IClientAPI client) + { + return m_clientManager.TryGetValue(avatarID, out client); + } + + public bool TryGetClient(System.Net.IPEndPoint remoteEndPoint, out IClientAPI client) + { + return m_clientManager.TryGetValue(remoteEndPoint, out client); } public void ForEachSOG(Action action) diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index cf5c3c8..82731d1 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -102,12 +102,7 @@ namespace OpenSim.Region.Framework.Scenes private readonly Mutex _primAllocateMutex = new Mutex(false); - private readonly ClientManager m_clientManager = new ClientManager(); - - public ClientManager ClientManager - { - get { return m_clientManager; } - } + protected readonly ClientManager m_clientManager = new ClientManager(); public float TimeDilation { -- cgit v1.1 From b6651ce79017bc7c6d1df66757e26a74bacfc36f Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 26 Oct 2009 18:22:32 -0700 Subject: * Double the priority on avatar bake texture requests to get avatars rezzing in faster than the surrounding scene * Adds duplicate tracking for SceneObjectParts and ScenePresences to avoid sending out duplicate ImprovedTerseObjectUpdate packets --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 44 ++++++++++---- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 69 +++++++--------------- 2 files changed, 55 insertions(+), 58 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index d84c35c..a87bde0 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -248,6 +248,12 @@ namespace OpenSim.Region.Framework.Scenes protected UUID m_uuid; protected Vector3 m_velocity; + protected Vector3 m_lastPosition; + protected Quaternion m_lastRotation; + protected Vector3 m_lastVelocity; + protected Vector3 m_lastAcceleration; + protected Vector3 m_lastAngularVelocity; + // TODO: Those have to be changed into persistent properties at some later point, // or sit-camera on vehicles will break on sim-crossing. private Vector3 m_cameraEyeOffset; @@ -2387,18 +2393,36 @@ if (m_shape != null) { /// public void SendScheduledUpdates() { - if (m_updateFlag == 1) //some change has been made so update the clients + const float VELOCITY_TOLERANCE = 0.01f; + const float POSITION_TOLERANCE = 10.0f; + + if (m_updateFlag == 1) { - AddTerseUpdateToAllAvatars(); - ClearUpdateSchedule(); + // Throw away duplicate or insignificant updates + if (RotationOffset != m_lastRotation || + Acceleration != m_lastAcceleration || + (Velocity - m_lastVelocity).Length() > VELOCITY_TOLERANCE || + (RotationalVelocity - m_lastAngularVelocity).Length() > VELOCITY_TOLERANCE || + (OffsetPosition - m_lastPosition).Length() > POSITION_TOLERANCE) + { + AddTerseUpdateToAllAvatars(); + ClearUpdateSchedule(); - // This causes the Scene to 'poll' physical objects every couple of frames - // bad, so it's been replaced by an event driven method. - //if ((ObjectFlags & (uint)PrimFlags.Physics) != 0) - //{ - // Only send the constant terse updates on physical objects! - //ScheduleTerseUpdate(); - //} + // This causes the Scene to 'poll' physical objects every couple of frames + // bad, so it's been replaced by an event driven method. + //if ((ObjectFlags & (uint)PrimFlags.Physics) != 0) + //{ + // Only send the constant terse updates on physical objects! + //ScheduleTerseUpdate(); + //} + + // Update the "last" values + m_lastPosition = OffsetPosition; + m_lastRotation = RotationOffset; + m_lastVelocity = Velocity; + m_lastAcceleration = Acceleration; + m_lastAngularVelocity = RotationalVelocity; + } } else { diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 67384fb..0ac5be0 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -93,12 +93,13 @@ namespace OpenSim.Region.Framework.Scenes public Vector3 lastKnownAllowedPosition; public bool sentMessageAboutRestrictedParcelFlyingDown; - + private Vector3 m_lastPosition; + private Quaternion m_lastRotation; + private Vector3 m_lastVelocity; private bool m_updateflag; private byte m_movementflag; private readonly List m_forcesList = new List(); - private short m_updateCount; private uint m_requestedSitTargetID; private UUID m_requestedSitTargetUUID = UUID.Zero; private SendCourseLocationsMethod m_sendCourseLocationsMethod; @@ -145,12 +146,9 @@ namespace OpenSim.Region.Framework.Scenes public string JID = string.Empty; // Agent moves with a PID controller causing a force to be exerted. - private bool m_newForce; private bool m_newCoarseLocations = true; private float m_health = 100f; - private Vector3 m_lastVelocity = Vector3.Zero; - // Default AV Height private float m_avHeight = 127.0f; @@ -158,16 +156,6 @@ namespace OpenSim.Region.Framework.Scenes protected ulong crossingFromRegion; private readonly Vector3[] Dir_Vectors = new Vector3[6]; - - /// - /// The avatar position last sent to clients - /// - private Vector3 lastPhysPos = Vector3.Zero; - - /// - /// The avatar body rotation last sent to clients - /// - private Quaternion lastPhysRot = Quaternion.Identity; // Position of agent's camera in world (region cordinates) protected Vector3 m_CameraCenter = Vector3.Zero; @@ -1123,18 +1111,18 @@ namespace OpenSim.Region.Framework.Scenes CameraConstraintActive = true; //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); - Vector3 normal = Vector3.Normalize(new Vector3(0,0,collisionPoint.Z) - collisionPoint); + Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); } else { - if (((Util.GetDistanceTo(lastPhysPos, AbsolutePosition) > 0.02) - || (Util.GetDistanceTo(m_lastVelocity, m_velocity) > 0.02) - || lastPhysRot != m_bodyRot)) + if ((m_pos - m_lastPosition).Length() > 0.02f || + (m_velocity - m_lastVelocity).Length() > 0.02f || + m_bodyRot != m_lastRotation) { if (CameraConstraintActive) { - ControllingClient.SendCameraConstraint(new Vector4(0, 0.5f, 0.9f, -3000f)); + ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); CameraConstraintActive = false; } } @@ -2373,6 +2361,9 @@ namespace OpenSim.Region.Framework.Scenes public override void Update() { + const float VELOCITY_TOLERANCE = 0.01f; + const float POSITION_TOLERANCE = 10.0f; + SendPrimUpdates(); if (m_newCoarseLocations) @@ -2383,28 +2374,17 @@ namespace OpenSim.Region.Framework.Scenes if (m_isChildAgent == false) { - if (m_newForce) // user movement 'forces' (ie commands to move) + // Throw away duplicate or insignificant updates + if (m_bodyRot != m_lastRotation || + (m_velocity - m_lastVelocity).Length() > VELOCITY_TOLERANCE || + (m_pos - m_lastPosition).Length() > POSITION_TOLERANCE) { SendTerseUpdateToAllClients(); - m_updateCount = 0; - } - else if (m_movementflag != 0) // scripted movement (?) - { - m_updateCount++; - if (m_updateCount > 3) - { - SendTerseUpdateToAllClients(); - m_updateCount = 0; - } - } - else if ((Util.GetDistanceTo(lastPhysPos, AbsolutePosition) > 0.02) - || (Util.GetDistanceTo(m_lastVelocity, m_velocity) > 0.02) - || lastPhysRot != m_bodyRot) - { - // Send Terse Update to all clients updates lastPhysPos and m_lastVelocity - // doing the above assures us that we know what we sent the clients last - SendTerseUpdateToAllClients(); - m_updateCount = 0; + + // Update the "last" values + m_lastPosition = m_pos; + m_lastRotation = m_bodyRot; + m_lastVelocity = m_velocity; } // followed suggestion from mic bowman. reversed the two lines below. @@ -2447,15 +2427,10 @@ namespace OpenSim.Region.Framework.Scenes public void SendTerseUpdateToAllClients() { m_perfMonMS = Environment.TickCount; - + m_scene.ForEachClient(SendTerseUpdateToClient); - m_lastVelocity = m_velocity; - lastPhysPos = AbsolutePosition; - lastPhysRot = m_bodyRot; - m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); - } public void SendCoarseLocations() @@ -3316,7 +3291,6 @@ namespace OpenSim.Region.Framework.Scenes /// public override void UpdateMovement() { - m_newForce = false; lock (m_forcesList) { if (m_forcesList.Count > 0) @@ -3338,7 +3312,6 @@ namespace OpenSim.Region.Framework.Scenes // Ignoring this causes no movement to be sent to the physics engine... // which when the scene is moving at 1 frame every 10 seconds, it doesn't really matter! } - m_newForce = true; m_forcesList.Clear(); } -- cgit v1.1 From d199767e6991d6f368661fce9c5a072e564b8a4b Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Sun, 25 Oct 2009 23:16:12 -0700 Subject: Experimental change of PhysicsVector to Vector3. Untested --- OpenSim/Region/Framework/Scenes/Scene.cs | 4 +- .../Region/Framework/Scenes/SceneObjectGroup.cs | 26 ++++++------ OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 46 +++++++++++----------- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 18 ++++----- 4 files changed, 45 insertions(+), 49 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 7eafef7..6c34056 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4606,7 +4606,7 @@ namespace OpenSim.Region.Framework.Scenes { case PhysicsJointType.Ball: { - PhysicsVector jointAnchor = PhysicsScene.GetJointAnchor(joint); + Vector3 jointAnchor = PhysicsScene.GetJointAnchor(joint); Vector3 proxyPos = new Vector3(jointAnchor.X, jointAnchor.Y, jointAnchor.Z); jointProxyObject.ParentGroup.UpdateGroupPosition(proxyPos); // schedules the entire group for a terse update } @@ -4614,7 +4614,7 @@ namespace OpenSim.Region.Framework.Scenes case PhysicsJointType.Hinge: { - PhysicsVector jointAnchor = PhysicsScene.GetJointAnchor(joint); + Vector3 jointAnchor = PhysicsScene.GetJointAnchor(joint); // Normally, we would just ask the physics scene to return the axis for the joint. // Unfortunately, ODE sometimes returns <0,0,0> for the joint axis, which should diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 34ada4c..38a0cff 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1479,8 +1479,8 @@ namespace OpenSim.Region.Framework.Scenes dupe.RootPart.PhysActor = m_scene.PhysicsScene.AddPrimShape( dupe.RootPart.Name, pbs, - new PhysicsVector(dupe.RootPart.AbsolutePosition.X, dupe.RootPart.AbsolutePosition.Y, dupe.RootPart.AbsolutePosition.Z), - new PhysicsVector(dupe.RootPart.Scale.X, dupe.RootPart.Scale.Y, dupe.RootPart.Scale.Z), + dupe.RootPart.AbsolutePosition, + dupe.RootPart.Scale, dupe.RootPart.RotationOffset, dupe.RootPart.PhysActor.IsPhysical); @@ -1595,7 +1595,7 @@ namespace OpenSim.Region.Framework.Scenes */ } - public void applyImpulse(PhysicsVector impulse) + public void applyImpulse(Vector3 impulse) { // We check if rootpart is null here because scripts don't delete if you delete the host. // This means that unfortunately, we can pass a null physics actor to Simulate! @@ -1622,7 +1622,7 @@ namespace OpenSim.Region.Framework.Scenes } } - public void applyAngularImpulse(PhysicsVector impulse) + public void applyAngularImpulse(Vector3 impulse) { // We check if rootpart is null here because scripts don't delete if you delete the host. // This means that unfortunately, we can pass a null physics actor to Simulate! @@ -1641,7 +1641,7 @@ namespace OpenSim.Region.Framework.Scenes } } - public void setAngularImpulse(PhysicsVector impulse) + public void setAngularImpulse(Vector3 impulse) { // We check if rootpart is null here because scripts don't delete if you delete the host. // This means that unfortunately, we can pass a null physics actor to Simulate! @@ -1672,8 +1672,8 @@ namespace OpenSim.Region.Framework.Scenes { if (!IsAttachment) { - PhysicsVector torque = rootpart.PhysActor.Torque; - return new Vector3(torque.X, torque.Y, torque.Z); + Vector3 torque = rootpart.PhysActor.Torque; + return torque; } } } @@ -1706,7 +1706,7 @@ namespace OpenSim.Region.Framework.Scenes { if (rootpart.PhysActor != null) { - rootpart.PhysActor.PIDTarget = new PhysicsVector(target.X, target.Y, target.Z); + rootpart.PhysActor.PIDTarget = target; rootpart.PhysActor.PIDTau = tau; rootpart.PhysActor.PIDActive = true; } @@ -2374,7 +2374,7 @@ namespace OpenSim.Region.Framework.Scenes if (m_rootPart.PhysActor.IsPhysical) { Vector3 llmoveforce = pos - AbsolutePosition; - PhysicsVector grabforce = new PhysicsVector(llmoveforce.X, llmoveforce.Y, llmoveforce.Z); + Vector3 grabforce = llmoveforce; grabforce = (grabforce / 10) * m_rootPart.PhysActor.Mass; m_rootPart.PhysActor.AddForce(grabforce,true); m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); @@ -2479,7 +2479,7 @@ namespace OpenSim.Region.Framework.Scenes rotationAxis.Normalize(); //m_log.Error("SCENE OBJECT GROUP]: rotation axis is " + rotationAxis); - PhysicsVector spinforce = new PhysicsVector(rotationAxis.X, rotationAxis.Y, rotationAxis.Z); + Vector3 spinforce = new Vector3(rotationAxis.X, rotationAxis.Y, rotationAxis.Z); spinforce = (spinforce/8) * m_rootPart.PhysActor.Mass; // 8 is an arbitrary torque scaling factor m_rootPart.PhysActor.AddAngularForce(spinforce,true); m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); @@ -2706,8 +2706,7 @@ namespace OpenSim.Region.Framework.Scenes if (scale.Z > m_scene.m_maxPhys) scale.Z = m_scene.m_maxPhys; } - part.PhysActor.Size = - new PhysicsVector(scale.X, scale.Y, scale.Z); + part.PhysActor.Size = scale; m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); } //if (part.UUID != m_rootPart.UUID) @@ -2851,8 +2850,7 @@ namespace OpenSim.Region.Framework.Scenes if (part.PhysActor != null) { - part.PhysActor.Size = - new PhysicsVector(prevScale.X, prevScale.Y, prevScale.Z); + part.PhysActor.Size = prevScale; m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index a87bde0..70f3112 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -167,9 +167,9 @@ namespace OpenSim.Region.Framework.Scenes [XmlIgnore] public uint AttachmentPoint; - + [XmlIgnore] - public PhysicsVector RotationAxis = new PhysicsVector(1f, 1f, 1f); + public Vector3 RotationAxis = Vector3.One; [XmlIgnore] public bool VolumeDetectActive; // XmlIgnore set to avoid problems with persistance until I come to care for this @@ -537,13 +537,13 @@ namespace OpenSim.Region.Framework.Scenes // Root prim actually goes at Position if (_parentID == 0) { - PhysActor.Position = new PhysicsVector(value.X, value.Y, value.Z); + PhysActor.Position = value; } else { // To move the child prim in respect to the group position and rotation we have to calculate Vector3 resultingposition = GetWorldPosition(); - PhysActor.Position = new PhysicsVector(resultingposition.X, resultingposition.Y, resultingposition.Z); + PhysActor.Position = resultingposition; Quaternion resultingrot = GetWorldRotation(); PhysActor.Orientation = resultingrot; } @@ -585,7 +585,7 @@ namespace OpenSim.Region.Framework.Scenes if (_parentID != 0 && PhysActor != null) { Vector3 resultingposition = GetWorldPosition(); - PhysActor.Position = new PhysicsVector(resultingposition.X, resultingposition.Y, resultingposition.Z); + PhysActor.Position = resultingposition; Quaternion resultingrot = GetWorldRotation(); PhysActor.Orientation = resultingrot; @@ -675,7 +675,7 @@ namespace OpenSim.Region.Framework.Scenes { if (PhysActor.IsPhysical) { - PhysActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z); + PhysActor.Velocity = value; m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); } } @@ -817,7 +817,7 @@ if (m_shape != null) { { if (m_parentGroup.Scene.PhysicsScene != null) { - PhysActor.Size = new PhysicsVector(m_shape.Scale.X, m_shape.Scale.Y, m_shape.Scale.Z); + PhysActor.Size = m_shape.Scale; m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); } } @@ -1225,7 +1225,7 @@ if (m_shape != null) { /// true for the local frame, false for the global frame public void ApplyImpulse(Vector3 impulsei, bool localGlobalTF) { - PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z); + Vector3 impulse = impulsei; if (localGlobalTF) { @@ -1233,7 +1233,7 @@ if (m_shape != null) { Quaternion AXgrot = grot; Vector3 AXimpulsei = impulsei; Vector3 newimpulse = AXimpulsei * AXgrot; - impulse = new PhysicsVector(newimpulse.X, newimpulse.Y, newimpulse.Z); + impulse = newimpulse; } if (m_parentGroup != null) @@ -1251,7 +1251,7 @@ if (m_shape != null) { /// true for the local frame, false for the global frame public void ApplyAngularImpulse(Vector3 impulsei, bool localGlobalTF) { - PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z); + Vector3 impulse = impulsei; if (localGlobalTF) { @@ -1259,7 +1259,7 @@ if (m_shape != null) { Quaternion AXgrot = grot; Vector3 AXimpulsei = impulsei; Vector3 newimpulse = AXimpulsei * AXgrot; - impulse = new PhysicsVector(newimpulse.X, newimpulse.Y, newimpulse.Z); + impulse = newimpulse; } if (m_parentGroup != null) @@ -1277,7 +1277,7 @@ if (m_shape != null) { /// true for the local frame, false for the global frame public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF) { - PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z); + Vector3 impulse = impulsei; if (localGlobalTF) { @@ -1285,7 +1285,7 @@ if (m_shape != null) { Quaternion AXgrot = grot; Vector3 AXimpulsei = impulsei; Vector3 newimpulse = AXimpulsei * AXgrot; - impulse = new PhysicsVector(newimpulse.X, newimpulse.Y, newimpulse.Z); + impulse = newimpulse; } if (m_parentGroup != null) @@ -1333,8 +1333,8 @@ if (m_shape != null) { PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape( Name, Shape, - new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z), - new PhysicsVector(Scale.X, Scale.Y, Scale.Z), + AbsolutePosition, + Scale, RotationOffset, RigidBody); @@ -1523,7 +1523,7 @@ if (m_shape != null) { PhysicsJoint joint; joint = m_parentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType, - new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z), + AbsolutePosition, this.RotationOffset, Description, bodyNames, @@ -1708,12 +1708,12 @@ if (m_shape != null) { } } - public PhysicsVector GetForce() + public Vector3 GetForce() { if (PhysActor != null) return PhysActor.Force; else - return new PhysicsVector(); + return Vector3.Zero; } public void GetProperties(IClientAPI client) @@ -2078,7 +2078,7 @@ if (m_shape != null) { } } - public void PhysicsOutOfBounds(PhysicsVector pos) + public void PhysicsOutOfBounds(Vector3 pos) { m_log.Error("[PHYSICS]: Physical Object went out of bounds."); @@ -2564,7 +2564,7 @@ if (m_shape != null) { } } - public void SetForce(PhysicsVector force) + public void SetForce(Vector3 force) { if (PhysActor != null) { @@ -2588,7 +2588,7 @@ if (m_shape != null) { } } - public void SetVehicleVectorParam(int param, PhysicsVector value) + public void SetVehicleVectorParam(int param, Vector3 value) { if (PhysActor != null) { @@ -3430,8 +3430,8 @@ if (m_shape != null) { PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape( Name, Shape, - new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z), - new PhysicsVector(Scale.X, Scale.Y, Scale.Z), + AbsolutePosition, + Scale, RotationOffset, UsePhysics); diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 0ac5be0..87fac0c 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -434,7 +434,7 @@ namespace OpenSim.Region.Framework.Scenes { lock (m_scene.SyncRoot) { - m_physicsActor.Position = new PhysicsVector(value.X, value.Y, value.Z); + m_physicsActor.Position = value; } } catch (Exception e) @@ -474,7 +474,7 @@ namespace OpenSim.Region.Framework.Scenes { lock (m_scene.SyncRoot) { - m_physicsActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z); + m_physicsActor.Velocity = value; } } catch (Exception e) @@ -1046,7 +1046,7 @@ namespace OpenSim.Region.Framework.Scenes m_avHeight = height; if (PhysicsActor != null && !IsChildAgent) { - PhysicsVector SetSize = new PhysicsVector(0.45f, 0.6f, m_avHeight); + Vector3 SetSize = new Vector3(0.45f, 0.6f, m_avHeight); PhysicsActor.Size = SetSize; } } @@ -3345,20 +3345,18 @@ namespace OpenSim.Region.Framework.Scenes PhysicsScene scene = m_scene.PhysicsScene; - PhysicsVector pVec = - new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, - AbsolutePosition.Z); + Vector3 pVec = AbsolutePosition; // Old bug where the height was in centimeters instead of meters if (m_avHeight == 127.0f) { - m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new PhysicsVector(0, 0, 1.56f), + m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new Vector3(0f, 0f, 1.56f), isFlying); } else { m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, - new PhysicsVector(0, 0, m_avHeight), isFlying); + new Vector3(0f, 0f, m_avHeight), isFlying); } scene.AddPhysicsActorTaint(m_physicsActor); //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; @@ -3369,7 +3367,7 @@ namespace OpenSim.Region.Framework.Scenes } - private void OutOfBoundsCall(PhysicsVector pos) + private void OutOfBoundsCall(Vector3 pos) { //bool flying = m_physicsActor.Flying; //RemoveFromPhysicalScene(); @@ -3592,7 +3590,7 @@ namespace OpenSim.Region.Framework.Scenes */ } - internal void PushForce(PhysicsVector impulse) + internal void PushForce(Vector3 impulse) { if (PhysicsActor != null) { -- cgit v1.1 From c75d4156487b35aac47aa6818144862a99bb841c Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 27 Oct 2009 00:26:56 -0700 Subject: * Converts ClientManager.ForEach() (and as a result, Scene.ForEachClient()) to use a non-blocking parallel method when operating in async mode * Minor code readability cleanup --- OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs index cfe32d0..1a91f0c 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs @@ -394,7 +394,7 @@ namespace OpenSim.Region.Framework.Scenes void ProcessViewerEffect(IClientAPI remoteClient, List args) { // TODO: don't create new blocks if recycling an old packet - List effectBlock = new List(); + ViewerEffectPacket.EffectBlock[] effectBlockArray = new ViewerEffectPacket.EffectBlock[args.Count]; for (int i = 0; i < args.Count; i++) { ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock(); @@ -404,9 +404,8 @@ namespace OpenSim.Region.Framework.Scenes effect.ID = args[i].ID; effect.Type = args[i].Type; effect.TypeData = args[i].TypeData; - effectBlock.Add(effect); + effectBlockArray[i] = effect; } - ViewerEffectPacket.EffectBlock[] effectBlockArray = effectBlock.ToArray(); ForEachClient( delegate(IClientAPI client) -- cgit v1.1 From 3a1ee79ee4239213b35f6b73a65c127c2af977fb Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 27 Oct 2009 02:36:57 -0700 Subject: Finally hunted down the Parallel deadlock. Packets were being handled asynchronously (filling up the threadpool with handlers), which would turn around and try to do parallel operations on the starved threadpool. The solution for now is to disable Parallel.cs operations until we can gracefully handle parallel operations with a potentially starved threadpool --- OpenSim/Region/Framework/Scenes/Scene.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 6c34056..42051d0 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -120,7 +120,7 @@ namespace OpenSim.Region.Framework.Scenes private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing private int m_incrementsof15seconds; private volatile bool m_backingup; - private bool m_useAsyncWhenPossible = true; + private bool m_useAsyncWhenPossible; private Dictionary m_returns = new Dictionary(); private Dictionary m_groupsWithTargets = new Dictionary(); @@ -480,7 +480,7 @@ namespace OpenSim.Region.Framework.Scenes IConfig startupConfig = m_config.Configs["Startup"]; // Should we try to run loops synchronously or asynchronously? - m_useAsyncWhenPossible = startupConfig.GetBoolean("use_async_when_possible", true); + m_useAsyncWhenPossible = startupConfig.GetBoolean("use_async_when_possible", false); //Animation states m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); @@ -4261,10 +4261,13 @@ namespace OpenSim.Region.Framework.Scenes public void ForEachClient(Action action, bool doAsynchronous) { - if (doAsynchronous) - m_clientManager.ForEach(action); - else - m_clientManager.ForEachSync(action); + // FIXME: Asynchronous iteration is disabled until we have a threading model that + // can support calling this function from an async packet handler without + // potentially deadlocking + //if (doAsynchronous) + // m_clientManager.ForEach(action); + //else + // m_clientManager.ForEachSync(action); } public bool TryGetClient(UUID avatarID, out IClientAPI client) -- cgit v1.1