aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs3
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs65
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs227
3 files changed, 107 insertions, 188 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
index 0e46471..f111e87 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
@@ -751,8 +751,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
751 751
752 m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace); 752 m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace);
753 753
754 collider = d.HashSpaceCreate(m_parent_scene.CharsSpace); 754 collider = d.SimpleSpaceCreate(m_parent_scene.CharsSpace);
755 d.HashSpaceSetLevels(collider, -4, 3);
756 d.SpaceSetSublevel(collider, 3); 755 d.SpaceSetSublevel(collider, 3);
757 d.SpaceSetCleanup(collider, false); 756 d.SpaceSetCleanup(collider, false);
758 d.GeomSetCategoryBits(collider, (uint)m_collisionCategories); 757 d.GeomSetCategoryBits(collider, (uint)m_collisionCategories);
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
index aa208e2..e080b18 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
@@ -196,8 +196,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
196 196
197 private int m_eventsubscription; 197 private int m_eventsubscription;
198 private int m_cureventsubscription; 198 private int m_cureventsubscription;
199 private CollisionEventUpdate CollisionEventsThisFrame = null; 199 private CollisionEventUpdate CollisionEvents = null;
200 private CollisionEventUpdate CollisionVDTCEventsThisFrame = null; 200 private CollisionEventUpdate CollisionVDTCEvents = null;
201 private bool SentEmptyCollisionsEvent; 201 private bool SentEmptyCollisionsEvent;
202 202
203 public volatile bool childPrim; 203 public volatile bool childPrim;
@@ -1138,24 +1138,24 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1138 { 1138 {
1139 m_eventsubscription = ms; 1139 m_eventsubscription = ms;
1140 m_cureventsubscription = 0; 1140 m_cureventsubscription = 0;
1141 if (CollisionEventsThisFrame == null) 1141 if (CollisionEvents == null)
1142 CollisionEventsThisFrame = new CollisionEventUpdate(); 1142 CollisionEvents = new CollisionEventUpdate();
1143 if (CollisionVDTCEventsThisFrame == null) 1143 if (CollisionVDTCEvents == null)
1144 CollisionVDTCEventsThisFrame = new CollisionEventUpdate(); 1144 CollisionVDTCEvents = new CollisionEventUpdate();
1145 SentEmptyCollisionsEvent = false; 1145 SentEmptyCollisionsEvent = false;
1146 } 1146 }
1147 1147
1148 public override void UnSubscribeEvents() 1148 public override void UnSubscribeEvents()
1149 { 1149 {
1150 if (CollisionVDTCEventsThisFrame != null) 1150 if (CollisionVDTCEvents != null)
1151 { 1151 {
1152 CollisionVDTCEventsThisFrame.Clear(); 1152 CollisionVDTCEvents.Clear();
1153 CollisionVDTCEventsThisFrame = null; 1153 CollisionVDTCEvents = null;
1154 } 1154 }
1155 if (CollisionEventsThisFrame != null) 1155 if (CollisionEvents != null)
1156 { 1156 {
1157 CollisionEventsThisFrame.Clear(); 1157 CollisionEvents.Clear();
1158 CollisionEventsThisFrame = null; 1158 CollisionEvents = null;
1159 } 1159 }
1160 m_eventsubscription = 0; 1160 m_eventsubscription = 0;
1161 _parent_scene.RemoveCollisionEventReporting(this); 1161 _parent_scene.RemoveCollisionEventReporting(this);
@@ -1163,27 +1163,27 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1163 1163
1164 public override void AddCollisionEvent(uint CollidedWith, ContactPoint contact) 1164 public override void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
1165 { 1165 {
1166 if (CollisionEventsThisFrame == null) 1166 if (CollisionEvents == null)
1167 CollisionEventsThisFrame = new CollisionEventUpdate(); 1167 CollisionEvents = new CollisionEventUpdate();
1168 1168
1169 CollisionEventsThisFrame.AddCollider(CollidedWith, contact); 1169 CollisionEvents.AddCollider(CollidedWith, contact);
1170 _parent_scene.AddCollisionEventReporting(this); 1170 _parent_scene.AddCollisionEventReporting(this);
1171 } 1171 }
1172 1172
1173 public override void AddVDTCCollisionEvent(uint CollidedWith, ContactPoint contact) 1173 public override void AddVDTCCollisionEvent(uint CollidedWith, ContactPoint contact)
1174 { 1174 {
1175 if (CollisionVDTCEventsThisFrame == null) 1175 if (CollisionVDTCEvents == null)
1176 CollisionVDTCEventsThisFrame = new CollisionEventUpdate(); 1176 CollisionVDTCEvents = new CollisionEventUpdate();
1177 1177
1178 CollisionVDTCEventsThisFrame.AddCollider(CollidedWith, contact); 1178 CollisionVDTCEvents.AddCollider(CollidedWith, contact);
1179 _parent_scene.AddCollisionEventReporting(this); 1179 _parent_scene.AddCollisionEventReporting(this);
1180 } 1180 }
1181 1181
1182 internal void SleeperAddCollisionEvents() 1182 internal void SleeperAddCollisionEvents()
1183 { 1183 {
1184 if(CollisionEventsThisFrame != null && CollisionEventsThisFrame.m_objCollisionList.Count != 0) 1184 if(CollisionEvents != null && CollisionEvents.m_objCollisionList.Count != 0)
1185 { 1185 {
1186 foreach(KeyValuePair<uint,ContactPoint> kvp in CollisionEventsThisFrame.m_objCollisionList) 1186 foreach(KeyValuePair<uint,ContactPoint> kvp in CollisionEvents.m_objCollisionList)
1187 { 1187 {
1188 if(kvp.Key == 0) 1188 if(kvp.Key == 0)
1189 continue; 1189 continue;
@@ -1196,9 +1196,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1196 other.AddCollisionEvent(ParentActor.LocalID,cp); 1196 other.AddCollisionEvent(ParentActor.LocalID,cp);
1197 } 1197 }
1198 } 1198 }
1199 if(CollisionVDTCEventsThisFrame != null && CollisionVDTCEventsThisFrame.m_objCollisionList.Count != 0) 1199 if(CollisionVDTCEvents != null && CollisionVDTCEvents.m_objCollisionList.Count != 0)
1200 { 1200 {
1201 foreach(KeyValuePair<uint,ContactPoint> kvp in CollisionVDTCEventsThisFrame.m_objCollisionList) 1201 foreach(KeyValuePair<uint,ContactPoint> kvp in CollisionVDTCEvents.m_objCollisionList)
1202 { 1202 {
1203 OdePrim other = _parent_scene.getPrim(kvp.Key); 1203 OdePrim other = _parent_scene.getPrim(kvp.Key);
1204 if(other == null) 1204 if(other == null)
@@ -1213,8 +1213,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1213 1213
1214 internal void clearSleeperCollisions() 1214 internal void clearSleeperCollisions()
1215 { 1215 {
1216 if(CollisionVDTCEventsThisFrame != null && CollisionVDTCEventsThisFrame.Count >0 ) 1216 if(CollisionVDTCEvents != null && CollisionVDTCEvents.Count >0 )
1217 CollisionVDTCEventsThisFrame.Clear(); 1217 CollisionVDTCEvents.Clear();
1218 } 1218 }
1219 1219
1220 public void SendCollisions(int timestep) 1220 public void SendCollisions(int timestep)
@@ -1226,14 +1226,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1226 if (m_cureventsubscription < m_eventsubscription) 1226 if (m_cureventsubscription < m_eventsubscription)
1227 return; 1227 return;
1228 1228
1229 if (CollisionEventsThisFrame == null) 1229 if (CollisionEvents == null)
1230 return; 1230 return;
1231 1231
1232 int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; 1232 int ncolisions = CollisionEvents.m_objCollisionList.Count;
1233 1233
1234 if (!SentEmptyCollisionsEvent || ncolisions > 0) 1234 if (!SentEmptyCollisionsEvent || ncolisions > 0)
1235 { 1235 {
1236 base.SendCollisionUpdate(CollisionEventsThisFrame); 1236 base.SendCollisionUpdate(CollisionEvents);
1237 m_cureventsubscription = 0; 1237 m_cureventsubscription = 0;
1238 1238
1239 if (ncolisions == 0) 1239 if (ncolisions == 0)
@@ -1244,7 +1244,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1244 else if(Body == IntPtr.Zero || (d.BodyIsEnabled(Body) && m_bodydisablecontrol >= 0 )) 1244 else if(Body == IntPtr.Zero || (d.BodyIsEnabled(Body) && m_bodydisablecontrol >= 0 ))
1245 { 1245 {
1246 SentEmptyCollisionsEvent = false; 1246 SentEmptyCollisionsEvent = false;
1247 CollisionEventsThisFrame.Clear(); 1247 CollisionEvents.Clear();
1248 } 1248 }
1249 } 1249 }
1250 } 1250 }
@@ -1832,7 +1832,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1832 // should only be called for non physical prims unless they are becoming non physical 1832 // should only be called for non physical prims unless they are becoming non physical
1833 private void SetInStaticSpace(OdePrim prim) 1833 private void SetInStaticSpace(OdePrim prim)
1834 { 1834 {
1835 IntPtr targetSpace = _parent_scene.MoveGeomToStaticSpace(prim.prim_geom, prim._position, prim.m_targetSpace); 1835 IntPtr targetSpace = _parent_scene.MoveGeomToStaticSpace(prim.prim_geom, prim.m_targetSpace);
1836 prim.m_targetSpace = targetSpace; 1836 prim.m_targetSpace = targetSpace;
1837 collide_geom = IntPtr.Zero; 1837 collide_geom = IntPtr.Zero;
1838 } 1838 }
@@ -2069,8 +2069,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2069 } 2069 }
2070 else 2070 else
2071 { 2071 {
2072 m_targetSpace = d.HashSpaceCreate(_parent_scene.ActiveSpace); 2072 m_targetSpace = d.SimpleSpaceCreate(_parent_scene.ActiveSpace);
2073 d.HashSpaceSetLevels(m_targetSpace, -2, 8);
2074 d.SpaceSetSublevel(m_targetSpace, 3); 2073 d.SpaceSetSublevel(m_targetSpace, 3);
2075 d.SpaceSetCleanup(m_targetSpace, false); 2074 d.SpaceSetCleanup(m_targetSpace, false);
2076 2075
@@ -2964,7 +2963,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2964 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z); 2963 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2965 _position = newPos; 2964 _position = newPos;
2966 2965
2967 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace); 2966 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, m_targetSpace);
2968 } 2967 }
2969 } 2968 }
2970 } 2969 }
@@ -3103,7 +3102,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
3103 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z); 3102 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
3104 _position = newPos; 3103 _position = newPos;
3105 3104
3106 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace); 3105 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, m_targetSpace);
3107 } 3106 }
3108 } 3107 }
3109 } 3108 }
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)