diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 92a5f2f..9525a11 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 | |||
48 | public abstract class BSPhysObject : PhysicsActor | 58 | public 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 | ||
@@ -280,11 +293,48 @@ 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 | } | ||
308 | |||
309 | // Unregister a pre step action. Safe to call if the action has not been registered. | ||
310 | protected void UnRegisterPreStepAction(string op, uint id) | ||
311 | { | ||
312 | string identifier = op + "-" + id.ToString(); | ||
313 | if (RegisteredActions.ContainsKey(identifier)) | ||
314 | { | ||
315 | PhysicsScene.BeforeStep -= RegisteredActions[identifier]; | ||
316 | RegisteredActions.Remove(identifier); | ||
317 | } | ||
318 | } | ||
319 | |||
320 | protected void UnRegisterAllPreStepActions() | ||
321 | { | ||
322 | foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredActions) | ||
323 | { | ||
324 | PhysicsScene.BeforeStep -= kvp.Value; | ||
325 | } | ||
326 | RegisteredActions.Clear(); | ||
327 | } | ||
328 | |||
329 | |||
330 | #endregion // Per Simulation Step actions | ||
331 | |||
283 | // High performance detailed logging routine used by the physical objects. | 332 | // High performance detailed logging routine used by the physical objects. |
284 | protected void DetailLog(string msg, params Object[] args) | 333 | protected void DetailLog(string msg, params Object[] args) |
285 | { | 334 | { |
286 | if (PhysicsScene.PhysicsLogging.Enabled) | 335 | if (PhysicsScene.PhysicsLogging.Enabled) |
287 | PhysicsScene.DetailLog(msg, args); | 336 | PhysicsScene.DetailLog(msg, args); |
288 | } | 337 | } |
338 | |||
289 | } | 339 | } |
290 | } | 340 | } |