From 47aa8107fd49039feb8dd95ec93e8ac80088e158 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 9 Sep 2015 18:53:24 +0100 Subject: let old ode also have a Module class --- OpenSim/Region/PhysicsModules/Ode/ODEModule.cs | 85 ++++++++++++++++++++ OpenSim/Region/PhysicsModules/Ode/OdeScene.cs | 92 +++++----------------- .../PhysicsModules/Ode/Tests/ODETestClass.cs | 16 ++-- 3 files changed, 113 insertions(+), 80 deletions(-) create mode 100644 OpenSim/Region/PhysicsModules/Ode/ODEModule.cs (limited to 'OpenSim/Region/PhysicsModules') diff --git a/OpenSim/Region/PhysicsModules/Ode/ODEModule.cs b/OpenSim/Region/PhysicsModules/Ode/ODEModule.cs new file mode 100644 index 0000000..101e8b0 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/Ode/ODEModule.cs @@ -0,0 +1,85 @@ +using System; +using System.Reflection; +using log4net; +using Nini.Config; +using Mono.Addins; +using OpenSim.Framework; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Interfaces; +using Ode.NET; + +namespace OpenSim.Region.PhysicsModule.ODE +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")] + public class OdeModule : INonSharedRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_Enabled = false; + private IConfigSource m_config; + private OdeScene m_scene; + + #region INonSharedRegionModule + + public string Name + { + get { return "OpenDynamicsEngine"; } + } + + public Type ReplaceableInterface + { + get { return null; } + } + + public void Initialise(IConfigSource source) + { + IConfig config = source.Configs["Startup"]; + if (config != null) + { + string physics = config.GetString("physics", string.Empty); + if (physics == Name) + { + m_config = source; + m_Enabled = true; + } + } + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + if (Util.IsWindows()) + Util.LoadArchSpecificWindowsDll("ode.dll"); + + // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to + // http://opensimulator.org/mantis/view.php?id=2750). + d.InitODE(); + + m_scene = new OdeScene(scene, m_config, Name); + } + + public void RemoveRegion(Scene scene) + { + if (!m_Enabled || m_scene == null) + return; + + m_scene.Dispose(); + m_scene = null; + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled || m_scene == null) + return; + + m_scene.RegionLoaded(); + } + #endregion + } +} diff --git a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs index 1d1b710..3ea522c 100644 --- a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs +++ b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs @@ -111,11 +111,9 @@ namespace OpenSim.Region.PhysicsModule.ODE Rubber = 6 } - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")] - public class OdeScene : PhysicsScene, INonSharedRegionModule + public class OdeScene : PhysicsScene { private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString()); - private bool m_Enabled = false; // private Dictionary m_storedCollisions = new Dictionary(); @@ -534,89 +532,37 @@ namespace OpenSim.Region.PhysicsModule.ODE int spaceGridMaxY; private ODERayCastRequestManager m_rayCastManager; + + public Scene m_frameWorkScene = null; + public OdeScene(Scene pscene, IConfigSource psourceconfig, string pname) + { + m_config = psourceconfig; + m_frameWorkScene = pscene; + + EngineType = pname; + PhysicsSceneName = EngineType + "/" + pscene.RegionInfo.RegionName; - #region INonSharedRegionModule - public string Name - { - get { return "OpenDynamicsEngine"; } - } - - public Type ReplaceableInterface - { - get { return null; } - } - - public void Initialise(IConfigSource source) - { - // TODO: Move this out of Startup - IConfig config = source.Configs["Startup"]; - if (config != null) - { - string physics = config.GetString("physics", string.Empty); - if (physics == Name) - { - m_Enabled = true; - m_config = source; - - // We do this so that OpenSimulator on Windows loads the correct native ODE library depending on whether - // it's running as a 32-bit process or a 64-bit one. By invoking LoadLibary here, later DLLImports - // will find it already loaded later on. - // - // This isn't necessary for other platforms (e.g. Mac OSX and Linux) since the DLL used can be - // controlled in Ode.NET.dll.config - if (Util.IsWindows()) - Util.LoadArchSpecificWindowsDll("ode.dll"); - - // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to - // http://opensimulator.org/mantis/view.php?id=2750). - d.InitODE(); - - } - } - - } - - public void Close() - { - } - - public void AddRegion(Scene scene) - { - if (!m_Enabled) - return; - - EngineType = Name; - PhysicsSceneName = EngineType + "/" + scene.RegionInfo.RegionName; - - scene.RegisterModuleInterface(this); - Vector3 extent = new Vector3(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY, scene.RegionInfo.RegionSizeZ); + pscene.RegisterModuleInterface(this); + Vector3 extent = new Vector3(pscene.RegionInfo.RegionSizeX, pscene.RegionInfo.RegionSizeY, pscene.RegionInfo.RegionSizeZ); Initialise(extent); InitialiseFromConfig(m_config); // This may not be that good since terrain may not be avaiable at this point - base.Initialise(scene.PhysicsRequestAsset, - (scene.Heightmap != null ? scene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]), - (float)scene.RegionInfo.RegionSettings.WaterHeight); + base.Initialise(pscene.PhysicsRequestAsset, + (pscene.Heightmap != null ? pscene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]), + (float)pscene.RegionInfo.RegionSettings.WaterHeight); } - public void RemoveRegion(Scene scene) + public void RegionLoaded() { - if (!m_Enabled) - return; - } - - public void RegionLoaded(Scene scene) - { - if (!m_Enabled) - return; - - mesher = scene.RequestModuleInterface(); + mesher = m_frameWorkScene.RequestModuleInterface(); if (mesher == null) m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName); + + m_frameWorkScene.PhysicsEnabled = true; } - #endregion /// /// Initiailizes the scene diff --git a/OpenSim/Region/PhysicsModules/Ode/Tests/ODETestClass.cs b/OpenSim/Region/PhysicsModules/Ode/Tests/ODETestClass.cs index 483e044..2c134e7 100644 --- a/OpenSim/Region/PhysicsModules/Ode/Tests/ODETestClass.cs +++ b/OpenSim/Region/PhysicsModules/Ode/Tests/ODETestClass.cs @@ -47,6 +47,8 @@ namespace OpenSim.Region.PhysicsModule.ODE.Tests //private OpenSim.Region.PhysicsModule.ODE.OdePlugin cbt; private PhysicsScene pScene; + private OpenSim.Region.PhysicsModule.ODE.OdeModule odemodule; + [SetUp] public void Initialize() @@ -71,13 +73,12 @@ namespace OpenSim.Region.PhysicsModule.ODE.Tests //mod.AddRegion(scene); //mod.RegionLoaded(scene); - pScene = new OdeScene(); - Console.WriteLine("HERE " + (pScene == null ? "Null" : "Not null")); - INonSharedRegionModule mod = (pScene as INonSharedRegionModule); - Console.WriteLine("HERE " + (mod == null ? "Null" : "Not null")); - mod.Initialise(openSimINI); - mod.AddRegion(scene); - mod.RegionLoaded(scene); + // pScene = new OdeScene(); + odemodule = new OpenSim.Region.PhysicsModule.ODE.OdeModule(); + Console.WriteLine("HERE " + (odemodule == null ? "Null" : "Not null")); + odemodule.Initialise(openSimINI); + odemodule.AddRegion(scene); + odemodule.RegionLoaded(scene); // Loading ODEPlugin //cbt = new OdePlugin(); @@ -90,6 +91,7 @@ namespace OpenSim.Region.PhysicsModule.ODE.Tests { _heightmap[i] = 21f; } + pScene = scene.PhysicsScene; pScene.SetTerrain(_heightmap); } -- cgit v1.1