ODEModule.cs 2.3 KB

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