From ae8e089b9c73a6a675038759e3e3f9491819eb72 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 16 Mar 2012 15:33:49 +0000 Subject: some more work on costs --- .../Region/Framework/Scenes/SceneObjectGroup.cs | 96 ++++++++++++++++++++++ OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 62 ++++++++++++++ 2 files changed, 158 insertions(+) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 5507aa0..3e4d552 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1231,6 +1231,102 @@ namespace OpenSim.Region.Framework.Scenes #endregion + public void GetResourcesCosts(SceneObjectPart apart, + out float linksetResCost, out float linksetPhysCost, out float partCost, out float partPhysCost) + { + // this information may need to be cached + + float cost; + float tmpcost; + + bool ComplexCost = false; + + SceneObjectPart p; + SceneObjectPart[] parts; + + lock (m_parts) + { + parts = m_parts.GetArray(); + } + + int nparts = parts.Length; + + + for (int i = 0; i < nparts; i++) + { + p = parts[i]; + + if (p.UsesComplexCost) + { + ComplexCost = true; + break; + } + } + + if (ComplexCost) + { + linksetResCost = 0; + linksetPhysCost = 0; + partCost = 0; + partPhysCost = 0; + + for (int i = 0; i < nparts; i++) + { + p = parts[i]; + + cost = p.StreamingCost; + tmpcost = p.SimulationCost; + if (tmpcost > cost) + cost = tmpcost; + tmpcost = p.PhysicsCost; + if (tmpcost > cost) + cost = tmpcost; + + linksetPhysCost += tmpcost; + linksetResCost += cost; + + if (p == apart) + { + partCost = cost; + partPhysCost = tmpcost; + } + } + } + else + { + partPhysCost = 1.0f; + partCost = 1.0f; + linksetResCost = (float)nparts; + linksetPhysCost = linksetResCost; + } + } + + public void GetSelectedCosts(out float PhysCost, out float StreamCost, out float SimulCost) + { + SceneObjectPart p; + SceneObjectPart[] parts; + + lock (m_parts) + { + parts = m_parts.GetArray(); + } + + int nparts = parts.Length; + + PhysCost = 0; + StreamCost = 0; + SimulCost = 0; + + for (int i = 0; i < nparts; i++) + { + p = parts[i]; + + StreamCost += p.StreamingCost; + SimulCost += p.SimulationCost; + PhysCost += p.PhysicsCost; + } + } + public void SaveScriptedState(XmlTextWriter writer) { SaveScriptedState(writer, false); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index f188e8d..fbe959a 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1416,6 +1416,14 @@ namespace OpenSim.Region.Framework.Scenes } // not a propriety to move to methods place later + private bool HasMesh() + { + if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh)) + return true; + return false; + } + + // not a propriety to move to methods place later public byte DefaultPhysicsShapeType() { byte type; @@ -1428,6 +1436,60 @@ namespace OpenSim.Region.Framework.Scenes return type; } + [XmlIgnore] + public bool UsesComplexCost + { + get + { + byte pst = PhysicsShapeType; + if(pst == (byte) PhysShapeType.none || pst == (byte) PhysShapeType.convex || HasMesh()) + return true; + return false; + } + } + + [XmlIgnore] + public float PhysicsCost + { + get + { + if(PhysicsShapeType == (byte)PhysShapeType.none) + return 0; + + float cost = 0.1f; + if (PhysActor != null) +// cost += PhysActor.Cost; + + if ((Flags & PrimFlags.Physics) != 0) + cost *= (1.0f + 0.01333f * Scale.LengthSquared()); // 0.01333 == 0.04/3 + return cost; + } + } + + [XmlIgnore] + public float StreamingCost + { + get + { + + + return 0.1f; + } + } + + [XmlIgnore] + public float SimulationCost + { + get + { + // ignoring scripts. Don't like considering them for this + if((Flags & PrimFlags.Physics) != 0) + return 1.0f; + + return 0.5f; + } + } + public byte PhysicsShapeType { get { return m_physicsShapeType; } -- cgit v1.1