From e8acf1cca92592fea38208dbfe4137555431434d Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Mon, 9 Jul 2007 15:29:39 +0000 Subject: * Begun work on Primitive Duplication. Not hooked up yet, but theoretically could be done so. In practice, more work needs to be done. --- OpenSim/Framework/General/Interfaces/IClientAPI.cs | 2 ++ OpenSim/Region/ClientStack/ClientView.API.cs | 1 + .../ClientStack/ClientView.ProcessPackets.cs | 12 ++++++++ OpenSim/Region/Environment/Scenes/EntityBase.cs | 10 +++++++ OpenSim/Region/Environment/Scenes/Primitive.cs | 35 ++++++++++++++++++++++ .../Environment/Scenes/Scene.PacketHandlers.cs | 33 ++++++++++++++++++++ OpenSim/Region/Environment/Scenes/Scene.cs | 21 +++++++++++-- OpenSim/Region/Environment/Scenes/SceneObject.cs | 28 +++++++++++++++++ 8 files changed, 140 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/General/Interfaces/IClientAPI.cs b/OpenSim/Framework/General/Interfaces/IClientAPI.cs index acacabe..206122d 100644 --- a/OpenSim/Framework/General/Interfaces/IClientAPI.cs +++ b/OpenSim/Framework/General/Interfaces/IClientAPI.cs @@ -59,6 +59,7 @@ namespace OpenSim.Framework.Interfaces public delegate void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient); public delegate void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient); public delegate void UpdatePrimGroupRotation(uint localID,LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient); + public delegate void ObjectDuplicate(uint localID, LLVector3 offset, uint dupeFlags); public delegate void StatusChange(bool status); public delegate void NewAvatar(IClientAPI remoteClient, LLUUID agentID, bool status); public delegate void UpdateAgent(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation); @@ -92,6 +93,7 @@ namespace OpenSim.Framework.Interfaces event UpdateAgent OnAgentUpdate; event GenericCall OnRequestAvatarsData; event GenericCall4 OnAddPrim; + event ObjectDuplicate OnObjectDuplicate; event UpdateVector OnGrapObject; event ObjectSelect OnDeGrapObject; event MoveObject OnGrapUpdate; diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs index cefe856..3c1df75 100644 --- a/OpenSim/Region/ClientStack/ClientView.API.cs +++ b/OpenSim/Region/ClientStack/ClientView.API.cs @@ -55,6 +55,7 @@ namespace OpenSim.Region.ClientStack public event LinkObjects OnLinkObjects; public event UpdateVector OnGrapObject; public event ObjectSelect OnDeGrapObject; + public event ObjectDuplicate OnObjectDuplicate; public event MoveObject OnGrapUpdate; public event GenericCall4 OnAddPrim; public event UpdateShape OnUpdatePrimShape; diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs index def14c7..982ae50 100644 --- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs +++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs @@ -233,6 +233,18 @@ namespace OpenSim.Region.ClientStack } } break; + case PacketType.ObjectDuplicate: + ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack; + for (int i = 0; i < dupe.ObjectData.Length; i++) + { + if (OnObjectDuplicate != null) + { + OnObjectDuplicate(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset, dupe.SharedData.DuplicateFlags); + } + } + + break; + case PacketType.ObjectSelect: ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack; for (int i = 0; i < incomingselect.ObjectData.Length; i++) diff --git a/OpenSim/Region/Environment/Scenes/EntityBase.cs b/OpenSim/Region/Environment/Scenes/EntityBase.cs index 99ca021..7914bab 100644 --- a/OpenSim/Region/Environment/Scenes/EntityBase.cs +++ b/OpenSim/Region/Environment/Scenes/EntityBase.cs @@ -74,6 +74,7 @@ namespace OpenSim.Region.Environment.Scenes public uint LocalId { get { return m_localId; } + set { m_localId = value; } } /// @@ -122,6 +123,15 @@ namespace OpenSim.Region.Environment.Scenes } /// + /// Copies the entity + /// + /// + public virtual EntityBase Copy() + { + return (EntityBase)this.MemberwiseClone(); + } + + /// /// Infoms the entity that the land (heightmap) has changed /// public virtual void LandRenegerated() diff --git a/OpenSim/Region/Environment/Scenes/Primitive.cs b/OpenSim/Region/Environment/Scenes/Primitive.cs index 9d01618..8d31d63 100644 --- a/OpenSim/Region/Environment/Scenes/Primitive.cs +++ b/OpenSim/Region/Environment/Scenes/Primitive.cs @@ -141,8 +141,43 @@ namespace OpenSim.Region.Environment.Scenes this.CreateFromPacket(addPacket, ownerID, localID); this.rotation = Axiom.Math.Quaternion.Identity; } + + /// + /// + /// + /// Empty constructor for duplication + public Primitive() + { + + } + #endregion + #region Duplication + + public Primitive Copy(EntityBase parent, SceneObject rootParent) + { + Primitive dupe = (Primitive)this.MemberwiseClone(); + // TODO: Copy this properly. + dupe.inventoryItems = this.inventoryItems; + dupe.m_Parent = parent; + dupe.m_RootParent = rootParent; + // TODO: Copy this properly. + dupe.m_Shape = this.m_Shape; + + uint newLocalID = this.m_world.PrimIDAllocate(); + dupe.LocalId = newLocalID; + + dupe.Scale = new LLVector3(this.Scale.X, this.Scale.Y, this.Scale.Z); + dupe.rotation = new Quaternion(this.rotation.w, this.rotation.x, this.rotation.y, this.rotation.z); + dupe.Pos = new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z); + + return dupe; + } + + #endregion + + #region Override from EntityBase /// /// diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index e078348..35e0ea6 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -215,6 +215,39 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// + /// + /// + /// + public void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags) + { + SceneObject originPrim = null; + foreach (EntityBase ent in Entities.Values) + { + if (ent is SceneObject) + { + if (((SceneObject)ent).rootLocalID == originalPrim) + { + originPrim = (SceneObject)ent; + break; + } + } + } + + if (originPrim != null) + { + //SceneObject copy = originPrim.Copy(); + + } + else + { + OpenSim.Framework.Console.MainLog.Instance.Warn("Attempted to duplicate nonexistant prim"); + } + + } + + /// + /// + /// /// /// public void LinkObjects(uint parentPrim, List childPrims) diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index fdf3cc8..1798cba 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -57,6 +57,7 @@ namespace OpenSim.Region.Environment.Scenes private float timeStep = 0.1f; private Random Rand = new Random(); private uint _primCount = 702000; + private System.Threading.Mutex _primAllocateMutex = new Mutex(false); private int storageCount; private Mutex updateLock; @@ -397,6 +398,22 @@ namespace OpenSim.Region.Environment.Scenes } /// + /// Returns a new unallocated primitive ID + /// + /// A brand new primitive ID + public uint PrimIDAllocate() + { + uint myID; + + _primAllocateMutex.WaitOne(); + ++_primCount; + myID = _primCount; + _primAllocateMutex.ReleaseMutex(); + + return myID; + } + + /// /// /// /// @@ -415,9 +432,8 @@ namespace OpenSim.Region.Environment.Scenes { try { - SceneObject sceneOb = new SceneObject(m_regionHandle, this, addPacket, ownerID, this._primCount); + SceneObject sceneOb = new SceneObject(m_regionHandle, this, addPacket, ownerID, this.PrimIDAllocate()); this.Entities.Add(sceneOb.rootUUID, sceneOb); - this._primCount++; // Trigger event for listeners // eventManager.TriggerOnNewPrimitive(prim); @@ -468,6 +484,7 @@ namespace OpenSim.Region.Environment.Scenes client.OnObjectDescription += this.PrimDescription; client.OnObjectName += this.PrimName; client.OnLinkObjects += this.LinkObjects; + client.OnObjectDuplicate += this.DuplicateObject; /* remoteClient.OnParcelPropertiesRequest += new ParcelPropertiesRequest(parcelManager.handleParcelPropertiesRequest); remoteClient.OnParcelDivideRequest += new ParcelDivideRequest(parcelManager.handleParcelDivideRequest); diff --git a/OpenSim/Region/Environment/Scenes/SceneObject.cs b/OpenSim/Region/Environment/Scenes/SceneObject.cs index 452502b..2b80d57 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObject.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObject.cs @@ -78,6 +78,15 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// + /// Need a null constructor for duplication + public SceneObject() + { + + } + + /// + /// + /// /// /// /// @@ -100,6 +109,25 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// + /// A complete copy of the object + public SceneObject Copy() + { + SceneObject dupe = new SceneObject(); + + Primitive newRoot = this.rootPrimitive.Copy((EntityBase)dupe, dupe); + + foreach (EntityBase child in this.children) + { + EntityBase newChild = child.Copy(); + dupe.children.Add(newChild); + } + + return dupe; + } + + /// + /// + /// public void DeleteAllChildren() { this.children.Clear(); -- cgit v1.1