mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 17:55:48 +08:00
First pass at cleaning up thread safety in EntityManager and SceneGraph
This commit is contained in:
@@ -90,7 +90,7 @@ namespace OpenSim.Region.Framework.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="entityList"></param>
|
||||
/// <param name="fileName"></param>
|
||||
void SavePrimListToXml2(List<EntityBase> entityList, string fileName);
|
||||
void SavePrimListToXml2(EntityBase[] entityList, string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// <param name="stream"></param>
|
||||
/// <param name="min"></param>
|
||||
/// <param name="max"></param>
|
||||
void SavePrimListToXml2(List<EntityBase> 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);
|
||||
|
||||
|
||||
@@ -34,187 +34,89 @@ using OpenMetaverse;
|
||||
|
||||
namespace OpenSim.Region.Framework.Scenes
|
||||
{
|
||||
public class EntityManager : IEnumerable<EntityBase>
|
||||
public class EntityManager //: IEnumerable<EntityBase>
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private readonly Dictionary<UUID,EntityBase> m_eb_uuid = new Dictionary<UUID, EntityBase>();
|
||||
private readonly Dictionary<uint, EntityBase> m_eb_localID = new Dictionary<uint, EntityBase>();
|
||||
//private readonly Dictionary<UUID, ScenePresence> m_pres_uuid = new Dictionary<UUID, ScenePresence>();
|
||||
private readonly Object m_lock = new Object();
|
||||
private readonly DoubleDictionary<UUID, uint, EntityBase> m_entities = new DoubleDictionary<UUID, uint, EntityBase>();
|
||||
|
||||
[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<EntityBase> GetAllByType<T>()
|
||||
public EntityBase[] GetAllByType<T>()
|
||||
{
|
||||
List<EntityBase> tmp = new List<EntityBase>();
|
||||
|
||||
lock (m_lock)
|
||||
{
|
||||
try
|
||||
m_entities.ForEach(
|
||||
delegate(EntityBase entity)
|
||||
{
|
||||
foreach (KeyValuePair<UUID, EntityBase> 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<EntityBase> GetEntities()
|
||||
public EntityBase[] GetEntities()
|
||||
{
|
||||
lock (m_lock)
|
||||
{
|
||||
return new List<EntityBase>(m_eb_uuid.Values);
|
||||
}
|
||||
List<EntityBase> tmp = new List<EntityBase>(m_entities.Count);
|
||||
m_entities.ForEach(delegate(EntityBase entity) { tmp.Add(entity); });
|
||||
return tmp.ToArray();
|
||||
}
|
||||
|
||||
public void ForEach(Action<EntityBase> action)
|
||||
{
|
||||
m_entities.ForEach(action);
|
||||
}
|
||||
|
||||
public EntityBase Find(Predicate<EntityBase> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This could be optimised to work on the list 'live' rather than making a safe copy and iterating that.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerator<EntityBase> GetEnumerator()
|
||||
{
|
||||
return GetEntities().GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
//public IEnumerator<EntityBase> GetEnumerator()
|
||||
//{
|
||||
// return GetEntities().GetEnumerator();
|
||||
//}
|
||||
|
||||
//IEnumerator IEnumerable.GetEnumerator()
|
||||
//{
|
||||
// return GetEnumerator();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -116,9 +116,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
/// <param name="remoteClient"></param>
|
||||
public void RequestPrim(uint primLocalID, IClientAPI remoteClient)
|
||||
{
|
||||
List<EntityBase> 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
|
||||
/// <param name="remoteClient"></param>
|
||||
public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
|
||||
{
|
||||
List<EntityBase> 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<SurfaceTouchEventArgs> surfaceArgs)
|
||||
{
|
||||
List<EntityBase> 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<SurfaceTouchEventArgs> surfaceArgs)
|
||||
{
|
||||
List<EntityBase> 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<SurfaceTouchEventArgs> surfaceArgs)
|
||||
{
|
||||
List<EntityBase> EntityList = GetEntities();
|
||||
EntityBase[] EntityList = GetEntities();
|
||||
|
||||
SurfaceTouchEventArgs surfaceArg = null;
|
||||
if (surfaceArgs != null && surfaceArgs.Count > 0)
|
||||
|
||||
@@ -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<EntityBase> 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<EntityBase> entities = new List<EntityBase>(Entities);
|
||||
|
||||
EntityBase[] entities = Entities.GetEntities();
|
||||
foreach (EntityBase e in entities)
|
||||
{
|
||||
if (e is SceneObjectGroup)
|
||||
@@ -3977,9 +3977,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
/// </summary>
|
||||
public void ForceClientUpdate()
|
||||
{
|
||||
List<EntityBase> 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<EntityBase> 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.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<EntityBase> GetEntities()
|
||||
public EntityBase[] GetEntities()
|
||||
{
|
||||
return m_sceneGraph.GetEntities();
|
||||
}
|
||||
@@ -4402,9 +4400,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
|
||||
public void CleanTempObjects()
|
||||
{
|
||||
List<EntityBase> objs = GetEntities();
|
||||
|
||||
foreach (EntityBase obj in objs)
|
||||
EntityBase[] entities = GetEntities();
|
||||
foreach (EntityBase obj in entities)
|
||||
{
|
||||
if (obj is SceneObjectGroup)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
/// <returns>true if the object was deleted, false if there was no object to delete</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -468,9 +453,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
protected internal void AddToUpdateList(SceneObjectGroup obj)
|
||||
{
|
||||
lock (m_updateList)
|
||||
{
|
||||
m_updateList[obj.UUID] = obj;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -480,34 +463,39 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
{
|
||||
if (!Monitor.TryEnter(m_updateLock))
|
||||
return;
|
||||
|
||||
List<SceneObjectGroup> 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<SceneObjectGroup>(m_updateList.Values);
|
||||
m_updateList.Clear();
|
||||
}
|
||||
List<SceneObjectGroup> 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<SceneObjectGroup>(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
|
||||
/// <returns>null if no scene object group containing that prim is found</returns>
|
||||
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<EntityBase> 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<EntityBase> 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<EntityBase> EntityList = GetEntities();
|
||||
EntityBase[] EntityList = GetEntities();
|
||||
foreach (EntityBase ent in EntityList)
|
||||
{
|
||||
if (ent is SceneObjectGroup)
|
||||
@@ -984,23 +970,28 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
/// <returns>null if the part was not found</returns>
|
||||
protected internal SceneObjectPart GetSceneObjectPart(string name)
|
||||
{
|
||||
List<EntityBase> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1021,7 +1012,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
/// it
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected internal List<EntityBase> GetEntities()
|
||||
protected internal EntityBase[] GetEntities()
|
||||
{
|
||||
return Entities.GetEntities();
|
||||
}
|
||||
@@ -1030,7 +1021,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
{
|
||||
Dictionary<uint, float> topScripts = new Dictionary<uint, float>();
|
||||
|
||||
List<EntityBase> 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<EntityBase> EntityList = GetEntities();
|
||||
foreach (EntityBase ent in EntityList)
|
||||
EntityBase[] entityList = GetEntities();
|
||||
foreach (EntityBase ent in entityList)
|
||||
{
|
||||
if (ent is SceneObjectGroup)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -84,9 +84,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
|
||||
int primCount = 0;
|
||||
stream.WriteLine("<scene>\n");
|
||||
|
||||
List<EntityBase> 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<EntityBase> 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<EntityBase> 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<EntityBase> entityList = scene.GetEntities();
|
||||
EntityBase[] entityList = scene.GetEntities();
|
||||
List<EntityBase> primList = new List<EntityBase>();
|
||||
|
||||
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<EntityBase> 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<EntityBase> entityList, TextWriter stream, Vector3 min, Vector3 max)
|
||||
public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max)
|
||||
{
|
||||
int primCount = 0;
|
||||
stream.WriteLine("<scene>\n");
|
||||
|
||||
Reference in New Issue
Block a user