aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs5
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs48
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs83
3 files changed, 122 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 98069a0..9b75fb8 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -514,6 +514,11 @@ namespace OpenSim.Region.Physics.OdePlugin
514 } 514 }
515 } 515 }
516 516
517 public override float CollisionScore
518 {
519 get { return 0f; }
520 }
521
517 public override bool Kinematic 522 public override bool Kinematic
518 { 523 {
519 get { return false; } 524 get { return false; }
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 5cdbb77..a063962 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -55,6 +55,7 @@ namespace OpenSim.Region.Physics.OdePlugin
55 private bool m_taintPhysics = false; 55 private bool m_taintPhysics = false;
56 public bool m_taintremove = false; 56 public bool m_taintremove = false;
57 public bool m_taintdisable = false; 57 public bool m_taintdisable = false;
58 public bool m_disabled = false;
58 59
59 private bool m_taintforce = false; 60 private bool m_taintforce = false;
60 private List<PhysicsVector> m_forcelist = new List<PhysicsVector>(); 61 private List<PhysicsVector> m_forcelist = new List<PhysicsVector>();
@@ -65,10 +66,15 @@ namespace OpenSim.Region.Physics.OdePlugin
65 public IntPtr m_targetSpace = (IntPtr) 0; 66 public IntPtr m_targetSpace = (IntPtr) 0;
66 public IntPtr prim_geom; 67 public IntPtr prim_geom;
67 public IntPtr _triMeshData; 68 public IntPtr _triMeshData;
69
68 private bool iscolliding = false; 70 private bool iscolliding = false;
69 private bool m_isphysical = false; 71 private bool m_isphysical = false;
70 private bool m_throttleUpdates = false; 72 private bool m_throttleUpdates = false;
71 private int throttleCounter = 0; 73 private int throttleCounter = 0;
74 public int m_interpenetrationcount = 0;
75 public int m_collisionscore = 0;
76 public int m_roundsUnderMotionThreshold = 0;
77
72 public bool outofBounds = false; 78 public bool outofBounds = false;
73 private float m_density = 10.000006836f; // Aluminum g/cm3; 79 private float m_density = 10.000006836f; // Aluminum g/cm3;
74 80
@@ -257,6 +263,10 @@ namespace OpenSim.Region.Physics.OdePlugin
257 d.GeomSetBody(prim_geom, Body); 263 d.GeomSetBody(prim_geom, Body);
258 d.BodySetAutoDisableFlag(Body, true); 264 d.BodySetAutoDisableFlag(Body, true);
259 d.BodySetAutoDisableSteps(Body, 20); 265 d.BodySetAutoDisableSteps(Body, 20);
266
267 m_interpenetrationcount = 0;
268 m_collisionscore = 0;
269 m_disabled = false;
260 270
261 _parent_scene.addActivePrim(this); 271 _parent_scene.addActivePrim(this);
262 } 272 }
@@ -383,6 +393,8 @@ namespace OpenSim.Region.Physics.OdePlugin
383 d.BodyDestroy(Body); 393 d.BodyDestroy(Body);
384 Body = (IntPtr) 0; 394 Body = (IntPtr) 0;
385 } 395 }
396 m_disabled = true;
397 m_collisionscore = 0;
386 } 398 }
387 399
388 public void setMesh(OdeScene parent_scene, IMesh mesh) 400 public void setMesh(OdeScene parent_scene, IMesh mesh)
@@ -425,7 +437,11 @@ namespace OpenSim.Region.Physics.OdePlugin
425 if (IsPhysical && Body == (IntPtr) 0) 437 if (IsPhysical && Body == (IntPtr) 0)
426 { 438 {
427 // Recreate the body 439 // Recreate the body
440 m_interpenetrationcount = 0;
441 m_collisionscore = 0;
442
428 enableBody(); 443 enableBody();
444
429 } 445 }
430 } 446 }
431 447
@@ -485,7 +501,7 @@ namespace OpenSim.Region.Physics.OdePlugin
485 _parent_scene.waitForSpaceUnlock(m_targetSpace); 501 _parent_scene.waitForSpaceUnlock(m_targetSpace);
486 d.SpaceAdd(m_targetSpace, prim_geom); 502 d.SpaceAdd(m_targetSpace, prim_geom);
487 } 503 }
488 504 resetCollisionAccounting();
489 m_taintposition = _position; 505 m_taintposition = _position;
490 } 506 }
491 507
@@ -501,14 +517,23 @@ namespace OpenSim.Region.Physics.OdePlugin
501 { 517 {
502 d.BodySetQuaternion(Body, ref myrot); 518 d.BodySetQuaternion(Body, ref myrot);
503 } 519 }
504 520 resetCollisionAccounting();
505 m_taintrot = _orientation; 521 m_taintrot = _orientation;
506 } 522 }
507 public void changedisable(float timestep) 523
524 private void resetCollisionAccounting()
508 { 525 {
526 m_collisionscore = 0;
527 m_interpenetrationcount = 0;
528 m_disabled = false;
529 }
530
531 public void changedisable(float timestep)
532 {
533 m_disabled = true;
509 if (Body != (IntPtr) 0) 534 if (Body != (IntPtr) 0)
510 d.BodyDisable(Body); 535 d.BodyDisable(Body);
511 536
512 m_taintdisable = false; 537 m_taintdisable = false;
513 } 538 }
514 539
@@ -528,8 +553,7 @@ namespace OpenSim.Region.Physics.OdePlugin
528 disableBody(); 553 disableBody();
529 } 554 }
530 } 555 }
531 556 resetCollisionAccounting();
532
533 m_taintPhysics = m_isphysical; 557 m_taintPhysics = m_isphysical;
534 } 558 }
535 559
@@ -670,7 +694,7 @@ namespace OpenSim.Region.Physics.OdePlugin
670 } 694 }
671 695
672 _parent_scene.geom_name_map[prim_geom] = oldname; 696 _parent_scene.geom_name_map[prim_geom] = oldname;
673 697 resetCollisionAccounting();
674 m_taintsize = _size; 698 m_taintsize = _size;
675 } 699 }
676 700
@@ -724,7 +748,7 @@ namespace OpenSim.Region.Physics.OdePlugin
724 d.GeomSetQuaternion(prim_geom, ref myrot); 748 d.GeomSetQuaternion(prim_geom, ref myrot);
725 } 749 }
726 _parent_scene.geom_name_map[prim_geom] = oldname; 750 _parent_scene.geom_name_map[prim_geom] = oldname;
727 751 resetCollisionAccounting();
728 m_taintshape = false; 752 m_taintshape = false;
729 } 753 }
730 754
@@ -746,6 +770,8 @@ namespace OpenSim.Region.Physics.OdePlugin
746 } 770 }
747 m_forcelist.Clear(); 771 m_forcelist.Clear();
748 } 772 }
773 m_collisionscore = 0;
774 m_interpenetrationcount = 0;
749 m_taintforce = false; 775 m_taintforce = false;
750 776
751 } 777 }
@@ -759,6 +785,7 @@ namespace OpenSim.Region.Physics.OdePlugin
759 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z); 785 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z);
760 } 786 }
761 } 787 }
788 resetCollisionAccounting();
762 m_taintVelocity = PhysicsVector.Zero; 789 m_taintVelocity = PhysicsVector.Zero;
763 } 790 }
764 public override bool IsPhysical 791 public override bool IsPhysical
@@ -865,6 +892,11 @@ namespace OpenSim.Region.Physics.OdePlugin
865 } 892 }
866 } 893 }
867 894
895 public override float CollisionScore
896 {
897 get { return m_collisionscore; }
898 }
899
868 public override bool Kinematic 900 public override bool Kinematic
869 { 901 {
870 get { return false; } 902 get { return false; }
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 1aa141b..a2f354a 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -89,6 +89,9 @@ namespace OpenSim.Region.Physics.OdePlugin
89 private static float ODE_STEPSIZE = 0.020f; 89 private static float ODE_STEPSIZE = 0.020f;
90 private static bool RENDER_FLAG = false; 90 private static bool RENDER_FLAG = false;
91 private static float metersInSpace = 29.9f; 91 private static float metersInSpace = 29.9f;
92
93 private int interpenetrations_before_disable = 35;
94
92 private IntPtr contactgroup; 95 private IntPtr contactgroup;
93 private IntPtr LandGeom = (IntPtr) 0; 96 private IntPtr LandGeom = (IntPtr) 0;
94 private float[] _heightmap; 97 private float[] _heightmap;
@@ -109,13 +112,18 @@ namespace OpenSim.Region.Physics.OdePlugin
109 private d.Contact AvatarMovementprimContact; 112 private d.Contact AvatarMovementprimContact;
110 private d.Contact AvatarMovementTerrainContact; 113 private d.Contact AvatarMovementTerrainContact;
111 114
115
116
112 private int m_physicsiterations = 10; 117 private int m_physicsiterations = 10;
113 private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag 118 private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
114 private PhysicsActor PANull = new NullPhysicsActor(); 119 private PhysicsActor PANull = new NullPhysicsActor();
115 private float step_time = 0.0f; 120 private float step_time = 0.0f;
121 private int ms = 0;
116 public IntPtr world; 122 public IntPtr world;
117 123
118 public IntPtr space; 124 public IntPtr space;
125
126 private IntPtr tmpSpace;
119 // split static geometry collision handling into spaces of 30 meters 127 // split static geometry collision handling into spaces of 30 meters
120 public IntPtr[,] staticPrimspace = new IntPtr[(int) (300/metersInSpace),(int) (300/metersInSpace)]; 128 public IntPtr[,] staticPrimspace = new IntPtr[(int) (300/metersInSpace),(int) (300/metersInSpace)];
121 129
@@ -206,6 +214,14 @@ namespace OpenSim.Region.Physics.OdePlugin
206 } 214 }
207 } 215 }
208 216
217 public void starttiming()
218 {
219 ms = Environment.TickCount;
220 }
221 public int stoptiming()
222 {
223 return Environment.TickCount - ms;
224 }
209 // Initialize the mesh plugin 225 // Initialize the mesh plugin
210 public override void Initialise(IMesher meshmerizer) 226 public override void Initialise(IMesher meshmerizer)
211 { 227 {
@@ -311,6 +327,7 @@ namespace OpenSim.Region.Physics.OdePlugin
311 327
312 for (int i = 0; i < count; i++) 328 for (int i = 0; i < count; i++)
313 { 329 {
330 //m_log.Warn("[CCOUNT]: " + count);
314 IntPtr joint; 331 IntPtr joint;
315 // If we're colliding with terrain, use 'TerrainContact' instead of contact. 332 // If we're colliding with terrain, use 'TerrainContact' instead of contact.
316 // allows us to have different settings 333 // allows us to have different settings
@@ -405,13 +422,46 @@ namespace OpenSim.Region.Physics.OdePlugin
405 // If you interpenetrate a prim with another prim 422 // If you interpenetrate a prim with another prim
406 if (p1.PhysicsActorType == (int) ActorTypes.Prim && p2.PhysicsActorType == (int) ActorTypes.Prim) 423 if (p1.PhysicsActorType == (int) ActorTypes.Prim && p2.PhysicsActorType == (int) ActorTypes.Prim)
407 { 424 {
408 if (contacts[i].depth >= 0.25f) 425 OdePrim op1 = (OdePrim)p1;
426 OdePrim op2 = (OdePrim)p2;
427 op1.m_collisionscore++;
428 op2.m_collisionscore++;
429
430
431 if (op1.m_collisionscore > 80 || op2.m_collisionscore > 80)
409 { 432 {
410 // Don't collide, one or both prim will explode. 433 op1.m_taintdisable = true;
411 ((OdePrim)p1).m_taintdisable = true;
412 AddPhysicsActorTaint(p1); 434 AddPhysicsActorTaint(p1);
413 ((OdePrim)p2).m_taintdisable = true; 435 op2.m_taintdisable = true;
414 AddPhysicsActorTaint(p2); 436 AddPhysicsActorTaint(p2);
437 }
438
439 if (contacts[i].depth >= 0.25f)
440 {
441 // Don't collide, one or both prim will explode.
442
443
444 op1.m_interpenetrationcount++;
445 op2.m_interpenetrationcount++;
446 interpenetrations_before_disable = 20;
447 if (op1.m_interpenetrationcount >= interpenetrations_before_disable)
448 {
449 op1.m_taintdisable = true;
450 AddPhysicsActorTaint(p1);
451 }
452 if (op2.m_interpenetrationcount >= interpenetrations_before_disable)
453 {
454 op2.m_taintdisable = true;
455 AddPhysicsActorTaint(p2);
456 }
457
458
459 //contacts[i].depth = contacts[i].depth / 8f;
460 //contacts[i].normal = new d.Vector3(0, 0, 1);
461 }
462 if (op1.m_disabled || op2.m_disabled)
463 {
464 //Manually disabled objects stay disabled
415 contacts[i].depth = 0f; 465 contacts[i].depth = 0f;
416 } 466 }
417 } 467 }
@@ -531,6 +581,7 @@ namespace OpenSim.Region.Physics.OdePlugin
531 /// <param name="timeStep"></param> 581 /// <param name="timeStep"></param>
532 private void collision_optimized(float timeStep) 582 private void collision_optimized(float timeStep)
533 { 583 {
584 starttiming();
534 foreach (OdeCharacter chr in _characters) 585 foreach (OdeCharacter chr in _characters)
535 { 586 {
536 // Reset the collision values to false 587 // Reset the collision values to false
@@ -554,6 +605,7 @@ namespace OpenSim.Region.Physics.OdePlugin
554 //forcedZ = true; 605 //forcedZ = true;
555 //} 606 //}
556 } 607 }
608 int avms = stoptiming();
557 609
558 // If the sim is running slow this frame, 610 // If the sim is running slow this frame,
559 // don't process collision for prim! 611 // don't process collision for prim!
@@ -562,9 +614,11 @@ namespace OpenSim.Region.Physics.OdePlugin
562 foreach (OdePrim chr in _activeprims) 614 foreach (OdePrim chr in _activeprims)
563 { 615 {
564 // This if may not need to be there.. it might be skipped anyway. 616 // This if may not need to be there.. it might be skipped anyway.
565 if (d.BodyIsEnabled(chr.Body)) 617 if (d.BodyIsEnabled(chr.Body) && (!chr.m_disabled))
566 { 618 {
619
567 d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); 620 d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback);
621 //calculateSpaceForGeom(chr.Position)
568 //foreach (OdePrim ch2 in _prims) 622 //foreach (OdePrim ch2 in _prims)
569 /// should be a separate space -- lots of avatars will be N**2 slow 623 /// should be a separate space -- lots of avatars will be N**2 slow
570 //{ 624 //{
@@ -580,6 +634,7 @@ namespace OpenSim.Region.Physics.OdePlugin
580 //} 634 //}
581 //} 635 //}
582 } 636 }
637 d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback);
583 } 638 }
584 } 639 }
585 else 640 else
@@ -593,6 +648,9 @@ namespace OpenSim.Region.Physics.OdePlugin
593 { 648 {
594 // Collide test the prims with the terrain.. since if you don't do this, 649 // Collide test the prims with the terrain.. since if you don't do this,
595 // next frame, all of the physical prim in the scene will awaken and explode upwards 650 // next frame, all of the physical prim in the scene will awaken and explode upwards
651 tmpSpace = calculateSpaceForGeom(chr.Position);
652 if (tmpSpace != (IntPtr) 0 && d.GeomIsSpace(tmpSpace))
653 d.SpaceCollide2(calculateSpaceForGeom(chr.Position), chr.prim_geom, IntPtr.Zero, nearCallback);
596 d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback); 654 d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback);
597 } 655 }
598 } 656 }
@@ -1140,7 +1198,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1140 } 1198 }
1141 1199
1142 collision_optimized(timeStep); 1200 collision_optimized(timeStep);
1143 d.WorldQuickStep(world, ODE_STEPSIZE); 1201 try
1202 {
1203 d.WorldQuickStep(world, ODE_STEPSIZE);
1204 }
1205 catch (StackOverflowException)
1206 {
1207 d.WorldQuickStep(world, 0.001f);
1208 }
1144 d.JointGroupEmpty(contactgroup); 1209 d.JointGroupEmpty(contactgroup);
1145 foreach (OdeCharacter actor in _characters) 1210 foreach (OdeCharacter actor in _characters)
1146 { 1211 {
@@ -1165,6 +1230,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1165 RemovePrimThreadLocked(prim); 1230 RemovePrimThreadLocked(prim);
1166 } 1231 }
1167 processedtaints = true; 1232 processedtaints = true;
1233 prim.m_collisionscore = 0;
1234 }
1235
1236 foreach (OdePrim prim in _activeprims)
1237 {
1238 prim.m_collisionscore = 0;
1168 } 1239 }
1169 1240
1170 if (processedtaints) 1241 if (processedtaints)