From 5d3723a47f7ddb32964055561ecf2a601f6b19f2 Mon Sep 17 00:00:00 2001 From: dahlia Date: Fri, 13 Jul 2012 21:22:15 -0700 Subject: [PATCH 1/9] update PrimMesher.cs to dll version r72 which fixes some path errors in sliced linear prims. Addresses Mantis #6085 --- OpenSim/Region/Physics/Meshing/PrimMesher.cs | 326 +++++++++++-------- 1 file changed, 183 insertions(+), 143 deletions(-) diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs index 53022ad6b4..4049ee1598 100644 --- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs +++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs @@ -236,6 +236,13 @@ namespace PrimMesher this.U = u; this.V = v; } + + public UVCoord Flip() + { + this.U = 1.0f - this.U; + this.V = 1.0f - this.V; + return this; + } } public struct Face @@ -603,40 +610,40 @@ namespace PrimMesher /// /// generates a profile for extrusion /// - internal class Profile + public class Profile { private const float twoPi = 2.0f * (float)Math.PI; - internal string errorMessage = null; + public string errorMessage = null; - internal List coords; - internal List faces; - internal List vertexNormals; - internal List us; - internal List faceUVs; - internal List faceNumbers; + public List coords; + public List faces; + public List vertexNormals; + public List us; + public List faceUVs; + public List faceNumbers; // use these for making individual meshes for each prim face - internal List outerCoordIndices = null; - internal List hollowCoordIndices = null; - internal List cut1CoordIndices = null; - internal List cut2CoordIndices = null; + public List outerCoordIndices = null; + public List hollowCoordIndices = null; + public List cut1CoordIndices = null; + public List cut2CoordIndices = null; - internal Coord faceNormal = new Coord(0.0f, 0.0f, 1.0f); - internal Coord cutNormal1 = new Coord(); - internal Coord cutNormal2 = new Coord(); + public Coord faceNormal = new Coord(0.0f, 0.0f, 1.0f); + public Coord cutNormal1 = new Coord(); + public Coord cutNormal2 = new Coord(); - internal int numOuterVerts = 0; - internal int numHollowVerts = 0; + public int numOuterVerts = 0; + public int numHollowVerts = 0; - internal int outerFaceNumber = -1; - internal int hollowFaceNumber = -1; + public int outerFaceNumber = -1; + public int hollowFaceNumber = -1; - internal bool calcVertexNormals = false; - internal int bottomFaceNumber = 0; - internal int numPrimFaces = 0; + public bool calcVertexNormals = false; + public int bottomFaceNumber = 0; + public int numPrimFaces = 0; - internal Profile() + public Profile() { this.coords = new List(); this.faces = new List(); @@ -646,7 +653,7 @@ namespace PrimMesher this.faceNumbers = new List(); } - internal Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool createFaces, bool calcVertexNormals) + public Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool createFaces, bool calcVertexNormals) { this.calcVertexNormals = calcVertexNormals; this.coords = new List(); @@ -657,7 +664,6 @@ namespace PrimMesher this.faceNumbers = new List(); Coord center = new Coord(0.0f, 0.0f, 0.0f); - //bool hasCenter = false; List hollowCoords = new List(); List hollowNormals = new List(); @@ -682,8 +688,8 @@ namespace PrimMesher float yScale = 0.5f; if (sides == 4) // corners of a square are sqrt(2) from center { - xScale = 0.707f; - yScale = 0.707f; + xScale = 0.707107f; + yScale = 0.707107f; } float startAngle = profileStart * twoPi; @@ -724,7 +730,6 @@ namespace PrimMesher else if (!simpleFace) { this.coords.Add(center); - //hasCenter = true; if (this.calcVertexNormals) this.vertexNormals.Add(new Coord(0.0f, 0.0f, 1.0f)); this.us.Add(0.0f); @@ -752,7 +757,10 @@ namespace PrimMesher else hollowNormals.Add(new Coord(-angle.X, -angle.Y, 0.0f)); - hollowUs.Add(angle.angle * hollow); + if (hollowSides == 4) + hollowUs.Add(angle.angle * hollow * 0.707107f); + else + hollowUs.Add(angle.angle * hollow); } } } @@ -829,9 +837,6 @@ namespace PrimMesher if (createFaces) { - //int numOuterVerts = this.coords.Count; - //numOuterVerts = this.coords.Count; - //int numHollowVerts = hollowCoords.Count; int numTotalVerts = this.numOuterVerts + this.numHollowVerts; if (this.numOuterVerts == this.numHollowVerts) @@ -993,11 +998,7 @@ namespace PrimMesher if (startVert > 0) this.faceNumbers.Add(-1); for (int i = 0; i < this.numOuterVerts - 1; i++) - //this.faceNumbers.Add(sides < 5 ? faceNum++ : faceNum); - this.faceNumbers.Add(sides < 5 && i < sides ? faceNum++ : faceNum); - - //if (!hasHollow && !hasProfileCut) - // this.bottomFaceNumber = faceNum++; + this.faceNumbers.Add(sides < 5 && i <= sides ? faceNum++ : faceNum); this.faceNumbers.Add(hasProfileCut ? -1 : faceNum++); @@ -1014,8 +1015,7 @@ namespace PrimMesher this.hollowFaceNumber = faceNum++; } - //if (hasProfileCut || hasHollow) - // this.bottomFaceNumber = faceNum++; + this.bottomFaceNumber = faceNum++; if (hasHollow && hasProfileCut) @@ -1030,19 +1030,19 @@ namespace PrimMesher } - internal void MakeFaceUVs() + public void MakeFaceUVs() { this.faceUVs = new List(); foreach (Coord c in this.coords) - this.faceUVs.Add(new UVCoord(0.5f + c.X, 0.5f - c.Y)); + this.faceUVs.Add(new UVCoord(1.0f - (0.5f + c.X), 1.0f - (0.5f - c.Y))); } - internal Profile Copy() + public Profile Copy() { return this.Copy(true); } - internal Profile Copy(bool needFaces) + public Profile Copy(bool needFaces) { Profile copy = new Profile(); @@ -1071,12 +1071,12 @@ namespace PrimMesher return copy; } - internal void AddPos(Coord v) + public void AddPos(Coord v) { this.AddPos(v.X, v.Y, v.Z); } - internal void AddPos(float x, float y, float z) + public void AddPos(float x, float y, float z) { int i; int numVerts = this.coords.Count; @@ -1092,7 +1092,7 @@ namespace PrimMesher } } - internal void AddRot(Quat q) + public void AddRot(Quat q) { int i; int numVerts = this.coords.Count; @@ -1113,7 +1113,7 @@ namespace PrimMesher } } - internal void Scale(float x, float y) + public void Scale(float x, float y) { int i; int numVerts = this.coords.Count; @@ -1131,7 +1131,7 @@ namespace PrimMesher /// /// Changes order of the vertex indices and negates the center vertex normal. Does not alter vertex normals of radial vertices /// - internal void FlipNormals() + public void FlipNormals() { int i; int numFaces = this.faces.Count; @@ -1171,7 +1171,7 @@ namespace PrimMesher } } - internal void AddValue2FaceVertexIndices(int num) + public void AddValue2FaceVertexIndices(int num) { int numFaces = this.faces.Count; Face tmpFace; @@ -1186,7 +1186,7 @@ namespace PrimMesher } } - internal void AddValue2FaceNormalIndices(int num) + public void AddValue2FaceNormalIndices(int num) { if (this.calcVertexNormals) { @@ -1204,7 +1204,7 @@ namespace PrimMesher } } - internal void DumpRaw(String path, String name, String title) + public void DumpRaw(String path, String name, String title) { if (path == null) return; @@ -1261,6 +1261,15 @@ namespace PrimMesher public void Create(PathType pathType, int steps) { + if (this.taperX > 0.999f) + this.taperX = 0.999f; + if (this.taperX < -0.999f) + this.taperX = -0.999f; + if (this.taperY > 0.999f) + this.taperY = 0.999f; + if (this.taperY < -0.999f) + this.taperY = -0.999f; + if (pathType == PathType.Linear || pathType == PathType.Flexible) { int step = 0; @@ -1273,12 +1282,12 @@ namespace PrimMesher float start = -0.5f; float stepSize = length / (float)steps; - float percentOfPathMultiplier = stepSize; - float xOffset = 0.0f; - float yOffset = 0.0f; + float percentOfPathMultiplier = stepSize * 0.999999f; + float xOffset = this.topShearX * this.pathCutBegin; + float yOffset = this.topShearY * this.pathCutBegin; float zOffset = start; - float xOffsetStepIncrement = this.topShearX / steps; - float yOffsetStepIncrement = this.topShearY / steps; + float xOffsetStepIncrement = this.topShearX * length / steps; + float yOffsetStepIncrement = this.topShearY * length / steps; float percentOfPath = this.pathCutBegin; zOffset += percentOfPath; @@ -1573,13 +1582,6 @@ namespace PrimMesher this.hollow = 0.99f; if (hollow < 0.0f) this.hollow = 0.0f; - - //if (sphereMode) - // this.hasProfileCut = this.profileEnd - this.profileStart < 0.4999f; - //else - // //this.hasProfileCut = (this.profileStart > 0.0f || this.profileEnd < 1.0f); - // this.hasProfileCut = this.profileEnd - this.profileStart < 0.9999f; - //this.hasHollow = (this.hollow > 0.001f); } /// @@ -1614,10 +1616,9 @@ namespace PrimMesher steps = (int)(steps * 4.5 * length); } - if (sphereMode) + if (this.sphereMode) this.hasProfileCut = this.profileEnd - this.profileStart < 0.4999f; else - //this.hasProfileCut = (this.profileStart > 0.0f || this.profileEnd < 1.0f); this.hasProfileCut = this.profileEnd - this.profileStart < 0.9999f; this.hasHollow = (this.hollow > 0.001f); @@ -1630,6 +1631,22 @@ namespace PrimMesher float hollow = this.hollow; + if (pathType == PathType.Circular) + { + needEndFaces = false; + if (this.pathCutBegin != 0.0f || this.pathCutEnd != 1.0f) + needEndFaces = true; + else if (this.taperX != 0.0f || this.taperY != 0.0f) + needEndFaces = true; + else if (this.skew != 0.0f) + needEndFaces = true; + else if (twistTotal != 0.0f) + needEndFaces = true; + else if (this.radius != 0.0f) + needEndFaces = true; + } + else needEndFaces = true; + // sanity checks float initialProfileRot = 0.0f; if (pathType == PathType.Circular) @@ -1689,20 +1706,13 @@ namespace PrimMesher this.numPrimFaces = profile.numPrimFaces; - //profileOuterFaceNumber = profile.faceNumbers[0]; - //if (!needEndFaces) - // profileOuterFaceNumber--; - //profileOuterFaceNumber = needEndFaces ? 1 : 0; - - - //if (hasHollow) - //{ - // if (needEndFaces) - // profileHollowFaceNumber = profile.faceNumbers[profile.numOuterVerts + 1]; - // else - // profileHollowFaceNumber = profile.faceNumbers[profile.numOuterVerts] - 1; - //} - + int cut1FaceNumber = profile.bottomFaceNumber + 1; + int cut2FaceNumber = cut1FaceNumber + 1; + if (!needEndFaces) + { + cut1FaceNumber -= 2; + cut2FaceNumber -= 2; + } profileOuterFaceNumber = profile.outerFaceNumber; if (!needEndFaces) @@ -1732,7 +1742,8 @@ namespace PrimMesher Coord lastCutNormal1 = new Coord(); Coord lastCutNormal2 = new Coord(); - float lastV = 1.0f; + float thisV = 0.0f; + float lastV = 0.0f; Path path = new Path(); path.twistBegin = twistBegin; @@ -1754,23 +1765,6 @@ namespace PrimMesher path.Create(pathType, steps); - - if (pathType == PathType.Circular) - { - needEndFaces = false; - if (this.pathCutBegin != 0.0f || this.pathCutEnd != 1.0f) - needEndFaces = true; - else if (this.taperX != 0.0f || this.taperY != 0.0f) - needEndFaces = true; - else if (this.skew != 0.0f) - needEndFaces = true; - else if (twistTotal != 0.0f) - needEndFaces = true; - else if (this.radius != 0.0f) - needEndFaces = true; - } - else needEndFaces = true; - for (int nodeIndex = 0; nodeIndex < path.pathNodes.Count; nodeIndex++) { PathNode node = path.pathNodes[nodeIndex]; @@ -1784,7 +1778,7 @@ namespace PrimMesher { newLayer.FlipNormals(); - // add the top faces to the viewerFaces list here + // add the bottom faces to the viewerFaces list if (this.viewerMode) { Coord faceNormal = newLayer.faceNormal; @@ -1811,6 +1805,13 @@ namespace PrimMesher newViewerFace.uv2 = newLayer.faceUVs[face.v2]; newViewerFace.uv3 = newLayer.faceUVs[face.v3]; + if (pathType == PathType.Linear) + { + newViewerFace.uv1.Flip(); + newViewerFace.uv2.Flip(); + newViewerFace.uv3.Flip(); + } + this.viewerFaces.Add(newViewerFace); } } @@ -1835,7 +1836,10 @@ namespace PrimMesher // fill faces between layers int numVerts = newLayer.coords.Count; - Face newFace = new Face(); + Face newFace1 = new Face(); + Face newFace2 = new Face(); + + thisV = 1.0f - node.percentOfPath; if (nodeIndex > 0) { @@ -1853,14 +1857,23 @@ namespace PrimMesher int whichVert = i - startVert; - newFace.v1 = i; - newFace.v2 = i - numVerts; - newFace.v3 = iNext - numVerts; - this.faces.Add(newFace); + newFace1.v1 = i; + newFace1.v2 = i - numVerts; + newFace1.v3 = iNext; - newFace.v2 = iNext - numVerts; - newFace.v3 = iNext; - this.faces.Add(newFace); + newFace1.n1 = newFace1.v1; + newFace1.n2 = newFace1.v2; + newFace1.n3 = newFace1.v3; + this.faces.Add(newFace1); + + newFace2.v1 = iNext; + newFace2.v2 = i - numVerts; + newFace2.v3 = iNext - numVerts; + + newFace2.n1 = newFace2.v1; + newFace2.n2 = newFace2.v2; + newFace2.n3 = newFace2.v3; + this.faces.Add(newFace2); if (this.viewerMode) { @@ -1873,10 +1886,16 @@ namespace PrimMesher ViewerFace newViewerFace1 = new ViewerFace(primFaceNum); ViewerFace newViewerFace2 = new ViewerFace(primFaceNum); - float u1 = newLayer.us[whichVert]; + int uIndex = whichVert; + if (!hasHollow && sides > 4 && uIndex < newLayer.us.Count - 1) + { + uIndex++; + } + + float u1 = newLayer.us[uIndex]; float u2 = 1.0f; - if (whichVert < newLayer.us.Count - 1) - u2 = newLayer.us[whichVert + 1]; + if (uIndex < (int)newLayer.us.Count - 1) + u2 = newLayer.us[uIndex + 1]; if (whichVert == cut1Vert || whichVert == cut2Vert) { @@ -1894,13 +1913,22 @@ namespace PrimMesher u1 -= (int)u1; if (u2 < 0.1f) u2 = 1.0f; - //this.profileOuterFaceNumber = primFaceNum; } - else if (whichVert > profile.coords.Count - profile.numHollowVerts - 1) + } + + if (this.sphereMode) + { + if (whichVert != cut1Vert && whichVert != cut2Vert) { - u1 *= 2.0f; - u2 *= 2.0f; - //this.profileHollowFaceNumber = primFaceNum; + u1 = u1 * 2.0f - 1.0f; + u2 = u2 * 2.0f - 1.0f; + + if (whichVert >= newLayer.numOuterVerts) + { + u1 -= hollow; + u2 -= hollow; + } + } } @@ -1908,37 +1936,39 @@ namespace PrimMesher newViewerFace1.uv2.U = u1; newViewerFace1.uv3.U = u2; - newViewerFace1.uv1.V = 1.0f - node.percentOfPath; + newViewerFace1.uv1.V = thisV; newViewerFace1.uv2.V = lastV; - newViewerFace1.uv3.V = lastV; + newViewerFace1.uv3.V = thisV; - newViewerFace2.uv1.U = u1; - newViewerFace2.uv2.U = u2; + newViewerFace2.uv1.U = u2; + newViewerFace2.uv2.U = u1; newViewerFace2.uv3.U = u2; - newViewerFace2.uv1.V = 1.0f - node.percentOfPath; + newViewerFace2.uv1.V = thisV; newViewerFace2.uv2.V = lastV; - newViewerFace2.uv3.V = 1.0f - node.percentOfPath; + newViewerFace2.uv3.V = lastV; - newViewerFace1.v1 = this.coords[i]; - newViewerFace1.v2 = this.coords[i - numVerts]; - newViewerFace1.v3 = this.coords[iNext - numVerts]; + newViewerFace1.v1 = this.coords[newFace1.v1]; + newViewerFace1.v2 = this.coords[newFace1.v2]; + newViewerFace1.v3 = this.coords[newFace1.v3]; - newViewerFace2.v1 = this.coords[i]; - newViewerFace2.v2 = this.coords[iNext - numVerts]; - newViewerFace2.v3 = this.coords[iNext]; + newViewerFace2.v1 = this.coords[newFace2.v1]; + newViewerFace2.v2 = this.coords[newFace2.v2]; + newViewerFace2.v3 = this.coords[newFace2.v3]; - newViewerFace1.coordIndex1 = i; - newViewerFace1.coordIndex2 = i - numVerts; - newViewerFace1.coordIndex3 = iNext - numVerts; + newViewerFace1.coordIndex1 = newFace1.v1; + newViewerFace1.coordIndex2 = newFace1.v2; + newViewerFace1.coordIndex3 = newFace1.v3; - newViewerFace2.coordIndex1 = i; - newViewerFace2.coordIndex2 = iNext - numVerts; - newViewerFace2.coordIndex3 = iNext; + newViewerFace2.coordIndex1 = newFace2.v1; + newViewerFace2.coordIndex2 = newFace2.v2; + newViewerFace2.coordIndex3 = newFace2.v3; // profile cut faces if (whichVert == cut1Vert) { + newViewerFace1.primFaceNumber = cut1FaceNumber; + newViewerFace2.primFaceNumber = cut1FaceNumber; newViewerFace1.n1 = newLayer.cutNormal1; newViewerFace1.n2 = newViewerFace1.n3 = lastCutNormal1; @@ -1947,10 +1977,14 @@ namespace PrimMesher } else if (whichVert == cut2Vert) { + newViewerFace1.primFaceNumber = cut2FaceNumber; + newViewerFace2.primFaceNumber = cut2FaceNumber; newViewerFace1.n1 = newLayer.cutNormal2; - newViewerFace1.n2 = newViewerFace1.n3 = lastCutNormal2; + newViewerFace1.n2 = lastCutNormal2; + newViewerFace1.n3 = lastCutNormal2; - newViewerFace2.n1 = newViewerFace2.n3 = newLayer.cutNormal2; + newViewerFace2.n1 = newLayer.cutNormal2; + newViewerFace2.n3 = newLayer.cutNormal2; newViewerFace2.n2 = lastCutNormal2; } @@ -1963,13 +1997,13 @@ namespace PrimMesher } else { - newViewerFace1.n1 = this.normals[i]; - newViewerFace1.n2 = this.normals[i - numVerts]; - newViewerFace1.n3 = this.normals[iNext - numVerts]; + newViewerFace1.n1 = this.normals[newFace1.n1]; + newViewerFace1.n2 = this.normals[newFace1.n2]; + newViewerFace1.n3 = this.normals[newFace1.n3]; - newViewerFace2.n1 = this.normals[i]; - newViewerFace2.n2 = this.normals[iNext - numVerts]; - newViewerFace2.n3 = this.normals[iNext]; + newViewerFace2.n1 = this.normals[newFace2.n1]; + newViewerFace2.n2 = this.normals[newFace2.n2]; + newViewerFace2.n3 = this.normals[newFace2.n3]; } } @@ -1982,14 +2016,13 @@ namespace PrimMesher lastCutNormal1 = newLayer.cutNormal1; lastCutNormal2 = newLayer.cutNormal2; - lastV = 1.0f - node.percentOfPath; + lastV = thisV; if (needEndFaces && nodeIndex == path.pathNodes.Count - 1 && viewerMode) { // add the top faces to the viewerFaces list here Coord faceNormal = newLayer.faceNormal; - ViewerFace newViewerFace = new ViewerFace(); - newViewerFace.primFaceNumber = 0; + ViewerFace newViewerFace = new ViewerFace(0); int numFaces = newLayer.faces.Count; List faces = newLayer.faces; @@ -2012,6 +2045,13 @@ namespace PrimMesher newViewerFace.uv2 = newLayer.faceUVs[face.v2 - coordsLen]; newViewerFace.uv3 = newLayer.faceUVs[face.v3 - coordsLen]; + if (pathType == PathType.Linear) + { + newViewerFace.uv1.Flip(); + newViewerFace.uv2.Flip(); + newViewerFace.uv3.Flip(); + } + this.viewerFaces.Add(newViewerFace); } } From ee7478fa16b95352db22e0eba5c4cb90d47dabd5 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Mon, 16 Jul 2012 14:47:03 +0100 Subject: [PATCH 2/9] sending more user-friendly messages to the script error window rather than the thrown exceptions. Signed-off-by: Melanie --- .../Shared/Api/Implementation/OSSL_Api.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 3654106427..413739776f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -1664,9 +1664,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api CheckThreatLevel(ThreatLevel.Low, "osMessageObject"); m_host.AddScriptLPS(1); + UUID objUUID; + if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead. + { + OSSLShoutError("osMessageObject() cannot send messages to objects with invalid UUIDs"); + return; + } + object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) }; - SceneObjectPart sceneOP = World.GetSceneObjectPart(new UUID(objectUUID)); + SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID); + + if (sceneOP == null) // prior to patching, PostObjectEvent() would cause a throw exception to be shouted instead. + { + OSSLShoutError("osMessageObject() cannot send message to " + objUUID.ToString() + ", object was not found in scene."); + return; + } m_ScriptEngine.PostObjectEvent( sceneOP.LocalId, new EventParams( From ed14dac0a38defa64d36e691b12ba6a2e2b8642d Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Mon, 16 Jul 2012 23:03:23 +0100 Subject: [PATCH 3/9] Stop warning about no session from ViewerStats if user teleports to another region in the same simulator that was not next to the source region. This was because teleporting to the new region invoked the new session setup code before the agent was removed from the old region, which then invoked the session teardown code. Now, we only invoke the teardown code if the region ID occupied by the agent being removed is the same as the one registered for the current session. --- OpenSim/Region/UserStatistics/WebStatsModule.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index faf746fac0..d1a7217e4a 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -57,7 +57,12 @@ namespace OpenSim.Region.UserStatistics LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static SqliteConnection dbConn; + + /// + /// User statistics sessions keyed by agent ID + /// private Dictionary m_sessions = new Dictionary(); + private List m_scenes = new List(); private Dictionary reports = new Dictionary(); private Dictionary m_simstatsCounters = new Dictionary(); @@ -308,7 +313,6 @@ namespace OpenSim.Region.UserStatistics scene.EventManager.OnDeregisterCaps += OnDeRegisterCaps; scene.EventManager.OnClientClosed += OnClientClosed; scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; - scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; } } } @@ -342,15 +346,11 @@ namespace OpenSim.Region.UserStatistics } } - private void OnMakeChildAgent(ScenePresence agent) - { - } - private void OnClientClosed(UUID agentID, Scene scene) { lock (m_sessions) { - if (m_sessions.ContainsKey(agentID)) + if (m_sessions.ContainsKey(agentID) && m_sessions[agentID].region_id == scene.RegionInfo.RegionID) { m_sessions.Remove(agentID); } From 217f47b0d5b2382a93f3947e0840056a3ba1abfd Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Mon, 16 Jul 2012 23:09:48 +0100 Subject: [PATCH 4/9] In WebStatsModule.OnMakeRootAgent(), get region ID directly from SP.Scene.RegionInfo.RegionID instead of manually looking it up from the stored scene list. --- .../Region/UserStatistics/WebStatsModule.cs | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index d1a7217e4a..ed424abadf 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -319,8 +319,6 @@ namespace OpenSim.Region.UserStatistics private void OnMakeRootAgent(ScenePresence agent) { - UUID regionUUID = GetRegionUUIDFromHandle(agent.RegionHandle); - lock (m_sessions) { if (!m_sessions.ContainsKey(agent.UUID)) @@ -330,7 +328,7 @@ namespace OpenSim.Region.UserStatistics UserSessionID uid = new UserSessionID(); uid.name_f = agent.Firstname; uid.name_l = agent.Lastname; - uid.region_id = regionUUID; + uid.region_id = agent.Scene.RegionInfo.RegionID; uid.session_id = agent.ControllingClient.SessionId; uid.session_data = usd; @@ -339,7 +337,7 @@ namespace OpenSim.Region.UserStatistics else { UserSessionID uid = m_sessions[agent.UUID]; - uid.region_id = regionUUID; + uid.region_id = agent.Scene.RegionInfo.RegionID; uid.session_id = agent.ControllingClient.SessionId; m_sessions[agent.UUID] = uid; } @@ -395,20 +393,6 @@ namespace OpenSim.Region.UserStatistics return encoding.GetString(buffer); } - private UUID GetRegionUUIDFromHandle(ulong regionhandle) - { - lock (m_scenes) - { - foreach (Scene scene in m_scenes) - { - if (scene.RegionInfo.RegionHandle == regionhandle) - return scene.RegionInfo.RegionID; - } - } - - return UUID.Zero; - } - /// /// Callback for a viewerstats cap /// From c1667d39a610488e80e9d7c939ee7b449f02410d Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Mon, 16 Jul 2012 23:15:02 +0100 Subject: [PATCH 5/9] refactor: factor out common code in WebStatsModule.OnMakeRootAgent() --- OpenSim/Region/UserStatistics/WebStatsModule.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index ed424abadf..c11ea0225a 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -321,26 +321,25 @@ namespace OpenSim.Region.UserStatistics { lock (m_sessions) { + UserSessionID uid; + if (!m_sessions.ContainsKey(agent.UUID)) { UserSessionData usd = UserSessionUtil.newUserSessionData(); - - UserSessionID uid = new UserSessionID(); + uid = new UserSessionID(); uid.name_f = agent.Firstname; uid.name_l = agent.Lastname; - uid.region_id = agent.Scene.RegionInfo.RegionID; - uid.session_id = agent.ControllingClient.SessionId; uid.session_data = usd; m_sessions.Add(agent.UUID, uid); } else { - UserSessionID uid = m_sessions[agent.UUID]; - uid.region_id = agent.Scene.RegionInfo.RegionID; - uid.session_id = agent.ControllingClient.SessionId; - m_sessions[agent.UUID] = uid; + uid = m_sessions[agent.UUID]; } + + uid.region_id = agent.Scene.RegionInfo.RegionID; + uid.session_id = agent.ControllingClient.SessionId; } } From 1c3b0da74a6e662ceebad53c82d38ba8a42795b3 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 16 Jul 2012 23:31:55 +0100 Subject: [PATCH 6/9] Revert "Fix script "Running" behavior" A better solution using the already present flags must be found. This reverts commit 6d3ee8bb39d47ed7b32e8905fa0b2fc31c5a9f80. --- .../Region/Framework/Interfaces/IScriptModule.cs | 2 -- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 14 -------------- .../ScriptEngine/Interfaces/IScriptInstance.cs | 10 ---------- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 9 --------- .../Shared/Instance/ScriptSerializer.cs | 11 ----------- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 7 ------- 6 files changed, 53 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs index 42dbedcd56..143af48d99 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs @@ -77,8 +77,6 @@ namespace OpenSim.Region.Framework.Interfaces /// The item ID of the script. bool GetScriptState(UUID itemID); - void SetRunEnable(UUID instanceID, bool enable); - void SaveAllState(); /// diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 9ff8467086..e4132817ac 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -2143,24 +2143,10 @@ namespace OpenSim.Region.Framework.Scenes if (part == null) return; - IScriptModule[] engines = RequestModuleInterfaces(); - if (running) - { - foreach (IScriptModule engine in engines) - { - engine.SetRunEnable(itemID, true); - } EventManager.TriggerStartScript(part.LocalId, itemID); - } else - { - foreach (IScriptModule engine in engines) - { - engine.SetRunEnable(itemID, false); - } EventManager.TriggerStopScript(part.LocalId, itemID); - } } public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index ec13b6cc01..b04f6b6624 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -63,16 +63,6 @@ namespace OpenSim.Region.ScriptEngine.Interfaces /// bool Running { get; set; } - /// - /// Gets or sets a value indicating whether this - /// is run. - /// For viewer script editor control - /// - /// - /// true if run; otherwise, false. - /// - bool Run { get; set; } - /// /// Is the script suspended? /// diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index f1abd4b746..d570ef7fb6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -121,8 +121,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public bool Running { get; set; } - public bool Run { get; set; } - public bool Suspended { get { return m_Suspended; } @@ -218,7 +216,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_postOnRez = postOnRez; m_AttachedAvatar = part.ParentGroup.AttachedAvatar; m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; - Run = true; if (part != null) { @@ -360,9 +357,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (m_startedFromSavedState) { - if (!Run) - return; - Start(); if (m_postOnRez) { @@ -395,9 +389,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } else { - if (!Run) - return; - Start(); PostEvent(new EventParams("state_entry", new Object[0], new DetectParams[0])); diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs index 797bce3ce1..bcdc7bf5dd 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs @@ -55,7 +55,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public static string Serialize(ScriptInstance instance) { bool running = instance.Running; - bool enabled = instance.Run; XmlDocument xmldoc = new XmlDocument(); @@ -78,12 +77,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance rootElement.AppendChild(run); - XmlElement run_enable = xmldoc.CreateElement("", "Run", ""); - run_enable.AppendChild(xmldoc.CreateTextNode( - enabled.ToString())); - - rootElement.AppendChild(run_enable); - Dictionary vars = instance.GetVars(); XmlElement variables = xmldoc.CreateElement("", "Variables", ""); @@ -232,7 +225,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { object varValue; XmlNodeList partL = rootNode.ChildNodes; - instance.Run = true; foreach (XmlNode part in partL) { @@ -244,9 +236,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance case "Running": instance.Running=bool.Parse(part.InnerText); break; - case "Run": - instance.Run = bool.Parse(part.InnerText); - break; case "Variables": XmlNodeList varL = part.ChildNodes; foreach (XmlNode var in varL) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 20fad05b72..01aebb64af 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1541,13 +1541,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine } } - public void SetRunEnable(UUID instanceID, bool enable) - { - IScriptInstance instance = GetInstance(instanceID); - if (instance != null) - instance.Run = enable; - } - public bool GetScriptState(UUID itemID) { IScriptInstance instance = GetInstance(itemID); From b6476eaac35c37862ae74e6f6a070a80cf51c0c0 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Jul 2012 00:00:26 +0100 Subject: [PATCH 7/9] Stop sending the viewer an inventory create message if a known attachment item is updated. This doesn't seem to make any sense and probably stems from a period when this code was directly involved in attaching objects directly from the scene. This message is already being sent by InventoryAccessModule code instead. --- .../CoreModules/Avatar/Attachments/AttachmentsModule.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 64ee7e44b8..fff47e2ae6 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -566,11 +566,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments item.InvType = (int)InventoryType.Object; m_scene.InventoryService.UpdateItem(item); - - // this gets called when the agent logs off! - if (sp.ControllingClient != null) - sp.ControllingClient.SendInventoryItemCreateUpdate(item, 0); } + grp.HasGroupChanged = false; // Prevent it being saved over and over } // else From 356d5972961cc91593cfcc5c529a8ba81381b8f4 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Jul 2012 00:17:51 +0100 Subject: [PATCH 8/9] Restore update of inventory item on derez/logout. This is necessary to update the name if this has been changed whilst attached. Note, this behaviour appears to be at variance with the ll grid as of Tues 17 July 2012, testing with viewer 3.2.1. The item name in inventory does not change either at the point of detach or after a relog. --- .../CoreModules/Avatar/Attachments/AttachmentsModule.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index fff47e2ae6..d34a8f63d7 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -566,8 +566,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments item.InvType = (int)InventoryType.Object; m_scene.InventoryService.UpdateItem(item); + + // If the name of the object has been changed whilst attached then we want to update the inventory + // item in the viewer. + if (sp.ControllingClient != null) + sp.ControllingClient.SendInventoryItemCreateUpdate(item, 0); } - + grp.HasGroupChanged = false; // Prevent it being saved over and over } // else From c489bc1cd2c81273aaf0e0beb23b3714079ce4be Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 17 Jul 2012 15:00:42 +0200 Subject: [PATCH 9/9] Make the scrpt running flag work properly --- .../Shared/Instance/ScriptInstance.cs | 14 ++++++++------ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index d570ef7fb6..5793cc9de6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -312,11 +312,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); - Running = false; - - if (ShuttingDown) + if (!Running) m_startOnInit = false; + Running = false; + // we get new rez events on sim restart, too // but if there is state, then we fire the change // event @@ -352,12 +352,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public void Init() { - if (!m_startOnInit) + if (ShuttingDown) return; if (m_startedFromSavedState) { - Start(); + if (m_startOnInit) + Start(); if (m_postOnRez) { PostEvent(new EventParams("on_rez", @@ -389,7 +390,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } else { - Start(); + if (m_startOnInit) + Start(); PostEvent(new EventParams("state_entry", new Object[0], new DetectParams[0])); if (m_postOnRez) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 01aebb64af..7a9c80c28e 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -108,6 +108,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine private bool m_KillTimedOutScripts; private string m_ScriptEnginesPath = null; + private ExpiringCache m_runFlags = new ExpiringCache(); + /// /// Is the entire simulator in the process of shutting down? /// @@ -1196,6 +1198,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (instance != null) instance.Init(); + bool runIt; + if (m_runFlags.TryGetValue(itemID, out runIt)) + { + if (!runIt) + StopScript(itemID); + m_runFlags.Remove(itemID); + } + return true; } @@ -1568,6 +1578,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine IScriptInstance instance = GetInstance(itemID); if (instance != null) instance.Start(); + else + m_runFlags.AddOrUpdate(itemID, true, 240); } public void StopScript(UUID itemID) @@ -1579,6 +1591,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine // cause issues on mono 2.6, 2.10 and possibly later where locks are not released properly on abort. instance.Stop(1000); } + else + { + m_runFlags.AddOrUpdate(itemID, false, 240); + } } public DetectParams GetDetectParams(UUID itemID, int idx)