* 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(
SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted)
{
sceneObject.RegionHandle = m_regInfo.RegionHandle;
sceneObject.SetScene(m_parentScene);
foreach (SceneObjectPart part in sceneObject.Children.Values)
{
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)
return false;
sceneObject.ApplyPhysics(m_parentScene.m_physicalPrim);
sceneObject.ScheduleGroupForFullUpdate();
sceneObject.AttachToScene(m_parentScene);
lock (Entities)
{

View File

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

View File

@ -508,35 +508,23 @@ namespace OpenSim.Region.Environment.Scenes
}
/// <summary>
///
/// Constructor. This object is added to the scene later via AttachToScene()
/// </summary>
public SceneObjectGroup(Scene scene, ulong regionHandle, UUID ownerID, uint localID, Vector3 pos,
Quaternion rot, PrimitiveBaseShape shape)
public SceneObjectGroup(UUID ownerID, uint localID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
{
m_regionHandle = regionHandle;
m_scene = scene;
// this.Pos = pos;
Vector3 rootOffset = new Vector3(0, 0, 0);
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;
m_parts.Add(newPart.UUID, 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>
///
/// Constructor.
/// </summary>
public SceneObjectGroup(Scene scene, ulong regionHandle, UUID ownerID, uint localID, Vector3 pos,
PrimitiveBaseShape shape)
: this(scene, regionHandle, ownerID, localID, pos, Quaternion.Identity, shape)
public SceneObjectGroup(UUID ownerID, uint localID, Vector3 pos, PrimitiveBaseShape shape)
: this(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()
{
Vector3 minScale = new Vector3(Constants.RegionSize,Constants.RegionSize,Constants.RegionSize);

View File

@ -216,9 +216,9 @@ namespace OpenSim.Region.Environment.Scenes
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)
: 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="shape"></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,
Vector3 offsetPosition)
{
m_name = "Primitive";
m_regionHandle = regionHandle;
m_parentGroup = parent;
Rezzed = DateTime.Now;
@ -260,14 +261,9 @@ namespace OpenSim.Region.Environment.Scenes
Velocity = new Vector3(0, 0, 0);
AngularVelocity = new Vector3(0, 0, 0);
Acceleration = new Vector3(0, 0, 0);
m_TextureAnimation = new byte[0];
m_particleSystem = new byte[0];
// 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
// 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();
//m_undo = new UndoStack<UndoState>(ParentGroup.GetSceneMaxUndo());
ScheduleFullUpdate();
}
/// <summary>
@ -291,11 +285,10 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="localID"></param>
/// <param name="shape"></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,
Vector3 position, Quaternion rotation, uint flags)
{
m_regionHandle = regionHandle;
m_parentGroup = parent;
TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
_creationDate = creationDate;
@ -324,8 +317,6 @@ namespace OpenSim.Region.Environment.Scenes
TrimPermissions();
// ApplyPhysics();
ScheduleFullUpdate();
}
protected SceneObjectPart(SerializationInfo info, StreamingContext context)
@ -370,7 +361,8 @@ namespace OpenSim.Region.Environment.Scenes
private DateTime m_expires;
private DateTime m_rezzed;
public UUID CreatorID {
public UUID CreatorID
{
get
{
return _creatorID;
@ -553,17 +545,6 @@ namespace OpenSim.Region.Environment.Scenes
{
StoreUndoState();
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)
{
@ -778,6 +759,7 @@ namespace OpenSim.Region.Environment.Scenes
TriggerScriptChangedEvent(Changed.SHAPE);
}
}
public Vector3 Scale
{
get { return m_shape.Scale; }
@ -813,7 +795,6 @@ if (m_shape != null) {
//---------------
#region Public Properties with only Get
public Vector3 AbsolutePosition
{
get {
@ -3419,6 +3400,16 @@ if (m_shape != null) {
#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()
{
return (byte)((AttachmentPoint % 16) * 16 + (AttachmentPoint / 16));

View File

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

View File

@ -28,6 +28,7 @@
using System;
using Nini.Config;
using NUnit.Framework;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
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);
SceneObjectGroup sceneObject = new SceneObjectGroup();
SceneObjectPart part = new SceneObjectPart();
sceneObject.AddPart(part);
new SceneObjectPart(sceneObject, UUID.Zero, 1, null, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
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)
: base(
regionHandle, parent, ownerID, localID, PrimitiveBaseShape.Default, groupPosition, offsetPosition
)
: base(parent, ownerID, localID, PrimitiveBaseShape.Default, groupPosition, offsetPosition)
{
m_rotationDirection = rotationDirection;
@ -80,29 +78,29 @@ namespace OpenSim.Region.Examples.SimpleModule
}
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);
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)));
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)));
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)));
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)));
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)));
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)));
RootPart.Flags |= PrimFlags.Touch;

View File

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

View File

@ -35,7 +35,7 @@ namespace OpenSim.Region.Examples.SimpleModule
public class FileSystemObject : SceneObjectGroup
{
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;
}