ODEModule.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Reflection;
  3. using log4net;
  4. using Nini.Config;
  5. using Mono.Addins;
  6. using OdeAPI;
  7. using OpenSim.Framework;
  8. using OpenSim.Region.Framework.Scenes;
  9. using OpenSim.Region.Framework.Interfaces;
  10. namespace OpenSim.Region.PhysicsModule.ubOde
  11. {
  12. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ubODEPhysicsScene")]
  13. class ubOdeModule : 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. private bool ubOdeLib;
  20. #region INonSharedRegionModule
  21. public string Name
  22. {
  23. get { return "ubODE"; }
  24. }
  25. public Type ReplaceableInterface
  26. {
  27. get { return null; }
  28. }
  29. public void Initialise(IConfigSource source)
  30. {
  31. IConfig config = source.Configs["Startup"];
  32. if (config != null)
  33. {
  34. string physics = config.GetString("physics", string.Empty);
  35. if (physics == Name)
  36. {
  37. m_config = source;
  38. m_Enabled = true;
  39. }
  40. }
  41. }
  42. public void Close()
  43. {
  44. }
  45. public void AddRegion(Scene scene)
  46. {
  47. if (!m_Enabled)
  48. return;
  49. if (Util.IsWindows())
  50. Util.LoadArchSpecificWindowsDll("ode.dll");
  51. // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to
  52. // http://opensimulator.org/mantis/view.php?id=2750).
  53. d.InitODE();
  54. string ode_config = d.GetConfiguration();
  55. if (ode_config != null && ode_config != "")
  56. {
  57. m_log.InfoFormat("[ubODE] ode library configuration: {0}", ode_config);
  58. // ubODE still not avaiable
  59. if (ode_config.Contains("ubODE"))
  60. {
  61. ubOdeLib = true;
  62. }
  63. }
  64. m_scene = new ODEScene(scene, m_config, Name, ubOdeLib);
  65. }
  66. public void RemoveRegion(Scene scene)
  67. {
  68. if (!m_Enabled || m_scene == null)
  69. return;
  70. m_scene.Dispose();
  71. m_scene = null;
  72. }
  73. public void RegionLoaded(Scene scene)
  74. {
  75. if (!m_Enabled || m_scene == null)
  76. return;
  77. m_scene.RegionLoaded();
  78. }
  79. #endregion
  80. }
  81. }