ODEModule.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Reflection;
  3. using log4net;
  4. using Nini.Config;
  5. using Mono.Addins;
  6. using OpenSim.Framework;
  7. using OpenSim.Region.Framework.Scenes;
  8. using OpenSim.Region.Framework.Interfaces;
  9. using Ode.NET;
  10. namespace OpenSim.Region.PhysicsModule.ODE
  11. {
  12. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")]
  13. public class OdeModule : INonSharedRegionModule
  14. {
  15. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  16. private bool m_Enabled = false;
  17. private IConfigSource m_config;
  18. private OdeScene m_scene;
  19. #region INonSharedRegionModule
  20. public string Name
  21. {
  22. get { return "OpenDynamicsEngine"; }
  23. }
  24. public Type ReplaceableInterface
  25. {
  26. get { return null; }
  27. }
  28. public void Initialise(IConfigSource source)
  29. {
  30. IConfig config = source.Configs["Startup"];
  31. if (config != null)
  32. {
  33. string physics = config.GetString("physics", string.Empty);
  34. if (physics == Name)
  35. {
  36. m_config = source;
  37. m_Enabled = true;
  38. }
  39. }
  40. }
  41. public void Close()
  42. {
  43. }
  44. public void AddRegion(Scene scene)
  45. {
  46. if (!m_Enabled)
  47. return;
  48. if (Util.IsWindows())
  49. Util.LoadArchSpecificWindowsDll("ode.dll");
  50. // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to
  51. // http://opensimulator.org/mantis/view.php?id=2750).
  52. d.InitODE();
  53. m_scene = new OdeScene(scene, m_config, Name);
  54. }
  55. public void RemoveRegion(Scene scene)
  56. {
  57. if (!m_Enabled || m_scene == null)
  58. return;
  59. m_scene.Dispose();
  60. m_scene = null;
  61. }
  62. public void RegionLoaded(Scene scene)
  63. {
  64. if (!m_Enabled || m_scene == null)
  65. return;
  66. m_scene.RegionLoaded();
  67. }
  68. #endregion
  69. }
  70. }