* refactor: Attach a scene object to a scene separately from its construction

0.6.0-stable
Justin Clarke Casey 2008-11-06 22:21:25 +00:00
parent 629b0d9f28
commit 0d17ba2a76
9 changed files with 84 additions and 85 deletions

View File

@ -197,9 +197,6 @@ namespace OpenSim.Region.Environment.Scenes
protected internal bool AddRestoredSceneObject( protected internal bool AddRestoredSceneObject(
SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted) SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted)
{ {
sceneObject.RegionHandle = m_regInfo.RegionHandle;
sceneObject.SetScene(m_parentScene);
foreach (SceneObjectPart part in sceneObject.Children.Values) foreach (SceneObjectPart part in sceneObject.Children.Values)
{ {
part.LocalId = m_parentScene.PrimIDAllocate(); part.LocalId = m_parentScene.PrimIDAllocate();
@ -252,8 +249,7 @@ namespace OpenSim.Region.Environment.Scenes
if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero) if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero)
return false; return false;
sceneObject.ApplyPhysics(m_parentScene.m_physicalPrim); sceneObject.AttachToScene(m_parentScene);
sceneObject.ScheduleGroupForFullUpdate();
lock (Entities) lock (Entities)
{ {

View File

@ -1735,8 +1735,7 @@ namespace OpenSim.Region.Environment.Scenes
//m_log.DebugFormat( //m_log.DebugFormat(
// "[SCENE]: Scene.AddNewPrim() called for agent {0} in {1}", ownerID, RegionInfo.RegionName); // "[SCENE]: Scene.AddNewPrim() called for agent {0} in {1}", ownerID, RegionInfo.RegionName);
SceneObjectGroup sceneOb = SceneObjectGroup sceneOb = new SceneObjectGroup(ownerID, PrimIDAllocate(), pos, rot, shape);
new SceneObjectGroup(this, m_regionHandle, ownerID, PrimIDAllocate(), pos, rot, shape);
SceneObjectPart rootPart = sceneOb.GetChildPart(sceneOb.UUID); SceneObjectPart rootPart = sceneOb.GetChildPart(sceneOb.UUID);
// if grass or tree, make phantom // if grass or tree, make phantom

View File

@ -508,35 +508,23 @@ namespace OpenSim.Region.Environment.Scenes
} }
/// <summary> /// <summary>
/// /// Constructor. This object is added to the scene later via AttachToScene()
/// </summary> /// </summary>
public SceneObjectGroup(Scene scene, ulong regionHandle, UUID ownerID, uint localID, Vector3 pos, public SceneObjectGroup(UUID ownerID, uint localID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
Quaternion rot, PrimitiveBaseShape shape)
{ {
m_regionHandle = regionHandle;
m_scene = scene;
// this.Pos = pos;
Vector3 rootOffset = new Vector3(0, 0, 0); Vector3 rootOffset = new Vector3(0, 0, 0);
SceneObjectPart newPart = SceneObjectPart newPart =
new SceneObjectPart(m_regionHandle, this, ownerID, localID, shape, pos, rot, rootOffset); new SceneObjectPart(this, ownerID, localID, shape, pos, rot, rootOffset);
newPart.LinkNum = 0; newPart.LinkNum = 0;
m_parts.Add(newPart.UUID, newPart); m_parts.Add(newPart.UUID, newPart);
SetPartAsRoot(newPart); SetPartAsRoot(newPart);
// one of these is a proxy.
if (shape.PCode != (byte)PCode.None && shape.PCode != (byte)PCode.ParticleSystem)
AttachToBackup();
//ApplyPhysics(scene.m_physicalPrim);
} }
/// <summary> /// <summary>
/// /// Constructor.
/// </summary> /// </summary>
public SceneObjectGroup(Scene scene, ulong regionHandle, UUID ownerID, uint localID, Vector3 pos, public SceneObjectGroup(UUID ownerID, uint localID, Vector3 pos, PrimitiveBaseShape shape)
PrimitiveBaseShape shape) : this(ownerID, localID, pos, Quaternion.Identity, shape)
: this(scene, regionHandle, ownerID, localID, pos, Quaternion.Identity, shape)
{ {
} }
@ -576,6 +564,31 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
/// <summary>
/// Attach the given group to a scene. It will appear to agents.
/// </summary>
/// <param name="scene"></param>
public void AttachToScene(Scene scene)
{
m_scene = scene;
ApplyPhysics(m_scene.m_physicalPrim);
lock (m_parts)
{
foreach (SceneObjectPart part in m_parts.Values)
{
part.AttachToScene(scene.RegionInfo.RegionHandle);
}
}
// one of these is a proxy.
if (m_rootPart.Shape.PCode != (byte)PCode.None && m_rootPart.Shape.PCode != (byte)PCode.ParticleSystem)
AttachToBackup();
ScheduleGroupForFullUpdate();
}
public Vector3 GroupScale() public Vector3 GroupScale()
{ {
Vector3 minScale = new Vector3(Constants.RegionSize,Constants.RegionSize,Constants.RegionSize); Vector3 minScale = new Vector3(Constants.RegionSize,Constants.RegionSize,Constants.RegionSize);

View File

@ -216,9 +216,9 @@ namespace OpenSim.Region.Environment.Scenes
Rezzed = DateTime.Now; Rezzed = DateTime.Now;
} }
public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, UUID ownerID, uint localID, public SceneObjectPart(SceneObjectGroup parent, UUID ownerID, uint localID,
PrimitiveBaseShape shape, Vector3 groupPosition, Vector3 offsetPosition) PrimitiveBaseShape shape, Vector3 groupPosition, Vector3 offsetPosition)
: this(regionHandle, parent, ownerID, localID, shape, groupPosition, Quaternion.Identity, offsetPosition) : this(parent, ownerID, localID, shape, groupPosition, Quaternion.Identity, offsetPosition)
{ {
} }
@ -231,12 +231,13 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="localID"></param> /// <param name="localID"></param>
/// <param name="shape"></param> /// <param name="shape"></param>
/// <param name="position"></param> /// <param name="position"></param>
public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, UUID ownerID, uint localID, /// <param name="rotationOffset"></param>
/// <param name="offsetPosition"></param>
public SceneObjectPart(SceneObjectGroup parent, UUID ownerID, uint localID,
PrimitiveBaseShape shape, Vector3 groupPosition, Quaternion rotationOffset, PrimitiveBaseShape shape, Vector3 groupPosition, Quaternion rotationOffset,
Vector3 offsetPosition) Vector3 offsetPosition)
{ {
m_name = "Primitive"; m_name = "Primitive";
m_regionHandle = regionHandle;
m_parentGroup = parent; m_parentGroup = parent;
Rezzed = DateTime.Now; Rezzed = DateTime.Now;
@ -260,14 +261,9 @@ namespace OpenSim.Region.Environment.Scenes
Velocity = new Vector3(0, 0, 0); Velocity = new Vector3(0, 0, 0);
AngularVelocity = new Vector3(0, 0, 0); AngularVelocity = new Vector3(0, 0, 0);
Acceleration = new Vector3(0, 0, 0); Acceleration = new Vector3(0, 0, 0);
m_TextureAnimation = new byte[0]; m_TextureAnimation = new byte[0];
m_particleSystem = new byte[0]; m_particleSystem = new byte[0];
// Prims currently only contain a single folder (Contents). From looking at the Second Life protocol, // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol,
// this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
// the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
@ -277,8 +273,6 @@ namespace OpenSim.Region.Environment.Scenes
TrimPermissions(); TrimPermissions();
//m_undo = new UndoStack<UndoState>(ParentGroup.GetSceneMaxUndo()); //m_undo = new UndoStack<UndoState>(ParentGroup.GetSceneMaxUndo());
ScheduleFullUpdate();
} }
/// <summary> /// <summary>
@ -291,11 +285,10 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="localID"></param> /// <param name="localID"></param>
/// <param name="shape"></param> /// <param name="shape"></param>
/// <param name="position"></param> /// <param name="position"></param>
public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, int creationDate, UUID ownerID, public SceneObjectPart(SceneObjectGroup parent, int creationDate, UUID ownerID,
UUID creatorID, UUID lastOwnerID, uint localID, PrimitiveBaseShape shape, UUID creatorID, UUID lastOwnerID, uint localID, PrimitiveBaseShape shape,
Vector3 position, Quaternion rotation, uint flags) Vector3 position, Quaternion rotation, uint flags)
{ {
m_regionHandle = regionHandle;
m_parentGroup = parent; m_parentGroup = parent;
TimeStampTerse = (uint) Util.UnixTimeSinceEpoch(); TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
_creationDate = creationDate; _creationDate = creationDate;
@ -324,8 +317,6 @@ namespace OpenSim.Region.Environment.Scenes
TrimPermissions(); TrimPermissions();
// ApplyPhysics(); // ApplyPhysics();
ScheduleFullUpdate();
} }
protected SceneObjectPart(SerializationInfo info, StreamingContext context) protected SceneObjectPart(SerializationInfo info, StreamingContext context)
@ -370,7 +361,8 @@ namespace OpenSim.Region.Environment.Scenes
private DateTime m_expires; private DateTime m_expires;
private DateTime m_rezzed; private DateTime m_rezzed;
public UUID CreatorID { public UUID CreatorID
{
get get
{ {
return _creatorID; return _creatorID;
@ -553,17 +545,6 @@ namespace OpenSim.Region.Environment.Scenes
{ {
StoreUndoState(); StoreUndoState();
m_offsetPosition = value; m_offsetPosition = value;
//try
//{
// Hack to get the child prim to update world positions in the physics engine
// ParentGroup.ResetChildPrimPhysicsPositions();
//}
//catch (NullReferenceException)
//{
// Ignore, and skip over.
//}
//m_log.Info("[PART]: OFFSET:" + m_offsetPosition.ToString());
if (ParentGroup != null && ParentGroup.RootPart != null) if (ParentGroup != null && ParentGroup.RootPart != null)
{ {
@ -778,6 +759,7 @@ namespace OpenSim.Region.Environment.Scenes
TriggerScriptChangedEvent(Changed.SHAPE); TriggerScriptChangedEvent(Changed.SHAPE);
} }
} }
public Vector3 Scale public Vector3 Scale
{ {
get { return m_shape.Scale; } get { return m_shape.Scale; }
@ -813,7 +795,6 @@ if (m_shape != null) {
//--------------- //---------------
#region Public Properties with only Get #region Public Properties with only Get
public Vector3 AbsolutePosition public Vector3 AbsolutePosition
{ {
get { get {
@ -3419,6 +3400,16 @@ if (m_shape != null) {
#endregion Public Methods #endregion Public Methods
/// <summary>
/// Attach this part to a scene such that it appears to avatars
/// </summary>
protected internal void AttachToScene(ulong regionHandle)
{
m_regionHandle = regionHandle;
ScheduleFullUpdate();
}
private byte GetAttachPointEncoded() private byte GetAttachPointEncoded()
{ {
return (byte)((AttachmentPoint % 16) * 16 + (AttachmentPoint / 16)); return (byte)((AttachmentPoint % 16) * 16 + (AttachmentPoint / 16));

View File

@ -1107,20 +1107,22 @@ namespace OpenSim.Region.Environment.Scenes
//proxy.PCode = (byte)PCode.ParticleSystem; //proxy.PCode = (byte)PCode.ParticleSystem;
uint nextUUID = m_scene.NextLocalId; uint nextUUID = m_scene.NextLocalId;
proxyObjectGroup = new SceneObjectGroup(m_scene, m_scene.RegionInfo.RegionHandle, UUID, nextUUID, Pos, Rotation, proxy); proxyObjectGroup = new SceneObjectGroup(UUID, nextUUID, Pos, Rotation, proxy);
if (proxyObjectGroup != null) proxyObjectGroup.AttachToScene(m_scene);
{
// Commented out this code since it could never have executed, but might still be informative.
// if (proxyObjectGroup != null)
// {
proxyObjectGroup.SendGroupFullUpdate(); proxyObjectGroup.SendGroupFullUpdate();
remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false);
m_scene.DeleteSceneObject(proxyObjectGroup); m_scene.DeleteSceneObject(proxyObjectGroup);
} // }
else // else
{ // {
m_autopilotMoving = false; // m_autopilotMoving = false;
m_autoPilotTarget = Vector3.Zero; // m_autoPilotTarget = Vector3.Zero;
ControllingClient.SendAlertMessage("Autopilot cancelled"); // ControllingClient.SendAlertMessage("Autopilot cancelled");
} // }
} }
private void CheckAtSitTarget() private void CheckAtSitTarget()

View File

@ -28,6 +28,7 @@
using System; using System;
using Nini.Config; using Nini.Config;
using NUnit.Framework; using NUnit.Framework;
using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Communications; using OpenSim.Framework.Communications;
using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Scenes;
@ -73,8 +74,7 @@ namespace OpenSim.Region.Environment.Scenes.Tests
= new Scene(regInfo, acm, cm, scs, null, sm, null, null, false, false, false, configSource, null); = new Scene(regInfo, acm, cm, scs, null, sm, null, null, false, false, false, configSource, null);
SceneObjectGroup sceneObject = new SceneObjectGroup(); SceneObjectGroup sceneObject = new SceneObjectGroup();
SceneObjectPart part = new SceneObjectPart(); new SceneObjectPart(sceneObject, UUID.Zero, 1, null, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
sceneObject.AddPart(part);
scene.AddNewSceneObject(sceneObject, false); scene.AddNewSceneObject(sceneObject, false);
} }

View File

@ -51,11 +51,9 @@ namespace OpenSim.Region.Examples.SimpleModule
{ {
} }
public RotatingWheel(ulong regionHandle, SceneObjectGroup parent, UUID ownerID, uint localID, public RotatingWheel(SceneObjectGroup parent, UUID ownerID, uint localID,
Vector3 groupPosition, Vector3 offsetPosition, Quaternion rotationDirection) Vector3 groupPosition, Vector3 offsetPosition, Quaternion rotationDirection)
: base( : base(parent, ownerID, localID, PrimitiveBaseShape.Default, groupPosition, offsetPosition)
regionHandle, parent, ownerID, localID, PrimitiveBaseShape.Default, groupPosition, offsetPosition
)
{ {
m_rotationDirection = rotationDirection; m_rotationDirection = rotationDirection;
@ -64,13 +62,13 @@ namespace OpenSim.Region.Examples.SimpleModule
public override void UpdateMovement() public override void UpdateMovement()
{ {
UpdateRotation(RotationOffset*m_rotationDirection); UpdateRotation(RotationOffset * m_rotationDirection);
} }
} }
public override void UpdateMovement() public override void UpdateMovement()
{ {
UpdateGroupRotation(GroupRotation*m_rotationDirection); UpdateGroupRotation(GroupRotation * m_rotationDirection);
base.UpdateMovement(); base.UpdateMovement();
} }
@ -80,29 +78,29 @@ namespace OpenSim.Region.Examples.SimpleModule
} }
public ComplexObject(Scene scene, ulong regionHandle, UUID ownerID, uint localID, Vector3 pos) public ComplexObject(Scene scene, ulong regionHandle, UUID ownerID, uint localID, Vector3 pos)
: base(scene, regionHandle, ownerID, localID, pos, PrimitiveBaseShape.Default) : base(ownerID, localID, pos, PrimitiveBaseShape.Default)
{ {
m_rotationDirection = new Quaternion(0.05f, 0.1f, 0.15f); m_rotationDirection = new Quaternion(0.05f, 0.1f, 0.15f);
AddPart( AddPart(
new RotatingWheel(regionHandle, this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0, 0, 0.75f), new RotatingWheel(this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0, 0, 0.75f),
new Quaternion(0.05f, 0, 0))); new Quaternion(0.05f, 0, 0)));
AddPart( AddPart(
new RotatingWheel(regionHandle, this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0, 0, -0.75f), new RotatingWheel(this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0, 0, -0.75f),
new Quaternion(-0.05f, 0, 0))); new Quaternion(-0.05f, 0, 0)));
AddPart( AddPart(
new RotatingWheel(regionHandle, this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0, 0.75f, 0), new RotatingWheel(this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0, 0.75f, 0),
new Quaternion(0.5f, 0, 0.05f))); new Quaternion(0.5f, 0, 0.05f)));
AddPart( AddPart(
new RotatingWheel(regionHandle, this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0, -0.75f, 0), new RotatingWheel(this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0, -0.75f, 0),
new Quaternion(-0.5f, 0, -0.05f))); new Quaternion(-0.5f, 0, -0.05f)));
AddPart( AddPart(
new RotatingWheel(regionHandle, this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0.75f, 0, 0), new RotatingWheel(this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(0.75f, 0, 0),
new Quaternion(0, 0.5f, 0.05f))); new Quaternion(0, 0.5f, 0.05f)));
AddPart( AddPart(
new RotatingWheel(regionHandle, this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(-0.75f, 0, 0), new RotatingWheel(this, ownerID, scene.PrimIDAllocate(), pos, new Vector3(-0.75f, 0, 0),
new Quaternion(0, -0.5f, -0.05f))); new Quaternion(0, -0.5f, -0.05f)));
RootPart.Flags |= PrimFlags.Touch; RootPart.Flags |= PrimFlags.Touch;

View File

@ -45,8 +45,8 @@ namespace OpenSim.Region.Examples.SimpleModule
private PerformanceCounter m_counter; private PerformanceCounter m_counter;
public CpuCounterObject(Scene world, ulong regionHandle, UUID ownerID, uint localID, Vector3 pos) public CpuCounterObject(UUID ownerID, uint localID, Vector3 pos)
: base(world, regionHandle, ownerID, localID, pos, PrimitiveBaseShape.Default) : base(ownerID, localID, pos, PrimitiveBaseShape.Default)
{ {
String objectName = "Processor"; String objectName = "Processor";
String counterName = "% Processor Time"; String counterName = "% Processor Time";

View File

@ -35,7 +35,7 @@ namespace OpenSim.Region.Examples.SimpleModule
public class FileSystemObject : SceneObjectGroup public class FileSystemObject : SceneObjectGroup
{ {
public FileSystemObject(Scene world, FileInfo fileInfo, Vector3 pos) public FileSystemObject(Scene world, FileInfo fileInfo, Vector3 pos)
: base(world, world.RegionInfo.RegionHandle, UUID.Zero, world.NextLocalId, pos, PrimitiveBaseShape.Default) : base(UUID.Zero, world.NextLocalId, pos, PrimitiveBaseShape.Default)
{ {
Text = fileInfo.Name; Text = fileInfo.Name;
} }