let old ode also have a Module class

avinationmerge
UbitUmarov 2015-09-09 18:53:24 +01:00
parent e1a8125b4f
commit 47aa8107fd
3 changed files with 113 additions and 80 deletions

View File

@ -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
}
}

View File

@ -111,11 +111,9 @@ namespace OpenSim.Region.PhysicsModule.ODE
Rubber = 6 Rubber = 6
} }
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")] public class OdeScene : PhysicsScene
public class OdeScene : PhysicsScene, INonSharedRegionModule
{ {
private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString()); private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString());
private bool m_Enabled = false;
// private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
@ -535,88 +533,36 @@ namespace OpenSim.Region.PhysicsModule.ODE
private ODERayCastRequestManager m_rayCastManager; private ODERayCastRequestManager m_rayCastManager;
public Scene m_frameWorkScene = null;
#region INonSharedRegionModule public OdeScene(Scene pscene, IConfigSource psourceconfig, string pname)
public string Name {
{ m_config = psourceconfig;
get { return "OpenDynamicsEngine"; } m_frameWorkScene = pscene;
}
public Type ReplaceableInterface EngineType = pname;
{ PhysicsSceneName = EngineType + "/" + pscene.RegionInfo.RegionName;
get { return null; }
}
public void Initialise(IConfigSource source) pscene.RegisterModuleInterface<PhysicsScene>(this);
{ Vector3 extent = new Vector3(pscene.RegionInfo.RegionSizeX, pscene.RegionInfo.RegionSizeY, pscene.RegionInfo.RegionSizeZ);
// 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<PhysicsScene>(this);
Vector3 extent = new Vector3(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY, scene.RegionInfo.RegionSizeZ);
Initialise(extent); Initialise(extent);
InitialiseFromConfig(m_config); InitialiseFromConfig(m_config);
// This may not be that good since terrain may not be avaiable at this point // This may not be that good since terrain may not be avaiable at this point
base.Initialise(scene.PhysicsRequestAsset, base.Initialise(pscene.PhysicsRequestAsset,
(scene.Heightmap != null ? scene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]), (pscene.Heightmap != null ? pscene.Heightmap.GetFloatsSerialised() : new float[(int)(extent.X * extent.Y)]),
(float)scene.RegionInfo.RegionSettings.WaterHeight); (float)pscene.RegionInfo.RegionSettings.WaterHeight);
} }
public void RemoveRegion(Scene scene) public void RegionLoaded()
{ {
if (!m_Enabled) mesher = m_frameWorkScene.RequestModuleInterface<IMesher>();
return;
}
public void RegionLoaded(Scene scene)
{
if (!m_Enabled)
return;
mesher = scene.RequestModuleInterface<IMesher>();
if (mesher == null) if (mesher == null)
m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName); m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName);
m_frameWorkScene.PhysicsEnabled = true;
} }
#endregion
/// <summary> /// <summary>
/// Initiailizes the scene /// Initiailizes the scene

View File

@ -47,6 +47,8 @@ namespace OpenSim.Region.PhysicsModule.ODE.Tests
//private OpenSim.Region.PhysicsModule.ODE.OdePlugin cbt; //private OpenSim.Region.PhysicsModule.ODE.OdePlugin cbt;
private PhysicsScene pScene; private PhysicsScene pScene;
private OpenSim.Region.PhysicsModule.ODE.OdeModule odemodule;
[SetUp] [SetUp]
public void Initialize() public void Initialize()
@ -71,13 +73,12 @@ namespace OpenSim.Region.PhysicsModule.ODE.Tests
//mod.AddRegion(scene); //mod.AddRegion(scene);
//mod.RegionLoaded(scene); //mod.RegionLoaded(scene);
pScene = new OdeScene(); // pScene = new OdeScene();
Console.WriteLine("HERE " + (pScene == null ? "Null" : "Not null")); odemodule = new OpenSim.Region.PhysicsModule.ODE.OdeModule();
INonSharedRegionModule mod = (pScene as INonSharedRegionModule); Console.WriteLine("HERE " + (odemodule == null ? "Null" : "Not null"));
Console.WriteLine("HERE " + (mod == null ? "Null" : "Not null")); odemodule.Initialise(openSimINI);
mod.Initialise(openSimINI); odemodule.AddRegion(scene);
mod.AddRegion(scene); odemodule.RegionLoaded(scene);
mod.RegionLoaded(scene);
// Loading ODEPlugin // Loading ODEPlugin
//cbt = new OdePlugin(); //cbt = new OdePlugin();
@ -90,6 +91,7 @@ namespace OpenSim.Region.PhysicsModule.ODE.Tests
{ {
_heightmap[i] = 21f; _heightmap[i] = 21f;
} }
pScene = scene.PhysicsScene;
pScene.SetTerrain(_heightmap); pScene.SetTerrain(_heightmap);
} }