From dd277a0d02f1aa79f4fcb5d108cbc696e90500c2 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 10 Sep 2010 12:04:12 -0700 Subject: [PATCH] First pass at cleaning up thread safety in EntityManager and SceneGraph --- OpenSim/Data/IAssetData.cs | 11 - OpenSim/Data/IInventoryData.cs | 11 - .../Avatar/Attachments/AttachmentsModule.cs | 2 +- .../ArchiveWriteRequestPreparation.cs | 2 +- .../World/Land/LandManagementModule.cs | 3 +- .../World/Serialiser/SerialiseObjects.cs | 2 +- .../World/Serialiser/SerialiserModule.cs | 4 +- .../World/WorldMap/MapImageModule.cs | 2 +- OpenSim/Region/DataSnapshot/ObjectSnapshot.cs | 3 +- .../Interfaces/IRegionSerialiserModule.cs | 4 +- .../Region/Framework/Scenes/EntityManager.cs | 208 ++++---------- .../Framework/Scenes/Scene.Inventory.cs | 3 +- .../Framework/Scenes/Scene.PacketHandlers.cs | 16 +- OpenSim/Region/Framework/Scenes/Scene.cs | 45 ++- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 271 +++++++++--------- .../Region/Framework/Scenes/SceneViewer.cs | 3 +- .../Scenes/Serialization/SceneXmlLoader.cs | 23 +- .../Server/IRCClientView.cs | 10 +- .../CMEntityCollection.cs | 2 +- .../ContentManagementEntity.cs | 2 +- .../Scripting/Minimodule/ObjectAccessor.cs | 4 +- .../Scripting/Minimodule/World.cs | 6 +- .../TreePopulator/TreePopulatorModule.cs | 3 +- .../Implementation/Plugins/SensorRepeat.cs | 2 +- .../SimianGrid/SimianActivityDetector.cs | 5 +- 25 files changed, 252 insertions(+), 395 deletions(-) diff --git a/OpenSim/Data/IAssetData.cs b/OpenSim/Data/IAssetData.cs index 90d5eeb489..f31b215c0f 100644 --- a/OpenSim/Data/IAssetData.cs +++ b/OpenSim/Data/IAssetData.cs @@ -40,15 +40,4 @@ namespace OpenSim.Data void Initialise(string connect); bool Delete(string id); } - - public class AssetDataInitialiser : PluginInitialiserBase - { - private string connect; - public AssetDataInitialiser (string s) { connect = s; } - public override void Initialise (IPlugin plugin) - { - IAssetDataPlugin p = plugin as IAssetDataPlugin; - p.Initialise (connect); - } - } } diff --git a/OpenSim/Data/IInventoryData.cs b/OpenSim/Data/IInventoryData.cs index 90f74b713b..74d5d37bf9 100644 --- a/OpenSim/Data/IInventoryData.cs +++ b/OpenSim/Data/IInventoryData.cs @@ -155,15 +155,4 @@ namespace OpenSim.Data /// List fetchActiveGestures(UUID avatarID); } - - public class InventoryDataInitialiser : PluginInitialiserBase - { - private string connect; - public InventoryDataInitialiser (string s) { connect = s; } - public override void Initialise (IPlugin plugin) - { - IInventoryDataPlugin p = plugin as IInventoryDataPlugin; - p.Initialise (connect); - } - } } diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index dd7d831ed8..7270304a2d 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -436,7 +436,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // We can NOT use the dictionries here, as we are looking // for an entity by the fromAssetID, which is NOT the prim UUID - List detachEntities = m_scene.GetEntities(); + EntityBase[] detachEntities = m_scene.GetEntities(); SceneObjectGroup group; foreach (EntityBase entity in detachEntities) diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs index b25636ffcb..283b33be04 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs @@ -102,7 +102,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver { Dictionary assetUuids = new Dictionary(); - List entities = m_scene.GetEntities(); + EntityBase[] entities = m_scene.GetEntities(); List sceneObjects = new List(); /* diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs index da7a284ed9..ea71fd9f59 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs @@ -794,7 +794,8 @@ namespace OpenSim.Region.CoreModules.World.Land public void EventManagerOnParcelPrimCountUpdate() { ResetAllLandPrimCounts(); - foreach (EntityBase obj in m_scene.Entities) + EntityBase[] entities = m_scene.Entities.GetEntities(); + foreach (EntityBase obj in entities) { if (obj != null) { diff --git a/OpenSim/Region/CoreModules/World/Serialiser/SerialiseObjects.cs b/OpenSim/Region/CoreModules/World/Serialiser/SerialiseObjects.cs index bef7fe4627..5067ebd12b 100644 --- a/OpenSim/Region/CoreModules/World/Serialiser/SerialiseObjects.cs +++ b/OpenSim/Region/CoreModules/World/Serialiser/SerialiseObjects.cs @@ -80,7 +80,7 @@ namespace OpenSim.Region.CoreModules.World.Serialiser { string xmlstream = ""; - List EntityList = scene.GetEntities(); + EntityBase[] EntityList = scene.GetEntities(); List EntityXml = new List(); foreach (EntityBase ent in EntityList) diff --git a/OpenSim/Region/CoreModules/World/Serialiser/SerialiserModule.cs b/OpenSim/Region/CoreModules/World/Serialiser/SerialiserModule.cs index 58e42619c7..98fe4935bc 100644 --- a/OpenSim/Region/CoreModules/World/Serialiser/SerialiserModule.cs +++ b/OpenSim/Region/CoreModules/World/Serialiser/SerialiserModule.cs @@ -165,12 +165,12 @@ namespace OpenSim.Region.CoreModules.World.Serialiser return SceneXmlLoader.SaveGroupToXml2(grp); } - public void SavePrimListToXml2(List entityList, string fileName) + public void SavePrimListToXml2(EntityBase[] entityList, string fileName) { SceneXmlLoader.SavePrimListToXml2(entityList, fileName); } - public void SavePrimListToXml2(List entityList, TextWriter stream, Vector3 min, Vector3 max) + public void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max) { SceneXmlLoader.SavePrimListToXml2(entityList, stream, min, max); } diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs index 57eff8a0b3..1d9c2bdc07 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs @@ -212,7 +212,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap double[,] hm = whichScene.Heightmap.GetDoubles(); tc = Environment.TickCount; m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); - List objs = whichScene.GetEntities(); + EntityBase[] objs = whichScene.GetEntities(); Dictionary z_sort = new Dictionary(); //SortedList z_sort = new SortedList(); List z_sortheights = new List(); diff --git a/OpenSim/Region/DataSnapshot/ObjectSnapshot.cs b/OpenSim/Region/DataSnapshot/ObjectSnapshot.cs index 3c39f9e9cf..5e75cae838 100644 --- a/OpenSim/Region/DataSnapshot/ObjectSnapshot.cs +++ b/OpenSim/Region/DataSnapshot/ObjectSnapshot.cs @@ -101,7 +101,8 @@ namespace OpenSim.Region.DataSnapshot.Providers XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "objectdata", ""); XmlNode node; - foreach (EntityBase entity in m_scene.Entities) + EntityBase[] entities = m_scene.Entities.GetEntities(); + foreach (EntityBase entity in entities) { // only objects, not avatars if (entity is SceneObjectGroup) diff --git a/OpenSim/Region/Framework/Interfaces/IRegionSerialiserModule.cs b/OpenSim/Region/Framework/Interfaces/IRegionSerialiserModule.cs index e7562a55c9..18758c8832 100644 --- a/OpenSim/Region/Framework/Interfaces/IRegionSerialiserModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IRegionSerialiserModule.cs @@ -90,7 +90,7 @@ namespace OpenSim.Region.Framework.Interfaces /// /// /// - void SavePrimListToXml2(List entityList, string fileName); + void SavePrimListToXml2(EntityBase[] entityList, string fileName); /// /// Save a set of prims in the xml2 format, optionally specifying a bounding box for which @@ -101,7 +101,7 @@ namespace OpenSim.Region.Framework.Interfaces /// /// /// - void SavePrimListToXml2(List entityList, TextWriter stream, Vector3 min, Vector3 max); + void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max); void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName); diff --git a/OpenSim/Region/Framework/Scenes/EntityManager.cs b/OpenSim/Region/Framework/Scenes/EntityManager.cs index 099fcce559..85d0a4f9ec 100644 --- a/OpenSim/Region/Framework/Scenes/EntityManager.cs +++ b/OpenSim/Region/Framework/Scenes/EntityManager.cs @@ -34,187 +34,89 @@ using OpenMetaverse; namespace OpenSim.Region.Framework.Scenes { - public class EntityManager : IEnumerable + public class EntityManager //: IEnumerable { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private readonly Dictionary m_eb_uuid = new Dictionary(); - private readonly Dictionary m_eb_localID = new Dictionary(); - //private readonly Dictionary m_pres_uuid = new Dictionary(); - private readonly Object m_lock = new Object(); + private readonly DoubleDictionary m_entities = new DoubleDictionary(); - [Obsolete("Use Add() instead.")] - public void Add(UUID id, EntityBase eb) + public int Count { - Add(eb); + get { return m_entities.Count; } } public void Add(EntityBase entity) { - lock (m_lock) - { - try - { - m_eb_uuid.Add(entity.UUID, entity); - m_eb_localID.Add(entity.LocalId, entity); - } - catch(Exception e) - { - m_log.ErrorFormat("Add Entity failed: {0}", e.Message); - } - } - } - - public void InsertOrReplace(EntityBase entity) - { - lock (m_lock) - { - try - { - m_eb_uuid[entity.UUID] = entity; - m_eb_localID[entity.LocalId] = entity; - } - catch(Exception e) - { - m_log.ErrorFormat("Insert or Replace Entity failed: {0}", e.Message); - } - } + m_entities.Add(entity.UUID, entity.LocalId, entity); } public void Clear() { - lock (m_lock) - { - m_eb_uuid.Clear(); - m_eb_localID.Clear(); - } - } - - public int Count - { - get - { - return m_eb_uuid.Count; - } + m_entities.Clear(); } public bool ContainsKey(UUID id) { - try - { - return m_eb_uuid.ContainsKey(id); - } - catch - { - return false; - } + return m_entities.ContainsKey(id); } public bool ContainsKey(uint localID) { - try - { - return m_eb_localID.ContainsKey(localID); - } - catch - { - return false; - } + return m_entities.ContainsKey(localID); } public bool Remove(uint localID) { - lock (m_lock) - { - try - { - bool a = false; - EntityBase entity; - if (m_eb_localID.TryGetValue(localID, out entity)) - a = m_eb_uuid.Remove(entity.UUID); - - bool b = m_eb_localID.Remove(localID); - return a && b; - } - catch (Exception e) - { - m_log.ErrorFormat("Remove Entity failed for {0}", localID, e); - return false; - } - } + return m_entities.Remove(localID); } public bool Remove(UUID id) { - lock (m_lock) - { - try - { - bool a = false; - EntityBase entity; - if (m_eb_uuid.TryGetValue(id, out entity)) - a = m_eb_localID.Remove(entity.LocalId); - - bool b = m_eb_uuid.Remove(id); - return a && b; - } - catch (Exception e) - { - m_log.ErrorFormat("Remove Entity failed for {0}", id, e); - return false; - } - } + return m_entities.Remove(id); } - public List GetAllByType() + public EntityBase[] GetAllByType() { List tmp = new List(); - lock (m_lock) - { - try + m_entities.ForEach( + delegate(EntityBase entity) { - foreach (KeyValuePair pair in m_eb_uuid) - { - if (pair.Value is T) - { - tmp.Add(pair.Value); - } - } + if (entity is T) + tmp.Add(entity); } - catch (Exception e) - { - m_log.ErrorFormat("GetAllByType failed for {0}", e); - tmp = null; - } - } + ); - return tmp; + return tmp.ToArray(); } - public List GetEntities() + public EntityBase[] GetEntities() { - lock (m_lock) - { - return new List(m_eb_uuid.Values); - } + List tmp = new List(m_entities.Count); + m_entities.ForEach(delegate(EntityBase entity) { tmp.Add(entity); }); + return tmp.ToArray(); + } + + public void ForEach(Action action) + { + m_entities.ForEach(action); + } + + public EntityBase Find(Predicate predicate) + { + return m_entities.FindValue(predicate); } public EntityBase this[UUID id] { get { - lock (m_lock) - { - EntityBase entity; - if (m_eb_uuid.TryGetValue(id, out entity)) - return entity; - else - return null; - } + EntityBase entity; + m_entities.TryGetValue(id, out entity); + return entity; } set { - InsertOrReplace(value); + Add(value); } } @@ -222,50 +124,38 @@ namespace OpenSim.Region.Framework.Scenes { get { - lock (m_lock) - { - EntityBase entity; - if (m_eb_localID.TryGetValue(localID, out entity)) - return entity; - else - return null; - } + EntityBase entity; + m_entities.TryGetValue(localID, out entity); + return entity; } set { - InsertOrReplace(value); + Add(value); } } public bool TryGetValue(UUID key, out EntityBase obj) { - lock (m_lock) - { - return m_eb_uuid.TryGetValue(key, out obj); - } + return m_entities.TryGetValue(key, out obj); } public bool TryGetValue(uint key, out EntityBase obj) { - lock (m_lock) - { - return m_eb_localID.TryGetValue(key, out obj); - } + return m_entities.TryGetValue(key, out obj); } /// /// This could be optimised to work on the list 'live' rather than making a safe copy and iterating that. /// /// - public IEnumerator GetEnumerator() - { - return GetEntities().GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + //public IEnumerator GetEnumerator() + //{ + // return GetEntities().GetEnumerator(); + //} + //IEnumerator IEnumerable.GetEnumerator() + //{ + // return GetEnumerator(); + //} } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index c49386a85b..a439eb9f1f 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -58,7 +58,8 @@ namespace OpenSim.Region.Framework.Scenes { m_log.Info("[PRIM INVENTORY]: Starting scripts in scene"); - foreach (EntityBase group in Entities) + EntityBase[] entities = Entities.GetEntities(); + foreach (EntityBase group in entities) { if (group is SceneObjectGroup) { diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs index c511774d69..2f69476664 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs @@ -116,9 +116,8 @@ namespace OpenSim.Region.Framework.Scenes /// public void RequestPrim(uint primLocalID, IClientAPI remoteClient) { - List EntityList = GetEntities(); - - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = GetEntities(); + foreach (EntityBase ent in entityList) { if (ent is SceneObjectGroup) { @@ -138,9 +137,8 @@ namespace OpenSim.Region.Framework.Scenes /// public void SelectPrim(uint primLocalID, IClientAPI remoteClient) { - List EntityList = GetEntities(); - - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = GetEntities(); + foreach (EntityBase ent in entityList) { if (ent is SceneObjectGroup) { @@ -259,7 +257,7 @@ namespace OpenSim.Region.Framework.Scenes public virtual void ProcessObjectGrab(uint localID, Vector3 offsetPos, IClientAPI remoteClient, List surfaceArgs) { - List EntityList = GetEntities(); + EntityBase[] EntityList = GetEntities(); SurfaceTouchEventArgs surfaceArg = null; if (surfaceArgs != null && surfaceArgs.Count > 0) @@ -303,7 +301,7 @@ namespace OpenSim.Region.Framework.Scenes public virtual void ProcessObjectGrabUpdate(UUID objectID, Vector3 offset, Vector3 pos, IClientAPI remoteClient, List surfaceArgs) { - List EntityList = GetEntities(); + EntityBase[] EntityList = GetEntities(); SurfaceTouchEventArgs surfaceArg = null; if (surfaceArgs != null && surfaceArgs.Count > 0) @@ -343,7 +341,7 @@ namespace OpenSim.Region.Framework.Scenes public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient, List surfaceArgs) { - List EntityList = GetEntities(); + EntityBase[] EntityList = GetEntities(); SurfaceTouchEventArgs surfaceArg = null; if (surfaceArgs != null && surfaceArgs.Count > 0) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 82e7d763df..7ce95a7299 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1029,29 +1029,30 @@ namespace OpenSim.Region.Framework.Scenes if (ScriptEngine) { m_log.Info("Stopping all Scripts in Scene"); - foreach (EntityBase ent in Entities) + + EntityBase[] entities = Entities.GetEntities(); + foreach (EntityBase ent in entities) { if (ent is SceneObjectGroup) - { - ((SceneObjectGroup) ent).RemoveScriptInstances(false); - } + ((SceneObjectGroup)ent).RemoveScriptInstances(false); } } else { m_log.Info("Starting all Scripts in Scene"); - lock (Entities) + + EntityBase[] entities = Entities.GetEntities(); + foreach (EntityBase ent in entities) { - foreach (EntityBase ent in Entities) + if (ent is SceneObjectGroup) { - if (ent is SceneObjectGroup) - { - ((SceneObjectGroup)ent).CreateScriptInstances(0, false, DefaultScriptEngine, 0); - ((SceneObjectGroup)ent).ResumeScripts(); - } + SceneObjectGroup sog = (SceneObjectGroup)ent; + sog.CreateScriptInstances(0, false, DefaultScriptEngine, 0); + sog.ResumeScripts(); } } } + m_scripts_enabled = !ScriptEngine; m_log.Info("[TOTEDD]: Here is the method to trigger disabling of the scripting engine"); } @@ -1098,7 +1099,7 @@ namespace OpenSim.Region.Framework.Scenes shuttingdown = true; m_log.Debug("[SCENE]: Persisting changed objects"); - List entities = GetEntities(); + EntityBase[] entities = GetEntities(); foreach (EntityBase entity in entities) { if (!entity.IsDeleted && entity is SceneObjectGroup && ((SceneObjectGroup)entity).HasGroupChanged) @@ -2037,8 +2038,7 @@ namespace OpenSim.Region.Framework.Scenes { lock (Entities) { - ICollection entities = new List(Entities); - + EntityBase[] entities = Entities.GetEntities(); foreach (EntityBase e in entities) { if (e is SceneObjectGroup) @@ -3977,9 +3977,8 @@ namespace OpenSim.Region.Framework.Scenes /// public void ForceClientUpdate() { - List EntityList = GetEntities(); - - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = GetEntities(); + foreach (EntityBase ent in entityList) { if (ent is SceneObjectGroup) { @@ -3997,9 +3996,8 @@ namespace OpenSim.Region.Framework.Scenes { m_log.Debug("Searching for Primitive: '" + cmdparams[2] + "'"); - List EntityList = GetEntities(); - - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = GetEntities(); + foreach (EntityBase ent in entityList) { if (ent is SceneObjectGroup) { @@ -4368,7 +4366,7 @@ namespace OpenSim.Region.Framework.Scenes /// will not affect the original list of objects in the scene. /// /// - public List GetEntities() + public EntityBase[] GetEntities() { return m_sceneGraph.GetEntities(); } @@ -4402,9 +4400,8 @@ namespace OpenSim.Region.Framework.Scenes public void CleanTempObjects() { - List objs = GetEntities(); - - foreach (EntityBase obj in objs) + EntityBase[] entities = GetEntities(); + foreach (EntityBase obj in entities) { if (obj is SceneObjectGroup) { diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index dfb26b9c15..3d3e822eee 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -348,68 +348,57 @@ namespace OpenSim.Region.Framework.Scenes if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero) return false; - lock (sceneObject) - { - if (Entities.ContainsKey(sceneObject.UUID)) + if (Entities.ContainsKey(sceneObject.UUID)) + return false; + + // Clamp child prim sizes and add child prims to the m_numPrim count + lock (sceneObject.Children) + { + if (m_parentScene.m_clampPrimSize) { -// m_log.WarnFormat( -// "[SCENE GRAPH]: Scene object {0} {1} was already in region {2} on add request", -// sceneObject.Name, sceneObject.UUID, m_parentScene.RegionInfo.RegionName); - return false; - } - -// m_log.DebugFormat( -// "[SCENE GRAPH]: Adding object {0} {1} to region {2}", -// sceneObject.Name, sceneObject.UUID, m_parentScene.RegionInfo.RegionName); - - lock (sceneObject.Children) - { - if (m_parentScene.m_clampPrimSize) + foreach (SceneObjectPart part in sceneObject.Children.Values) { - foreach (SceneObjectPart part in sceneObject.Children.Values) - { - Vector3 scale = part.Shape.Scale; - - if (scale.X > m_parentScene.m_maxNonphys) - scale.X = m_parentScene.m_maxNonphys; - if (scale.Y > m_parentScene.m_maxNonphys) - scale.Y = m_parentScene.m_maxNonphys; - if (scale.Z > m_parentScene.m_maxNonphys) - scale.Z = m_parentScene.m_maxNonphys; - - part.Shape.Scale = scale; - } + Vector3 scale = part.Shape.Scale; + + if (scale.X > m_parentScene.m_maxNonphys) + scale.X = m_parentScene.m_maxNonphys; + if (scale.Y > m_parentScene.m_maxNonphys) + scale.Y = m_parentScene.m_maxNonphys; + if (scale.Z > m_parentScene.m_maxNonphys) + scale.Z = m_parentScene.m_maxNonphys; + + part.Shape.Scale = scale; } - - m_numPrim += sceneObject.Children.Count; } - - sceneObject.AttachToScene(m_parentScene); - if (sendClientUpdates) - sceneObject.ScheduleGroupForFullUpdate(); - - Entities.Add(sceneObject); + m_numPrim += sceneObject.Children.Count; + } - if (attachToBackup) - sceneObject.AttachToBackup(); + sceneObject.AttachToScene(m_parentScene); - if (OnObjectCreate != null) - OnObjectCreate(sceneObject); - - lock (SceneObjectGroupsByFullID) - { - SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject; - foreach (SceneObjectPart part in sceneObject.Children.Values) - SceneObjectGroupsByFullID[part.UUID] = sceneObject; - } - - lock (SceneObjectGroupsByLocalID) - { - SceneObjectGroupsByLocalID[sceneObject.LocalId] = sceneObject; - foreach (SceneObjectPart part in sceneObject.Children.Values) - SceneObjectGroupsByLocalID[part.LocalId] = sceneObject; - } + if (sendClientUpdates) + sceneObject.ScheduleGroupForFullUpdate(); + + Entities.Add(sceneObject); + + if (attachToBackup) + sceneObject.AttachToBackup(); + + if (OnObjectCreate != null) + OnObjectCreate(sceneObject); + + lock (SceneObjectGroupsByFullID) + { + SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject; + foreach (SceneObjectPart part in sceneObject.Children.Values) + SceneObjectGroupsByFullID[part.UUID] = sceneObject; + } + + lock (SceneObjectGroupsByLocalID) + { + SceneObjectGroupsByLocalID[sceneObject.LocalId] = sceneObject; + foreach (SceneObjectPart part in sceneObject.Children.Values) + SceneObjectGroupsByLocalID[part.LocalId] = sceneObject; } return true; @@ -421,42 +410,38 @@ namespace OpenSim.Region.Framework.Scenes /// true if the object was deleted, false if there was no object to delete public bool DeleteSceneObject(UUID uuid, bool resultOfObjectLinked) { - if (Entities.ContainsKey(uuid)) + EntityBase entity; + if (!Entities.TryGetValue(uuid, out entity) && entity is SceneObjectGroup) + return false; + + SceneObjectGroup grp = (SceneObjectGroup)entity; + + if (!resultOfObjectLinked) { - SceneObjectGroup grp = (SceneObjectGroup)Entities[uuid]; + m_numPrim -= grp.PrimCount; - if (!resultOfObjectLinked) - { - m_numPrim -= grp.PrimCount; - - if ((grp.RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics) - RemovePhysicalPrim(grp.PrimCount); - } - - if (OnObjectRemove != null) - OnObjectRemove(Entities[uuid]); - - lock (SceneObjectGroupsByFullID) - { - foreach (SceneObjectPart part in grp.Children.Values) - SceneObjectGroupsByFullID.Remove(part.UUID); - SceneObjectGroupsByFullID.Remove(grp.RootPart.UUID); - } - lock (SceneObjectGroupsByLocalID) - { - foreach (SceneObjectPart part in grp.Children.Values) - SceneObjectGroupsByLocalID.Remove(part.LocalId); - SceneObjectGroupsByLocalID.Remove(grp.RootPart.LocalId); - } - - Entities.Remove(uuid); - //SceneObjectGroup part; - //((part.RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics) - - return true; + if ((grp.RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics) + RemovePhysicalPrim(grp.PrimCount); } - return false; + if (OnObjectRemove != null) + OnObjectRemove(Entities[uuid]); + + lock (SceneObjectGroupsByFullID) + { + foreach (SceneObjectPart part in grp.Children.Values) + SceneObjectGroupsByFullID.Remove(part.UUID); + SceneObjectGroupsByFullID.Remove(grp.RootPart.UUID); + } + + lock (SceneObjectGroupsByLocalID) + { + foreach (SceneObjectPart part in grp.Children.Values) + SceneObjectGroupsByLocalID.Remove(part.LocalId); + SceneObjectGroupsByLocalID.Remove(grp.RootPart.LocalId); + } + + return Entities.Remove(uuid); } /// @@ -468,9 +453,7 @@ namespace OpenSim.Region.Framework.Scenes protected internal void AddToUpdateList(SceneObjectGroup obj) { lock (m_updateList) - { m_updateList[obj.UUID] = obj; - } } /// @@ -480,34 +463,39 @@ namespace OpenSim.Region.Framework.Scenes { if (!Monitor.TryEnter(m_updateLock)) return; - - List updates; - - // Some updates add more updates to the updateList. - // Get the current list of updates and clear the list before iterating - lock (m_updateList) + try { - updates = new List(m_updateList.Values); - m_updateList.Clear(); - } + List updates; - // Go through all updates - for (int i = 0; i < updates.Count; i++) - { - SceneObjectGroup sog = updates[i]; - - // Don't abort the whole update if one entity happens to give us an exception. - try + // Some updates add more updates to the updateList. + // Get the current list of updates and clear the list before iterating + lock (m_updateList) { - sog.Update(); + updates = new List(m_updateList.Values); + m_updateList.Clear(); } - catch (Exception e) + + // Go through all updates + for (int i = 0; i < updates.Count; i++) { - m_log.ErrorFormat( - "[INNER SCENE]: Failed to update {0}, {1} - {2}", sog.Name, sog.UUID, e); + SceneObjectGroup sog = updates[i]; + + // Don't abort the whole update if one entity happens to give us an exception. + try + { + sog.Update(); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[INNER SCENE]: Failed to update {0}, {1} - {2}", sog.Name, sog.UUID, e); + } } } - Monitor.Exit(m_updateLock); + finally + { + Monitor.Exit(m_updateLock); + } } protected internal void AddPhysicalPrim(int number) @@ -864,8 +852,9 @@ namespace OpenSim.Region.Framework.Scenes /// null if no scene object group containing that prim is found public SceneObjectGroup GetGroupByPrim(uint localID) { - if (Entities.ContainsKey(localID)) - return Entities[localID] as SceneObjectGroup; + EntityBase entity; + if (Entities.TryGetValue(localID, out entity)) + return entity as SceneObjectGroup; //m_log.DebugFormat("Entered GetGroupByPrim with localID {0}", localID); SceneObjectGroup sog; @@ -879,23 +868,22 @@ namespace OpenSim.Region.Framework.Scenes } } - List EntityList = GetEntities(); - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = GetEntities(); + foreach (EntityBase ent in entityList) { //m_log.DebugFormat("Looking at entity {0}", ent.UUID); if (ent is SceneObjectGroup) { - if (((SceneObjectGroup)ent).HasChildPrim(localID)) + sog = (SceneObjectGroup)ent; + if (sog.HasChildPrim(localID)) { - sog = (SceneObjectGroup)ent; lock (SceneObjectGroupsByLocalID) - { SceneObjectGroupsByLocalID[localID] = sog; - } return sog; } } } + return null; } @@ -921,23 +909,21 @@ namespace OpenSim.Region.Framework.Scenes } } - List EntityList = GetEntities(); - - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = GetEntities(); + foreach (EntityBase ent in entityList) { if (ent is SceneObjectGroup) { - if (((SceneObjectGroup)ent).HasChildPrim(fullID)) + sog = (SceneObjectGroup)ent; + if (sog.HasChildPrim(fullID)) { - sog = (SceneObjectGroup)ent; lock (SceneObjectGroupsByFullID) - { SceneObjectGroupsByFullID[fullID] = sog; - } return sog; } } } + return null; } @@ -946,7 +932,7 @@ namespace OpenSim.Region.Framework.Scenes // Primitive Ray Tracing float closestDistance = 280f; EntityIntersection result = new EntityIntersection(); - List EntityList = GetEntities(); + EntityBase[] EntityList = GetEntities(); foreach (EntityBase ent in EntityList) { if (ent is SceneObjectGroup) @@ -984,23 +970,28 @@ namespace OpenSim.Region.Framework.Scenes /// null if the part was not found protected internal SceneObjectPart GetSceneObjectPart(string name) { - List EntityList = GetEntities(); + SceneObjectPart sop = null; - // FIXME: use a dictionary here - foreach (EntityBase ent in EntityList) - { - if (ent is SceneObjectGroup) + Entities.Find( + delegate(EntityBase entity) { - foreach (SceneObjectPart p in ((SceneObjectGroup) ent).GetParts()) + if (entity is SceneObjectGroup) { - if (p.Name == name) + foreach (SceneObjectPart p in ((SceneObjectGroup)entity).GetParts()) { - return p; + if (p.Name == name) + { + sop = p; + return true; + } } } + + return false; } - } - return null; + ); + + return sop; } /// @@ -1021,7 +1012,7 @@ namespace OpenSim.Region.Framework.Scenes /// it /// /// - protected internal List GetEntities() + protected internal EntityBase[] GetEntities() { return Entities.GetEntities(); } @@ -1030,7 +1021,7 @@ namespace OpenSim.Region.Framework.Scenes { Dictionary topScripts = new Dictionary(); - List EntityList = GetEntities(); + EntityBase[] EntityList = GetEntities(); int limit = 0; foreach (EntityBase ent in EntityList) { @@ -1726,8 +1717,8 @@ namespace OpenSim.Region.Framework.Scenes UUID objid = UUID.Zero; SceneObjectPart obj = null; - List EntityList = GetEntities(); - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = GetEntities(); + foreach (EntityBase ent in entityList) { if (ent is SceneObjectGroup) { diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs index f478a4a770..7aa5a93e8b 100644 --- a/OpenSim/Region/Framework/Scenes/SceneViewer.cs +++ b/OpenSim/Region/Framework/Scenes/SceneViewer.cs @@ -75,7 +75,8 @@ namespace OpenSim.Region.Framework.Scenes lock(m_pendingObjects) { - foreach (EntityBase e in m_presence.Scene.Entities) + EntityBase[] entities = m_presence.Scene.Entities.GetEntities(); + foreach (EntityBase e in entities) { if (e != null && e is SceneObjectGroup) m_pendingObjects.Enqueue((SceneObjectGroup)e); diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index b6677f092e..5494549a3e 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -84,9 +84,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization int primCount = 0; stream.WriteLine("\n"); - List EntityList = scene.GetEntities(); - - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = scene.GetEntities(); + foreach (EntityBase ent in entityList) { if (ent is SceneObjectGroup) { @@ -204,16 +203,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization public static void SavePrimsToXml2(Scene scene, string fileName) { - List EntityList = scene.GetEntities(); - - SavePrimListToXml2(EntityList, fileName); + EntityBase[] entityList = scene.GetEntities(); + SavePrimListToXml2(entityList, fileName); } public static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max) { - List EntityList = scene.GetEntities(); - - SavePrimListToXml2(EntityList, stream, min, max); + EntityBase[] entityList = scene.GetEntities(); + SavePrimListToXml2(entityList, stream, min, max); } public static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName) @@ -222,7 +219,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}", primName, scene.RegionInfo.RegionName, fileName); - List entityList = scene.GetEntities(); + EntityBase[] entityList = scene.GetEntities(); List primList = new List(); foreach (EntityBase ent in entityList) @@ -236,10 +233,10 @@ namespace OpenSim.Region.Framework.Scenes.Serialization } } - SavePrimListToXml2(primList, fileName); + SavePrimListToXml2(primList.ToArray(), fileName); } - public static void SavePrimListToXml2(List entityList, string fileName) + public static void SavePrimListToXml2(EntityBase[] entityList, string fileName) { FileStream file = new FileStream(fileName, FileMode.Create); try @@ -260,7 +257,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization } } - public static void SavePrimListToXml2(List entityList, TextWriter stream, Vector3 min, Vector3 max) + public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max) { int primCount = 0; stream.WriteLine("\n"); diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index 6793ef63f3..159af79ace 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -375,8 +375,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server private void IRC_SendNamesReply() { - List users = m_scene.Entities.GetAllByType(); - + EntityBase[] users = m_scene.Entities.GetAllByType(); foreach (EntityBase user in users) { SendServerCommand("353 " + m_nick + " = " + IrcRegionName + " :" + user.Name.Replace(" ", "")); @@ -386,8 +385,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server private void IRC_SendWhoReply() { - List users = m_scene.Entities.GetAllByType(); - + EntityBase[] users = m_scene.Entities.GetAllByType(); foreach (EntityBase user in users) { /*SendServerCommand(String.Format("352 {0} {1} {2} {3} {4} {5} :0 {6}", IrcRegionName, @@ -415,11 +413,11 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server private void IRC_SendReplyUsers() { - List users = m_scene.Entities.GetAllByType(); + EntityBase[] users = m_scene.Entities.GetAllByType(); SendServerCommand("392 :UserID Terminal Host"); - if (users.Count == 0) + if (users.Length == 0) { SendServerCommand("395 :Nobody logged in"); return; diff --git a/OpenSim/Region/OptionalModules/ContentManagementSystem/CMEntityCollection.cs b/OpenSim/Region/OptionalModules/ContentManagementSystem/CMEntityCollection.cs index de1e01c89d..d21b6527f6 100644 --- a/OpenSim/Region/OptionalModules/ContentManagementSystem/CMEntityCollection.cs +++ b/OpenSim/Region/OptionalModules/ContentManagementSystem/CMEntityCollection.cs @@ -111,7 +111,7 @@ namespace OpenSim.Region.OptionalModules.ContentManagement } // Check if there are SceneObjectGroups in the list that do not have corresponding ContentManagementGroups in the CMEntityHash - public System.Collections.ArrayList CheckForMissingEntities(System.Collections.Generic.List currList) + public System.Collections.ArrayList CheckForMissingEntities(EntityBase[] currList) { System.Collections.ArrayList missingList = new System.Collections.ArrayList(); SceneObjectGroup temp = null; diff --git a/OpenSim/Region/OptionalModules/ContentManagementSystem/ContentManagementEntity.cs b/OpenSim/Region/OptionalModules/ContentManagementSystem/ContentManagementEntity.cs index 2730eee2e5..49d20e10f8 100644 --- a/OpenSim/Region/OptionalModules/ContentManagementSystem/ContentManagementEntity.cs +++ b/OpenSim/Region/OptionalModules/ContentManagementSystem/ContentManagementEntity.cs @@ -127,7 +127,7 @@ namespace OpenSim.Region.OptionalModules.ContentManagement /// public void FindDifferences() { - System.Collections.Generic.List sceneEntityList = m_Entity.Scene.GetEntities(); + List sceneEntityList = new List(m_Entity.Scene.GetEntities()); DiffersFromSceneGroup = false; // if group is not contained in scene's list if (!ContainsKey(sceneEntityList, m_UnchangedEntity.UUID)) diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs index 6ba5ccfdc9..140264b5e7 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs @@ -41,12 +41,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule private readonly Scene m_scene; private readonly IEnumerator m_sogEnum; private readonly ISecurityCredential m_security; + private readonly List m_entities; public IObjEnum(Scene scene, ISecurityCredential security) { m_scene = scene; m_security = security; - m_sogEnum = m_scene.Entities.GetAllByType().GetEnumerator(); + m_entities = new List(m_scene.Entities.GetEntities()); + m_sogEnum = m_entities.GetEnumerator(); } public void Dispose() diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs index 45bb005903..f2324d29a8 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs @@ -205,10 +205,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { get { - List ents = m_internalScene.Entities.GetAllByType(); - IAvatar[] rets = new IAvatar[ents.Count]; + EntityBase[] ents = m_internalScene.Entities.GetAllByType(); + IAvatar[] rets = new IAvatar[ents.Length]; - for (int i = 0; i < ents.Count; i++) + for (int i = 0; i < ents.Length; i++) { EntityBase ent = ents[i]; rets[i] = new SPAvatar(m_internalScene, ent.UUID, m_security); diff --git a/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs index 3ed338baea..421da3664a 100644 --- a/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs +++ b/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs @@ -568,8 +568,7 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator { m_copse = new List(); - List objs = m_scene.GetEntities(); - + EntityBase[] objs = m_scene.GetEntities(); foreach (EntityBase obj in objs) { if (obj is SceneObjectGroup) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 5c2abd5e9d..2b67e841b2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs @@ -286,7 +286,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins } else { - Entities = m_CmdManager.m_ScriptEngine.World.GetEntities(); + Entities = new List(m_CmdManager.m_ScriptEngine.World.GetEntities()); } SceneObjectPart SensePoint = ts.host; diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs index 67b73f39de..67a06f3f83 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs @@ -69,7 +69,10 @@ namespace OpenSim.Services.Connectors.SimianGrid public void OnMakeRootAgent(ScenePresence sp) { m_log.DebugFormat("[SIMIAN ACTIVITY DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName); - m_GridUserService.SetLastPosition(sp.UUID.ToString(), sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat); + Util.FireAndForget(delegate(object o) + { + m_GridUserService.SetLastPosition(sp.UUID.ToString(), sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat); + }); } public void OnNewClient(IClientAPI client)