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.cs224
1 files changed, 168 insertions, 56 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index af95c28..c16038c 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
@@ -130,13 +139,18 @@ namespace OpenSim.Region.Framework.Scenes
130 139
131 protected internal void Close() 140 protected internal void Close()
132 { 141 {
133 lock (m_presenceLock) 142 m_scenePresencesLock.EnterWriteLock();
143 try
134 { 144 {
135 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(); 145 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>();
136 List<ScenePresence> newlist = new List<ScenePresence>(); 146 List<ScenePresence> newlist = new List<ScenePresence>();
137 m_scenePresenceMap = newmap; 147 m_scenePresenceMap = newmap;
138 m_scenePresenceArray = newlist; 148 m_scenePresenceArray = newlist;
139 } 149 }
150 finally
151 {
152 m_scenePresencesLock.ExitWriteLock();
153 }
140 154
141 lock (SceneObjectGroupsByFullID) 155 lock (SceneObjectGroupsByFullID)
142 SceneObjectGroupsByFullID.Clear(); 156 SceneObjectGroupsByFullID.Clear();
@@ -275,6 +289,33 @@ namespace OpenSim.Region.Framework.Scenes
275 protected internal bool AddRestoredSceneObject( 289 protected internal bool AddRestoredSceneObject(
276 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 290 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
277 { 291 {
292 if (!m_parentScene.CombineRegions)
293 {
294 // KF: Check for out-of-region, move inside and make static.
295 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
296 sceneObject.RootPart.GroupPosition.Y,
297 sceneObject.RootPart.GroupPosition.Z);
298 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 ||
299 npos.X > Constants.RegionSize ||
300 npos.Y > Constants.RegionSize))
301 {
302 if (npos.X < 0.0) npos.X = 1.0f;
303 if (npos.Y < 0.0) npos.Y = 1.0f;
304 if (npos.Z < 0.0) npos.Z = 0.0f;
305 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
306 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
307
308 foreach (SceneObjectPart part in sceneObject.Parts)
309 {
310 part.GroupPosition = npos;
311 }
312 sceneObject.RootPart.Velocity = Vector3.Zero;
313 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
314 sceneObject.RootPart.Acceleration = Vector3.Zero;
315 sceneObject.RootPart.Velocity = Vector3.Zero;
316 }
317 }
318
278 if (attachToBackup && (!alreadyPersisted)) 319 if (attachToBackup && (!alreadyPersisted))
279 { 320 {
280 sceneObject.ForceInventoryPersistence(); 321 sceneObject.ForceInventoryPersistence();
@@ -492,6 +533,30 @@ namespace OpenSim.Region.Framework.Scenes
492 m_updateList[obj.UUID] = obj; 533 m_updateList[obj.UUID] = obj;
493 } 534 }
494 535
536 public void FireAttachToBackup(SceneObjectGroup obj)
537 {
538 if (OnAttachToBackup != null)
539 {
540 OnAttachToBackup(obj);
541 }
542 }
543
544 public void FireDetachFromBackup(SceneObjectGroup obj)
545 {
546 if (OnDetachFromBackup != null)
547 {
548 OnDetachFromBackup(obj);
549 }
550 }
551
552 public void FireChangeBackup(SceneObjectGroup obj)
553 {
554 if (OnChangeBackup != null)
555 {
556 OnChangeBackup(obj);
557 }
558 }
559
495 /// <summary> 560 /// <summary>
496 /// Process all pending updates 561 /// Process all pending updates
497 /// </summary> 562 /// </summary>
@@ -623,7 +688,8 @@ namespace OpenSim.Region.Framework.Scenes
623 688
624 Entities[presence.UUID] = presence; 689 Entities[presence.UUID] = presence;
625 690
626 lock (m_presenceLock) 691 m_scenePresencesLock.EnterWriteLock();
692 try
627 { 693 {
628 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 694 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
629 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 695 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -647,6 +713,10 @@ namespace OpenSim.Region.Framework.Scenes
647 m_scenePresenceMap = newmap; 713 m_scenePresenceMap = newmap;
648 m_scenePresenceArray = newlist; 714 m_scenePresenceArray = newlist;
649 } 715 }
716 finally
717 {
718 m_scenePresencesLock.ExitWriteLock();
719 }
650 } 720 }
651 721
652 /// <summary> 722 /// <summary>
@@ -661,7 +731,8 @@ namespace OpenSim.Region.Framework.Scenes
661 agentID); 731 agentID);
662 } 732 }
663 733
664 lock (m_presenceLock) 734 m_scenePresencesLock.EnterWriteLock();
735 try
665 { 736 {
666 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 737 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
667 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 738 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -683,6 +754,10 @@ namespace OpenSim.Region.Framework.Scenes
683 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); 754 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
684 } 755 }
685 } 756 }
757 finally
758 {
759 m_scenePresencesLock.ExitWriteLock();
760 }
686 } 761 }
687 762
688 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) 763 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
@@ -1396,8 +1471,13 @@ namespace OpenSim.Region.Framework.Scenes
1396 { 1471 {
1397 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0)) 1472 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0))
1398 { 1473 {
1399 if (m_parentScene.AttachmentsModule != null) 1474 // Set the new attachment point data in the object
1400 m_parentScene.AttachmentsModule.UpdateAttachmentPosition(group, pos); 1475 byte attachmentPoint = group.GetAttachmentPoint();
1476 group.UpdateGroupPosition(pos);
1477 group.IsAttachment = false;
1478 group.AbsolutePosition = group.RootPart.AttachedPos;
1479 group.AttachmentPoint = attachmentPoint;
1480 group.HasGroupChanged = true;
1401 } 1481 }
1402 else 1482 else
1403 { 1483 {
@@ -1669,8 +1749,11 @@ namespace OpenSim.Region.Framework.Scenes
1669 return; 1749 return;
1670 1750
1671 Monitor.Enter(m_updateLock); 1751 Monitor.Enter(m_updateLock);
1752
1672 try 1753 try
1673 { 1754 {
1755 parentGroup.areUpdatesSuspended = true;
1756
1674 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>(); 1757 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>();
1675 1758
1676 // We do this in reverse to get the link order of the prims correct 1759 // We do this in reverse to get the link order of the prims correct
@@ -1681,9 +1764,13 @@ namespace OpenSim.Region.Framework.Scenes
1681 // Make sure no child prim is set for sale 1764 // Make sure no child prim is set for sale
1682 // So that, on delink, no prims are unwittingly 1765 // So that, on delink, no prims are unwittingly
1683 // left for sale and sold off 1766 // left for sale and sold off
1684 child.RootPart.ObjectSaleType = 0; 1767
1685 child.RootPart.SalePrice = 10; 1768 if (child != null)
1686 childGroups.Add(child); 1769 {
1770 child.RootPart.ObjectSaleType = 0;
1771 child.RootPart.SalePrice = 10;
1772 childGroups.Add(child);
1773 }
1687 } 1774 }
1688 1775
1689 foreach (SceneObjectGroup child in childGroups) 1776 foreach (SceneObjectGroup child in childGroups)
@@ -1702,12 +1789,19 @@ namespace OpenSim.Region.Framework.Scenes
1702 // occur on link to invoke this elsewhere (such as object selection) 1789 // occur on link to invoke this elsewhere (such as object selection)
1703 parentGroup.RootPart.CreateSelected = true; 1790 parentGroup.RootPart.CreateSelected = true;
1704 parentGroup.TriggerScriptChangedEvent(Changed.LINK); 1791 parentGroup.TriggerScriptChangedEvent(Changed.LINK);
1705 parentGroup.HasGroupChanged = true;
1706 parentGroup.ScheduleGroupForFullUpdate();
1707
1708 } 1792 }
1709 finally 1793 finally
1710 { 1794 {
1795 lock (SceneObjectGroupsByLocalPartID)
1796 {
1797 foreach (SceneObjectPart part in parentGroup.Parts)
1798 SceneObjectGroupsByLocalPartID[part.LocalId] = parentGroup;
1799 }
1800
1801 parentGroup.areUpdatesSuspended = false;
1802 parentGroup.HasGroupChanged = true;
1803 parentGroup.ProcessBackup(m_parentScene.SimulationDataService, true);
1804 parentGroup.ScheduleGroupForFullUpdate();
1711 Monitor.Exit(m_updateLock); 1805 Monitor.Exit(m_updateLock);
1712 } 1806 }
1713 } 1807 }
@@ -1744,21 +1838,24 @@ namespace OpenSim.Region.Framework.Scenes
1744 1838
1745 SceneObjectGroup group = part.ParentGroup; 1839 SceneObjectGroup group = part.ParentGroup;
1746 if (!affectedGroups.Contains(group)) 1840 if (!affectedGroups.Contains(group))
1841 {
1842 group.areUpdatesSuspended = true;
1747 affectedGroups.Add(group); 1843 affectedGroups.Add(group);
1844 }
1748 } 1845 }
1749 } 1846 }
1750 } 1847 }
1751 1848
1752 foreach (SceneObjectPart child in childParts) 1849 if (childParts.Count > 0)
1753 { 1850 {
1754 // Unlink all child parts from their groups 1851 foreach (SceneObjectPart child in childParts)
1755 // 1852 {
1756 child.ParentGroup.DelinkFromGroup(child, true); 1853 // Unlink all child parts from their groups
1757 1854 //
1758 // These are not in affected groups and will not be 1855 child.ParentGroup.DelinkFromGroup(child, true);
1759 // handled further. Do the honors here. 1856 child.ParentGroup.HasGroupChanged = true;
1760 child.ParentGroup.HasGroupChanged = true; 1857 child.ParentGroup.ScheduleGroupForFullUpdate();
1761 child.ParentGroup.ScheduleGroupForFullUpdate(); 1858 }
1762 } 1859 }
1763 1860
1764 foreach (SceneObjectPart root in rootParts) 1861 foreach (SceneObjectPart root in rootParts)
@@ -1768,56 +1865,68 @@ namespace OpenSim.Region.Framework.Scenes
1768 // However, editing linked parts and unlinking may be different 1865 // However, editing linked parts and unlinking may be different
1769 // 1866 //
1770 SceneObjectGroup group = root.ParentGroup; 1867 SceneObjectGroup group = root.ParentGroup;
1868 group.areUpdatesSuspended = true;
1771 1869
1772 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts); 1870 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts);
1773 int numChildren = newSet.Count; 1871 int numChildren = newSet.Count;
1774 1872
1873 if (numChildren == 1)
1874 break;
1875
1775 // If there are prims left in a link set, but the root is 1876 // If there are prims left in a link set, but the root is
1776 // slated for unlink, we need to do this 1877 // slated for unlink, we need to do this
1878 // Unlink the remaining set
1777 // 1879 //
1778 if (numChildren != 1) 1880 bool sendEventsToRemainder = true;
1779 { 1881 if (numChildren > 1)
1780 // Unlink the remaining set 1882 sendEventsToRemainder = false;
1781 //
1782 bool sendEventsToRemainder = true;
1783 if (numChildren > 1)
1784 sendEventsToRemainder = false;
1785 1883
1786 foreach (SceneObjectPart p in newSet) 1884 foreach (SceneObjectPart p in newSet)
1885 {
1886 if (p != group.RootPart)
1787 { 1887 {
1788 if (p != group.RootPart) 1888 group.DelinkFromGroup(p, sendEventsToRemainder);
1789 group.DelinkFromGroup(p, sendEventsToRemainder); 1889 if (numChildren > 2)
1890 {
1891 p.ParentGroup.areUpdatesSuspended = true;
1892 }
1893 else
1894 {
1895 p.ParentGroup.HasGroupChanged = true;
1896 p.ParentGroup.ScheduleGroupForFullUpdate();
1897 }
1790 } 1898 }
1899 }
1900
1901 // If there is more than one prim remaining, we
1902 // need to re-link
1903 //
1904 if (numChildren > 2)
1905 {
1906 // Remove old root
1907 //
1908 if (newSet.Contains(root))
1909 newSet.Remove(root);
1791 1910
1792 // If there is more than one prim remaining, we 1911 // Preserve link ordering
1793 // need to re-link
1794 // 1912 //
1795 if (numChildren > 2) 1913 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1796 { 1914 {
1797 // Remove old root 1915 return a.LinkNum.CompareTo(b.LinkNum);
1798 // 1916 });
1799 if (newSet.Contains(root))
1800 newSet.Remove(root);
1801
1802 // Preserve link ordering
1803 //
1804 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1805 {
1806 return a.LinkNum.CompareTo(b.LinkNum);
1807 });
1808 1917
1809 // Determine new root 1918 // Determine new root
1810 // 1919 //
1811 SceneObjectPart newRoot = newSet[0]; 1920 SceneObjectPart newRoot = newSet[0];
1812 newSet.RemoveAt(0); 1921 newSet.RemoveAt(0);
1813 1922
1814 foreach (SceneObjectPart newChild in newSet) 1923 foreach (SceneObjectPart newChild in newSet)
1815 newChild.ClearUpdateSchedule(); 1924 newChild.ClearUpdateSchedule();
1816 1925
1817 LinkObjects(newRoot, newSet); 1926 newRoot.ParentGroup.areUpdatesSuspended = true;
1818 if (!affectedGroups.Contains(newRoot.ParentGroup)) 1927 LinkObjects(newRoot, newSet);
1819 affectedGroups.Add(newRoot.ParentGroup); 1928 if (!affectedGroups.Contains(newRoot.ParentGroup))
1820 } 1929 affectedGroups.Add(newRoot.ParentGroup);
1821 } 1930 }
1822 } 1931 }
1823 1932
@@ -1825,8 +1934,14 @@ namespace OpenSim.Region.Framework.Scenes
1825 // 1934 //
1826 foreach (SceneObjectGroup g in affectedGroups) 1935 foreach (SceneObjectGroup g in affectedGroups)
1827 { 1936 {
1937 // Child prims that have been unlinked and deleted will
1938 // return unless the root is deleted. This will remove them
1939 // from the database. They will be rewritten immediately,
1940 // minus the rows for the unlinked child prims.
1941 m_parentScene.SimulationDataService.RemoveObject(g.UUID, m_parentScene.RegionInfo.RegionID);
1828 g.TriggerScriptChangedEvent(Changed.LINK); 1942 g.TriggerScriptChangedEvent(Changed.LINK);
1829 g.HasGroupChanged = true; // Persist 1943 g.HasGroupChanged = true; // Persist
1944 g.areUpdatesSuspended = false;
1830 g.ScheduleGroupForFullUpdate(); 1945 g.ScheduleGroupForFullUpdate();
1831 } 1946 }
1832 } 1947 }
@@ -1944,9 +2059,6 @@ namespace OpenSim.Region.Framework.Scenes
1944 child.ApplyNextOwnerPermissions(); 2059 child.ApplyNextOwnerPermissions();
1945 } 2060 }
1946 } 2061 }
1947
1948 copy.RootPart.ObjectSaleType = 0;
1949 copy.RootPart.SalePrice = 10;
1950 } 2062 }
1951 2063
1952 // FIXME: This section needs to be refactored so that it just calls AddSceneObject() 2064 // FIXME: This section needs to be refactored so that it just calls AddSceneObject()