1
0

ODEModule.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. private static Dictionary<Scene, ODEScene> m_scenes = new Dictionary<Scene, ODEScene>();
  17. private bool m_Enabled = false;
  18. private IConfigSource m_config;
  19. private bool OSOdeLib;
  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. m_Enabled = true;
  43. if (Util.IsWindows())
  44. Util.LoadArchSpecificWindowsDll("ode.dll");
  45. SafeNativeMethods.InitODE();
  46. string ode_config = SafeNativeMethods.GetConfiguration();
  47. if (ode_config == null || ode_config == "" || !ode_config.Contains("ODE_OPENSIM"))
  48. {
  49. m_log.Error("[ubODE] Native ode library version not supported");
  50. m_Enabled = false;
  51. return;
  52. }
  53. m_log.InfoFormat("[ubODE] ode library configuration: {0}", ode_config);
  54. OSOdeLib = true;
  55. }
  56. }
  57. }
  58. public void Close()
  59. {
  60. }
  61. public void AddRegion(Scene scene)
  62. {
  63. if (!m_Enabled)
  64. return;
  65. if(m_scenes.ContainsKey(scene)) // ???
  66. return;
  67. ODEScene newodescene = new ODEScene(scene, m_config, Name, Version, OSOdeLib);
  68. m_scenes[scene] = newodescene;
  69. }
  70. public void RemoveRegion(Scene scene)
  71. {
  72. if (!m_Enabled)
  73. return;
  74. // a odescene.dispose is called later directly by scene.cs
  75. // since it is seen as a module interface
  76. if(m_scenes.ContainsKey(scene))
  77. m_scenes.Remove(scene);
  78. }
  79. public void RegionLoaded(Scene scene)
  80. {
  81. if (!m_Enabled)
  82. return;
  83. if(m_scenes.ContainsKey(scene))
  84. {
  85. m_scenes[scene].RegionLoaded();
  86. }
  87. }
  88. #endregion
  89. }
  90. }