PageRenderTime 26ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/OpenSim/Region/PhysicsModules/ubOde/ODEModule.cs

https://github.com/opensim/opensim
C# | 132 lines | 106 code | 23 blank | 3 comment | 17 complexity | 791b9e43eff0b5fa34e6cf05649d3585 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using log4net;
  5. using Nini.Config;
  6. using Mono.Addins;
  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. ODEScene m_odeScene = null;
  17. private IConfigSource m_config;
  18. private string m_libVersion = string.Empty;
  19. private bool m_Enabled = false;
  20. #region INonSharedRegionModule
  21. public string Name
  22. {
  23. get { return "ubODE"; }
  24. }
  25. public string Version
  26. {
  27. get { return "1.0"; }
  28. }
  29. public Type ReplaceableInterface
  30. {
  31. get { return null; }
  32. }
  33. public void Initialise(IConfigSource source)
  34. {
  35. IConfig config = source.Configs["Startup"];
  36. if (config != null)
  37. {
  38. string physics = config.GetString("physics", string.Empty);
  39. if (physics == Name)
  40. {
  41. m_config = source;
  42. string mesher = config.GetString("meshing", string.Empty);
  43. if (string.IsNullOrEmpty(mesher) || !mesher.Equals("ubODEMeshmerizer"))
  44. {
  45. m_log.Error("[ubODE] Opensim.ini meshing option must be set to \"ubODEMeshmerizer\"");
  46. //throw new Exception("Invalid physics meshing option");
  47. }
  48. if (Util.IsWindows())
  49. Util.LoadArchSpecificWindowsDll("ubode.dll");
  50. SafeNativeMethods.InitODE();
  51. string ode_config = SafeNativeMethods.GetConfiguration();
  52. if (string.IsNullOrEmpty(ode_config))
  53. {
  54. m_log.Error("[ubODE] Native ode library version not supported");
  55. return;
  56. }
  57. int indx = ode_config.IndexOf("ODE_OPENSIM");
  58. if (indx < 0)
  59. {
  60. m_log.Error("[ubODE] Native ode library version not supported");
  61. return;
  62. }
  63. indx += 12;
  64. if (indx >= ode_config.Length)
  65. {
  66. m_log.Error("[ubODE] Native ode library version not supported");
  67. return;
  68. }
  69. m_libVersion = ode_config.Substring(indx);
  70. if (string.IsNullOrEmpty(m_libVersion))
  71. {
  72. m_log.Error("[ubODE] Native ode library version not supported");
  73. return;
  74. }
  75. m_libVersion.Trim();
  76. if(m_libVersion.StartsWith("OS"))
  77. m_libVersion = m_libVersion.Substring(2);
  78. m_log.InfoFormat("[ubODE] ode library configuration: {0}", ode_config);
  79. m_Enabled = true;
  80. }
  81. }
  82. }
  83. public void Close()
  84. {
  85. }
  86. public void AddRegion(Scene scene)
  87. {
  88. if (!m_Enabled)
  89. return;
  90. m_odeScene = new ODEScene(scene, m_config, Name, Version + "-" + m_libVersion);
  91. }
  92. public void RemoveRegion(Scene scene)
  93. {
  94. if (!m_Enabled)
  95. return;
  96. // a odescene.dispose is called later directly by scene.cs
  97. // since it is seen as a module interface
  98. m_odeScene = null;
  99. }
  100. public void RegionLoaded(Scene scene)
  101. {
  102. if (!m_Enabled)
  103. return;
  104. if(m_odeScene != null)
  105. m_odeScene.RegionLoaded();
  106. }
  107. #endregion
  108. }
  109. }