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/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 +++++++++++++++++ 5 files changed, 125 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Environment/Scenes') 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