aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOde
diff options
context:
space:
mode:
Diffstat (limited to '')
-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.cs245
3 files changed, 117 insertions, 196 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 004ee7f..5f63a7b 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
@@ -179,12 +179,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
179 179
180// const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce; 180// const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce;
181 181
182 const d.ContactFlags comumContactFlags = d.ContactFlags.Bounce | d.ContactFlags.Approx1 | d.ContactFlags.Slip1 | d.ContactFlags.Slip2; 182// const d.ContactFlags comumContactFlags = d.ContactFlags.Bounce | d.ContactFlags.Approx1 | d.ContactFlags.Slip1 | d.ContactFlags.Slip2;
183 const d.ContactFlags comumContactFlags = d.ContactFlags.Bounce | d.ContactFlags.Approx1;
183 const float comumContactERP = 0.75f; 184 const float comumContactERP = 0.75f;
184 const float comumContactCFM = 0.0001f; 185 const float comumContactCFM = 0.0001f;
185 const float comumContactSLIP = 0f; 186 const float comumContactSLIP = 0f;
186 187
187 float frictionMovementMult = 0.8f; 188// float frictionMovementMult = 0.2f;
188 189
189 float TerrainBounce = 0.001f; 190 float TerrainBounce = 0.001f;
190 float TerrainFriction = 0.3f; 191 float TerrainFriction = 0.3f;
@@ -200,7 +201,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
200 public float ODE_STEPSIZE = 0.020f; 201 public float ODE_STEPSIZE = 0.020f;
201 public float HalfOdeStep = 0.01f; 202 public float HalfOdeStep = 0.01f;
202 public int odetimestepMS = 20; // rounded 203 public int odetimestepMS = 20; // rounded
203 private float metersInSpace = 25.6f;
204 private float m_timeDilation = 1.0f; 204 private float m_timeDilation = 1.0f;
205 205
206 private double m_lastframe; 206 private double m_lastframe;
@@ -283,16 +283,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
283 public IntPtr StaticSpace; // space for the static things around 283 public IntPtr StaticSpace; // space for the static things around
284 public IntPtr GroundSpace; // space for ground 284 public IntPtr GroundSpace; // space for ground
285 285
286 // some speedup variables
287 private int spaceGridMaxX;
288 private int spaceGridMaxY;
289 private float spacesPerMeterX;
290 private float spacesPerMeterY;
291
292 // split static geometry collision into a grid as before
293 private IntPtr[,] staticPrimspace;
294 private IntPtr[] staticPrimspaceOffRegion;
295
296 public Object OdeLock; 286 public Object OdeLock;
297 public static Object SimulationLock; 287 public static Object SimulationLock;
298 288
@@ -385,13 +375,23 @@ namespace OpenSim.Region.PhysicsModule.ubOde
385 try 375 try
386 { 376 {
387 world = d.WorldCreate(); 377 world = d.WorldCreate();
388 TopSpace = d.HashSpaceCreate(IntPtr.Zero); 378 TopSpace = d.SimpleSpaceCreate(IntPtr.Zero);
389 379 ActiveSpace = d.SimpleSpaceCreate(TopSpace);
390 // now the major subspaces 380 CharsSpace = d.SimpleSpaceCreate(TopSpace);
391 ActiveSpace = d.HashSpaceCreate(TopSpace); 381 GroundSpace = d.SimpleSpaceCreate(TopSpace);
392 CharsSpace = d.HashSpaceCreate(TopSpace); 382 float sx = WorldExtents.X + 16;
393 StaticSpace = d.HashSpaceCreate(TopSpace); 383 float sy = WorldExtents.Y + 16;
394 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);
395 } 395 }
396 catch 396 catch
397 { 397 {
@@ -399,12 +399,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
399 // i did! 399 // i did!
400 } 400 }
401 401
402 d.HashSpaceSetLevels(TopSpace, -5, 12);
403 d.HashSpaceSetLevels(ActiveSpace, -5, 10);
404 d.HashSpaceSetLevels(CharsSpace, -4, 3);
405 d.HashSpaceSetLevels(StaticSpace, -5, 12);
406 d.HashSpaceSetLevels(GroundSpace, 0, 8);
407
408 // demote to second level 402 // demote to second level
409 d.SpaceSetSublevel(ActiveSpace, 1); 403 d.SpaceSetSublevel(ActiveSpace, 1);
410 d.SpaceSetSublevel(CharsSpace, 1); 404 d.SpaceSetSublevel(CharsSpace, 1);
@@ -468,8 +462,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
468 gravityy = physicsconfig.GetFloat("world_gravityy", gravityy); 462 gravityy = physicsconfig.GetFloat("world_gravityy", gravityy);
469 gravityz = physicsconfig.GetFloat("world_gravityz", gravityz); 463 gravityz = physicsconfig.GetFloat("world_gravityz", gravityz);
470 464
471 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", metersInSpace);
472
473 // contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer); 465 // contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer);
474 466
475 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE); 467 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE);
@@ -559,76 +551,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
559 m_materialContactsData[(int)Material.light].mu = 0.0f; 551 m_materialContactsData[(int)Material.light].mu = 0.0f;
560 m_materialContactsData[(int)Material.light].bounce = 0.0f; 552 m_materialContactsData[(int)Material.light].bounce = 0.0f;
561 553
562
563 spacesPerMeterX = 1.0f / metersInSpace;
564 spacesPerMeterY = spacesPerMeterX;
565 spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeterX);
566 spaceGridMaxY = (int)(WorldExtents.Y * spacesPerMeterY);
567
568 if (spaceGridMaxX > 24)
569 {
570 spaceGridMaxX = 24;
571 spacesPerMeterX = spaceGridMaxX / WorldExtents.X;
572 }
573
574 if (spaceGridMaxY > 24)
575 {
576 spaceGridMaxY = 24;
577 spacesPerMeterY = spaceGridMaxY / WorldExtents.Y;
578 }
579
580 staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY];
581
582 // create all spaces now
583 int i, j;
584 IntPtr newspace;
585
586 for (i = 0; i < spaceGridMaxX; i++)
587 for (j = 0; j < spaceGridMaxY; j++)
588 {
589 newspace = d.HashSpaceCreate(StaticSpace);
590 d.GeomSetCategoryBits(newspace, (int)CollisionCategories.Space);
591 waitForSpaceUnlock(newspace);
592 d.SpaceSetSublevel(newspace, 2);
593 d.HashSpaceSetLevels(newspace, -2, 8);
594 d.GeomSetCategoryBits(newspace, (uint)(CollisionCategories.Space |
595 CollisionCategories.Geom |
596 CollisionCategories.Land |
597 CollisionCategories.Water |
598 CollisionCategories.Phantom |
599 CollisionCategories.VolumeDtc
600 ));
601 d.GeomSetCollideBits(newspace, 0);
602
603 staticPrimspace[i, j] = newspace;
604 }
605
606 // let this now be index limit
607 spaceGridMaxX--;
608 spaceGridMaxY--;
609
610 // create 4 off world spaces (x<0,x>max,y<0,y>max)
611 staticPrimspaceOffRegion = new IntPtr[4];
612
613 for (i = 0; i < 4; i++)
614 {
615 newspace = d.HashSpaceCreate(StaticSpace);
616 d.GeomSetCategoryBits(newspace, (int)CollisionCategories.Space);
617 waitForSpaceUnlock(newspace);
618 d.SpaceSetSublevel(newspace, 2);
619 d.HashSpaceSetLevels(newspace, -2, 8);
620 d.GeomSetCategoryBits(newspace, (uint)(CollisionCategories.Space |
621 CollisionCategories.Geom |
622 CollisionCategories.Land |
623 CollisionCategories.Water |
624 CollisionCategories.Phantom |
625 CollisionCategories.VolumeDtc
626 ));
627 d.GeomSetCollideBits(newspace, 0);
628
629 staticPrimspaceOffRegion[i] = newspace;
630 }
631
632 m_lastframe = Util.GetTimeStamp(); 554 m_lastframe = Util.GetTimeStamp();
633 m_lastMeshExpire = m_lastframe; 555 m_lastMeshExpire = m_lastframe;
634 step_time = -1; 556 step_time = -1;
@@ -757,7 +679,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
757 // 679 //
758 */ 680 */
759 681
760
761 if (d.GeomGetCategoryBits(g1) == (uint)CollisionCategories.VolumeDtc || 682 if (d.GeomGetCategoryBits(g1) == (uint)CollisionCategories.VolumeDtc ||
762 d.GeomGetCategoryBits(g2) == (uint)CollisionCategories.VolumeDtc) 683 d.GeomGetCategoryBits(g2) == (uint)CollisionCategories.VolumeDtc)
763 { 684 {
@@ -866,9 +787,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
866 break; 787 break;
867 788
868 case (int)ActorTypes.Prim: 789 case (int)ActorTypes.Prim:
869 Vector3 relV = p1.rootVelocity - p2.rootVelocity; 790// Vector3 relV = p1.rootVelocity - p2.rootVelocity;
870 float relVlenSQ = relV.LengthSquared(); 791// float relVlenSQ = relV.LengthSquared();
871 if (relVlenSQ > 0.0001f) 792// if (relVlenSQ > 0.0001f)
872 { 793 {
873 p1.CollidingObj = true; 794 p1.CollidingObj = true;
874 p2.CollidingObj = true; 795 p2.CollidingObj = true;
@@ -878,8 +799,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
878 bounce = contactdata1.bounce * contactdata2.bounce; 799 bounce = contactdata1.bounce * contactdata2.bounce;
879 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); 800 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
880 801
881 if (relVlenSQ > 0.01f) 802// if (relVlenSQ > 0.01f)
882 mu *= frictionMovementMult; 803// mu *= frictionMovementMult;
883 804
884 if(d.GeomGetClass(g2) == d.GeomClassID.TriMeshClass && 805 if(d.GeomGetClass(g2) == d.GeomClassID.TriMeshClass &&
885 d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass) 806 d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass)
@@ -891,9 +812,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
891 bounce = contactdata1.bounce * TerrainBounce; 812 bounce = contactdata1.bounce * TerrainBounce;
892 mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction); 813 mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction);
893 814
894 Vector3 v1 = p1.rootVelocity; 815// Vector3 v1 = p1.rootVelocity;
895 if (Math.Abs(v1.X) > 0.1f || Math.Abs(v1.Y) > 0.1f) 816// if (Math.Abs(v1.X) > 0.1f || Math.Abs(v1.Y) > 0.1f)
896 mu *= frictionMovementMult; 817// mu *= frictionMovementMult;
897 p1.CollidingGround = true; 818 p1.CollidingGround = true;
898 819
899 if(d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass) 820 if(d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass)
@@ -918,9 +839,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
918 839
919// if (curContact.side1 > 0) // should be 2 ? 840// if (curContact.side1 > 0) // should be 2 ?
920// IgnoreNegSides = true; 841// IgnoreNegSides = true;
921 Vector3 v2 = p2.rootVelocity; 842// Vector3 v2 = p2.rootVelocity;
922 if (Math.Abs(v2.X) > 0.1f || Math.Abs(v2.Y) > 0.1f) 843// if (Math.Abs(v2.X) > 0.1f || Math.Abs(v2.Y) > 0.1f)
923 mu *= frictionMovementMult; 844// mu *= frictionMovementMult;
924 845
925 if(d.GeomGetClass(g2) == d.GeomClassID.TriMeshClass) 846 if(d.GeomGetClass(g2) == d.GeomClassID.TriMeshClass)
926 smoothMesh = true; 847 smoothMesh = true;
@@ -1306,6 +1227,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1306 public override void RemoveAvatar(PhysicsActor actor) 1227 public override void RemoveAvatar(PhysicsActor actor)
1307 { 1228 {
1308 //m_log.Debug("[PHYSICS]:ODELOCK"); 1229 //m_log.Debug("[PHYSICS]:ODELOCK");
1230 if (world == IntPtr.Zero)
1231 return;
1232
1309 lock (OdeLock) 1233 lock (OdeLock)
1310 { 1234 {
1311 d.AllocateODEDataForThread(0); 1235 d.AllocateODEDataForThread(0);
@@ -1460,27 +1384,23 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1460 1384
1461 /// <summary> 1385 /// <summary>
1462 /// Called when a static prim moves or becomes static 1386 /// Called when a static prim moves or becomes static
1463 /// Places the prim in a space one the static sub-spaces grid 1387 /// Places the prim in a space one the static space
1464 /// </summary> 1388 /// </summary>
1465 /// <param name="geom">the pointer to the geom that moved</param> 1389 /// <param name="geom">the pointer to the geom that moved</param>
1466 /// <param name="pos">the position that the geom moved to</param>
1467 /// <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>
1468 /// <returns>a pointer to the new space it's in</returns> 1391 /// <returns>a pointer to the new space it's in</returns>
1469 public IntPtr MoveGeomToStaticSpace(IntPtr geom, Vector3 pos, IntPtr currentspace) 1392 public IntPtr MoveGeomToStaticSpace(IntPtr geom, IntPtr currentspace)
1470 { 1393 {
1471 // 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
1472 1395
1473 // Called ODEPrim so 1396 // Called ODEPrim so
1474 // it's already in locked space. 1397 // it's already in locked space.
1475 1398
1476 if (geom == IntPtr.Zero) // shouldn't happen 1399 if (geom == IntPtr.Zero) // shouldn't happen
1477 return IntPtr.Zero; 1400 return IntPtr.Zero;
1478 1401
1479 // get the static sub-space for current position 1402 if (StaticSpace == currentspace) // if we are there all done
1480 IntPtr newspace = calculateSpaceForGeom(pos); 1403 return StaticSpace;
1481
1482 if (newspace == currentspace) // if we are there all done
1483 return newspace;
1484 1404
1485 // else remove it from its current space 1405 // else remove it from its current space
1486 if (currentspace != IntPtr.Zero && d.SpaceQuery(currentspace, geom)) 1406 if (currentspace != IntPtr.Zero && d.SpaceQuery(currentspace, geom))
@@ -1515,44 +1435,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1515 { 1435 {
1516 d.SpaceDestroy(currentspace); 1436 d.SpaceDestroy(currentspace);
1517 } 1437 }
1518
1519 } 1438 }
1520 } 1439 }
1521 } 1440 }
1522 1441
1523 // put the geom in the newspace 1442 // put the geom in the newspace
1524 waitForSpaceUnlock(newspace); 1443 waitForSpaceUnlock(StaticSpace);
1525 d.SpaceAdd(newspace, geom); 1444 d.SpaceAdd(StaticSpace, geom);
1526 1445
1527 // let caller know this newspace 1446 return StaticSpace;
1528 return newspace;
1529 } 1447 }
1530 1448
1531 /// <summary>
1532 /// Calculates the space the prim should be in by its position
1533 /// </summary>
1534 /// <param name="pos"></param>
1535 /// <returns>a pointer to the space. This could be a new space or reused space.</returns>
1536 public IntPtr calculateSpaceForGeom(Vector3 pos)
1537 {
1538 int x, y;
1539
1540 if (pos.X < 0)
1541 return staticPrimspaceOffRegion[0];
1542
1543 if (pos.Y < 0)
1544 return staticPrimspaceOffRegion[2];
1545
1546 x = (int)(pos.X * spacesPerMeterX);
1547 if (x > spaceGridMaxX)
1548 return staticPrimspaceOffRegion[1];
1549
1550 y = (int)(pos.Y * spacesPerMeterY);
1551 if (y > spaceGridMaxY)
1552 return staticPrimspaceOffRegion[3];
1553
1554 return staticPrimspace[x, y];
1555 }
1556 1449
1557 #endregion 1450 #endregion
1558 1451
@@ -1641,6 +1534,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1641 /// <returns></returns> 1534 /// <returns></returns>
1642 public override float Simulate(float reqTimeStep) 1535 public override float Simulate(float reqTimeStep)
1643 { 1536 {
1537 if (world == IntPtr.Zero)
1538 return 0;
1539
1644 double now = Util.GetTimeStamp(); 1540 double now = Util.GetTimeStamp();
1645 double timeStep = now - m_lastframe; 1541 double timeStep = now - m_lastframe;
1646 m_lastframe = now; 1542 m_lastframe = now;
@@ -1679,10 +1575,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1679 double maxChangestime = (int)(reqTimeStep * 500f); // half the time 1575 double maxChangestime = (int)(reqTimeStep * 500f); // half the time
1680 double maxLoopTime = (int)(reqTimeStep * 1200f); // 1.2 the time 1576 double maxLoopTime = (int)(reqTimeStep * 1200f); // 1.2 the time
1681 1577
1682// double collisionTime = 0; 1578/*
1683// double qstepTIme = 0; 1579 double collisionTime = 0;
1684// double tmpTime = 0; 1580 double qstepTIme = 0;
1685 1581 double tmpTime = 0;
1582 double changestot = 0;
1583 double collisonRepo = 0;
1584 double updatesTime = 0;
1585 double moveTime = 0;
1586 double rayTime = 0;
1587*/
1686 d.AllocateODEDataForThread(~0U); 1588 d.AllocateODEDataForThread(~0U);
1687 1589
1688 if (ChangesQueue.Count > 0) 1590 if (ChangesQueue.Count > 0)
@@ -1719,6 +1621,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1719 m_global_contactcount = 0; 1621 m_global_contactcount = 0;
1720 1622
1721 1623
1624// tmpTime = Util.GetTimeStampMS();
1625
1722 // Move characters 1626 // Move characters
1723 lock (_characters) 1627 lock (_characters)
1724 { 1628 {
@@ -1746,13 +1650,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1746 aprim.Move(); 1650 aprim.Move();
1747 } 1651 }
1748 } 1652 }
1653// moveTime += Util.GetTimeStampMS() - tmpTime;
1749 1654
1655// tmpTime = Util.GetTimeStampMS();
1750 m_rayCastManager.ProcessQueuedRequests(); 1656 m_rayCastManager.ProcessQueuedRequests();
1657// rayTime += Util.GetTimeStampMS() - tmpTime;
1751 1658
1752// tmpTime = Util.GetTimeStampMS(); 1659// tmpTime = Util.GetTimeStampMS();
1753 collision_optimized(); 1660 collision_optimized();
1754// collisionTime += Util.GetTimeStampMS() - tmpTime; 1661// collisionTime += Util.GetTimeStampMS() - tmpTime;
1755 1662
1663// tmpTime = Util.GetTimeStampMS();
1756 lock(_collisionEventPrimRemove) 1664 lock(_collisionEventPrimRemove)
1757 { 1665 {
1758 foreach (PhysicsActor obj in _collisionEventPrimRemove) 1666 foreach (PhysicsActor obj in _collisionEventPrimRemove)
@@ -1791,6 +1699,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1791 foreach(OdePrim prm in sleepers) 1699 foreach(OdePrim prm in sleepers)
1792 prm.SleeperAddCollisionEvents(); 1700 prm.SleeperAddCollisionEvents();
1793 sleepers.Clear(); 1701 sleepers.Clear();
1702// collisonRepo += Util.GetTimeStampMS() - tmpTime;
1703
1794 1704
1795 // do a ode simulation step 1705 // do a ode simulation step
1796// tmpTime = Util.GetTimeStampMS(); 1706// tmpTime = Util.GetTimeStampMS();
@@ -1814,7 +1724,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1814 } 1724 }
1815 } 1725 }
1816 */ 1726 */
1817 1727// tmpTime = Util.GetTimeStampMS();
1818 lock (_activegroups) 1728 lock (_activegroups)
1819 { 1729 {
1820 { 1730 {
@@ -1827,6 +1737,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1827 } 1737 }
1828 } 1738 }
1829 } 1739 }
1740// updatesTime += Util.GetTimeStampMS() - tmpTime;
1830 } 1741 }
1831 catch (Exception e) 1742 catch (Exception e)
1832 { 1743 {
@@ -1834,10 +1745,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1834// ode.dunlock(world); 1745// ode.dunlock(world);
1835 } 1746 }
1836 1747
1748
1837 step_time -= ODE_STEPSIZE; 1749 step_time -= ODE_STEPSIZE;
1838 nodeframes++; 1750 nodeframes++;
1839 1751
1840 looptimeMS = Util.GetTimeStampMS() - loopstartMS; 1752 looptimeMS = Util.GetTimeStampMS() - loopstartMS;
1753
1841 if (looptimeMS > maxLoopTime) 1754 if (looptimeMS > maxLoopTime)
1842 break; 1755 break;
1843 } 1756 }
@@ -1854,9 +1767,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1854 _badCharacter.Clear(); 1767 _badCharacter.Clear();
1855 } 1768 }
1856 } 1769 }
1857
1858// information block for in debug breakpoint only
1859/* 1770/*
1771// information block for in debug breakpoint only
1772
1860 int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace); 1773 int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace);
1861 int ntopstaticgeoms = d.SpaceGetNumGeoms(StaticSpace); 1774 int ntopstaticgeoms = d.SpaceGetNumGeoms(StaticSpace);
1862 int ngroundgeoms = d.SpaceGetNumGeoms(GroundSpace); 1775 int ngroundgeoms = d.SpaceGetNumGeoms(GroundSpace);
@@ -1898,14 +1811,24 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1898 int nbodies = d.NTotalBodies; 1811 int nbodies = d.NTotalBodies;
1899 int ngeoms = d.NTotalGeoms; 1812 int ngeoms = d.NTotalGeoms;
1900*/ 1813*/
1814
1901/* 1815/*
1902 looptimeMS /= nodeframes; 1816 looptimeMS /= nodeframes;
1903 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)
1904 { 1826 {
1905 collisionTime /= nodeframes; 1827
1906 qstepTIme /= nodeframes; 1828
1907 } 1829 }
1908*/ 1830*/
1831/*
1909 // Finished with all sim stepping. If requested, dump world state to file for debugging. 1832 // Finished with all sim stepping. If requested, dump world state to file for debugging.
1910 // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed? 1833 // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed?
1911 // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots? 1834 // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots?
@@ -1924,7 +1847,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1924 1847
1925 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); 1848 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
1926 } 1849 }
1927 1850*/
1928 fps = (float)nodeframes * ODE_STEPSIZE / reqTimeStep; 1851 fps = (float)nodeframes * ODE_STEPSIZE / reqTimeStep;
1929 1852
1930 if(step_time < HalfOdeStep) 1853 if(step_time < HalfOdeStep)