diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 66 |
1 files changed, 56 insertions, 10 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 027c786..285d4a2 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -101,6 +101,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
101 | public virtual void Destroy() | 101 | public virtual void Destroy() |
102 | { | 102 | { |
103 | UnRegisterAllPreStepActions(); | 103 | UnRegisterAllPreStepActions(); |
104 | UnRegisterAllPostStepActions(); | ||
104 | } | 105 | } |
105 | 106 | ||
106 | public BSScene PhysicsScene { get; protected set; } | 107 | public BSScene PhysicsScene { get; protected set; } |
@@ -393,17 +394,18 @@ public abstract class BSPhysObject : PhysicsActor | |||
393 | // These actions are optional so, rather than scanning all the physical objects and asking them | 394 | // These actions are optional so, rather than scanning all the physical objects and asking them |
394 | // if they have anything to do, a physical object registers for an event call before the step is performed. | 395 | // if they have anything to do, a physical object registers for an event call before the step is performed. |
395 | // This bookkeeping makes it easy to add, remove and clean up after all these registrations. | 396 | // This bookkeeping makes it easy to add, remove and clean up after all these registrations. |
396 | private Dictionary<string, BSScene.PreStepAction> RegisteredActions = new Dictionary<string, BSScene.PreStepAction>(); | 397 | private Dictionary<string, BSScene.PreStepAction> RegisteredPrestepActions = new Dictionary<string, BSScene.PreStepAction>(); |
398 | private Dictionary<string, BSScene.PostStepAction> RegisteredPoststepActions = new Dictionary<string, BSScene.PostStepAction>(); | ||
397 | protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn) | 399 | protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn) |
398 | { | 400 | { |
399 | string identifier = op + "-" + id.ToString(); | 401 | string identifier = op + "-" + id.ToString(); |
400 | 402 | ||
401 | lock (RegisteredActions) | 403 | lock (RegisteredPrestepActions) |
402 | { | 404 | { |
403 | // Clean out any existing action | 405 | // Clean out any existing action |
404 | UnRegisterPreStepAction(op, id); | 406 | UnRegisterPreStepAction(op, id); |
405 | 407 | ||
406 | RegisteredActions[identifier] = actn; | 408 | RegisteredPrestepActions[identifier] = actn; |
407 | } | 409 | } |
408 | PhysicsScene.BeforeStep += actn; | 410 | PhysicsScene.BeforeStep += actn; |
409 | DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); | 411 | DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); |
@@ -414,12 +416,12 @@ public abstract class BSPhysObject : PhysicsActor | |||
414 | { | 416 | { |
415 | string identifier = op + "-" + id.ToString(); | 417 | string identifier = op + "-" + id.ToString(); |
416 | bool removed = false; | 418 | bool removed = false; |
417 | lock (RegisteredActions) | 419 | lock (RegisteredPrestepActions) |
418 | { | 420 | { |
419 | if (RegisteredActions.ContainsKey(identifier)) | 421 | if (RegisteredPrestepActions.ContainsKey(identifier)) |
420 | { | 422 | { |
421 | PhysicsScene.BeforeStep -= RegisteredActions[identifier]; | 423 | PhysicsScene.BeforeStep -= RegisteredPrestepActions[identifier]; |
422 | RegisteredActions.Remove(identifier); | 424 | RegisteredPrestepActions.Remove(identifier); |
423 | removed = true; | 425 | removed = true; |
424 | } | 426 | } |
425 | } | 427 | } |
@@ -428,17 +430,61 @@ public abstract class BSPhysObject : PhysicsActor | |||
428 | 430 | ||
429 | protected void UnRegisterAllPreStepActions() | 431 | protected void UnRegisterAllPreStepActions() |
430 | { | 432 | { |
431 | lock (RegisteredActions) | 433 | lock (RegisteredPrestepActions) |
432 | { | 434 | { |
433 | foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredActions) | 435 | foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredPrestepActions) |
434 | { | 436 | { |
435 | PhysicsScene.BeforeStep -= kvp.Value; | 437 | PhysicsScene.BeforeStep -= kvp.Value; |
436 | } | 438 | } |
437 | RegisteredActions.Clear(); | 439 | RegisteredPrestepActions.Clear(); |
438 | } | 440 | } |
439 | DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID); | 441 | DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID); |
440 | } | 442 | } |
443 | |||
444 | protected void RegisterPostStepAction(string op, uint id, BSScene.PostStepAction actn) | ||
445 | { | ||
446 | string identifier = op + "-" + id.ToString(); | ||
447 | |||
448 | lock (RegisteredPoststepActions) | ||
449 | { | ||
450 | // Clean out any existing action | ||
451 | UnRegisterPostStepAction(op, id); | ||
452 | |||
453 | RegisteredPoststepActions[identifier] = actn; | ||
454 | } | ||
455 | PhysicsScene.AfterStep += actn; | ||
456 | DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); | ||
457 | } | ||
458 | |||
459 | // Unregister a pre step action. Safe to call if the action has not been registered. | ||
460 | protected void UnRegisterPostStepAction(string op, uint id) | ||
461 | { | ||
462 | string identifier = op + "-" + id.ToString(); | ||
463 | bool removed = false; | ||
464 | lock (RegisteredPoststepActions) | ||
465 | { | ||
466 | if (RegisteredPoststepActions.ContainsKey(identifier)) | ||
467 | { | ||
468 | PhysicsScene.AfterStep -= RegisteredPoststepActions[identifier]; | ||
469 | RegisteredPoststepActions.Remove(identifier); | ||
470 | removed = true; | ||
471 | } | ||
472 | } | ||
473 | DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed); | ||
474 | } | ||
441 | 475 | ||
476 | protected void UnRegisterAllPostStepActions() | ||
477 | { | ||
478 | lock (RegisteredPoststepActions) | ||
479 | { | ||
480 | foreach (KeyValuePair<string, BSScene.PostStepAction> kvp in RegisteredPoststepActions) | ||
481 | { | ||
482 | PhysicsScene.AfterStep -= kvp.Value; | ||
483 | } | ||
484 | RegisteredPoststepActions.Clear(); | ||
485 | } | ||
486 | DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID); | ||
487 | } | ||
442 | 488 | ||
443 | #endregion // Per Simulation Step actions | 489 | #endregion // Per Simulation Step actions |
444 | 490 | ||