aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules/Ode/OdeScene.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/Ode/OdeScene.cs390
1 files changed, 127 insertions, 263 deletions
diff --git a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
index 8cc7f28..4e95b7a 100644
--- a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
+++ b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
@@ -40,6 +40,7 @@ using System.Diagnostics;
40using System.IO; 40using System.IO;
41using System.Linq; 41using System.Linq;
42using System.Reflection; 42using System.Reflection;
43using System.Runtime.ExceptionServices;
43using System.Runtime.InteropServices; 44using System.Runtime.InteropServices;
44using System.Threading; 45using System.Threading;
45using log4net; 46using log4net;
@@ -111,11 +112,9 @@ namespace OpenSim.Region.PhysicsModule.ODE
111 Rubber = 6 112 Rubber = 6
112 } 113 }
113 114
114 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")] 115 public class OdeScene : PhysicsScene
115 public class OdeScene : PhysicsScene, INonSharedRegionModule
116 { 116 {
117 private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString()); 117 private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString());
118 private bool m_Enabled = false;
119 118
120 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); 119 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
121 120
@@ -293,11 +292,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
293 292
294 private float contactsurfacelayer = 0.001f; 293 private float contactsurfacelayer = 0.001f;
295 294
296 private int worldHashspaceLow = -4; 295 private int HashspaceLow = -5;
297 private int worldHashspaceHigh = 128; 296 private int HashspaceHigh = 12;
298
299 private int smallHashspaceLow = -4;
300 private int smallHashspaceHigh = 66;
301 297
302 private float waterlevel = 0f; 298 private float waterlevel = 0f;
303 private int framecount = 0; 299 private int framecount = 0;
@@ -356,10 +352,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
356 public float bodyPIDD = 35f; 352 public float bodyPIDD = 35f;
357 public float bodyPIDG = 25; 353 public float bodyPIDG = 25;
358 354
359 public int geomCrossingFailuresBeforeOutofbounds = 5;
360
361 public float bodyMotorJointMaxforceTensor = 2;
362
363 public int bodyFramesAutoDisable = 20; 355 public int bodyFramesAutoDisable = 20;
364 356
365 private float[] _watermap; 357 private float[] _watermap;
@@ -478,7 +470,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
478 private int m_physicsiterations = 10; 470 private int m_physicsiterations = 10;
479 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag 471 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
480 private readonly PhysicsActor PANull = new NullPhysicsActor(); 472 private readonly PhysicsActor PANull = new NullPhysicsActor();
481// private float step_time = 0.0f; 473 private float step_time = 0.0f;
482//Ckrinke: Comment out until used. We declare it, initialize it, but do not use it 474//Ckrinke: Comment out until used. We declare it, initialize it, but do not use it
483//Ckrinke private int ms = 0; 475//Ckrinke private int ms = 0;
484 public IntPtr world; 476 public IntPtr world;
@@ -534,89 +526,37 @@ namespace OpenSim.Region.PhysicsModule.ODE
534 int spaceGridMaxY; 526 int spaceGridMaxY;
535 527
536 private ODERayCastRequestManager m_rayCastManager; 528 private ODERayCastRequestManager m_rayCastManager;
529
530 public Scene m_frameWorkScene = null;
537 531
532 public OdeScene(Scene pscene, IConfigSource psourceconfig, string pname)
533 {
534 m_config = psourceconfig;
535 m_frameWorkScene = pscene;
536
537 EngineType = pname;
538 PhysicsSceneName = EngineType + "/" + pscene.RegionInfo.RegionName;
538 539
539 #region INonSharedRegionModule 540 pscene.RegisterModuleInterface<PhysicsScene>(this);
540 public string Name 541 Vector3 extent = new Vector3(pscene.RegionInfo.RegionSizeX, pscene.RegionInfo.RegionSizeY, pscene.RegionInfo.RegionSizeZ);
541 {
542 get { return "OpenDynamicsEngine"; }
543 }
544
545 public Type ReplaceableInterface
546 {
547 get { return null; }
548 }
549
550 public void Initialise(IConfigSource source)
551 {
552 // TODO: Move this out of Startup
553 IConfig config = source.Configs["Startup"];
554 if (config != null)
555 {
556 string physics = config.GetString("physics", string.Empty);
557 if (physics == Name)
558 {
559 m_Enabled = true;
560 m_config = source;
561
562 // We do this so that OpenSimulator on Windows loads the correct native ODE library depending on whether
563 // it's running as a 32-bit process or a 64-bit one. By invoking LoadLibary here, later DLLImports
564 // will find it already loaded later on.
565 //
566 // This isn't necessary for other platforms (e.g. Mac OSX and Linux) since the DLL used can be
567 // controlled in Ode.NET.dll.config
568 if (Util.IsWindows())
569 Util.LoadArchSpecificWindowsDll("ode.dll");
570
571 // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to
572 // http://opensimulator.org/mantis/view.php?id=2750).
573 d.InitODE();
574
575 }
576 }
577
578 }
579
580 public void Close()
581 {
582 }
583
584 public void AddRegion(Scene scene)
585 {
586 if (!m_Enabled)
587 return;
588
589 EngineType = Name;
590 PhysicsSceneName = EngineType + "/" + scene.RegionInfo.RegionName;
591
592 scene.RegisterModuleInterface<PhysicsScene>(this);
593 Vector3 extent = new Vector3(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY, scene.RegionInfo.RegionSizeZ);
594 Initialise(extent); 542 Initialise(extent);
595 InitialiseFromConfig(m_config); 543 InitialiseFromConfig(m_config);
596 544
597 // This may not be that good since terrain may not be avaiable at this point 545 // This may not be that good since terrain may not be avaiable at this point
598 base.Initialise(scene.PhysicsRequestAsset, 546 base.Initialise(pscene.PhysicsRequestAsset,
599 (scene.Heightmap != null ? scene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]), 547 (pscene.Heightmap != null ? pscene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]),
600 (float)scene.RegionInfo.RegionSettings.WaterHeight); 548 (float)pscene.RegionInfo.RegionSettings.WaterHeight);
601 549
602 } 550 }
603 551
604 public void RemoveRegion(Scene scene) 552 public void RegionLoaded()
605 { 553 {
606 if (!m_Enabled) 554 mesher = m_frameWorkScene.RequestModuleInterface<IMesher>();
607 return;
608 }
609
610 public void RegionLoaded(Scene scene)
611 {
612 if (!m_Enabled)
613 return;
614
615 mesher = scene.RequestModuleInterface<IMesher>();
616 if (mesher == null) 555 if (mesher == null)
617 m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName); 556 m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName);
557
558 m_frameWorkScene.PhysicsEnabled = true;
618 } 559 }
619 #endregion
620 560
621 /// <summary> 561 /// <summary>
622 /// Initiailizes the scene 562 /// Initiailizes the scene
@@ -633,8 +573,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
633 m_suportCombine = false; 573 m_suportCombine = false;
634 574
635 nearCallback = near; 575 nearCallback = near;
636 triCallback = TriCallback; 576// triCallback = TriCallback;
637 triArrayCallback = TriArrayCallback; 577// triArrayCallback = TriArrayCallback;
638 m_rayCastManager = new ODERayCastRequestManager(this); 578 m_rayCastManager = new ODERayCastRequestManager(this);
639 579
640 // Create the world and the first space 580 // Create the world and the first space
@@ -679,18 +619,9 @@ namespace OpenSim.Region.PhysicsModule.ODE
679 m_config = config; 619 m_config = config;
680 // Defaults 620 // Defaults
681 621
682 if (Environment.OSVersion.Platform == PlatformID.Unix) 622 avPIDD = 2200.0f;
683 { 623 avPIDP = 900.0f;
684 avPIDD = 3200.0f; 624 avStandupTensor = 550000f;
685 avPIDP = 1400.0f;
686 avStandupTensor = 2000000f;
687 }
688 else
689 {
690 avPIDD = 2200.0f;
691 avPIDP = 900.0f;
692 avStandupTensor = 550000f;
693 }
694 625
695 int contactsPerCollision = 80; 626 int contactsPerCollision = 80;
696 627
@@ -714,12 +645,10 @@ namespace OpenSim.Region.PhysicsModule.ODE
714 avatarTerminalVelocity, AvatarTerminalVelocity); 645 avatarTerminalVelocity, AvatarTerminalVelocity);
715 } 646 }
716 647
717 worldHashspaceLow = physicsconfig.GetInt("world_hashspace_size_low", -4); 648 HashspaceLow = physicsconfig.GetInt("world_hashspace_level_low", -5);
718 worldHashspaceHigh = physicsconfig.GetInt("world_hashspace_size_high", 128); 649 HashspaceHigh = physicsconfig.GetInt("world_hashspace_level_high", 12);
719 650
720 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", 29.9f); 651 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", 29.9f);
721 smallHashspaceLow = physicsconfig.GetInt("small_hashspace_size_low", -4);
722 smallHashspaceHigh = physicsconfig.GetInt("small_hashspace_size_high", 66);
723 652
724 contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", 0.001f); 653 contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", 0.001f);
725 654
@@ -738,7 +667,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
738 mAvatarObjectContactBounce = physicsconfig.GetFloat("m_avatarobjectcontact_bounce", 0.1f); 667 mAvatarObjectContactBounce = physicsconfig.GetFloat("m_avatarobjectcontact_bounce", 0.1f);
739 668
740 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE); 669 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE);
741 m_physicsiterations = physicsconfig.GetInt("world_internal_steps_without_collisions", 10); 670 m_physicsiterations = physicsconfig.GetInt("world_solver_iterations", 10);
742 671
743 avDensity = physicsconfig.GetFloat("av_density", 80f); 672 avDensity = physicsconfig.GetFloat("av_density", 80f);
744// avHeightFudgeFactor = physicsconfig.GetFloat("av_height_fudge_factor", 0.52f); 673// avHeightFudgeFactor = physicsconfig.GetFloat("av_height_fudge_factor", 0.52f);
@@ -754,7 +683,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
754 683
755 geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 5); 684 geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 5);
756 geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); 685 geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15);
757 geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5);
758 686
759 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f); 687 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f);
760 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20); 688 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20);
@@ -767,23 +695,10 @@ namespace OpenSim.Region.PhysicsModule.ODE
767 meshSculptLOD = physicsconfig.GetFloat("mesh_lod", 32f); 695 meshSculptLOD = physicsconfig.GetFloat("mesh_lod", 32f);
768 MeshSculptphysicalLOD = physicsconfig.GetFloat("mesh_physical_lod", 16f); 696 MeshSculptphysicalLOD = physicsconfig.GetFloat("mesh_physical_lod", 16f);
769 m_filterCollisions = physicsconfig.GetBoolean("filter_collisions", false); 697 m_filterCollisions = physicsconfig.GetBoolean("filter_collisions", false);
770
771
772 698
773 if (Environment.OSVersion.Platform == PlatformID.Unix) 699 avPIDD = physicsconfig.GetFloat("av_pid_derivative", 2200.0f);
774 { 700 avPIDP = physicsconfig.GetFloat("av_pid_proportional", 900.0f);
775 avPIDD = physicsconfig.GetFloat("av_pid_derivative_linux", 2200.0f); 701 avStandupTensor = physicsconfig.GetFloat("av_capsule_standup_tensor", 550000f);
776 avPIDP = physicsconfig.GetFloat("av_pid_proportional_linux", 900.0f);
777 avStandupTensor = physicsconfig.GetFloat("av_capsule_standup_tensor_linux", 550000f);
778 bodyMotorJointMaxforceTensor = physicsconfig.GetFloat("body_motor_joint_maxforce_tensor_linux", 5f);
779 }
780 else
781 {
782 avPIDD = physicsconfig.GetFloat("av_pid_derivative_win", 2200.0f);
783 avPIDP = physicsconfig.GetFloat("av_pid_proportional_win", 900.0f);
784 avStandupTensor = physicsconfig.GetFloat("av_capsule_standup_tensor_win", 550000f);
785 bodyMotorJointMaxforceTensor = physicsconfig.GetFloat("body_motor_joint_maxforce_tensor_win", 5f);
786 }
787 702
788 physics_logging = physicsconfig.GetBoolean("physics_logging", false); 703 physics_logging = physicsconfig.GetBoolean("physics_logging", false);
789 physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0); 704 physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0);
@@ -812,7 +727,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
812 if (spaceGridMaxY > 24) 727 if (spaceGridMaxY > 24)
813 { 728 {
814 spaceGridMaxY = 24; 729 spaceGridMaxY = 24;
815 spacesPerMeterY = spaceGridMaxY / WorldExtents.Y ; 730 spacesPerMeterY = spaceGridMaxY / WorldExtents.Y;
816 } 731 }
817 732
818 staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY]; 733 staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY];
@@ -984,7 +899,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
984 m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.010f; 899 m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.010f;
985 m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.010f; 900 m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.010f;
986 901
987 d.HashSpaceSetLevels(space, worldHashspaceLow, worldHashspaceHigh); 902 d.HashSpaceSetLevels(space, HashspaceLow, HashspaceHigh);
988 903
989 // Set the gravity,, don't disable things automatically (we set it explicitly on some things) 904 // Set the gravity,, don't disable things automatically (we set it explicitly on some things)
990 905
@@ -1864,10 +1779,10 @@ namespace OpenSim.Region.PhysicsModule.ODE
1864 //} 1779 //}
1865 // } 1780 // }
1866 } 1781 }
1867 1782/*
1868 private int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) 1783 private int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount)
1869 { 1784 {
1870 /* String name1 = null; 1785 String name1 = null;
1871 String name2 = null; 1786 String name2 = null;
1872 1787
1873 if (!geom_name_map.TryGetValue(trimesh, out name1)) 1788 if (!geom_name_map.TryGetValue(trimesh, out name1))
@@ -1880,7 +1795,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1880 } 1795 }
1881 1796
1882 m_log.InfoFormat("TriArrayCallback: A collision was detected between {1} and {2}", 0, name1, name2); 1797 m_log.InfoFormat("TriArrayCallback: A collision was detected between {1} and {2}", 0, name1, name2);
1883 */ 1798
1884 return 1; 1799 return 1;
1885 } 1800 }
1886 1801
@@ -1910,7 +1825,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1910 1825
1911 return 1; 1826 return 1;
1912 } 1827 }
1913 1828*/
1914 /// <summary> 1829 /// <summary>
1915 /// This is our collision testing routine in ODE 1830 /// This is our collision testing routine in ODE
1916 /// </summary> 1831 /// </summary>
@@ -2042,7 +1957,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
2042 x = x - offsetX + 1f; 1957 x = x - offsetX + 1f;
2043 y = y - offsetY + 1f; 1958 y = y - offsetY + 1f;
2044 1959
2045 index = (int)((int)x * ((int)m_regionHeight +3) + (int)y); 1960 // map is rotated
1961 index = (int)x * ((int)m_regionHeight + 3) + (int)y;
2046 1962
2047 if (index < TerrainHeightFieldHeights[heightFieldGeom].Length) 1963 if (index < TerrainHeightFieldHeights[heightFieldGeom].Length)
2048 { 1964 {
@@ -2620,59 +2536,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
2620 2536
2621 2537
2622 } 2538 }
2623 // we don't want to remove the main space
2624
2625 // If the geometry is in the targetspace, remove it from the target space
2626 //m_log.Warn(prim.m_targetSpace);
2627
2628 //if (prim.m_targetSpace != IntPtr.Zero)
2629 //{
2630 //if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom))
2631 //{
2632
2633 //if (d.GeomIsSpace(prim.m_targetSpace))
2634 //{
2635 //waitForSpaceUnlock(prim.m_targetSpace);
2636 //d.SpaceRemove(prim.m_targetSpace, prim.prim_geom);
2637 prim.m_targetSpace = IntPtr.Zero; 2539 prim.m_targetSpace = IntPtr.Zero;
2638 //}
2639 //else
2640 //{
2641 // m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
2642 //((OdePrim)prim).m_targetSpace.ToString());
2643 //}
2644
2645 //}
2646 //}
2647 //m_log.Warn(prim.prim_geom);
2648
2649 if (!prim.RemoveGeom()) 2540 if (!prim.RemoveGeom())
2650 m_log.Warn("[ODE SCENE]: Unable to remove prim from physics scene"); 2541 m_log.Warn("[ODE SCENE]: Unable to remove prim from physics scene");
2651 2542
2652 lock (_prims) 2543 lock (_prims)
2653 _prims.Remove(prim); 2544 _prims.Remove(prim);
2654 2545
2655 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
2656 //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)
2657 //{
2658 //if (prim.m_targetSpace != null)
2659 //{
2660 //if (d.GeomIsSpace(prim.m_targetSpace))
2661 //{
2662 //waitForSpaceUnlock(prim.m_targetSpace);
2663 //d.SpaceRemove(space, prim.m_targetSpace);
2664 // free up memory used by the space.
2665 //d.SpaceDestroy(prim.m_targetSpace);
2666 //int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position);
2667 //resetSpaceArrayItemToZero(xyspace[0], xyspace[1]);
2668 //}
2669 //else
2670 //{
2671 //m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
2672 //((OdePrim) prim).m_targetSpace.ToString());
2673 //}
2674 //}
2675 //}
2676 2546
2677 if (SupportsNINJAJoints) 2547 if (SupportsNINJAJoints)
2678 RemoveAllJointsConnectedToActorThreadLocked(prim); 2548 RemoveAllJointsConnectedToActorThreadLocked(prim);
@@ -2768,12 +2638,9 @@ namespace OpenSim.Region.PhysicsModule.ODE
2768 { 2638 {
2769 if (d.GeomIsSpace(currentspace)) 2639 if (d.GeomIsSpace(currentspace))
2770 { 2640 {
2771// waitForSpaceUnlock(currentspace);
2772// waitForSpaceUnlock(space);
2773 d.SpaceRemove(space, currentspace); 2641 d.SpaceRemove(space, currentspace);
2774 // free up memory used by the space. 2642 // free up memory used by the space.
2775 2643
2776 //d.SpaceDestroy(currentspace);
2777 resetSpaceArrayItemToZero(currentspace); 2644 resetSpaceArrayItemToZero(currentspace);
2778 } 2645 }
2779 else 2646 else
@@ -2831,7 +2698,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2831 if (newspace == IntPtr.Zero) 2698 if (newspace == IntPtr.Zero)
2832 { 2699 {
2833 newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); 2700 newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
2834 d.HashSpaceSetLevels(newspace, smallHashspaceLow, smallHashspaceHigh); 2701 d.HashSpaceSetLevels(newspace, HashspaceLow, HashspaceHigh);
2835 } 2702 }
2836 2703
2837 return newspace; 2704 return newspace;
@@ -3052,6 +2919,46 @@ namespace OpenSim.Region.PhysicsModule.ODE
3052 } 2919 }
3053 } 2920 }
3054 2921
2922 // does all pending changes generated during region load process
2923 public override void ProcessPreSimulation()
2924 {
2925 lock (OdeLock)
2926 {
2927 if (world == IntPtr.Zero)
2928 {
2929 _taintedPrims.Clear();;
2930 return;
2931 }
2932
2933 int donechanges = 0;
2934 if (_taintedPrims.Count > 0)
2935 {
2936 m_log.InfoFormat("[Ode] start processing pending actor operations");
2937 int tstart = Util.EnvironmentTickCount();
2938
2939 lock (_taintedPrims)
2940 {
2941 foreach (OdePrim prim in _taintedPrims)
2942 {
2943 if (prim.m_taintremove)
2944 RemovePrimThreadLocked(prim);
2945 else
2946 prim.ProcessTaints();
2947
2948 prim.m_collisionscore = 0;
2949 donechanges++;
2950 }
2951 _taintedPrims.Clear();
2952 }
2953
2954 int time = Util.EnvironmentTickCountSubtract(tstart);
2955 m_log.InfoFormat("[Ode] finished {0} operations in {1}ms", donechanges, time);
2956 }
2957 m_log.InfoFormat("[Ode] {0} prim actors loaded",_prims.Count);
2958 }
2959 }
2960
2961
3055 /// <summary> 2962 /// <summary>
3056 /// This is our main simulate loop 2963 /// This is our main simulate loop
3057 /// </summary> 2964 /// </summary>
@@ -3077,26 +2984,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
3077 2984
3078 float fps = 0; 2985 float fps = 0;
3079 2986
3080 float timeLeft = timeStep; 2987 step_time += timeStep;
2988
2989 float HalfOdeStep = ODE_STEPSIZE * 0.5f;
2990 if (step_time < HalfOdeStep)
2991 return 0;
3081 2992
3082 //m_log.Info(timeStep.ToString());
3083// step_time += timeSte
3084//
3085// // If We're loaded down by something else,
3086// // or debugging with the Visual Studio project on pause
3087// // skip a few frames to catch up gracefully.
3088// // without shooting the physicsactors all over the place
3089//
3090// if (step_time >= m_SkipFramesAtms)
3091// {
3092// // Instead of trying to catch up, it'll do 5 physics frames only
3093// step_time = ODE_STEPSIZE;
3094// m_physicsiterations = 5;
3095// }
3096// else
3097// {
3098// m_physicsiterations = 10;
3099// }
3100 2993
3101 // We change _collisionEventPrimChanges to avoid locking _collisionEventPrim itself and causing potential 2994 // We change _collisionEventPrimChanges to avoid locking _collisionEventPrim itself and causing potential
3102 // deadlock if the collision event tries to lock something else later on which is already locked by a 2995 // deadlock if the collision event tries to lock something else later on which is already locked by a
@@ -3138,11 +3031,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
3138 // Figure out the Frames Per Second we're going at. 3031 // Figure out the Frames Per Second we're going at.
3139 //(step_time == 0.004f, there's 250 of those per second. Times the step time/step size 3032 //(step_time == 0.004f, there's 250 of those per second. Times the step time/step size
3140 3033
3141 fps = (timeStep / ODE_STEPSIZE) * 1000; 3034
3142 // HACK: Using a time dilation of 1.0 to debug rubberbanding issues 3035 // HACK: Using a time dilation of 1.0 to debug rubberbanding issues
3143 //m_timeDilation = Math.Min((step_time / ODE_STEPSIZE) / (0.09375f / ODE_STEPSIZE), 1.0f); 3036 //m_timeDilation = Math.Min((step_time / ODE_STEPSIZE) / (0.09375f / ODE_STEPSIZE), 1.0f);
3144 3037
3145 while (timeLeft > 0.0f) 3038 while (step_time > HalfOdeStep)
3146 { 3039 {
3147 try 3040 try
3148 { 3041 {
@@ -3307,7 +3200,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
3307 m_log.ErrorFormat("[ODE SCENE]: {0}, {1}, {2}", e.Message, e.TargetSite, e); 3200 m_log.ErrorFormat("[ODE SCENE]: {0}, {1}, {2}", e.Message, e.TargetSite, e);
3308 } 3201 }
3309 3202
3310 timeLeft -= ODE_STEPSIZE; 3203 step_time -= ODE_STEPSIZE;
3204 fps += ODE_STEPSIZE;
3311 } 3205 }
3312 3206
3313 if (CollectStats) 3207 if (CollectStats)
@@ -3403,6 +3297,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3403 m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCountSubtract(startFrameTick); 3297 m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCountSubtract(startFrameTick);
3404 } 3298 }
3405 3299
3300 fps *= 1.0f/timeStep;
3406 return fps; 3301 return fps;
3407 } 3302 }
3408 3303
@@ -3675,7 +3570,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
3675 3570
3676 _heightmap = new float[heightmapWidthSamples * heightmapHeightSamples]; 3571 _heightmap = new float[heightmapWidthSamples * heightmapHeightSamples];
3677 3572
3678
3679 const float scale = 1.0f; 3573 const float scale = 1.0f;
3680 const float offset = 0.0f; 3574 const float offset = 0.0f;
3681 const float thickness = 10f; 3575 const float thickness = 10f;
@@ -3740,7 +3634,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
3740 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 3634 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
3741 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, 3635 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0,
3742 heightmapWidth, heightmapHeight, 3636 heightmapWidth, heightmapHeight,
3743 (int)heightmapWidthSamples, (int)heightmapHeightSamples, 3637 (int)heightmapWidthSamples,
3638 (int)heightmapHeightSamples,
3744 scale, offset, thickness, wrap); 3639 scale, offset, thickness, wrap);
3745 3640
3746 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); 3641 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
@@ -3765,7 +3660,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3765 3660
3766 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); 3661 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
3767 d.GeomSetRotation(GroundGeom, ref R); 3662 d.GeomSetRotation(GroundGeom, ref R);
3768 d.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0f); 3663 d.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0.0f);
3769 IntPtr testGround = IntPtr.Zero; 3664 IntPtr testGround = IntPtr.Zero;
3770 if (RegionTerrain.TryGetValue(pOffset, out testGround)) 3665 if (RegionTerrain.TryGetValue(pOffset, out testGround))
3771 { 3666 {
@@ -3796,74 +3691,24 @@ namespace OpenSim.Region.PhysicsModule.ODE
3796 public override void SetWaterLevel(float baseheight) 3691 public override void SetWaterLevel(float baseheight)
3797 { 3692 {
3798 waterlevel = baseheight; 3693 waterlevel = baseheight;
3799// randomizeWater(waterlevel);
3800 } 3694 }
3801 3695
3802/* 3696 [HandleProcessCorruptedStateExceptions]
3803 private void randomizeWater(float baseheight) 3697 public override void Dispose()
3804 { 3698 {
3805 uint heightmapWidth = m_regionWidth + 2;
3806 uint heightmapHeight = m_regionHeight + 2;
3807 uint heightmapWidthSamples = m_regionWidth + 2;
3808 uint heightmapHeightSamples = m_regionHeight + 2;
3809 float scale = 1.0f;
3810 float offset = 0.0f;
3811 float thickness = 2.9f;
3812 int wrap = 0;
3813
3814 for (int i = 0; i < (258 * 258); i++)
3815 {
3816 _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f);
3817 // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f));
3818 }
3819
3820 lock (OdeLock) 3699 lock (OdeLock)
3821 { 3700 {
3822 if (WaterGeom != IntPtr.Zero) 3701 if(world == IntPtr.Zero)
3823 { 3702 return;
3824 d.SpaceRemove(space, WaterGeom);
3825 }
3826 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
3827 d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight,
3828 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
3829 offset, thickness, wrap);
3830 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
3831 WaterGeom = d.CreateHeightfield(space, HeightmapData, 1);
3832 if (WaterGeom != IntPtr.Zero)
3833 {
3834 d.GeomSetCategoryBits(WaterGeom, (int)(CollisionCategories.Water));
3835 d.GeomSetCollideBits(WaterGeom, (int)(CollisionCategories.Space));
3836 }
3837
3838 geom_name_map[WaterGeom] = "Water";
3839
3840 d.Matrix3 R = new d.Matrix3();
3841
3842 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
3843 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
3844 //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));
3845
3846 q1 = q1 * q2;
3847 //q1 = q1 * q3;
3848 Vector3 v3;
3849 float angle;
3850 q1.GetAxisAngle(out v3, out angle);
3851 3703
3852 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); 3704 _worldInitialized = false;
3853 d.GeomSetRotation(WaterGeom, ref R);
3854 d.GeomSetPosition(WaterGeom, 128, 128, 0);
3855 }
3856 }
3857*/
3858 public override void Dispose()
3859 {
3860 _worldInitialized = false;
3861 3705
3862 m_rayCastManager.Dispose(); 3706 if (m_rayCastManager != null)
3863 m_rayCastManager = null; 3707 {
3708 m_rayCastManager.Dispose();
3709 m_rayCastManager = null;
3710 }
3864 3711
3865 lock (OdeLock)
3866 {
3867 lock (_prims) 3712 lock (_prims)
3868 { 3713 {
3869 foreach (OdePrim prm in _prims) 3714 foreach (OdePrim prm in _prims)
@@ -3876,10 +3721,29 @@ namespace OpenSim.Region.PhysicsModule.ODE
3876 //{ 3721 //{
3877 //RemoveAvatar(act); 3722 //RemoveAvatar(act);
3878 //} 3723 //}
3879 d.WorldDestroy(world); 3724 IntPtr GroundGeom = IntPtr.Zero;
3725 if (RegionTerrain.TryGetValue(m_worldOffset, out GroundGeom))
3726 {
3727 RegionTerrain.Remove(m_worldOffset);
3728 if (GroundGeom != IntPtr.Zero)
3729 {
3730 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
3731 TerrainHeightFieldHeights.Remove(GroundGeom);
3732 d.GeomDestroy(GroundGeom);
3733 }
3734 }
3735
3736 try
3737 {
3738 d.WorldDestroy(world);
3739 world = IntPtr.Zero;
3740 }
3741 catch (AccessViolationException e)
3742 {
3743 m_log.ErrorFormat("[ODE SCENE]: exception {0}", e.Message);
3744 }
3880 //d.CloseODE(); 3745 //d.CloseODE();
3881 } 3746 }
3882
3883 } 3747 }
3884 3748
3885 public override Dictionary<uint, float> GetTopColliders() 3749 public override Dictionary<uint, float> GetTopColliders()