From aea700753361621f25a3e22f4176fcd2cc981b9f Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sun, 31 Jul 2011 02:50:50 +0100 Subject: refactor: split out ninja joint part of SOP.DoPhysicsPropertyUpdate() so that we don't have to look at it if it's not relevant --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 157 +++++++++++---------- 1 file changed, 86 insertions(+), 71 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 58fc6fc..7c9636a 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1751,96 +1751,111 @@ namespace OpenSim.Region.Framework.Scenes return part; } - public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew) + /// + /// Do a physics property update for a NINJA joint. + /// + /// + /// + protected void DoPhysicsPropertyUpdateForNinjaJoint(bool UsePhysics, bool isNew) { - if (IsJoint()) + if (UsePhysics) { - if (UsePhysics) - { - // by turning a joint proxy object physical, we cause creation of a joint in the ODE scene. - // note that, as a special case, joints have no bodies or geoms in the physics scene, even though they are physical. + // by turning a joint proxy object physical, we cause creation of a joint in the ODE scene. + // note that, as a special case, joints have no bodies or geoms in the physics scene, even though they are physical. - PhysicsJointType jointType; - if (IsHingeJoint()) - { - jointType = PhysicsJointType.Hinge; - } - else if (IsBallJoint()) - { - jointType = PhysicsJointType.Ball; - } - else - { - jointType = PhysicsJointType.Ball; - } + PhysicsJointType jointType; + if (IsHingeJoint()) + { + jointType = PhysicsJointType.Hinge; + } + else if (IsBallJoint()) + { + jointType = PhysicsJointType.Ball; + } + else + { + jointType = PhysicsJointType.Ball; + } - List bodyNames = new List(); - string RawParams = Description; - string[] jointParams = RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); - string trackedBodyName = null; - if (jointParams.Length >= 2) + List bodyNames = new List(); + string RawParams = Description; + string[] jointParams = RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); + string trackedBodyName = null; + if (jointParams.Length >= 2) + { + for (int iBodyName = 0; iBodyName < 2; iBodyName++) { - for (int iBodyName = 0; iBodyName < 2; iBodyName++) + string bodyName = jointParams[iBodyName]; + bodyNames.Add(bodyName); + if (bodyName != "NULL") { - string bodyName = jointParams[iBodyName]; - bodyNames.Add(bodyName); - if (bodyName != "NULL") + if (trackedBodyName == null) { - if (trackedBodyName == null) - { - trackedBodyName = bodyName; - } + trackedBodyName = bodyName; } } } + } - SceneObjectPart trackedBody = m_parentGroup.Scene.GetSceneObjectPart(trackedBodyName); // FIXME: causes a sequential lookup - Quaternion localRotation = Quaternion.Identity; - if (trackedBody != null) - { - localRotation = Quaternion.Inverse(trackedBody.RotationOffset) * this.RotationOffset; - } - else - { - // error, output it below - } + SceneObjectPart trackedBody = m_parentGroup.Scene.GetSceneObjectPart(trackedBodyName); // FIXME: causes a sequential lookup + Quaternion localRotation = Quaternion.Identity; + if (trackedBody != null) + { + localRotation = Quaternion.Inverse(trackedBody.RotationOffset) * this.RotationOffset; + } + else + { + // error, output it below + } - PhysicsJoint joint; + PhysicsJoint joint; - joint = m_parentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType, - AbsolutePosition, - this.RotationOffset, - Description, - bodyNames, - trackedBodyName, - localRotation); + joint = m_parentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType, + AbsolutePosition, + this.RotationOffset, + Description, + bodyNames, + trackedBodyName, + localRotation); - if (trackedBody == null) - { - ParentGroup.Scene.jointErrorMessage(joint, "warning: tracked body name not found! joint location will not be updated properly. joint: " + Name); - } + if (trackedBody == null) + { + ParentGroup.Scene.jointErrorMessage(joint, "warning: tracked body name not found! joint location will not be updated properly. joint: " + Name); + } + } + else + { + if (isNew) + { + // if the joint proxy is new, and it is not physical, do nothing. There is no joint in ODE to + // delete, and if we try to delete it, due to asynchronous processing, the deletion request + // will get processed later at an indeterminate time, which could cancel a later-arriving + // joint creation request. } else { - if (isNew) - { - // if the joint proxy is new, and it is not physical, do nothing. There is no joint in ODE to - // delete, and if we try to delete it, due to asynchronous processing, the deletion request - // will get processed later at an indeterminate time, which could cancel a later-arriving - // joint creation request. - } - else - { - // here we turn off the joint object, so remove the joint from the physics scene - m_parentGroup.Scene.PhysicsScene.RequestJointDeletion(Name); // FIXME: what if the name changed? + // here we turn off the joint object, so remove the joint from the physics scene + m_parentGroup.Scene.PhysicsScene.RequestJointDeletion(Name); // FIXME: what if the name changed? - // make sure client isn't interpolating the joint proxy object - Velocity = Vector3.Zero; - AngularVelocity = Vector3.Zero; - Acceleration = Vector3.Zero; - } + // make sure client isn't interpolating the joint proxy object + Velocity = Vector3.Zero; + AngularVelocity = Vector3.Zero; + Acceleration = Vector3.Zero; } } + } + + /// + /// Do a physics propery update for this part. + /// + /// + /// + public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew) + { + if (IsJoint()) + { + DoPhysicsPropertyUpdateForNinjaJoint(UsePhysics, isNew); + } else { if (PhysActor != null) @@ -4699,7 +4714,7 @@ namespace OpenSim.Region.Framework.Scenes /// public void CheckSculptAndLoad() { -// m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId); + m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId); if (ParentGroup.IsDeleted) return; -- cgit v1.1