aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs60
1 files changed, 41 insertions, 19 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 52997dd..dabced5 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -75,10 +75,11 @@ public class BSScene : PhysicsScene, IPhysicsParameters
75 75
76 public Dictionary<uint, BSPhysObject> PhysObjects = new Dictionary<uint, BSPhysObject>(); 76 public Dictionary<uint, BSPhysObject> PhysObjects = new Dictionary<uint, BSPhysObject>();
77 77
78 private HashSet<BSPhysObject> m_objectsWithCollisions = new HashSet<BSPhysObject>(); 78 public HashSet<BSPhysObject> ObjectsWithCollisions = new HashSet<BSPhysObject>();
79 // Following is a kludge and can be removed when avatar animation updating is 79 public HashSet<BSPhysObject> ObjectsWithNoMoreCollisions = new HashSet<BSPhysObject>();
80 // moved to a better place. 80 // Keep track of all the avatars so we can send them a collision event
81 private HashSet<BSPhysObject> m_avatarsWithCollisions = new HashSet<BSPhysObject>(); 81 // every tick so OpenSim will update its animation.
82 private HashSet<BSPhysObject> m_avatars = new HashSet<BSPhysObject>();
82 83
83 // List of all the objects that have vehicle properties and should be called 84 // List of all the objects that have vehicle properties and should be called
84 // to update each physics step. 85 // to update each physics step.
@@ -379,7 +380,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
379 // TODO: Remove kludge someday. 380 // TODO: Remove kludge someday.
380 // We must generate a collision for avatars whether they collide or not. 381 // We must generate a collision for avatars whether they collide or not.
381 // This is required by OpenSim to update avatar animations, etc. 382 // This is required by OpenSim to update avatar animations, etc.
382 lock (m_avatarsWithCollisions) m_avatarsWithCollisions.Add(actor); 383 lock (m_avatars) m_avatars.Add(actor);
383 384
384 return actor; 385 return actor;
385 } 386 }
@@ -397,7 +398,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
397 { 398 {
398 lock (PhysObjects) PhysObjects.Remove(actor.LocalID); 399 lock (PhysObjects) PhysObjects.Remove(actor.LocalID);
399 // Remove kludge someday 400 // Remove kludge someday
400 lock (m_avatarsWithCollisions) m_avatarsWithCollisions.Remove(bsactor); 401 lock (m_avatars) m_avatars.Remove(bsactor);
401 } 402 }
402 catch (Exception e) 403 catch (Exception e)
403 { 404 {
@@ -464,6 +465,9 @@ public class BSScene : PhysicsScene, IPhysicsParameters
464 int collidersCount = 0; 465 int collidersCount = 0;
465 IntPtr collidersPtr; 466 IntPtr collidersPtr;
466 467
468 int beforeTime = 0;
469 int simTime = 0;
470
467 // prevent simulation until we've been initialized 471 // prevent simulation until we've been initialized
468 if (!m_initialized) return 5.0f; 472 if (!m_initialized) return 5.0f;
469 473
@@ -481,10 +485,14 @@ public class BSScene : PhysicsScene, IPhysicsParameters
481 int numSubSteps = 0; 485 int numSubSteps = 0;
482 try 486 try
483 { 487 {
488 if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount();
489
484 numSubSteps = BulletSimAPI.PhysicsStep(WorldID, timeStep, m_maxSubSteps, m_fixedTimeStep, 490 numSubSteps = BulletSimAPI.PhysicsStep(WorldID, timeStep, m_maxSubSteps, m_fixedTimeStep,
485 out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); 491 out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr);
486 DetailLog("{0},Simulate,call, nTaints= {1}, substeps={2}, updates={3}, colliders={4}", 492
487 DetailLogZero, numTaints, numSubSteps, updatedEntityCount, collidersCount); 493 if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime);
494 DetailLog("{0},Simulate,call, nTaints={1}, simTime={2}, substeps={3}, updates={4}, colliders={5}",
495 DetailLogZero, numTaints, simTime, numSubSteps, updatedEntityCount, collidersCount);
488 } 496 }
489 catch (Exception e) 497 catch (Exception e)
490 { 498 {
@@ -502,12 +510,6 @@ public class BSScene : PhysicsScene, IPhysicsParameters
502 // Get a value for 'now' so all the collision and update routines don't have to get their own 510 // Get a value for 'now' so all the collision and update routines don't have to get their own
503 SimulationNowTime = Util.EnvironmentTickCount(); 511 SimulationNowTime = Util.EnvironmentTickCount();
504 512
505 // This is a kludge to get avatar movement updates.
506 // ODE sends collisions for avatars even if there are have been no collisions. This updates
507 // avatar animations and stuff.
508 // If you fix avatar animation updates, remove this overhead and let normal collision processing happen.
509 m_objectsWithCollisions = new HashSet<BSPhysObject>(m_avatarsWithCollisions);
510
511 // If there were collisions, process them by sending the event to the prim. 513 // If there were collisions, process them by sending the event to the prim.
512 // Collisions must be processed before updates. 514 // Collisions must be processed before updates.
513 if (collidersCount > 0) 515 if (collidersCount > 0)
@@ -523,11 +525,31 @@ public class BSScene : PhysicsScene, IPhysicsParameters
523 } 525 }
524 } 526 }
525 527
528 // This is a kludge to get avatar movement updates.
529 // ODE sends collisions for avatars even if there are have been no collisions. This updates
530 // avatar animations and stuff.
531 // If you fix avatar animation updates, remove this overhead and let normal collision processing happen.
532 foreach (BSPhysObject bsp in m_avatars)
533 bsp.SendCollisions();
534
526 // The above SendCollision's batch up the collisions on the objects. 535 // The above SendCollision's batch up the collisions on the objects.
527 // Now push the collisions into the simulator. 536 // Now push the collisions into the simulator.
528 foreach (BSPhysObject bsp in m_objectsWithCollisions) 537 // If the object is done colliding, it will add itself to the ObjectsWithNoMoreCollisions list.
529 bsp.SendCollisions(); 538 if (ObjectsWithCollisions.Count > 0)
530 m_objectsWithCollisions.Clear(); 539 {
540 foreach (BSPhysObject bsp in ObjectsWithCollisions)
541 if (!m_avatars.Contains(bsp)) // don't call avatars twice
542 bsp.SendCollisions();
543 }
544
545 // Objects that are done colliding are removed from the ObjectsWithCollisions list.
546 // This can't be done by SendCollisions because it is inside an iteration of ObjectWithCollisions.
547 if (ObjectsWithNoMoreCollisions.Count > 0)
548 {
549 foreach (BSPhysObject po in ObjectsWithNoMoreCollisions)
550 ObjectsWithCollisions.Remove(po);
551 ObjectsWithNoMoreCollisions.Clear();
552 }
531 553
532 // If any of the objects had updated properties, tell the object it has been changed by the physics engine 554 // If any of the objects had updated properties, tell the object it has been changed by the physics engine
533 if (updatedEntityCount > 0) 555 if (updatedEntityCount > 0)
@@ -555,7 +577,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
555 // The physics engine returns the number of milliseconds it simulated this call. 577 // The physics engine returns the number of milliseconds it simulated this call.
556 // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. 578 // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS.
557 // Since Bullet normally does 5 or 6 substeps, this will normally sum to about 60 FPS. 579 // Since Bullet normally does 5 or 6 substeps, this will normally sum to about 60 FPS.
558 return numSubSteps * m_fixedTimeStep; 580 return numSubSteps * m_fixedTimeStep * 1000;
559 } 581 }
560 582
561 // Something has collided 583 // Something has collided
@@ -583,7 +605,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
583 if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration)) 605 if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration))
584 { 606 {
585 // If a collision was posted, remember to send it to the simulator 607 // If a collision was posted, remember to send it to the simulator
586 m_objectsWithCollisions.Add(collider); 608 ObjectsWithCollisions.Add(collider);
587 } 609 }
588 610
589 return; 611 return;