From 33f5d0d1e90c3e63e06a200043a01c32768335c1 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 15 Mar 2010 14:17:17 -0700 Subject: * UuidGatherer now tracks asset types for assets it discovers. The asset types are inferred from context * OAR saving will attempt to correct unknown asset types before writing broken assets to the OAR file --- .../Framework/Scenes/Tests/UuidGathererTests.cs | 4 +-- OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 29 +++++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs index 6686264..8b80ebe 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs @@ -61,7 +61,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests AssetBase corruptAsset = AssetHelpers.CreateAsset(corruptAssetUuid, "CORRUPT ASSET", UUID.Zero); m_assetService.Store(corruptAsset); - IDictionary foundAssetUuids = new Dictionary(); + IDictionary foundAssetUuids = new Dictionary(); m_uuidGatherer.GatherAssetUuids(corruptAssetUuid, AssetType.Object, foundAssetUuids); // We count the uuid as gathered even if the asset itself is corrupt. @@ -77,7 +77,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelper.InMethod(); UUID missingAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); - IDictionary foundAssetUuids = new Dictionary(); + IDictionary foundAssetUuids = new Dictionary(); m_uuidGatherer.GatherAssetUuids(missingAssetUuid, AssetType.Object, foundAssetUuids); diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 3edb677..4a1f648 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -84,9 +84,9 @@ namespace OpenSim.Region.Framework.Scenes /// The uuid of the asset for which to gather referenced assets /// The type of the asset for the uuid given /// The assets gathered - public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary assetUuids) + public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary assetUuids) { - assetUuids[assetUuid] = 1; + assetUuids[assetUuid] = assetType; if (AssetType.Bodypart == assetType || AssetType.Clothing == assetType) { @@ -116,7 +116,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// The scene object for which to gather assets /// The assets gathered - public void GatherAssetUuids(SceneObjectGroup sceneObject, IDictionary assetUuids) + public void GatherAssetUuids(SceneObjectGroup sceneObject, IDictionary assetUuids) { // m_log.DebugFormat( // "[ASSET GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID); @@ -131,7 +131,7 @@ namespace OpenSim.Region.Framework.Scenes Primitive.TextureEntry textureEntry = part.Shape.Textures; // Get the prim's default texture. This will be used for faces which don't have their own texture - assetUuids[textureEntry.DefaultTexture.TextureID] = 1; + assetUuids[textureEntry.DefaultTexture.TextureID] = AssetType.Texture; // XXX: Not a great way to iterate through face textures, but there's no // other method available to tell how many faces there actually are @@ -141,13 +141,13 @@ namespace OpenSim.Region.Framework.Scenes if (texture != null) { //m_log.DebugFormat("[ARCHIVER]: Got face {0}", i++); - assetUuids[texture.TextureID] = 1; + assetUuids[texture.TextureID] = AssetType.Texture; } } // If the prim is a sculpt then preserve this information too if (part.Shape.SculptTexture != UUID.Zero) - assetUuids[part.Shape.SculptTexture] = 1; + assetUuids[part.Shape.SculptTexture] = AssetType.Texture; TaskInventoryDictionary taskDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); @@ -217,7 +217,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// Dictionary in which to record the references - protected void GetScriptAssetUuids(UUID scriptUuid, IDictionary assetUuids) + protected void GetScriptAssetUuids(UUID scriptUuid, IDictionary assetUuids) { AssetBase scriptAsset = GetAsset(scriptUuid); @@ -232,7 +232,9 @@ namespace OpenSim.Region.Framework.Scenes { UUID uuid = new UUID(uuidMatch.Value); //m_log.DebugFormat("[ARCHIVER]: Recording {0} in script", uuid); - assetUuids[uuid] = 1; + + // Assume AssetIDs embedded in scripts are textures + assetUuids[uuid] = AssetType.Texture; } } } @@ -242,7 +244,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// Dictionary in which to record the references - protected void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary assetUuids) + protected void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary assetUuids) { AssetBase assetBase = GetAsset(wearableAssetUuid); @@ -257,8 +259,7 @@ namespace OpenSim.Region.Framework.Scenes foreach (UUID uuid in wearableAsset.Textures.Values) { - //m_log.DebugFormat("[ARCHIVER]: Got bodypart uuid {0}", uuid); - assetUuids[uuid] = 1; + assetUuids[uuid] = AssetType.Texture; } } } @@ -270,7 +271,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// - protected void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary assetUuids) + protected void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary assetUuids) { AssetBase objectAsset = GetAsset(sceneObjectUuid); @@ -284,7 +285,7 @@ namespace OpenSim.Region.Framework.Scenes } } - protected void GetGestureAssetUuids(UUID gestureUuid, IDictionary assetUuids) + protected void GetGestureAssetUuids(UUID gestureUuid, IDictionary assetUuids) { AssetBase assetBase = GetAsset(gestureUuid); @@ -316,7 +317,7 @@ namespace OpenSim.Region.Framework.Scenes // If it can be parsed as a UUID, it is an asset ID UUID uuid; if (UUID.TryParse(id, out uuid)) - assetUuids[uuid] = 1; + assetUuids[uuid] = AssetType.Animation; } } } -- cgit v1.1 From b4dcdffb5094c488a98acbe675b333c3bd4cc570 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 16 Mar 2010 11:50:22 -0700 Subject: Fixed several unhandled exceptions and performance issues with PrimitiveBaseShape.Textures. This really should be moved from a property to a method if it is going to decode a byte[] into a TextureEntry each time --- OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 4a1f648..0ec3cc3 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -129,19 +129,20 @@ namespace OpenSim.Region.Framework.Scenes try { Primitive.TextureEntry textureEntry = part.Shape.Textures; - - // Get the prim's default texture. This will be used for faces which don't have their own texture - assetUuids[textureEntry.DefaultTexture.TextureID] = AssetType.Texture; - - // XXX: Not a great way to iterate through face textures, but there's no - // other method available to tell how many faces there actually are - //int i = 0; - foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures) + if (textureEntry != null) { - if (texture != null) + // Get the prim's default texture. This will be used for faces which don't have their own texture + if (textureEntry.DefaultTexture != null) + assetUuids[textureEntry.DefaultTexture.TextureID] = AssetType.Texture; + + if (textureEntry.FaceTextures != null) { - //m_log.DebugFormat("[ARCHIVER]: Got face {0}", i++); - assetUuids[texture.TextureID] = AssetType.Texture; + // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture) + foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures) + { + if (texture != null) + assetUuids[texture.TextureID] = AssetType.Texture; + } } } -- cgit v1.1 From b51f40da8f24b78fa6101d70726ca2000e5b0341 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 16 Mar 2010 12:03:04 -0700 Subject: Removed the unused use_async_when_possible config variable --- OpenSim/Region/Framework/Scenes/Scene.cs | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index c510dc8..baa8759 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -131,7 +131,6 @@ 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; private Dictionary m_returns = new Dictionary(); private Dictionary m_groupsWithTargets = new Dictionary(); @@ -654,9 +653,6 @@ 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", false); - //Animation states m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); // TODO: Change default to true once the feature is supported @@ -4289,20 +4285,7 @@ namespace OpenSim.Region.Framework.Scenes public void ForEachClient(Action action) { - ForEachClient(action, m_useAsyncWhenPossible); - } - - public void ForEachClient(Action action, bool doAsynchronous) - { - // 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 m_clientManager.ForEachSync(action); - - //if (doAsynchronous) - // m_clientManager.ForEach(action); - //else - // m_clientManager.ForEachSync(action); } public bool TryGetClient(UUID avatarID, out IClientAPI client) -- cgit v1.1 From 73e9b0be725a73a489b29f3fe2df236c897ef3b5 Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Wed, 17 Mar 2010 06:40:00 -0700 Subject: Inconsistent locking of ScenePresence array in SceneGraph. Fixed by eliminating option to return the actual list. Callers can now either request a copy of the array as a new List or ask the SceneGraph to call a delegate function on every ScenePresence. Iteration and locking of the ScenePresences now takes place only within the SceneGraph class. This patch also applies a fix to Combat/CombatModule.cs which had unlocked iteration of the ScenePresences and inconsistent try/catch around the use of those ScenePresences. --- OpenSim/Region/Framework/Scenes/Scene.cs | 52 +++--- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 193 ++++++++++++++------- OpenSim/Region/Framework/Scenes/SceneManager.cs | 17 +- .../Region/Framework/Scenes/SceneObjectGroup.cs | 12 +- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 82 ++++----- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 20 +-- 6 files changed, 211 insertions(+), 165 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index baa8759..a86a33c 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -3599,9 +3599,7 @@ namespace OpenSim.Region.Framework.Scenes public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying) { ScenePresence presence; - m_sceneGraph.TryGetAvatar(agentID, out presence); - - if (presence != null) + if(m_sceneGraph.TryGetAvatar(agentID, out presence)) { try { @@ -3776,9 +3774,7 @@ namespace OpenSim.Region.Framework.Scenes Vector3 lookAt, uint teleportFlags) { ScenePresence sp; - m_sceneGraph.TryGetAvatar(remoteClient.AgentId, out sp); - - if (sp != null) + if(m_sceneGraph.TryGetAvatar(remoteClient.AgentId, out sp)) { uint regionX = m_regInfo.RegionLocX; uint regionY = m_regInfo.RegionLocY; @@ -4134,6 +4130,11 @@ namespace OpenSim.Region.Framework.Scenes //The idea is to have a group of method that return a list of avatars meeting some requirement // ie it could be all m_scenePresences within a certain range of the calling prim/avatar. + // + // GetAvatars returns a new list of all root agent presences in the scene + // GetScenePresences returns a new list of all presences in the scene or a filter may be passed. + // GetScenePresence returns the presence with matching UUID or first/last name. + // ForEachScenePresence requests the Scene to run a delegate function against all presences. /// /// Return a list of all avatars in this region. @@ -4150,7 +4151,7 @@ namespace OpenSim.Region.Framework.Scenes /// This list is a new object, so it can be iterated over without locking. /// /// - public ScenePresence[] GetScenePresences() + public List GetScenePresences() { return m_sceneGraph.GetScenePresences(); } @@ -4176,6 +4177,28 @@ namespace OpenSim.Region.Framework.Scenes return m_sceneGraph.GetScenePresence(avatarID); } + /// + /// Request the ScenePresence in this region by first/last name. + /// Should normally only be a single match, but first is always returned + /// + /// + /// + /// + public ScenePresence GetScenePresence(string firstName, string lastName) + { + return m_sceneGraph.GetScenePresence(firstName, lastName); + } + + /// + /// Request the ScenePresence in this region by localID. + /// + /// + /// + public ScenePresence GetScenePresence(uint localID) + { + return m_sceneGraph.GetScenePresence(localID); + } + public override bool PresenceChildStatus(UUID avatarID) { ScenePresence cp = GetScenePresence(avatarID); @@ -4191,25 +4214,14 @@ namespace OpenSim.Region.Framework.Scenes } /// - /// + /// Performs action on all scene presences. /// /// public void ForEachScenePresence(Action action) { - // We don't want to try to send messages if there are no avatars. if (m_sceneGraph != null) { - try - { - ScenePresence[] presences = GetScenePresences(); - for (int i = 0; i < presences.Length; i++) - action(presences[i]); - } - catch (Exception e) - { - m_log.Info("[BUG] in " + RegionInfo.RegionName + ": " + e.ToString()); - m_log.Info("[BUG] Stack Trace: " + e.StackTrace); - } + m_sceneGraph.ForEachScenePresence(action); } } diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index d944834..d259c42 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -165,9 +165,10 @@ namespace OpenSim.Region.Framework.Scenes protected internal void UpdatePresences() { - ScenePresence[] updateScenePresences = GetScenePresences(); - for (int i = 0; i < updateScenePresences.Length; i++) - updateScenePresences[i].Update(); + ForEachScenePresence(delegate(ScenePresence presence) + { + presence.Update(); + }); } protected internal float UpdatePhysics(double elapsed) @@ -196,9 +197,10 @@ namespace OpenSim.Region.Framework.Scenes protected internal void UpdateScenePresenceMovement() { - ScenePresence[] moveEntities = GetScenePresences(); - for (int i = 0; i < moveEntities.Length; i++) - moveEntities[i].UpdateMovement(); + ForEachScenePresence(delegate(ScenePresence presence) + { + presence.UpdateMovement(); + }); } #endregion @@ -616,18 +618,16 @@ namespace OpenSim.Region.Framework.Scenes public void RecalculateStats() { - ScenePresence[] presences = GetScenePresences(); int rootcount = 0; int childcount = 0; - for (int i = 0; i < presences.Length; i++) + ForEachScenePresence(delegate(ScenePresence presence) { - ScenePresence user = presences[i]; - if (user.IsChildAgent) + if (presence.IsChildAgent) ++childcount; else ++rootcount; - } + }); m_numRootAgents = rootcount; m_numChildAgents = childcount; @@ -674,25 +674,6 @@ namespace OpenSim.Region.Framework.Scenes #endregion #region Get Methods - - /// - /// Request a List of all scene presences in this scene. This is a new list, so no - /// locking is required to iterate over it. - /// - /// - protected internal ScenePresence[] GetScenePresences() - { - return m_scenePresenceArray; - } - - protected internal List GetAvatars() - { - List result = - GetScenePresences(delegate(ScenePresence scenePresence) { return !scenePresence.IsChildAgent; }); - - return result; - } - /// /// Get the controlling client for the given avatar, if there is one. /// @@ -718,45 +699,119 @@ namespace OpenSim.Region.Framework.Scenes return null; } + // The idea is to have a group of method that return a list of avatars meeting some requirement + // ie it could be all m_scenePresences within a certain range of the calling prim/avatar. + // + // GetAvatars returns a new list of all root agent presences in the scene + // GetScenePresences returns a new list of all presences in the scene or a filter may be passed. + // GetScenePresence returns the presence with matching UUID or the first presence matching the passed filter. + // ForEachScenePresence requests the Scene to run a delegate function against all presences. + + /// + /// Request a list of all avatars in this region (no child agents) + /// This list is a new object, so it can be iterated over without locking. + /// + /// + public List GetAvatars() + { + return GetScenePresences(delegate(ScenePresence scenePresence) + { + return !scenePresence.IsChildAgent; + }); + } + + /// + /// Request a list of m_scenePresences in this World + /// Returns a copy so it can be iterated without a lock. + /// There is no guarantee that presences will remain in the scene after the list is returned. + /// + /// + protected internal List GetScenePresences() + { + List result; + lock (m_scenePresences) + { + result = new List(m_scenePresenceArray.Length); + result.AddRange(m_scenePresenceArray); + } + return result; + } + /// /// Request a filtered list of m_scenePresences in this World + /// Returns a copy so it can be iterated without a lock. + /// There is no guarantee that presences will remain in the scene after the list is returned. /// /// protected internal List GetScenePresences(FilterAvatarList filter) { - // No locking of scene presences here since we're passing back a list... - List result = new List(); - ScenePresence[] scenePresences = GetScenePresences(); + // Check each ScenePresence against the filter + ForEachScenePresence(delegate(ScenePresence presence) + { + if (filter(presence)) + result.Add(presence); + }); + return result; + } - for (int i = 0; i < scenePresences.Length; i++) + /// + /// Request the ScenePresence in this region matching filter. + /// Only the first match is returned. + /// + /// + /// + /// + protected internal ScenePresence GetScenePresence(FilterAvatarList filter) + { + ScenePresence result = null; + // Get all of the ScenePresences + List presences = GetScenePresences(); + foreach (ScenePresence presence in presences) { - ScenePresence avatar = scenePresences[i]; - if (filter(avatar)) - result.Add(avatar); + if (filter(presence)) + { + result = presence; + break; + } } - return result; } + protected internal ScenePresence GetScenePresence(string firstName, string lastName) + { + return GetScenePresence(delegate(ScenePresence presence) + { + return(presence.Firstname == firstName && presence.Lastname == lastName); + }); + } + /// /// Request a scene presence by UUID /// - /// + /// /// null if the agent was not found protected internal ScenePresence GetScenePresence(UUID agentID) { ScenePresence sp; - - lock (m_scenePresences) - { - m_scenePresences.TryGetValue(agentID, out sp); - } - + TryGetAvatar(agentID, out sp); return sp; } /// + /// Request the ScenePresence in this region by localID. + /// + /// + /// + protected internal ScenePresence GetScenePresence(uint localID) + { + return GetScenePresence(delegate(ScenePresence presence) + { + return (presence.LocalId == localID); + }); + } + + /// /// Get a scene object group that contains the prim with the given local id /// /// @@ -910,29 +965,19 @@ namespace OpenSim.Region.Framework.Scenes protected internal bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) { lock (m_scenePresences) - return m_scenePresences.TryGetValue(avatarId, out avatar); + { + m_scenePresences.TryGetValue(avatarId, out avatar); + } + return (avatar != null); } protected internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) { - ScenePresence[] presences = GetScenePresences(); - - for (int i = 0; i < presences.Length; i++) + avatar = GetScenePresence(delegate(ScenePresence presence) { - ScenePresence presence = presences[i]; - - if (!presence.IsChildAgent) - { - if (String.Compare(avatarName, presence.ControllingClient.Name, true) == 0) - { - avatar = presence; - return true; - } - } - } - - avatar = null; - return false; + return (String.Compare(avatarName, presence.ControllingClient.Name, true) == 0); + }); + return (avatar != null); } /// @@ -1013,6 +1058,28 @@ namespace OpenSim.Region.Framework.Scenes } } } + + + /// + /// Performs action on all scene presences. + /// + /// + public void ForEachScenePresence(Action action) + { + List presences = GetScenePresences(); + try + { + foreach(ScenePresence presence in presences) + { + action(presence); + } + } + catch (Exception e) + { + m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString()); + m_log.Info("[BUG] Stack Trace: " + e.StackTrace); + } + } #endregion diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index 680c39a..a955532 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs @@ -414,12 +414,8 @@ namespace OpenSim.Region.Framework.Scenes ForEachCurrentScene( delegate(Scene scene) { - ScenePresence[] scenePresences = scene.GetScenePresences(); - - for (int i = 0; i < scenePresences.Length; i++) + scene.ForEachScenePresence(delegate(ScenePresence scenePresence) { - ScenePresence scenePresence = scenePresences[i]; - if (!scenePresence.IsChildAgent) { m_log.DebugFormat("Packet debug for {0} {1} set to {2}", @@ -429,7 +425,7 @@ namespace OpenSim.Region.Framework.Scenes scenePresence.ControllingClient.SetDebugPacketLevel(newDebug); } - } + }); } ); } @@ -441,14 +437,11 @@ namespace OpenSim.Region.Framework.Scenes ForEachCurrentScene( delegate(Scene scene) { - ScenePresence[] scenePresences = scene.GetScenePresences(); - - for (int i = 0; i < scenePresences.Length; i++) + scene.ForEachScenePresence(delegate(ScenePresence scenePresence) { - ScenePresence scenePresence = scenePresences[i]; if (!scenePresence.IsChildAgent) avatars.Add(scenePresence); - } + }); } ); @@ -461,7 +454,7 @@ namespace OpenSim.Region.Framework.Scenes ForEachCurrentScene(delegate(Scene scene) { - ScenePresence[] scenePresences = scene.GetScenePresences(); + List scenePresences = scene.GetScenePresences(); presences.AddRange(scenePresences); }); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 88deedf..8aefd50 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1268,22 +1268,20 @@ namespace OpenSim.Region.Framework.Scenes foreach (SceneObjectPart part in m_parts.Values) { // part.Inventory.RemoveScriptInstances(); - - ScenePresence[] avatars = Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - if (avatars[i].ParentID == LocalId) + if (avatar.ParentID == LocalId) { - avatars[i].StandUp(); + avatar.StandUp(); } if (!silent) { part.UpdateFlag = 0; if (part == m_rootPart) - avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId); + avatar.ControllingClient.SendKillObject(m_regionHandle, part.LocalId); } - } + }); } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index a2b98b9..0e21487 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1197,15 +1197,14 @@ namespace OpenSim.Region.Framework.Scenes private void SendObjectPropertiesToClient(UUID AgentID) { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { // Ugly reference :( - if (avatars[i].UUID == AgentID) + if (avatar.UUID == AgentID) { - m_parentGroup.GetProperties(avatars[i].ControllingClient); + m_parentGroup.GetProperties(avatar.ControllingClient); } - } + }); } // TODO: unused: @@ -1260,11 +1259,10 @@ namespace OpenSim.Region.Framework.Scenes /// public void AddFullUpdateToAllAvatars() { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - avatars[i].SceneViewer.QueuePartForUpdate(this); - } + avatar.SceneViewer.QueuePartForUpdate(this); + }); } public void AddFullUpdateToAvatar(ScenePresence presence) @@ -1285,11 +1283,10 @@ namespace OpenSim.Region.Framework.Scenes /// Terse updates public void AddTerseUpdateToAllAvatars() { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - avatars[i].SceneViewer.QueuePartForUpdate(this); - } + avatar.SceneViewer.QueuePartForUpdate(this); + }); } public void AddTerseUpdateToAvatar(ScenePresence presence) @@ -2121,17 +2118,13 @@ namespace OpenSim.Region.Framework.Scenes } else { - ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); - - for (int i = 0; i < avlist.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av) { - ScenePresence av = avlist[i]; - if (av.LocalId == localId) { if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar if (found) { @@ -2153,7 +2146,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work if (!found) { @@ -2171,7 +2164,7 @@ namespace OpenSim.Region.Framework.Scenes } } - } + }); } } if (colliding.Count > 0) @@ -2257,17 +2250,13 @@ namespace OpenSim.Region.Framework.Scenes } else { - ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); - - for (int i = 0; i < avlist.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av) { - ScenePresence av = avlist[i]; - if (av.LocalId == localId) { if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar if (found) { @@ -2289,7 +2278,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work if (!found) { @@ -2307,7 +2296,7 @@ namespace OpenSim.Region.Framework.Scenes } } - } + }); } } if (colliding.Count > 0) @@ -2388,17 +2377,13 @@ namespace OpenSim.Region.Framework.Scenes } else { - ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); - - for (int i = 0; i < avlist.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av) { - ScenePresence av = avlist[i]; - if (av.LocalId == localId) { if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar if (found) { @@ -2420,7 +2405,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work if (!found) { @@ -2438,7 +2423,7 @@ namespace OpenSim.Region.Framework.Scenes } } - } + }); } } @@ -2877,11 +2862,10 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendFullUpdateToAllClients() { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - SendFullUpdate(avatars[i].ControllingClient, avatars[i].GenerateClientFlags(UUID)); - } + SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID)); + }); } /// @@ -2890,13 +2874,12 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendFullUpdateToAllClientsExcept(UUID agentID) { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { // Ugly reference :( - if (avatars[i].UUID != agentID) - SendFullUpdate(avatars[i].ControllingClient, avatars[i].GenerateClientFlags(UUID)); - } + if (avatar.UUID != agentID) + SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID)); + }); } /// @@ -3096,11 +3079,10 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendTerseUpdateToAllClients() { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - SendTerseUpdateToClient(avatars[i].ControllingClient); - } + SendTerseUpdateToClient(avatar.ControllingClient); + }); } public void SetAttachmentPoint(uint AttachmentPoint) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 6f16ff3..766f6d3 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -912,14 +912,11 @@ namespace OpenSim.Region.Framework.Scenes m_isChildAgent = false; - ScenePresence[] animAgents = m_scene.GetScenePresences(); - for (int i = 0; i < animAgents.Length; i++) + m_scene.ForEachScenePresence(delegate(ScenePresence presence) { - ScenePresence presence = animAgents[i]; - if (presence != this) presence.Animator.SendAnimPackToClient(ControllingClient); - } + }); m_scene.EventManager.TriggerOnMakeRootAgent(this); } @@ -2469,13 +2466,10 @@ namespace OpenSim.Region.Framework.Scenes public void SendInitialFullUpdateToAllClients() { m_perfMonMS = Util.EnvironmentTickCount(); - - ScenePresence[] avatars = m_scene.GetScenePresences(); - - for (int i = 0; i < avatars.Length; i++) + int avUpdates = 0; + m_scene.ForEachScenePresence(delegate(ScenePresence avatar) { - ScenePresence avatar = avatars[i]; - + ++avUpdates; // only send if this is the root (children are only "listening posts" in a foreign region) if (!IsChildAgent) { @@ -2491,9 +2485,9 @@ namespace OpenSim.Region.Framework.Scenes avatar.Animator.SendAnimPackToClient(ControllingClient); } } - } + }); - m_scene.StatsReporter.AddAgentUpdates(avatars.Length); + m_scene.StatsReporter.AddAgentUpdates(avUpdates); m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); //Animator.SendAnimPack(); -- cgit v1.1 From 734b0416deac953937df9cd6dd1d0bbfbdc03a58 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 18 Mar 2010 18:57:29 +0000 Subject: Unify a previous refactor of object return with the older solution. We really don't need two methods doing the same thing, but differently. --- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 7 +++--- .../Region/Framework/Scenes/Scene.Permissions.cs | 29 +++++----------------- 2 files changed, 10 insertions(+), 26 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 41533a1..c662a6b 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -1518,9 +1518,10 @@ namespace OpenSim.Region.Framework.Scenes if (remoteClient != null) { permissionToTake = - Permissions.CanReturnObject( - grp.UUID, - remoteClient.AgentId); + Permissions.CanReturnObjects( + null, + remoteClient.AgentId, + new List() {grp}); permissionToDelete = permissionToTake; if (permissionToDelete) diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs index d1d6b6a..7dab04f 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs @@ -48,7 +48,7 @@ namespace OpenSim.Region.Framework.Scenes public delegate bool EditObjectInventoryHandler(UUID objectID, UUID editorID, Scene scene); public delegate bool MoveObjectHandler(UUID objectID, UUID moverID, Scene scene); public delegate bool ObjectEntryHandler(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene); - public delegate bool ReturnObjectHandler(UUID objectID, UUID returnerID, Scene scene); + public delegate bool ReturnObjectsHandler(ILandObject land, UUID user, List objects, Scene scene); public delegate bool InstantMessageHandler(UUID user, UUID target, Scene startScene); public delegate bool InventoryTransferHandler(UUID user, UUID target, Scene startScene); public delegate bool ViewScriptHandler(UUID script, UUID objectID, UUID user, Scene scene); @@ -81,7 +81,6 @@ namespace OpenSim.Region.Framework.Scenes public delegate bool CopyUserInventoryHandler(UUID itemID, UUID userID); public delegate bool DeleteUserInventoryHandler(UUID itemID, UUID userID); public delegate bool TeleportHandler(UUID userID, Scene scene); - public delegate bool UseObjectReturnHandler(ILandObject landData, uint type, IClientAPI client, List retlist, Scene scene); #endregion public class ScenePermissions @@ -107,7 +106,7 @@ namespace OpenSim.Region.Framework.Scenes public event EditObjectInventoryHandler OnEditObjectInventory; public event MoveObjectHandler OnMoveObject; public event ObjectEntryHandler OnObjectEntry; - public event ReturnObjectHandler OnReturnObject; + public event ReturnObjectsHandler OnReturnObjects; public event InstantMessageHandler OnInstantMessage; public event InventoryTransferHandler OnInventoryTransfer; public event ViewScriptHandler OnViewScript; @@ -140,7 +139,6 @@ namespace OpenSim.Region.Framework.Scenes public event CopyUserInventoryHandler OnCopyUserInventory; public event DeleteUserInventoryHandler OnDeleteUserInventory; public event TeleportHandler OnTeleport; - public event UseObjectReturnHandler OnUseObjectReturn; #endregion #region Object Permission Checks @@ -377,15 +375,15 @@ namespace OpenSim.Region.Framework.Scenes #endregion #region RETURN OBJECT - public bool CanReturnObject(UUID objectID, UUID returnerID) + public bool CanReturnObjects(ILandObject land, UUID user, List objects) { - ReturnObjectHandler handler = OnReturnObject; + ReturnObjectsHandler handler = OnReturnObjects; if (handler != null) { Delegate[] list = handler.GetInvocationList(); - foreach (ReturnObjectHandler h in list) + foreach (ReturnObjectsHandler h in list) { - if (h(objectID, returnerID, m_scene) == false) + if (h(land, user, objects, m_scene) == false) return false; } } @@ -949,20 +947,5 @@ namespace OpenSim.Region.Framework.Scenes } return true; } - - public bool CanUseObjectReturn(ILandObject landData, uint type , IClientAPI client, List retlist) - { - UseObjectReturnHandler handler = OnUseObjectReturn; - if (handler != null) - { - Delegate[] list = handler.GetInvocationList(); - foreach (UseObjectReturnHandler h in list) - { - if (h(landData, type, client, retlist, m_scene) == false) - return false; - } - } - return true; - } } } -- cgit v1.1