aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
authorMelanie2010-03-30 21:34:27 +0100
committerMelanie2010-03-30 21:34:27 +0100
commit5693870fe26fae35a28f2d5103780434f4f40e57 (patch)
tree0e070fb6f11ab8763ac4f1f9a851a0061101d4d6 /OpenSim/Region/Framework/Scenes
parentMerge branch 'careminster-presence-refactor' of ssh://3dhosting.de/var/git/ca... (diff)
parentminor: commented out code removal (diff)
downloadopensim-SC-5693870fe26fae35a28f2d5103780434f4f40e57.zip
opensim-SC-5693870fe26fae35a28f2d5103780434f4f40e57.tar.gz
opensim-SC-5693870fe26fae35a28f2d5103780434f4f40e57.tar.bz2
opensim-SC-5693870fe26fae35a28f2d5103780434f4f40e57.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs16
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs204
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneBase.cs6
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs186
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneManager.cs12
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs21
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs58
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs2
8 files changed, 283 insertions, 222 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index cadb858..1875c48 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -132,7 +132,7 @@ namespace OpenSim.Region.Framework.Scenes
132 { 132 {
133 ScenePresence avatar; 133 ScenePresence avatar;
134 134
135 if (TryGetAvatar(avatarId, out avatar)) 135 if (TryGetScenePresence(avatarId, out avatar))
136 { 136 {
137 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>(); 137 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
138 if (invAccess != null) 138 if (invAccess != null)
@@ -230,7 +230,7 @@ namespace OpenSim.Region.Framework.Scenes
230 { 230 {
231 ScenePresence avatar; 231 ScenePresence avatar;
232 232
233 if (TryGetAvatar(avatarId, out avatar)) 233 if (TryGetScenePresence(avatarId, out avatar))
234 { 234 {
235 return CapsUpdateTaskInventoryScriptAsset( 235 return CapsUpdateTaskInventoryScriptAsset(
236 avatar.ControllingClient, itemId, primId, isScriptRunning, data); 236 avatar.ControllingClient, itemId, primId, isScriptRunning, data);
@@ -683,7 +683,7 @@ namespace OpenSim.Region.Framework.Scenes
683 if (transactionID == UUID.Zero) 683 if (transactionID == UUID.Zero)
684 { 684 {
685 ScenePresence presence; 685 ScenePresence presence;
686 if (TryGetAvatar(remoteClient.AgentId, out presence)) 686 if (TryGetScenePresence(remoteClient.AgentId, out presence))
687 { 687 {
688 byte[] data = null; 688 byte[] data = null;
689 689
@@ -945,7 +945,7 @@ namespace OpenSim.Region.Framework.Scenes
945 { 945 {
946 ScenePresence avatar; 946 ScenePresence avatar;
947 947
948 if (TryGetAvatar(avatarId, out avatar)) 948 if (TryGetScenePresence(avatarId, out avatar))
949 { 949 {
950 return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId); 950 return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId);
951 } 951 }
@@ -1059,7 +1059,7 @@ namespace OpenSim.Region.Framework.Scenes
1059 1059
1060 ScenePresence avatar; 1060 ScenePresence avatar;
1061 1061
1062 if (TryGetAvatar(srcTaskItem.OwnerID, out avatar)) 1062 if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
1063 { 1063 {
1064 destPart.GetProperties(avatar.ControllingClient); 1064 destPart.GetProperties(avatar.ControllingClient);
1065 } 1065 }
@@ -1087,7 +1087,7 @@ namespace OpenSim.Region.Framework.Scenes
1087 } 1087 }
1088 1088
1089 ScenePresence avatar = null; 1089 ScenePresence avatar = null;
1090 if (TryGetAvatar(destID, out avatar)) 1090 if (TryGetScenePresence(destID, out avatar))
1091 { 1091 {
1092 //profile.SendInventoryDecendents(avatar.ControllingClient, 1092 //profile.SendInventoryDecendents(avatar.ControllingClient,
1093 // profile.RootFolder.ID, true, false); 1093 // profile.RootFolder.ID, true, false);
@@ -1424,7 +1424,7 @@ namespace OpenSim.Region.Framework.Scenes
1424 1424
1425 ScenePresence avatar; 1425 ScenePresence avatar;
1426 1426
1427 if (TryGetAvatar(srcTaskItem.OwnerID, out avatar)) 1427 if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
1428 { 1428 {
1429 destPart.GetProperties(avatar.ControllingClient); 1429 destPart.GetProperties(avatar.ControllingClient);
1430 } 1430 }
@@ -1865,7 +1865,7 @@ namespace OpenSim.Region.Framework.Scenes
1865 UUID inventoryID = part.ParentGroup.GetFromItemID(); 1865 UUID inventoryID = part.ParentGroup.GetFromItemID();
1866 1866
1867 ScenePresence presence; 1867 ScenePresence presence;
1868 if (TryGetAvatar(remoteClient.AgentId, out presence)) 1868 if (TryGetScenePresence(remoteClient.AgentId, out presence))
1869 { 1869 {
1870 if (!Permissions.CanRezObject(part.ParentGroup.Children.Count, remoteClient.AgentId, presence.AbsolutePosition)) 1870 if (!Permissions.CanRezObject(part.ParentGroup.Children.Count, remoteClient.AgentId, presence.AbsolutePosition))
1871 return; 1871 return;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index b2c8dfd..2b6f80b 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -606,7 +606,46 @@ namespace OpenSim.Region.Framework.Scenes
606 606
607 if (m_storageManager.EstateDataStore != null) 607 if (m_storageManager.EstateDataStore != null)
608 { 608 {
609 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID); 609 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, false);
610 if (m_regInfo.EstateSettings.EstateID == 0) // No record at all
611 {
612 MainConsole.Instance.Output("Your region is not part of an estate.");
613 while (true)
614 {
615 string response = MainConsole.Instance.CmdPrompt("Do you wish to join an existing estate?", "no", new List<string>() {"yes", "no"});
616 if (response == "no")
617 {
618 // Create a new estate
619 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, true);
620
621 m_regInfo.EstateSettings.EstateName = MainConsole.Instance.CmdPrompt("New estate name", m_regInfo.EstateSettings.EstateName);
622 m_regInfo.EstateSettings.Save();
623 break;
624 }
625 else
626 {
627 response = MainConsole.Instance.CmdPrompt("Estate name to join", "None");
628 if (response == "None")
629 continue;
630
631 List<int> estateIDs = m_storageManager.EstateDataStore.GetEstates(response);
632 if (estateIDs.Count < 1)
633 {
634 MainConsole.Instance.Output("The name you have entered matches no known estate. Please try again");
635 continue;
636 }
637
638 int estateID = estateIDs[0];
639
640 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(estateID);
641
642 if (m_storageManager.EstateDataStore.LinkRegion(m_regInfo.RegionID, estateID))
643 break;
644
645 MainConsole.Instance.Output("Joining the estate failed. Please try again.");
646 }
647 }
648 }
610 } 649 }
611 650
612 //Bind Storage Manager functions to some land manager functions for this scene 651 //Bind Storage Manager functions to some land manager functions for this scene
@@ -1229,6 +1268,84 @@ namespace OpenSim.Region.Framework.Scenes
1229 m_dialogModule = RequestModuleInterface<IDialogModule>(); 1268 m_dialogModule = RequestModuleInterface<IDialogModule>();
1230 m_capsModule = RequestModuleInterface<ICapabilitiesModule>(); 1269 m_capsModule = RequestModuleInterface<ICapabilitiesModule>();
1231 m_teleportModule = RequestModuleInterface<IEntityTransferModule>(); 1270 m_teleportModule = RequestModuleInterface<IEntityTransferModule>();
1271
1272 // Shoving this in here for now, because we have the needed
1273 // interfaces at this point
1274 //
1275 // TODO: Find a better place for this
1276 //
1277 while (m_regInfo.EstateSettings.EstateOwner == UUID.Zero && MainConsole.Instance != null)
1278 {
1279 MainConsole.Instance.Output("The current estate has no owner set.");
1280 string first = MainConsole.Instance.CmdPrompt("Estate owner first name", "Test");
1281 string last = MainConsole.Instance.CmdPrompt("Estate owner last name", "User");
1282
1283 UserAccount account = UserAccountService.GetUserAccount(m_regInfo.ScopeID, first, last);
1284
1285 if (account == null)
1286 {
1287 // Create a new account
1288 account = new UserAccount(m_regInfo.ScopeID, first, last, String.Empty);
1289 if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
1290 {
1291 account.ServiceURLs = new Dictionary<string, object>();
1292 account.ServiceURLs["HomeURI"] = string.Empty;
1293 account.ServiceURLs["GatekeeperURI"] = string.Empty;
1294 account.ServiceURLs["InventoryServerURI"] = string.Empty;
1295 account.ServiceURLs["AssetServerURI"] = string.Empty;
1296 }
1297
1298 if (UserAccountService.StoreUserAccount(account))
1299 {
1300 string password = MainConsole.Instance.PasswdPrompt("Password");
1301 string email = MainConsole.Instance.CmdPrompt("Email", "");
1302
1303 account.Email = email;
1304 UserAccountService.StoreUserAccount(account);
1305
1306 bool success = false;
1307 success = AuthenticationService.SetPassword(account.PrincipalID, password);
1308 if (!success)
1309 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.",
1310 first, last);
1311
1312 GridRegion home = null;
1313 if (GridService != null)
1314 {
1315 List<GridRegion> defaultRegions = GridService.GetDefaultRegions(UUID.Zero);
1316 if (defaultRegions != null && defaultRegions.Count >= 1)
1317 home = defaultRegions[0];
1318
1319 if (PresenceService != null && home != null)
1320 PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
1321 else
1322 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
1323 first, last);
1324
1325 }
1326 else
1327 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.",
1328 first, last);
1329
1330 if (InventoryService != null)
1331 success = InventoryService.CreateUserInventory(account.PrincipalID);
1332 if (!success)
1333 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.",
1334 first, last);
1335
1336
1337 m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", first, last);
1338
1339 m_regInfo.EstateSettings.EstateOwner = account.PrincipalID;
1340 m_regInfo.EstateSettings.Save();
1341 }
1342 }
1343 else
1344 {
1345 m_regInfo.EstateSettings.EstateOwner = account.PrincipalID;
1346 m_regInfo.EstateSettings.Save();
1347 }
1348 }
1232 } 1349 }
1233 1350
1234 #endregion 1351 #endregion
@@ -3296,7 +3413,7 @@ namespace OpenSim.Region.Framework.Scenes
3296 } 3413 }
3297 } 3414 }
3298 3415
3299 ScenePresence sp = m_sceneGraph.GetScenePresence(agent.AgentID); 3416 ScenePresence sp = GetScenePresence(agent.AgentID);
3300 if (sp != null) 3417 if (sp != null)
3301 { 3418 {
3302 m_log.DebugFormat( 3419 m_log.DebugFormat(
@@ -3594,8 +3711,7 @@ namespace OpenSim.Region.Framework.Scenes
3594 /// <param name="message">message to display to the user. Reason for being logged off</param> 3711 /// <param name="message">message to display to the user. Reason for being logged off</param>
3595 public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message) 3712 public void HandleLogOffUserFromGrid(UUID AvatarID, UUID RegionSecret, string message)
3596 { 3713 {
3597 ScenePresence loggingOffUser = null; 3714 ScenePresence loggingOffUser = GetScenePresence(AvatarID);
3598 loggingOffUser = GetScenePresence(AvatarID);
3599 if (loggingOffUser != null) 3715 if (loggingOffUser != null)
3600 { 3716 {
3601 UUID localRegionSecret = UUID.Zero; 3717 UUID localRegionSecret = UUID.Zero;
@@ -3631,8 +3747,8 @@ namespace OpenSim.Region.Framework.Scenes
3631 /// <param name="isFlying"></param> 3747 /// <param name="isFlying"></param>
3632 public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying) 3748 public virtual void AgentCrossing(UUID agentID, Vector3 position, bool isFlying)
3633 { 3749 {
3634 ScenePresence presence; 3750 ScenePresence presence = GetScenePresence(agentID);
3635 if(m_sceneGraph.TryGetAvatar(agentID, out presence)) 3751 if(presence != null)
3636 { 3752 {
3637 try 3753 try
3638 { 3754 {
@@ -3806,8 +3922,8 @@ namespace OpenSim.Region.Framework.Scenes
3806 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, Vector3 position, 3922 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, Vector3 position,
3807 Vector3 lookAt, uint teleportFlags) 3923 Vector3 lookAt, uint teleportFlags)
3808 { 3924 {
3809 ScenePresence sp; 3925 ScenePresence sp = GetScenePresence(remoteClient.AgentId);
3810 if(m_sceneGraph.TryGetAvatar(remoteClient.AgentId, out sp)) 3926 if (sp != null)
3811 { 3927 {
3812 uint regionX = m_regInfo.RegionLocX; 3928 uint regionX = m_regInfo.RegionLocX;
3813 uint regionY = m_regInfo.RegionLocY; 3929 uint regionY = m_regInfo.RegionLocY;
@@ -3985,17 +4101,17 @@ namespace OpenSim.Region.Framework.Scenes
3985 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname", 4101 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname",
3986 "Agent ID", "Session ID", "Circuit", "IP", "World"); 4102 "Agent ID", "Session ID", "Circuit", "IP", "World");
3987 4103
3988 foreach (ScenePresence scenePresence in GetAvatars()) 4104 ForEachScenePresence(delegate(ScenePresence sp)
3989 { 4105 {
3990 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}", 4106 m_log.ErrorFormat("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}",
3991 scenePresence.Firstname, 4107 sp.Firstname,
3992 scenePresence.Lastname, 4108 sp.Lastname,
3993 scenePresence.UUID, 4109 sp.UUID,
3994 scenePresence.ControllingClient.AgentId, 4110 sp.ControllingClient.AgentId,
3995 "Unknown", 4111 "Unknown",
3996 "Unknown", 4112 "Unknown",
3997 RegionInfo.RegionName); 4113 RegionInfo.RegionName);
3998 } 4114 });
3999 4115
4000 break; 4116 break;
4001 } 4117 }
@@ -4161,72 +4277,42 @@ namespace OpenSim.Region.Framework.Scenes
4161 m_sceneGraph.RemovePhysicalPrim(num); 4277 m_sceneGraph.RemovePhysicalPrim(num);
4162 } 4278 }
4163 4279
4164 //The idea is to have a group of method that return a list of avatars meeting some requirement 4280 public int GetRootAgentCount()
4165 // ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
4166 //
4167 // GetAvatars returns a new list of all root agent presences in the scene
4168 // GetScenePresences returns a new list of all presences in the scene or a filter may be passed.
4169 // GetScenePresence returns the presence with matching UUID or first/last name.
4170 // ForEachScenePresence requests the Scene to run a delegate function against all presences.
4171
4172 /// <summary>
4173 /// Return a list of all avatars in this region.
4174 /// This list is a new object, so it can be iterated over without locking.
4175 /// </summary>
4176 /// <returns></returns>
4177 public List<ScenePresence> GetAvatars()
4178 { 4281 {
4179 return m_sceneGraph.GetAvatars(); 4282 return m_sceneGraph.GetRootAgentCount();
4180 } 4283 }
4181 4284
4182 /// <summary> 4285 public int GetChildAgentCount()
4183 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents.
4184 /// This list is a new object, so it can be iterated over without locking.
4185 /// </summary>
4186 /// <returns></returns>
4187 public List<ScenePresence> GetScenePresences()
4188 { 4286 {
4189 return m_sceneGraph.GetScenePresences(); 4287 return m_sceneGraph.GetChildAgentCount();
4190 } 4288 }
4191 4289
4192 /// <summary> 4290 /// <summary>
4193 /// Request a filtered list of ScenePresences in this region. 4291 /// Request a scene presence by UUID. Fast, indexed lookup.
4194 /// This list is a new object, so it can be iterated over without locking.
4195 /// </summary> 4292 /// </summary>
4196 /// <param name="filter"></param> 4293 /// <param name="agentID"></param>
4197 /// <returns></returns> 4294 /// <returns>null if the presence was not found</returns>
4198 public List<ScenePresence> GetScenePresences(FilterAvatarList filter) 4295 public ScenePresence GetScenePresence(UUID agentID)
4199 {
4200 return m_sceneGraph.GetScenePresences(filter);
4201 }
4202
4203 /// <summary>
4204 /// Request a scene presence by UUID
4205 /// </summary>
4206 /// <param name="avatarID"></param>
4207 /// <returns></returns>
4208 public ScenePresence GetScenePresence(UUID avatarID)
4209 { 4296 {
4210 return m_sceneGraph.GetScenePresence(avatarID); 4297 return m_sceneGraph.GetScenePresence(agentID);
4211 } 4298 }
4212 4299
4213 /// <summary> 4300 /// <summary>
4214 /// Request the ScenePresence in this region by first/last name. 4301 /// Request the scene presence by name.
4215 /// Should normally only be a single match, but first is always returned
4216 /// </summary> 4302 /// </summary>
4217 /// <param name="firstName"></param> 4303 /// <param name="firstName"></param>
4218 /// <param name="lastName"></param> 4304 /// <param name="lastName"></param>
4219 /// <returns></returns> 4305 /// <returns>null if the presence was not found</returns>
4220 public ScenePresence GetScenePresence(string firstName, string lastName) 4306 public ScenePresence GetScenePresence(string firstName, string lastName)
4221 { 4307 {
4222 return m_sceneGraph.GetScenePresence(firstName, lastName); 4308 return m_sceneGraph.GetScenePresence(firstName, lastName);
4223 } 4309 }
4224 4310
4225 /// <summary> 4311 /// <summary>
4226 /// Request the ScenePresence in this region by localID. 4312 /// Request the scene presence by localID.
4227 /// </summary> 4313 /// </summary>
4228 /// <param name="localID"></param> 4314 /// <param name="localID"></param>
4229 /// <returns></returns> 4315 /// <returns>null if the presence was not found</returns>
4230 public ScenePresence GetScenePresence(uint localID) 4316 public ScenePresence GetScenePresence(uint localID)
4231 { 4317 {
4232 return m_sceneGraph.GetScenePresence(localID); 4318 return m_sceneGraph.GetScenePresence(localID);
@@ -4318,9 +4404,9 @@ namespace OpenSim.Region.Framework.Scenes
4318 return m_sceneGraph.GetGroupByPrim(localID); 4404 return m_sceneGraph.GetGroupByPrim(localID);
4319 } 4405 }
4320 4406
4321 public override bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) 4407 public override bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
4322 { 4408 {
4323 return m_sceneGraph.TryGetAvatar(avatarId, out avatar); 4409 return m_sceneGraph.TryGetScenePresence(avatarId, out avatar);
4324 } 4410 }
4325 4411
4326 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 4412 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs
index 74476ed..3218dad 100644
--- a/OpenSim/Region/Framework/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs
@@ -190,11 +190,11 @@ namespace OpenSim.Region.Framework.Scenes
190 /// <param name="agentID"></param> 190 /// <param name="agentID"></param>
191 public abstract void RemoveClient(UUID agentID); 191 public abstract void RemoveClient(UUID agentID);
192 192
193 public bool TryGetAvatar(UUID agentID, out object scenePresence) 193 public bool TryGetScenePresence(UUID agentID, out object scenePresence)
194 { 194 {
195 scenePresence = null; 195 scenePresence = null;
196 ScenePresence sp = null; 196 ScenePresence sp = null;
197 if (TryGetAvatar(agentID, out sp)) 197 if (TryGetScenePresence(agentID, out sp))
198 { 198 {
199 scenePresence = sp; 199 scenePresence = sp;
200 return true; 200 return true;
@@ -203,7 +203,7 @@ namespace OpenSim.Region.Framework.Scenes
203 return false; 203 return false;
204 } 204 }
205 205
206 public abstract bool TryGetAvatar(UUID agentID, out ScenePresence scenePresence); 206 public abstract bool TryGetScenePresence(UUID agentID, out ScenePresence scenePresence);
207 207
208 #endregion 208 #endregion
209 209
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index 19298d2..3a1962c 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -723,116 +723,84 @@ namespace OpenSim.Region.Framework.Scenes
723 return null; 723 return null;
724 } 724 }
725 725
726 // The idea is to have a group of method that return a list of avatars meeting some requirement
727 // ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
728 //
729 // GetAvatars returns a new list of all root agent presences in the scene
730 // GetScenePresences returns a new list of all presences in the scene or a filter may be passed.
731 // GetScenePresence returns the presence with matching UUID or the first presence matching the passed filter.
732 // ForEachScenePresence requests the Scene to run a delegate function against all presences.
733
734 /// <summary> 726 /// <summary>
735 /// Request a list of all avatars in this region (no child agents) 727 /// Request a copy of m_scenePresences in this World
736 /// This list is a new object, so it can be iterated over without locking. 728 /// There is no guarantee that presences will remain in the scene after the list is returned.
729 /// This list should remain private to SceneGraph. Callers wishing to iterate should instead
730 /// pass a delegate to ForEachScenePresence.
737 /// </summary> 731 /// </summary>
738 /// <returns></returns> 732 /// <returns></returns>
739 public List<ScenePresence> GetAvatars() 733 private List<ScenePresence> GetScenePresences()
740 { 734 {
741 return GetScenePresences(delegate(ScenePresence scenePresence) 735 lock (m_scenePresences)
742 { 736 return new List<ScenePresence>(m_scenePresenceArray);
743 return !scenePresence.IsChildAgent;
744 });
745 } 737 }
746 738
747 /// <summary> 739 /// <summary>
748 /// Request a list of m_scenePresences in this World 740 /// Request a scene presence by UUID. Fast, indexed lookup.
749 /// Returns a copy so it can be iterated without a lock.
750 /// There is no guarantee that presences will remain in the scene after the list is returned.
751 /// </summary> 741 /// </summary>
752 /// <returns></returns> 742 /// <param name="agentID"></param>
753 protected internal List<ScenePresence> GetScenePresences() 743 /// <returns>null if the presence was not found</returns>
744 protected internal ScenePresence GetScenePresence(UUID agentID)
754 { 745 {
755 List<ScenePresence> result; 746 ScenePresence sp;
756 lock (m_scenePresences) 747 lock (m_scenePresences)
757 { 748 {
758 result = new List<ScenePresence>(m_scenePresenceArray.Length); 749 m_scenePresences.TryGetValue(agentID, out sp);
759 result.AddRange(m_scenePresenceArray);
760 } 750 }
761 return result; 751 return sp;
762 } 752 }
763 753
764 /// <summary> 754 /// <summary>
765 /// Request a filtered list of m_scenePresences in this World 755 /// Request the scene presence by name.
766 /// Returns a copy so it can be iterated without a lock.
767 /// There is no guarantee that presences will remain in the scene after the list is returned.
768 /// </summary> 756 /// </summary>
769 /// <returns></returns> 757 /// <param name="firstName"></param>
770 protected internal List<ScenePresence> GetScenePresences(FilterAvatarList filter) 758 /// <param name="lastName"></param>
759 /// <returns>null if the presence was not found</returns>
760 protected internal ScenePresence GetScenePresence(string firstName, string lastName)
771 { 761 {
772 List<ScenePresence> result = new List<ScenePresence>(); 762 foreach (ScenePresence presence in GetScenePresences())
773 // Check each ScenePresence against the filter
774 ForEachScenePresence(delegate(ScenePresence presence)
775 { 763 {
776 if (filter(presence)) 764 if (presence.Firstname == firstName && presence.Lastname == lastName)
777 result.Add(presence); 765 return presence;
778 }); 766 }
779 return result; 767 return null;
780 } 768 }
781 769
782 /// <summary> 770 /// <summary>
783 /// Request the ScenePresence in this region matching filter. 771 /// Request the scene presence by localID.
784 /// Only the first match is returned.
785 ///
786 /// </summary> 772 /// </summary>
787 /// <param name="filter"></param> 773 /// <param name="localID"></param>
788 /// <returns></returns> 774 /// <returns>null if the presence was not found</returns>
789 protected internal ScenePresence GetScenePresence(FilterAvatarList filter) 775 protected internal ScenePresence GetScenePresence(uint localID)
790 { 776 {
791 ScenePresence result = null; 777 foreach (ScenePresence presence in GetScenePresences())
792 // Get all of the ScenePresences 778 if (presence.LocalId == localID)
793 List<ScenePresence> presences = GetScenePresences(); 779 return presence;
794 foreach (ScenePresence presence in presences) 780 return null;
795 {
796 if (filter(presence))
797 {
798 result = presence;
799 break;
800 }
801 }
802 return result;
803 } 781 }
804 782
805 protected internal ScenePresence GetScenePresence(string firstName, string lastName) 783 protected internal bool TryGetScenePresence(UUID agentID, out ScenePresence avatar)
806 { 784 {
807 return GetScenePresence(delegate(ScenePresence presence) 785 lock (m_scenePresences)
808 { 786 {
809 return(presence.Firstname == firstName && presence.Lastname == lastName); 787 m_scenePresences.TryGetValue(agentID, out avatar);
810 }); 788 }
811 } 789 return (avatar != null);
812
813 /// <summary>
814 /// Request a scene presence by UUID
815 /// </summary>
816 /// <param name="agentID"></param>
817 /// <returns>null if the agent was not found</returns>
818 protected internal ScenePresence GetScenePresence(UUID agentID)
819 {
820 ScenePresence sp;
821 TryGetAvatar(agentID, out sp);
822 return sp;
823 } 790 }
824 791
825 /// <summary> 792 protected internal bool TryGetAvatarByName(string name, out ScenePresence avatar)
826 /// Request the ScenePresence in this region by localID.
827 /// </summary>
828 /// <param name="localID"></param>
829 /// <returns></returns>
830 protected internal ScenePresence GetScenePresence(uint localID)
831 { 793 {
832 return GetScenePresence(delegate(ScenePresence presence) 794 avatar = null;
795 foreach (ScenePresence presence in GetScenePresences())
833 { 796 {
834 return (presence.LocalId == localID); 797 if (String.Compare(name, presence.ControllingClient.Name, true) == 0)
835 }); 798 {
799 avatar = presence;
800 break;
801 }
802 }
803 return (avatar != null);
836 } 804 }
837 805
838 /// <summary> 806 /// <summary>
@@ -986,24 +954,6 @@ namespace OpenSim.Region.Framework.Scenes
986 return group.GetChildPart(fullID); 954 return group.GetChildPart(fullID);
987 } 955 }
988 956
989 protected internal bool TryGetAvatar(UUID avatarId, out ScenePresence avatar)
990 {
991 lock (m_scenePresences)
992 {
993 m_scenePresences.TryGetValue(avatarId, out avatar);
994 }
995 return (avatar != null);
996 }
997
998 protected internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
999 {
1000 avatar = GetScenePresence(delegate(ScenePresence presence)
1001 {
1002 return (String.Compare(avatarName, presence.ControllingClient.Name, true) == 0);
1003 });
1004 return (avatar != null);
1005 }
1006
1007 /// <summary> 957 /// <summary>
1008 /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over 958 /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over
1009 /// it 959 /// it
@@ -1066,6 +1016,10 @@ namespace OpenSim.Region.Framework.Scenes
1066 return UUID.Zero; 1016 return UUID.Zero;
1067 } 1017 }
1068 1018
1019 /// <summary>
1020 /// Performs action on all scene object groups.
1021 /// </summary>
1022 /// <param name="action"></param>
1069 protected internal void ForEachSOG(Action<SceneObjectGroup> action) 1023 protected internal void ForEachSOG(Action<SceneObjectGroup> action)
1070 { 1024 {
1071 List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values); 1025 List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values);
@@ -1085,23 +1039,41 @@ namespace OpenSim.Region.Framework.Scenes
1085 1039
1086 1040
1087 /// <summary> 1041 /// <summary>
1088 /// Performs action on all scene presences. 1042 /// Performs action on all scene presences. This can ultimately run the actions in parallel but
1043 /// any delegates passed in will need to implement their own locking on data they reference and
1044 /// modify outside of the scope of the delegate.
1089 /// </summary> 1045 /// </summary>
1090 /// <param name="action"></param> 1046 /// <param name="action"></param>
1091 public void ForEachScenePresence(Action<ScenePresence> action) 1047 public void ForEachScenePresence(Action<ScenePresence> action)
1092 { 1048 {
1093 List<ScenePresence> presences = GetScenePresences(); 1049 // Once all callers have their delegates configured for parallelism, we can unleash this
1094 try 1050 /*
1051 Action<ScenePresence> protectedAction = new Action<ScenePresence>(delegate(ScenePresence sp)
1052 {
1053 try
1054 {
1055 action(sp);
1056 }
1057 catch (Exception e)
1058 {
1059 m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1060 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
1061 }
1062 });
1063 Parallel.ForEach<ScenePresence>(GetScenePresences(), protectedAction);
1064 */
1065 // For now, perform actiona serially
1066 foreach (ScenePresence sp in GetScenePresences())
1095 { 1067 {
1096 foreach(ScenePresence presence in presences) 1068 try
1097 { 1069 {
1098 action(presence); 1070 action(sp);
1071 }
1072 catch (Exception e)
1073 {
1074 m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1075 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
1099 } 1076 }
1100 }
1101 catch (Exception e)
1102 {
1103 m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1104 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
1105 } 1077 }
1106 } 1078 }
1107 1079
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index a955532..3b84734 100644
--- a/OpenSim/Region/Framework/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs
@@ -454,8 +454,10 @@ namespace OpenSim.Region.Framework.Scenes
454 454
455 ForEachCurrentScene(delegate(Scene scene) 455 ForEachCurrentScene(delegate(Scene scene)
456 { 456 {
457 List<ScenePresence> scenePresences = scene.GetScenePresences(); 457 scene.ForEachScenePresence(delegate(ScenePresence sp)
458 presences.AddRange(scenePresences); 458 {
459 presences.Add(sp);
460 });
459 }); 461 });
460 462
461 return presences; 463 return presences;
@@ -484,11 +486,11 @@ namespace OpenSim.Region.Framework.Scenes
484 ForEachCurrentScene(delegate(Scene scene) { scene.HandleEditCommand(cmdparams); }); 486 ForEachCurrentScene(delegate(Scene scene) { scene.HandleEditCommand(cmdparams); });
485 } 487 }
486 488
487 public bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) 489 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
488 { 490 {
489 foreach (Scene scene in m_localScenes) 491 foreach (Scene scene in m_localScenes)
490 { 492 {
491 if (scene.TryGetAvatar(avatarId, out avatar)) 493 if (scene.TryGetScenePresence(avatarId, out avatar))
492 { 494 {
493 return true; 495 return true;
494 } 496 }
@@ -503,7 +505,7 @@ namespace OpenSim.Region.Framework.Scenes
503 ScenePresence avatar = null; 505 ScenePresence avatar = null;
504 foreach (Scene mScene in m_localScenes) 506 foreach (Scene mScene in m_localScenes)
505 { 507 {
506 if (mScene.TryGetAvatar(avatarId, out avatar)) 508 if (mScene.TryGetScenePresence(avatarId, out avatar))
507 { 509 {
508 scene = mScene; 510 scene = mScene;
509 return true; 511 return true;
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 539f2b1..4b2641c 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -682,7 +682,7 @@ namespace OpenSim.Region.Framework.Scenes
682 if (m_parentGroup != null) // TODO can there be a SOP without a SOG? 682 if (m_parentGroup != null) // TODO can there be a SOP without a SOG?
683 { 683 {
684 ScenePresence avatar; 684 ScenePresence avatar;
685 if (m_parentGroup.Scene.TryGetAvatar(m_sitTargetAvatar, out avatar)) 685 if (m_parentGroup.Scene.TryGetScenePresence(m_sitTargetAvatar, out avatar))
686 { 686 {
687 avatar.ParentPosition = GetWorldPosition(); 687 avatar.ParentPosition = GetWorldPosition();
688 } 688 }
@@ -1332,11 +1332,11 @@ namespace OpenSim.Region.Framework.Scenes
1332 if (volume < 0) 1332 if (volume < 0)
1333 volume = 0; 1333 volume = 0;
1334 1334
1335 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars(); 1335 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
1336 foreach (ScenePresence p in avatarts)
1337 { 1336 {
1338 p.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume); 1337 if(!sp.IsChildAgent)
1339 } 1338 sp.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume);
1339 });
1340 } 1340 }
1341 1341
1342 /// <summary> 1342 /// <summary>
@@ -2626,12 +2626,13 @@ namespace OpenSim.Region.Framework.Scenes
2626 TaskInventory.LockItemsForRead(false); 2626 TaskInventory.LockItemsForRead(false);
2627 } 2627 }
2628 2628
2629 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars(); 2629 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
2630 foreach (ScenePresence p in avatarts)
2631 { 2630 {
2632 if (!(Util.GetDistanceTo(p.AbsolutePosition, AbsolutePosition) >= 100)) 2631 if (sp.IsChildAgent)
2633 p.ControllingClient.SendPreLoadSound(objectID, objectID, soundID); 2632 return;
2634 } 2633 if (!(Util.GetDistanceTo(sp.AbsolutePosition, AbsolutePosition) >= 100))
2634 sp.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
2635 });
2635 } 2636 }
2636 2637
2637 public void RemFlag(PrimFlags flag) 2638 public void RemFlag(PrimFlags flag)
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 1e530e1..5c54616 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -2598,35 +2598,33 @@ Console.WriteLine("Scripted Sit ofset {0}", m_pos);
2598 2598
2599 List<Vector3> CoarseLocations = new List<Vector3>(); 2599 List<Vector3> CoarseLocations = new List<Vector3>();
2600 List<UUID> AvatarUUIDs = new List<UUID>(); 2600 List<UUID> AvatarUUIDs = new List<UUID>();
2601 List<ScenePresence> avatars = m_scene.GetAvatars(); 2601 m_scene.ForEachScenePresence(delegate(ScenePresence sp)
2602 for (int i = 0; i < avatars.Count; i++)
2603 { 2602 {
2604 // Requested by LibOMV. Send Course Location on self. 2603 if (sp.IsChildAgent)
2605 //if (avatars[i] != this) 2604 return;
2606 //{ 2605
2607 if (avatars[i].ParentID != 0) 2606 if (sp.ParentID != 0)
2607 {
2608 // sitting avatar
2609 SceneObjectPart sop = m_scene.GetSceneObjectPart(sp.ParentID);
2610 if (sop != null)
2608 { 2611 {
2609 // sitting avatar 2612 CoarseLocations.Add(sop.AbsolutePosition + sp.m_pos);
2610 SceneObjectPart sop = m_scene.GetSceneObjectPart(avatars[i].ParentID); 2613 AvatarUUIDs.Add(sp.UUID);
2611 if (sop != null)
2612 {
2613 CoarseLocations.Add(sop.AbsolutePosition + avatars[i].m_pos);
2614 AvatarUUIDs.Add(avatars[i].UUID);
2615 }
2616 else
2617 {
2618 // we can't find the parent.. ! arg!
2619 CoarseLocations.Add(avatars[i].m_pos);
2620 AvatarUUIDs.Add(avatars[i].UUID);
2621 }
2622 } 2614 }
2623 else 2615 else
2624 { 2616 {
2625 CoarseLocations.Add(avatars[i].m_pos); 2617 // we can't find the parent.. ! arg!
2626 AvatarUUIDs.Add(avatars[i].UUID); 2618 CoarseLocations.Add(sp.m_pos);
2619 AvatarUUIDs.Add(sp.UUID);
2627 } 2620 }
2628 //} 2621 }
2629 } 2622 else
2623 {
2624 CoarseLocations.Add(sp.m_pos);
2625 AvatarUUIDs.Add(sp.UUID);
2626 }
2627 });
2630 2628
2631 m_controllingClient.SendCoarseLocationUpdate(AvatarUUIDs, CoarseLocations); 2629 m_controllingClient.SendCoarseLocationUpdate(AvatarUUIDs, CoarseLocations);
2632 2630
@@ -2700,13 +2698,15 @@ Console.WriteLine("Scripted Sit ofset {0}", m_pos);
2700 m_perfMonMS = Util.EnvironmentTickCount(); 2698 m_perfMonMS = Util.EnvironmentTickCount();
2701 2699
2702 // only send update from root agents to other clients; children are only "listening posts" 2700 // only send update from root agents to other clients; children are only "listening posts"
2703 List<ScenePresence> avatars = m_scene.GetAvatars(); 2701 int count = 0;
2704 foreach (ScenePresence avatar in avatars) 2702 m_scene.ForEachScenePresence(delegate(ScenePresence sp)
2705 { 2703 {
2706 SendFullUpdateToOtherClient(avatar); 2704 if (sp.IsChildAgent)
2707 2705 return;
2708 } 2706 SendFullUpdateToOtherClient(sp);
2709 m_scene.StatsReporter.AddAgentUpdates(avatars.Count); 2707 ++count;
2708 });
2709 m_scene.StatsReporter.AddAgentUpdates(count);
2710 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2710 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2711 2711
2712 Animator.SendAnimPack(); 2712 Animator.SendAnimPack();
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
index 840039c..dd9f8f6 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
@@ -66,7 +66,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
66 throw new NotImplementedException(); 66 throw new NotImplementedException();
67 } 67 }
68 68
69 public override bool TryGetAvatar(UUID agentID, out ScenePresence scenePresence) 69 public override bool TryGetScenePresence(UUID agentID, out ScenePresence scenePresence)
70 { 70 {
71 throw new NotImplementedException(); 71 throw new NotImplementedException();
72 } 72 }