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
}
[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<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
@ -535,88 +533,36 @@ namespace OpenSim.Region.PhysicsModule.ODE
private ODERayCastRequestManager m_rayCastManager;
public Scene m_frameWorkScene = null;
#region INonSharedRegionModule
public string Name
public OdeScene(Scene pscene, IConfigSource psourceconfig, string pname)
{
get { return "OpenDynamicsEngine"; }
}
m_config = psourceconfig;
m_frameWorkScene = pscene;
public Type ReplaceableInterface
{
get { return null; }
}
EngineType = pname;
PhysicsSceneName = EngineType + "/" + pscene.RegionInfo.RegionName;
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<PhysicsScene>(this);
Vector3 extent = new Vector3(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY, scene.RegionInfo.RegionSizeZ);
pscene.RegisterModuleInterface<PhysicsScene>(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<IMesher>();
mesher = m_frameWorkScene.RequestModuleInterface<IMesher>();
if (mesher == null)
m_log.WarnFormat("[ODE SCENE]: No mesher in {0}. Things will not work well.", PhysicsSceneName);
m_frameWorkScene.PhysicsEnabled = true;
}
#endregion
/// <summary>
/// Initiailizes the scene

View File

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