aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs227
1 files changed, 74 insertions, 153 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
index 5602bd9..9867bfd 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
@@ -201,7 +201,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
201 public float ODE_STEPSIZE = 0.020f; 201 public float ODE_STEPSIZE = 0.020f;
202 public float HalfOdeStep = 0.01f; 202 public float HalfOdeStep = 0.01f;
203 public int odetimestepMS = 20; // rounded 203 public int odetimestepMS = 20; // rounded
204 private float metersInSpace = 25.6f;
205 private float m_timeDilation = 1.0f; 204 private float m_timeDilation = 1.0f;
206 205
207 private double m_lastframe; 206 private double m_lastframe;
@@ -284,16 +283,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
284 public IntPtr StaticSpace; // space for the static things around 283 public IntPtr StaticSpace; // space for the static things around
285 public IntPtr GroundSpace; // space for ground 284 public IntPtr GroundSpace; // space for ground
286 285
287 // some speedup variables
288 private int spaceGridMaxX;
289 private int spaceGridMaxY;
290 private float spacesPerMeterX;
291 private float spacesPerMeterY;
292
293 // split static geometry collision into a grid as before
294 private IntPtr[,] staticPrimspace;
295 private IntPtr[] staticPrimspaceOffRegion;
296
297 public Object OdeLock; 286 public Object OdeLock;
298 public static Object SimulationLock; 287 public static Object SimulationLock;
299 288
@@ -386,13 +375,23 @@ namespace OpenSim.Region.PhysicsModule.ubOde
386 try 375 try
387 { 376 {
388 world = d.WorldCreate(); 377 world = d.WorldCreate();
389 TopSpace = d.HashSpaceCreate(IntPtr.Zero); 378 TopSpace = d.SimpleSpaceCreate(IntPtr.Zero);
390 379 ActiveSpace = d.SimpleSpaceCreate(TopSpace);
391 // now the major subspaces 380 CharsSpace = d.SimpleSpaceCreate(TopSpace);
392 ActiveSpace = d.HashSpaceCreate(TopSpace); 381 GroundSpace = d.SimpleSpaceCreate(TopSpace);
393 CharsSpace = d.HashSpaceCreate(TopSpace); 382 float sx = WorldExtents.X + 16;
394 StaticSpace = d.HashSpaceCreate(TopSpace); 383 float sy = WorldExtents.Y + 16;
395 GroundSpace = d.HashSpaceCreate(TopSpace); 384 d.Vector3 ex =new d.Vector3(sx, sy, 0);
385 d.Vector3 px =new d.Vector3(sx * 0.5f, sx * 0.5f, 0);
386 if(sx < sy)
387 sx = sy;
388 sx = (float)Math.Log(sx) * 1.442695f + 0.5f;
389 int dp = (int)sx - 2;
390 if(dp > 8)
391 dp = 8;
392 else if(dp < 4)
393 dp = 4;
394 StaticSpace = d.QuadTreeSpaceCreate(TopSpace, ref px, ref ex, dp);
396 } 395 }
397 catch 396 catch
398 { 397 {
@@ -400,12 +399,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
400 // i did! 399 // i did!
401 } 400 }
402 401
403 d.HashSpaceSetLevels(TopSpace, -5, 12);
404 d.HashSpaceSetLevels(ActiveSpace, -5, 10);
405 d.HashSpaceSetLevels(CharsSpace, -4, 3);
406 d.HashSpaceSetLevels(StaticSpace, -5, 12);
407 d.HashSpaceSetLevels(GroundSpace, 0, 8);
408
409 // demote to second level 402 // demote to second level
410 d.SpaceSetSublevel(ActiveSpace, 1); 403 d.SpaceSetSublevel(ActiveSpace, 1);
411 d.SpaceSetSublevel(CharsSpace, 1); 404 d.SpaceSetSublevel(CharsSpace, 1);
@@ -469,8 +462,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
469 gravityy = physicsconfig.GetFloat("world_gravityy", gravityy); 462 gravityy = physicsconfig.GetFloat("world_gravityy", gravityy);
470 gravityz = physicsconfig.GetFloat("world_gravityz", gravityz); 463 gravityz = physicsconfig.GetFloat("world_gravityz", gravityz);
471 464
472 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", metersInSpace);
473
474 // contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer); 465 // contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer);
475 466
476 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE); 467 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE);
@@ -560,76 +551,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
560 m_materialContactsData[(int)Material.light].mu = 0.0f; 551 m_materialContactsData[(int)Material.light].mu = 0.0f;
561 m_materialContactsData[(int)Material.light].bounce = 0.0f; 552 m_materialContactsData[(int)Material.light].bounce = 0.0f;
562 553
563
564 spacesPerMeterX = 1.0f / metersInSpace;
565 spacesPerMeterY = spacesPerMeterX;
566 spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeterX);
567 spaceGridMaxY = (int)(WorldExtents.Y * spacesPerMeterY);
568
569 if (spaceGridMaxX > 24)
570 {
571 spaceGridMaxX = 24;
572 spacesPerMeterX = spaceGridMaxX / WorldExtents.X;
573 }
574
575 if (spaceGridMaxY > 24)
576 {
577 spaceGridMaxY = 24;
578 spacesPerMeterY = spaceGridMaxY / WorldExtents.Y;
579 }
580
581 staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY];
582
583 // create all spaces now
584 int i, j;
585 IntPtr newspace;
586
587 for (i = 0; i < spaceGridMaxX; i++)
588 for (j = 0; j < spaceGridMaxY; j++)
589 {
590 newspace = d.HashSpaceCreate(StaticSpace);
591 d.GeomSetCategoryBits(newspace, (int)CollisionCategories.Space);
592 waitForSpaceUnlock(newspace);
593 d.SpaceSetSublevel(newspace, 2);
594 d.HashSpaceSetLevels(newspace, -2, 8);
595 d.GeomSetCategoryBits(newspace, (uint)(CollisionCategories.Space |
596 CollisionCategories.Geom |
597 CollisionCategories.Land |
598 CollisionCategories.Water |
599 CollisionCategories.Phantom |
600 CollisionCategories.VolumeDtc
601 ));
602 d.GeomSetCollideBits(newspace, 0);
603
604 staticPrimspace[i, j] = newspace;
605 }
606
607 // let this now be index limit
608 spaceGridMaxX--;
609 spaceGridMaxY--;
610
611 // create 4 off world spaces (x<0,x>max,y<0,y>max)
612 staticPrimspaceOffRegion = new IntPtr[4];
613
614 for (i = 0; i < 4; i++)
615 {
616 newspace = d.HashSpaceCreate(StaticSpace);
617 d.GeomSetCategoryBits(newspace, (int)CollisionCategories.Space);
618 waitForSpaceUnlock(newspace);
619 d.SpaceSetSublevel(newspace, 2);
620 d.HashSpaceSetLevels(newspace, -2, 8);
621 d.GeomSetCategoryBits(newspace, (uint)(CollisionCategories.Space |
622 CollisionCategories.Geom |
623 CollisionCategories.Land |
624 CollisionCategories.Water |
625 CollisionCategories.Phantom |
626 CollisionCategories.VolumeDtc
627 ));
628 d.GeomSetCollideBits(newspace, 0);
629
630 staticPrimspaceOffRegion[i] = newspace;
631 }
632
633 m_lastframe = Util.GetTimeStamp(); 554 m_lastframe = Util.GetTimeStamp();
634 m_lastMeshExpire = m_lastframe; 555 m_lastMeshExpire = m_lastframe;
635 step_time = -1; 556 step_time = -1;
@@ -758,7 +679,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
758 // 679 //
759 */ 680 */
760 681
761
762 if (d.GeomGetCategoryBits(g1) == (uint)CollisionCategories.VolumeDtc || 682 if (d.GeomGetCategoryBits(g1) == (uint)CollisionCategories.VolumeDtc ||
763 d.GeomGetCategoryBits(g2) == (uint)CollisionCategories.VolumeDtc) 683 d.GeomGetCategoryBits(g2) == (uint)CollisionCategories.VolumeDtc)
764 { 684 {
@@ -1307,6 +1227,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1307 public override void RemoveAvatar(PhysicsActor actor) 1227 public override void RemoveAvatar(PhysicsActor actor)
1308 { 1228 {
1309 //m_log.Debug("[PHYSICS]:ODELOCK"); 1229 //m_log.Debug("[PHYSICS]:ODELOCK");
1230 if (world == IntPtr.Zero)
1231 return;
1232
1310 lock (OdeLock) 1233 lock (OdeLock)
1311 { 1234 {
1312 d.AllocateODEDataForThread(0); 1235 d.AllocateODEDataForThread(0);
@@ -1461,27 +1384,23 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1461 1384
1462 /// <summary> 1385 /// <summary>
1463 /// Called when a static prim moves or becomes static 1386 /// Called when a static prim moves or becomes static
1464 /// Places the prim in a space one the static sub-spaces grid 1387 /// Places the prim in a space one the static space
1465 /// </summary> 1388 /// </summary>
1466 /// <param name="geom">the pointer to the geom that moved</param> 1389 /// <param name="geom">the pointer to the geom that moved</param>
1467 /// <param name="pos">the position that the geom moved to</param>
1468 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param> 1390 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param>
1469 /// <returns>a pointer to the new space it's in</returns> 1391 /// <returns>a pointer to the new space it's in</returns>
1470 public IntPtr MoveGeomToStaticSpace(IntPtr geom, Vector3 pos, IntPtr currentspace) 1392 public IntPtr MoveGeomToStaticSpace(IntPtr geom, IntPtr currentspace)
1471 { 1393 {
1472 // moves a prim into another static sub-space or from another space into a static sub-space 1394 // moves a prim into static sub-space
1473 1395
1474 // Called ODEPrim so 1396 // Called ODEPrim so
1475 // it's already in locked space. 1397 // it's already in locked space.
1476 1398
1477 if (geom == IntPtr.Zero) // shouldn't happen 1399 if (geom == IntPtr.Zero) // shouldn't happen
1478 return IntPtr.Zero; 1400 return IntPtr.Zero;
1479 1401
1480 // get the static sub-space for current position 1402 if (StaticSpace == currentspace) // if we are there all done
1481 IntPtr newspace = calculateSpaceForGeom(pos); 1403 return StaticSpace;
1482
1483 if (newspace == currentspace) // if we are there all done
1484 return newspace;
1485 1404
1486 // else remove it from its current space 1405 // else remove it from its current space
1487 if (currentspace != IntPtr.Zero && d.SpaceQuery(currentspace, geom)) 1406 if (currentspace != IntPtr.Zero && d.SpaceQuery(currentspace, geom))
@@ -1516,44 +1435,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1516 { 1435 {
1517 d.SpaceDestroy(currentspace); 1436 d.SpaceDestroy(currentspace);
1518 } 1437 }
1519
1520 } 1438 }
1521 } 1439 }
1522 } 1440 }
1523 1441
1524 // put the geom in the newspace 1442 // put the geom in the newspace
1525 waitForSpaceUnlock(newspace); 1443 waitForSpaceUnlock(StaticSpace);
1526 d.SpaceAdd(newspace, geom); 1444 d.SpaceAdd(StaticSpace, geom);
1527 1445
1528 // let caller know this newspace 1446 return StaticSpace;
1529 return newspace;
1530 } 1447 }
1531 1448
1532 /// <summary>
1533 /// Calculates the space the prim should be in by its position
1534 /// </summary>
1535 /// <param name="pos"></param>
1536 /// <returns>a pointer to the space. This could be a new space or reused space.</returns>
1537 public IntPtr calculateSpaceForGeom(Vector3 pos)
1538 {
1539 int x, y;
1540
1541 if (pos.X < 0)
1542 return staticPrimspaceOffRegion[0];
1543
1544 if (pos.Y < 0)
1545 return staticPrimspaceOffRegion[2];
1546
1547 x = (int)(pos.X * spacesPerMeterX);
1548 if (x > spaceGridMaxX)
1549 return staticPrimspaceOffRegion[1];
1550
1551 y = (int)(pos.Y * spacesPerMeterY);
1552 if (y > spaceGridMaxY)
1553 return staticPrimspaceOffRegion[3];
1554
1555 return staticPrimspace[x, y];
1556 }
1557 1449
1558 #endregion 1450 #endregion
1559 1451
@@ -1642,6 +1534,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1642 /// <returns></returns> 1534 /// <returns></returns>
1643 public override float Simulate(float reqTimeStep) 1535 public override float Simulate(float reqTimeStep)
1644 { 1536 {
1537 if (world == IntPtr.Zero)
1538 return 0;
1539
1645 double now = Util.GetTimeStamp(); 1540 double now = Util.GetTimeStamp();
1646 double timeStep = now - m_lastframe; 1541 double timeStep = now - m_lastframe;
1647 m_lastframe = now; 1542 m_lastframe = now;
@@ -1680,9 +1575,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1680 double maxChangestime = (int)(reqTimeStep * 500f); // half the time 1575 double maxChangestime = (int)(reqTimeStep * 500f); // half the time
1681 double maxLoopTime = (int)(reqTimeStep * 1200f); // 1.2 the time 1576 double maxLoopTime = (int)(reqTimeStep * 1200f); // 1.2 the time
1682 1577
1683// double collisionTime = 0; 1578
1684// double qstepTIme = 0; 1579 double collisionTime = 0;
1685// double tmpTime = 0; 1580 double qstepTIme = 0;
1581 double tmpTime = 0;
1582 double changestot = 0;
1583 double collisonRepo = 0;
1584 double updatesTime = 0;
1585 double moveTime = 0;
1586 double rayTime = 0;
1686 1587
1687 d.AllocateODEDataForThread(~0U); 1588 d.AllocateODEDataForThread(~0U);
1688 1589
@@ -1720,6 +1621,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1720 m_global_contactcount = 0; 1621 m_global_contactcount = 0;
1721 1622
1722 1623
1624 tmpTime = Util.GetTimeStampMS();
1625
1723 // Move characters 1626 // Move characters
1724 lock (_characters) 1627 lock (_characters)
1725 { 1628 {
@@ -1747,13 +1650,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1747 aprim.Move(); 1650 aprim.Move();
1748 } 1651 }
1749 } 1652 }
1653 moveTime += Util.GetTimeStampMS() - tmpTime;
1750 1654
1655 tmpTime = Util.GetTimeStampMS();
1751 m_rayCastManager.ProcessQueuedRequests(); 1656 m_rayCastManager.ProcessQueuedRequests();
1657 rayTime += Util.GetTimeStampMS() - tmpTime;
1752 1658
1753// tmpTime = Util.GetTimeStampMS(); 1659 tmpTime = Util.GetTimeStampMS();
1754 collision_optimized(); 1660 collision_optimized();
1755// collisionTime += Util.GetTimeStampMS() - tmpTime; 1661 collisionTime += Util.GetTimeStampMS() - tmpTime;
1756 1662
1663 tmpTime = Util.GetTimeStampMS();
1757 lock(_collisionEventPrimRemove) 1664 lock(_collisionEventPrimRemove)
1758 { 1665 {
1759 foreach (PhysicsActor obj in _collisionEventPrimRemove) 1666 foreach (PhysicsActor obj in _collisionEventPrimRemove)
@@ -1792,12 +1699,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1792 foreach(OdePrim prm in sleepers) 1699 foreach(OdePrim prm in sleepers)
1793 prm.SleeperAddCollisionEvents(); 1700 prm.SleeperAddCollisionEvents();
1794 sleepers.Clear(); 1701 sleepers.Clear();
1702 collisonRepo += Util.GetTimeStampMS() - tmpTime;
1703
1795 1704
1796 // do a ode simulation step 1705 // do a ode simulation step
1797// tmpTime = Util.GetTimeStampMS(); 1706 tmpTime = Util.GetTimeStampMS();
1798 d.WorldQuickStep(world, ODE_STEPSIZE); 1707 d.WorldQuickStep(world, ODE_STEPSIZE);
1799 d.JointGroupEmpty(contactgroup); 1708 d.JointGroupEmpty(contactgroup);
1800// qstepTIme += Util.GetTimeStampMS() - tmpTime; 1709 qstepTIme += Util.GetTimeStampMS() - tmpTime;
1801 1710
1802 // update managed ideia of physical data and do updates to core 1711 // update managed ideia of physical data and do updates to core
1803 /* 1712 /*
@@ -1815,7 +1724,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1815 } 1724 }
1816 } 1725 }
1817 */ 1726 */
1818 1727// tmpTime = Util.GetTimeStampMS();
1819 lock (_activegroups) 1728 lock (_activegroups)
1820 { 1729 {
1821 { 1730 {
@@ -1828,6 +1737,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1828 } 1737 }
1829 } 1738 }
1830 } 1739 }
1740// updatesTime += Util.GetTimeStampMS() - tmpTime;
1831 } 1741 }
1832 catch (Exception e) 1742 catch (Exception e)
1833 { 1743 {
@@ -1835,10 +1745,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1835// ode.dunlock(world); 1745// ode.dunlock(world);
1836 } 1746 }
1837 1747
1748
1838 step_time -= ODE_STEPSIZE; 1749 step_time -= ODE_STEPSIZE;
1839 nodeframes++; 1750 nodeframes++;
1840 1751
1841 looptimeMS = Util.GetTimeStampMS() - loopstartMS; 1752 looptimeMS = Util.GetTimeStampMS() - loopstartMS;
1753
1842 if (looptimeMS > maxLoopTime) 1754 if (looptimeMS > maxLoopTime)
1843 break; 1755 break;
1844 } 1756 }
@@ -1855,9 +1767,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1855 _badCharacter.Clear(); 1767 _badCharacter.Clear();
1856 } 1768 }
1857 } 1769 }
1858
1859// information block for in debug breakpoint only
1860/* 1770/*
1771// information block for in debug breakpoint only
1772
1861 int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace); 1773 int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace);
1862 int ntopstaticgeoms = d.SpaceGetNumGeoms(StaticSpace); 1774 int ntopstaticgeoms = d.SpaceGetNumGeoms(StaticSpace);
1863 int ngroundgeoms = d.SpaceGetNumGeoms(GroundSpace); 1775 int ngroundgeoms = d.SpaceGetNumGeoms(GroundSpace);
@@ -1899,14 +1811,23 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1899 int nbodies = d.NTotalBodies; 1811 int nbodies = d.NTotalBodies;
1900 int ngeoms = d.NTotalGeoms; 1812 int ngeoms = d.NTotalGeoms;
1901*/ 1813*/
1902/* 1814
1815
1903 looptimeMS /= nodeframes; 1816 looptimeMS /= nodeframes;
1904 if(looptimeMS > 0.080) 1817 collisionTime /= nodeframes;
1818 qstepTIme /= nodeframes;
1819 changestot /= nodeframes;
1820 collisonRepo /= nodeframes;
1821 updatesTime /= nodeframes;
1822 moveTime /= nodeframes;
1823 rayTime /= nodeframes;
1824
1825 if(looptimeMS > .05)
1905 { 1826 {
1906 collisionTime /= nodeframes; 1827
1907 qstepTIme /= nodeframes; 1828
1908 } 1829 }
1909*/ 1830/*
1910 // Finished with all sim stepping. If requested, dump world state to file for debugging. 1831 // Finished with all sim stepping. If requested, dump world state to file for debugging.
1911 // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed? 1832 // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed?
1912 // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots? 1833 // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots?
@@ -1925,7 +1846,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1925 1846
1926 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); 1847 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
1927 } 1848 }
1928 1849*/
1929 fps = (float)nodeframes * ODE_STEPSIZE / reqTimeStep; 1850 fps = (float)nodeframes * ODE_STEPSIZE / reqTimeStep;
1930 1851
1931 if(step_time < HalfOdeStep) 1852 if(step_time < HalfOdeStep)