aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs63
1 files changed, 59 insertions, 4 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 92a5f2f..c76f869 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -45,6 +45,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin
45 * ForceVariableName: direct reference (store and fetch) to the value in the physics engine. 45 * ForceVariableName: direct reference (store and fetch) to the value in the physics engine.
46 * The last two (and certainly the last one) should be referenced only in taint-time. 46 * The last two (and certainly the last one) should be referenced only in taint-time.
47 */ 47 */
48
49/*
50 * As of 20121221, the following are the call sequences (going down) for different script physical functions:
51 * llApplyImpulse llApplyRotImpulse llSetTorque llSetForce
52 * SOP.ApplyImpulse SOP.ApplyAngularImpulse SOP.SetAngularImpulse SOP.SetForce
53 * SOG.ApplyImpulse SOG.ApplyAngularImpulse SOG.SetAngularImpulse
54 * PA.AddForce PA.AddAngularForce PA.Torque = v PA.Force = v
55 * BS.ApplyCentralForce BS.ApplyTorque
56 */
57
48public abstract class BSPhysObject : PhysicsActor 58public abstract class BSPhysObject : PhysicsActor
49{ 59{
50 protected BSPhysObject() 60 protected BSPhysObject()
@@ -69,6 +79,12 @@ public abstract class BSPhysObject : PhysicsActor
69 CollidingGroundStep = 0; 79 CollidingGroundStep = 0;
70 } 80 }
71 81
82 // Tell the object to clean up.
83 public virtual void Destroy()
84 {
85 UnRegisterAllPreStepActions();
86 }
87
72 public BSScene PhysicsScene { get; protected set; } 88 public BSScene PhysicsScene { get; protected set; }
73 // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor 89 // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor
74 public string PhysObjectName { get; protected set; } 90 public string PhysObjectName { get; protected set; }
@@ -130,9 +146,6 @@ public abstract class BSPhysObject : PhysicsActor
130 // Update the physical location and motion of the object. Called with data from Bullet. 146 // Update the physical location and motion of the object. Called with data from Bullet.
131 public abstract void UpdateProperties(EntityProperties entprop); 147 public abstract void UpdateProperties(EntityProperties entprop);
132 148
133 // Tell the object to clean up.
134 public abstract void Destroy();
135
136 public abstract OMV.Vector3 RawPosition { get; set; } 149 public abstract OMV.Vector3 RawPosition { get; set; }
137 public abstract OMV.Vector3 ForcePosition { get; set; } 150 public abstract OMV.Vector3 ForcePosition { get; set; }
138 151
@@ -140,7 +153,7 @@ public abstract class BSPhysObject : PhysicsActor
140 public abstract OMV.Quaternion ForceOrientation { get; set; } 153 public abstract OMV.Quaternion ForceOrientation { get; set; }
141 154
142 // The system is telling us the velocity it wants to move at. 155 // The system is telling us the velocity it wants to move at.
143 protected OMV.Vector3 m_targetVelocity; 156 // protected OMV.Vector3 m_targetVelocity; // use the definition in PhysicsActor
144 public override OMV.Vector3 TargetVelocity 157 public override OMV.Vector3 TargetVelocity
145 { 158 {
146 get { return m_targetVelocity; } 159 get { return m_targetVelocity; }
@@ -280,11 +293,53 @@ public abstract class BSPhysObject : PhysicsActor
280 293
281 #endregion // Collisions 294 #endregion // Collisions
282 295
296 #region Per Simulation Step actions
297 // There are some actions that must be performed for a physical object before each simulation step.
298 // These actions are optional so, rather than scanning all the physical objects and asking them
299 // if they have anything to do, a physical object registers for an event call before the step is performed.
300 // This bookkeeping makes it easy to add, remove and clean up after all these registrations.
301 private Dictionary<string, BSScene.PreStepAction> RegisteredActions = new Dictionary<string, BSScene.PreStepAction>();
302 protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn)
303 {
304 string identifier = op + "-" + id.ToString();
305 RegisteredActions[identifier] = actn;
306 PhysicsScene.BeforeStep += actn;
307 DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier);
308 }
309
310 // Unregister a pre step action. Safe to call if the action has not been registered.
311 protected void UnRegisterPreStepAction(string op, uint id)
312 {
313 string identifier = op + "-" + id.ToString();
314 bool removed = false;
315 if (RegisteredActions.ContainsKey(identifier))
316 {
317 PhysicsScene.BeforeStep -= RegisteredActions[identifier];
318 RegisteredActions.Remove(identifier);
319 removed = true;
320 }
321 DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed);
322 }
323
324 protected void UnRegisterAllPreStepActions()
325 {
326 foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredActions)
327 {
328 PhysicsScene.BeforeStep -= kvp.Value;
329 }
330 RegisteredActions.Clear();
331 DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID);
332 }
333
334
335 #endregion // Per Simulation Step actions
336
283 // High performance detailed logging routine used by the physical objects. 337 // High performance detailed logging routine used by the physical objects.
284 protected void DetailLog(string msg, params Object[] args) 338 protected void DetailLog(string msg, params Object[] args)
285 { 339 {
286 if (PhysicsScene.PhysicsLogging.Enabled) 340 if (PhysicsScene.PhysicsLogging.Enabled)
287 PhysicsScene.DetailLog(msg, args); 341 PhysicsScene.DetailLog(msg, args);
288 } 342 }
343
289} 344}
290} 345}