diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 3dc990779a..7a53dedf2c 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -734,8 +734,6 @@ namespace OpenSim clientServer = clientNetworkServers; 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.SetTerrain(scene.Heightmap.GetFloatsSerialised()); scene.PhysicsScene.SetWaterLevel((float) regionInfo.RegionSettings.WaterHeight); @@ -751,10 +749,13 @@ namespace OpenSim protected override Scene CreateScene(RegionInfo regionInfo, ISimulationDataService simDataService, IEstateDataService estateDataService, AgentCircuitManager circuitManager) { + Vector3 regionExtent = new Vector3(regionInfo.RegionSizeX, regionInfo.RegionSizeY, regionInfo.RegionSizeZ); + PhysicsScene physicsScene = GetPhysicsScene(regionInfo.RegionName, regionExtent); + SceneCommunicationService sceneGridService = new SceneCommunicationService(); return new Scene( - regionInfo, circuitManager, sceneGridService, + regionInfo, circuitManager, physicsScene, sceneGridService, simDataService, estateDataService, Config, m_version); } diff --git a/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs b/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs index 69d7e16203..d10c9b427a 100644 --- a/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs +++ b/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs @@ -159,7 +159,7 @@ namespace OpenSim.Region.CoreModules.Framework.Library } RegionInfo regInfo = new RegionInfo(); - Scene m_MockScene = new Scene(regInfo); + Scene m_MockScene = new Scene(regInfo, null); LocalInventoryService invService = new LocalInventoryService(lib); m_MockScene.RegisterModuleInterface(invService); m_MockScene.RegisterModuleInterface(m_Scene.AssetService); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs index 25ae689b7c..aa5f889287 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs @@ -85,7 +85,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests r1.ExternalHostName = "127.0.0.1"; r1.HttpPort = 9001; 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; m_LocalConnector.AddRegion(s); @@ -97,7 +97,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests r2.ExternalHostName = "127.0.0.1"; r2.HttpPort = 9002; 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; m_LocalConnector.AddRegion(s); @@ -109,7 +109,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests r3.ExternalHostName = "127.0.0.1"; r3.HttpPort = 9003; 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; m_LocalConnector.AddRegion(s); @@ -121,7 +121,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests r4.ExternalHostName = "127.0.0.1"; r4.HttpPort = 9004; 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; m_LocalConnector.AddRegion(s); diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 35b9f1ae4e..7b060968ad 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -103,7 +103,29 @@ namespace OpenSim.Region.Framework.Scenes /// /// If false then physical objects are disabled, though collisions will continue as normal. /// - 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; /// /// If false then scripts are not enabled on the smiulator @@ -712,11 +734,11 @@ namespace OpenSim.Region.Framework.Scenes #region Constructors - public Scene(RegionInfo regInfo, AgentCircuitManager authen, + public Scene(RegionInfo regInfo, AgentCircuitManager authen, PhysicsScene physicsScene, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, IConfigSource config, string simulatorVersion) - : this(regInfo) + : this(regInfo, physicsScene) { m_config = config; MinFrameTime = 0.089f; @@ -789,21 +811,6 @@ namespace OpenSim.Region.Framework.Scenes EventManager.OnLandObjectRemoved += 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(); // 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; } - 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; CollidablePrims = true; PhysicsEnabled = true; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 8b4df05f3e..867d6ff903 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -54,6 +54,14 @@ public static class BSParam // =================== // From: + /// + /// Set whether physics is active or not. + /// + /// + /// Can be enabled and disabled to start and stop physics. + /// + public static bool Active { get; private set; } + public static bool UseSeparatePhysicsThread { get; private set; } public static float PhysicsTimeStep { get; private set; } @@ -373,6 +381,8 @@ public static class BSParam // v = value (appropriate type) private static ParameterDefnBase[] ParameterDefinitions = { + new ParameterDefn("Active", "If 'true', false then physics is not active", + false ), new ParameterDefn("UseSeparatePhysicsThread", "If 'true', the physics engine runs independent from the simulator heartbeat", false ), new ParameterDefn("PhysicsTimeStep", "If separate thread, seconds to simulate each interval", diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 17d26a98c2..e5173894ec 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -821,7 +821,10 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters while (m_initialized) { int beginSimulationRealtimeMS = Util.EnvironmentTickCount(); - DoPhysicsStep(BSParam.PhysicsTimeStep); + + if (BSParam.Active) + DoPhysicsStep(BSParam.PhysicsTimeStep); + int simulationRealtimeMS = Util.EnvironmentTickCountSubtract(beginSimulationRealtimeMS); int simulationTimeVsRealtimeDifferenceMS = ((int)(BSParam.PhysicsTimeStep*1000f)) - simulationRealtimeMS; diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs index 342cd06004..ae2be7005f 100644 --- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs @@ -151,8 +151,15 @@ namespace OpenSim.Tests.Common 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( - regInfo, m_acm, scs, SimDataService, m_estateDataService, configSource, null); + regInfo, m_acm, physicsScene, scs, SimDataService, m_estateDataService, configSource, null); INonSharedRegionModule godsModule = new GodsModule(); godsModule.Initialise(new IniConfigSource()); @@ -195,13 +202,7 @@ namespace OpenSim.Tests.Common testScene.SetModuleInterfaces(); testScene.LandChannel = new TestLandChannel(testScene); - 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.LoadWorldMap(); testScene.RegionInfo.EstateSettings = new EstateSettings(); testScene.LoginsEnabled = true; diff --git a/OpenSim/Tests/Common/Mock/TestScene.cs b/OpenSim/Tests/Common/Mock/TestScene.cs index 27736248a4..40e2adcb95 100644 --- a/OpenSim/Tests/Common/Mock/TestScene.cs +++ b/OpenSim/Tests/Common/Mock/TestScene.cs @@ -33,6 +33,7 @@ using OpenSim.Framework.Servers; using OpenSim.Region.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Physics.Manager; using OpenSim.Services.Interfaces; namespace OpenSim.Tests.Common.Mock @@ -40,10 +41,10 @@ namespace OpenSim.Tests.Common.Mock public class TestScene : Scene { public TestScene( - RegionInfo regInfo, AgentCircuitManager authen, + RegionInfo regInfo, AgentCircuitManager authen, PhysicsScene physicsScene, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, IConfigSource config, string simulatorVersion) - : base(regInfo, authen, sceneGridService, simDataService, estateDataService, + : base(regInfo, authen, physicsScene, sceneGridService, simDataService, estateDataService, config, simulatorVersion) { }