Eliminate pointless checks of SOG.RootPart != null

It's never possible for SOG to have no RootPart, except in the first few picosends of the big bang when it's pulled from region persistence or deserialized
remove-scene-viewer
Justin Clark-Casey (justincc) 2011-09-01 02:09:41 +01:00
parent 10d883dc88
commit 7eca929686
12 changed files with 126 additions and 212 deletions

View File

@ -322,8 +322,6 @@ namespace OpenSim.Region.ClientStack.Linden
rootpart.NextOwnerMask = next_owner_mask; rootpart.NextOwnerMask = next_owner_mask;
rootpart.Material = (byte)material; rootpart.Material = (byte)material;
m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor); m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor);
responsedata["int_response_code"] = 200; //501; //410; //404; responsedata["int_response_code"] = 200; //501; //410; //404;

View File

@ -470,12 +470,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
return; return;
} }
if (null == att.RootPart)
{
m_log.Error("[ATTACHMENTS MODULE]: Unable to save attachment for a prim without the rootpart!");
return;
}
InventoryItemBase item = new InventoryItemBase(itemID, sp.UUID); InventoryItemBase item = new InventoryItemBase(itemID, sp.UUID);
item = m_scene.InventoryService.GetItem(item); item = m_scene.InventoryService.GetItem(item);
bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID); bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID);

View File

@ -1772,7 +1772,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
foreach (SceneObjectGroup gobj in m_attachments) foreach (SceneObjectGroup gobj in m_attachments)
{ {
// If the prim group is null then something must have happened to it! // If the prim group is null then something must have happened to it!
if (gobj != null && gobj.RootPart != null) if (gobj != null)
{ {
// Set the parent localID to 0 so it transfers over properly. // Set the parent localID to 0 so it transfers over properly.
gobj.RootPart.SetParentLocalId(0); gobj.RootPart.SetParentLocalId(0);

View File

@ -118,59 +118,56 @@ namespace OpenSim.Region.DataSnapshot.Providers
{ {
SceneObjectPart m_rootPart = obj.RootPart; SceneObjectPart m_rootPart = obj.RootPart;
if (m_rootPart != null) ILandObject land = m_scene.LandChannel.GetLandObject(m_rootPart.AbsolutePosition.X, m_rootPart.AbsolutePosition.Y);
XmlNode xmlobject = nodeFactory.CreateNode(XmlNodeType.Element, "object", "");
node = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
node.InnerText = obj.UUID.ToString();
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "title", "");
node.InnerText = m_rootPart.Name;
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "description", "");
node.InnerText = m_rootPart.Description;
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "flags", "");
node.InnerText = String.Format("{0:x}", (uint)m_rootPart.Flags);
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "regionuuid", "");
node.InnerText = m_scene.RegionInfo.RegionSettings.RegionUUID.ToString();
xmlobject.AppendChild(node);
if (land != null && land.LandData != null)
{ {
ILandObject land = m_scene.LandChannel.GetLandObject(m_rootPart.AbsolutePosition.X, m_rootPart.AbsolutePosition.Y); node = nodeFactory.CreateNode(XmlNodeType.Element, "parceluuid", "");
node.InnerText = land.LandData.GlobalID.ToString();
XmlNode xmlobject = nodeFactory.CreateNode(XmlNodeType.Element, "object", "");
node = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
node.InnerText = obj.UUID.ToString();
xmlobject.AppendChild(node); xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "title", "");
node.InnerText = m_rootPart.Name;
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "description", "");
node.InnerText = m_rootPart.Description;
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "flags", "");
node.InnerText = String.Format("{0:x}", (uint)m_rootPart.Flags);
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "regionuuid", "");
node.InnerText = m_scene.RegionInfo.RegionSettings.RegionUUID.ToString();
xmlobject.AppendChild(node);
if (land != null && land.LandData != null)
{
node = nodeFactory.CreateNode(XmlNodeType.Element, "parceluuid", "");
node.InnerText = land.LandData.GlobalID.ToString();
xmlobject.AppendChild(node);
}
else
{
// Something is wrong with this object. Let's not list it.
m_log.WarnFormat("[DATASNAPSHOT]: Bad data for object {0} ({1}) in region {2}", obj.Name, obj.UUID, m_scene.RegionInfo.RegionName);
continue;
}
node = nodeFactory.CreateNode(XmlNodeType.Element, "location", "");
Vector3 loc = obj.AbsolutePosition;
node.InnerText = loc.X.ToString() + "/" + loc.Y.ToString() + "/" + loc.Z.ToString();
xmlobject.AppendChild(node);
string bestImage = GuessImage(obj);
if (bestImage != string.Empty)
{
node = nodeFactory.CreateNode(XmlNodeType.Element, "image", "");
node.InnerText = bestImage;
xmlobject.AppendChild(node);
}
parent.AppendChild(xmlobject);
} }
else
{
// Something is wrong with this object. Let's not list it.
m_log.WarnFormat("[DATASNAPSHOT]: Bad data for object {0} ({1}) in region {2}", obj.Name, obj.UUID, m_scene.RegionInfo.RegionName);
continue;
}
node = nodeFactory.CreateNode(XmlNodeType.Element, "location", "");
Vector3 loc = obj.AbsolutePosition;
node.InnerText = loc.X.ToString() + "/" + loc.Y.ToString() + "/" + loc.Z.ToString();
xmlobject.AppendChild(node);
string bestImage = GuessImage(obj);
if (bestImage != string.Empty)
{
node = nodeFactory.CreateNode(XmlNodeType.Element, "image", "");
node.InnerText = bestImage;
xmlobject.AppendChild(node);
}
parent.AppendChild(xmlobject);
} }
#pragma warning disable 0612 #pragma warning disable 0612
} }

