ODEModule.cs 3.0 KB

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