From 8e15d4ad57de6f2a0c900968ef778fba7cdced63 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 8 Sep 2014 23:58:49 +0100 Subject: [PATCH] limit number of prims on physical objects. Not all cases covered still --- .../Framework/Scenes/Scene.Inventory.cs | 5 ++ OpenSim/Region/Framework/Scenes/Scene.cs | 9 ++++ OpenSim/Region/Framework/Scenes/SceneGraph.cs | 10 +++- .../Framework/Scenes/SceneObjectGroup.cs | 46 ++++++++++++++++++- .../Shared/Api/Implementation/LSL_Api.cs | 11 +++++ 5 files changed, 78 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 8634a3a139..e003a59f6a 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -2705,12 +2705,17 @@ namespace OpenSim.Region.Framework.Scenes return; } + bool oldUsePhysics = (root.Flags & PrimFlags.Physics) != 0; m_sceneGraph.LinkObjects(root, children); ScenePresence sp; if (TryGetScenePresence(agentId, out sp)) { root.SendPropertiesToClient(sp.ControllingClient); + if (oldUsePhysics && (root.Flags & PrimFlags.Physics) == 0) + { + sp.ControllingClient.SendAlertMessage("Object physics canceled"); + } } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index aa81000cef..323b5889ba 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -204,6 +204,12 @@ namespace OpenSim.Region.Framework.Scenes /// public int m_linksetCapacity = 0; + /// + /// Max prims an Physical object will hold + /// + /// + public int m_linksetPhysCapacity = 5; + public bool m_clampPrimSize; public bool m_trustBinaries; public bool m_allowScriptCrossings; @@ -901,6 +907,9 @@ namespace OpenSim.Region.Framework.Scenes m_linksetCapacity = RegionInfo.LinksetCapacity; } + m_linksetPhysCapacity = startupConfig.GetInt("LinksetPhysPrims", m_linksetPhysCapacity); + + SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest"); TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false); diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index b0f8991c1f..973891bc5c 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -1547,6 +1547,7 @@ namespace OpenSim.Region.Framework.Scenes // VolumeDetect can't be set via UI and will always be off when a change is made there // now only change volume dtc if phantom off + bool wantedPhys = UsePhysics; if (PhysData.PhysShapeType == PhysShapeType.invalid) // check for extraPhysics data { bool vdtc; @@ -1563,10 +1564,17 @@ namespace OpenSim.Region.Framework.Scenes if (part != null) { part.UpdateExtraPhysics(PhysData); - if (part.UpdatePhysRequired) + if (part.UpdatePhysRequired && remoteClient != null) remoteClient.SendPartPhysicsProprieties(part); } } + + if (wantedPhys != group.UsesPhysics && remoteClient != null) + { + remoteClient.SendAlertMessage("Object physics canceled because exceeds the limit of " + + m_parentScene.m_linksetPhysCapacity + " physical prims with shape type not set to None"); + group.RootPart.ScheduleFullUpdate(); + } } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index d3dd5d71dd..d4a563f200 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1712,7 +1712,9 @@ namespace OpenSim.Region.Framework.Scenes m_rootPart.SetParentLocalId(0); AttachmentPoint = (byte)0; // must check if buildind should be true or false here - m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false); +// m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false); + ApplyPhysics(); + HasGroupChanged = true; RootPart.Rezzed = DateTime.Now; RootPart.RemFlag(PrimFlags.TemporaryOnRez); @@ -2879,6 +2881,33 @@ namespace OpenSim.Region.Framework.Scenes return; } + // physical prims count limit + // not very eficient :( + + if (UsesPhysics && m_scene.m_linksetPhysCapacity > 0 && (PrimCount + objectGroup.PrimCount) > + m_scene.m_linksetPhysCapacity) + { + int cntr = 0; + foreach (SceneObjectPart part in Parts) + { + if (part.PhysicsShapeType != (byte)PhysicsShapeType.None) + cntr++; + } + foreach (SceneObjectPart part in objectGroup.Parts) + { + if (part.PhysicsShapeType != (byte)PhysicsShapeType.None) + cntr++; + } + + if (cntr > m_scene.m_linksetPhysCapacity) + { + // cancel physics + RootPart.Flags &= ~PrimFlags.Physics; + ApplyPhysics(); + } + } + + // 'linkPart' == the root of the group being linked into this group SceneObjectPart linkPart = objectGroup.m_rootPart; @@ -3477,8 +3506,12 @@ namespace OpenSim.Region.Framework.Scenes { SceneObjectPart[] parts = m_parts.GetArray(); - if (Scene != null) + if (Scene != null && UsePhysics) { + int maxprims = m_scene.m_linksetPhysCapacity; + bool checkShape = (maxprims > 0 && + parts.Length > maxprims); + for (int i = 0; i < parts.Length; i++) { SceneObjectPart part = parts[i]; @@ -3489,6 +3522,15 @@ namespace OpenSim.Region.Framework.Scenes UsePhysics = false; // Reset physics break; } + + if (checkShape && part.PhysicsShapeType != (byte)PhysicsShapeType.None) + { + if (--maxprims < 0) + { + UsePhysics = false; + break; + } + } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index b5691943d6..bb083fa053 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -1400,6 +1400,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api SceneObjectGroup group = m_host.ParentGroup; bool allow = true; + int maxprims = World.m_linksetPhysCapacity; + bool checkShape = (maxprims > 0 && group.PrimCount > maxprims); + foreach (SceneObjectPart part in group.Parts) { if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys) @@ -1407,6 +1410,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api allow = false; break; } + if (checkShape && part.PhysicsShapeType != (byte)PhysicsShapeType.None) + { + if (--maxprims < 0) + { + allow = false; + break; + } + } } if (!allow)