Allow the "debug scene set physics false|true" command to work when bulletsim physics is running in a separate thread.

This will also allow the "disable physics" setting in the region debug viewer dialog to work in this circumstance.
bullet-2.82
Justin Clark-Casey (justincc) 2014-07-29 01:21:15 +01:00
parent df816b38ac
commit 3654ae8d8c
8 changed files with 78 additions and 39 deletions

View File

@ -730,8 +730,6 @@ namespace OpenSim
clientServer = clientNetworkServers; clientServer = clientNetworkServers;
scene.LoadWorldMap(); scene.LoadWorldMap();
Vector3 regionExtent = new Vector3(regionInfo.RegionSizeX, regionInfo.RegionSizeY, regionInfo.RegionSizeZ);
scene.PhysicsScene = GetPhysicsScene(scene.RegionInfo.RegionName, regionExtent);
scene.PhysicsScene.RequestAssetMethod = scene.PhysicsRequestAsset; scene.PhysicsScene.RequestAssetMethod = scene.PhysicsRequestAsset;
scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
scene.PhysicsScene.SetWaterLevel((float) regionInfo.RegionSettings.WaterHeight); scene.PhysicsScene.SetWaterLevel((float) regionInfo.RegionSettings.WaterHeight);
@ -747,10 +745,13 @@ namespace OpenSim
protected override Scene CreateScene(RegionInfo regionInfo, ISimulationDataService simDataService, protected override Scene CreateScene(RegionInfo regionInfo, ISimulationDataService simDataService,
IEstateDataService estateDataService, AgentCircuitManager circuitManager) IEstateDataService estateDataService, AgentCircuitManager circuitManager)
{ {
Vector3 regionExtent = new Vector3(regionInfo.RegionSizeX, regionInfo.RegionSizeY, regionInfo.RegionSizeZ);
PhysicsScene physicsScene = GetPhysicsScene(regionInfo.RegionName, regionExtent);
SceneCommunicationService sceneGridService = new SceneCommunicationService(); SceneCommunicationService sceneGridService = new SceneCommunicationService();
return new Scene( return new Scene(
regionInfo, circuitManager, sceneGridService, regionInfo, circuitManager, physicsScene, sceneGridService,
simDataService, estateDataService, simDataService, estateDataService,
Config, m_version); Config, m_version);
} }

View File

@ -159,7 +159,7 @@ namespace OpenSim.Region.CoreModules.Framework.Library
} }
RegionInfo regInfo = new RegionInfo(); RegionInfo regInfo = new RegionInfo();
Scene m_MockScene = new Scene(regInfo); Scene m_MockScene = new Scene(regInfo, null);
LocalInventoryService invService = new LocalInventoryService(lib); LocalInventoryService invService = new LocalInventoryService(lib);
m_MockScene.RegisterModuleInterface<IInventoryService>(invService); m_MockScene.RegisterModuleInterface<IInventoryService>(invService);
m_MockScene.RegisterModuleInterface<IAssetService>(m_Scene.AssetService); m_MockScene.RegisterModuleInterface<IAssetService>(m_Scene.AssetService);

View File

@ -85,7 +85,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
r1.ExternalHostName = "127.0.0.1"; r1.ExternalHostName = "127.0.0.1";
r1.HttpPort = 9001; r1.HttpPort = 9001;
r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
Scene s = new Scene(new RegionInfo()); Scene s = new Scene(new RegionInfo(), null);
s.RegionInfo.RegionID = r1.RegionID; s.RegionInfo.RegionID = r1.RegionID;
m_LocalConnector.AddRegion(s); m_LocalConnector.AddRegion(s);
@ -97,7 +97,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
r2.ExternalHostName = "127.0.0.1"; r2.ExternalHostName = "127.0.0.1";
r2.HttpPort = 9002; r2.HttpPort = 9002;
r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
s = new Scene(new RegionInfo()); s = new Scene(new RegionInfo(), null);
s.RegionInfo.RegionID = r2.RegionID; s.RegionInfo.RegionID = r2.RegionID;
m_LocalConnector.AddRegion(s); m_LocalConnector.AddRegion(s);
@ -109,7 +109,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
r3.ExternalHostName = "127.0.0.1"; r3.ExternalHostName = "127.0.0.1";
r3.HttpPort = 9003; r3.HttpPort = 9003;
r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
s = new Scene(new RegionInfo()); s = new Scene(new RegionInfo(), null);
s.RegionInfo.RegionID = r3.RegionID; s.RegionInfo.RegionID = r3.RegionID;
m_LocalConnector.AddRegion(s); m_LocalConnector.AddRegion(s);
@ -121,7 +121,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
r4.ExternalHostName = "127.0.0.1"; r4.ExternalHostName = "127.0.0.1";
r4.HttpPort = 9004; r4.HttpPort = 9004;
r4.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); r4.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
s = new Scene(new RegionInfo()); s = new Scene(new RegionInfo(), null);
s.RegionInfo.RegionID = r4.RegionID; s.RegionInfo.RegionID = r4.RegionID;
m_LocalConnector.AddRegion(s); m_LocalConnector.AddRegion(s);

