aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-02-13 07:50:15 +0000
committerTeravus Ovares2008-02-13 07:50:15 +0000
commitd773ca514726d67d7f8092440484f27440459745 (patch)
tree9af8e68eb67c144735e7f773292df45c368218bd /OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
parentClean up more unnecessary String.Format calls (diff)
downloadopensim-SC-d773ca514726d67d7f8092440484f27440459745.zip
opensim-SC-d773ca514726d67d7f8092440484f27440459745.tar.gz
opensim-SC-d773ca514726d67d7f8092440484f27440459745.tar.bz2
opensim-SC-d773ca514726d67d7f8092440484f27440459745.tar.xz
* Made physical prim stable enough for the general population to turn on. (though I still don't recommend it for welcome regions unless object build is off.
* Updated the ode.dll for windows with a more reasonable stack space reserve. Linux users will need to type ulimit -s 262144 before starting up OpenSimulator if using Physical Prim to protect against stack collisions. or run the included ./bin/opensim-ode.sh to start up OpenSimulator in ODE mode. * Added internal collision score and am keeping track of 'high usage' prim. * Tweaked collisions some more * Tested up to 460 physical prim in extremely close quarters (which was previously impossible in OpenSim). After 460 in tight quarters, physics slows down enough to make it hard to do any moving, however.. non physics things still work, such as logging on to the simulator, etc.
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/OdePlugin.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs83
1 files changed, 77 insertions, 6 deletions
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)