aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
authorTeravus Ovares2008-02-13 23:14:41 +0000
committerTeravus Ovares2008-02-13 23:14:41 +0000
commit3588d89b2cba36415991c46c300b1f9c94f109bf (patch)
tree985987f9e0a2e60815134f05a4d69c658aef4ed4 /OpenSim/Region/Physics/OdePlugin
parent* Fixed another bug in avatarpicker ('surname'/'lastname' mixup) (diff)
downloadopensim-SC_OLD-3588d89b2cba36415991c46c300b1f9c94f109bf.zip
opensim-SC_OLD-3588d89b2cba36415991c46c300b1f9c94f109bf.tar.gz
opensim-SC_OLD-3588d89b2cba36415991c46c300b1f9c94f109bf.tar.bz2
opensim-SC_OLD-3588d89b2cba36415991c46c300b1f9c94f109bf.tar.xz
* Bigish ODE stability Update. Run Prebuild
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs12
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs238
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs96
3 files changed, 229 insertions, 117 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 80c2a48..75d62cc 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -16,7 +16,7 @@
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMEd. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
@@ -35,7 +35,7 @@ using OpenSim.Region.Physics.Manager;
35namespace OpenSim.Region.Physics.OdePlugin 35namespace OpenSim.Region.Physics.OdePlugin
36{ 36{
37 /// <summary> 37 /// <summary>
38 /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves. 38 /// Various properties that ODE uses for AMotors but isn't exposed in d.NET so we must define them ourselves.
39 /// </summary> 39 /// </summary>
40 40
41 public enum dParam : int 41 public enum dParam : int
@@ -87,6 +87,7 @@ namespace OpenSim.Region.Physics.OdePlugin
87 private bool m_hackSentFall = false; 87 private bool m_hackSentFall = false;
88 private bool m_hackSentFly = false; 88 private bool m_hackSentFly = false;
89 private bool m_foundDebian = false; 89 private bool m_foundDebian = false;
90 private CollisionLocker ode;
90 91
91 private string m_name = String.Empty; 92 private string m_name = String.Empty;
92 93
@@ -103,8 +104,9 @@ namespace OpenSim.Region.Physics.OdePlugin
103 public d.Mass ShellMass; 104 public d.Mass ShellMass;
104 public bool collidelock = false; 105 public bool collidelock = false;
105 106
106 public OdeCharacter(String avName, OdeScene parent_scene, PhysicsVector pos) 107 public OdeCharacter(String avName, OdeScene parent_scene, PhysicsVector pos, CollisionLocker dode)
107 { 108 {
109 ode = dode;
108 _velocity = new PhysicsVector(); 110 _velocity = new PhysicsVector();
109 _target_velocity = new PhysicsVector(); 111 _target_velocity = new PhysicsVector();
110 _position = pos; 112 _position = pos;
@@ -801,5 +803,9 @@ namespace OpenSim.Region.Physics.OdePlugin
801 d.BodyDestroy(Body); 803 d.BodyDestroy(Body);
802 } 804 }
803 } 805 }
806 public override void CrossingFailure()
807 {
808
809 }
804 } 810 }
805} 811}
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 6103320..527a5cc 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -16,7 +16,7 @@
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMEd. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
@@ -56,6 +56,8 @@ namespace OpenSim.Region.Physics.OdePlugin
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 public bool m_disabled = false;
59 public bool m_taintadd = false;
60 private CollisionLocker ode;
59 61
60 private bool m_taintforce = false; 62 private bool m_taintforce = false;
61 private List<PhysicsVector> m_forcelist = new List<PhysicsVector>(); 63 private List<PhysicsVector> m_forcelist = new List<PhysicsVector>();
@@ -74,6 +76,7 @@ namespace OpenSim.Region.Physics.OdePlugin
74 public int m_interpenetrationcount = 0; 76 public int m_interpenetrationcount = 0;
75 public int m_collisionscore = 0; 77 public int m_collisionscore = 0;
76 public int m_roundsUnderMotionThreshold = 0; 78 public int m_roundsUnderMotionThreshold = 0;
79 private int m_crossingfailures = 0;
77 80
78 public bool outofBounds = false; 81 public bool outofBounds = false;
79 private float m_density = 10.000006836f; // Aluminum g/cm3; 82 private float m_density = 10.000006836f; // Aluminum g/cm3;
@@ -90,9 +93,9 @@ namespace OpenSim.Region.Physics.OdePlugin
90 private int debugcounter = 0; 93 private int debugcounter = 0;
91 94
92 public OdePrim(String primName, OdeScene parent_scene, IntPtr targetSpace, PhysicsVector pos, PhysicsVector size, 95 public OdePrim(String primName, OdeScene parent_scene, IntPtr targetSpace, PhysicsVector pos, PhysicsVector size,
93 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical) 96 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode)
94 { 97 {
95 98 ode = dode;
96 _velocity = new PhysicsVector(); 99 _velocity = new PhysicsVector();
97 _position = pos; 100 _position = pos;
98 m_taintposition = pos; 101 m_taintposition = pos;
@@ -136,86 +139,11 @@ namespace OpenSim.Region.Physics.OdePlugin
136 m_targetSpace = _parent_scene.space; 139 m_targetSpace = _parent_scene.space;
137 } 140 }
138 m_primName = primName; 141 m_primName = primName;
139 if (mesh != null) 142 m_taintadd = true;
140 { 143 _parent_scene.AddPhysicsActorTaint(this);
141 } 144 // don't do .add() here; old geoms get recycled with the same hash
142 else 145 parent_scene.geom_name_map[prim_geom] = primName;
143 { 146 parent_scene.actor_name_map[prim_geom] = (PhysicsActor) this;
144 if (_parent_scene.needsMeshing(_pbs))
145 {
146 // Don't need to re-enable body.. it's done in SetMesh
147 mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size);
148 // createmesh returns null when it's a shape that isn't a cube.
149 }
150 }
151
152 lock (OdeScene.OdeLock)
153 {
154 if (mesh != null)
155 {
156 setMesh(parent_scene, mesh);
157 }
158 else
159 {
160 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1)
161 {
162 if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
163 {
164 if (((_size.X / 2f) > 0f))
165 {
166
167
168 _parent_scene.waitForSpaceUnlock(m_targetSpace);
169 prim_geom = d.CreateSphere(m_targetSpace, _size.X / 2);
170 }
171 else
172 {
173 _parent_scene.waitForSpaceUnlock(m_targetSpace);
174 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
175 }
176 }
177 else
178 {
179 _parent_scene.waitForSpaceUnlock(m_targetSpace);
180 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
181 }
182 }
183 //else if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
184 //{
185 //Cyllinder
186 //if (_size.X == _size.Y)
187 //{
188 //prim_geom = d.CreateCylinder(m_targetSpace, _size.X / 2, _size.Z);
189 //}
190 //else
191 //{
192 //prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
193 //}
194 //}
195 else
196 {
197 _parent_scene.waitForSpaceUnlock(m_targetSpace);
198 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
199 }
200 }
201
202 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
203 d.Quaternion myrot = new d.Quaternion();
204 myrot.W = rotation.w;
205 myrot.X = rotation.x;
206 myrot.Y = rotation.y;
207 myrot.Z = rotation.z;
208 d.GeomSetQuaternion(prim_geom, ref myrot);
209
210
211 if (m_isphysical && Body == (IntPtr) 0)
212 {
213 enableBody();
214 }
215 parent_scene.geom_name_map[prim_geom] = primName;
216 parent_scene.actor_name_map[prim_geom] = (PhysicsActor) this;
217 // don't do .add() here; old geoms get recycled with the same hash
218 }
219 } 147 }
220 148
221 /// <summary> 149 /// <summary>
@@ -399,15 +327,18 @@ namespace OpenSim.Region.Physics.OdePlugin
399 327
400 public void setMesh(OdeScene parent_scene, IMesh mesh) 328 public void setMesh(OdeScene parent_scene, IMesh mesh)
401 { 329 {
330 // This sleeper is there to moderate how long it takes between
331 // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object
332
333 System.Threading.Thread.Sleep(10);
334
402 //Kill Body so that mesh can re-make the geom 335 //Kill Body so that mesh can re-make the geom
403 if (IsPhysical && Body != (IntPtr) 0) 336 if (IsPhysical && Body != (IntPtr) 0)
404 { 337 {
405 disableBody(); 338 disableBody();
406 } 339 }
407 340
408 // This sleeper is there to moderate how long it takes between 341
409 // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object
410 System.Threading.Thread.Sleep(10);
411 342
412 343
413 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory 344 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
@@ -448,6 +379,10 @@ namespace OpenSim.Region.Physics.OdePlugin
448 public void ProcessTaints(float timestep) 379 public void ProcessTaints(float timestep)
449 { 380 {
450 System.Threading.Thread.Sleep(5); 381 System.Threading.Thread.Sleep(5);
382
383 if (m_taintadd)
384 changeadd(timestep);
385
451 if (m_taintposition != _position) 386 if (m_taintposition != _position)
452 Move(timestep); 387 Move(timestep);
453 388
@@ -477,8 +412,124 @@ namespace OpenSim.Region.Physics.OdePlugin
477 changevelocity(timestep); 412 changevelocity(timestep);
478 } 413 }
479 414
480
481 415
416 public void changeadd(float timestep)
417 {
418 if (_mesh != null)
419 {
420 }
421 else
422 {
423 if (_parent_scene.needsMeshing(_pbs))
424 {
425 // Don't need to re-enable body.. it's done in SetMesh
426 _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size);
427 // createmesh returns null when it's a shape that isn't a cube.
428 }
429 }
430
431 lock (OdeScene.OdeLock)
432 {
433 if (_mesh != null)
434 {
435 setMesh(_parent_scene, _mesh);
436 }
437 else
438 {
439 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1)
440 {
441 if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
442 {
443 if (((_size.X / 2f) > 0f))
444 {
445
446
447 _parent_scene.waitForSpaceUnlock(m_targetSpace);
448 try
449 {
450 prim_geom = d.CreateSphere(m_targetSpace, _size.X / 2);
451 }
452 catch (System.AccessViolationException)
453 {
454 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object");
455 return;
456 }
457 }
458 else
459 {
460 _parent_scene.waitForSpaceUnlock(m_targetSpace);
461 try
462 {
463 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
464 }
465 catch (System.AccessViolationException)
466 {
467 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object");
468 return;
469 }
470 }
471 }
472 else
473 {
474 _parent_scene.waitForSpaceUnlock(m_targetSpace);
475 try
476 {
477 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
478 }
479 catch (System.AccessViolationException)
480 {
481 return;
482 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object");
483 }
484 }
485 }
486 //else if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
487 //{
488 //Cyllinder
489 //if (_size.X == _size.Y)
490 //{
491 //prim_geom = d.CreateCylinder(m_targetSpace, _size.X / 2, _size.Z);
492 //}
493 //else
494 //{
495 //prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
496 //}
497 //}
498 else
499 {
500 _parent_scene.waitForSpaceUnlock(m_targetSpace);
501 try
502 {
503 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
504 }
505 catch (System.AccessViolationException)
506 {
507 m_log.Warn("[PHYSICS]: Unable to create physics proxy for object");
508 return;
509 }
510 }
511 }
512
513 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
514 d.Quaternion myrot = new d.Quaternion();
515 myrot.W = _orientation.w;
516 myrot.X = _orientation.x;
517 myrot.Y = _orientation.y;
518 myrot.Z = _orientation.z;
519 d.GeomSetQuaternion(prim_geom, ref myrot);
520
521
522 if (m_isphysical && Body == (IntPtr)0)
523 {
524 enableBody();
525 }
526
527
528 }
529 m_taintadd = false;
530
531
532 }
482 public void Move(float timestep) 533 public void Move(float timestep)
483 { 534 {
484 if (m_isphysical) 535 if (m_isphysical)
@@ -941,7 +992,15 @@ namespace OpenSim.Region.Physics.OdePlugin
941 } 992 }
942 set { m_rotationalVelocity = value; } 993 set { m_rotationalVelocity = value; }
943 } 994 }
995 public override void CrossingFailure()
996 {
997 m_crossingfailures++;
998 if (m_crossingfailures >= 5)
999 {
1000 m_log.Warn("[PHYSICS]: Too many crossing failures for: " + m_primName);
944 1001
1002 }
1003 }
945 public void UpdatePositionAndVelocity() 1004 public void UpdatePositionAndVelocity()
946 { 1005 {
947 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! 1006 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
@@ -969,7 +1028,10 @@ namespace OpenSim.Region.Physics.OdePlugin
969 1028
970 if (l_position.X > 257f || l_position.X < -1f || l_position.Y > 257f || l_position.Y < -1f) 1029 if (l_position.X > 257f || l_position.X < -1f || l_position.Y > 257f || l_position.Y < -1f)
971 { 1030 {
972 base.RequestPhysicsterseUpdate(); 1031 if (m_crossingfailures < 5)
1032 {
1033 base.RequestPhysicsterseUpdate();
1034 }
973 } 1035 }
974 1036
975 if (l_position.Z < 0) 1037 if (l_position.Z < 0)
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 1c16cfb..66af095 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -16,7 +16,7 @@
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMEd. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
@@ -46,10 +46,12 @@ namespace OpenSim.Region.Physics.OdePlugin
46 { 46 {
47 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
48 48
49 private CollisionLocker ode;
49 private OdeScene _mScene; 50 private OdeScene _mScene;
50 51
51 public OdePlugin() 52 public OdePlugin()
52 { 53 {
54 ode = new CollisionLocker();
53 } 55 }
54 56
55 public bool Init() 57 public bool Init()
@@ -61,7 +63,7 @@ namespace OpenSim.Region.Physics.OdePlugin
61 { 63 {
62 if (_mScene == null) 64 if (_mScene == null)
63 { 65 {
64 _mScene = new OdeScene(); 66 _mScene = new OdeScene(ode);
65 } 67 }
66 return (_mScene); 68 return (_mScene);
67 } 69 }
@@ -74,7 +76,7 @@ namespace OpenSim.Region.Physics.OdePlugin
74 public void Dispose() 76 public void Dispose()
75 { 77 {
76 78
77 d.CloseODE(); 79
78 } 80 }
79 } 81 }
80 82
@@ -82,6 +84,7 @@ namespace OpenSim.Region.Physics.OdePlugin
82 { 84 {
83 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 85 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
84 86
87 CollisionLocker ode;
85 // TODO: this should be hard-coded in some common place 88 // TODO: this should be hard-coded in some common place
86 private const uint m_regionWidth = 256; 89 private const uint m_regionWidth = 256;
87 private const uint m_regionHeight = 256; 90 private const uint m_regionHeight = 256;
@@ -137,8 +140,9 @@ namespace OpenSim.Region.Physics.OdePlugin
137 /// Sets many properties that ODE requires to be stable 140 /// Sets many properties that ODE requires to be stable
138 /// These settings need to be tweaked 'exactly' right or weird stuff happens. 141 /// These settings need to be tweaked 'exactly' right or weird stuff happens.
139 /// </summary> 142 /// </summary>
140 public OdeScene() 143 public OdeScene(CollisionLocker dode)
141 { 144 {
145 ode = dode;
142 nearCallback = near; 146 nearCallback = near;
143 triCallback = TriCallback; 147 triCallback = TriCallback;
144 triArrayCallback = TriArrayCallback; 148 triArrayCallback = TriArrayCallback;
@@ -178,6 +182,7 @@ namespace OpenSim.Region.Physics.OdePlugin
178 182
179 lock (OdeLock) 183 lock (OdeLock)
180 { 184 {
185
181 // Creat the world and the first space 186 // Creat the world and the first space
182 world = d.WorldCreate(); 187 world = d.WorldCreate();
183 space = d.HashSpaceCreate(IntPtr.Zero); 188 space = d.HashSpaceCreate(IntPtr.Zero);
@@ -268,8 +273,14 @@ namespace OpenSim.Region.Physics.OdePlugin
268 // We'll be calling near recursivly if one 273 // We'll be calling near recursivly if one
269 // of them is a space to find all of the 274 // of them is a space to find all of the
270 // contact points in the space 275 // contact points in the space
271 276 try
272 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback); 277 {
278 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
279 }
280 catch (System.AccessViolationException)
281 {
282 m_log.Warn("[PHYSICS]: Unable to collide test a space");
283 }
273 //Colliding a space or a geom with a space or a geom. so drill down 284 //Colliding a space or a geom with a space or a geom. so drill down
274 285
275 //Collide all geoms in each space.. 286 //Collide all geoms in each space..
@@ -304,7 +315,7 @@ namespace OpenSim.Region.Physics.OdePlugin
304 name2 = "null"; 315 name2 = "null";
305 } 316 }
306 317
307 //if (id == d.GeomClassID.TriMeshClass) 318 //if (id == d.GeomClassId.TriMeshClass)
308 //{ 319 //{
309 // m_log.Info("near: A collision was detected between {1} and {2}", 0, name1, name2); 320 // m_log.Info("near: A collision was detected between {1} and {2}", 0, name1, name2);
310 //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2); 321 //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2);
@@ -321,6 +332,10 @@ namespace OpenSim.Region.Physics.OdePlugin
321 m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); 332 m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim.");
322 base.TriggerPhysicsBasedRestart(); 333 base.TriggerPhysicsBasedRestart();
323 } 334 }
335 catch (System.AccessViolationException)
336 {
337 m_log.Warn("[PHYSICS]: Unable to collide test an object");
338 }
324 339
325 PhysicsActor p1; 340 PhysicsActor p1;
326 PhysicsActor p2; 341 PhysicsActor p2;
@@ -438,7 +453,7 @@ namespace OpenSim.Region.Physics.OdePlugin
438 453
439 if (contacts[i].depth >= 0.25f) 454 if (contacts[i].depth >= 0.25f)
440 { 455 {
441 // Don't collide, one or both prim will explode. 456 // Don't collide, one or both prim will expld.
442 457
443 458
444 op1.m_interpenetrationcount++; 459 op1.m_interpenetrationcount++;
@@ -596,8 +611,14 @@ namespace OpenSim.Region.Physics.OdePlugin
596 // And we'll run this again against the avatar and the space segment 611 // And we'll run this again against the avatar and the space segment
597 // This will return with a bunch of possible objects in the space segment 612 // This will return with a bunch of possible objects in the space segment
598 // and we'll run it again on all of them. 613 // and we'll run it again on all of them.
599 614 try
600 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); 615 {
616 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
617 }
618 catch (AccessViolationException)
619 {
620 m_log.Warn("[PHYSICS]: Unable to space collide");
621 }
601 //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); 622 //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y);
602 //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10) 623 //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10)
603 //{ 624 //{
@@ -616,8 +637,14 @@ namespace OpenSim.Region.Physics.OdePlugin
616 // This if may not need to be there.. it might be skipped anyway. 637 // This if may not need to be there.. it might be skipped anyway.
617 if (d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) 638 if (d.BodyIsEnabled(chr.Body) && (!chr.m_disabled))
618 { 639 {
619 640 try
620 d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); 641 {
642 d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback);
643 }
644 catch (AccessViolationException)
645 {
646 m_log.Warn("[PHYSICS]: Unable to space collide");
647 }
621 //calculateSpaceForGeom(chr.Position) 648 //calculateSpaceForGeom(chr.Position)
622 //foreach (OdePrim ch2 in _prims) 649 //foreach (OdePrim ch2 in _prims)
623 /// should be a separate space -- lots of avatars will be N**2 slow 650 /// should be a separate space -- lots of avatars will be N**2 slow
@@ -634,7 +661,14 @@ namespace OpenSim.Region.Physics.OdePlugin
634 //} 661 //}
635 //} 662 //}
636 } 663 }
637 d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback); 664 try
665 {
666 d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback);
667 }
668 catch (AccessViolationException)
669 {
670 m_log.Warn("[PHYSICS]: Unable to space collide");
671 }
638 } 672 }
639 } 673 }
640 else 674 else
@@ -663,7 +697,7 @@ namespace OpenSim.Region.Physics.OdePlugin
663 pos.X = position.X; 697 pos.X = position.X;
664 pos.Y = position.Y; 698 pos.Y = position.Y;
665 pos.Z = position.Z; 699 pos.Z = position.Z;
666 OdeCharacter newAv = new OdeCharacter(avName, this, pos); 700 OdeCharacter newAv = new OdeCharacter(avName, this, pos, ode);
667 _characters.Add(newAv); 701 _characters.Add(newAv);
668 return newAv; 702 return newAv;
669 } 703 }
@@ -1007,7 +1041,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1007 OdePrim newPrim; 1041 OdePrim newPrim;
1008 lock (OdeLock) 1042 lock (OdeLock)
1009 { 1043 {
1010 newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical); 1044 newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical, ode);
1011 1045
1012 _prims.Add(newPrim); 1046 _prims.Add(newPrim);
1013 } 1047 }
@@ -1203,8 +1237,15 @@ namespace OpenSim.Region.Physics.OdePlugin
1203 actor.Move(timeStep); 1237 actor.Move(timeStep);
1204 actor.collidelock = true; 1238 actor.collidelock = true;
1205 } 1239 }
1240
1241 ode.dlock(world);
1206 1242
1207 collision_optimized(timeStep); 1243 collision_optimized(timeStep);
1244
1245
1246
1247 ode.dunlock(world);
1248
1208 try 1249 try
1209 { 1250 {
1210 d.WorldQuickStep(world, ODE_STEPSIZE); 1251 d.WorldQuickStep(world, ODE_STEPSIZE);
@@ -1228,25 +1269,28 @@ namespace OpenSim.Region.Physics.OdePlugin
1228 actor.UpdatePositionAndVelocity(); 1269 actor.UpdatePositionAndVelocity();
1229 } 1270 }
1230 1271
1231 bool processedtaints = false; 1272 if (!ode.lockquery())
1232 foreach (OdePrim prim in _taintedPrim)
1233 { 1273 {
1234 prim.ProcessTaints(timeStep); 1274 bool processedtaints = false;
1235 if (prim.m_taintremove) 1275 foreach (OdePrim prim in _taintedPrim)
1236 { 1276 {
1237 RemovePrimThreadLocked(prim); 1277 prim.ProcessTaints(timeStep);
1238 } 1278 if (prim.m_taintremove)
1239 processedtaints = true; 1279 {
1240 prim.m_collisionscore = 0; 1280 RemovePrimThreadLocked(prim);
1281 }
1282 processedtaints = true;
1283 prim.m_collisionscore = 0;
1284 }
1285 if (processedtaints)
1286 _taintedPrim = new List<OdePrim>();
1241 } 1287 }
1242
1243 foreach (OdePrim prim in _activeprims) 1288 foreach (OdePrim prim in _activeprims)
1244 { 1289 {
1245 prim.m_collisionscore = 0; 1290 prim.m_collisionscore = 0;
1246 } 1291 }
1247 1292
1248 if (processedtaints) 1293
1249 _taintedPrim = new List<OdePrim>();
1250 1294
1251 if (timeStep < 0.2f) 1295 if (timeStep < 0.2f)
1252 { 1296 {