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.cs443
1 files changed, 308 insertions, 135 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index 0a5bfd2..b0f8991 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -41,6 +41,12 @@ namespace OpenSim.Region.Framework.Scenes
41{ 41{
42 public delegate void PhysicsCrash(); 42 public delegate void PhysicsCrash();
43 43
44 public delegate void AttachToBackupDelegate(SceneObjectGroup sog);
45
46 public delegate void DetachFromBackupDelegate(SceneObjectGroup sog);
47
48 public delegate void ChangedBackupDelegate(SceneObjectGroup sog);
49
44 /// <summary> 50 /// <summary>
45 /// This class used to be called InnerScene and may not yet truly be a SceneGraph. The non scene graph components 51 /// This class used to be called InnerScene and may not yet truly be a SceneGraph. The non scene graph components
46 /// should be migrated out over time. 52 /// should be migrated out over time.
@@ -54,11 +60,15 @@ namespace OpenSim.Region.Framework.Scenes
54 protected internal event PhysicsCrash UnRecoverableError; 60 protected internal event PhysicsCrash UnRecoverableError;
55 private PhysicsCrash handlerPhysicsCrash = null; 61 private PhysicsCrash handlerPhysicsCrash = null;
56 62
63 public event AttachToBackupDelegate OnAttachToBackup;
64 public event DetachFromBackupDelegate OnDetachFromBackup;
65 public event ChangedBackupDelegate OnChangeBackup;
66
57 #endregion 67 #endregion
58 68
59 #region Fields 69 #region Fields
60 70
61 protected object m_presenceLock = new object(); 71 protected OpenMetaverse.ReaderWriterLockSlim m_scenePresencesLock = new OpenMetaverse.ReaderWriterLockSlim();
62 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>(); 72 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>();
63 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>(); 73 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>();
64 74
@@ -127,13 +137,18 @@ namespace OpenSim.Region.Framework.Scenes
127 137
128 protected internal void Close() 138 protected internal void Close()
129 { 139 {
130 lock (m_presenceLock) 140 m_scenePresencesLock.EnterWriteLock();
141 try
131 { 142 {
132 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(); 143 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>();
133 List<ScenePresence> newlist = new List<ScenePresence>(); 144 List<ScenePresence> newlist = new List<ScenePresence>();
134 m_scenePresenceMap = newmap; 145 m_scenePresenceMap = newmap;
135 m_scenePresenceArray = newlist; 146 m_scenePresenceArray = newlist;
136 } 147 }
148 finally
149 {
150 m_scenePresencesLock.ExitWriteLock();
151 }
137 152
138 lock (SceneObjectGroupsByFullID) 153 lock (SceneObjectGroupsByFullID)
139 SceneObjectGroupsByFullID.Clear(); 154 SceneObjectGroupsByFullID.Clear();
@@ -254,6 +269,33 @@ namespace OpenSim.Region.Framework.Scenes
254 protected internal bool AddRestoredSceneObject( 269 protected internal bool AddRestoredSceneObject(
255 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 270 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
256 { 271 {
272 if (!m_parentScene.CombineRegions)
273 {
274 // KF: Check for out-of-region, move inside and make static.
275 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
276 sceneObject.RootPart.GroupPosition.Y,
277 sceneObject.RootPart.GroupPosition.Z);
278 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 ||
279 npos.X > Constants.RegionSize ||
280 npos.Y > Constants.RegionSize))
281 {
282 if (npos.X < 0.0) npos.X = 1.0f;
283 if (npos.Y < 0.0) npos.Y = 1.0f;
284 if (npos.Z < 0.0) npos.Z = 0.0f;
285 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
286 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
287
288 foreach (SceneObjectPart part in sceneObject.Parts)
289 {
290 part.GroupPosition = npos;
291 }
292 sceneObject.RootPart.Velocity = Vector3.Zero;
293 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
294 sceneObject.RootPart.Acceleration = Vector3.Zero;
295 sceneObject.RootPart.Velocity = Vector3.Zero;
296 }
297 }
298
257 if (attachToBackup && (!alreadyPersisted)) 299 if (attachToBackup && (!alreadyPersisted))
258 { 300 {
259 sceneObject.ForceInventoryPersistence(); 301 sceneObject.ForceInventoryPersistence();
@@ -317,9 +359,8 @@ namespace OpenSim.Region.Framework.Scenes
317 if (pa != null && pa.IsPhysical && vel != Vector3.Zero) 359 if (pa != null && pa.IsPhysical && vel != Vector3.Zero)
318 { 360 {
319 sceneObject.RootPart.ApplyImpulse((vel * sceneObject.GetMass()), false); 361 sceneObject.RootPart.ApplyImpulse((vel * sceneObject.GetMass()), false);
320 sceneObject.Velocity = vel;
321 } 362 }
322 363
323 return true; 364 return true;
324 } 365 }
325 366
@@ -344,6 +385,11 @@ namespace OpenSim.Region.Framework.Scenes
344 /// </returns> 385 /// </returns>
345 protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates) 386 protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
346 { 387 {
388 if (sceneObject == null)
389 {
390 m_log.ErrorFormat("[SCENEGRAPH]: Tried to add null scene object");
391 return false;
392 }
347 if (sceneObject.UUID == UUID.Zero) 393 if (sceneObject.UUID == UUID.Zero)
348 { 394 {
349 m_log.ErrorFormat( 395 m_log.ErrorFormat(
@@ -475,6 +521,30 @@ namespace OpenSim.Region.Framework.Scenes
475 m_updateList[obj.UUID] = obj; 521 m_updateList[obj.UUID] = obj;
476 } 522 }
477 523
524 public void FireAttachToBackup(SceneObjectGroup obj)
525 {
526 if (OnAttachToBackup != null)
527 {
528 OnAttachToBackup(obj);
529 }
530 }
531
532 public void FireDetachFromBackup(SceneObjectGroup obj)
533 {
534 if (OnDetachFromBackup != null)
535 {
536 OnDetachFromBackup(obj);
537 }
538 }
539
540 public void FireChangeBackup(SceneObjectGroup obj)
541 {
542 if (OnChangeBackup != null)
543 {
544 OnChangeBackup(obj);
545 }
546 }
547
478 /// <summary> 548 /// <summary>
479 /// Process all pending updates 549 /// Process all pending updates
480 /// </summary> 550 /// </summary>
@@ -519,12 +589,12 @@ namespace OpenSim.Region.Framework.Scenes
519 589
520 protected internal void AddPhysicalPrim(int number) 590 protected internal void AddPhysicalPrim(int number)
521 { 591 {
522 m_physicalPrim++; 592 m_physicalPrim += number;
523 } 593 }
524 594
525 protected internal void RemovePhysicalPrim(int number) 595 protected internal void RemovePhysicalPrim(int number)
526 { 596 {
527 m_physicalPrim--; 597 m_physicalPrim -= number;
528 } 598 }
529 599
530 protected internal void AddToScriptLPS(int number) 600 protected internal void AddToScriptLPS(int number)
@@ -566,7 +636,8 @@ namespace OpenSim.Region.Framework.Scenes
566 636
567 Entities[presence.UUID] = presence; 637 Entities[presence.UUID] = presence;
568 638
569 lock (m_presenceLock) 639 m_scenePresencesLock.EnterWriteLock();
640 try
570 { 641 {
571 m_numChildAgents++; 642 m_numChildAgents++;
572 643
@@ -592,6 +663,10 @@ namespace OpenSim.Region.Framework.Scenes
592 m_scenePresenceMap = newmap; 663 m_scenePresenceMap = newmap;
593 m_scenePresenceArray = newlist; 664 m_scenePresenceArray = newlist;
594 } 665 }
666 finally
667 {
668 m_scenePresencesLock.ExitWriteLock();
669 }
595 670
596 return presence; 671 return presence;
597 } 672 }
@@ -608,7 +683,8 @@ namespace OpenSim.Region.Framework.Scenes
608 agentID); 683 agentID);
609 } 684 }
610 685
611 lock (m_presenceLock) 686 m_scenePresencesLock.EnterWriteLock();
687 try
612 { 688 {
613 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 689 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
614 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 690 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -630,6 +706,10 @@ namespace OpenSim.Region.Framework.Scenes
630 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); 706 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
631 } 707 }
632 } 708 }
709 finally
710 {
711 m_scenePresencesLock.ExitWriteLock();
712 }
633 } 713 }
634 714
635 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) 715 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
@@ -1183,6 +1263,52 @@ namespace OpenSim.Region.Framework.Scenes
1183 1263
1184 #region Client Event handlers 1264 #region Client Event handlers
1185 1265
1266 protected internal void ClientChangeObject(uint localID, object odata, IClientAPI remoteClient)
1267 {
1268 SceneObjectPart part = GetSceneObjectPart(localID);
1269 ObjectChangeData data = (ObjectChangeData)odata;
1270
1271 if (part != null)
1272 {
1273 SceneObjectGroup grp = part.ParentGroup;
1274 if (grp != null)
1275 {
1276 if (m_parentScene.Permissions.CanEditObject(grp.UUID, remoteClient.AgentId))
1277 {
1278 // These two are exceptions SL makes in the interpretation
1279 // of the change flags. Must check them here because otherwise
1280 // the group flag (see below) would be lost
1281 if (data.change == ObjectChangeType.groupS)
1282 data.change = ObjectChangeType.primS;
1283 if (data.change == ObjectChangeType.groupPS)
1284 data.change = ObjectChangeType.primPS;
1285 part.StoreUndoState(data.change); // lets test only saving what we changed
1286 grp.doChangeObject(part, (ObjectChangeData)data);
1287 }
1288 else
1289 {
1290 // Is this any kind of group operation?
1291 if ((data.change & ObjectChangeType.Group) != 0)
1292 {
1293 // Is a move and/or rotation requested?
1294 if ((data.change & (ObjectChangeType.Position | ObjectChangeType.Rotation)) != 0)
1295 {
1296 // Are we allowed to move it?
1297 if (m_parentScene.Permissions.CanMoveObject(grp.UUID, remoteClient.AgentId))
1298 {
1299 // Strip all but move and rotation from request
1300 data.change &= (ObjectChangeType.Group | ObjectChangeType.Position | ObjectChangeType.Rotation);
1301
1302 part.StoreUndoState(data.change);
1303 grp.doChangeObject(part, (ObjectChangeData)data);
1304 }
1305 }
1306 }
1307 }
1308 }
1309 }
1310 }
1311
1186 /// <summary> 1312 /// <summary>
1187 /// Update the scale of an individual prim. 1313 /// Update the scale of an individual prim.
1188 /// </summary> 1314 /// </summary>
@@ -1197,7 +1323,17 @@ namespace OpenSim.Region.Framework.Scenes
1197 { 1323 {
1198 if (m_parentScene.Permissions.CanEditObject(part.ParentGroup.UUID, remoteClient.AgentId)) 1324 if (m_parentScene.Permissions.CanEditObject(part.ParentGroup.UUID, remoteClient.AgentId))
1199 { 1325 {
1326 bool physbuild = false;
1327 if (part.ParentGroup.RootPart.PhysActor != null)
1328 {
1329 part.ParentGroup.RootPart.PhysActor.Building = true;
1330 physbuild = true;
1331 }
1332
1200 part.Resize(scale); 1333 part.Resize(scale);
1334
1335 if (physbuild)
1336 part.ParentGroup.RootPart.PhysActor.Building = false;
1201 } 1337 }
1202 } 1338 }
1203 } 1339 }
@@ -1209,7 +1345,17 @@ namespace OpenSim.Region.Framework.Scenes
1209 { 1345 {
1210 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId)) 1346 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
1211 { 1347 {
1348 bool physbuild = false;
1349 if (group.RootPart.PhysActor != null)
1350 {
1351 group.RootPart.PhysActor.Building = true;
1352 physbuild = true;
1353 }
1354
1212 group.GroupResize(scale); 1355 group.GroupResize(scale);
1356
1357 if (physbuild)
1358 group.RootPart.PhysActor.Building = false;
1213 } 1359 }
1214 } 1360 }
1215 } 1361 }
@@ -1337,8 +1483,13 @@ namespace OpenSim.Region.Framework.Scenes
1337 { 1483 {
1338 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0)) 1484 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0))
1339 { 1485 {
1340 if (m_parentScene.AttachmentsModule != null) 1486 // Set the new attachment point data in the object
1341 m_parentScene.AttachmentsModule.UpdateAttachmentPosition(group, pos); 1487 byte attachmentPoint = group.GetAttachmentPoint();
1488 group.UpdateGroupPosition(pos);
1489 group.IsAttachment = false;
1490 group.AbsolutePosition = group.RootPart.AttachedPos;
1491 group.AttachmentPoint = attachmentPoint;
1492 group.HasGroupChanged = true;
1342 } 1493 }
1343 else 1494 else
1344 { 1495 {
@@ -1559,6 +1710,7 @@ namespace OpenSim.Region.Framework.Scenes
1559 { 1710 {
1560 part.Material = Convert.ToByte(material); 1711 part.Material = Convert.ToByte(material);
1561 group.HasGroupChanged = true; 1712 group.HasGroupChanged = true;
1713 remoteClient.SendPartPhysicsProprieties(part);
1562 } 1714 }
1563 } 1715 }
1564 } 1716 }
@@ -1637,8 +1789,10 @@ namespace OpenSim.Region.Framework.Scenes
1637 return; 1789 return;
1638 1790
1639 Monitor.Enter(m_updateLock); 1791 Monitor.Enter(m_updateLock);
1792
1640 try 1793 try
1641 { 1794 {
1795
1642 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>(); 1796 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>();
1643 1797
1644 // We do this in reverse to get the link order of the prims correct 1798 // We do this in reverse to get the link order of the prims correct
@@ -1653,9 +1807,13 @@ namespace OpenSim.Region.Framework.Scenes
1653 // Make sure no child prim is set for sale 1807 // Make sure no child prim is set for sale
1654 // So that, on delink, no prims are unwittingly 1808 // So that, on delink, no prims are unwittingly
1655 // left for sale and sold off 1809 // left for sale and sold off
1656 child.RootPart.ObjectSaleType = 0; 1810
1657 child.RootPart.SalePrice = 10; 1811 if (child != null)
1658 childGroups.Add(child); 1812 {
1813 child.RootPart.ObjectSaleType = 0;
1814 child.RootPart.SalePrice = 10;
1815 childGroups.Add(child);
1816 }
1659 } 1817 }
1660 1818
1661 foreach (SceneObjectGroup child in childGroups) 1819 foreach (SceneObjectGroup child in childGroups)
@@ -1684,6 +1842,16 @@ namespace OpenSim.Region.Framework.Scenes
1684 } 1842 }
1685 finally 1843 finally
1686 { 1844 {
1845 lock (SceneObjectGroupsByLocalPartID)
1846 {
1847 foreach (SceneObjectPart part in parentGroup.Parts)
1848 SceneObjectGroupsByLocalPartID[part.LocalId] = parentGroup;
1849 }
1850
1851 parentGroup.AdjustChildPrimPermissions();
1852 parentGroup.HasGroupChanged = true;
1853 parentGroup.ProcessBackup(m_parentScene.SimulationDataService, true);
1854 parentGroup.ScheduleGroupForFullUpdate();
1687 Monitor.Exit(m_updateLock); 1855 Monitor.Exit(m_updateLock);
1688 } 1856 }
1689 } 1857 }
@@ -1725,21 +1893,23 @@ namespace OpenSim.Region.Framework.Scenes
1725 1893
1726 SceneObjectGroup group = part.ParentGroup; 1894 SceneObjectGroup group = part.ParentGroup;
1727 if (!affectedGroups.Contains(group)) 1895 if (!affectedGroups.Contains(group))
1896 {
1728 affectedGroups.Add(group); 1897 affectedGroups.Add(group);
1898 }
1729 } 1899 }
1730 } 1900 }
1731 } 1901 }
1732 1902
1733 foreach (SceneObjectPart child in childParts) 1903 if (childParts.Count > 0)
1734 { 1904 {
1735 // Unlink all child parts from their groups 1905 foreach (SceneObjectPart child in childParts)
1736 // 1906 {
1737 child.ParentGroup.DelinkFromGroup(child, true); 1907 // Unlink all child parts from their groups
1738 1908 //
1739 // These are not in affected groups and will not be 1909 child.ParentGroup.DelinkFromGroup(child, true);
1740 // handled further. Do the honors here. 1910 child.ParentGroup.HasGroupChanged = true;
1741 child.ParentGroup.HasGroupChanged = true; 1911 child.ParentGroup.ScheduleGroupForFullUpdate();
1742 child.ParentGroup.ScheduleGroupForFullUpdate(); 1912 }
1743 } 1913 }
1744 1914
1745 foreach (SceneObjectPart root in rootParts) 1915 foreach (SceneObjectPart root in rootParts)
@@ -1753,52 +1923,61 @@ namespace OpenSim.Region.Framework.Scenes
1753 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts); 1923 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts);
1754 int numChildren = newSet.Count; 1924 int numChildren = newSet.Count;
1755 1925
1926 if (numChildren == 1)
1927 break;
1928
1756 // If there are prims left in a link set, but the root is 1929 // If there are prims left in a link set, but the root is
1757 // slated for unlink, we need to do this 1930 // slated for unlink, we need to do this
1931 // Unlink the remaining set
1758 // 1932 //
1759 if (numChildren != 1) 1933 bool sendEventsToRemainder = true;
1760 { 1934 if (numChildren > 1)
1761 // Unlink the remaining set 1935 sendEventsToRemainder = false;
1762 //
1763 bool sendEventsToRemainder = true;
1764 if (numChildren > 1)
1765 sendEventsToRemainder = false;
1766 1936
1767 foreach (SceneObjectPart p in newSet) 1937 foreach (SceneObjectPart p in newSet)
1938 {
1939 if (p != group.RootPart)
1768 { 1940 {
1769 if (p != group.RootPart) 1941 group.DelinkFromGroup(p, sendEventsToRemainder);
1770 group.DelinkFromGroup(p, sendEventsToRemainder); 1942 if (numChildren > 2)
1943 {
1944 }
1945 else
1946 {
1947 p.ParentGroup.HasGroupChanged = true;
1948 p.ParentGroup.ScheduleGroupForFullUpdate();
1949 }
1771 } 1950 }
1951 }
1772 1952
1773 // If there is more than one prim remaining, we 1953 // If there is more than one prim remaining, we
1774 // need to re-link 1954 // need to re-link
1955 //
1956 if (numChildren > 2)
1957 {
1958 // Remove old root
1775 // 1959 //
1776 if (numChildren > 2) 1960 if (newSet.Contains(root))
1961 newSet.Remove(root);
1962
1963 // Preserve link ordering
1964 //
1965 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1777 { 1966 {
1778 // Remove old root 1967 return a.LinkNum.CompareTo(b.LinkNum);
1779 // 1968 });
1780 if (newSet.Contains(root))
1781 newSet.Remove(root);
1782
1783 // Preserve link ordering
1784 //
1785 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1786 {
1787 return a.LinkNum.CompareTo(b.LinkNum);
1788 });
1789 1969
1790 // Determine new root 1970 // Determine new root
1791 // 1971 //
1792 SceneObjectPart newRoot = newSet[0]; 1972 SceneObjectPart newRoot = newSet[0];
1793 newSet.RemoveAt(0); 1973 newSet.RemoveAt(0);
1794 1974
1795 foreach (SceneObjectPart newChild in newSet) 1975 foreach (SceneObjectPart newChild in newSet)
1796 newChild.ClearUpdateSchedule(); 1976 newChild.ClearUpdateSchedule();
1797 1977
1798 LinkObjects(newRoot, newSet); 1978 LinkObjects(newRoot, newSet);
1799 if (!affectedGroups.Contains(newRoot.ParentGroup)) 1979 if (!affectedGroups.Contains(newRoot.ParentGroup))
1800 affectedGroups.Add(newRoot.ParentGroup); 1980 affectedGroups.Add(newRoot.ParentGroup);
1801 }
1802 } 1981 }
1803 } 1982 }
1804 1983
@@ -1806,6 +1985,12 @@ namespace OpenSim.Region.Framework.Scenes
1806 // 1985 //
1807 foreach (SceneObjectGroup g in affectedGroups) 1986 foreach (SceneObjectGroup g in affectedGroups)
1808 { 1987 {
1988 // Child prims that have been unlinked and deleted will
1989 // return unless the root is deleted. This will remove them
1990 // from the database. They will be rewritten immediately,
1991 // minus the rows for the unlinked child prims.
1992 g.AdjustChildPrimPermissions();
1993 m_parentScene.SimulationDataService.RemoveObject(g.UUID, m_parentScene.RegionInfo.RegionID);
1809 g.TriggerScriptChangedEvent(Changed.LINK); 1994 g.TriggerScriptChangedEvent(Changed.LINK);
1810 g.HasGroupChanged = true; // Persist 1995 g.HasGroupChanged = true; // Persist
1811 g.ScheduleGroupForFullUpdate(); 1996 g.ScheduleGroupForFullUpdate();
@@ -1879,108 +2064,96 @@ namespace OpenSim.Region.Framework.Scenes
1879 /// <param name="GroupID"></param> 2064 /// <param name="GroupID"></param>
1880 /// <param name="rot"></param> 2065 /// <param name="rot"></param>
1881 /// <returns>null if duplication fails, otherwise the duplicated object</returns> 2066 /// <returns>null if duplication fails, otherwise the duplicated object</returns>
1882 public SceneObjectGroup DuplicateObject( 2067 /// <summary>
1883 uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot) 2068 public SceneObjectGroup DuplicateObject(uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot)
1884 { 2069 {
1885 Monitor.Enter(m_updateLock); 2070// m_log.DebugFormat(
2071// "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}",
2072// originalPrimID, offset, AgentID);
1886 2073
1887 try 2074 SceneObjectGroup original = GetGroupByPrim(originalPrimID);
2075 if (original != null)
1888 { 2076 {
1889 // m_log.DebugFormat( 2077 if (m_parentScene.Permissions.CanDuplicateObject(
1890 // "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", 2078 original.PrimCount, original.UUID, AgentID, original.AbsolutePosition))
1891 // originalPrimID, offset, AgentID);
1892
1893 SceneObjectGroup original = GetGroupByPrim(originalPrimID);
1894 if (original == null)
1895 { 2079 {
1896 m_log.WarnFormat( 2080 SceneObjectGroup copy = original.Copy(true);
1897 "[SCENEGRAPH]: Attempt to duplicate nonexistant prim id {0} by {1}", originalPrimID, AgentID); 2081 copy.AbsolutePosition = copy.AbsolutePosition + offset;
1898 2082
1899 return null; 2083 if (original.OwnerID != AgentID)
1900 } 2084 {
2085 copy.SetOwnerId(AgentID);
2086 copy.SetRootPartOwner(copy.RootPart, AgentID, GroupID);
1901 2087
1902 if (!m_parentScene.Permissions.CanDuplicateObject( 2088 SceneObjectPart[] partList = copy.Parts;
1903 original.PrimCount, original.UUID, AgentID, original.AbsolutePosition)) 2089
1904 return null; 2090 if (m_parentScene.Permissions.PropagatePermissions())
2091 {
2092 foreach (SceneObjectPart child in partList)
2093 {
2094 child.Inventory.ChangeInventoryOwner(AgentID);
2095 child.TriggerScriptChangedEvent(Changed.OWNER);
2096 child.ApplyNextOwnerPermissions();
2097 }
2098 }
2099 }
1905 2100
1906 SceneObjectGroup copy = original.Copy(true); 2101 // FIXME: This section needs to be refactored so that it just calls AddSceneObject()
1907 copy.AbsolutePosition = copy.AbsolutePosition + offset; 2102 Entities.Add(copy);
1908 2103
1909 if (original.OwnerID != AgentID) 2104 lock (SceneObjectGroupsByFullID)
1910 { 2105 SceneObjectGroupsByFullID[copy.UUID] = copy;
1911 copy.SetOwnerId(AgentID);
1912 copy.SetRootPartOwner(copy.RootPart, AgentID, GroupID);
1913 2106
1914 SceneObjectPart[] partList = copy.Parts; 2107 SceneObjectPart[] children = copy.Parts;
1915 2108
1916 if (m_parentScene.Permissions.PropagatePermissions()) 2109 lock (SceneObjectGroupsByFullPartID)
1917 { 2110 {
1918 foreach (SceneObjectPart child in partList) 2111 SceneObjectGroupsByFullPartID[copy.UUID] = copy;
1919 { 2112 foreach (SceneObjectPart part in children)
1920 child.Inventory.ChangeInventoryOwner(AgentID); 2113 SceneObjectGroupsByFullPartID[part.UUID] = copy;
1921 child.TriggerScriptChangedEvent(Changed.OWNER);
1922 child.ApplyNextOwnerPermissions();
1923 }
1924 } 2114 }
1925 2115
1926 copy.RootPart.ObjectSaleType = 0; 2116 lock (SceneObjectGroupsByLocalPartID)
1927 copy.RootPart.SalePrice = 10; 2117 {
1928 } 2118 SceneObjectGroupsByLocalPartID[copy.LocalId] = copy;
2119 foreach (SceneObjectPart part in children)
2120 SceneObjectGroupsByLocalPartID[part.LocalId] = copy;
2121 }
2122 // PROBABLE END OF FIXME
1929 2123
1930 // FIXME: This section needs to be refactored so that it just calls AddSceneObject() 2124 // Since we copy from a source group that is in selected
1931 Entities.Add(copy); 2125 // state, but the copy is shown deselected in the viewer,
1932 2126 // We need to clear the selection flag here, else that
1933 lock (SceneObjectGroupsByFullID) 2127 // prim never gets persisted at all. The client doesn't
1934 SceneObjectGroupsByFullID[copy.UUID] = copy; 2128 // think it's selected, so it will never send a deselect...
1935 2129 copy.IsSelected = false;
1936 SceneObjectPart[] children = copy.Parts; 2130
1937 2131 m_numPrim += copy.Parts.Length;
1938 lock (SceneObjectGroupsByFullPartID) 2132
1939 { 2133 if (rot != Quaternion.Identity)
1940 SceneObjectGroupsByFullPartID[copy.UUID] = copy; 2134 {
1941 foreach (SceneObjectPart part in children) 2135 copy.UpdateGroupRotationR(rot);
1942 SceneObjectGroupsByFullPartID[part.UUID] = copy; 2136 }
1943 }
1944
1945 lock (SceneObjectGroupsByLocalPartID)
1946 {
1947 SceneObjectGroupsByLocalPartID[copy.LocalId] = copy;
1948 foreach (SceneObjectPart part in children)
1949 SceneObjectGroupsByLocalPartID[part.LocalId] = copy;
1950 }
1951 // PROBABLE END OF FIXME
1952
1953 // Since we copy from a source group that is in selected
1954 // state, but the copy is shown deselected in the viewer,
1955 // We need to clear the selection flag here, else that
1956 // prim never gets persisted at all. The client doesn't
1957 // think it's selected, so it will never send a deselect...
1958 copy.IsSelected = false;
1959
1960 m_numPrim += copy.Parts.Length;
1961
1962 if (rot != Quaternion.Identity)
1963 {
1964 copy.UpdateGroupRotationR(rot);
1965 }
1966 2137
1967 copy.CreateScriptInstances(0, false, m_parentScene.DefaultScriptEngine, 1); 2138 copy.CreateScriptInstances(0, false, m_parentScene.DefaultScriptEngine, 1);
1968 copy.HasGroupChanged = true; 2139 copy.HasGroupChanged = true;
1969 copy.ScheduleGroupForFullUpdate(); 2140 copy.ScheduleGroupForFullUpdate();
1970 copy.ResumeScripts(); 2141 copy.ResumeScripts();
1971 2142
1972 // required for physics to update it's position 2143 // required for physics to update it's position
1973 copy.AbsolutePosition = copy.AbsolutePosition; 2144 copy.AbsolutePosition = copy.AbsolutePosition;
1974 2145
1975 return copy; 2146 return copy;
2147 }
1976 } 2148 }
1977 finally 2149 else
1978 { 2150 {
1979 Monitor.Exit(m_updateLock); 2151 m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID);
1980 } 2152 }
2153
2154 return null;
1981 } 2155 }
1982 2156
1983 /// <summary>
1984 /// Calculates the distance between two Vector3s 2157 /// Calculates the distance between two Vector3s
1985 /// </summary> 2158 /// </summary>
1986 /// <param name="v1"></param> 2159 /// <param name="v1"></param>