View File

@ -103,7 +103,29 @@ namespace OpenSim.Region.Framework.Scenes
/// <summary> /// <summary>
/// If false then physical objects are disabled, though collisions will continue as normal. /// If false then physical objects are disabled, though collisions will continue as normal.
/// </summary> /// </summary>
public bool PhysicsEnabled { get; set; } public bool PhysicsEnabled
{
get
{
return m_physicsEnabled;
}
set
{
m_physicsEnabled = value;
if (PhysicsScene != null)
{
IPhysicsParameters physScene = PhysicsScene as IPhysicsParameters;
if (physScene != null)
physScene.SetPhysicsParameter(
"Active", m_physicsEnabled.ToString(), PhysParameterEntry.APPLY_TO_NONE);
}
}
}
private bool m_physicsEnabled;
/// <summary> /// <summary>
/// If false then scripts are not enabled on the smiulator /// If false then scripts are not enabled on the smiulator
@ -712,11 +734,11 @@ namespace OpenSim.Region.Framework.Scenes
#region Constructors #region Constructors
public Scene(RegionInfo regInfo, AgentCircuitManager authen, public Scene(RegionInfo regInfo, AgentCircuitManager authen, PhysicsScene physicsScene,
SceneCommunicationService sceneGridService, SceneCommunicationService sceneGridService,
ISimulationDataService simDataService, IEstateDataService estateDataService, ISimulationDataService simDataService, IEstateDataService estateDataService,
IConfigSource config, string simulatorVersion) IConfigSource config, string simulatorVersion)
: this(regInfo) : this(regInfo, physicsScene)
{ {
m_config = config; m_config = config;
MinFrameTime = 0.089f; MinFrameTime = 0.089f;
@ -789,21 +811,6 @@ namespace OpenSim.Region.Framework.Scenes
EventManager.OnLandObjectRemoved += EventManager.OnLandObjectRemoved +=
new EventManager.LandObjectRemoved(simDataService.RemoveLandObject); new EventManager.LandObjectRemoved(simDataService.RemoveLandObject);
m_sceneGraph = new SceneGraph(this);
// If the scene graph has an Unrecoverable error, restart this sim.
// Currently the only thing that causes it to happen is two kinds of specific
// Physics based crashes.
//
// Out of memory
// Operating system has killed the plugin
m_sceneGraph.UnRecoverableError
+= () =>
{
m_log.ErrorFormat("[SCENE]: Restarting region {0} due to unrecoverable physics crash", Name);
RestartNow();
};
RegisterDefaultSceneEvents(); RegisterDefaultSceneEvents();
// XXX: Don't set the public property since we don't want to activate here. This needs to be handled // XXX: Don't set the public property since we don't want to activate here. This needs to be handled
@ -1014,8 +1021,24 @@ namespace OpenSim.Region.Framework.Scenes
StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
} }
public Scene(RegionInfo regInfo) : base(regInfo) public Scene(RegionInfo regInfo, PhysicsScene physicsScene) : base(regInfo)
{ {
m_sceneGraph = new SceneGraph(this);
m_sceneGraph.PhysicsScene = physicsScene;
// If the scene graph has an Unrecoverable error, restart this sim.
// Currently the only thing that causes it to happen is two kinds of specific
// Physics based crashes.
//
// Out of memory
// Operating system has killed the plugin
m_sceneGraph.UnRecoverableError
+= () =>
{
m_log.ErrorFormat("[SCENE]: Restarting region {0} due to unrecoverable physics crash", Name);
RestartNow();
};
PhysicalPrims = true; PhysicalPrims = true;
CollidablePrims = true; CollidablePrims = true;
PhysicsEnabled = true; PhysicsEnabled = true;

View File

@ -54,6 +54,14 @@ public static class BSParam
// =================== // ===================
// From: // From:
/// <summary>
/// Set whether physics is active or not.
/// </summary>
/// <remarks>
/// Can be enabled and disabled to start and stop physics.
/// </remarks>
public static bool Active { get; private set; }
public static bool UseSeparatePhysicsThread { get; private set; } public static bool UseSeparatePhysicsThread { get; private set; }
public static float PhysicsTimeStep { get; private set; } public static float PhysicsTimeStep { get; private set; }
@ -373,6 +381,8 @@ public static class BSParam
// v = value (appropriate type) // v = value (appropriate type)
private static ParameterDefnBase[] ParameterDefinitions = private static ParameterDefnBase[] ParameterDefinitions =
{ {
new ParameterDefn<bool>("Active", "If 'true', false then physics is not active",
false ),
new ParameterDefn<bool>("UseSeparatePhysicsThread", "If 'true', the physics engine runs independent from the simulator heartbeat", new ParameterDefn<bool>("UseSeparatePhysicsThread", "If 'true', the physics engine runs independent from the simulator heartbeat",
false ), false ),
new ParameterDefn<float>("PhysicsTimeStep", "If separate thread, seconds to simulate each interval", new ParameterDefn<float>("PhysicsTimeStep", "If separate thread, seconds to simulate each interval",

View File

@ -821,7 +821,10 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
while (m_initialized) while (m_initialized)
{ {
int beginSimulationRealtimeMS = Util.EnvironmentTickCount(); int beginSimulationRealtimeMS = Util.EnvironmentTickCount();
if (BSParam.Active)
DoPhysicsStep(BSParam.PhysicsTimeStep); DoPhysicsStep(BSParam.PhysicsTimeStep);
int simulationRealtimeMS = Util.EnvironmentTickCountSubtract(beginSimulationRealtimeMS); int simulationRealtimeMS = Util.EnvironmentTickCountSubtract(beginSimulationRealtimeMS);
int simulationTimeVsRealtimeDifferenceMS = ((int)(BSParam.PhysicsTimeStep*1000f)) - simulationRealtimeMS; int simulationTimeVsRealtimeDifferenceMS = ((int)(BSParam.PhysicsTimeStep*1000f)) - simulationRealtimeMS;

View File

@ -151,8 +151,15 @@ namespace OpenSim.Tests.Common
SceneCommunicationService scs = new SceneCommunicationService(); SceneCommunicationService scs = new SceneCommunicationService();
PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
Vector3 regionExtent = new Vector3( regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ);
PhysicsScene physicsScene
= physicsPluginManager.GetPhysicsScene(
"basicphysics", "ZeroMesher", new IniConfigSource(), "test", regionExtent);
TestScene testScene = new TestScene( TestScene testScene = new TestScene(
regInfo, m_acm, scs, SimDataService, m_estateDataService, configSource, null); regInfo, m_acm, physicsScene, scs, SimDataService, m_estateDataService, configSource, null);
INonSharedRegionModule godsModule = new GodsModule(); INonSharedRegionModule godsModule = new GodsModule();
godsModule.Initialise(new IniConfigSource()); godsModule.Initialise(new IniConfigSource());
@ -197,12 +204,6 @@ namespace OpenSim.Tests.Common
testScene.LandChannel = new TestLandChannel(testScene); testScene.LandChannel = new TestLandChannel(testScene);
testScene.LoadWorldMap(); testScene.LoadWorldMap();
PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
Vector3 regionExtent = new Vector3( regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ);
testScene.PhysicsScene
= physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test", regionExtent);
testScene.RegionInfo.EstateSettings = new EstateSettings(); testScene.RegionInfo.EstateSettings = new EstateSettings();
testScene.LoginsEnabled = true; testScene.LoginsEnabled = true;
testScene.RegisterRegionWithGrid(); testScene.RegisterRegionWithGrid();

View File

@ -33,6 +33,7 @@ using OpenSim.Framework.Servers;
using OpenSim.Region.Framework; using OpenSim.Region.Framework;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Physics.Manager;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
namespace OpenSim.Tests.Common.Mock namespace OpenSim.Tests.Common.Mock
@ -40,10 +41,10 @@ namespace OpenSim.Tests.Common.Mock
public class TestScene : Scene public class TestScene : Scene
{ {
public TestScene( public TestScene(
RegionInfo regInfo, AgentCircuitManager authen, RegionInfo regInfo, AgentCircuitManager authen, PhysicsScene physicsScene,
SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService,
IConfigSource config, string simulatorVersion) IConfigSource config, string simulatorVersion)
: base(regInfo, authen, sceneGridService, simDataService, estateDataService, : base(regInfo, authen, physicsScene, sceneGridService, simDataService, estateDataService,
config, simulatorVersion) config, simulatorVersion)
{ {
} }