* Swaps Scene.Entities Dictionary for EntityManager.

* Important Changes: Scene.Entities is now IEnumerable directly. You do not need to use Entities.Values, you can Enumerate on .Entities directly. (So 'foreach Scene.Entities' vs 'foreach Scene.Entities.Values').
* Locks: Entities maintains it's own internal locking states. This means you do not need to lock entities anymore. I'll be going through and removing locks on it systematically.
0.6.1-post-fixes
Adam Frisby 2008-11-24 14:45:05 +00:00
parent 202406c522
commit 47829849d9
8 changed files with 48 additions and 19 deletions

View File

@ -98,7 +98,7 @@ namespace OpenSim.Region.DataSnapshot.Providers
XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "objectdata", ""); XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "objectdata", "");
XmlNode node; XmlNode node;
foreach (EntityBase entity in m_scene.Entities.Values) foreach (EntityBase entity in m_scene.Entities)
{ {
// only objects, not avatars // only objects, not avatars
if (entity is SceneObjectGroup) if (entity is SceneObjectGroup)

View File

@ -272,7 +272,12 @@ namespace OpenSim.Region.Environment.Modules.ContentManagement
lock (scene) lock (scene)
{ {
scene.Entities = ReplacementList; scene.Entities.Clear();
foreach(KeyValuePair<UUID,EntityBase> kvp in ReplacementList)
{
scene.Entities.Add(kvp.Value);
}
} }
foreach (EntityBase ent in ReplacementList.Values) foreach (EntityBase ent in ReplacementList.Values)

View File

@ -666,7 +666,7 @@ namespace OpenSim.Region.Environment.Modules.World.Land
ResetAllLandPrimCounts(); ResetAllLandPrimCounts();
lock (m_scene.Entities) lock (m_scene.Entities)
{ {
foreach (EntityBase obj in m_scene.Entities.Values) foreach (EntityBase obj in m_scene.Entities)
{ {
if (obj != null) if (obj != null)
{ {

View File

@ -71,21 +71,25 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
public void Remove(uint localID) public bool Remove(uint localID)
{ {
lock(m_lock) lock(m_lock)
{ {
m_eb_uuid.Remove(m_eb_localID[localID].UUID); bool a = m_eb_uuid.Remove(m_eb_localID[localID].UUID);
m_eb_localID.Remove(localID); bool b = m_eb_localID.Remove(localID);
return a && b;
} }
} }
public void Remove(UUID id) public bool Remove(UUID id)
{ {
lock(m_lock) lock(m_lock)
{ {
m_eb_localID.Remove(m_eb_uuid[id].LocalId); bool a = m_eb_localID.Remove(m_eb_uuid[id].LocalId);
m_eb_uuid.Remove(id); bool b = m_eb_uuid.Remove(id);
return a && b;
} }
} }
@ -145,6 +149,22 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
public bool TryGetValue(UUID key, out EntityBase obj)
{
lock(m_lock)
{
return m_eb_uuid.TryGetValue(key, out obj);
}
}
public bool TryGetValue(uint key, out EntityBase obj)
{
lock (m_lock)
{
return m_eb_localID.TryGetValue(key, out obj);
}
}
/// <summary> /// <summary>
/// This could be optimised to work on the list 'live' rather than making a safe copy and iterating that. /// This could be optimised to work on the list 'live' rather than making a safe copy and iterating that.
/// </summary> /// </summary>

View File

@ -57,7 +57,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
m_log.Info("[PRIM INVENTORY]: Starting scripts in scene"); m_log.Info("[PRIM INVENTORY]: Starting scripts in scene");
foreach (EntityBase group in Entities.Values) foreach (EntityBase group in Entities)
{ {
if (group is SceneObjectGroup) if (group is SceneObjectGroup)
{ {

View File

@ -244,6 +244,7 @@ namespace OpenSim.Region.Environment.Scenes
// set { m_sceneGraph.SceneObjects = value; } // set { m_sceneGraph.SceneObjects = value; }
// } // }
/**
/// <summary> /// <summary>
/// The dictionary of all entities in this scene. The contents of this dictionary may be changed at any time. /// The dictionary of all entities in this scene. The contents of this dictionary may be changed at any time.
/// If you wish to add or remove entities, please use the appropriate method for that entity rather than /// If you wish to add or remove entities, please use the appropriate method for that entity rather than
@ -257,6 +258,11 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_sceneGraph.Entities; } get { return m_sceneGraph.Entities; }
set { m_sceneGraph.Entities = value; } set { m_sceneGraph.Entities = value; }
} }
*/
public EntityManager Entities
{
get { return m_sceneGraph.Entities; }
}
public Dictionary<UUID, ScenePresence> m_restorePresences public Dictionary<UUID, ScenePresence> m_restorePresences
{ {
@ -605,7 +611,7 @@ namespace OpenSim.Region.Environment.Scenes
m_log.Info("Stopping all Scripts in Scene"); m_log.Info("Stopping all Scripts in Scene");
lock (Entities) lock (Entities)
{ {
foreach (EntityBase ent in Entities.Values) foreach (EntityBase ent in Entities)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -619,7 +625,7 @@ namespace OpenSim.Region.Environment.Scenes
m_log.Info("Starting all Scripts in Scene"); m_log.Info("Starting all Scripts in Scene");
lock (Entities) lock (Entities)
{ {
foreach (EntityBase ent in Entities.Values) foreach (EntityBase ent in Entities)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -1857,7 +1863,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
lock (Entities) lock (Entities)
{ {
ICollection<EntityBase> entities = new List<EntityBase>(Entities.Values); ICollection<EntityBase> entities = new List<EntityBase>(Entities);
foreach (EntityBase e in entities) foreach (EntityBase e in entities)
{ {

View File

@ -59,7 +59,8 @@ namespace OpenSim.Region.Environment.Scenes
protected internal Dictionary<UUID, ScenePresence> ScenePresences = new Dictionary<UUID, ScenePresence>(); protected internal Dictionary<UUID, ScenePresence> ScenePresences = new Dictionary<UUID, ScenePresence>();
// SceneObjects is not currently populated or used. // SceneObjects is not currently populated or used.
//public Dictionary<UUID, SceneObjectGroup> SceneObjects; //public Dictionary<UUID, SceneObjectGroup> SceneObjects;
protected internal Dictionary<UUID, EntityBase> Entities = new Dictionary<UUID, EntityBase>(); protected internal EntityManager Entities = new EntityManager();
// protected internal Dictionary<UUID, EntityBase> Entities = new Dictionary<UUID, EntityBase>();
protected internal Dictionary<UUID, ScenePresence> RestorePresences = new Dictionary<UUID, ScenePresence>(); protected internal Dictionary<UUID, ScenePresence> RestorePresences = new Dictionary<UUID, ScenePresence>();
protected internal BasicQuadTreeNode QuadTree; protected internal BasicQuadTreeNode QuadTree;
@ -972,10 +973,7 @@ namespace OpenSim.Region.Environment.Scenes
/// <returns></returns> /// <returns></returns>
protected internal List<EntityBase> GetEntities() protected internal List<EntityBase> GetEntities()
{ {
lock (Entities) return Entities.GetEntities();
{
return new List<EntityBase>(Entities.Values);
}
} }
protected internal Dictionary<uint, float> GetTopScripts() protected internal Dictionary<uint, float> GetTopScripts()

View File

@ -600,7 +600,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
m_pendingObjects = new Queue<SceneObjectGroup>(); m_pendingObjects = new Queue<SceneObjectGroup>();
List<EntityBase> ents = new List<EntityBase>(m_scene.Entities.Values); List<EntityBase> ents = new List<EntityBase>(m_scene.Entities);
if (!m_isChildAgent) // Proximity sort makes no sense for if (!m_isChildAgent) // Proximity sort makes no sense for
{ // Child agents { // Child agents
ents.Sort(delegate(EntityBase a, EntityBase b) ents.Sort(delegate(EntityBase a, EntityBase b)