aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs22
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs6
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs105
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs12
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs4
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActors.cs49
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs3
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs35
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs22
10 files changed, 137 insertions, 123 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs
index 634a898..8416740 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs
@@ -67,14 +67,6 @@ public class BSActorAvatarMove : BSActor
67 { 67 {
68 m_physicsScene.DetailLog("{0},BSActorAvatarMove,refresh", m_controllingPrim.LocalID); 68 m_physicsScene.DetailLog("{0},BSActorAvatarMove,refresh", m_controllingPrim.LocalID);
69 69
70 // If not active any more, get rid of me (shouldn't ever happen, but just to be safe)
71 if (m_controllingPrim.RawForce == OMV.Vector3.Zero)
72 {
73 m_physicsScene.DetailLog("{0},BSActorAvatarMove,refresh,notAvatarMove,removing={1}", m_controllingPrim.LocalID, ActorName);
74 m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName);
75 return;
76 }
77
78 // If the object is physically active, add the hoverer prestep action 70 // If the object is physically active, add the hoverer prestep action
79 if (isActive) 71 if (isActive)
80 { 72 {
@@ -95,14 +87,19 @@ public class BSActorAvatarMove : BSActor
95 // Nothing to do for the hoverer since it is all software at pre-step action time. 87 // Nothing to do for the hoverer since it is all software at pre-step action time.
96 } 88 }
97 89
90 // Usually called when target velocity changes to set the current velocity and the target
91 // into the movement motor.
98 public void SetVelocityAndTarget(OMV.Vector3 vel, OMV.Vector3 targ, bool inTaintTime) 92 public void SetVelocityAndTarget(OMV.Vector3 vel, OMV.Vector3 targ, bool inTaintTime)
99 { 93 {
100 m_physicsScene.TaintedObject(inTaintTime, "BSActorAvatarMove.setVelocityAndTarget", delegate() 94 m_physicsScene.TaintedObject(inTaintTime, "BSActorAvatarMove.setVelocityAndTarget", delegate()
101 { 95 {
102 m_velocityMotor.Reset(); 96 if (m_velocityMotor != null)
103 m_velocityMotor.SetTarget(targ); 97 {
104 m_velocityMotor.SetCurrent(vel); 98 m_velocityMotor.Reset();
105 m_velocityMotor.Enabled = true; 99 m_velocityMotor.SetTarget(targ);
100 m_velocityMotor.SetCurrent(vel);
101 m_velocityMotor.Enabled = true;
102 }
106 }); 103 });
107 } 104 }
108 105
@@ -119,6 +116,7 @@ public class BSActorAvatarMove : BSActor
119 1f // efficiency 116 1f // efficiency
120 ); 117 );
121 // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. 118 // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages.
119 SetVelocityAndTarget(m_controllingPrim.RawVelocity, m_controllingPrim.TargetVelocity, true /* inTaintTime */);
122 120
123 m_physicsScene.BeforeStep += Mover; 121 m_physicsScene.BeforeStep += Mover;
124 } 122 }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs
index 8dd3700..e8310df 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs
@@ -67,12 +67,10 @@ public class BSActorHover : BSActor
67 { 67 {
68 m_physicsScene.DetailLog("{0},BSActorHover,refresh", m_controllingPrim.LocalID); 68 m_physicsScene.DetailLog("{0},BSActorHover,refresh", m_controllingPrim.LocalID);
69 69
70 // If not active any more, get rid of me (shouldn't ever happen, but just to be safe) 70 // If not active any more, turn me off
71 if (!m_controllingPrim.HoverActive) 71 if (!m_controllingPrim.HoverActive)
72 { 72 {
73 m_physicsScene.DetailLog("{0},BSActorHover,refresh,notHovering,removing={1}", m_controllingPrim.LocalID, ActorName); 73 SetEnabled(false);
74 m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName);
75 return;
76 } 74 }
77 75
78 // If the object is physically active, add the hoverer prestep action 76 // If the object is physically active, add the hoverer prestep action
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
index c40a499..09ee32b 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
@@ -36,7 +36,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
36{ 36{
37public class BSActorLockAxis : BSActor 37public class BSActorLockAxis : BSActor
38{ 38{
39 bool TryExperimentalLockAxisCode = true;
40 BSConstraint LockAxisConstraint = null; 39 BSConstraint LockAxisConstraint = null;
41 40
42 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) 41 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
@@ -69,18 +68,13 @@ public class BSActorLockAxis : BSActor
69 // If all the axis are free, we don't need to exist 68 // If all the axis are free, we don't need to exist
70 if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree) 69 if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree)
71 { 70 {
72 m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,allAxisFree,removing={1}", m_controllingPrim.LocalID, ActorName); 71 Enabled = false;
73 m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName);
74 return;
75 } 72 }
73
76 // If the object is physically active, add the axis locking constraint 74 // If the object is physically active, add the axis locking constraint
77 if (Enabled 75 if (isActive)
78 && m_controllingPrim.IsPhysicallyActive
79 && TryExperimentalLockAxisCode
80 && m_controllingPrim.LockedAxis != m_controllingPrim.LockedAxisFree)
81 { 76 {
82 if (LockAxisConstraint == null) 77 AddAxisLockConstraint();
83 AddAxisLockConstraint();
84 } 78 }
85 else 79 else
86 { 80 {
@@ -108,58 +102,61 @@ public class BSActorLockAxis : BSActor
108 102
109 private void AddAxisLockConstraint() 103 private void AddAxisLockConstraint()
110 { 104 {
111 // Lock that axis by creating a 6DOF constraint that has one end in the world and 105 if (LockAxisConstraint == null)
112 // the other in the object. 106 {
113 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 107 // Lock that axis by creating a 6DOF constraint that has one end in the world and
114 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 108 // the other in the object.
109 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817
110 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380
115 111
116 // Remove any existing axis constraint (just to be sure) 112 // Remove any existing axis constraint (just to be sure)
117 RemoveAxisLockConstraint(); 113 RemoveAxisLockConstraint();
118 114
119 BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, 115 BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody,
120 OMV.Vector3.Zero, OMV.Quaternion.Identity, 116 OMV.Vector3.Zero, OMV.Quaternion.Identity,
121 false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); 117 false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */);
122 LockAxisConstraint = axisConstrainer; 118 LockAxisConstraint = axisConstrainer;
123 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); 119 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint);
124 120
125 // The constraint is tied to the world and oriented to the prim. 121 // The constraint is tied to the world and oriented to the prim.
126 122
127 // Free to move linearly in the region 123 // Free to move linearly in the region
128 OMV.Vector3 linearLow = OMV.Vector3.Zero; 124 OMV.Vector3 linearLow = OMV.Vector3.Zero;
129 OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; 125 OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize;
130 axisConstrainer.SetLinearLimits(linearLow, linearHigh); 126 axisConstrainer.SetLinearLimits(linearLow, linearHigh);
131 127
132 // Angular with some axis locked 128 // Angular with some axis locked
133 float fPI = (float)Math.PI; 129 float fPI = (float)Math.PI;
134 OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); 130 OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI);
135 OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); 131 OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI);
136 if (m_controllingPrim.LockedAxis.X != 1f) 132 if (m_controllingPrim.LockedAxis.X != 1f)
137 { 133 {
138 angularLow.X = 0f; 134 angularLow.X = 0f;
139 angularHigh.X = 0f; 135 angularHigh.X = 0f;
140 } 136 }
141 if (m_controllingPrim.LockedAxis.Y != 1f) 137 if (m_controllingPrim.LockedAxis.Y != 1f)
142 { 138 {
143 angularLow.Y = 0f; 139 angularLow.Y = 0f;
144 angularHigh.Y = 0f; 140 angularHigh.Y = 0f;
145 } 141 }
146 if (m_controllingPrim.LockedAxis.Z != 1f) 142 if (m_controllingPrim.LockedAxis.Z != 1f)
147 { 143 {
148 angularLow.Z = 0f; 144 angularLow.Z = 0f;
149 angularHigh.Z = 0f; 145 angularHigh.Z = 0f;
150 } 146 }
151 if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) 147 if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh))
152 { 148 {
153 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); 149 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID);
154 } 150 }
155 151
156 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", 152 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}",
157 m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); 153 m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh);
158 154
159 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. 155 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo.
160 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); 156 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f);
161 157
162 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); 158 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass);
159 }
163 } 160 }
164 161
165 private void RemoveAxisLockConstraint() 162 private void RemoveAxisLockConstraint()
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs
index 3517ef2..16c2b14 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs
@@ -67,15 +67,12 @@ public class BSActorMoveToTarget : BSActor
67 { 67 {
68 m_physicsScene.DetailLog("{0},BSActorMoveToTarget,refresh", m_controllingPrim.LocalID); 68 m_physicsScene.DetailLog("{0},BSActorMoveToTarget,refresh", m_controllingPrim.LocalID);
69 69
70 // If not active any more, get rid of me (shouldn't ever happen, but just to be safe) 70 // If not active any more...
71 if (!m_controllingPrim.HoverActive) 71 if (!m_controllingPrim.MoveToTargetActive)
72 { 72 {
73 m_physicsScene.DetailLog("{0},BSActorMoveToTarget,refresh,notMoveToTarget,removing={1}", m_controllingPrim.LocalID, ActorName); 73 Enabled = false;
74 m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName);
75 return;
76 } 74 }
77 75
78 // If the object is physically active, add the hoverer prestep action
79 if (isActive) 76 if (isActive)
80 { 77 {
81 ActivateMoveToTarget(); 78 ActivateMoveToTarget();
@@ -92,7 +89,7 @@ public class BSActorMoveToTarget : BSActor
92 // BSActor.RemoveBodyDependencies() 89 // BSActor.RemoveBodyDependencies()
93 public override void RemoveBodyDependencies() 90 public override void RemoveBodyDependencies()
94 { 91 {
95 // Nothing to do for the hoverer since it is all software at pre-step action time. 92 // Nothing to do for the moveToTarget since it is all software at pre-step action time.
96 } 93 }
97 94
98 // If a hover motor has not been created, create one and start the hovering. 95 // If a hover motor has not been created, create one and start the hovering.
@@ -144,7 +141,6 @@ public class BSActorMoveToTarget : BSActor
144 m_physicsScene.DetailLog("{0},BSPrim.PIDTarget,zeroMovement,movePos={1},pos={2},mass={3}", 141 m_physicsScene.DetailLog("{0},BSPrim.PIDTarget,zeroMovement,movePos={1},pos={2},mass={3}",
145 m_controllingPrim.LocalID, movePosition, m_controllingPrim.RawPosition, m_controllingPrim.Mass); 142 m_controllingPrim.LocalID, movePosition, m_controllingPrim.RawPosition, m_controllingPrim.Mass);
146 m_controllingPrim.ForcePosition = m_targetMotor.TargetValue; 143 m_controllingPrim.ForcePosition = m_targetMotor.TargetValue;
147 m_targetMotor.Enabled = false;
148 } 144 }
149 else 145 else
150 { 146 {
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs
index d942490..3ad138d 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs
@@ -71,7 +71,7 @@ public class BSActorSetForce : BSActor
71 if (m_controllingPrim.RawForce == OMV.Vector3.Zero) 71 if (m_controllingPrim.RawForce == OMV.Vector3.Zero)
72 { 72 {
73 m_physicsScene.DetailLog("{0},BSActorSetForce,refresh,notSetForce,removing={1}", m_controllingPrim.LocalID, ActorName); 73 m_physicsScene.DetailLog("{0},BSActorSetForce,refresh,notSetForce,removing={1}", m_controllingPrim.LocalID, ActorName);
74 m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName); 74 Enabled = false;
75 return; 75 return;
76 } 76 }
77 77
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs
index e0f719f..159a3a8 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs
@@ -70,8 +70,8 @@ public class BSActorSetTorque : BSActor
70 // If not active any more, get rid of me (shouldn't ever happen, but just to be safe) 70 // If not active any more, get rid of me (shouldn't ever happen, but just to be safe)
71 if (m_controllingPrim.RawTorque == OMV.Vector3.Zero) 71 if (m_controllingPrim.RawTorque == OMV.Vector3.Zero)
72 { 72 {
73 m_physicsScene.DetailLog("{0},BSActorSetTorque,refresh,notSetTorque,removing={1}", m_controllingPrim.LocalID, ActorName); 73 m_physicsScene.DetailLog("{0},BSActorSetTorque,refresh,notSetTorque,disabling={1}", m_controllingPrim.LocalID, ActorName);
74 m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName); 74 Enabled = false;
75 return; 75 return;
76 } 76 }
77 77
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs
index fb4d452..12a8817 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs
@@ -42,24 +42,36 @@ public class BSActorCollection
42 } 42 }
43 public void Add(string name, BSActor actor) 43 public void Add(string name, BSActor actor)
44 { 44 {
45 m_actors[name] = actor; 45 lock (m_actors)
46 {
47 if (!m_actors.ContainsKey(name))
48 {
49 m_actors[name] = actor;
50 }
51 }
46 } 52 }
47 public bool RemoveAndRelease(string name) 53 public bool RemoveAndRelease(string name)
48 { 54 {
49 bool ret = false; 55 bool ret = false;
50 if (m_actors.ContainsKey(name)) 56 lock (m_actors)
51 { 57 {
52 BSActor beingRemoved = m_actors[name]; 58 if (m_actors.ContainsKey(name))
53 beingRemoved.Dispose(); 59 {
54 m_actors.Remove(name); 60 BSActor beingRemoved = m_actors[name];
55 ret = true; 61 m_actors.Remove(name);
62 beingRemoved.Dispose();
63 ret = true;
64 }
56 } 65 }
57 return ret; 66 return ret;
58 } 67 }
59 public void Clear() 68 public void Clear()
60 { 69 {
61 Release(); 70 lock (m_actors)
62 m_actors.Clear(); 71 {
72 Release();
73 m_actors.Clear();
74 }
63 } 75 }
64 public void Dispose() 76 public void Dispose()
65 { 77 {
@@ -69,15 +81,22 @@ public class BSActorCollection
69 { 81 {
70 return m_actors.ContainsKey(name); 82 return m_actors.ContainsKey(name);
71 } 83 }
84 public bool TryGetActor(string actorName, out BSActor theActor)
85 {
86 return m_actors.TryGetValue(actorName, out theActor);
87 }
72 public void ForEachActor(Action<BSActor> act) 88 public void ForEachActor(Action<BSActor> act)
73 { 89 {
74 foreach (KeyValuePair<string, BSActor> kvp in m_actors) 90 lock (m_actors)
75 act(kvp.Value); 91 {
92 foreach (KeyValuePair<string, BSActor> kvp in m_actors)
93 act(kvp.Value);
94 }
76 } 95 }
77 96
78 public void Enable(bool enabl) 97 public void Enable(bool enabl)
79 { 98 {
80 ForEachActor(a => a.Enable(enabl)); 99 ForEachActor(a => a.SetEnabled(enabl));
81 } 100 }
82 public void Release() 101 public void Release()
83 { 102 {
@@ -106,7 +125,7 @@ public abstract class BSActor
106{ 125{
107 protected BSScene m_physicsScene { get; private set; } 126 protected BSScene m_physicsScene { get; private set; }
108 protected BSPhysObject m_controllingPrim { get; private set; } 127 protected BSPhysObject m_controllingPrim { get; private set; }
109 protected bool Enabled { get; set; } 128 public virtual bool Enabled { get; set; }
110 public string ActorName { get; private set; } 129 public string ActorName { get; private set; }
111 130
112 public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) 131 public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName)
@@ -122,8 +141,10 @@ public abstract class BSActor
122 { 141 {
123 get { return Enabled; } 142 get { return Enabled; }
124 } 143 }
125 // Turn the actor on an off. 144
126 public virtual void Enable(bool setEnabled) 145 // Turn the actor on an off. Only used by ActorCollection to set all enabled/disabled.
146 // Anyone else should assign true/false to 'Enabled'.
147 public void SetEnabled(bool setEnabled)
127 { 148 {
128 Enabled = setEnabled; 149 Enabled = setEnabled;
129 } 150 }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 09c9b16..a0d58d3 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -160,6 +160,9 @@ public sealed class BSCharacter : BSPhysObject
160 // Make so capsule does not fall over 160 // Make so capsule does not fall over
161 PhysicsScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero); 161 PhysicsScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero);
162 162
163 // The avatar mover sets some parameters.
164 PhysicalActors.Refresh();
165
163 PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT); 166 PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT);
164 167
165 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); 168 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 644bc7e..64bf395 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -282,30 +282,31 @@ public abstract class BSPhysObject : PhysicsActor
282 282
283 // 'actors' act on the physical object to change or constrain its motion. These can range from 283 // 'actors' act on the physical object to change or constrain its motion. These can range from
284 // hovering to complex vehicle motion. 284 // hovering to complex vehicle motion.
285 // May be called at non-taint time as this just adds the actor to the action list and the real
286 // work is done during the simulation step.
287 // Note that, if the actor is already in the list and we are disabling same, the actor is just left
288 // in the list disabled.
285 public delegate BSActor CreateActor(); 289 public delegate BSActor CreateActor();
286 public void CreateRemoveActor(bool createRemove, string actorName, bool inTaintTime, CreateActor creator) 290 public void EnableActor(bool enableActor, string actorName, CreateActor creator)
287 { 291 {
288 if (createRemove) 292 lock (PhysicalActors)
289 { 293 {
290 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CreateRemoveActor:" + actorName, delegate() 294 BSActor theActor;
295 if (PhysicalActors.TryGetActor(actorName, out theActor))
291 { 296 {
292 if (!PhysicalActors.HasActor(actorName)) 297 // The actor already exists so just turn it on or off
293 { 298 theActor.Enabled = enableActor;
294 DetailLog("{0},BSPrim.CreateRemoveActor,taint,registerActor,a={1}", LocalID, actorName); 299 }
295 PhysicalActors.Add(actorName, creator()); 300 else
296 }
297 });
298 }
299 else
300 {
301 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CreateRemoveActor:" + actorName, delegate()
302 { 301 {
303 if (PhysicalActors.HasActor(actorName)) 302 // The actor does not exist. If it should, create it.
303 if (enableActor)
304 { 304 {
305 DetailLog("{0},BSPrim.CreateRemoveActor,taint,unregisterActor,a={1}", LocalID, actorName); 305 theActor = creator();
306 PhysicalActors.RemoveAndRelease(actorName); 306 PhysicalActors.Add(actorName, theActor);
307 theActor.Enabled = true;
307 } 308 }
308 }); 309 }
309 } 310 }
310 } 311 }
311 312
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 71fea59..16c7a90 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -95,6 +95,7 @@ public class BSPrim : BSPhysObject
95 _isPhysical = pisPhysical; 95 _isPhysical = pisPhysical;
96 _isVolumeDetect = false; 96 _isVolumeDetect = false;
97 97
98 // We keep a handle to the vehicle actor so we can set vehicle parameters later.
98 VehicleActor = new BSDynamics(PhysicsScene, this, VehicleActorName); 99 VehicleActor = new BSDynamics(PhysicsScene, this, VehicleActorName);
99 PhysicalActors.Add(VehicleActorName, VehicleActor); 100 PhysicalActors.Add(VehicleActorName, VehicleActor);
100 101
@@ -264,7 +265,7 @@ public class BSPrim : BSPhysObject
264 if (axis.Z != 1) locking.Z = 0f; 265 if (axis.Z != 1) locking.Z = 0f;
265 LockedAxis = locking; 266 LockedAxis = locking;
266 267
267 CreateRemoveActor(LockedAxis != LockedAxisFree /* creatActor */, LockedAxisActorName, false /* inTaintTime */, delegate() 268 EnableActor(LockedAxis != LockedAxisFree, LockedAxisActorName, delegate()
268 { 269 {
269 return new BSActorLockAxis(PhysicsScene, this, LockedAxisActorName); 270 return new BSActorLockAxis(PhysicsScene, this, LockedAxisActorName);
270 }); 271 });
@@ -501,7 +502,7 @@ public class BSPrim : BSPhysObject
501 get { return RawForce; } 502 get { return RawForce; }
502 set { 503 set {
503 RawForce = value; 504 RawForce = value;
504 CreateRemoveActor(RawForce == OMV.Vector3.Zero, SetForceActorName, false /* inTaintTime */, delegate() 505 EnableActor(RawForce != OMV.Vector3.Zero, SetForceActorName, delegate()
505 { 506 {
506 return new BSActorSetForce(PhysicsScene, this, SetForceActorName); 507 return new BSActorSetForce(PhysicsScene, this, SetForceActorName);
507 }); 508 });
@@ -510,14 +511,13 @@ public class BSPrim : BSPhysObject
510 511
511 public override int VehicleType { 512 public override int VehicleType {
512 get { 513 get {
513 return (int)VehicleActor.Type; // if we are a vehicle, return that type 514 return (int)VehicleActor.Type;
514 } 515 }
515 set { 516 set {
516 Vehicle type = (Vehicle)value; 517 Vehicle type = (Vehicle)value;
517 518
518 PhysicsScene.TaintedObject("setVehicleType", delegate() 519 PhysicsScene.TaintedObject("setVehicleType", delegate()
519 { 520 {
520 // Done at taint time so we're sure the physics engine is not using the variables
521 // Vehicle code changes the parameters for this vehicle type. 521 // Vehicle code changes the parameters for this vehicle type.
522 VehicleActor.ProcessTypeChange(type); 522 VehicleActor.ProcessTypeChange(type);
523 ActivateIfPhysical(false); 523 ActivateIfPhysical(false);
@@ -669,11 +669,11 @@ public class BSPrim : BSPhysObject
669 get { return RawTorque; } 669 get { return RawTorque; }
670 set { 670 set {
671 RawTorque = value; 671 RawTorque = value;
672 CreateRemoveActor(RawTorque == OMV.Vector3.Zero, SetTorqueActorName, false /* inTaintTime */, delegate() 672 EnableActor(RawTorque != OMV.Vector3.Zero, SetTorqueActorName, delegate()
673 { 673 {
674 return new BSActorSetTorque(PhysicsScene, this, SetTorqueActorName); 674 return new BSActorSetTorque(PhysicsScene, this, SetTorqueActorName);
675 }); 675 });
676 // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); 676 DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, RawTorque);
677 } 677 }
678 } 678 }
679 public override OMV.Vector3 Acceleration { 679 public override OMV.Vector3 Acceleration {
@@ -786,7 +786,6 @@ public class BSPrim : BSPhysObject
786 MakeDynamic(IsStatic); 786 MakeDynamic(IsStatic);
787 787
788 // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) 788 // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters)
789 VehicleActor.Refresh();
790 PhysicalActors.Refresh(); 789 PhysicalActors.Refresh();
791 790
792 // Arrange for collision events if the simulator wants them 791 // Arrange for collision events if the simulator wants them
@@ -1037,7 +1036,7 @@ public class BSPrim : BSPhysObject
1037 public override bool PIDActive { 1036 public override bool PIDActive {
1038 set { 1037 set {
1039 base.MoveToTargetActive = value; 1038 base.MoveToTargetActive = value;
1040 CreateRemoveActor(MoveToTargetActive, MoveToTargetActorName, false /* inTaintTime */, delegate() 1039 EnableActor(MoveToTargetActive, MoveToTargetActorName, delegate()
1041 { 1040 {
1042 return new BSActorMoveToTarget(PhysicsScene, this, MoveToTargetActorName); 1041 return new BSActorMoveToTarget(PhysicsScene, this, MoveToTargetActorName);
1043 }); 1042 });
@@ -1049,7 +1048,7 @@ public class BSPrim : BSPhysObject
1049 public override bool PIDHoverActive { 1048 public override bool PIDHoverActive {
1050 set { 1049 set {
1051 base.HoverActive = value; 1050 base.HoverActive = value;
1052 CreateRemoveActor(HoverActive /* creatActor */, HoverActorName, false /* inTaintTime */, delegate() 1051 EnableActor(HoverActive, HoverActorName, delegate()
1053 { 1052 {
1054 return new BSActorHover(PhysicsScene, this, HoverActorName); 1053 return new BSActorHover(PhysicsScene, this, HoverActorName);
1055 }); 1054 });
@@ -1458,7 +1457,7 @@ public class BSPrim : BSPhysObject
1458 { 1457 {
1459 // Create the correct physical representation for this type of object. 1458 // Create the correct physical representation for this type of object.
1460 // Updates base.PhysBody and base.PhysShape with the new information. 1459 // Updates base.PhysBody and base.PhysShape with the new information.
1461 // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. 1460 // Ignore 'forceRebuild'. 'GetBodyAndShape' makes the right choices and changes of necessary.
1462 PhysicsScene.Shapes.GetBodyAndShape(false /*forceRebuild */, PhysicsScene.World, this, null, delegate(BulletBody dBody) 1461 PhysicsScene.Shapes.GetBodyAndShape(false /*forceRebuild */, PhysicsScene.World, this, null, delegate(BulletBody dBody)
1463 { 1462 {
1464 // Called if the current prim body is about to be destroyed. 1463 // Called if the current prim body is about to be destroyed.
@@ -1472,9 +1471,9 @@ public class BSPrim : BSPhysObject
1472 return; 1471 return;
1473 } 1472 }
1474 1473
1474 // Called at taint-time
1475 protected virtual void RemoveBodyDependencies() 1475 protected virtual void RemoveBodyDependencies()
1476 { 1476 {
1477 VehicleActor.RemoveBodyDependencies();
1478 PhysicalActors.RemoveBodyDependencies(); 1477 PhysicalActors.RemoveBodyDependencies();
1479 } 1478 }
1480 1479
@@ -1482,6 +1481,7 @@ public class BSPrim : BSPhysObject
1482 // the world that things have changed. 1481 // the world that things have changed.
1483 public override void UpdateProperties(EntityProperties entprop) 1482 public override void UpdateProperties(EntityProperties entprop)
1484 { 1483 {
1484 // Let anyone (like the actors) modify the updated properties before they are pushed into the object and the simulator.
1485 TriggerPreUpdatePropertyAction(ref entprop); 1485 TriggerPreUpdatePropertyAction(ref entprop);
1486 1486
1487 // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG 1487 // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG