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.cs230
1 files changed, 167 insertions, 63 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index a2ed54f..7eebb99 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();
@@ -259,6 +273,33 @@ namespace OpenSim.Region.Framework.Scenes
259 protected internal bool AddRestoredSceneObject( 273 protected internal bool AddRestoredSceneObject(
260 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 274 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
261 { 275 {
276 if (!m_parentScene.CombineRegions)
277 {
278 // KF: Check for out-of-region, move inside and make static.
279 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
280 sceneObject.RootPart.GroupPosition.Y,
281 sceneObject.RootPart.GroupPosition.Z);
282 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 ||
283 npos.X > Constants.RegionSize ||
284 npos.Y > Constants.RegionSize))
285 {
286 if (npos.X < 0.0) npos.X = 1.0f;
287 if (npos.Y < 0.0) npos.Y = 1.0f;
288 if (npos.Z < 0.0) npos.Z = 0.0f;
289 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
290 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
291
292 foreach (SceneObjectPart part in sceneObject.Parts)
293 {
294 part.GroupPosition = npos;
295 }
296 sceneObject.RootPart.Velocity = Vector3.Zero;
297 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
298 sceneObject.RootPart.Acceleration = Vector3.Zero;
299 sceneObject.RootPart.Velocity = Vector3.Zero;
300 }
301 }
302
262 if (attachToBackup && (!alreadyPersisted)) 303 if (attachToBackup && (!alreadyPersisted))
263 { 304 {
264 sceneObject.ForceInventoryPersistence(); 305 sceneObject.ForceInventoryPersistence();
@@ -458,6 +499,30 @@ namespace OpenSim.Region.Framework.Scenes
458 m_updateList[obj.UUID] = obj; 499 m_updateList[obj.UUID] = obj;
459 } 500 }
460 501
502 public void FireAttachToBackup(SceneObjectGroup obj)
503 {
504 if (OnAttachToBackup != null)
505 {
506 OnAttachToBackup(obj);
507 }
508 }
509
510 public void FireDetachFromBackup(SceneObjectGroup obj)
511 {
512 if (OnDetachFromBackup != null)
513 {
514 OnDetachFromBackup(obj);
515 }
516 }
517
518 public void FireChangeBackup(SceneObjectGroup obj)
519 {
520 if (OnChangeBackup != null)
521 {
522 OnChangeBackup(obj);
523 }
524 }
525
461 /// <summary> 526 /// <summary>
462 /// Process all pending updates 527 /// Process all pending updates
463 /// </summary> 528 /// </summary>
@@ -592,7 +657,8 @@ namespace OpenSim.Region.Framework.Scenes
592 657
593 Entities[presence.UUID] = presence; 658 Entities[presence.UUID] = presence;
594 659
595 lock (m_presenceLock) 660 m_scenePresencesLock.EnterWriteLock();
661 try
596 { 662 {
597 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 663 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
598 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 664 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -616,6 +682,10 @@ namespace OpenSim.Region.Framework.Scenes
616 m_scenePresenceMap = newmap; 682 m_scenePresenceMap = newmap;
617 m_scenePresenceArray = newlist; 683 m_scenePresenceArray = newlist;
618 } 684 }
685 finally
686 {
687 m_scenePresencesLock.ExitWriteLock();
688 }
619 } 689 }
620 690
621 /// <summary> 691 /// <summary>
@@ -630,7 +700,8 @@ namespace OpenSim.Region.Framework.Scenes
630 agentID); 700 agentID);
631 } 701 }
632 702
633 lock (m_presenceLock) 703 m_scenePresencesLock.EnterWriteLock();
704 try
634 { 705 {
635 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 706 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
636 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 707 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -652,6 +723,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); 723 m_log.WarnFormat("[SCENE]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
653 } 724 }
654 } 725 }
726 finally
727 {
728 m_scenePresencesLock.ExitWriteLock();
729 }
655 } 730 }
656 731
657 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) 732 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
@@ -775,6 +850,11 @@ namespace OpenSim.Region.Framework.Scenes
775 return m_scenePresenceArray; 850 return m_scenePresenceArray;
776 } 851 }
777 852
853 public int GetNumberOfScenePresences()
854 {
855 return m_scenePresenceArray.Count;
856 }
857
778 /// <summary> 858 /// <summary>
779 /// Request a scene presence by UUID. Fast, indexed lookup. 859 /// Request a scene presence by UUID. Fast, indexed lookup.
780 /// </summary> 860 /// </summary>
@@ -1068,9 +1148,11 @@ namespace OpenSim.Region.Framework.Scenes
1068 /// <param name="action"></param> 1148 /// <param name="action"></param>
1069 protected internal void ForEachSOG(Action<SceneObjectGroup> action) 1149 protected internal void ForEachSOG(Action<SceneObjectGroup> action)
1070 { 1150 {
1071 List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values); 1151 EntityBase[] objlist = Entities.GetAllByType<SceneObjectGroup>();
1072 foreach (SceneObjectGroup obj in objlist) 1152 foreach (EntityBase ent in objlist)
1073 { 1153 {
1154 SceneObjectGroup obj = (SceneObjectGroup)ent;
1155
1074 try 1156 try
1075 { 1157 {
1076 action(obj); 1158 action(obj);
@@ -1281,8 +1363,13 @@ namespace OpenSim.Region.Framework.Scenes
1281 { 1363 {
1282 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0)) 1364 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0))
1283 { 1365 {
1284 if (m_parentScene.AttachmentsModule != null) 1366 // Set the new attachment point data in the object
1285 m_parentScene.AttachmentsModule.UpdateAttachmentPosition(group, pos); 1367 byte attachmentPoint = group.GetAttachmentPoint();
1368 group.UpdateGroupPosition(pos);
1369 group.RootPart.IsAttachment = false;
1370 group.AbsolutePosition = group.RootPart.AttachedPos;
1371 group.SetAttachmentPoint(attachmentPoint);
1372 group.HasGroupChanged = true;
1286 } 1373 }
1287 else 1374 else
1288 { 1375 {
@@ -1526,10 +1613,13 @@ namespace OpenSim.Region.Framework.Scenes
1526 /// <param name="childPrims"></param> 1613 /// <param name="childPrims"></param>
1527 protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children) 1614 protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children)
1528 { 1615 {
1616 SceneObjectGroup parentGroup = root.ParentGroup;
1617 if (parentGroup == null) return;
1529 Monitor.Enter(m_updateLock); 1618 Monitor.Enter(m_updateLock);
1619
1530 try 1620 try
1531 { 1621 {
1532 SceneObjectGroup parentGroup = root.ParentGroup; 1622 parentGroup.areUpdatesSuspended = true;
1533 1623
1534 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>(); 1624 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>();
1535 if (parentGroup != null) 1625 if (parentGroup != null)
@@ -1541,11 +1631,6 @@ namespace OpenSim.Region.Framework.Scenes
1541 1631
1542 if (child != null) 1632 if (child != null)
1543 { 1633 {
1544 // Make sure no child prim is set for sale
1545 // So that, on delink, no prims are unwittingly
1546 // left for sale and sold off
1547 child.RootPart.ObjectSaleType = 0;
1548 child.RootPart.SalePrice = 10;
1549 childGroups.Add(child); 1634 childGroups.Add(child);
1550 } 1635 }
1551 } 1636 }
@@ -1568,12 +1653,13 @@ namespace OpenSim.Region.Framework.Scenes
1568 // occur on link to invoke this elsewhere (such as object selection) 1653 // occur on link to invoke this elsewhere (such as object selection)
1569 parentGroup.RootPart.CreateSelected = true; 1654 parentGroup.RootPart.CreateSelected = true;
1570 parentGroup.TriggerScriptChangedEvent(Changed.LINK); 1655 parentGroup.TriggerScriptChangedEvent(Changed.LINK);
1571 parentGroup.HasGroupChanged = true;
1572 parentGroup.ScheduleGroupForFullUpdate();
1573
1574 } 1656 }
1575 finally 1657 finally
1576 { 1658 {
1659 parentGroup.areUpdatesSuspended = false;
1660 parentGroup.HasGroupChanged = true;
1661 parentGroup.ProcessBackup(m_parentScene.SimulationDataService, true);
1662 parentGroup.ScheduleGroupForFullUpdate();
1577 Monitor.Exit(m_updateLock); 1663 Monitor.Exit(m_updateLock);
1578 } 1664 }
1579 } 1665 }
@@ -1605,21 +1691,24 @@ namespace OpenSim.Region.Framework.Scenes
1605 1691
1606 SceneObjectGroup group = part.ParentGroup; 1692 SceneObjectGroup group = part.ParentGroup;
1607 if (!affectedGroups.Contains(group)) 1693 if (!affectedGroups.Contains(group))
1694 {
1695 group.areUpdatesSuspended = true;
1608 affectedGroups.Add(group); 1696 affectedGroups.Add(group);
1697 }
1609 } 1698 }
1610 } 1699 }
1611 } 1700 }
1612 1701
1613 foreach (SceneObjectPart child in childParts) 1702 if (childParts.Count > 0)
1614 { 1703 {
1615 // Unlink all child parts from their groups 1704 foreach (SceneObjectPart child in childParts)
1616 // 1705 {
1617 child.ParentGroup.DelinkFromGroup(child, true); 1706 // Unlink all child parts from their groups
1618 1707 //
1619 // These are not in affected groups and will not be 1708 child.ParentGroup.DelinkFromGroup(child, true);
1620 // handled further. Do the honors here. 1709 child.ParentGroup.HasGroupChanged = true;
1621 child.ParentGroup.HasGroupChanged = true; 1710 child.ParentGroup.ScheduleGroupForFullUpdate();
1622 child.ParentGroup.ScheduleGroupForFullUpdate(); 1711 }
1623 } 1712 }
1624 1713
1625 foreach (SceneObjectPart root in rootParts) 1714 foreach (SceneObjectPart root in rootParts)
@@ -1629,56 +1718,68 @@ namespace OpenSim.Region.Framework.Scenes
1629 // However, editing linked parts and unlinking may be different 1718 // However, editing linked parts and unlinking may be different
1630 // 1719 //
1631 SceneObjectGroup group = root.ParentGroup; 1720 SceneObjectGroup group = root.ParentGroup;
1721 group.areUpdatesSuspended = true;
1632 1722
1633 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts); 1723 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts);
1634 int numChildren = newSet.Count; 1724 int numChildren = newSet.Count;
1635 1725
1726 if (numChildren == 1)
1727 break;
1728
1636 // If there are prims left in a link set, but the root is 1729 // If there are prims left in a link set, but the root is
1637 // slated for unlink, we need to do this 1730 // slated for unlink, we need to do this
1731 // Unlink the remaining set
1638 // 1732 //
1639 if (numChildren != 1) 1733 bool sendEventsToRemainder = true;
1640 { 1734 if (numChildren > 1)
1641 // Unlink the remaining set 1735 sendEventsToRemainder = false;
1642 //
1643 bool sendEventsToRemainder = true;
1644 if (numChildren > 1)
1645 sendEventsToRemainder = false;
1646 1736
1647 foreach (SceneObjectPart p in newSet) 1737 foreach (SceneObjectPart p in newSet)
1738 {
1739 if (p != group.RootPart)
1648 { 1740 {
1649 if (p != group.RootPart) 1741 group.DelinkFromGroup(p, sendEventsToRemainder);
1650 group.DelinkFromGroup(p, sendEventsToRemainder); 1742 if (numChildren > 2)
1743 {
1744 p.ParentGroup.areUpdatesSuspended = true;
1745 }
1746 else
1747 {
1748 p.ParentGroup.HasGroupChanged = true;
1749 p.ParentGroup.ScheduleGroupForFullUpdate();
1750 }
1651 } 1751 }
1752 }
1753
1754 // If there is more than one prim remaining, we
1755 // need to re-link
1756 //
1757 if (numChildren > 2)
1758 {
1759 // Remove old root
1760 //
1761 if (newSet.Contains(root))
1762 newSet.Remove(root);
1652 1763
1653 // If there is more than one prim remaining, we 1764 // Preserve link ordering
1654 // need to re-link
1655 // 1765 //
1656 if (numChildren > 2) 1766 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1657 { 1767 {
1658 // Remove old root 1768 return a.LinkNum.CompareTo(b.LinkNum);
1659 // 1769 });
1660 if (newSet.Contains(root))
1661 newSet.Remove(root);
1662
1663 // Preserve link ordering
1664 //
1665 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1666 {
1667 return a.LinkNum.CompareTo(b.LinkNum);
1668 });
1669 1770
1670 // Determine new root 1771 // Determine new root
1671 // 1772 //
1672 SceneObjectPart newRoot = newSet[0]; 1773 SceneObjectPart newRoot = newSet[0];
1673 newSet.RemoveAt(0); 1774 newSet.RemoveAt(0);
1674 1775
1675 foreach (SceneObjectPart newChild in newSet) 1776 foreach (SceneObjectPart newChild in newSet)
1676 newChild.UpdateFlag = 0; 1777 newChild.UpdateFlag = 0;
1677 1778
1678 LinkObjects(newRoot, newSet); 1779 newRoot.ParentGroup.areUpdatesSuspended = true;
1679 if (!affectedGroups.Contains(newRoot.ParentGroup)) 1780 LinkObjects(newRoot, newSet);
1680 affectedGroups.Add(newRoot.ParentGroup); 1781 if (!affectedGroups.Contains(newRoot.ParentGroup))
1681 } 1782 affectedGroups.Add(newRoot.ParentGroup);
1682 } 1783 }
1683 } 1784 }
1684 1785
@@ -1686,8 +1787,14 @@ namespace OpenSim.Region.Framework.Scenes
1686 // 1787 //
1687 foreach (SceneObjectGroup g in affectedGroups) 1788 foreach (SceneObjectGroup g in affectedGroups)
1688 { 1789 {
1790 // Child prims that have been unlinked and deleted will
1791 // return unless the root is deleted. This will remove them
1792 // from the database. They will be rewritten immediately,
1793 // minus the rows for the unlinked child prims.
1794 m_parentScene.SimulationDataService.RemoveObject(g.UUID, m_parentScene.RegionInfo.RegionID);
1689 g.TriggerScriptChangedEvent(Changed.LINK); 1795 g.TriggerScriptChangedEvent(Changed.LINK);
1690 g.HasGroupChanged = true; // Persist 1796 g.HasGroupChanged = true; // Persist
1797 g.areUpdatesSuspended = false;
1691 g.ScheduleGroupForFullUpdate(); 1798 g.ScheduleGroupForFullUpdate();
1692 } 1799 }
1693 } 1800 }
@@ -1802,9 +1909,6 @@ namespace OpenSim.Region.Framework.Scenes
1802 child.ApplyNextOwnerPermissions(); 1909 child.ApplyNextOwnerPermissions();
1803 } 1910 }
1804 } 1911 }
1805
1806 copy.RootPart.ObjectSaleType = 0;
1807 copy.RootPart.SalePrice = 10;
1808 } 1912 }
1809 1913
1810 Entities.Add(copy); 1914 Entities.Add(copy);