aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
diff options
context:
space:
mode:
authorRobert Adams2013-04-07 08:27:49 -0700
committerRobert Adams2013-04-08 06:27:43 -0700
commitfe16dc09da3f2736fad5a9e792f5f81098b5f9a1 (patch)
tree14df85296a103e7326726ccfb9a017bc9ecb669f /OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
parentOptimize the number of Simian calls to get the initial presence (diff)
downloadopensim-SC_OLD-fe16dc09da3f2736fad5a9e792f5f81098b5f9a1.zip
opensim-SC_OLD-fe16dc09da3f2736fad5a9e792f5f81098b5f9a1.tar.gz
opensim-SC_OLD-fe16dc09da3f2736fad5a9e792f5f81098b5f9a1.tar.bz2
opensim-SC_OLD-fe16dc09da3f2736fad5a9e792f5f81098b5f9a1.tar.xz
BulletSim: complete movement of physical object action code out of the
physical object and into actors for setForce, setTorque, hover, lock axis and avatar move.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs226
1 files changed, 80 insertions, 146 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 98ea833..644bc7e 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -43,7 +43,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
43 * VariableName: used by the simulator and performs taint operations, etc 43 * VariableName: used by the simulator and performs taint operations, etc
44 * RawVariableName: direct reference to the BulletSim storage for the variable value 44 * RawVariableName: direct reference to the BulletSim storage for the variable value
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 one should only be referenced in taint-time.
47 */ 47 */
48 48
49/* 49/*
@@ -84,6 +84,7 @@ public abstract class BSPhysObject : PhysicsActor
84 // Initialize variables kept in base. 84 // Initialize variables kept in base.
85 GravModifier = 1.0f; 85 GravModifier = 1.0f;
86 Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); 86 Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity);
87 HoverActive = false;
87 88
88 // We don't have any physical representation yet. 89 // We don't have any physical representation yet.
89 PhysBody = new BulletBody(localID); 90 PhysBody = new BulletBody(localID);
@@ -110,11 +111,10 @@ public abstract class BSPhysObject : PhysicsActor
110 // Tell the object to clean up. 111 // Tell the object to clean up.
111 public virtual void Destroy() 112 public virtual void Destroy()
112 { 113 {
113 UnRegisterAllPreStepActions(); 114 PhysicalActors.Enable(false);
114 UnRegisterAllPostStepActions();
115 PhysicsScene.TaintedObject("BSPhysObject.Destroy", delegate() 115 PhysicsScene.TaintedObject("BSPhysObject.Destroy", delegate()
116 { 116 {
117 PhysicalActors.Release(); 117 PhysicalActors.Dispose();
118 }); 118 });
119 } 119 }
120 120
@@ -203,15 +203,48 @@ public abstract class BSPhysObject : PhysicsActor
203 public abstract OMV.Quaternion RawOrientation { get; set; } 203 public abstract OMV.Quaternion RawOrientation { get; set; }
204 public abstract OMV.Quaternion ForceOrientation { get; set; } 204 public abstract OMV.Quaternion ForceOrientation { get; set; }
205 205
206 public abstract OMV.Vector3 RawVelocity { get; set; } 206 public OMV.Vector3 RawVelocity { get; set; }
207 public abstract OMV.Vector3 ForceVelocity { get; set; } 207 public abstract OMV.Vector3 ForceVelocity { get; set; }
208 208
209 public OMV.Vector3 RawForce { get; set; }
210 public OMV.Vector3 RawTorque { get; set; }
211 public override void AddAngularForce(OMV.Vector3 force, bool pushforce)
212 {
213 AddAngularForce(force, pushforce, false);
214 }
215 public abstract void AddAngularForce(OMV.Vector3 force, bool pushforce, bool inTaintTime);
216
209 public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } 217 public abstract OMV.Vector3 ForceRotationalVelocity { get; set; }
210 218
211 public abstract float ForceBuoyancy { get; set; } 219 public abstract float ForceBuoyancy { get; set; }
212 220
213 public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } 221 public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; }
214 222
223 public override bool PIDActive { set { MoveToTargetActive = value; } }
224 public override OMV.Vector3 PIDTarget { set { MoveToTargetTarget = value; } }
225 public override float PIDTau { set { MoveToTargetTau = value; } }
226
227 public bool MoveToTargetActive { get; set; }
228 public OMV.Vector3 MoveToTargetTarget { get; set; }
229 public float MoveToTargetTau { get; set; }
230
231 // Used for llSetHoverHeight and maybe vehicle height. Hover Height will override MoveTo target's Z
232 public override bool PIDHoverActive { set { HoverActive = value; } }
233 public override float PIDHoverHeight { set { HoverHeight = value; } }
234 public override PIDHoverType PIDHoverType { set { HoverType = value; } }
235 public override float PIDHoverTau { set { HoverTau = value; } }
236
237 public bool HoverActive { get; set; }
238 public float HoverHeight { get; set; }
239 public PIDHoverType HoverType { get; set; }
240 public float HoverTau { get; set; }
241
242 // For RotLookAt
243 public override OMV.Quaternion APIDTarget { set { return; } }
244 public override bool APIDActive { set { return; } }
245 public override float APIDStrength { set { return; } }
246 public override float APIDDamping { set { return; } }
247
215 // The current velocity forward 248 // The current velocity forward
216 public virtual float ForwardSpeed 249 public virtual float ForwardSpeed
217 { 250 {
@@ -237,7 +270,44 @@ public abstract class BSPhysObject : PhysicsActor
237 270
238 public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free. 271 public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free.
239 public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free 272 public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free
240 public readonly String LockedAxisActorName = "BSPrim.LockedAxis"; 273
274 // Enable physical actions. Bullet will keep sleeping non-moving physical objects so
275 // they need waking up when parameters are changed.
276 // Called in taint-time!!
277 public void ActivateIfPhysical(bool forceIt)
278 {
279 if (IsPhysical && PhysBody.HasPhysicalBody)
280 PhysicsScene.PE.Activate(PhysBody, forceIt);
281 }
282
283 // 'actors' act on the physical object to change or constrain its motion. These can range from
284 // hovering to complex vehicle motion.
285 public delegate BSActor CreateActor();
286 public void CreateRemoveActor(bool createRemove, string actorName, bool inTaintTime, CreateActor creator)
287 {
288 if (createRemove)
289 {
290 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CreateRemoveActor:" + actorName, delegate()
291 {
292 if (!PhysicalActors.HasActor(actorName))
293 {
294 DetailLog("{0},BSPrim.CreateRemoveActor,taint,registerActor,a={1}", LocalID, actorName);
295 PhysicalActors.Add(actorName, creator());
296 }
297 });
298 }
299 else
300 {
301 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CreateRemoveActor:" + actorName, delegate()
302 {
303 if (PhysicalActors.HasActor(actorName))
304 {
305 DetailLog("{0},BSPrim.CreateRemoveActor,taint,unregisterActor,a={1}", LocalID, actorName);
306 PhysicalActors.RemoveAndRelease(actorName);
307 }
308 });
309 }
310 }
241 311
242 #region Collisions 312 #region Collisions
243 313
@@ -255,7 +325,9 @@ public abstract class BSPhysObject : PhysicsActor
255 protected CollisionFlags CurrentCollisionFlags { get; set; } 325 protected CollisionFlags CurrentCollisionFlags { get; set; }
256 // On a collision, check the collider and remember if the last collider was moving 326 // On a collision, check the collider and remember if the last collider was moving
257 // Used to modify the standing of avatars (avatars on stationary things stand still) 327 // Used to modify the standing of avatars (avatars on stationary things stand still)
258 protected bool ColliderIsMoving; 328 public bool ColliderIsMoving;
329 // Used by BSCharacter to manage standing (and not slipping)
330 public bool IsStationary;
259 331
260 // Count of collisions for this object 332 // Count of collisions for this object
261 protected long CollisionAccumulation { get; set; } 333 protected long CollisionAccumulation { get; set; }
@@ -293,7 +365,7 @@ public abstract class BSPhysObject : PhysicsActor
293 protected CollisionEventUpdate CollisionCollection; 365 protected CollisionEventUpdate CollisionCollection;
294 // Remember collisions from last tick for fancy collision based actions 366 // Remember collisions from last tick for fancy collision based actions
295 // (like a BSCharacter walking up stairs). 367 // (like a BSCharacter walking up stairs).
296 protected CollisionEventUpdate CollisionsLastTick; 368 public CollisionEventUpdate CollisionsLastTick;
297 369
298 // The simulation step is telling this object about a collision. 370 // The simulation step is telling this object about a collision.
299 // Return 'true' if a collision was processed and should be sent up. 371 // Return 'true' if a collision was processed and should be sent up.
@@ -424,104 +496,6 @@ public abstract class BSPhysObject : PhysicsActor
424 496
425 public BSActorCollection PhysicalActors; 497 public BSActorCollection PhysicalActors;
426 498
427 // There are some actions that must be performed for a physical object before each simulation step.
428 // These actions are optional so, rather than scanning all the physical objects and asking them
429 // if they have anything to do, a physical object registers for an event call before the step is performed.
430 // This bookkeeping makes it easy to add, remove and clean up after all these registrations.
431 private Dictionary<string, BSScene.PreStepAction> RegisteredPrestepActions = new Dictionary<string, BSScene.PreStepAction>();
432 private Dictionary<string, BSScene.PostStepAction> RegisteredPoststepActions = new Dictionary<string, BSScene.PostStepAction>();
433 protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn)
434 {
435 string identifier = op + "-" + id.ToString();
436
437 lock (RegisteredPrestepActions)
438 {
439 // Clean out any existing action
440 UnRegisterPreStepAction(op, id);
441 RegisteredPrestepActions[identifier] = actn;
442 PhysicsScene.BeforeStep += actn;
443 }
444 DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier);
445 }
446
447 // Unregister a pre step action. Safe to call if the action has not been registered.
448 // Returns 'true' if an action was actually removed
449 protected bool UnRegisterPreStepAction(string op, uint id)
450 {
451 string identifier = op + "-" + id.ToString();
452 bool removed = false;
453 lock (RegisteredPrestepActions)
454 {
455 if (RegisteredPrestepActions.ContainsKey(identifier))
456 {
457 PhysicsScene.BeforeStep -= RegisteredPrestepActions[identifier];
458 RegisteredPrestepActions.Remove(identifier);
459 removed = true;
460 }
461 }
462 DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed);
463 return removed;
464 }
465
466 protected void UnRegisterAllPreStepActions()
467 {
468 lock (RegisteredPrestepActions)
469 {
470 foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredPrestepActions)
471 {
472 PhysicsScene.BeforeStep -= kvp.Value;
473 }
474 RegisteredPrestepActions.Clear();
475 }
476 DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID);
477 }
478
479 protected void RegisterPostStepAction(string op, uint id, BSScene.PostStepAction actn)
480 {
481 string identifier = op + "-" + id.ToString();
482
483 lock (RegisteredPoststepActions)
484 {
485 // Clean out any existing action
486 UnRegisterPostStepAction(op, id);
487 RegisteredPoststepActions[identifier] = actn;
488 PhysicsScene.AfterStep += actn;
489 }
490 DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier);
491 }
492
493 // Unregister a pre step action. Safe to call if the action has not been registered.
494 // Returns 'true' if an action was actually removed.
495 protected bool UnRegisterPostStepAction(string op, uint id)
496 {
497 string identifier = op + "-" + id.ToString();
498 bool removed = false;
499 lock (RegisteredPoststepActions)
500 {
501 if (RegisteredPoststepActions.ContainsKey(identifier))
502 {
503 PhysicsScene.AfterStep -= RegisteredPoststepActions[identifier];
504 RegisteredPoststepActions.Remove(identifier);
505 removed = true;
506 }
507 }
508 DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed);
509 return removed;
510 }
511
512 protected void UnRegisterAllPostStepActions()
513 {
514 lock (RegisteredPoststepActions)
515 {
516 foreach (KeyValuePair<string, BSScene.PostStepAction> kvp in RegisteredPoststepActions)
517 {
518 PhysicsScene.AfterStep -= kvp.Value;
519 }
520 RegisteredPoststepActions.Clear();
521 }
522 DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID);
523 }
524
525 // When an update to the physical properties happens, this event is fired to let 499 // When an update to the physical properties happens, this event is fired to let
526 // different actors to modify the update before it is passed around 500 // different actors to modify the update before it is passed around
527 public delegate void PreUpdatePropertyAction(ref EntityProperties entprop); 501 public delegate void PreUpdatePropertyAction(ref EntityProperties entprop);
@@ -533,46 +507,6 @@ public abstract class BSPhysObject : PhysicsActor
533 actions(ref entprop); 507 actions(ref entprop);
534 } 508 }
535 509
536 private Dictionary<string, PreUpdatePropertyAction> RegisteredPreUpdatePropertyActions = new Dictionary<string, PreUpdatePropertyAction>();
537 public void RegisterPreUpdatePropertyAction(string identifier, PreUpdatePropertyAction actn)
538 {
539 lock (RegisteredPreUpdatePropertyActions)
540 {
541 // Clean out any existing action
542 UnRegisterPreUpdatePropertyAction(identifier);
543 RegisteredPreUpdatePropertyActions[identifier] = actn;
544 OnPreUpdateProperty += actn;
545 }
546 DetailLog("{0},BSPhysObject.RegisterPreUpdatePropertyAction,id={1}", LocalID, identifier);
547 }
548 public bool UnRegisterPreUpdatePropertyAction(string identifier)
549 {
550 bool removed = false;
551 lock (RegisteredPreUpdatePropertyActions)
552 {
553 if (RegisteredPreUpdatePropertyActions.ContainsKey(identifier))
554 {
555 OnPreUpdateProperty -= RegisteredPreUpdatePropertyActions[identifier];
556 RegisteredPreUpdatePropertyActions.Remove(identifier);
557 removed = true;
558 }
559 }
560 DetailLog("{0},BSPhysObject.UnRegisterPreUpdatePropertyAction,id={1},removed={2}", LocalID, identifier, removed);
561 return removed;
562 }
563 public void UnRegisterAllPreUpdatePropertyActions()
564 {
565 lock (RegisteredPreUpdatePropertyActions)
566 {
567 foreach (KeyValuePair<string, PreUpdatePropertyAction> kvp in RegisteredPreUpdatePropertyActions)
568 {
569 OnPreUpdateProperty -= kvp.Value;
570 }
571 RegisteredPreUpdatePropertyActions.Clear();
572 }
573 DetailLog("{0},BSPhysObject.UnRegisterAllPreUpdatePropertyAction,", LocalID);
574 }
575
576 #endregion // Per Simulation Step actions 510 #endregion // Per Simulation Step actions
577 511
578 // High performance detailed logging routine used by the physical objects. 512 // High performance detailed logging routine used by the physical objects.