View File

@ -191,10 +191,6 @@ namespace OpenSim.Region.Framework.Scenes
if (part == null) if (part == null)
return; return;
// The prim is in the process of being deleted.
if (null == part.ParentGroup.RootPart)
return;
// A deselect packet contains all the local prims being deselected. However, since selection is still // A deselect packet contains all the local prims being deselected. However, since selection is still
// group based we only want the root prim to trigger a full update - otherwise on objects with many prims // group based we only want the root prim to trigger a full update - otherwise on objects with many prims
// we end up sending many duplicate ObjectUpdates // we end up sending many duplicate ObjectUpdates

View File

@ -1743,14 +1743,6 @@ namespace OpenSim.Region.Framework.Scenes
foreach (SceneObjectGroup group in PrimsFromDB) foreach (SceneObjectGroup group in PrimsFromDB)
{ {
EventManager.TriggerOnSceneObjectLoaded(group); EventManager.TriggerOnSceneObjectLoaded(group);
if (group.RootPart == null)
{
m_log.ErrorFormat(
"[SCENE]: Found a SceneObjectGroup with m_rootPart == null and {0} children",
group.Parts == null ? 0 : group.PrimCount);
}
AddRestoredSceneObject(group, true, true); AddRestoredSceneObject(group, true, true);
SceneObjectPart rootPart = group.GetChildPart(group.UUID); SceneObjectPart rootPart = group.GetChildPart(group.UUID);
rootPart.Flags &= ~PrimFlags.Scripted; rootPart.Flags &= ~PrimFlags.Scripted;
@ -4215,7 +4207,7 @@ namespace OpenSim.Region.Framework.Scenes
// their scripts will actually run. // their scripts will actually run.
// -- Leaf, Tue Aug 12 14:17:05 EDT 2008 // -- Leaf, Tue Aug 12 14:17:05 EDT 2008
SceneObjectPart parent = part.ParentGroup.RootPart; SceneObjectPart parent = part.ParentGroup.RootPart;
if (parent != null && part.ParentGroup.IsAttachment) if (part.ParentGroup.IsAttachment)
return ScriptDanger(parent, parent.GetWorldPosition()); return ScriptDanger(parent, parent.GetWorldPosition());
else else
return ScriptDanger(part, part.GetWorldPosition()); return ScriptDanger(part, part.GetWorldPosition());
@ -5015,7 +5007,9 @@ namespace OpenSim.Region.Framework.Scenes
if (rootPart.GroupPosition.Z < 0.0 || rootPart.GroupPosition.Z > 10000.0) if (rootPart.GroupPosition.Z < 0.0 || rootPart.GroupPosition.Z > 10000.0)
{ {
delete = true; delete = true;
} else { }
else
{
ILandObject parcel = LandChannel.GetLandObject(rootPart.GroupPosition.X, rootPart.GroupPosition.Y); ILandObject parcel = LandChannel.GetLandObject(rootPart.GroupPosition.X, rootPart.GroupPosition.Y);
if (parcel == null || parcel.LandData.Name == "NO LAND") if (parcel == null || parcel.LandData.Name == "NO LAND")

View File

@ -362,7 +362,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </returns> /// </returns>
protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates) protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
{ {
if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero) if (sceneObject == null || sceneObject.RootPart.UUID == UUID.Zero)
return false; return false;
if (Entities.ContainsKey(sceneObject.UUID)) if (Entities.ContainsKey(sceneObject.UUID))

View File

@ -254,14 +254,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
public override string Name public override string Name
{ {
get get { return RootPart.Name; }
{
if (RootPart == null)
return String.Empty;
else
return RootPart.Name;
}
set { RootPart.Name = value; } set { RootPart.Name = value; }
} }
@ -1054,7 +1047,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
part.SetParent(this); part.SetParent(this);
part.LinkNum = m_parts.Add(part.UUID, part); part.LinkNum = m_parts.Add(part.UUID, part);
if (part.LinkNum == 2 && RootPart != null) if (part.LinkNum == 2)
RootPart.LinkNum = 1; RootPart.LinkNum = 1;
} }
@ -1537,137 +1530,93 @@ namespace OpenSim.Region.Framework.Scenes
public void applyImpulse(Vector3 impulse) public void applyImpulse(Vector3 impulse)
{ {
// We check if rootpart is null here because scripts don't delete if you delete the host. if (IsAttachment)
// This means that unfortunately, we can pass a null physics actor to Simulate!
// Make sure we don't do that!
SceneObjectPart rootpart = m_rootPart;
if (rootpart != null)
{ {
if (IsAttachment) ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
if (avatar != null)
{ {
ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); avatar.PushForce(impulse);
if (avatar != null)
{
avatar.PushForce(impulse);
}
} }
else }
else
{
if (RootPart.PhysActor != null)
{ {
if (rootpart.PhysActor != null) RootPart.PhysActor.AddForce(impulse, true);
{ m_scene.PhysicsScene.AddPhysicsActorTaint(RootPart.PhysActor);
rootpart.PhysActor.AddForce(impulse, true);
m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor);
}
} }
} }
} }
public void applyAngularImpulse(Vector3 impulse) public void applyAngularImpulse(Vector3 impulse)
{ {
// We check if rootpart is null here because scripts don't delete if you delete the host. if (RootPart.PhysActor != null)
// This means that unfortunately, we can pass a null physics actor to Simulate!
// Make sure we don't do that!
SceneObjectPart rootpart = m_rootPart;
if (rootpart != null)
{ {
if (rootpart.PhysActor != null) if (!IsAttachment)
{ {
if (!IsAttachment) RootPart.PhysActor.AddAngularForce(impulse, true);
{ m_scene.PhysicsScene.AddPhysicsActorTaint(RootPart.PhysActor);
rootpart.PhysActor.AddAngularForce(impulse, true);
m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor);
}
} }
} }
} }
public void setAngularImpulse(Vector3 impulse) public void setAngularImpulse(Vector3 impulse)
{ {
// We check if rootpart is null here because scripts don't delete if you delete the host. if (RootPart.PhysActor != null)
// This means that unfortunately, we can pass a null physics actor to Simulate!
// Make sure we don't do that!
SceneObjectPart rootpart = m_rootPart;
if (rootpart != null)
{ {
if (rootpart.PhysActor != null) if (!IsAttachment)
{ {
if (!IsAttachment) RootPart.PhysActor.Torque = impulse;
{ m_scene.PhysicsScene.AddPhysicsActorTaint(RootPart.PhysActor);
rootpart.PhysActor.Torque = impulse;
m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor);
}
} }
} }
} }
public Vector3 GetTorque() public Vector3 GetTorque()
{ {
// We check if rootpart is null here because scripts don't delete if you delete the host. if (RootPart.PhysActor != null)
// This means that unfortunately, we can pass a null physics actor to Simulate!
// Make sure we don't do that!
SceneObjectPart rootpart = m_rootPart;
if (rootpart != null)
{ {
if (rootpart.PhysActor != null) if (!IsAttachment)
{ {
if (!IsAttachment) Vector3 torque = RootPart.PhysActor.Torque;
{ return torque;
Vector3 torque = rootpart.PhysActor.Torque;
return torque;
}
} }
} }
return Vector3.Zero; return Vector3.Zero;
} }
public void moveToTarget(Vector3 target, float tau) public void moveToTarget(Vector3 target, float tau)
{ {
SceneObjectPart rootpart = m_rootPart; if (IsAttachment)
if (rootpart != null)
{ {
if (IsAttachment) ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
if (avatar != null)
{ {
ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); avatar.MoveToTarget(target, false);
if (avatar != null)
{
avatar.MoveToTarget(target, false);
}
} }
else }
else
{
if (RootPart.PhysActor != null)
{ {
if (rootpart.PhysActor != null) RootPart.PhysActor.PIDTarget = target;
{ RootPart.PhysActor.PIDTau = tau;
rootpart.PhysActor.PIDTarget = target; RootPart.PhysActor.PIDActive = true;
rootpart.PhysActor.PIDTau = tau;
rootpart.PhysActor.PIDActive = true;
}
} }
} }
} }
public void stopMoveToTarget() public void stopMoveToTarget()
{ {
SceneObjectPart rootpart = m_rootPart; if (RootPart.PhysActor != null)
if (rootpart != null) RootPart.PhysActor.PIDActive = false;
{
if (rootpart.PhysActor != null)
{
rootpart.PhysActor.PIDActive = false;
}
}
} }
public void stopLookAt() public void stopLookAt()
{ {
SceneObjectPart rootpart = m_rootPart; if (RootPart.PhysActor != null)
if (rootpart != null) RootPart.PhysActor.APIDActive = false;
{
if (rootpart.PhysActor != null)
{
rootpart.PhysActor.APIDActive = false;
}
}
} }
/// <summary> /// <summary>
@ -1678,22 +1627,18 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="tau">Number of seconds over which to reach target</param> /// <param name="tau">Number of seconds over which to reach target</param>
public void SetHoverHeight(float height, PIDHoverType hoverType, float tau) public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
{ {
SceneObjectPart rootpart = m_rootPart; if (RootPart.PhysActor != null)
if (rootpart != null)
{ {
if (rootpart.PhysActor != null) if (height != 0f)
{ {
if (height != 0f) RootPart.PhysActor.PIDHoverHeight = height;
{ RootPart.PhysActor.PIDHoverType = hoverType;
rootpart.PhysActor.PIDHoverHeight = height; RootPart.PhysActor.PIDTau = tau;
rootpart.PhysActor.PIDHoverType = hoverType; RootPart.PhysActor.PIDHoverActive = true;
rootpart.PhysActor.PIDTau = tau; }
rootpart.PhysActor.PIDHoverActive = true; else
} {
else RootPart.PhysActor.PIDHoverActive = false;
{
rootpart.PhysActor.PIDHoverActive = false;
}
} }
} }
} }
@ -3056,28 +3001,23 @@ namespace OpenSim.Region.Framework.Scenes
int yaxis = 4; int yaxis = 4;
int zaxis = 8; int zaxis = 8;
if (m_rootPart != null) setX = ((axis & xaxis) != 0) ? true : false;
{ setY = ((axis & yaxis) != 0) ? true : false;
setX = ((axis & xaxis) != 0) ? true : false; setZ = ((axis & zaxis) != 0) ? true : false;
setY = ((axis & yaxis) != 0) ? true : false;
setZ = ((axis & zaxis) != 0) ? true : false;
float setval = (rotate10 > 0) ? 1f : 0f; float setval = (rotate10 > 0) ? 1f : 0f;
if (setX) if (setX)
m_rootPart.RotationAxis.X = setval; RootPart.RotationAxis.X = setval;
if (setY) if (setY)
m_rootPart.RotationAxis.Y = setval; RootPart.RotationAxis.Y = setval;
if (setZ) if (setZ)
m_rootPart.RotationAxis.Z = setval; RootPart.RotationAxis.Z = setval;
if (setX || setY || setZ) if (setX || setY || setZ)
{ RootPart.SetPhysicsAxisRotation();
m_rootPart.SetPhysicsAxisRotation();
}
}
} }
public int registerRotTargetWaypoint(Quaternion target, float tolerance) public int registerRotTargetWaypoint(Quaternion target, float tolerance)
{ {
scriptRotTarget waypoint = new scriptRotTarget(); scriptRotTarget waypoint = new scriptRotTarget();
@ -3205,7 +3145,13 @@ namespace OpenSim.Region.Framework.Scenes
foreach (uint idx in m_rotTargets.Keys) foreach (uint idx in m_rotTargets.Keys)
{ {
scriptRotTarget target = m_rotTargets[idx]; scriptRotTarget target = m_rotTargets[idx];
double angle = Math.Acos(target.targetRot.X * m_rootPart.RotationOffset.X + target.targetRot.Y * m_rootPart.RotationOffset.Y + target.targetRot.Z * m_rootPart.RotationOffset.Z + target.targetRot.W * m_rootPart.RotationOffset.W) * 2; double angle
= Math.Acos(
target.targetRot.X * m_rootPart.RotationOffset.X
+ target.targetRot.Y * m_rootPart.RotationOffset.Y
+ target.targetRot.Z * m_rootPart.RotationOffset.Z
+ target.targetRot.W * m_rootPart.RotationOffset.W)
* 2;
if (angle < 0) angle = -angle; if (angle < 0) angle = -angle;
if (angle > Math.PI) angle = (Math.PI * 2 - angle); if (angle > Math.PI) angle = (Math.PI * 2 - angle);
if (angle <= target.tolerance) if (angle <= target.tolerance)

View File

@ -381,7 +381,6 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
{ {
SceneObjectPart selectedTree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart; SceneObjectPart selectedTree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart;
m_scene.DeleteSceneObject(selectedTree.ParentGroup, false); m_scene.DeleteSceneObject(selectedTree.ParentGroup, false);
m_scene.ForEachClient(delegate(IClientAPI controller) m_scene.ForEachClient(delegate(IClientAPI controller)
{ {

View File

@ -2767,8 +2767,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// If either of these are null, then there was an unknown error. // If either of these are null, then there was an unknown error.
if (new_group == null) if (new_group == null)
continue; continue;
if (new_group.RootPart == null)
continue;
// objects rezzed with this method are die_at_edge by default. // objects rezzed with this method are die_at_edge by default.
new_group.RootPart.SetDieAtEdge(true); new_group.RootPart.SetDieAtEdge(true);
@ -6983,10 +6981,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
// we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
SceneObjectPart rootPart = part.ParentGroup.RootPart; SceneObjectPart rootPart = part.ParentGroup.RootPart;
if (rootPart != null) // better safe than sorry SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q));
{
SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q));
}
} }
break; break;

View File

@ -673,8 +673,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
if (m_host.ParentGroup.RootPart != null) m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
} }
// Teleport functions // Teleport functions

View File

@ -99,11 +99,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
m_log.Debug("Paid: " + objectID + " from " + agentID + ", amount " + amount); m_log.Debug("Paid: " + objectID + " from " + agentID + ", amount " + amount);
part = part.ParentGroup.RootPart; part = part.ParentGroup.RootPart;
money(part.LocalId, agentID, amount);
if (part != null)
{
money(part.LocalId, agentID, amount);
}
} }
/// <summary> /// <summary>