aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/PhysicsModules/Ode/OdeScene.cs (renamed from OpenSim/Region/Physics/OdePlugin/OdeScene.cs)145
1 files changed, 117 insertions, 28 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
index 812b469..b00a5ab 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
@@ -25,13 +25,11 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28// Ubit changes for varsize regions 28// changes for varsize regions
29// using a large Heightfield geometry for terrain 29// note that raycasts need to have limited range
30// ODE ode should handle it fine
31// EXCEPT raycasts, those need to have limited range
32// (even in normal regions) 30// (even in normal regions)
33// or aplication stack will just blowup 31// or aplication thread stack may just blowup
34 32// see RayCast(ODERayCastRequest req)
35 33
36//#define USE_DRAWSTUFF 34//#define USE_DRAWSTUFF
37//#define SPAM 35//#define SPAM
@@ -46,15 +44,19 @@ using System.Runtime.InteropServices;
46using System.Threading; 44using System.Threading;
47using log4net; 45using log4net;
48using Nini.Config; 46using Nini.Config;
47using Mono.Addins;
49using Ode.NET; 48using Ode.NET;
50using OpenMetaverse; 49using OpenMetaverse;
51#if USE_DRAWSTUFF 50#if USE_DRAWSTUFF
52using Drawstuff.NET; 51using Drawstuff.NET;
53#endif 52#endif
54using OpenSim.Framework; 53using OpenSim.Framework;
55using OpenSim.Region.Physics.Manager; 54using OpenSim.Region.PhysicsModules.SharedBase;
55using OpenSim.Region.Framework.Scenes;
56using OpenSim.Region.Framework.Interfaces;
57
56 58
57namespace OpenSim.Region.Physics.OdePlugin 59namespace OpenSim.Region.PhysicsModule.ODE
58{ 60{
59 public enum StatusIndicators : int 61 public enum StatusIndicators : int
60 { 62 {
@@ -109,9 +111,12 @@ namespace OpenSim.Region.Physics.OdePlugin
109 Rubber = 6 111 Rubber = 6
110 } 112 }
111 113
112 public class OdeScene : PhysicsScene 114 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")]
115 public class OdeScene : PhysicsScene, INonSharedRegionModule
113 { 116 {
114 private readonly ILog m_log; 117 private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString());
118 private bool m_Enabled = false;
119
115 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); 120 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
116 121
117 /// <summary> 122 /// <summary>
@@ -298,7 +303,7 @@ namespace OpenSim.Region.Physics.OdePlugin
298 private int framecount = 0; 303 private int framecount = 0;
299 //private int m_returncollisions = 10; 304 //private int m_returncollisions = 10;
300 305
301 private readonly IntPtr contactgroup; 306 private IntPtr contactgroup;
302 307
303// internal IntPtr WaterGeom; 308// internal IntPtr WaterGeom;
304 309
@@ -530,19 +535,103 @@ namespace OpenSim.Region.Physics.OdePlugin
530 535
531 private ODERayCastRequestManager m_rayCastManager; 536 private ODERayCastRequestManager m_rayCastManager;
532 537
538
539 #region INonSharedRegionModule
540 public string Name
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);
595 InitialiseFromConfig(m_config);
596
597 // This may not be that good since terrain may not be avaiable at this point
598 base.Initialise(scene.PhysicsRequestAsset,
599 (scene.Heightmap != null ? scene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]),
600 (float)scene.RegionInfo.RegionSettings.WaterHeight);
601
602 }
603
604 public void RemoveRegion(Scene scene)
605 {
606 if (!m_Enabled)
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)
617 m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName);
618 }
619 #endregion
620
533 /// <summary> 621 /// <summary>
534 /// Initiailizes the scene 622 /// Initiailizes the scene
535 /// Sets many properties that ODE requires to be stable 623 /// Sets many properties that ODE requires to be stable
536 /// These settings need to be tweaked 'exactly' right or weird stuff happens. 624 /// These settings need to be tweaked 'exactly' right or weird stuff happens.
537 /// </summary> 625 /// </summary>
538 /// <param value="name">Name of the scene. Useful in debug messages.</param> 626 private void Initialise(Vector3 regionExtent)
539 public OdeScene(string engineType, string name)
540 { 627 {
541 m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + name); 628 WorldExtents.X = regionExtent.X;
542 629 m_regionWidth = (uint)regionExtent.X;
543 Name = name; 630 WorldExtents.Y = regionExtent.Y;
544 EngineType = engineType; 631 m_regionHeight = (uint)regionExtent.Y;
545 632
633 m_suportCombine = false;
634
546 nearCallback = near; 635 nearCallback = near;
547 triCallback = TriCallback; 636 triCallback = TriCallback;
548 triArrayCallback = TriArrayCallback; 637 triArrayCallback = TriArrayCallback;
@@ -582,7 +671,7 @@ namespace OpenSim.Region.Physics.OdePlugin
582 } 671 }
583#endif 672#endif
584 673
585 public override void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent) 674 public void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
586 { 675 {
587 WorldExtents.X = regionExtent.X; 676 WorldExtents.X = regionExtent.X;
588 m_regionWidth = (uint)regionExtent.X; 677 m_regionWidth = (uint)regionExtent.X;
@@ -593,11 +682,10 @@ namespace OpenSim.Region.Physics.OdePlugin
593 } 682 }
594 683
595 // Initialize the mesh plugin 684 // Initialize the mesh plugin
596 public override void Initialise(IMesher meshmerizer, IConfigSource config) 685 public void Initialise(IMesher meshmerizer, IConfigSource config)
597 { 686 {
598 InitializeExtraStats(); 687 InitializeExtraStats();
599 688
600 mesher = meshmerizer;
601 m_config = config; 689 m_config = config;
602 // Defaults 690 // Defaults
603 691
@@ -725,11 +813,11 @@ namespace OpenSim.Region.Physics.OdePlugin
725 spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeterX); 813 spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeterX);
726 spaceGridMaxY = (int)(WorldExtents.Y * spacesPerMeterY); 814 spaceGridMaxY = (int)(WorldExtents.Y * spacesPerMeterY);
727 815
728 // ubit: limit number of spaces 816 // note: limit number of spaces
729 if (spaceGridMaxX > 24) 817 if (spaceGridMaxX > 24)
730 { 818 {
731 spaceGridMaxX = 24; 819 spaceGridMaxX = 24;
732 spacesPerMeterX = spaceGridMaxX / WorldExtents.X ; 820 spacesPerMeterX = spaceGridMaxX / WorldExtents.X;
733 } 821 }
734 if (spaceGridMaxY > 24) 822 if (spaceGridMaxY > 24)
735 { 823 {
@@ -1862,7 +1950,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1862 } 1950 }
1863 catch (AccessViolationException) 1951 catch (AccessViolationException)
1864 { 1952 {
1865 m_log.ErrorFormat("[ODE SCENE]: Unable to space collide {0}", Name); 1953 m_log.ErrorFormat("[ODE SCENE]: Unable to space collide {0}", PhysicsSceneName);
1866 } 1954 }
1867 1955
1868 //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); 1956 //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y);
@@ -3119,7 +3207,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3119 { 3207 {
3120 m_log.ErrorFormat( 3208 m_log.ErrorFormat(
3121 "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2} due to defect found when moving", 3209 "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2} due to defect found when moving",
3122 actor.Name, actor.LocalID, Name); 3210 actor.Name, actor.LocalID, PhysicsSceneName);
3123 3211
3124 RemoveCharacter(actor); 3212 RemoveCharacter(actor);
3125 actor.DestroyOdeStructures(); 3213 actor.DestroyOdeStructures();
@@ -3236,7 +3324,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3236 { 3324 {
3237 m_log.ErrorFormat( 3325 m_log.ErrorFormat(
3238 "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2} due to defect found when updating position and velocity", 3326 "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2} due to defect found when updating position and velocity",
3239 actor.Name, actor.LocalID, Name); 3327 actor.Name, actor.LocalID, PhysicsSceneName);
3240 3328
3241 RemoveCharacter(actor); 3329 RemoveCharacter(actor);
3242 actor.DestroyOdeStructures(); 3330 actor.DestroyOdeStructures();
@@ -3835,7 +3923,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3835 private void SetTerrain(float[] heightMap, Vector3 pOffset) 3923 private void SetTerrain(float[] heightMap, Vector3 pOffset)
3836 { 3924 {
3837 int startTime = Util.EnvironmentTickCount(); 3925 int startTime = Util.EnvironmentTickCount();
3838 m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0} with offset {1}", Name, pOffset); 3926 m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0} with offset {1}", PhysicsSceneName, pOffset);
3839 3927
3840 3928
3841 float[] _heightmap; 3929 float[] _heightmap;
@@ -3873,6 +3961,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3873 uint xt = 0; 3961 uint xt = 0;
3874 xx = 0; 3962 xx = 0;
3875 3963
3964
3876 for (uint x = 0; x < heightmapWidthSamples; x++) 3965 for (uint x = 0; x < heightmapWidthSamples; x++)
3877 { 3966 {
3878 if (x > 1 && xx < maxXX) 3967 if (x > 1 && xx < maxXX)
@@ -3951,7 +4040,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3951 } 4040 }
3952 4041
3953 m_log.DebugFormat( 4042 m_log.DebugFormat(
3954 "[ODE SCENE]: Setting terrain for {0} took {1}ms", Name, Util.EnvironmentTickCountSubtract(startTime)); 4043 "[ODE SCENE]: Setting terrain for {0} took {1}ms", PhysicsSceneName, Util.EnvironmentTickCountSubtract(startTime));
3955 } 4044 }
3956 4045
3957 public override void DeleteTerrain() 4046 public override void DeleteTerrain()