aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SceneGraph.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneGraph.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs243
1 files changed, 161 insertions, 82 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index 032c859..b2d9358 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -43,6 +43,12 @@ namespace OpenSim.Region.Framework.Scenes
43 43
44 public delegate void ObjectDuplicateDelegate(EntityBase original, EntityBase clone); 44 public delegate void ObjectDuplicateDelegate(EntityBase original, EntityBase clone);
45 45
46 public delegate void AttachToBackupDelegate(SceneObjectGroup sog);
47
48 public delegate void DetachFromBackupDelegate(SceneObjectGroup sog);
49
50 public delegate void ChangedBackupDelegate(SceneObjectGroup sog);
51
46 public delegate void ObjectCreateDelegate(EntityBase obj); 52 public delegate void ObjectCreateDelegate(EntityBase obj);
47 53
48 public delegate void ObjectDeleteDelegate(EntityBase obj); 54 public delegate void ObjectDeleteDelegate(EntityBase obj);
@@ -61,6 +67,9 @@ namespace OpenSim.Region.Framework.Scenes
61 private PhysicsCrash handlerPhysicsCrash = null; 67 private PhysicsCrash handlerPhysicsCrash = null;
62 68
63 public event ObjectDuplicateDelegate OnObjectDuplicate; 69 public event ObjectDuplicateDelegate OnObjectDuplicate;
70 public event AttachToBackupDelegate OnAttachToBackup;
71 public event DetachFromBackupDelegate OnDetachFromBackup;
72 public event ChangedBackupDelegate OnChangeBackup;
64 public event ObjectCreateDelegate OnObjectCreate; 73 public event ObjectCreateDelegate OnObjectCreate;
65 public event ObjectDeleteDelegate OnObjectRemove; 74 public event ObjectDeleteDelegate OnObjectRemove;
66 75
@@ -68,7 +77,7 @@ namespace OpenSim.Region.Framework.Scenes
68 77
69 #region Fields 78 #region Fields
70 79
71 protected object m_presenceLock = new object(); 80 protected OpenMetaverse.ReaderWriterLockSlim m_scenePresencesLock = new OpenMetaverse.ReaderWriterLockSlim();
72 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>(); 81 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>();
73 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>(); 82 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>();
74 83
@@ -124,13 +133,18 @@ namespace OpenSim.Region.Framework.Scenes
124 133
125 protected internal void Close() 134 protected internal void Close()
126 { 135 {
127 lock (m_presenceLock) 136 m_scenePresencesLock.EnterWriteLock();
137 try
128 { 138 {
129 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(); 139 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>();
130 List<ScenePresence> newlist = new List<ScenePresence>(); 140 List<ScenePresence> newlist = new List<ScenePresence>();
131 m_scenePresenceMap = newmap; 141 m_scenePresenceMap = newmap;
132 m_scenePresenceArray = newlist; 142 m_scenePresenceArray = newlist;
133 } 143 }
144 finally
145 {
146 m_scenePresencesLock.ExitWriteLock();
147 }
134 148
135 lock (SceneObjectGroupsByFullID) 149 lock (SceneObjectGroupsByFullID)
136 SceneObjectGroupsByFullID.Clear(); 150 SceneObjectGroupsByFullID.Clear();
@@ -209,27 +223,8 @@ namespace OpenSim.Region.Framework.Scenes
209 if (sp.IsChildAgent) 223 if (sp.IsChildAgent)
210 return; 224 return;
211 225
212 if (sp.ParentID != 0) 226 coarseLocations.Add(sp.AbsolutePosition);
213 { 227 avatarUUIDs.Add(sp.UUID);
214 // sitting avatar
215 SceneObjectPart sop = m_parentScene.GetSceneObjectPart(sp.ParentID);
216 if (sop != null)
217 {
218 coarseLocations.Add(sop.AbsolutePosition + sp.AbsolutePosition);
219 avatarUUIDs.Add(sp.UUID);
220 }
221 else
222 {
223 // we can't find the parent.. ! arg!
224 coarseLocations.Add(sp.AbsolutePosition);
225 avatarUUIDs.Add(sp.UUID);
226 }
227 }
228 else
229 {
230 coarseLocations.Add(sp.AbsolutePosition);
231 avatarUUIDs.Add(sp.UUID);
232 }
233 } 228 }
234 } 229 }
235 230
@@ -259,6 +254,33 @@ namespace OpenSim.Region.Framework.Scenes
259 protected internal bool AddRestoredSceneObject( 254 protected internal bool AddRestoredSceneObject(
260 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 255 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
261 { 256 {
257 if (!m_parentScene.CombineRegions)
258 {
259 // KF: Check for out-of-region, move inside and make static.
260 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
261 sceneObject.RootPart.GroupPosition.Y,
262 sceneObject.RootPart.GroupPosition.Z);
263 if (!(((sceneObject.RootPart.Shape.PCode == (byte)PCode.Prim) && (sceneObject.RootPart.Shape.State != 0))) && (npos.X < 0.0 || npos.Y < 0.0 || npos.Z < 0.0 ||
264 npos.X > Constants.RegionSize ||
265 npos.Y > Constants.RegionSize))
266 {
267 if (npos.X < 0.0) npos.X = 1.0f;
268 if (npos.Y < 0.0) npos.Y = 1.0f;
269 if (npos.Z < 0.0) npos.Z = 0.0f;
270 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
271 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
272
273 foreach (SceneObjectPart part in sceneObject.Parts)
274 {
275 part.GroupPosition = npos;
276 }
277 sceneObject.RootPart.Velocity = Vector3.Zero;
278 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
279 sceneObject.RootPart.Acceleration = Vector3.Zero;
280 sceneObject.RootPart.Velocity = Vector3.Zero;
281 }
282 }
283
262 if (attachToBackup && (!alreadyPersisted)) 284 if (attachToBackup && (!alreadyPersisted))
263 { 285 {
264 sceneObject.ForceInventoryPersistence(); 286 sceneObject.ForceInventoryPersistence();
@@ -458,6 +480,30 @@ namespace OpenSim.Region.Framework.Scenes
458 m_updateList[obj.UUID] = obj; 480 m_updateList[obj.UUID] = obj;
459 } 481 }
460 482
483 public void FireAttachToBackup(SceneObjectGroup obj)
484 {
485 if (OnAttachToBackup != null)
486 {
487 OnAttachToBackup(obj);
488 }
489 }
490
491 public void FireDetachFromBackup(SceneObjectGroup obj)
492 {
493 if (OnDetachFromBackup != null)
494 {
495 OnDetachFromBackup(obj);
496 }
497 }
498
499 public void FireChangeBackup(SceneObjectGroup obj)
500 {
501 if (OnChangeBackup != null)
502 {
503 OnChangeBackup(obj);
504 }
505 }
506
461 /// <summary> 507 /// <summary>
462 /// Process all pending updates 508 /// Process all pending updates
463 /// </summary> 509 /// </summary>
@@ -592,7 +638,8 @@ namespace OpenSim.Region.Framework.Scenes
592 638
593 Entities[presence.UUID] = presence; 639 Entities[presence.UUID] = presence;
594 640
595 lock (m_presenceLock) 641 m_scenePresencesLock.EnterWriteLock();
642 try
596 { 643 {
597 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 644 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
598 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 645 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -616,6 +663,10 @@ namespace OpenSim.Region.Framework.Scenes
616 m_scenePresenceMap = newmap; 663 m_scenePresenceMap = newmap;
617 m_scenePresenceArray = newlist; 664 m_scenePresenceArray = newlist;
618 } 665 }
666 finally
667 {
668 m_scenePresencesLock.ExitWriteLock();
669 }
619 } 670 }
620 671
621 /// <summary> 672 /// <summary>
@@ -630,7 +681,8 @@ namespace OpenSim.Region.Framework.Scenes
630 agentID); 681 agentID);
631 } 682 }
632 683
633 lock (m_presenceLock) 684 m_scenePresencesLock.EnterWriteLock();
685 try
634 { 686 {
635 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 687 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
636 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 688 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -652,6 +704,10 @@ namespace OpenSim.Region.Framework.Scenes
652 m_log.WarnFormat("[SCENE]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); 704 m_log.WarnFormat("[SCENE]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
653 } 705 }
654 } 706 }
707 finally
708 {
709 m_scenePresencesLock.ExitWriteLock();
710 }
655 } 711 }
656 712
657 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) 713 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
@@ -775,6 +831,11 @@ namespace OpenSim.Region.Framework.Scenes
775 return m_scenePresenceArray; 831 return m_scenePresenceArray;
776 } 832 }
777 833
834 public int GetNumberOfScenePresences()
835 {
836 return m_scenePresenceArray.Count;
837 }
838
778 /// <summary> 839 /// <summary>
779 /// Request a scene presence by UUID. Fast, indexed lookup. 840 /// Request a scene presence by UUID. Fast, indexed lookup.
780 /// </summary> 841 /// </summary>
@@ -1068,9 +1129,11 @@ namespace OpenSim.Region.Framework.Scenes
1068 /// <param name="action"></param> 1129 /// <param name="action"></param>
1069 protected internal void ForEachSOG(Action<SceneObjectGroup> action) 1130 protected internal void ForEachSOG(Action<SceneObjectGroup> action)
1070 { 1131 {
1071 List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values); 1132 EntityBase[] objlist = Entities.GetAllByType<SceneObjectGroup>();
1072 foreach (SceneObjectGroup obj in objlist) 1133 foreach (EntityBase ent in objlist)
1073 { 1134 {
1135 SceneObjectGroup obj = (SceneObjectGroup)ent;
1136
1074 try 1137 try
1075 { 1138 {
1076 action(obj); 1139 action(obj);
@@ -1531,10 +1594,13 @@ namespace OpenSim.Region.Framework.Scenes
1531 /// <param name="childPrims"></param> 1594 /// <param name="childPrims"></param>
1532 protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children) 1595 protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children)
1533 { 1596 {
1597 SceneObjectGroup parentGroup = root.ParentGroup;
1598 if (parentGroup == null) return;
1534 Monitor.Enter(m_updateLock); 1599 Monitor.Enter(m_updateLock);
1600
1535 try 1601 try
1536 { 1602 {
1537 SceneObjectGroup parentGroup = root.ParentGroup; 1603 parentGroup.areUpdatesSuspended = true;
1538 1604
1539 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>(); 1605 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>();
1540 if (parentGroup != null) 1606 if (parentGroup != null)
@@ -1546,11 +1612,6 @@ namespace OpenSim.Region.Framework.Scenes
1546 1612
1547 if (child != null) 1613 if (child != null)
1548 { 1614 {
1549 // Make sure no child prim is set for sale
1550 // So that, on delink, no prims are unwittingly
1551 // left for sale and sold off
1552 child.RootPart.ObjectSaleType = 0;
1553 child.RootPart.SalePrice = 10;
1554 childGroups.Add(child); 1615 childGroups.Add(child);
1555 } 1616 }
1556 } 1617 }
@@ -1573,12 +1634,12 @@ namespace OpenSim.Region.Framework.Scenes
1573 // occur on link to invoke this elsewhere (such as object selection) 1634 // occur on link to invoke this elsewhere (such as object selection)
1574 parentGroup.RootPart.CreateSelected = true; 1635 parentGroup.RootPart.CreateSelected = true;
1575 parentGroup.TriggerScriptChangedEvent(Changed.LINK); 1636 parentGroup.TriggerScriptChangedEvent(Changed.LINK);
1576 parentGroup.HasGroupChanged = true;
1577 parentGroup.ScheduleGroupForFullUpdate();
1578
1579 } 1637 }
1580 finally 1638 finally
1581 { 1639 {
1640 parentGroup.areUpdatesSuspended = false;
1641 parentGroup.HasGroupChanged = true;
1642 parentGroup.ScheduleGroupForFullUpdate();
1582 Monitor.Exit(m_updateLock); 1643 Monitor.Exit(m_updateLock);
1583 } 1644 }
1584 } 1645 }
@@ -1610,21 +1671,24 @@ namespace OpenSim.Region.Framework.Scenes
1610 1671
1611 SceneObjectGroup group = part.ParentGroup; 1672 SceneObjectGroup group = part.ParentGroup;
1612 if (!affectedGroups.Contains(group)) 1673 if (!affectedGroups.Contains(group))
1674 {
1675 group.areUpdatesSuspended = true;
1613 affectedGroups.Add(group); 1676 affectedGroups.Add(group);
1677 }
1614 } 1678 }
1615 } 1679 }
1616 } 1680 }
1617 1681
1618 foreach (SceneObjectPart child in childParts) 1682 if (childParts.Count > 0)
1619 { 1683 {
1620 // Unlink all child parts from their groups 1684 foreach (SceneObjectPart child in childParts)
1621 // 1685 {
1622 child.ParentGroup.DelinkFromGroup(child, true); 1686 // Unlink all child parts from their groups
1623 1687 //
1624 // These are not in affected groups and will not be 1688 child.ParentGroup.DelinkFromGroup(child, true);
1625 // handled further. Do the honors here. 1689 child.ParentGroup.HasGroupChanged = true;
1626 child.ParentGroup.HasGroupChanged = true; 1690 child.ParentGroup.ScheduleGroupForFullUpdate();
1627 child.ParentGroup.ScheduleGroupForFullUpdate(); 1691 }
1628 } 1692 }
1629 1693
1630 foreach (SceneObjectPart root in rootParts) 1694 foreach (SceneObjectPart root in rootParts)
@@ -1634,56 +1698,68 @@ namespace OpenSim.Region.Framework.Scenes
1634 // However, editing linked parts and unlinking may be different 1698 // However, editing linked parts and unlinking may be different
1635 // 1699 //
1636 SceneObjectGroup group = root.ParentGroup; 1700 SceneObjectGroup group = root.ParentGroup;
1701 group.areUpdatesSuspended = true;
1637 1702
1638 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts); 1703 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts);
1639 int numChildren = newSet.Count; 1704 int numChildren = newSet.Count;
1640 1705
1706 if (numChildren == 1)
1707 break;
1708
1641 // If there are prims left in a link set, but the root is 1709 // If there are prims left in a link set, but the root is
1642 // slated for unlink, we need to do this 1710 // slated for unlink, we need to do this
1711 // Unlink the remaining set
1643 // 1712 //
1644 if (numChildren != 1) 1713 bool sendEventsToRemainder = true;
1645 { 1714 if (numChildren > 1)
1646 // Unlink the remaining set 1715 sendEventsToRemainder = false;
1647 //
1648 bool sendEventsToRemainder = true;
1649 if (numChildren > 1)
1650 sendEventsToRemainder = false;
1651 1716
1652 foreach (SceneObjectPart p in newSet) 1717 foreach (SceneObjectPart p in newSet)
1718 {
1719 if (p != group.RootPart)
1653 { 1720 {
1654 if (p != group.RootPart) 1721 group.DelinkFromGroup(p, sendEventsToRemainder);
1655 group.DelinkFromGroup(p, sendEventsToRemainder); 1722 if (numChildren > 2)
1723 {
1724 p.ParentGroup.areUpdatesSuspended = true;
1725 }
1726 else
1727 {
1728 p.ParentGroup.HasGroupChanged = true;
1729 p.ParentGroup.ScheduleGroupForFullUpdate();
1730 }
1656 } 1731 }
1732 }
1733
1734 // If there is more than one prim remaining, we
1735 // need to re-link
1736 //
1737 if (numChildren > 2)
1738 {
1739 // Remove old root
1740 //
1741 if (newSet.Contains(root))
1742 newSet.Remove(root);
1657 1743
1658 // If there is more than one prim remaining, we 1744 // Preserve link ordering
1659 // need to re-link
1660 // 1745 //
1661 if (numChildren > 2) 1746 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1662 { 1747 {
1663 // Remove old root 1748 return a.LinkNum.CompareTo(b.LinkNum);
1664 // 1749 });
1665 if (newSet.Contains(root))
1666 newSet.Remove(root);
1667
1668 // Preserve link ordering
1669 //
1670 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1671 {
1672 return a.LinkNum.CompareTo(b.LinkNum);
1673 });
1674 1750
1675 // Determine new root 1751 // Determine new root
1676 // 1752 //
1677 SceneObjectPart newRoot = newSet[0]; 1753 SceneObjectPart newRoot = newSet[0];
1678 newSet.RemoveAt(0); 1754 newSet.RemoveAt(0);
1679 1755
1680 foreach (SceneObjectPart newChild in newSet) 1756 foreach (SceneObjectPart newChild in newSet)
1681 newChild.UpdateFlag = 0; 1757 newChild.UpdateFlag = 0;
1682 1758
1683 LinkObjects(newRoot, newSet); 1759 newRoot.ParentGroup.areUpdatesSuspended = true;
1684 if (!affectedGroups.Contains(newRoot.ParentGroup)) 1760 LinkObjects(newRoot, newSet);
1685 affectedGroups.Add(newRoot.ParentGroup); 1761 if (!affectedGroups.Contains(newRoot.ParentGroup))
1686 } 1762 affectedGroups.Add(newRoot.ParentGroup);
1687 } 1763 }
1688 } 1764 }
1689 1765
@@ -1691,8 +1767,14 @@ namespace OpenSim.Region.Framework.Scenes
1691 // 1767 //
1692 foreach (SceneObjectGroup g in affectedGroups) 1768 foreach (SceneObjectGroup g in affectedGroups)
1693 { 1769 {
1770 // Child prims that have been unlinked and deleted will
1771 // return unless the root is deleted. This will remove them
1772 // from the database. They will be rewritten immediately,
1773 // minus the rows for the unlinked child prims.
1774 m_parentScene.SimulationDataService.RemoveObject(g.UUID, m_parentScene.RegionInfo.RegionID);
1694 g.TriggerScriptChangedEvent(Changed.LINK); 1775 g.TriggerScriptChangedEvent(Changed.LINK);
1695 g.HasGroupChanged = true; // Persist 1776 g.HasGroupChanged = true; // Persist
1777 g.areUpdatesSuspended = false;
1696 g.ScheduleGroupForFullUpdate(); 1778 g.ScheduleGroupForFullUpdate();
1697 } 1779 }
1698 } 1780 }
@@ -1807,9 +1889,6 @@ namespace OpenSim.Region.Framework.Scenes
1807 child.ApplyNextOwnerPermissions(); 1889 child.ApplyNextOwnerPermissions();
1808 } 1890 }
1809 } 1891 }
1810
1811 copy.RootPart.ObjectSaleType = 0;
1812 copy.RootPart.SalePrice = 10;
1813 } 1892 }
1814 1893
1815 Entities.Add(copy); 1894 Entities.Add(copy);