From be2192fd539fa399f01b7e43ba75f6edaaf7639e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 16 Feb 2023 05:04:11 +0000 Subject: [PATCH] revert change on script execution release points. That will need a full recompile with script states reset, not justifiable by now; plus cosmetics --- .../Shared/Api/Implementation/LSL_Api.cs | 38 +-- .../ScriptEngine/YEngine/MMRScriptCodeGen.cs | 21 +- .../ScriptEngine/YEngine/MMRScriptInlines.cs | 62 ++-- .../ScriptEngine/YEngine/MMRScriptTypeCast.cs | 87 ++--- .../Region/ScriptEngine/YEngine/XMREngine.cs | 4 +- .../ScriptEngine/YEngine/XMRInstAbstract.cs | 302 +++++++++--------- .../ScriptEngine/YEngine/XMRInstBackend.cs | 12 +- .../ScriptEngine/YEngine/XMRInstCapture.cs | 9 +- .../ScriptEngine/YEngine/XMRInstCtor.cs | 45 ++- 9 files changed, 275 insertions(+), 305 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 518ec7b5d2..d7bef3cfc8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -1037,7 +1037,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s; // m is always greater than zero // if m is not equal to 1 then Rotation needs to be normalized - if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision + if (Math.Abs(1.0 - m) > 0.000001) { m = 1.0 / Math.Sqrt(m); r.x *= m; @@ -5455,8 +5455,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { if (item is LSL_Integer LSL_Integeritem) return LSL_Integeritem; - else if (item is LSL_Float LSL_Floatitem) - return Convert.ToInt32(LSL_Floatitem.value); + if (item is LSL_Float LSL_Floatitem) + return new LSL_Integer(LSL_Floatitem.value); return new LSL_Integer(item.ToString()); } catch (FormatException) @@ -5492,11 +5492,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api try { - if (item is LSL_Integer intitem) - return Convert.ToDouble(intitem.value); - else if (item is LSL_Float floatitem) - return Convert.ToDouble(floatitem.value); - else if (item is LSL_String lstringitem) + if (item is LSL_Integer intitem) + return new LSL_Float(intitem.value); + if (item is LSL_Float floatitem) + return floatitem; + if (item is LSL_String lstringitem) { Match m = Regex.Match(lstringitem.m_string, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)"); if (m != Match.Empty) @@ -5558,26 +5558,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api index = src.Length + index; if (index >= src.Length || index < 0) - return new LSL_Vector(); + return LSL_Vector.Zero; object item = src.Data[index]; - if (item.GetType() == typeof(LSL_Vector)) - return (LSL_Vector)item; + //if (item.GetType() == typeof(LSL_Vector)) + // return (LSL_Vector)item; - // SL spits always out ZERO_VECTOR for anything other than - // strings or vectors. Although keys always return ZERO_VECTOR, - // it is currently difficult to make the distinction between - // a string, a key as string and a string that by coincidence - // is a string, so we're going to leave that up to the - // LSL_Vector constructor. - if(item is LSL_Vector vec) + if(item is LSL_Vector vec) return vec; - if (item is LSL_String || item is string) // xengine sees string - return new LSL_Vector(item.ToString()); + if (item is LSL_String lsv) + return new LSL_Vector(lsv.m_string); + if (item is string sv) // xengine sees string + return new LSL_Vector(sv); - return new LSL_Vector(0, 0, 0); + return LSL_Vector.Zero; } public LSL_Rotation llList2Rot(LSL_List src, int index) diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCodeGen.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCodeGen.cs index a2fcdeeaff..0ccb1027d4 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCodeGen.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCodeGen.cs @@ -34,7 +34,6 @@ using System.Reflection; using System.Reflection.Emit; using System.Runtime.Serialization; using System.Text; -using System.Threading; using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; @@ -78,14 +77,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine private static VarDict legalEventHandlers = CreateLegalEventHandlers(); private static CompValu[] zeroCompValus = Array.Empty(); private static TokenType[] zeroArgs = Array.Empty(); - private static TokenTypeBool tokenTypeBool = new TokenTypeBool(null); - private static TokenTypeExc tokenTypeExc = new TokenTypeExc(null); - private static TokenTypeFloat tokenTypeFlt = new TokenTypeFloat(null); - private static TokenTypeInt tokenTypeInt = new TokenTypeInt(null); - private static TokenTypeObject tokenTypeObj = new TokenTypeObject(null); - private static TokenTypeRot tokenTypeRot = new TokenTypeRot(null); - private static TokenTypeStr tokenTypeStr = new TokenTypeStr(null); - private static TokenTypeVec tokenTypeVec = new TokenTypeVec(null); + private static TokenTypeBool tokenTypeBool = new(null); + private static TokenTypeExc tokenTypeExc = new(null); + private static TokenTypeFloat tokenTypeFlt = new(null); + private static TokenTypeInt tokenTypeInt = new(null); + private static TokenTypeObject tokenTypeObj = new(null); + private static TokenTypeRot tokenTypeRot = new(null); + private static TokenTypeStr tokenTypeStr = new(null); + private static TokenTypeVec tokenTypeVec = new(null); private static Type[] instanceTypeArg = new Type[] { typeof(XMRInstAbstract) }; private static string[] instanceNameArg = new string[] { "$xmrthis" }; @@ -149,7 +148,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine public static bool CodeGen(TokenScript tokenScript, BinaryWriter objFileWriter, string sourceHash) { // Run compiler such that it has a 'this' context for convenience. - ScriptCodeGen scg = new ScriptCodeGen(tokenScript, objFileWriter, sourceHash); + ScriptCodeGen scg = new(tokenScript, objFileWriter, sourceHash); // Return pointer to resultant script object code. return !scg.youveAnError; @@ -5413,7 +5412,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } if(expr is CompValuFloat CompValuFloatexpr) { - constVal = ((CompValuFloat)expr).x != (double)0; + constVal = CompValuFloatexpr.x != 0; return true; } if(expr is CompValuInteger CompValuIntegerexpr) diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptInlines.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptInlines.cs index f138495dbc..1b3d83f4ee 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptInlines.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptInlines.cs @@ -65,50 +65,40 @@ namespace OpenSim.Region.ScriptEngine.Yengine * For all others, we generate the call then a call to CheckRun(). */ noCheckRuns = new HashSet() { - "llAcos", - "llAsin", - "llAtan2", - "llCeil", - "llChar", - "llCos", - "llDetectedGrab", - "llDetectedGroup", - "llDetectedKey", - "llDetectedLinkNumber", - "llDetectedName", - "llDetectedOwner", - "llDetectedPos", - "llDetectedRot", - "llDetectedTouchBinormal", - "llDetectedTouchFace", - "llDetectedTouchNormal", - "llDetectedTouchPos", - "llDetectedTouchST", - "llDetectedTouchUV", - "llDetectedType", - "llDetectedVel", - "llDie", - "llFabs", - "llFloor", - "llFrand", - "llLog", - "llLog10", - "llPow", - "llSin", - "llSqrt", - "llTan", - "llGetAccel", - "llGetGMTClock", - "llGetKey", + "llBase64ToString", + "llCSV2List", + "llDeleteSubList", + "llDeleteSubString", + "llDumpList2String", + "llEscapeURL", + "llEuler2Rot", "llGetListEntryType", - "llGetOwner", + "llGetListLength", + "llGetSubString", "llGetUnixTime", + "llInsertString", + "llList2CSV", "llList2Float", "llList2Integer", "llList2Key", "llList2Rot", + "llList2String", "llList2Vector", + "llListFindList", + "llListInsertList", + "llListRandomize", + "llListReplaceList", + "llListSort", + "llListStatistics", + "llMD5String", + "llParseString2List", + "llParseStringKeepNulls", + "llRot2Euler", "llStringLength", + "llStringToBase64", + "llStringTrim", + "llSubStringIndex", + "llUnescapeURL", "osGetSitActiveRange", "osIsNotValidNumber", "osSlerp", diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptTypeCast.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptTypeCast.cs index 7b270d66fe..038e79b998 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptTypeCast.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptTypeCast.cs @@ -833,7 +833,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } public static string ObjectToString(object x) { - return (x == null) ? null : x.ToString(); + return x?.ToString(); } public static string RotationToString(LSL_Rotation x) { @@ -878,27 +878,34 @@ namespace OpenSim.Region.ScriptEngine.Yengine public static double ObjectToFloat(object x) { - if(x is LSL_String) - return double.Parse(((LSL_String)x).m_string); - if(x is string) - return double.Parse((string)x); - if(x is LSL_Float) - return (double)(LSL_Float)x; - if(x is LSL_Integer) - return (double)(int)(LSL_Integer)x; - if(x is int) - return (double)(int)x; + if(x is LSL_String lsx) + return double.Parse(lsx.m_string); + if(x is string sx) + return double.Parse(sx); + if(x is LSL_Float lfx) + return lfx.value; + if(x is LSL_Integer lix) + return lix.value; + if(x is int ix) + return ix; return (double)x; } public static int ObjectToInteger(object x) { - if(x is LSL_String) - return int.Parse(((LSL_String)x).m_string); - if(x is string) - return int.Parse((string)x); - if(x is LSL_Integer) - return (int)(LSL_Integer)x; + if (x is int ix) + return ix; + if (x is LSL_Integer lix) + return lix.value; + if (x is LSL_String lsx) + return int.Parse(lsx.m_string); + if(x is string sx) + return int.Parse(sx); + if (x is LSL_Float lfx) + return (int)lfx.value; + if (x is double dx) + return (int)dx; + return (int)x; } @@ -909,19 +916,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine public static LSL_Rotation ObjectToRotation(object x) { - if(x is LSL_String) - return new LSL_Rotation(((LSL_String)x).m_string); - if(x is string) - return new LSL_Rotation((string)x); + if(x is LSL_String lsx) + return new LSL_Rotation(lsx.m_string); + if(x is string sx) + return new LSL_Rotation(sx); return (LSL_Rotation)x; } public static LSL_Vector ObjectToVector(object x) { - if(x is LSL_String) - return new LSL_Vector(((LSL_String)x).m_string); - if(x is string) - return new LSL_Vector((string)x); + if(x is LSL_String lsx) + return new LSL_Vector(lsx.m_string); + if(x is string sx) + return new LSL_Vector(sx); return (LSL_Vector)x; } @@ -937,44 +944,38 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ public static double EHArgUnwrapFloat(object x) { - if(x is LSL_Float) - return (double)(LSL_Float)x; + if(x is LSL_Float lfx) + return lfx.value; return (double)x; } public static int EHArgUnwrapInteger(object x) { - if(x is LSL_Integer) - return (int)(LSL_Integer)x; + if(x is LSL_Integer lix) + return lix.value; return (int)x; } public static LSL_Rotation EHArgUnwrapRotation(object x) { - if(x is OpenMetaverse.Quaternion) - { - OpenMetaverse.Quaternion q = (OpenMetaverse.Quaternion)x; - return new LSL_Rotation(q.X, q.Y, q.Z, q.W); - } + if(x is OpenMetaverse.Quaternion oqx) + return new LSL_Rotation(oqx); return (LSL_Rotation)x; } public static string EHArgUnwrapString(object x) { - if(x is LSL_Key) - return (string)(LSL_Key)x; - if(x is LSL_String) - return (string)(LSL_String)x; + if(x is LSL_Key lkx) + return lkx.m_string; + if(x is LSL_String sx) + return sx.m_string; return (string)x; } public static LSL_Vector EHArgUnwrapVector(object x) { - if(x is OpenMetaverse.Vector3) - { - OpenMetaverse.Vector3 v = (OpenMetaverse.Vector3)x; - return new LSL_Vector(v.X, v.Y, v.Z); - } + if(x is OpenMetaverse.Vector3 ovx) + return new LSL_Vector(ovx); return (LSL_Vector)x; } } diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs b/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs index 8aa1480ae7..59a68f6bf9 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs @@ -1374,7 +1374,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine { initerr = e1; } - if(initerr != null && !instance.m_ForceRecomp && initerr is CVVMismatchException) + if(initerr is not null && !instance.m_ForceRecomp && initerr is CVVMismatchException) { UUID itemID = instance.m_ItemID; Verbose("[YEngine]: {0}/{2} first load failed ({1}), retrying after recompile", @@ -1392,7 +1392,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine initerr = e2; } } - if(initerr != null) + if(initerr is not null) { UUID itemID = instance.m_ItemID; Verbose("[YEngine]: Error starting script {0}/{2}: {1}", diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs index 79e2a67145..d7d096ba8b 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs @@ -31,7 +31,6 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Reflection.Emit; -using System.Runtime.Serialization; using System.Text; using System.Threading; @@ -89,24 +88,24 @@ namespace OpenSim.Region.ScriptEngine.Yengine public void Clear() { int newheapUse = 0; - if(iarArrays != null) + if(iarArrays is not null) { foreach(XMR_Array xa in iarArrays) xa.__pub_clear(); } - if(iarChars != null) + if(iarChars is not null) iarChars = new char[iarChars.Length]; - if (iarLists != null) + if (iarLists is not null) iarLists = new LSL_List[iarLists.Length]; - if (iarObjects != null) + if (iarObjects is not null) iarObjects = new object[iarObjects.Length]; - if(iarStrings != null) + if(iarStrings is not null) iarStrings = new string[iarStrings.Length]; - if (iarFloats != null) + if (iarFloats is not null) newheapUse += iarFloats.Length * HeapTrackerObject.HT_DOUB; - if (iarIntegers != null) + if (iarIntegers is not null) newheapUse += iarIntegers.Length * HeapTrackerObject.HT_INT; - if (iarRotations != null) + if (iarRotations is not null) newheapUse += iarRotations.Length * HeapTrackerObject.HT_ROT; if (iarVectors != null) newheapUse += iarVectors.Length * HeapTrackerObject.HT_VEC; @@ -201,13 +200,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine ClearOldArrays(); iarArrays = (XMR_Array[])recver(); - if(iarArrays == null) + if(iarArrays is null) iarArrays = noArrays; int newheapuse = arraysHeapUse; char[] chrs = (char[])recver(); - if (chrs != null) + if (chrs is not null) { newheapuse += chrs.Length * HeapTrackerObject.HT_CHAR; iarChars = chrs; @@ -216,7 +215,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine iarChars = noChars; double[] flts = (double[])recver(); - if (flts != null) + if (flts is not null) { newheapuse += flts.Length * HeapTrackerObject.HT_DOUB; iarFloats = flts; @@ -225,7 +224,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine iarFloats = noFloats; int[] ints = (int[])recver(); - if (ints != null) + if (ints is not null) { newheapuse += ints.Length * HeapTrackerObject.HT_INT; iarIntegers = ints; @@ -234,7 +233,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine iarIntegers = noIntegers; LSL_List[] liss = (LSL_List[])recver(); - if (liss != null) + if (liss is not null) { foreach (LSL_List lis in liss) { @@ -247,7 +246,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine iarLists = noLists; object[] objs = (object[])recver(); - if (objs != null) + if (objs is not null) { foreach (object obj in objs) newheapuse += HeapTrackerObject.Size(obj); @@ -257,7 +256,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine iarObjects = noObjects; LSL_Rotation[] rots = (LSL_Rotation[])recver(); - if (rots != null) + if (rots is not null) { newheapuse += rots.Length * HeapTrackerObject.HT_ROT; iarRotations = rots; @@ -266,7 +265,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine iarRotations = noRotations; string[] strs = (string[])recver(); - if (strs != null) + if (strs is not null) { foreach (string str in strs) newheapuse += HeapTrackerString.Size(str); @@ -285,11 +284,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine iarVectors = noVectors; iarSDTClObjs = (XMRSDTypeClObj[])recver(); - if(iarSDTClObjs == null) + if(iarSDTClObjs is null) iarSDTClObjs = noSDTClObjs; Delegate[][] dels = (Delegate[][])recver(); - if(dels != null) + if(dels is not null) { newheapuse += dels.Length * HeapTrackerObject.HT_DELE; iarSDTIntfObjs = dels; @@ -307,54 +306,54 @@ namespace OpenSim.Region.ScriptEngine.Yengine int newheapuse = arraysHeapUse; iarArrays = null; - if(iarChars != null) + if(iarChars is not null) { newheapuse -= iarChars.Length * HeapTrackerObject.HT_CHAR; iarChars = null; } - if(iarFloats != null) + if(iarFloats is not null) { newheapuse -= iarFloats.Length * HeapTrackerObject.HT_DOUB; iarFloats = null; } - if(iarIntegers != null) + if(iarIntegers is not null) { newheapuse -= iarIntegers.Length * HeapTrackerObject.HT_INT; iarIntegers = null; } - if(iarLists != null) + if(iarLists is not null) { foreach(LSL_List lis in iarLists) { - if (!(lis is null)) + if ((lis is not null)) newheapuse += lis.Size; } iarLists = null; } - if(iarObjects != null) + if(iarObjects is not null) { foreach(object obj in iarObjects) newheapuse -= HeapTrackerObject.Size(obj); iarObjects = null; } - if(iarRotations != null) + if(iarRotations is not null) { newheapuse -= iarRotations.Length * HeapTrackerObject.HT_ROT; iarRotations = null; } - if(iarStrings != null) + if(iarStrings is not null) { foreach(string str in iarStrings) newheapuse -= HeapTrackerString.Size(str); iarStrings = null; } - if(iarVectors != null) + if(iarVectors is not null) { newheapuse -= iarVectors.Length * HeapTrackerObject.HT_VEC; iarVectors = null; } iarSDTClObjs = null; - if(iarSDTIntfObjs != null) + if(iarSDTIntfObjs is not null) { newheapuse -= iarSDTIntfObjs.Length * HeapTrackerObject.HT_DELE; iarSDTIntfObjs = null; @@ -651,7 +650,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ public void CheckRunQuick() { - // if (suspendOnCheckRunHold || suspendOnCheckRunTemp) + //if (suspendOnCheckRunHold || suspendOnCheckRunTemp) CheckRunWork(); } @@ -700,13 +699,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine public static LSL_List FixLLParcelMediaQuery(LSL_List oldlist) { object[] oldarray = oldlist.Data; - int len = oldarray.Length; - object[] newarray = new object[len]; - for(int i = 0; i < len; i++) + object[] newarray = new object[oldarray.Length]; + for(int i = 0; i < oldarray.Length; i++) { object obj = oldarray[i]; - if(obj is LSL_Integer) - obj = (int)(LSL_Integer)obj; + if(obj is LSL_Integer io) + obj = io.value; newarray[i] = obj; } return new LSL_List(newarray); @@ -719,19 +717,18 @@ namespace OpenSim.Region.ScriptEngine.Yengine public static LSL_List FixLLParcelMediaCommandList(LSL_List oldlist) { object[] oldarray = oldlist.Data; - int len = oldarray.Length; - object[] newarray = new object[len]; + object[] newarray = new object[oldarray.Length]; int verbatim = 0; - for(int i = 0; i < len; i++) + for(int i = 0; i < oldarray.Length; i++) { object obj = oldarray[i]; if(--verbatim < 0) { - if(obj is LSL_Integer) - obj = (int)(LSL_Integer)obj; - if(obj is int) + if(obj is LSL_Integer lio) + obj = lio.value; + if(obj is int io) { - switch((int)obj) + switch(io) { case ScriptBaseClass.PARCEL_MEDIA_COMMAND_AUTO_ALIGN: // leave next integer as LSL_Integer @@ -809,20 +806,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine // If that is the case, convert it to the object of the script-defined // class that is implementing the interface. This should let the next // step get the script-defined type name of the object. - if(o is Delegate[]) - o = ((Delegate[])o)[0].Target; + if(o is Delegate[] dao) + o = dao[0].Target; // If script-defined class instance, get the script-defined // type name. - if(o is XMRSDTypeClObj) - return ((XMRSDTypeClObj)o).sdtcClass.longName.val; + if(o is XMRSDTypeClObj XMRSDTypeClObjo) + return XMRSDTypeClObjo.sdtcClass.longName.val; // If it's a delegate, maybe we can look up its script-defined type name. Type ot = o.GetType(); if(o is Delegate) { - String os; - if(m_ObjCode.sdDelTypes.TryGetValue(ot, out os)) + if(m_ObjCode.sdDelTypes.TryGetValue(ot, out string os)) return os; } @@ -842,7 +838,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine object[] data = ev.Data; int evc = (int)(ev.GetLSLIntegerItem(0).value & 0xFFFFFFFF); ScriptEventHandler seh = m_ObjCode.scriptEventHandlerTable[stateCode, evc]; - if(seh != null) + if(seh is not null) { int nargs = data.Length - 1; object[] args = new object[nargs]; @@ -851,13 +847,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine object[] saveEHArgs = this.ehArgs; ScriptEventCode saveEventCode = this.eventCode; - this.ehArgs = args; - this.eventCode = (ScriptEventCode)evc; + ehArgs = args; + eventCode = (ScriptEventCode)evc; seh(this); - this.ehArgs = saveEHArgs; - this.eventCode = saveEventCode; + ehArgs = saveEHArgs; + eventCode = saveEventCode; } } @@ -969,9 +965,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine TokenDeclSDType sdType = inst.m_ObjCode.sdObjTypesIndx[sdtypeindex]; // If it is a script-defined interface object, convert to the original XMRSDTypeClObj. - if(thrown is Delegate[]) + if(thrown is Delegate[] dt) { - thrown = ((Delegate[])thrown)[0].Target; + thrown = dt[0].Target; } // If it is a script-defined delegate object, make sure it is an instance of the expected type. @@ -983,12 +979,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine } // If it is a script-defined class object, make sure it is an instance of the expected class. - if(thrown is XMRSDTypeClObj) + if(thrown is XMRSDTypeClObj XMRSDTypeClObjthrown) { // Step from the object's actual class rootward. // If we find the requested class along the way, the cast is valid. // If we run off the end of the root, the cast is not valid. - for(TokenDeclSDTypeClass ac = ((XMRSDTypeClObj)thrown).sdtcClass; ac != null; ac = ac.extends) + for(TokenDeclSDTypeClass ac = XMRSDTypeClObjthrown.sdtcClass; ac is not null; ac = ac.extends) { if(ac == sdType) return thrown; @@ -1130,14 +1126,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine object src = srcarray.GetValue(i + start); if(src == null) throw new NullReferenceException("null element " + i); - if(src is double) + if(src is double dsrc) { - output[i] = new LSL_Float((double)src); + output[i] = new LSL_Float(dsrc); continue; } - if(src is int) + if(src is int isrc) { - output[i] = new LSL_Integer((int)src); + output[i] = new LSL_Integer(isrc); continue; } if(src is LSL_Rotation) @@ -1150,9 +1146,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine output[i] = src; continue; } - if(src is string) + if(src is string ssrc) { - output[i] = new LSL_String((string)src); + output[i] = new LSL_String(ssrc); continue; } throw new InvalidCastException("invalid element " + i + " type " + src.GetType().Name); @@ -1187,12 +1183,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine for(int i = 0; i < count; i++) { object obj = srcarr[i + srcstart]; - if(obj is LSL_Float) - obj = ((LSL_Float)obj).value; - else if(obj is LSL_Integer) - obj = ((LSL_Integer)obj).value; - else if(obj is LSL_String) - obj = ((LSL_String)obj).m_string; + if(obj is LSL_Float lfo) + obj = lfo.value; + else if(obj is LSL_Integer lio) + obj = lio.value; + else if(obj is LSL_String lso) + obj = lso.m_string; dstarr.SetValue(obj, i + dststart); } } @@ -1491,32 +1487,32 @@ namespace OpenSim.Region.ScriptEngine.Yengine { try { - this.migrateOutWriter = mow; - this.migrateOutObjects = new Dictionary(); - this.migrateOutLists = new Dictionary(); - this.SendObjValue(this.ehArgs); - mow.Write(this.doGblInit); - mow.Write(this.stateCode); - mow.Write((int)this.eventCode); - this.glblVars.SendArrays(this.SendObjValue); - if(this.newStateCode >= 0) + migrateOutWriter = mow; + migrateOutObjects = new Dictionary(); + migrateOutLists = new Dictionary(); + SendObjValue(ehArgs); + mow.Write(doGblInit); + mow.Write(stateCode); + mow.Write((int)eventCode); + glblVars.SendArrays(SendObjValue); + if(newStateCode >= 0) { mow.Write("**newStateCode**"); - mow.Write(this.newStateCode); + mow.Write(newStateCode); } - for(XMRStackFrame thisSF = this.stackFrames; thisSF != null; thisSF = thisSF.nextSF) + for(XMRStackFrame thisSF = stackFrames; thisSF is not null; thisSF = thisSF.nextSF) { mow.Write(thisSF.funcName); mow.Write(thisSF.callNo); - this.SendObjValue(thisSF.objArray); + SendObjValue(thisSF.objArray); } mow.Write(""); } finally { - this.migrateOutWriter = null; - this.migrateOutObjects = null; - this.migrateOutLists = null; + migrateOutWriter = null; + migrateOutObjects = null; + migrateOutLists = null; } } @@ -1529,10 +1525,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine private Dictionary migrateOutLists; public void SendObjValue(object graph) { - BinaryWriter mow = this.migrateOutWriter; + BinaryWriter mow = migrateOutWriter; // Value types (including nulls) are always output directly. - if(graph == null) + if(graph is null) { mow.Write((byte)Ser.NULL); return; @@ -1543,47 +1539,45 @@ namespace OpenSim.Region.ScriptEngine.Yengine mow.Write((int)graph); return; } - if(graph is LSL_Float) + if(graph is LSL_Float lfg) { mow.Write((byte)Ser.LSLFLOAT); - mow.Write((double)((LSL_Float)graph).value); + mow.Write(lfg.value); return; } - if(graph is LSL_Integer) + if(graph is LSL_Integer lig) { mow.Write((byte)Ser.LSLINT); - mow.Write((int)((LSL_Integer)graph).value); + mow.Write(lig.value); return; } - if(graph is LSL_Key) + if(graph is LSL_Key lkg) { mow.Write((byte)Ser.LSLKEY); - LSL_Key key = (LSL_Key)graph; - SendObjValue(key.m_string); // m_string can be null + SendObjValue(lkg.m_string); // m_string can be null return; } - if(graph is LSL_Rotation) + if(graph is LSL_Rotation lrg) { mow.Write((byte)Ser.LSLROT); - mow.Write((double)((LSL_Rotation)graph).x); - mow.Write((double)((LSL_Rotation)graph).y); - mow.Write((double)((LSL_Rotation)graph).z); - mow.Write((double)((LSL_Rotation)graph).s); + mow.Write(lrg.x); + mow.Write(lrg.y); + mow.Write(lrg.z); + mow.Write(lrg.s); return; } - if(graph is LSL_String) + if(graph is LSL_String lsg) { mow.Write((byte)Ser.LSLSTR); - LSL_String str = (LSL_String)graph; - SendObjValue(str.m_string); // m_string can be null + SendObjValue(lsg.m_string); // m_string can be null return; } - if(graph is LSL_Vector) + if(graph is LSL_Vector lvg) { mow.Write((byte)Ser.LSLVEC); - mow.Write((double)((LSL_Vector)graph).x); - mow.Write((double)((LSL_Vector)graph).y); - mow.Write((double)((LSL_Vector)graph).z); + mow.Write(lvg.x); + mow.Write(lvg.y); + mow.Write(lvg.z); return; } if(graph is bool) @@ -1592,28 +1586,28 @@ namespace OpenSim.Region.ScriptEngine.Yengine mow.Write((bool)graph); return; } - if(graph is double) + if(graph is double dg) { mow.Write((byte)Ser.SYSDOUB); mow.Write((double)graph); return; } - if(graph is float) + if(graph is float fg) { mow.Write((byte)Ser.SYSFLOAT); - mow.Write((float)graph); + mow.Write(fg); return; } - if(graph is int) + if(graph is int ig) { mow.Write((byte)Ser.SYSINT); mow.Write((int)graph); return; } - if(graph is char) + if(graph is char cg) { mow.Write((byte)Ser.SYSCHAR); - mow.Write((char)graph); + mow.Write(cg); return; } @@ -1627,17 +1621,16 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Convert lists to object type. // This is compatible with old migration data and also // two vars pointing to same list won't duplicate it. - if(graph is LSL_List) + if(graph is LSL_List llg) { - object[] data = ((LSL_List)graph).Data; - ObjLslList oll; - if(!this.migrateOutLists.TryGetValue(data, out oll)) + object[] data = llg.Data; + if(!migrateOutLists.TryGetValue(data, out ObjLslList ollg)) { - oll = new ObjLslList(); - oll.objarray = data; - this.migrateOutLists[data] = oll; + ollg = new ObjLslList(); + ollg.objarray = data; + migrateOutLists[data] = ollg; } - graph = oll; + graph = ollg; } // If this same exact object was already serialized, @@ -1646,8 +1639,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // new object with the same values. Also this prevents // self-referencing objects (like arrays) from causing // an infinite loop. - int ident; - if(this.migrateOutObjects.TryGetValue(graph, out ident)) + if(migrateOutObjects.TryGetValue(graph, out int ident)) { mow.Write((byte)Ser.DUPREF); mow.Write(ident); @@ -1656,51 +1648,47 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Object not seen before, save its address with an unique // ident number that the receiver can easily regenerate. - ident = this.migrateOutObjects.Count; - this.migrateOutObjects.Add(graph, ident); + ident = migrateOutObjects.Count; + migrateOutObjects.Add(graph, ident); // Now output the object's value(s). // If the object self-references, the object is alreay entered // in the dictionary and so the self-reference will just emit // a DUPREF tag instead of trying to output the whole object // again. - if(graph is ObjLslList) + if(graph is ObjLslList oll) { mow.Write((byte)Ser.LSLLIST); - ObjLslList oll = (ObjLslList)graph; SendObjValue(oll.objarray); } - else if(graph is XMR_Array) + else if(graph is XMR_Array xg) { mow.Write((byte)Ser.XMRARRAY); - ((XMR_Array)graph).SendArrayObj(this.SendObjValue); + xg.SendArrayObj(SendObjValue); } - else if(graph is Array) + else if(graph is Array array) { - Array array = (Array)graph; mow.Write((byte)Ser.SYSARRAY); mow.Write(SysType2String(array.GetType().GetElementType())); - mow.Write((int)array.Length); + mow.Write(array.Length); for(int i = 0; i < array.Length; i++) - this.SendObjValue(array.GetValue(i)); + SendObjValue(array.GetValue(i)); } - else if(graph is string) + else if(graph is string sg) { mow.Write((byte)Ser.SYSSTR); - mow.Write((string)graph); + mow.Write(sg); } - else if(graph is Delegate) + else if(graph is Delegate del) { - Delegate del = (Delegate)graph; mow.Write((byte)Ser.DELEGATE); mow.Write(del.Method.Name); Type delType = del.GetType(); foreach(KeyValuePair kvp in m_ObjCode.sdObjTypesName) { TokenDeclSDType sdt = kvp.Value; - if(sdt is TokenDeclSDTypeDelegate) + if(sdt is TokenDeclSDTypeDelegate sdtd) { - TokenDeclSDTypeDelegate sdtd = (TokenDeclSDTypeDelegate)sdt; if(sdtd.GetSysType() == delType) { mow.Write(kvp.Key); @@ -1712,12 +1700,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine found: SendObjValue(del.Target); } - else if(graph is XMRSDTypeClObj) + else if(graph is XMRSDTypeClObj XMRSDTypeClObjgraph) { mow.Write((byte)Ser.SDTCLOBJ); - ((XMRSDTypeClObj)graph).Capture(this.SendObjValue); + XMRSDTypeClObjgraph.Capture(this.SendObjValue); } - else if(graph is ScriptThrownException) + else if(graph is ScriptThrownException ScriptThrownExceptiongraph) { MemoryStream memoryStream = new MemoryStream(); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter = @@ -1727,7 +1715,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine mow.Write((byte)Ser.THROWNEX); mow.Write((int)rawBytes.Length); mow.Write(rawBytes); - SendObjValue(((ScriptThrownException)graph).thrown); + SendObjValue(ScriptThrownExceptiongraph.thrown); } else { @@ -1737,7 +1725,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine bformatter.Serialize(memoryStream, graph); byte[] rawBytes = memoryStream.ToArray(); mow.Write((byte)Ser.SYSERIAL); - mow.Write((int)rawBytes.Length); + mow.Write(rawBytes.Length); mow.Write(rawBytes); } } @@ -1750,13 +1738,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine if(type.IsArray && (type.GetArrayRank() == 1)) { string str = KnownSysType2String(type.GetElementType()); - if(str != null) + if(str is not null) return str + "[]"; } else { string str = KnownSysType2String(type); - if(str != null) + if(str is not null) return str; } return type.ToString(); @@ -1832,29 +1820,29 @@ namespace OpenSim.Region.ScriptEngine.Yengine { try { - this.migrateInReader = mir; - this.migrateInObjects = new Dictionary(); - this.ehArgs = (object[])this.RecvObjValue(); - this.doGblInit = mir.ReadBoolean(); - this.stateCode = mir.ReadInt32(); - this.eventCode = (ScriptEventCode)mir.ReadInt32(); - this.newStateCode = -1; - this.glblVars.RecvArrays(this.RecvObjValue); + migrateInReader = mir; + migrateInObjects = new Dictionary(); + ehArgs = (object[])RecvObjValue(); + doGblInit = mir.ReadBoolean(); + stateCode = mir.ReadInt32(); + eventCode = (ScriptEventCode)mir.ReadInt32(); + newStateCode = -1; + glblVars.RecvArrays(RecvObjValue); XMRStackFrame lastSF = null; string funcName; while((funcName = mir.ReadString()) != "") { if(funcName == "**newStateCode**") { - this.newStateCode = mir.ReadInt32(); + newStateCode = mir.ReadInt32(); continue; } XMRStackFrame thisSF = new XMRStackFrame(); thisSF.funcName = funcName; thisSF.callNo = mir.ReadInt32(); - thisSF.objArray = (object[])this.RecvObjValue(); + thisSF.objArray = (object[])RecvObjValue(); if(lastSF == null) - this.stackFrames = thisSF; + stackFrames = thisSF; else lastSF.nextSF = thisSF; lastSF = thisSF; @@ -1862,8 +1850,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine } finally { - this.migrateInReader = null; - this.migrateInObjects = null; + migrateInReader = null; + migrateInObjects = null; } } diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstBackend.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstBackend.cs index bdb9f32b5d..992783f2fd 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstBackend.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstBackend.cs @@ -413,12 +413,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine for(int i = 0; i < plen;) { object ob = evt.Params[i]; - if(ob is int) - ob = (LSL_Integer)(int)ob; - else if(ob is double) - ob = (LSL_Float)(double)ob; - else if(ob is string) - ob = (LSL_String)(string)ob; + if(ob is int iob) + ob = (LSL_Integer)iob; + else if(ob is double dob) + ob = (LSL_Float)dob; + else if(ob is string sob) + ob = (LSL_String)sob; plist[++i] = ob; } m_DetectParams = evt.DetectParams; diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCapture.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCapture.cs index 1abaca4a3d..5b144b3b27 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCapture.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCapture.cs @@ -116,7 +116,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine //m_RunOnePhase = "GetExecutionState D"; CheckRunLockInvariants(true); - if(m_XMRLSLApi != null) + if(m_XMRLSLApi is not null) { double scriptTime = Util.GetTimeStampMS() - m_XMRLSLApi.getLSLTimer(); XmlElement scriptTimeN = doc.CreateElement("", "scrpTime", ""); @@ -150,7 +150,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // "DetectParams" are returned by llDetected...() script functions // for the currently active event, if any. var detectParams = m_DetectParams; - if (detectParams != null) + if (detectParams is not null) { XmlElement detParArrayN = doc.CreateElement("", "DetectArray", ""); AppendXMLDetectArray(doc, detParArrayN, detectParams); @@ -184,8 +184,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine CheckRunLockInvariants(true); // "Plugins" indicate enabled timers and listens, etc. - Object[] pluginData = - AsyncCommandManager.GetSerializationData(m_Engine, m_ItemID); + Object[] pluginData = AsyncCommandManager.GetSerializationData(m_Engine, m_ItemID); XmlNode plugins = doc.CreateElement("", "Plugins", ""); AppendXMLObjectArray(doc, plugins, pluginData, "plugin"); @@ -222,7 +221,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Does not change script state. stream.WriteByte(migrationVersion); stream.WriteByte((byte)16); - this.MigrateOut(new BinaryWriter(stream)); + MigrateOut(new BinaryWriter(stream)); } /** diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs index e1e95c6964..4ff696d5ed 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs @@ -666,68 +666,65 @@ namespace OpenSim.Region.ScriptEngine.Yengine XmlNodeList varL = part.ChildNodes; foreach (XmlNode var in varL) { - string varName; - object o = ReadXTypedValue(var, out varName); - Type otype = o.GetType(); - if (otype == typeof(LSL_Integer)) + object o = ReadXTypedValue(var, out string varName); + if (o is LSL_Integer lio) { if (intNames.TryGetValue(varName, out indx)) - ints[indx] = ((LSL_Integer)o); + ints[indx] = lio; continue; } - if (otype == typeof(LSL_Float)) + if (o is LSL_Float lfo) { if (doubleNames.TryGetValue(varName, out indx)) - doubles[indx] = ((LSL_Float)o); + doubles[indx] = lfo; continue; } - if (otype == typeof(LSL_String)) + if (o is LSL_String lso) { if (stringNames.TryGetValue(varName, out indx)) { - strings[indx] = ((LSL_String)o); - heapsz += ((LSL_String)o).Length; + strings[indx] = lso; + heapsz += lso.Length; } continue; } - if (otype == typeof(LSL_Rotation)) + if (o is LSL_Rotation lro) { if (rotationNames.TryGetValue(varName, out indx)) - rotations[indx] = ((LSL_Rotation)o); + rotations[indx] = lro; continue; } - if (otype == typeof(LSL_Vector)) + if (o is LSL_Vector lvo) { if (vectorNames.TryGetValue(varName, out indx)) - vectors[indx] = ((LSL_Vector)o); + vectors[indx] = lvo; continue; } - if (otype == typeof(LSL_Key)) + if (o is LSL_Key lko) { if (stringNames.TryGetValue(varName, out indx)) { - strings[indx] = ((LSL_Key)o); - heapsz += ((LSL_String)o).Length; + strings[indx] = lko; + heapsz += lko.Length; } continue; } - if (otype == typeof(UUID)) + if (o is UUID uo) { if (stringNames.TryGetValue(varName, out indx)) { - LSL_String id = ((UUID)o).ToString(); - strings[indx] = (id); + LSL_String id = uo.ToString(); + strings[indx] = id; heapsz += id.Length; } continue; } - if (otype == typeof(LSL_List)) + if (o is LSL_List llo) { if (listNames.TryGetValue(varName, out indx)) { - LSL_List lo = (LSL_List)o; - lists[indx] = (lo); - heapsz += lo.Size; + lists[indx] = (llo); + heapsz += llo.Size; } continue; }