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.cs111
1 files changed, 94 insertions, 17 deletions
diff --git a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
index d7163e2..3616200 100644
--- a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
+++ b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
@@ -38,6 +38,7 @@ using System.Runtime.InteropServices;
38using System.Threading; 38using System.Threading;
39using log4net; 39using log4net;
40using Nini.Config; 40using Nini.Config;
41using Mono.Addins;
41using Ode.NET; 42using Ode.NET;
42using OpenMetaverse; 43using OpenMetaverse;
43#if USE_DRAWSTUFF 44#if USE_DRAWSTUFF
@@ -45,6 +46,9 @@ using Drawstuff.NET;
45#endif 46#endif
46using OpenSim.Framework; 47using OpenSim.Framework;
47using OpenSim.Region.PhysicsModules.SharedBase; 48using OpenSim.Region.PhysicsModules.SharedBase;
49using OpenSim.Region.Framework.Scenes;
50using OpenSim.Region.Framework.Interfaces;
51
48 52
49namespace OpenSim.Region.PhysicsModule.ODE 53namespace OpenSim.Region.PhysicsModule.ODE
50{ 54{
@@ -101,9 +105,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
101 Rubber = 6 105 Rubber = 6
102 } 106 }
103 107
108 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")]
104 public class OdeScene : PhysicsScene 109 public class OdeScene : PhysicsScene
105 { 110 {
106 private readonly ILog m_log; 111 private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString());
112 private bool m_Enabled = false;
113
107 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); 114 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
108 115
109 /// <summary> 116 /// <summary>
@@ -288,7 +295,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
288 private int framecount = 0; 295 private int framecount = 0;
289 //private int m_returncollisions = 10; 296 //private int m_returncollisions = 10;
290 297
291 private readonly IntPtr contactgroup; 298 private IntPtr contactgroup;
292 299
293 internal IntPtr WaterGeom; 300 internal IntPtr WaterGeom;
294 301
@@ -520,19 +527,90 @@ namespace OpenSim.Region.PhysicsModule.ODE
520 527
521 private ODERayCastRequestManager m_rayCastManager; 528 private ODERayCastRequestManager m_rayCastManager;
522 529
530
531 #region INonSharedRegionModule
532 public string Name
533 {
534 get { return "OpenDynamicsEngine"; }
535 }
536
537 public Type ReplaceableInterface
538 {
539 get { return null; }
540 }
541
542 public void Initialise(IConfigSource source)
543 {
544 // TODO: Move this out of Startup
545 IConfig config = source.Configs["Startup"];
546 if (config != null)
547 {
548 string physics = config.GetString("physics", string.Empty);
549 if (physics == Name)
550 {
551 m_Enabled = true;
552 m_config = source;
553
554 // We do this so that OpenSimulator on Windows loads the correct native ODE library depending on whether
555 // it's running as a 32-bit process or a 64-bit one. By invoking LoadLibary here, later DLLImports
556 // will find it already loaded later on.
557 //
558 // This isn't necessary for other platforms (e.g. Mac OSX and Linux) since the DLL used can be
559 // controlled in Ode.NET.dll.config
560 if (Util.IsWindows())
561 Util.LoadArchSpecificWindowsDll("ode.dll");
562
563 // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to
564 // http://opensimulator.org/mantis/view.php?id=2750).
565 d.InitODE();
566
567 }
568 }
569
570 }
571
572 public void Close()
573 {
574 }
575
576 public void AddRegion(Scene scene)
577 {
578 if (!m_Enabled)
579 return;
580
581 EngineType = Name;
582 PhysicsSceneName = EngineType + "/" + scene.RegionInfo.RegionName;
583
584 scene.RegisterModuleInterface<PhysicsScene>(this);
585 Vector3 extent = new Vector3(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY, scene.RegionInfo.RegionSizeZ);
586 Initialise();
587 InitialiseFromConfig(m_config);
588 }
589
590 public void RemoveRegion(Scene scene)
591 {
592 if (!m_Enabled)
593 return;
594 }
595
596 public void RegionLoaded(Scene scene)
597 {
598 if (!m_Enabled)
599 return;
600
601 mesher = scene.RequestModuleInterface<IMesher>();
602 if (mesher == null)
603 m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName);
604 }
605 #endregion
606
523 /// <summary> 607 /// <summary>
524 /// Initiailizes the scene 608 /// Initiailizes the scene
525 /// Sets many properties that ODE requires to be stable 609 /// Sets many properties that ODE requires to be stable
526 /// These settings need to be tweaked 'exactly' right or weird stuff happens. 610 /// These settings need to be tweaked 'exactly' right or weird stuff happens.
527 /// </summary> 611 /// </summary>
528 /// <param value="name">Name of the scene. Useful in debug messages.</param> 612 private void Initialise()
529 public OdeScene(string engineType, string name)
530 { 613 {
531 m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + name);
532
533 Name = name;
534 EngineType = engineType;
535
536 nearCallback = near; 614 nearCallback = near;
537 triCallback = TriCallback; 615 triCallback = TriCallback;
538 triArrayCallback = TriArrayCallback; 616 triArrayCallback = TriArrayCallback;
@@ -572,12 +650,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
572 } 650 }
573#endif 651#endif
574 652
575 // Initialize the mesh plugin 653 // Initialize from configs
576 public override void Initialise(IMesher meshmerizer, IConfigSource config) 654 private void InitialiseFromConfig(IConfigSource config)
577 { 655 {
578 InitializeExtraStats(); 656 InitializeExtraStats();
579 657
580 mesher = meshmerizer;
581 m_config = config; 658 m_config = config;
582 // Defaults 659 // Defaults
583 660
@@ -1818,7 +1895,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1818 } 1895 }
1819 catch (AccessViolationException) 1896 catch (AccessViolationException)
1820 { 1897 {
1821 m_log.ErrorFormat("[ODE SCENE]: Unable to space collide {0}", Name); 1898 m_log.ErrorFormat("[ODE SCENE]: Unable to space collide {0}", PhysicsSceneName);
1822 } 1899 }
1823 1900
1824 //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); 1901 //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y);
@@ -3082,7 +3159,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3082 { 3159 {
3083 m_log.ErrorFormat( 3160 m_log.ErrorFormat(
3084 "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2} due to defect found when moving", 3161 "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2} due to defect found when moving",
3085 actor.Name, actor.LocalID, Name); 3162 actor.Name, actor.LocalID, PhysicsSceneName);
3086 3163
3087 RemoveCharacter(actor); 3164 RemoveCharacter(actor);
3088 actor.DestroyOdeStructures(); 3165 actor.DestroyOdeStructures();
@@ -3198,7 +3275,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3198 { 3275 {
3199 m_log.ErrorFormat( 3276 m_log.ErrorFormat(
3200 "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2} due to defect found when updating position and velocity", 3277 "[ODE SCENE]: Removing physics character {0} {1} from physics scene {2} due to defect found when updating position and velocity",
3201 actor.Name, actor.LocalID, Name); 3278 actor.Name, actor.LocalID, PhysicsSceneName);
3202 3279
3203 RemoveCharacter(actor); 3280 RemoveCharacter(actor);
3204 actor.DestroyOdeStructures(); 3281 actor.DestroyOdeStructures();
@@ -3795,7 +3872,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3795 private void SetTerrain(float[] heightMap, Vector3 pOffset) 3872 private void SetTerrain(float[] heightMap, Vector3 pOffset)
3796 { 3873 {
3797 int startTime = Util.EnvironmentTickCount(); 3874 int startTime = Util.EnvironmentTickCount();
3798 m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0} with offset {1}", Name, pOffset); 3875 m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0} with offset {1}", PhysicsSceneName, pOffset);
3799 3876
3800 // this._heightmap[i] = (double)heightMap[i]; 3877 // this._heightmap[i] = (double)heightMap[i];
3801 // dbm (danx0r) -- creating a buffer zone of one extra sample all around 3878 // dbm (danx0r) -- creating a buffer zone of one extra sample all around
@@ -3920,7 +3997,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3920 } 3997 }
3921 3998
3922 m_log.DebugFormat( 3999 m_log.DebugFormat(
3923 "[ODE SCENE]: Setting terrain for {0} took {1}ms", Name, Util.EnvironmentTickCountSubtract(startTime)); 4000 "[ODE SCENE]: Setting terrain for {0} took {1}ms", PhysicsSceneName, Util.EnvironmentTickCountSubtract(startTime));
3924 } 4001 }
3925 4002
3926 public override void DeleteTerrain() 4003 public override void DeleteTerrain()