diff options
author | Justin Clark-Casey (justincc) | 2011-09-01 02:09:41 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-09-01 02:11:00 +0100 |
commit | 7eca929686bd2db1cb42f5c9740fd1d186cdc8b1 (patch) | |
tree | 775f07f365acb56bc6043831d5832c2dac468ade /OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | |
parent | refactor: use ParentGroup.UUID directly instead of SOP.GetRootPartUUID() (diff) | |
download | opensim-SC-7eca929686bd2db1cb42f5c9740fd1d186cdc8b1.zip opensim-SC-7eca929686bd2db1cb42f5c9740fd1d186cdc8b1.tar.gz opensim-SC-7eca929686bd2db1cb42f5c9740fd1d186cdc8b1.tar.bz2 opensim-SC-7eca929686bd2db1cb42f5c9740fd1d186cdc8b1.tar.xz |
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
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | 194 |
1 files changed, 70 insertions, 124 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 74e8783..fca42c8 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | |||
@@ -254,14 +254,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
254 | /// </summary> | 254 | /// </summary> |
255 | public override string Name | 255 | public override string Name |
256 | { | 256 | { |
257 | get | 257 | get { return RootPart.Name; } |
258 | { | ||
259 | if (RootPart == null) | ||
260 | return String.Empty; | ||
261 | else | ||
262 | return RootPart.Name; | ||
263 | } | ||
264 | |||
265 | set { RootPart.Name = value; } | 258 | set { RootPart.Name = value; } |
266 | } | 259 | } |
267 | 260 | ||
@@ -1054,7 +1047,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1054 | { | 1047 | { |
1055 | part.SetParent(this); | 1048 | part.SetParent(this); |
1056 | part.LinkNum = m_parts.Add(part.UUID, part); | 1049 | part.LinkNum = m_parts.Add(part.UUID, part); |
1057 | if (part.LinkNum == 2 && RootPart != null) | 1050 | if (part.LinkNum == 2) |
1058 | RootPart.LinkNum = 1; | 1051 | RootPart.LinkNum = 1; |
1059 | } | 1052 | } |
1060 | 1053 | ||
@@ -1537,137 +1530,93 @@ namespace OpenSim.Region.Framework.Scenes | |||
1537 | 1530 | ||
1538 | public void applyImpulse(Vector3 impulse) | 1531 | public void applyImpulse(Vector3 impulse) |
1539 | { | 1532 | { |
1540 | // We check if rootpart is null here because scripts don't delete if you delete the host. | 1533 | if (IsAttachment) |
1541 | // This means that unfortunately, we can pass a null physics actor to Simulate! | ||
1542 | // Make sure we don't do that! | ||
1543 | SceneObjectPart rootpart = m_rootPart; | ||
1544 | if (rootpart != null) | ||
1545 | { | 1534 | { |
1546 | if (IsAttachment) | 1535 | ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); |
1536 | if (avatar != null) | ||
1547 | { | 1537 | { |
1548 | ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); | 1538 | avatar.PushForce(impulse); |
1549 | if (avatar != null) | ||
1550 | { | ||
1551 | avatar.PushForce(impulse); | ||
1552 | } | ||
1553 | } | 1539 | } |
1554 | else | 1540 | } |
1541 | else | ||
1542 | { | ||
1543 | if (RootPart.PhysActor != null) | ||
1555 | { | 1544 | { |
1556 | if (rootpart.PhysActor != null) | 1545 | RootPart.PhysActor.AddForce(impulse, true); |
1557 | { | 1546 | m_scene.PhysicsScene.AddPhysicsActorTaint(RootPart.PhysActor); |
1558 | rootpart.PhysActor.AddForce(impulse, true); | ||
1559 | m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor); | ||
1560 | } | ||
1561 | } | 1547 | } |
1562 | } | 1548 | } |
1563 | } | 1549 | } |
1564 | 1550 | ||
1565 | public void applyAngularImpulse(Vector3 impulse) | 1551 | public void applyAngularImpulse(Vector3 impulse) |
1566 | { | 1552 | { |
1567 | // We check if rootpart is null here because scripts don't delete if you delete the host. | 1553 | if (RootPart.PhysActor != null) |
1568 | // This means that unfortunately, we can pass a null physics actor to Simulate! | ||
1569 | // Make sure we don't do that! | ||
1570 | SceneObjectPart rootpart = m_rootPart; | ||
1571 | if (rootpart != null) | ||
1572 | { | 1554 | { |
1573 | if (rootpart.PhysActor != null) | 1555 | if (!IsAttachment) |
1574 | { | 1556 | { |
1575 | if (!IsAttachment) | 1557 | RootPart.PhysActor.AddAngularForce(impulse, true); |
1576 | { | 1558 | m_scene.PhysicsScene.AddPhysicsActorTaint(RootPart.PhysActor); |
1577 | rootpart.PhysActor.AddAngularForce(impulse, true); | ||
1578 | m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor); | ||
1579 | } | ||
1580 | } | 1559 | } |
1581 | } | 1560 | } |
1582 | } | 1561 | } |
1583 | 1562 | ||
1584 | public void setAngularImpulse(Vector3 impulse) | 1563 | public void setAngularImpulse(Vector3 impulse) |
1585 | { | 1564 | { |
1586 | // We check if rootpart is null here because scripts don't delete if you delete the host. | 1565 | if (RootPart.PhysActor != null) |
1587 | // This means that unfortunately, we can pass a null physics actor to Simulate! | ||
1588 | // Make sure we don't do that! | ||
1589 | SceneObjectPart rootpart = m_rootPart; | ||
1590 | if (rootpart != null) | ||
1591 | { | 1566 | { |
1592 | if (rootpart.PhysActor != null) | 1567 | if (!IsAttachment) |
1593 | { | 1568 | { |
1594 | if (!IsAttachment) | 1569 | RootPart.PhysActor.Torque = impulse; |
1595 | { | 1570 | m_scene.PhysicsScene.AddPhysicsActorTaint(RootPart.PhysActor); |
1596 | rootpart.PhysActor.Torque = impulse; | ||
1597 | m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor); | ||
1598 | } | ||
1599 | } | 1571 | } |
1600 | } | 1572 | } |
1601 | } | 1573 | } |
1602 | 1574 | ||
1603 | public Vector3 GetTorque() | 1575 | public Vector3 GetTorque() |
1604 | { | 1576 | { |
1605 | // We check if rootpart is null here because scripts don't delete if you delete the host. | 1577 | if (RootPart.PhysActor != null) |
1606 | // This means that unfortunately, we can pass a null physics actor to Simulate! | ||
1607 | // Make sure we don't do that! | ||
1608 | SceneObjectPart rootpart = m_rootPart; | ||
1609 | if (rootpart != null) | ||
1610 | { | 1578 | { |
1611 | if (rootpart.PhysActor != null) | 1579 | if (!IsAttachment) |
1612 | { | 1580 | { |
1613 | if (!IsAttachment) | 1581 | Vector3 torque = RootPart.PhysActor.Torque; |
1614 | { | 1582 | return torque; |
1615 | Vector3 torque = rootpart.PhysActor.Torque; | ||
1616 | return torque; | ||
1617 | } | ||
1618 | } | 1583 | } |
1619 | } | 1584 | } |
1585 | |||
1620 | return Vector3.Zero; | 1586 | return Vector3.Zero; |
1621 | } | 1587 | } |
1622 | 1588 | ||
1623 | public void moveToTarget(Vector3 target, float tau) | 1589 | public void moveToTarget(Vector3 target, float tau) |
1624 | { | 1590 | { |
1625 | SceneObjectPart rootpart = m_rootPart; | 1591 | if (IsAttachment) |
1626 | if (rootpart != null) | ||
1627 | { | 1592 | { |
1628 | if (IsAttachment) | 1593 | ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); |
1594 | if (avatar != null) | ||
1629 | { | 1595 | { |
1630 | ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); | 1596 | avatar.MoveToTarget(target, false); |
1631 | if (avatar != null) | ||
1632 | { | ||
1633 | avatar.MoveToTarget(target, false); | ||
1634 | } | ||
1635 | } | 1597 | } |
1636 | else | 1598 | } |
1599 | else | ||
1600 | { | ||
1601 | if (RootPart.PhysActor != null) | ||
1637 | { | 1602 | { |
1638 | if (rootpart.PhysActor != null) | 1603 | RootPart.PhysActor.PIDTarget = target; |
1639 | { | 1604 | RootPart.PhysActor.PIDTau = tau; |
1640 | rootpart.PhysActor.PIDTarget = target; | 1605 | RootPart.PhysActor.PIDActive = true; |
1641 | rootpart.PhysActor.PIDTau = tau; | ||
1642 | rootpart.PhysActor.PIDActive = true; | ||
1643 | } | ||
1644 | } | 1606 | } |
1645 | } | 1607 | } |
1646 | } | 1608 | } |
1647 | 1609 | ||
1648 | public void stopMoveToTarget() | 1610 | public void stopMoveToTarget() |
1649 | { | 1611 | { |
1650 | SceneObjectPart rootpart = m_rootPart; | 1612 | if (RootPart.PhysActor != null) |
1651 | if (rootpart != null) | 1613 | RootPart.PhysActor.PIDActive = false; |
1652 | { | ||
1653 | if (rootpart.PhysActor != null) | ||
1654 | { | ||
1655 | rootpart.PhysActor.PIDActive = false; | ||
1656 | } | ||
1657 | } | ||
1658 | } | 1614 | } |
1659 | 1615 | ||
1660 | public void stopLookAt() | 1616 | public void stopLookAt() |
1661 | { | 1617 | { |
1662 | SceneObjectPart rootpart = m_rootPart; | 1618 | if (RootPart.PhysActor != null) |
1663 | if (rootpart != null) | 1619 | RootPart.PhysActor.APIDActive = false; |
1664 | { | ||
1665 | if (rootpart.PhysActor != null) | ||
1666 | { | ||
1667 | rootpart.PhysActor.APIDActive = false; | ||
1668 | } | ||
1669 | } | ||
1670 | |||
1671 | } | 1620 | } |
1672 | 1621 | ||
1673 | /// <summary> | 1622 | /// <summary> |
@@ -1678,22 +1627,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
1678 | /// <param name="tau">Number of seconds over which to reach target</param> | 1627 | /// <param name="tau">Number of seconds over which to reach target</param> |
1679 | public void SetHoverHeight(float height, PIDHoverType hoverType, float tau) | 1628 | public void SetHoverHeight(float height, PIDHoverType hoverType, float tau) |
1680 | { | 1629 | { |
1681 | SceneObjectPart rootpart = m_rootPart; | 1630 | if (RootPart.PhysActor != null) |
1682 | if (rootpart != null) | ||
1683 | { | 1631 | { |
1684 | if (rootpart.PhysActor != null) | 1632 | if (height != 0f) |
1685 | { | 1633 | { |
1686 | if (height != 0f) | 1634 | RootPart.PhysActor.PIDHoverHeight = height; |
1687 | { | 1635 | RootPart.PhysActor.PIDHoverType = hoverType; |
1688 | rootpart.PhysActor.PIDHoverHeight = height; | 1636 | RootPart.PhysActor.PIDTau = tau; |
1689 | rootpart.PhysActor.PIDHoverType = hoverType; | 1637 | RootPart.PhysActor.PIDHoverActive = true; |
1690 | rootpart.PhysActor.PIDTau = tau; | 1638 | } |
1691 | rootpart.PhysActor.PIDHoverActive = true; | 1639 | else |
1692 | } | 1640 | { |
1693 | else | 1641 | RootPart.PhysActor.PIDHoverActive = false; |
1694 | { | ||
1695 | rootpart.PhysActor.PIDHoverActive = false; | ||
1696 | } | ||
1697 | } | 1642 | } |
1698 | } | 1643 | } |
1699 | } | 1644 | } |
@@ -3056,28 +3001,23 @@ namespace OpenSim.Region.Framework.Scenes | |||
3056 | int yaxis = 4; | 3001 | int yaxis = 4; |
3057 | int zaxis = 8; | 3002 | int zaxis = 8; |
3058 | 3003 | ||
3059 | if (m_rootPart != null) | 3004 | setX = ((axis & xaxis) != 0) ? true : false; |
3060 | { | 3005 | setY = ((axis & yaxis) != 0) ? true : false; |
3061 | setX = ((axis & xaxis) != 0) ? true : false; | 3006 | setZ = ((axis & zaxis) != 0) ? true : false; |
3062 | setY = ((axis & yaxis) != 0) ? true : false; | ||
3063 | setZ = ((axis & zaxis) != 0) ? true : false; | ||
3064 | |||
3065 | float setval = (rotate10 > 0) ? 1f : 0f; | ||
3066 | 3007 | ||
3067 | if (setX) | 3008 | float setval = (rotate10 > 0) ? 1f : 0f; |
3068 | m_rootPart.RotationAxis.X = setval; | ||
3069 | if (setY) | ||
3070 | m_rootPart.RotationAxis.Y = setval; | ||
3071 | if (setZ) | ||
3072 | m_rootPart.RotationAxis.Z = setval; | ||
3073 | 3009 | ||
3074 | if (setX || setY || setZ) | 3010 | if (setX) |
3075 | { | 3011 | RootPart.RotationAxis.X = setval; |
3076 | m_rootPart.SetPhysicsAxisRotation(); | 3012 | if (setY) |
3077 | } | 3013 | RootPart.RotationAxis.Y = setval; |
3014 | if (setZ) | ||
3015 | RootPart.RotationAxis.Z = setval; | ||
3078 | 3016 | ||
3079 | } | 3017 | if (setX || setY || setZ) |
3018 | RootPart.SetPhysicsAxisRotation(); | ||
3080 | } | 3019 | } |
3020 | |||
3081 | public int registerRotTargetWaypoint(Quaternion target, float tolerance) | 3021 | public int registerRotTargetWaypoint(Quaternion target, float tolerance) |
3082 | { | 3022 | { |
3083 | scriptRotTarget waypoint = new scriptRotTarget(); | 3023 | scriptRotTarget waypoint = new scriptRotTarget(); |
@@ -3205,7 +3145,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
3205 | foreach (uint idx in m_rotTargets.Keys) | 3145 | foreach (uint idx in m_rotTargets.Keys) |
3206 | { | 3146 | { |
3207 | scriptRotTarget target = m_rotTargets[idx]; | 3147 | scriptRotTarget target = m_rotTargets[idx]; |
3208 | 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; | 3148 | double angle |
3149 | = Math.Acos( | ||
3150 | target.targetRot.X * m_rootPart.RotationOffset.X | ||
3151 | + target.targetRot.Y * m_rootPart.RotationOffset.Y | ||
3152 | + target.targetRot.Z * m_rootPart.RotationOffset.Z | ||
3153 | + target.targetRot.W * m_rootPart.RotationOffset.W) | ||
3154 | * 2; | ||
3209 | if (angle < 0) angle = -angle; | 3155 | if (angle < 0) angle = -angle; |
3210 | if (angle > Math.PI) angle = (Math.PI * 2 - angle); | 3156 | if (angle > Math.PI) angle = (Math.PI * 2 - angle); |
3211 | if (angle <= target.tolerance) | 3157 | if (angle <= target.tolerance) |