aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitOdePlugin
diff options
context:
space:
mode:
authorUbitUmarov2012-10-09 00:18:39 +0100
committerUbitUmarov2012-10-09 00:18:39 +0100
commit3bf7201fd4d3e2b240f8139c20f88c916d338c31 (patch)
treef58ae6354071c182e487a72d9e5afad58c98d8a6 /OpenSim/Region/Physics/UbitOdePlugin
parent a few changes/fix (?) (diff)
downloadopensim-SC_OLD-3bf7201fd4d3e2b240f8139c20f88c916d338c31.zip
opensim-SC_OLD-3bf7201fd4d3e2b240f8139c20f88c916d338c31.tar.gz
opensim-SC_OLD-3bf7201fd4d3e2b240f8139c20f88c916d338c31.tar.bz2
opensim-SC_OLD-3bf7201fd4d3e2b240f8139c20f88c916d338c31.tar.xz
move terrain geom to own ode space. Limit range on raycast if includes
terrain until ode doesn't eat all stack. Add a pre-simulation method to do pending actors changes (except mesh assets still not ready to use), to be optionaly called before firing heartbeat. [UNTESTED]
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs128
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs16
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs165
3 files changed, 226 insertions, 83 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
index c2c4384..535a4e2 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
@@ -1325,12 +1325,48 @@ namespace OpenSim.Region.Physics.OdePlugin
1325 } 1325 }
1326 } 1326 }
1327 1327
1328
1329 private void SetGeom(IntPtr geom)
1330 {
1331 prim_geom = geom;
1332 //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
1333 if (prim_geom != IntPtr.Zero)
1334 {
1335
1336 if (m_NoColide)
1337 {
1338 d.GeomSetCategoryBits(prim_geom, 0);
1339 if (m_isphysical)
1340 {
1341 d.GeomSetCollideBits(prim_geom, (uint)CollisionCategories.Land);
1342 }
1343 else
1344 {
1345 d.GeomSetCollideBits(prim_geom, 0);
1346 d.GeomDisable(prim_geom);
1347 }
1348 }
1349 else
1350 {
1351 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
1352 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
1353 }
1354
1355 UpdatePrimBodyData();
1356 _parent_scene.actor_name_map[prim_geom] = this;
1357
1358 }
1359 else
1360 m_log.Warn("Setting bad Geom");
1361 }
1362
1328 private bool GetMeshGeom() 1363 private bool GetMeshGeom()
1329 { 1364 {
1330 IntPtr vertices, indices; 1365 IntPtr vertices, indices;
1331 int vertexCount, indexCount; 1366 int vertexCount, indexCount;
1332 int vertexStride, triStride; 1367 int vertexStride, triStride;
1333 1368
1369
1334 IMesh mesh = m_mesh; 1370 IMesh mesh = m_mesh;
1335 1371
1336 if (mesh == null) 1372 if (mesh == null)
@@ -1356,6 +1392,9 @@ namespace OpenSim.Region.Physics.OdePlugin
1356 m_mesh = null; 1392 m_mesh = null;
1357 return false; 1393 return false;
1358 } 1394 }
1395
1396 IntPtr geo = IntPtr.Zero;
1397
1359 try 1398 try
1360 { 1399 {
1361 _triMeshData = d.GeomTriMeshDataCreate(); 1400 _triMeshData = d.GeomTriMeshDataCreate();
@@ -1363,7 +1402,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1363 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); 1402 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
1364 d.GeomTriMeshDataPreprocess(_triMeshData); 1403 d.GeomTriMeshDataPreprocess(_triMeshData);
1365 1404
1366 prim_geom = d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null); 1405 geo = d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null);
1367 } 1406 }
1368 1407
1369 catch (Exception e) 1408 catch (Exception e)
@@ -1380,15 +1419,15 @@ namespace OpenSim.Region.Physics.OdePlugin
1380 } 1419 }
1381 } 1420 }
1382 _triMeshData = IntPtr.Zero; 1421 _triMeshData = IntPtr.Zero;
1383 prim_geom = IntPtr.Zero;
1384 1422
1385 m_hasOBB = false; 1423 m_hasOBB = false;
1386 m_OBBOffset = Vector3.Zero; 1424 m_OBBOffset = Vector3.Zero;
1387 m_OBB = _size * 0.5f; 1425 m_OBB = _size * 0.5f;
1388 m_physCost = 0.1f; 1426 m_physCost = 0.1f;
1389 m_streamCost = 1.0f; 1427 m_streamCost = 1.0f;
1428
1390 _parent_scene.mesher.ReleaseMesh(mesh); 1429 _parent_scene.mesher.ReleaseMesh(mesh);
1391 m_meshState = MeshState.AssetFailed; 1430 m_meshState = MeshState.MeshFailed;
1392 m_mesh = null; 1431 m_mesh = null;
1393 return false; 1432 return false;
1394 } 1433 }
@@ -1397,12 +1436,13 @@ namespace OpenSim.Region.Physics.OdePlugin
1397 // todo 1436 // todo
1398 m_streamCost = 1.0f; 1437 m_streamCost = 1.0f;
1399 1438
1439 SetGeom(geo);
1440
1400 return true; 1441 return true;
1401 } 1442 }
1402 1443
1403 private void CreateGeom() 1444 private void CreateGeom()
1404 { 1445 {
1405 IntPtr geo = IntPtr.Zero;
1406 bool hasMesh = false; 1446 bool hasMesh = false;
1407 1447
1408 m_NoColide = false; 1448 m_NoColide = false;
@@ -1418,8 +1458,11 @@ namespace OpenSim.Region.Physics.OdePlugin
1418 m_NoColide = true; 1458 m_NoColide = true;
1419 } 1459 }
1420 1460
1461
1421 if (!hasMesh) 1462 if (!hasMesh)
1422 { 1463 {
1464 IntPtr geo = IntPtr.Zero;
1465
1423 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1 1466 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1
1424 && _size.X == _size.Y && _size.Y == _size.Z) 1467 && _size.X == _size.Y && _size.Y == _size.Z)
1425 { // it's a sphere 1468 { // it's a sphere
@@ -1447,7 +1490,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1447 } 1490 }
1448 m_physCost = 0.1f; 1491 m_physCost = 0.1f;
1449 m_streamCost = 1.0f; 1492 m_streamCost = 1.0f;
1450 prim_geom = geo; 1493 SetGeom(geo);
1451 } 1494 }
1452 } 1495 }
1453 1496
@@ -2740,8 +2783,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2740 { 2783 {
2741 } 2784 }
2742 2785
2743
2744
2745 private void changeAddPhysRep(ODEPhysRepData repData) 2786 private void changeAddPhysRep(ODEPhysRepData repData)
2746 { 2787 {
2747 _size = repData.size; //?? 2788 _size = repData.size; //??
@@ -2763,10 +2804,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2763 2804
2764 if (prim_geom != IntPtr.Zero) 2805 if (prim_geom != IntPtr.Zero)
2765 { 2806 {
2766 UpdatePrimBodyData();
2767
2768 _parent_scene.actor_name_map[prim_geom] = this;
2769
2770 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 2807 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2771 d.Quaternion myrot = new d.Quaternion(); 2808 d.Quaternion myrot = new d.Quaternion();
2772 myrot.X = _orientation.X; 2809 myrot.X = _orientation.X;
@@ -2774,23 +2811,23 @@ namespace OpenSim.Region.Physics.OdePlugin
2774 myrot.Z = _orientation.Z; 2811 myrot.Z = _orientation.Z;
2775 myrot.W = _orientation.W; 2812 myrot.W = _orientation.W;
2776 d.GeomSetQuaternion(prim_geom, ref myrot); 2813 d.GeomSetQuaternion(prim_geom, ref myrot);
2814 }
2777 2815
2778 if (!m_isphysical) 2816 if (!m_isphysical)
2779 { 2817 {
2780 SetInStaticSpace(this); 2818 SetInStaticSpace(this);
2781 UpdateCollisionCatFlags(); 2819 UpdateCollisionCatFlags();
2782 ApplyCollisionCatFlags(); 2820 ApplyCollisionCatFlags();
2783 } 2821 }
2784 else 2822 else
2785 MakeBody(); 2823 MakeBody();
2786 2824
2787 if ((m_meshState & MeshState.NeedMask) != 0) 2825 if ((m_meshState & MeshState.NeedMask) != 0)
2788 { 2826 {
2789 repData.size = _size; 2827 repData.size = _size;
2790 repData.pbs = _pbs; 2828 repData.pbs = _pbs;
2791 repData.shapetype = m_shapetype; 2829 repData.shapetype = m_shapetype;
2792 _parent_scene.m_meshWorker.RequestMesh(repData); 2830 _parent_scene.m_meshWorker.RequestMesh(repData);
2793 }
2794 } 2831 }
2795 } 2832 }
2796 2833
@@ -2831,14 +2868,10 @@ namespace OpenSim.Region.Physics.OdePlugin
2831 2868
2832 primVolume = repData.volume; 2869 primVolume = repData.volume;
2833 2870
2834 CreateGeom(); 2871 CreateGeom();
2835 2872
2836 if (prim_geom != IntPtr.Zero) 2873 if (prim_geom != IntPtr.Zero)
2837 { 2874 {
2838 UpdatePrimBodyData();
2839
2840 _parent_scene.actor_name_map[prim_geom] = this;
2841
2842 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 2875 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2843 d.Quaternion myrot = new d.Quaternion(); 2876 d.Quaternion myrot = new d.Quaternion();
2844 myrot.X = _orientation.X; 2877 myrot.X = _orientation.X;
@@ -2846,29 +2879,28 @@ namespace OpenSim.Region.Physics.OdePlugin
2846 myrot.Z = _orientation.Z; 2879 myrot.Z = _orientation.Z;
2847 myrot.W = _orientation.W; 2880 myrot.W = _orientation.W;
2848 d.GeomSetQuaternion(prim_geom, ref myrot); 2881 d.GeomSetQuaternion(prim_geom, ref myrot);
2882 }
2849 2883
2850 if (m_isphysical) 2884 if (m_isphysical)
2885 {
2886 if (chp)
2851 { 2887 {
2852 if (chp) 2888 if (parent != null)
2853 { 2889 {
2854 if (parent != null) 2890 parent.MakeBody();
2855 {
2856 parent.MakeBody();
2857 }
2858 } 2891 }
2859 else
2860 MakeBody();
2861 } 2892 }
2862
2863 else 2893 else
2864 { 2894 MakeBody();
2865 SetInStaticSpace(this);
2866 UpdateCollisionCatFlags();
2867 ApplyCollisionCatFlags();
2868 }
2869
2870 resetCollisionAccounting();
2871 } 2895 }
2896 else
2897 {
2898 SetInStaticSpace(this);
2899 UpdateCollisionCatFlags();
2900 ApplyCollisionCatFlags();
2901 }
2902
2903 resetCollisionAccounting();
2872 2904
2873 if ((m_meshState & MeshState.NeedMask) != 0) 2905 if ((m_meshState & MeshState.NeedMask) != 0)
2874 { 2906 {
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs
index 21fe9c0..06cb302 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs
@@ -129,7 +129,7 @@ namespace OpenSim.Region.Physics.OdePlugin
129 req.length = length; 129 req.length = length;
130 req.Normal = direction; 130 req.Normal = direction;
131 req.Origin = position; 131 req.Origin = position;
132 req.filter = RayFilterFlags.AllPrims; 132 req.filter = RayFilterFlags.AllPrims | RayFilterFlags.land;
133 133
134 m_PendingRequests.Enqueue(req); 134 m_PendingRequests.Enqueue(req);
135 } 135 }
@@ -261,6 +261,12 @@ namespace OpenSim.Region.Physics.OdePlugin
261 closestHit = ((CurrentRayFilter & RayFilterFlags.ClosestHit) == 0 ? 0 : 1); 261 closestHit = ((CurrentRayFilter & RayFilterFlags.ClosestHit) == 0 ? 0 : 1);
262 backfacecull = ((CurrentRayFilter & RayFilterFlags.BackFaceCull) == 0 ? 0 : 1); 262 backfacecull = ((CurrentRayFilter & RayFilterFlags.BackFaceCull) == 0 ? 0 : 1);
263 263
264 // current ode land to ray collisions is very bad
265 // so for now limit its range badly
266
267 if (req.length > 30.0f && (CurrentRayFilter & RayFilterFlags.land) != 0)
268 req.length = 30.0f;
269
264 d.GeomRaySetLength(ray, req.length); 270 d.GeomRaySetLength(ray, req.length);
265 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z); 271 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
266 d.GeomRaySetParams(ray, 0, backfacecull); 272 d.GeomRaySetParams(ray, 0, backfacecull);
@@ -288,7 +294,10 @@ namespace OpenSim.Region.Physics.OdePlugin
288 catflags |= CollisionCategories.Water; 294 catflags |= CollisionCategories.Water;
289 295
290 if (catflags != 0) 296 if (catflags != 0)
297 {
298 d.GeomSetCollideBits(ray, (uint)catflags);
291 doSpaceRay(req); 299 doSpaceRay(req);
300 }
292 } 301 }
293 else 302 else
294 { 303 {
@@ -314,7 +323,8 @@ namespace OpenSim.Region.Physics.OdePlugin
314 /// 323 ///
315 324
316 private const RayFilterFlags FilterActiveSpace = RayFilterFlags.agent | RayFilterFlags.physical | RayFilterFlags.LSLPhanton; 325 private const RayFilterFlags FilterActiveSpace = RayFilterFlags.agent | RayFilterFlags.physical | RayFilterFlags.LSLPhanton;
317 private const RayFilterFlags FilterStaticSpace = RayFilterFlags.water | RayFilterFlags.land | RayFilterFlags.nonphysical | RayFilterFlags.LSLPhanton; 326// private const RayFilterFlags FilterStaticSpace = RayFilterFlags.water | RayFilterFlags.land | RayFilterFlags.nonphysical | RayFilterFlags.LSLPhanton;
327 private const RayFilterFlags FilterStaticSpace = RayFilterFlags.water | RayFilterFlags.nonphysical | RayFilterFlags.LSLPhanton;
318 328
319 private void doSpaceRay(ODERayRequest req) 329 private void doSpaceRay(ODERayRequest req)
320 { 330 {
@@ -323,6 +333,8 @@ namespace OpenSim.Region.Physics.OdePlugin
323 d.SpaceCollide2(ray, m_scene.ActiveSpace, IntPtr.Zero, nearCallback); 333 d.SpaceCollide2(ray, m_scene.ActiveSpace, IntPtr.Zero, nearCallback);
324 if ((CurrentRayFilter & FilterStaticSpace) != 0 && (m_contactResults.Count < CurrentMaxCount)) 334 if ((CurrentRayFilter & FilterStaticSpace) != 0 && (m_contactResults.Count < CurrentMaxCount))
325 d.SpaceCollide2(ray, m_scene.StaticSpace, IntPtr.Zero, nearCallback); 335 d.SpaceCollide2(ray, m_scene.StaticSpace, IntPtr.Zero, nearCallback);
336 if ((CurrentRayFilter & RayFilterFlags.land) != 0 && (m_contactResults.Count < CurrentMaxCount))
337 d.SpaceCollide2(ray, m_scene.GroundSpace, IntPtr.Zero, nearCallback);
326 338
327 if (req.callbackMethod is RaycastCallback) 339 if (req.callbackMethod is RaycastCallback)
328 { 340 {
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
index ed2a531..beaba13 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
@@ -300,6 +300,7 @@ namespace OpenSim.Region.Physics.OdePlugin
300 public IntPtr TopSpace; // the global space 300 public IntPtr TopSpace; // the global space
301 public IntPtr ActiveSpace; // space for active prims 301 public IntPtr ActiveSpace; // space for active prims
302 public IntPtr StaticSpace; // space for the static things around 302 public IntPtr StaticSpace; // space for the static things around
303 public IntPtr GroundSpace; // space for ground
303 304
304 // some speedup variables 305 // some speedup variables
305 private int spaceGridMaxX; 306 private int spaceGridMaxX;
@@ -372,6 +373,7 @@ namespace OpenSim.Region.Physics.OdePlugin
372 // now the major subspaces 373 // now the major subspaces
373 ActiveSpace = d.HashSpaceCreate(TopSpace); 374 ActiveSpace = d.HashSpaceCreate(TopSpace);
374 StaticSpace = d.HashSpaceCreate(TopSpace); 375 StaticSpace = d.HashSpaceCreate(TopSpace);
376 GroundSpace = d.HashSpaceCreate(TopSpace);
375 } 377 }
376 catch 378 catch
377 { 379 {
@@ -381,10 +383,12 @@ namespace OpenSim.Region.Physics.OdePlugin
381 d.HashSpaceSetLevels(TopSpace, -2, 8); 383 d.HashSpaceSetLevels(TopSpace, -2, 8);
382 d.HashSpaceSetLevels(ActiveSpace, -2, 8); 384 d.HashSpaceSetLevels(ActiveSpace, -2, 8);
383 d.HashSpaceSetLevels(StaticSpace, -2, 8); 385 d.HashSpaceSetLevels(StaticSpace, -2, 8);
386 d.HashSpaceSetLevels(GroundSpace, 0, 8);
384 387
385 // demote to second level 388 // demote to second level
386 d.SpaceSetSublevel(ActiveSpace, 1); 389 d.SpaceSetSublevel(ActiveSpace, 1);
387 d.SpaceSetSublevel(StaticSpace, 1); 390 d.SpaceSetSublevel(StaticSpace, 1);
391 d.SpaceSetSublevel(GroundSpace, 1);
388 392
389 d.GeomSetCategoryBits(ActiveSpace, (uint)(CollisionCategories.Space | 393 d.GeomSetCategoryBits(ActiveSpace, (uint)(CollisionCategories.Space |
390 CollisionCategories.Geom | 394 CollisionCategories.Geom |
@@ -402,6 +406,8 @@ namespace OpenSim.Region.Physics.OdePlugin
402 )); 406 ));
403 d.GeomSetCollideBits(StaticSpace, 0); 407 d.GeomSetCollideBits(StaticSpace, 0);
404 408
409 d.GeomSetCategoryBits(GroundSpace, (uint)(CollisionCategories.Land));
410 d.GeomSetCollideBits(GroundSpace, 0);
405 411
406 contactgroup = d.JointGroupCreate(0); 412 contactgroup = d.JointGroupCreate(0);
407 //contactgroup 413 //contactgroup
@@ -1210,6 +1216,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1210 chr.CollidingObj = false; 1216 chr.CollidingObj = false;
1211 // do colisions with static space 1217 // do colisions with static space
1212 d.SpaceCollide2(StaticSpace, chr.Shell, IntPtr.Zero, nearCallback); 1218 d.SpaceCollide2(StaticSpace, chr.Shell, IntPtr.Zero, nearCallback);
1219 // no coll with gnd
1213 } 1220 }
1214 } 1221 }
1215 catch (AccessViolationException) 1222 catch (AccessViolationException)
@@ -1238,7 +1245,10 @@ namespace OpenSim.Region.Physics.OdePlugin
1238 if (!prm.m_outbounds) 1245 if (!prm.m_outbounds)
1239 { 1246 {
1240 if (d.BodyIsEnabled(prm.Body)) 1247 if (d.BodyIsEnabled(prm.Body))
1248 {
1241 d.SpaceCollide2(StaticSpace, prm.collide_geom, IntPtr.Zero, nearCallback); 1249 d.SpaceCollide2(StaticSpace, prm.collide_geom, IntPtr.Zero, nearCallback);
1250 d.SpaceCollide2(GroundSpace, prm.collide_geom, IntPtr.Zero, nearCallback);
1251 }
1242 } 1252 }
1243 } 1253 }
1244 } 1254 }
@@ -1595,8 +1605,52 @@ namespace OpenSim.Region.Physics.OdePlugin
1595 /// </summary> 1605 /// </summary>
1596 /// <param name="prim"></param> 1606 /// <param name="prim"></param>
1597 public override void AddPhysicsActorTaint(PhysicsActor prim) 1607 public override void AddPhysicsActorTaint(PhysicsActor prim)
1608 {
1609 }
1610
1611 // does all pending changes generated during region load process
1612 public override void PrepareSimulation()
1613 {
1614 lock (OdeLock)
1598 { 1615 {
1616 if (world == IntPtr.Zero)
1617 {
1618 ChangesQueue.Clear();
1619 return;
1620 }
1621
1622 ODEchangeitem item;
1623
1624 int donechanges = 0;
1625 if (ChangesQueue.Count > 0)
1626 {
1627 m_log.InfoFormat("[ODE] start processing pending actor operations");
1628 int tstart = Util.EnvironmentTickCount();
1629
1630 while (ChangesQueue.Dequeue(out item))
1631 {
1632 if (item.actor != null)
1633 {
1634 try
1635 {
1636 if (item.actor is OdeCharacter)
1637 ((OdeCharacter)item.actor).DoAChange(item.what, item.arg);
1638 else if (((OdePrim)item.actor).DoAChange(item.what, item.arg))
1639 RemovePrimThreadLocked((OdePrim)item.actor);
1640 }
1641 catch
1642 {
1643 m_log.WarnFormat("[PHYSICS]: Operation failed for a actor {0} {1}",
1644 item.actor.Name, item.what.ToString());
1645 }
1646 }
1647 donechanges++;
1648 }
1649 int time = Util.EnvironmentTickCountSubtract(tstart);
1650 m_log.InfoFormat("[ODE] finished {0} operations in {1}ms", donechanges, time);
1651 }
1599 } 1652 }
1653 }
1600 1654
1601 /// <summary> 1655 /// <summary>
1602 /// This is our main simulate loop 1656 /// This is our main simulate loop
@@ -1642,7 +1696,40 @@ namespace OpenSim.Region.Physics.OdePlugin
1642 lock(OdeLock) 1696 lock(OdeLock)
1643 { 1697 {
1644 if (world == IntPtr.Zero) 1698 if (world == IntPtr.Zero)
1699 {
1700 ChangesQueue.Clear();
1645 return 0; 1701 return 0;
1702 }
1703
1704 ODEchangeitem item;
1705
1706 if (ChangesQueue.Count > 0)
1707 {
1708 int ttmpstart = Util.EnvironmentTickCount();
1709 int ttmp;
1710
1711 while (ChangesQueue.Dequeue(out item))
1712 {
1713 if (item.actor != null)
1714 {
1715 try
1716 {
1717 if (item.actor is OdeCharacter)
1718 ((OdeCharacter)item.actor).DoAChange(item.what, item.arg);
1719 else if (((OdePrim)item.actor).DoAChange(item.what, item.arg))
1720 RemovePrimThreadLocked((OdePrim)item.actor);
1721 }
1722 catch
1723 {
1724 m_log.WarnFormat("[PHYSICS]: doChange failed for a actor {0} {1}",
1725 item.actor.Name, item.what.ToString());
1726 }
1727 }
1728 ttmp = Util.EnvironmentTickCountSubtract(ttmpstart);
1729 if (ttmp > 20)
1730 break;
1731 }
1732 }
1646 1733
1647 d.WorldSetQuickStepNumIterations(world, curphysiteractions); 1734 d.WorldSetQuickStepNumIterations(world, curphysiteractions);
1648 1735
@@ -1653,35 +1740,6 @@ namespace OpenSim.Region.Physics.OdePlugin
1653 // clear pointer/counter to contacts to pass into joints 1740 // clear pointer/counter to contacts to pass into joints
1654 m_global_contactcount = 0; 1741 m_global_contactcount = 0;
1655 1742
1656 ODEchangeitem item;
1657
1658 if(ChangesQueue.Count >0)
1659 {
1660 int ttmpstart = Util.EnvironmentTickCount();
1661 int ttmp;
1662
1663 while(ChangesQueue.Dequeue(out item))
1664 {
1665 if (item.actor != null)
1666 {
1667 try
1668 {
1669 if (item.actor is OdeCharacter)
1670 ((OdeCharacter)item.actor).DoAChange(item.what, item.arg);
1671 else if (((OdePrim)item.actor).DoAChange(item.what, item.arg))
1672 RemovePrimThreadLocked((OdePrim)item.actor);
1673 }
1674 catch
1675 {
1676 m_log.WarnFormat("[PHYSICS]: doChange failed for a actor {0} {1}",
1677 item.actor.Name, item.what.ToString());
1678 }
1679 }
1680 ttmp = Util.EnvironmentTickCountSubtract(ttmpstart);
1681 if (ttmp > 20)
1682 break;
1683 }
1684 }
1685 1743
1686 // Move characters 1744 // Move characters
1687 lock (_characters) 1745 lock (_characters)
@@ -1813,10 +1871,47 @@ namespace OpenSim.Region.Physics.OdePlugin
1813 mesher.ExpireReleaseMeshs(); 1871 mesher.ExpireReleaseMeshs();
1814 m_lastMeshExpire = now; 1872 m_lastMeshExpire = now;
1815 } 1873 }
1874
1875// information block running in debug only
1816/* 1876/*
1817 int nactivegeoms = d.SpaceGetNumGeoms(ActiveSpace); 1877 int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace);
1818 int nstaticgeoms = d.SpaceGetNumGeoms(StaticSpace); 1878 int ntopstaticgeoms = d.SpaceGetNumGeoms(StaticSpace);
1879 int ngroundgeoms = d.SpaceGetNumGeoms(GroundSpace);
1880
1881 int nactivegeoms = 0;
1882 int nactivespaces = 0;
1883
1884 int nstaticgeoms = 0;
1885 int nstaticspaces = 0;
1886 IntPtr sp;
1887
1888 for (int i = 0; i < ntopactivegeoms; i++)
1889 {
1890 sp = d.SpaceGetGeom(ActiveSpace, i);
1891 if (d.GeomIsSpace(sp))
1892 {
1893 nactivespaces++;
1894 nactivegeoms += d.SpaceGetNumGeoms(sp);
1895 }
1896 else
1897 nactivegeoms++;
1898 }
1899
1900 for (int i = 0; i < ntopstaticgeoms; i++)
1901 {
1902 sp = d.SpaceGetGeom(StaticSpace, i);
1903 if (d.GeomIsSpace(sp))
1904 {
1905 nstaticspaces++;
1906 nstaticgeoms += d.SpaceGetNumGeoms(sp);
1907 }
1908 else
1909 nstaticgeoms++;
1910 }
1911
1819 int ntopgeoms = d.SpaceGetNumGeoms(TopSpace); 1912 int ntopgeoms = d.SpaceGetNumGeoms(TopSpace);
1913
1914 int totgeoms = nstaticgeoms + nactivegeoms + ngroundgeoms + 1; // one ray
1820 int nbodies = d.NTotalBodies; 1915 int nbodies = d.NTotalBodies;
1821 int ngeoms = d.NTotalGeoms; 1916 int ngeoms = d.NTotalGeoms;
1822*/ 1917*/
@@ -2113,7 +2208,9 @@ namespace OpenSim.Region.Physics.OdePlugin
2113 offset, thickness, wrap); 2208 offset, thickness, wrap);
2114 2209
2115 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); 2210 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2116 GroundGeom = d.CreateHeightfield(StaticSpace, HeightmapData, 1); 2211
2212 GroundGeom = d.CreateHeightfield(GroundSpace, HeightmapData, 1);
2213
2117 if (GroundGeom != IntPtr.Zero) 2214 if (GroundGeom != IntPtr.Zero)
2118 { 2215 {
2119 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land)); 2216 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land));
@@ -2234,12 +2331,13 @@ namespace OpenSim.Region.Physics.OdePlugin
2234 thickness, wrap); 2331 thickness, wrap);
2235 2332
2236// d.GeomUbitTerrainDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); 2333// d.GeomUbitTerrainDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2237 GroundGeom = d.CreateUbitTerrain(StaticSpace, HeightmapData, 1); 2334 GroundGeom = d.CreateUbitTerrain(GroundSpace, HeightmapData, 1);
2238 if (GroundGeom != IntPtr.Zero) 2335 if (GroundGeom != IntPtr.Zero)
2239 { 2336 {
2240 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land)); 2337 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land));
2241 d.GeomSetCollideBits(GroundGeom, 0); 2338 d.GeomSetCollideBits(GroundGeom, 0);
2242 2339
2340
2243 PhysicsActor pa = new NullPhysicsActor(); 2341 PhysicsActor pa = new NullPhysicsActor();
2244 pa.Name = "Terrain"; 2342 pa.Name = "Terrain";
2245 pa.PhysicsActorType = (int)ActorTypes.Ground; 2343 pa.PhysicsActorType = (int)ActorTypes.Ground;
@@ -2455,6 +2553,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2455 d.GeomDestroy(GroundGeom); 2553 d.GeomDestroy(GroundGeom);
2456 } 2554 }
2457 2555
2556
2458 RegionTerrain.Clear(); 2557 RegionTerrain.Clear();
2459 2558
2460 if (TerrainHeightFieldHeightsHandlers.Count > 0) 2559 if (TerrainHeightFieldHeightsHandlers.Count > 0)