diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 114 |
1 files changed, 75 insertions, 39 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 6c72324..7848b35 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | |||
@@ -237,20 +237,20 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
237 | 237 | ||
238 | private d.NearCallback nearCallback; | 238 | private d.NearCallback nearCallback; |
239 | 239 | ||
240 | private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>(); | 240 | private HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>(); |
241 | private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>(); | 241 | private HashSet<OdePrim> _prims = new HashSet<OdePrim>(); |
242 | private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>(); | 242 | private HashSet<OdePrim> _activeprims = new HashSet<OdePrim>(); |
243 | private readonly HashSet<OdePrim> _activegroups = new HashSet<OdePrim>(); | 243 | private HashSet<OdePrim> _activegroups = new HashSet<OdePrim>(); |
244 | 244 | ||
245 | public OpenSim.Framework.LocklessQueue<ODEchangeitem> ChangesQueue = new OpenSim.Framework.LocklessQueue<ODEchangeitem>(); | 245 | public OpenSim.Framework.LocklessQueue<ODEchangeitem> ChangesQueue = new OpenSim.Framework.LocklessQueue<ODEchangeitem>(); |
246 | 246 | ||
247 | /// <summary> | 247 | /// <summary> |
248 | /// A list of actors that should receive collision events. | 248 | /// A list of actors that should receive collision events. |
249 | /// </summary> | 249 | /// </summary> |
250 | private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>(); | 250 | private List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>(); |
251 | private readonly List<PhysicsActor> _collisionEventPrimRemove = new List<PhysicsActor>(); | 251 | private List<PhysicsActor> _collisionEventPrimRemove = new List<PhysicsActor>(); |
252 | 252 | ||
253 | private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>(); | 253 | private HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>(); |
254 | public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); | 254 | public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); |
255 | public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>(); | 255 | public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>(); |
256 | 256 | ||
@@ -264,26 +264,21 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
264 | private volatile int m_global_contactcount = 0; | 264 | private volatile int m_global_contactcount = 0; |
265 | 265 | ||
266 | 266 | ||
267 | private readonly IntPtr contactgroup; | 267 | private IntPtr contactgroup; |
268 | 268 | ||
269 | public ContactData[] m_materialContactsData = new ContactData[8]; | 269 | public ContactData[] m_materialContactsData = new ContactData[8]; |
270 | 270 | ||
271 | private readonly DoubleDictionary<Vector3, IntPtr, IntPtr> RegionTerrain = new DoubleDictionary<Vector3, IntPtr, IntPtr>(); | 271 | private Dictionary<Vector3, IntPtr> RegionTerrain = new Dictionary<Vector3, IntPtr>(); |
272 | private readonly Dictionary<IntPtr, float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>(); | 272 | private Dictionary<IntPtr, float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>(); |
273 | private readonly Dictionary<IntPtr, GCHandle> TerrainHeightFieldHeightsHandlers = new Dictionary<IntPtr, GCHandle>(); | 273 | private Dictionary<IntPtr, GCHandle> TerrainHeightFieldHeightsHandlers = new Dictionary<IntPtr, GCHandle>(); |
274 | 274 | ||
275 | private int m_physicsiterations = 10; | 275 | private int m_physicsiterations = 10; |
276 | private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag | 276 | private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag |
277 | private readonly PhysicsActor PANull = new NullPhysicsActor(); | 277 | private PhysicsActor PANull = new NullPhysicsActor(); |
278 | private float step_time = 0.0f; | 278 | private float step_time = 0.0f; |
279 | 279 | ||
280 | public IntPtr world; | 280 | public IntPtr world; |
281 | 281 | ||
282 | private uint obj2LocalID = 0; | ||
283 | private OdeCharacter cc1; | ||
284 | private OdePrim cp1; | ||
285 | private OdeCharacter cc2; | ||
286 | private OdePrim cp2; | ||
287 | 282 | ||
288 | // split the spaces acording to contents type | 283 | // split the spaces acording to contents type |
289 | // ActiveSpace contains characters and active prims | 284 | // ActiveSpace contains characters and active prims |
@@ -408,8 +403,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
408 | // checkThread(); | 403 | // checkThread(); |
409 | mesher = meshmerizer; | 404 | mesher = meshmerizer; |
410 | m_config = config; | 405 | m_config = config; |
411 | /* | 406 | |
412 | string ode_config = d.GetConfiguration("ODE"); | 407 | string ode_config = d.GetConfiguration(); |
413 | if (ode_config != null && ode_config != "") | 408 | if (ode_config != null && ode_config != "") |
414 | { | 409 | { |
415 | m_log.WarnFormat("ODE configuration: {0}", ode_config); | 410 | m_log.WarnFormat("ODE configuration: {0}", ode_config); |
@@ -419,7 +414,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
419 | OdeUbitLib = true; | 414 | OdeUbitLib = true; |
420 | } | 415 | } |
421 | } | 416 | } |
422 | */ | 417 | |
423 | /* | 418 | /* |
424 | if (region != null) | 419 | if (region != null) |
425 | { | 420 | { |
@@ -526,8 +521,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
526 | d.WorldSetGravity(world, gravityx, gravityy, gravityz); | 521 | d.WorldSetGravity(world, gravityx, gravityy, gravityz); |
527 | d.WorldSetContactSurfaceLayer(world, contactsurfacelayer); | 522 | d.WorldSetContactSurfaceLayer(world, contactsurfacelayer); |
528 | 523 | ||
529 | d.WorldSetLinearDamping(world, 0.001f); | 524 | d.WorldSetLinearDamping(world, 0.002f); |
530 | d.WorldSetAngularDamping(world, 0.001f); | 525 | d.WorldSetAngularDamping(world, 0.002f); |
531 | d.WorldSetAngularDampingThreshold(world, 0f); | 526 | d.WorldSetAngularDampingThreshold(world, 0f); |
532 | d.WorldSetLinearDampingThreshold(world, 0f); | 527 | d.WorldSetLinearDampingThreshold(world, 0f); |
533 | d.WorldSetMaxAngularSpeed(world, 100f); | 528 | d.WorldSetMaxAngularSpeed(world, 100f); |
@@ -921,6 +916,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
921 | cfm = 0.0001f / cfm; | 916 | cfm = 0.0001f / cfm; |
922 | if (cfm > 0.01f) | 917 | if (cfm > 0.01f) |
923 | cfm = 0.01f; | 918 | cfm = 0.01f; |
919 | else if (cfm < 0.00001f) | ||
920 | cfm = 0.00001f; | ||
924 | 921 | ||
925 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) | 922 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) |
926 | mu *= frictionMovementMult; | 923 | mu *= frictionMovementMult; |
@@ -947,6 +944,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
947 | cfm = 0.0001f / cfm; | 944 | cfm = 0.0001f / cfm; |
948 | if (cfm > 0.01f) | 945 | if (cfm > 0.01f) |
949 | cfm = 0.01f; | 946 | cfm = 0.01f; |
947 | else if (cfm < 0.00001f) | ||
948 | cfm = 0.00001f; | ||
950 | 949 | ||
951 | if (d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass) | 950 | if (d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass) |
952 | { | 951 | { |
@@ -989,6 +988,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
989 | cfm = 0.0001f / cfm; | 988 | cfm = 0.0001f / cfm; |
990 | if (cfm > 0.01f) | 989 | if (cfm > 0.01f) |
991 | cfm = 0.01f; | 990 | cfm = 0.01f; |
991 | else if (cfm < 0.00001f) | ||
992 | cfm = 0.00001f; | ||
992 | 993 | ||
993 | if (curContact.side1 > 0) // should be 2 ? | 994 | if (curContact.side1 > 0) // should be 2 ? |
994 | IgnoreNegSides = true; | 995 | IgnoreNegSides = true; |
@@ -1155,7 +1156,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1155 | 1156 | ||
1156 | private void collision_accounting_events(PhysicsActor p1, PhysicsActor p2, ContactPoint contact) | 1157 | private void collision_accounting_events(PhysicsActor p1, PhysicsActor p2, ContactPoint contact) |
1157 | { | 1158 | { |
1158 | obj2LocalID = 0; | 1159 | |
1160 | OdeCharacter cc1; | ||
1161 | OdePrim cp1; | ||
1162 | OdeCharacter cc2; | ||
1163 | OdePrim cp2; | ||
1164 | |||
1165 | uint obj2LocalID = 0; | ||
1159 | bool p1events = p1.SubscribedEvents(); | 1166 | bool p1events = p1.SubscribedEvents(); |
1160 | bool p2events = p2.SubscribedEvents(); | 1167 | bool p2events = p2.SubscribedEvents(); |
1161 | 1168 | ||
@@ -1892,18 +1899,22 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1892 | lock (SimulationLock) | 1899 | lock (SimulationLock) |
1893 | lock(OdeLock) | 1900 | lock(OdeLock) |
1894 | { | 1901 | { |
1902 | if (world == IntPtr.Zero) | ||
1903 | return 0; | ||
1904 | |||
1895 | // adjust number of iterations per step | 1905 | // adjust number of iterations per step |
1896 | try | 1906 | |
1897 | { | 1907 | // try |
1908 | // { | ||
1898 | d.WorldSetQuickStepNumIterations(world, curphysiteractions); | 1909 | d.WorldSetQuickStepNumIterations(world, curphysiteractions); |
1899 | } | 1910 | /* } |
1900 | catch (StackOverflowException) | 1911 | catch (StackOverflowException) |
1901 | { | 1912 | { |
1902 | m_log.Error("[PHYSICS]: The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); | 1913 | m_log.Error("[PHYSICS]: The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); |
1903 | // ode.drelease(world); | 1914 | // ode.drelease(world); |
1904 | base.TriggerPhysicsBasedRestart(); | 1915 | base.TriggerPhysicsBasedRestart(); |
1905 | } | 1916 | } |
1906 | 1917 | */ | |
1907 | while (step_time > HalfOdeStep && nodeframes < 10) //limit number of steps so we don't say here for ever | 1918 | while (step_time > HalfOdeStep && nodeframes < 10) //limit number of steps so we don't say here for ever |
1908 | { | 1919 | { |
1909 | try | 1920 | try |
@@ -1955,6 +1966,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1955 | { | 1966 | { |
1956 | RemoveCharacter(defect); | 1967 | RemoveCharacter(defect); |
1957 | } | 1968 | } |
1969 | defects.Clear(); | ||
1958 | } | 1970 | } |
1959 | } | 1971 | } |
1960 | 1972 | ||
@@ -2060,13 +2072,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2060 | _badCharacter.Clear(); | 2072 | _badCharacter.Clear(); |
2061 | } | 2073 | } |
2062 | } | 2074 | } |
2063 | 2075 | /* | |
2064 | int nactivegeoms = d.SpaceGetNumGeoms(ActiveSpace); | 2076 | int nactivegeoms = d.SpaceGetNumGeoms(ActiveSpace); |
2065 | int nstaticgeoms = d.SpaceGetNumGeoms(StaticSpace); | 2077 | int nstaticgeoms = d.SpaceGetNumGeoms(StaticSpace); |
2066 | int ntopgeoms = d.SpaceGetNumGeoms(TopSpace); | 2078 | int ntopgeoms = d.SpaceGetNumGeoms(TopSpace); |
2067 | int nbodies = d.NTotalBodies; | 2079 | int nbodies = d.NTotalBodies; |
2068 | int ngeoms = d.NTotalGeoms; | 2080 | int ngeoms = d.NTotalGeoms; |
2069 | 2081 | */ | |
2070 | // Finished with all sim stepping. If requested, dump world state to file for debugging. | 2082 | // Finished with all sim stepping. If requested, dump world state to file for debugging. |
2071 | // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed? | 2083 | // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed? |
2072 | // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots? | 2084 | // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots? |
@@ -2383,11 +2395,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2383 | d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); | 2395 | d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); |
2384 | d.GeomSetRotation(GroundGeom, ref R); | 2396 | d.GeomSetRotation(GroundGeom, ref R); |
2385 | d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f, 0); | 2397 | d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f, 0); |
2386 | RegionTerrain.Add(pOffset, GroundGeom, GroundGeom); | 2398 | RegionTerrain.Add(pOffset, GroundGeom); |
2387 | // TerrainHeightFieldHeights.Add(GroundGeom, ODElandMap); | ||
2388 | TerrainHeightFieldHeights.Add(GroundGeom, _heightmap); | 2399 | TerrainHeightFieldHeights.Add(GroundGeom, _heightmap); |
2389 | TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler); | 2400 | TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler); |
2390 | |||
2391 | } | 2401 | } |
2392 | } | 2402 | } |
2393 | 2403 | ||
@@ -2486,8 +2496,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2486 | geom_name_map[GroundGeom] = "Terrain"; | 2496 | geom_name_map[GroundGeom] = "Terrain"; |
2487 | 2497 | ||
2488 | d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f, 0); | 2498 | d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f, 0); |
2489 | RegionTerrain.Add(pOffset, GroundGeom, GroundGeom); | 2499 | RegionTerrain.Add(pOffset, GroundGeom); |
2490 | // TerrainHeightFieldHeights.Add(GroundGeom, ODElandMap); | ||
2491 | TerrainHeightFieldHeights.Add(GroundGeom, _heightmap); | 2500 | TerrainHeightFieldHeights.Add(GroundGeom, _heightmap); |
2492 | TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler); | 2501 | TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler); |
2493 | } | 2502 | } |
@@ -2649,19 +2658,42 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2649 | 2658 | ||
2650 | public override void Dispose() | 2659 | public override void Dispose() |
2651 | { | 2660 | { |
2652 | m_rayCastManager.Dispose(); | ||
2653 | m_rayCastManager = null; | ||
2654 | |||
2655 | lock (OdeLock) | 2661 | lock (OdeLock) |
2656 | { | 2662 | { |
2663 | m_rayCastManager.Dispose(); | ||
2664 | m_rayCastManager = null; | ||
2665 | |||
2657 | lock (_prims) | 2666 | lock (_prims) |
2658 | { | 2667 | { |
2668 | ChangesQueue.Clear(); | ||
2659 | foreach (OdePrim prm in _prims) | 2669 | foreach (OdePrim prm in _prims) |
2660 | { | 2670 | { |
2661 | RemovePrim(prm); | 2671 | prm.DoAChange(changes.Remove, null); |
2672 | _collisionEventPrim.Remove(prm); | ||
2662 | } | 2673 | } |
2674 | _prims.Clear(); | ||
2663 | } | 2675 | } |
2664 | 2676 | ||
2677 | OdeCharacter[] chtorem; | ||
2678 | lock (_characters) | ||
2679 | { | ||
2680 | chtorem = new OdeCharacter[_characters.Count]; | ||
2681 | _characters.CopyTo(chtorem); | ||
2682 | } | ||
2683 | |||
2684 | ChangesQueue.Clear(); | ||
2685 | foreach (OdeCharacter ch in chtorem) | ||
2686 | ch.DoAChange(changes.Remove, null); | ||
2687 | |||
2688 | |||
2689 | foreach (IntPtr GroundGeom in RegionTerrain.Values) | ||
2690 | { | ||
2691 | if (GroundGeom != IntPtr.Zero) | ||
2692 | d.GeomDestroy(GroundGeom); | ||
2693 | } | ||
2694 | |||
2695 | RegionTerrain.Clear(); | ||
2696 | |||
2665 | if (TerrainHeightFieldHeightsHandlers.Count > 0) | 2697 | if (TerrainHeightFieldHeightsHandlers.Count > 0) |
2666 | { | 2698 | { |
2667 | foreach (GCHandle gch in TerrainHeightFieldHeightsHandlers.Values) | 2699 | foreach (GCHandle gch in TerrainHeightFieldHeightsHandlers.Values) |
@@ -2671,6 +2703,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2671 | } | 2703 | } |
2672 | } | 2704 | } |
2673 | 2705 | ||
2706 | TerrainHeightFieldHeightsHandlers.Clear(); | ||
2707 | TerrainHeightFieldHeights.Clear(); | ||
2708 | |||
2674 | if (WaterGeom != IntPtr.Zero) | 2709 | if (WaterGeom != IntPtr.Zero) |
2675 | { | 2710 | { |
2676 | d.GeomDestroy(WaterGeom); | 2711 | d.GeomDestroy(WaterGeom); |
@@ -2691,6 +2726,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2691 | 2726 | ||
2692 | 2727 | ||
2693 | d.WorldDestroy(world); | 2728 | d.WorldDestroy(world); |
2729 | world = IntPtr.Zero; | ||
2694 | //d.CloseODE(); | 2730 | //d.CloseODE(); |
2695 | } | 2731 | } |
2696 | } | 2732 | } |