From b714fb0c391335c957d1fe9393fe154b885f7d62 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Wed, 15 Aug 2012 21:14:39 +0100 Subject: [PATCH] Implementing PRIM_LINK_TARGET in a non-recursive fashion --- .../Shared/Api/Implementation/LSL_Api.cs | 123 +++++++++++------- 1 file changed, 74 insertions(+), 49 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 3591d14c16..7a4a97c14b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -243,33 +243,38 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } public List GetLinkParts(int linkType) + { + return GetLinkParts(m_host, linkType); + } + + private List GetLinkParts(SceneObjectPart part, int linkType) { List ret = new List(); - ret.Add(m_host); + ret.Add(part); switch (linkType) { case ScriptBaseClass.LINK_SET: - return new List(m_host.ParentGroup.Parts); + return new List(part.ParentGroup.Parts); case ScriptBaseClass.LINK_ROOT: ret = new List(); - ret.Add(m_host.ParentGroup.RootPart); + ret.Add(part.ParentGroup.RootPart); return ret; case ScriptBaseClass.LINK_ALL_OTHERS: - ret = new List(m_host.ParentGroup.Parts); + ret = new List(part.ParentGroup.Parts); - if (ret.Contains(m_host)) - ret.Remove(m_host); + if (ret.Contains(part)) + ret.Remove(part); return ret; case ScriptBaseClass.LINK_ALL_CHILDREN: - ret = new List(m_host.ParentGroup.Parts); + ret = new List(part.ParentGroup.Parts); - if (ret.Contains(m_host.ParentGroup.RootPart)) - ret.Remove(m_host.ParentGroup.RootPart); + if (ret.Contains(part.ParentGroup.RootPart)) + ret.Remove(part.ParentGroup.RootPart); return ret; case ScriptBaseClass.LINK_THIS: @@ -279,7 +284,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (linkType < 0) return new List(); - SceneObjectPart target = m_host.ParentGroup.GetLinkNumPart(linkType); + SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType); if (target == null) return new List(); ret = new List(); @@ -7184,7 +7189,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llSetPrimitiveParams(LSL_List rules) { m_host.AddScriptLPS(1); - SetPrimParams(m_host, rules); + + setLinkPrimParams(ScriptBaseClass.LINK_THIS, rules); ScriptSleep(200); } @@ -7209,11 +7215,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { List parts = GetLinkParts(linknumber); + LSL_List remaining = null; + foreach (SceneObjectPart part in parts) - SetPrimParams(part, rules); + remaining = SetPrimParams(part, rules); + + while(remaining != null && remaining.Length > 2) + { + linknumber = remaining.GetLSLIntegerItem(0); + rules = remaining.GetSublist(1,-1); + parts = GetLinkParts(linknumber); + + foreach (SceneObjectPart part in parts) + remaining = SetPrimParams(part, rules); + } } - protected void SetPrimParams(SceneObjectPart part, LSL_List rules) + protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules) { int idx = 0; @@ -7236,7 +7254,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_POSITION: case (int)ScriptBaseClass.PRIM_POS_LOCAL: if (remain < 1) - return; + return null; v=rules.GetVector3Item(idx++); positionChanged = true; @@ -7245,7 +7263,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api break; case (int)ScriptBaseClass.PRIM_SIZE: if (remain < 1) - return; + return null; v=rules.GetVector3Item(idx++); SetScale(part, v); @@ -7253,7 +7271,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api break; case (int)ScriptBaseClass.PRIM_ROTATION: if (remain < 1) - return; + return null; LSL_Rotation q = rules.GetQuaternionItem(idx++); // try to let this work as in SL... @@ -7273,7 +7291,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TYPE: if (remain < 3) - return; + return null; code = (int)rules.GetLSLIntegerItem(idx++); @@ -7292,7 +7310,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { case (int)ScriptBaseClass.PRIM_TYPE_BOX: if (remain < 6) - return; + return null; face = (int)rules.GetLSLIntegerItem(idx++); v = rules.GetVector3Item(idx++); // cut @@ -7307,7 +7325,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER: if (remain < 6) - return; + return null; face = (int)rules.GetLSLIntegerItem(idx++); // holeshape v = rules.GetVector3Item(idx++); // cut @@ -7321,7 +7339,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TYPE_PRISM: if (remain < 6) - return; + return null; face = (int)rules.GetLSLIntegerItem(idx++); // holeshape v = rules.GetVector3Item(idx++); //cut @@ -7335,7 +7353,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TYPE_SPHERE: if (remain < 5) - return; + return null; face = (int)rules.GetLSLIntegerItem(idx++); // holeshape v = rules.GetVector3Item(idx++); // cut @@ -7348,7 +7366,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TYPE_TORUS: if (remain < 11) - return; + return null; face = (int)rules.GetLSLIntegerItem(idx++); // holeshape v = rules.GetVector3Item(idx++); //cut @@ -7367,7 +7385,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TYPE_TUBE: if (remain < 11) - return; + return null; face = (int)rules.GetLSLIntegerItem(idx++); // holeshape v = rules.GetVector3Item(idx++); //cut @@ -7386,7 +7404,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TYPE_RING: if (remain < 11) - return; + return null; face = (int)rules.GetLSLIntegerItem(idx++); // holeshape v = rules.GetVector3Item(idx++); //cut @@ -7405,7 +7423,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TYPE_SCULPT: if (remain < 2) - return; + return null; string map = rules.Data[idx++].ToString(); face = (int)rules.GetLSLIntegerItem(idx++); // type @@ -7417,7 +7435,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TEXTURE: if (remain < 5) - return; + return null; face=(int)rules.GetLSLIntegerItem(idx++); string tex=rules.Data[idx++].ToString(); @@ -7434,7 +7452,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_COLOR: if (remain < 3) - return; + return null; face=(int)rules.GetLSLIntegerItem(idx++); LSL_Vector color=rules.GetVector3Item(idx++); @@ -7447,7 +7465,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_FLEXIBLE: if (remain < 7) - return; + return null; bool flexi = rules.GetLSLIntegerItem(idx++); int softness = rules.GetLSLIntegerItem(idx++); @@ -7463,7 +7481,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_POINT_LIGHT: if (remain < 5) - return; + return null; bool light = rules.GetLSLIntegerItem(idx++); LSL_Vector lightcolor = rules.GetVector3Item(idx++); float intensity = (float)rules.GetLSLFloatItem(idx++); @@ -7476,7 +7494,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_GLOW: if (remain < 2) - return; + return null; face = rules.GetLSLIntegerItem(idx++); float glow = (float)rules.GetLSLFloatItem(idx++); @@ -7486,7 +7504,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_BUMP_SHINY: if (remain < 3) - return; + return null; face = (int)rules.GetLSLIntegerItem(idx++); int shiny = (int)rules.GetLSLIntegerItem(idx++); Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++); @@ -7497,7 +7515,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_FULLBRIGHT: if (remain < 2) - return; + return null; face = rules.GetLSLIntegerItem(idx++); bool st = rules.GetLSLIntegerItem(idx++); SetFullBright(part, face , st); @@ -7505,17 +7523,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_MATERIAL: if (remain < 1) - return; + return null; int mat = rules.GetLSLIntegerItem(idx++); if (mat < 0 || mat > 7) - return; + return null; part.Material = Convert.ToByte(mat); break; case (int)ScriptBaseClass.PRIM_PHANTOM: if (remain < 1) - return; + return null; string ph = rules.Data[idx++].ToString(); m_host.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1")); @@ -7524,7 +7542,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_PHYSICS: if (remain < 1) - return; + return null; string phy = rules.Data[idx++].ToString(); bool physics; @@ -7538,7 +7556,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ: if (remain < 1) - return; + return null; string temp = rules.Data[idx++].ToString(); m_host.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1")); @@ -7547,7 +7565,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case (int)ScriptBaseClass.PRIM_TEXGEN: if (remain < 2) - return; + return null; //face,type face = rules.GetLSLIntegerItem(idx++); int style = rules.GetLSLIntegerItem(idx++); @@ -7555,7 +7573,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api break; case (int)ScriptBaseClass.PRIM_TEXT: if (remain < 3) - return; + return null; string primText = rules.GetLSLStringItem(idx++); LSL_Vector primTextColor = rules.GetVector3Item(idx++); LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++); @@ -7567,25 +7585,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api break; case (int)ScriptBaseClass.PRIM_NAME: if (remain < 1) - return; + return null; string primName = rules.GetLSLStringItem(idx++); part.Name = primName; break; case (int)ScriptBaseClass.PRIM_DESC: if (remain < 1) - return; + return null; string primDesc = rules.GetLSLStringItem(idx++); part.Description = primDesc; break; case (int)ScriptBaseClass.PRIM_ROT_LOCAL: if (remain < 1) - return; + return null; LSL_Rotation lr = rules.GetQuaternionItem(idx++); SetRot(part, Rot2Quaternion(lr)); break; case (int)ScriptBaseClass.PRIM_OMEGA: if (remain < 3) - return; + return null; LSL_Vector axis = rules.GetVector3Item(idx++); LSL_Float spinrate = rules.GetLSLFloatItem(idx++); LSL_Float gain = rules.GetLSLFloatItem(idx++); @@ -7593,12 +7611,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api break; case (int)ScriptBaseClass.PRIM_LINK_TARGET: if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless. - return; - LSL_Integer new_linknumber = rules.GetLSLIntegerItem(idx++); - LSL_List new_rules = rules.GetSublist(idx, -1); - setLinkPrimParams((int)new_linknumber, new_rules); + return null; - return; + return rules.GetSublist(idx, -1); } } } @@ -7620,6 +7635,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } } + return null; } public LSL_String llStringToBase64(string str) @@ -10692,7 +10708,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (obj.OwnerID != m_host.OwnerID) return; - SetPrimParams(obj, rules); + LSL_List remaining = SetPrimParams(obj, rules); + + while (remaining != null && remaining.Length > 2) + { + LSL_Integer newLink = remaining.GetLSLIntegerItem(0); + LSL_List newrules = remaining.GetSublist(1, -1); + foreach(SceneObjectPart part in GetLinkParts(obj, newLink)){ + remaining = SetPrimParams(part, newrules); + } + } } public LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules)