From 323038ceb956fef577ebd83c502cc377bcfe83f9 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 26 Apr 2008 17:36:30 +0000 Subject: * Ooops, attachments now teleport/cross region borders along with your avatar. Those dastardly objects stick to you. --- OpenSim/Region/Environment/Scenes/InnerScene.cs | 32 ++++++++++-- OpenSim/Region/Environment/Scenes/Scene.cs | 22 +++++++++ .../Scenes/SceneCommunicationService.cs | 2 + .../Region/Environment/Scenes/SceneObjectGroup.cs | 57 ++++++++++++++++------ .../Region/Environment/Scenes/SceneObjectPart.cs | 7 +++ OpenSim/Region/Environment/Scenes/ScenePresence.cs | 43 +++++++++++++++- 6 files changed, 141 insertions(+), 22 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Scenes/InnerScene.cs b/OpenSim/Region/Environment/Scenes/InnerScene.cs index 2aa51b8..cbe5798 100644 --- a/OpenSim/Region/Environment/Scenes/InnerScene.cs +++ b/OpenSim/Region/Environment/Scenes/InnerScene.cs @@ -310,13 +310,22 @@ namespace OpenSim.Region.Environment.Scenes } } + /// + /// Event Handling routine for Attach Object + /// + /// + /// + /// + /// public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, LLQuaternion rot) { - List EntityList = GetEntities(); - - if (AttachmentPt == 0) - AttachmentPt = (uint)AttachmentPoint.LeftHand; + // Calls attach with a Zero position + AttachObject(remoteClient, objectLocalID, AttachmentPt, rot, LLVector3.Zero); + } + public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, LLQuaternion rot, LLVector3 attachPos) + { + List EntityList = GetEntities(); foreach (EntityBase obj in EntityList) { if (obj is SceneObjectGroup) @@ -324,7 +333,20 @@ namespace OpenSim.Region.Environment.Scenes if (((SceneObjectGroup)obj).LocalId == objectLocalID) { SceneObjectGroup group = (SceneObjectGroup)obj; - group.AttachToAgent(remoteClient.AgentId, AttachmentPt); + if (AttachmentPt == 0) + { + // Check object for stored attachment point + AttachmentPt = (uint)group.GetAttachmentPoint(); + + // if we still didn't find a suitable attachment point....... + if (AttachmentPt == 0) + { + AttachmentPt = (uint)AttachmentPoint.LeftHand; + } + + } + + group.AttachToAgent(remoteClient.AgentId, AttachmentPt, attachPos); } diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index ce713c5..9ca845f 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -1457,6 +1457,28 @@ namespace OpenSim.Region.Environment.Scenes if (XMLMethod == 0) { m_sceneXmlLoader.LoadGroupFromXml2String(objXMLData); + SceneObjectPart RootPrim = GetSceneObjectPart(primID); + if (RootPrim != null) + { + if (RootPrim.Shape.PCode == (byte)PCode.Prim) + { + SceneObjectGroup grp = RootPrim.ParentGroup; + if (grp != null) + { + if (RootPrim.Shape.State != 0) + { + // Attachment + ScenePresence sp = GetScenePresence(grp.OwnerID); + if (sp != null) + { + m_innerScene.AttachObject(sp.ControllingClient, grp.LocalId, (uint)0, grp.GroupRotation, grp.AbsolutePosition); + } + } + } + + + } + } return true; } else diff --git a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs index 0062e4d..27967bc 100644 --- a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs @@ -580,6 +580,8 @@ namespace OpenSim.Region.Environment.Scenes avatar.ControllingClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4), capsPath); avatar.MakeChildAgent(); + System.Threading.Thread.Sleep(5000); + avatar.CrossAttachmentsIntoNewRegion(regionHandle); if (KillObject != null) { KillObject(avatar.LocalId); diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index fbf0a73..7020eb8 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -628,24 +628,39 @@ namespace OpenSim.Region.Environment.Scenes } - public void AttachToAgent(LLUUID agentID, uint attachmentpoint) + public void AttachToAgent(LLUUID agentID, uint attachmentpoint, LLVector3 AttachOffset) { ScenePresence avatar = m_scene.GetScenePresence(agentID); if (avatar != null) { + DetachFromBackup(this); m_rootPart.m_attachedAvatar = agentID; - m_rootPart.SetParentLocalId(avatar.LocalId); - m_rootPart.SetAttachmentPoint(attachmentpoint); - m_rootPart.m_IsAttachment = true; + + if (m_rootPart.PhysActor != null) { m_scene.PhysicsScene.RemovePrim(m_rootPart.PhysActor); m_rootPart.PhysActor = null; - AbsolutePosition = LLVector3.Zero; + AbsolutePosition = AttachOffset; + m_rootPart.m_attachedPos = AttachOffset; } + m_rootPart.m_IsAttachment = true; + + m_rootPart.SetParentLocalId(avatar.LocalId); + m_rootPart.SetAttachmentPoint(attachmentpoint); + + avatar.AddAttachment(this); m_rootPart.ScheduleFullUpdate(); } } + public byte GetAttachmentPoint() + { + if (m_rootPart != null) + { + return m_rootPart.Shape.State; + } + return (byte)0; + } public void DetachToGround() { @@ -654,6 +669,7 @@ namespace OpenSim.Region.Environment.Scenes if (avatar != null) { detachedpos = avatar.AbsolutePosition; + avatar.RemoveAttachment(this); } AbsolutePosition = detachedpos; m_rootPart.m_attachedAvatar = LLUUID.Zero; @@ -661,6 +677,7 @@ namespace OpenSim.Region.Environment.Scenes m_rootPart.SetAttachmentPoint((byte)0); m_rootPart.m_IsAttachment = false; m_rootPart.ApplyPhysics(m_rootPart.ObjectFlags, m_scene.m_physicalPrim); + AttachToBackup(); m_rootPart.ScheduleFullUpdate(); } /// @@ -1395,26 +1412,36 @@ namespace OpenSim.Region.Environment.Scenes lock (m_parts) { + //if (m_rootPart.m_IsAttachment) + //{ + //foreach (SceneObjectPart part in m_parts.Values) + //{ + //part.SendScheduledUpdates(); + //} + //return; + //} + if (Util.GetDistanceTo(lastPhysGroupPos, AbsolutePosition) > 0.02) { - foreach (SceneObjectPart part in m_parts.Values) - { - if (part.UpdateFlag == 0) part.UpdateFlag = 1; - } - + m_rootPart.UpdateFlag = 1; lastPhysGroupPos = AbsolutePosition; - checkAtTargets(); } + //foreach (SceneObjectPart part in m_parts.Values) + //{ + //if (part.UpdateFlag == 0) part.UpdateFlag = 1; + //} + + + + checkAtTargets(); + if ((Math.Abs(lastPhysGroupRot.W - GroupRotation.W) > 0.1) || (Math.Abs(lastPhysGroupRot.X - GroupRotation.X) > 0.1) || (Math.Abs(lastPhysGroupRot.Y - GroupRotation.Y) > 0.1) || (Math.Abs(lastPhysGroupRot.Z - GroupRotation.Z) > 0.1)) { - foreach (SceneObjectPart part in m_parts.Values) - { - if (part.UpdateFlag == 0) part.UpdateFlag = 1; - } + m_rootPart.UpdateFlag = 1; lastPhysGroupRot = GroupRotation; } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 6a12fb9..b7e72ef 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -1300,6 +1300,13 @@ namespace OpenSim.Region.Environment.Scenes public void SetAttachmentPoint(uint AttachmentPoint) { m_attachmentPoint = AttachmentPoint; + + // save the attachment point. + //if (AttachmentPoint != 0) + //{ + m_shape.State = (byte)AttachmentPoint; + //} + } /// /// diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 94dbbb3..6a56204 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -117,6 +117,8 @@ namespace OpenSim.Region.Environment.Scenes protected AvatarAppearance m_appearance; + protected List m_attachments = new List(); + //neighbouring regions we have enabled a child agent in private readonly List m_knownChildRegions = new List(); @@ -1672,8 +1674,8 @@ namespace OpenSim.Region.Environment.Scenes // When the neighbour is informed of the border crossing, it will set up CAPS handlers for the avatar // This means we need to remove the current caps handler here and possibly compensate later, // in case both scenes are being hosted on the same region server. Messy - m_scene.RemoveCapsHandler(UUID); - + m_scene.RemoveCapsHandler(UUID); + newpos = newpos + (vel); bool res = m_scene.InformNeighbourOfCrossing(neighbourHandle, m_controllingClient.AgentId, newpos, m_physicsActor.Flying); @@ -1692,6 +1694,7 @@ namespace OpenSim.Region.Environment.Scenes m_controllingClient.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.ExternalEndPoint, capsPath); MakeChildAgent(); + CrossAttachmentsIntoNewRegion(neighbourHandle); m_scene.SendKillObject(m_localId); m_scene.NotifyMyCoarseLocationChange(); } @@ -1943,7 +1946,43 @@ namespace OpenSim.Region.Environment.Scenes DefaultTexture = textu.ToBytes(); } } + public void AddAttachment(SceneObjectGroup gobj) + { + lock (m_attachments) + { + m_attachments.Add(gobj); + } + } + public void RemoveAttachment(SceneObjectGroup gobj) + { + lock (m_attachments) + { + if (m_attachments.Contains(gobj)) + { + m_attachments.Remove(gobj); + } + } + } + public void CrossAttachmentsIntoNewRegion(ulong regionHandle) + { + lock (m_attachments) + { + foreach (SceneObjectGroup gobj in m_attachments) + { + // If the prim group is null then something must have happened to it! + if (gobj != null) + { + // Set the parent localID to 0 so it transfers over properly. + gobj.RootPart.SetParentLocalId(0); + gobj.RootPart.m_IsAttachment = false; + gobj.AbsolutePosition = gobj.RootPart.m_attachedPos; + m_scene.CrossPrimGroupIntoNewRegion(regionHandle, gobj); + } + } + m_attachments.Clear(); + } + } public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene) { m_controllingClient = client; -- cgit v1.1