aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
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/OdeScene.cs
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 'OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs165
1 files changed, 132 insertions, 33 deletions
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)