1
0

ODEModule.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. using OpenMetaverse;
  11. namespace OpenSim.Region.PhysicsModule.ubOde
  12. {
  13. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ubODEPhysicsScene")]
  14. class ubOdeModule : INonSharedRegionModule
  15. {
  16. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  17. ODEScene m_odeScene = null;
  18. private IConfigSource m_config;
  19. private string m_libVersion = string.Empty;
  20. private bool m_Enabled = false;
  21. #region INonSharedRegionModule
  22. public string Name
  23. {
  24. get { return "ubODE"; }
  25. }
  26. public string Version
  27. {
  28. get { return "1.0"; }
  29. }
  30. public Type ReplaceableInterface
  31. {
  32. get { return null; }
  33. }
  34. public void Initialise(IConfigSource source)
  35. {
  36. IConfig config = source.Configs["Startup"];
  37. if (config != null)
  38. {
  39. string physics = config.GetString("physics", string.Empty);
  40. if (physics == Name)
  41. {
  42. m_config = source;
  43. string mesher = config.GetString("meshing", string.Empty);
  44. if (string.IsNullOrEmpty(mesher) || !mesher.Equals("ubODEMeshmerizer"))
  45. {
  46. m_log.Error("[ubODE] Opensim.ini meshing option must be set to \"ubODEMeshmerizer\"");
  47. //throw new Exception("Invalid physics meshing option");
  48. }
  49. DllmapConfigHelper.RegisterAssembly(typeof(ubOdeModule).Assembly);
  50. UBOdeNative.InitODE();
  51. string ode_config = UBOdeNative.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. }