aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUbitUmarov2018-02-03 08:08:59 +0000
committerUbitUmarov2018-02-03 08:08:59 +0000
commit04a8ec518d5d7d8b69b62cd31c192c60d953b6df (patch)
tree62f0d7556770ac8fb357d7345946f260bd09049c
parentupdate opensim.ini.example with XMRengine information (diff)
downloadopensim-SC-04a8ec518d5d7d8b69b62cd31c192c60d953b6df.zip
opensim-SC-04a8ec518d5d7d8b69b62cd31c192c60d953b6df.tar.gz
opensim-SC-04a8ec518d5d7d8b69b62cd31c192c60d953b6df.tar.bz2
opensim-SC-04a8ec518d5d7d8b69b62cd31c192c60d953b6df.tar.xz
XMR: there is no need for a slice thread, it also causes timing issues; BelowNormal mb 2 Below on win; cosmetics
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMREngine.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs397
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMRInstBackend.cs86
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs1
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMRInstRun.cs85
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs17
6 files changed, 353 insertions, 237 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMREngine.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMREngine.cs
index 24d49f8..5889451 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMREngine.cs
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMREngine.cs
@@ -250,7 +250,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
250 } 250 }
251 251
252 m_SleepThread = StartMyThread (RunSleepThread, "xmrengine sleep", ThreadPriority.Normal); 252 m_SleepThread = StartMyThread (RunSleepThread, "xmrengine sleep", ThreadPriority.Normal);
253 m_SliceThread = StartMyThread (RunSliceThread, "xmrengine slice", ThreadPriority.Normal); 253// m_SliceThread = StartMyThread (RunSliceThread, "xmrengine slice", ThreadPriority.Normal);
254 254
255 /* 255 /*
256 * Verify that our ScriptEventCode's match OpenSim's scriptEvent's. 256 * Verify that our ScriptEventCode's match OpenSim's scriptEvent's.
@@ -895,8 +895,10 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
895 m_log.Error("[XMREngine]: XMREngine.SaveAllState() called!!"); 895 m_log.Error("[XMREngine]: XMREngine.SaveAllState() called!!");
896 } 896 }
897 897
898#pragma warning disable 0067
898 public event ScriptRemoved OnScriptRemoved; 899 public event ScriptRemoved OnScriptRemoved;
899 public event ObjectRemoved OnObjectRemoved; 900 public event ObjectRemoved OnObjectRemoved;
901#pragma warning restore 0067
900 902
901 // Events targeted at a specific script 903 // Events targeted at a specific script
902 // ... like listen() for an llListen() call 904 // ... like listen() for an llListen() call
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs
index 802eac2..fbdf1bf 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs
@@ -63,7 +63,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
63 63
64 private static readonly XMR_Array[] noArrays = new XMR_Array[0]; 64 private static readonly XMR_Array[] noArrays = new XMR_Array[0];
65 private static readonly char[] noChars = new char[0]; 65 private static readonly char[] noChars = new char[0];
66 private static readonly double[] noFloats = new double[0]; 66 private static readonly double[] noFloats = new double[0];
67 private static readonly int[] noIntegers = new int[0]; 67 private static readonly int[] noIntegers = new int[0];
68 private static readonly LSL_List[] noLists = new LSL_List[0]; 68 private static readonly LSL_List[] noLists = new LSL_List[0];
69 private static readonly object[] noObjects = new object[0]; 69 private static readonly object[] noObjects = new object[0];
@@ -97,7 +97,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
97 97
98 iarArrays = (ars.iasArrays > 0) ? new XMR_Array [ars.iasArrays] : noArrays; 98 iarArrays = (ars.iasArrays > 0) ? new XMR_Array [ars.iasArrays] : noArrays;
99 iarChars = (ars.iasChars > 0) ? new char [ars.iasChars] : noChars; 99 iarChars = (ars.iasChars > 0) ? new char [ars.iasChars] : noChars;
100 iarFloats = (ars.iasFloats > 0) ? new double [ars.iasFloats] : noFloats; 100 iarFloats = (ars.iasFloats > 0) ? new double [ars.iasFloats] : noFloats;
101 iarIntegers = (ars.iasIntegers > 0) ? new int [ars.iasIntegers] : noIntegers; 101 iarIntegers = (ars.iasIntegers > 0) ? new int [ars.iasIntegers] : noIntegers;
102 iarLists = (ars.iasLists > 0) ? new LSL_List [ars.iasLists] : noLists; 102 iarLists = (ars.iasLists > 0) ? new LSL_List [ars.iasLists] : noLists;
103 iarObjects = (ars.iasObjects > 0) ? new object [ars.iasObjects] : noObjects; 103 iarObjects = (ars.iasObjects > 0) ? new object [ars.iasObjects] : noObjects;
@@ -170,7 +170,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
170 170
171 iarArrays = (XMR_Array[]) recver (); 171 iarArrays = (XMR_Array[]) recver ();
172 char[] chrs = (char[]) recver (); 172 char[] chrs = (char[]) recver ();
173 double[] flts = (double[]) recver (); 173 double[] flts = (double[]) recver ();
174 int[] ints = (int[]) recver (); 174 int[] ints = (int[]) recver ();
175 LSL_List[] liss = (LSL_List[]) recver (); 175 LSL_List[] liss = (LSL_List[]) recver ();
176 object[] objs = (object[]) recver (); 176 object[] objs = (object[]) recver ();
@@ -191,15 +191,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
191 newheapuse += dels.Length * HeapTrackerObject.HT_DELE; 191 newheapuse += dels.Length * HeapTrackerObject.HT_DELE;
192 192
193 // lists, objects, strings are the sum of the size of each element 193 // lists, objects, strings are the sum of the size of each element
194 foreach (LSL_List lis in liss) { 194 foreach (LSL_List lis in liss)
195 newheapuse += HeapTrackerList.Size (lis); 195 newheapuse += HeapTrackerList.Size (lis);
196 } 196
197 foreach (object obj in objs) { 197 foreach (object obj in objs)
198 newheapuse += HeapTrackerObject.Size (obj); 198 newheapuse += HeapTrackerObject.Size (obj);
199 } 199
200 foreach (string str in strs) { 200 foreach (string str in strs)
201 newheapuse += HeapTrackerString.Size (str); 201 newheapuse += HeapTrackerString.Size (str);
202 }
203 202
204 // others (XMR_Array, XMRSDTypeClObj) keep track of their own heap usage 203 // others (XMR_Array, XMRSDTypeClObj) keep track of their own heap usage
205 204
@@ -222,46 +221,55 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
222 int newheapuse = heapUse; 221 int newheapuse = heapUse;
223 222
224 iarArrays = null; 223 iarArrays = null;
225 if (iarChars != null) { 224 if (iarChars != null)
225 {
226 newheapuse -= iarChars.Length * HeapTrackerObject.HT_CHAR; 226 newheapuse -= iarChars.Length * HeapTrackerObject.HT_CHAR;
227 iarChars = null; 227 iarChars = null;
228 } 228 }
229 if (iarFloats != null) { 229 if (iarFloats != null)
230 {
230 newheapuse -= iarFloats.Length * HeapTrackerObject.HT_SFLT; 231 newheapuse -= iarFloats.Length * HeapTrackerObject.HT_SFLT;
231 iarFloats = null; 232 iarFloats = null;
232 } 233 }
233 if (iarIntegers != null) { 234 if (iarIntegers != null)
235 {
234 newheapuse -= iarIntegers.Length * HeapTrackerObject.HT_INT; 236 newheapuse -= iarIntegers.Length * HeapTrackerObject.HT_INT;
235 iarIntegers = null; 237 iarIntegers = null;
236 } 238 }
237 if (iarLists != null) { 239 if (iarLists != null)
238 foreach (LSL_List lis in iarLists) { 240 {
241 foreach (LSL_List lis in iarLists)
239 newheapuse -= HeapTrackerList.Size (lis); 242 newheapuse -= HeapTrackerList.Size (lis);
240 } 243
241 iarLists = null; 244 iarLists = null;
242 } 245 }
243 if (iarObjects != null) { 246 if (iarObjects != null)
244 foreach (object obj in iarObjects) { 247 {
248 foreach (object obj in iarObjects)
245 newheapuse -= HeapTrackerObject.Size (obj); 249 newheapuse -= HeapTrackerObject.Size (obj);
246 } 250
247 iarObjects = null; 251 iarObjects = null;
248 } 252 }
249 if (iarRotations != null) { 253 if (iarRotations != null)
254 {
250 newheapuse -= iarRotations.Length * HeapTrackerObject.HT_ROT; 255 newheapuse -= iarRotations.Length * HeapTrackerObject.HT_ROT;
251 iarRotations = null; 256 iarRotations = null;
252 } 257 }
253 if (iarStrings != null) { 258 if (iarStrings != null)
254 foreach (string str in iarStrings) { 259 {
260 foreach (string str in iarStrings)
255 newheapuse -= HeapTrackerString.Size (str); 261 newheapuse -= HeapTrackerString.Size (str);
256 } 262
257 iarStrings = null; 263 iarStrings = null;
258 } 264 }
259 if (iarVectors != null) { 265 if (iarVectors != null)
266 {
260 newheapuse -= iarVectors.Length * HeapTrackerObject.HT_VEC; 267 newheapuse -= iarVectors.Length * HeapTrackerObject.HT_VEC;
261 iarVectors = null; 268 iarVectors = null;
262 } 269 }
263 iarSDTClObjs = null; 270 iarSDTClObjs = null;
264 if (iarSDTIntfObjs != null) { 271 if (iarSDTIntfObjs != null)
272 {
265 newheapuse -= iarSDTIntfObjs.Length * HeapTrackerObject.HT_DELE; 273 newheapuse -= iarSDTIntfObjs.Length * HeapTrackerObject.HT_DELE;
266 iarSDTIntfObjs = null; 274 iarSDTIntfObjs = null;
267 } 275 }
@@ -270,7 +278,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
270 } 278 }
271 } 279 }
272 280
273 public class XMRInstArSizes { 281 public class XMRInstArSizes
282 {
274 public int iasArrays; 283 public int iasArrays;
275 public int iasChars; 284 public int iasChars;
276 public int iasFloats; 285 public int iasFloats;
@@ -327,7 +336,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
327 } 336 }
328 } 337 }
329 338
330 public class XMRStackFrame { 339 public class XMRStackFrame
340 {
331 public XMRStackFrame nextSF; 341 public XMRStackFrame nextSF;
332 public string funcName; 342 public string funcName;
333 public int callNo; 343 public int callNo;
@@ -478,8 +488,10 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
478 callMode = (stackFrames == null) ? XMRInstAbstract.CallMode_NORMAL : 488 callMode = (stackFrames == null) ? XMRInstAbstract.CallMode_NORMAL :
479 XMRInstAbstract.CallMode_RESTORE; 489 XMRInstAbstract.CallMode_RESTORE;
480 490
481 while (true) { 491 while (true)
482 if (this.newStateCode < 0) { 492 {
493 if (this.newStateCode < 0)
494 {
483 495
484 /* 496 /*
485 * Process event given by 'stateCode' and 'eventCode'. 497 * Process event given by 'stateCode' and 'eventCode'.
@@ -487,10 +499,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
487 */ 499 */
488 int newState = this.stateCode; 500 int newState = this.stateCode;
489 seh = this.m_ObjCode.scriptEventHandlerTable[newState,(int)this.eventCode]; 501 seh = this.m_ObjCode.scriptEventHandlerTable[newState,(int)this.eventCode];
490 if (seh != null) { 502 if (seh != null)
491 try { 503 {
504 try
505 {
492 seh (this); 506 seh (this);
493 } catch (ScriptChangeStateException scse) { 507 }
508 catch (ScriptChangeStateException scse)
509 {
494 newState = scse.newState; 510 newState = scse.newState;
495 } 511 }
496 } 512 }
@@ -503,7 +519,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
503 * It does not execute the state_exit() or state_entry() handlers. 519 * It does not execute the state_exit() or state_entry() handlers.
504 * See http://wiki.secondlife.com/wiki/State 520 * See http://wiki.secondlife.com/wiki/State
505 */ 521 */
506 if (newState == this.stateCode) break; 522 if (newState == this.stateCode)
523 break;
507 524
508 /* 525 /*
509 * Save new state in a more permanent location in case we 526 * Save new state in a more permanent location in case we
@@ -517,10 +534,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
517 */ 534 */
518 this.eventCode = ScriptEventCode.state_exit; 535 this.eventCode = ScriptEventCode.state_exit;
519 seh = this.m_ObjCode.scriptEventHandlerTable[this.stateCode,(int)ScriptEventCode.state_exit]; 536 seh = this.m_ObjCode.scriptEventHandlerTable[this.stateCode,(int)ScriptEventCode.state_exit];
520 if (seh != null) { 537 if (seh != null)
521 try { 538 {
539 try
540 {
522 seh (this); 541 seh (this);
523 } catch (ScriptChangeStateException scse) { 542 }
543 catch (ScriptChangeStateException scse)
544 {
524 this.newStateCode = scse.newState; 545 this.newStateCode = scse.newState;
525 } 546 }
526 } 547 }
@@ -563,7 +584,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
563 */ 584 */
564 public void CheckRunStack () 585 public void CheckRunStack ()
565 { 586 {
566 if (xmrStackLeft () < stackLimit) { 587 if (xmrStackLeft () < stackLimit)
588 {
567 throw new OutOfStackException (); 589 throw new OutOfStackException ();
568 } 590 }
569 CheckRunQuick (); 591 CheckRunQuick ();
@@ -574,9 +596,9 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
574 */ 596 */
575 public void CheckRunQuick () 597 public void CheckRunQuick ()
576 { 598 {
577 if (suspendOnCheckRunHold || suspendOnCheckRunTemp) { 599// if (suspendOnCheckRunHold || suspendOnCheckRunTemp) {
578 CheckRunWork (); 600 CheckRunWork ();
579 } 601// }
580 } 602 }
581 603
582 /** 604 /**
@@ -608,7 +630,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
608 public object[] RestoreStackFrame (string funcName, out int callNo) 630 public object[] RestoreStackFrame (string funcName, out int callNo)
609 { 631 {
610 XMRStackFrame sf = stackFrames; 632 XMRStackFrame sf = stackFrames;
611 if (sf.funcName != funcName) { 633 if (sf.funcName != funcName)
634 {
612 throw new Exception ("frame mismatch " + sf.funcName + " vs " + funcName); 635 throw new Exception ("frame mismatch " + sf.funcName + " vs " + funcName);
613 } 636 }
614 callNo = sf.callNo; 637 callNo = sf.callNo;
@@ -625,7 +648,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
625 object[] oldarray = oldlist.Data; 648 object[] oldarray = oldlist.Data;
626 int len = oldarray.Length; 649 int len = oldarray.Length;
627 object[] newarray = new object[len]; 650 object[] newarray = new object[len];
628 for (int i = 0; i < len; i ++) { 651 for (int i = 0; i < len; i ++)
652 {
629 object obj = oldarray[i]; 653 object obj = oldarray[i];
630 if (obj is LSL_Integer) obj = (int)(LSL_Integer)obj; 654 if (obj is LSL_Integer) obj = (int)(LSL_Integer)obj;
631 newarray[i] = obj; 655 newarray[i] = obj;
@@ -643,18 +667,25 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
643 int len = oldarray.Length; 667 int len = oldarray.Length;
644 object[] newarray = new object[len]; 668 object[] newarray = new object[len];
645 int verbatim = 0; 669 int verbatim = 0;
646 for (int i = 0; i < len; i ++) { 670 for (int i = 0; i < len; i ++)
671 {
647 object obj = oldarray[i]; 672 object obj = oldarray[i];
648 if (-- verbatim < 0) { 673 if (-- verbatim < 0)
649 if (obj is LSL_Integer) obj = (int)(LSL_Integer)obj; 674 {
650 if (obj is int) { 675 if (obj is LSL_Integer)
651 switch ((int)obj) { 676 obj = (int)(LSL_Integer)obj;
652 case ScriptBaseClass.PARCEL_MEDIA_COMMAND_AUTO_ALIGN: { 677 if (obj is int)
678 {
679 switch ((int)obj)
680 {
681 case ScriptBaseClass.PARCEL_MEDIA_COMMAND_AUTO_ALIGN:
682 {
653 // leave next integer as LSL_Integer 683 // leave next integer as LSL_Integer
654 verbatim = 1; 684 verbatim = 1;
655 break; 685 break;
656 } 686 }
657 case ScriptBaseClass.PARCEL_MEDIA_COMMAND_SIZE: { 687 case ScriptBaseClass.PARCEL_MEDIA_COMMAND_SIZE:
688 {
658 // leave next two integers as LSL_Integer 689 // leave next two integers as LSL_Integer
659 verbatim = 2; 690 verbatim = 2;
660 break; 691 break;
@@ -715,7 +746,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
715 * class that is implementing the interface. This should let the next 746 * class that is implementing the interface. This should let the next
716 * step get the script-defined type name of the object. 747 * step get the script-defined type name of the object.
717 */ 748 */
718 if (o is Delegate[]) { 749 if (o is Delegate[])
750 {
719 o = ((Delegate[])o)[0].Target; 751 o = ((Delegate[])o)[0].Target;
720 } 752 }
721 753
@@ -723,7 +755,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
723 * If script-defined class instance, get the script-defined 755 * If script-defined class instance, get the script-defined
724 * type name. 756 * type name.
725 */ 757 */
726 if (o is XMRSDTypeClObj) { 758 if (o is XMRSDTypeClObj)
759 {
727 return ((XMRSDTypeClObj)o).sdtcClass.longName.val; 760 return ((XMRSDTypeClObj)o).sdtcClass.longName.val;
728 } 761 }
729 762
@@ -731,7 +764,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
731 * If it's a delegate, maybe we can look up its script-defined type name. 764 * If it's a delegate, maybe we can look up its script-defined type name.
732 */ 765 */
733 Type ot = o.GetType (); 766 Type ot = o.GetType ();
734 if (o is Delegate) { 767 if (o is Delegate)
768 {
735 String os; 769 String os;
736 if (m_ObjCode.sdDelTypes.TryGetValue (ot, out os)) return os; 770 if (m_ObjCode.sdDelTypes.TryGetValue (ot, out os)) return os;
737 } 771 }
@@ -754,7 +788,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
754 object[] data = ev.Data; 788 object[] data = ev.Data;
755 int evc = (int)(ev.GetLSLIntegerItem (0).value & 0xFFFFFFFF); 789 int evc = (int)(ev.GetLSLIntegerItem (0).value & 0xFFFFFFFF);
756 ScriptEventHandler seh = m_ObjCode.scriptEventHandlerTable[stateCode,evc]; 790 ScriptEventHandler seh = m_ObjCode.scriptEventHandlerTable[stateCode,evc];
757 if (seh != null) { 791 if (seh != null)
792 {
758 int nargs = data.Length - 1; 793 int nargs = data.Length - 1;
759 object[] args = new object[nargs]; 794 object[] args = new object[nargs];
760 Array.Copy (data, 1, args, 0, nargs); 795 Array.Copy (data, 1, args, 0, nargs);
@@ -777,23 +812,30 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
777 */ 812 */
778 public string xmrSubstring (string s, int offset) 813 public string xmrSubstring (string s, int offset)
779 { 814 {
780 if (offset >= s.Length) return ""; 815 if (offset >= s.Length)
816 return "";
781 return s.Substring (offset); 817 return s.Substring (offset);
782 } 818 }
783 // C# style 819 // C# style
784 public string xmrSubstring (string s, int offset, int length) 820 public string xmrSubstring (string s, int offset, int length)
785 { 821 {
786 if (length <= 0) return ""; 822 if (length <= 0)
787 if (offset >= s.Length) return ""; 823 return "";
788 if (length > s.Length - offset) length = s.Length - offset; 824 if (offset >= s.Length)
825 return "";
826 if (length > s.Length - offset)
827 length = s.Length - offset;
789 return s.Substring (offset, length); 828 return s.Substring (offset, length);
790 } 829 }
791 // java style 830 // java style
792 public string xmrJSubstring (string s, int beg, int end) 831 public string xmrJSubstring (string s, int beg, int end)
793 { 832 {
794 if (end <= beg) return ""; 833 if (end <= beg)
795 if (beg >= s.Length) return ""; 834 return "";
796 if (end > s.Length) end = s.Length; 835 if (beg >= s.Length)
836 return "";
837 if (end > s.Length)
838 end = s.Length;
797 return s.Substring (beg, end - beg); 839 return s.Substring (beg, end - beg);
798 } 840 }
799 841
@@ -839,22 +881,22 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
839 public int xmrString2Integer (string s) 881 public int xmrString2Integer (string s)
840 { 882 {
841 s = s.Trim (); 883 s = s.Trim ();
842 if (s.StartsWith ("0x") || s.StartsWith ("0X")) { 884 if (s.StartsWith ("0x") || s.StartsWith ("0X"))
843 return int.Parse (s.Substring (2), NumberStyles.HexNumber); 885 return int.Parse (s.Substring (2), NumberStyles.HexNumber);
844 } 886
845 return int.Parse (s, CultureInfo.InvariantCulture); 887 return int.Parse (s, CultureInfo.InvariantCulture);
846 } 888 }
847 public LSL_Rotation xmrString2Rotation (string s) 889 public LSL_Rotation xmrString2Rotation (string s)
848 { 890 {
849 s = s.Trim (); 891 s = s.Trim ();
850 if (!s.StartsWith ("<") || !s.EndsWith (">")) { 892 if (!s.StartsWith ("<") || !s.EndsWith (">"))
851 throw new FormatException ("doesn't begin with < and end with >"); 893 throw new FormatException ("doesn't begin with < and end with >");
852 } 894
853 s = s.Substring (1, s.Length - 2); 895 s = s.Substring (1, s.Length - 2);
854 string[] splitup = s.Split (justacomma, 5); 896 string[] splitup = s.Split (justacomma, 5);
855 if (splitup.Length != 4) { 897 if (splitup.Length != 4)
856 throw new FormatException ("doesn't have exactly 3 commas"); 898 throw new FormatException ("doesn't have exactly 3 commas");
857 } 899
858 double x = double.Parse (splitup[0], CultureInfo.InvariantCulture); 900 double x = double.Parse (splitup[0], CultureInfo.InvariantCulture);
859 double y = double.Parse (splitup[1], CultureInfo.InvariantCulture); 901 double y = double.Parse (splitup[1], CultureInfo.InvariantCulture);
860 double z = double.Parse (splitup[2], CultureInfo.InvariantCulture); 902 double z = double.Parse (splitup[2], CultureInfo.InvariantCulture);
@@ -864,14 +906,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
864 public LSL_Vector xmrString2Vector (string s) 906 public LSL_Vector xmrString2Vector (string s)
865 { 907 {
866 s = s.Trim (); 908 s = s.Trim ();
867 if (!s.StartsWith ("<") || !s.EndsWith (">")) { 909 if (!s.StartsWith ("<") || !s.EndsWith (">"))
868 throw new FormatException ("doesn't begin with < and end with >"); 910 throw new FormatException ("doesn't begin with < and end with >");
869 } 911
870 s = s.Substring (1, s.Length - 2); 912 s = s.Substring (1, s.Length - 2);
871 string[] splitup = s.Split (justacomma, 4); 913 string[] splitup = s.Split (justacomma, 4);
872 if (splitup.Length != 3) { 914 if (splitup.Length != 3)
873 throw new FormatException ("doesn't have exactly 2 commas"); 915 throw new FormatException ("doesn't have exactly 2 commas");
874 } 916
875 double x = double.Parse (splitup[0], CultureInfo.InvariantCulture); 917 double x = double.Parse (splitup[0], CultureInfo.InvariantCulture);
876 double y = double.Parse (splitup[1], CultureInfo.InvariantCulture); 918 double y = double.Parse (splitup[1], CultureInfo.InvariantCulture);
877 double z = double.Parse (splitup[2], CultureInfo.InvariantCulture); 919 double z = double.Parse (splitup[2], CultureInfo.InvariantCulture);
@@ -933,14 +975,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
933 /* 975 /*
934 * If it is a script-defined interface object, convert to the original XMRSDTypeClObj. 976 * If it is a script-defined interface object, convert to the original XMRSDTypeClObj.
935 */ 977 */
936 if (thrown is Delegate[]) { 978 if (thrown is Delegate[])
937 thrown = ((Delegate[])thrown)[0].Target; 979 thrown = ((Delegate[])thrown)[0].Target;
938 }
939 980
940 /* 981 /*
941 * If it is a script-defined delegate object, make sure it is an instance of the expected type. 982 * If it is a script-defined delegate object, make sure it is an instance of the expected type.
942 */ 983 */
943 if (thrown is Delegate) { 984 if (thrown is Delegate)
985 {
944 Type ot = thrown.GetType (); 986 Type ot = thrown.GetType ();
945 Type tt = sdType.GetSysType (); 987 Type tt = sdType.GetSysType ();
946 return (ot == tt) ? thrown : null; 988 return (ot == tt) ? thrown : null;
@@ -949,15 +991,18 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
949 /* 991 /*
950 * If it is a script-defined class object, make sure it is an instance of the expected class. 992 * If it is a script-defined class object, make sure it is an instance of the expected class.
951 */ 993 */
952 if (thrown is XMRSDTypeClObj) { 994 if (thrown is XMRSDTypeClObj)
995 {
953 996
954 /* 997 /*
955 * Step from the object's actual class rootward. 998 * Step from the object's actual class rootward.
956 * If we find the requested class along the way, the cast is valid. 999 * If we find the requested class along the way, the cast is valid.
957 * If we run off the end of the root, the cast is not valid. 1000 * If we run off the end of the root, the cast is not valid.
958 */ 1001 */
959 for (TokenDeclSDTypeClass ac = ((XMRSDTypeClObj)thrown).sdtcClass; ac != null; ac = ac.extends) { 1002 for (TokenDeclSDTypeClass ac = ((XMRSDTypeClObj)thrown).sdtcClass; ac != null; ac = ac.extends)
960 if (ac == sdType) return thrown; 1003 {
1004 if (ac == sdType)
1005 return thrown;
961 } 1006 }
962 } 1007 }
963 1008
@@ -1015,10 +1060,11 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1015 */ 1060 */
1016 int i = srctypename.IndexOf ('['); 1061 int i = srctypename.IndexOf ('[');
1017 int j = dsttypename.IndexOf ('['); 1062 int j = dsttypename.IndexOf ('[');
1018 if ((i < 0) || (j < 0)) throw new InvalidCastException ("non-array passed: " + srctypename + " and/or " + dsttypename); 1063 if ((i < 0) || (j < 0))
1019 if ((i != j) || !srctypename.StartsWith (dsttypename.Substring (0, j))) { 1064 throw new InvalidCastException ("non-array passed: " + srctypename + " and/or " + dsttypename);
1065 if ((i != j) || !srctypename.StartsWith (dsttypename.Substring (0, j)))
1020 throw new ArrayTypeMismatchException (srctypename + " vs " + dsttypename); 1066 throw new ArrayTypeMismatchException (srctypename + " vs " + dsttypename);
1021 } 1067
1022 1068
1023 /* 1069 /*
1024 * The number of brackets must match exactly. 1070 * The number of brackets must match exactly.
@@ -1030,11 +1076,15 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1030 int dstlen = dsttypename.Length; 1076 int dstlen = dsttypename.Length;
1031 int srcjags = 0; 1077 int srcjags = 0;
1032 int dstjags = 0; 1078 int dstjags = 0;
1033 while (++ i < srclen) if (srctypename[i] == ']') srcjags ++; 1079 while (++ i < srclen)
1034 while (++ j < dstlen) if (dsttypename[j] == ']') dstjags ++; 1080 if (srctypename[i] == ']')
1035 if (dstjags != srcjags) { 1081 srcjags ++;
1082 while (++ j < dstlen)
1083 if (dsttypename[j] == ']')
1084 dstjags ++;
1085 if (dstjags != srcjags)
1036 throw new ArrayTypeMismatchException (srctypename + " vs " + dsttypename); 1086 throw new ArrayTypeMismatchException (srctypename + " vs " + dsttypename);
1037 } 1087
1038 1088
1039 /* 1089 /*
1040 * Perform the copy. 1090 * Perform the copy.
@@ -1059,9 +1109,9 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1059 */ 1109 */
1060 XMRSDTypeClObj array = (XMRSDTypeClObj)srcar; 1110 XMRSDTypeClObj array = (XMRSDTypeClObj)srcar;
1061 TokenDeclSDTypeClass sdtClass = array.sdtcClass; 1111 TokenDeclSDTypeClass sdtClass = array.sdtcClass;
1062 if (sdtClass.arrayOfRank == 0) { 1112 if (sdtClass.arrayOfRank == 0)
1063 throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); 1113 throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val);
1064 } 1114
1065 1115
1066 /* 1116 /*
1067 * Validate objects they want to put in the list. 1117 * Validate objects they want to put in the list.
@@ -1069,26 +1119,33 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1069 */ 1119 */
1070 Array srcarray = (Array)array.instVars.iarObjects[0]; 1120 Array srcarray = (Array)array.instVars.iarObjects[0];
1071 object[] output = new object[count]; 1121 object[] output = new object[count];
1072 for (int i = 0; i < count; i ++) { 1122 for (int i = 0; i < count; i ++)
1123 {
1073 object src = srcarray.GetValue (i + start); 1124 object src = srcarray.GetValue (i + start);
1074 if (src == null) throw new NullReferenceException ("null element " + i); 1125 if (src == null)
1075 if (src is double) { 1126 throw new NullReferenceException ("null element " + i);
1127 if (src is double)
1128 {
1076 output[i] = new LSL_Float ((double)src); 1129 output[i] = new LSL_Float ((double)src);
1077 continue; 1130 continue;
1078 } 1131 }
1079 if (src is int) { 1132 if (src is int)
1133 {
1080 output[i] = new LSL_Integer ((int)src); 1134 output[i] = new LSL_Integer ((int)src);
1081 continue; 1135 continue;
1082 } 1136 }
1083 if (src is LSL_Rotation) { 1137 if (src is LSL_Rotation)
1138 {
1084 output[i] = src; 1139 output[i] = src;
1085 continue; 1140 continue;
1086 } 1141 }
1087 if (src is LSL_Vector) { 1142 if (src is LSL_Vector)
1143 {
1088 output[i] = src; 1144 output[i] = src;
1089 continue; 1145 continue;
1090 } 1146 }
1091 if (src is string) { 1147 if (src is string)
1148 {
1092 output[i] = new LSL_String ((string)src); 1149 output[i] = new LSL_String ((string)src);
1093 continue; 1150 continue;
1094 } 1151 }
@@ -1117,9 +1174,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1117 */ 1174 */
1118 XMRSDTypeClObj dstarray = (XMRSDTypeClObj)dstobj; 1175 XMRSDTypeClObj dstarray = (XMRSDTypeClObj)dstobj;
1119 TokenDeclSDTypeClass sdtClass = dstarray.sdtcClass; 1176 TokenDeclSDTypeClass sdtClass = dstarray.sdtcClass;
1120 if (sdtClass.arrayOfType == null) { 1177 if (sdtClass.arrayOfType == null)
1121 throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); 1178 throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val);
1122 }
1123 1179
1124 /* 1180 /*
1125 * Copy from the immutable array to the mutable array. 1181 * Copy from the immutable array to the mutable array.
@@ -1128,11 +1184,12 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1128 object[] srcarr = srclist.Data; 1184 object[] srcarr = srclist.Data;
1129 Array dstarr = (Array)dstarray.instVars.iarObjects[0]; 1185 Array dstarr = (Array)dstarray.instVars.iarObjects[0];
1130 1186
1131 for (int i = 0; i < count; i ++) { 1187 for (int i = 0; i < count; i ++)
1188 {
1132 object obj = srcarr[i+srcstart]; 1189 object obj = srcarr[i+srcstart];
1133 if (obj is LSL_Float) obj = ((LSL_Float)obj).value; 1190 if (obj is LSL_Float) obj = ((LSL_Float)obj).value;
1134 if (obj is LSL_Integer) obj = ((LSL_Integer)obj).value; 1191 else if (obj is LSL_Integer) obj = ((LSL_Integer)obj).value;
1135 if (obj is LSL_String) obj = ((LSL_String)obj).m_string; 1192 else if (obj is LSL_String) obj = ((LSL_String)obj).m_string;
1136 dstarr.SetValue (obj, i + dststart); 1193 dstarr.SetValue (obj, i + dststart);
1137 } 1194 }
1138 } 1195 }
@@ -1151,9 +1208,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1151 */ 1208 */
1152 XMRSDTypeClObj array = (XMRSDTypeClObj)srcar; 1209 XMRSDTypeClObj array = (XMRSDTypeClObj)srcar;
1153 TokenDeclSDTypeClass sdtClass = array.sdtcClass; 1210 TokenDeclSDTypeClass sdtClass = array.sdtcClass;
1154 if (sdtClass.arrayOfRank == 0) { 1211 if (sdtClass.arrayOfRank == 0)
1155 throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); 1212 throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val);
1156 }
1157 1213
1158 /* 1214 /*
1159 * We get a type cast error from mono if they didn't give us a character array. 1215 * We get a type cast error from mono if they didn't give us a character array.
@@ -1178,18 +1234,16 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1178 */ 1234 */
1179 XMRSDTypeClObj dstarray = (XMRSDTypeClObj)dstobj; 1235 XMRSDTypeClObj dstarray = (XMRSDTypeClObj)dstobj;
1180 TokenDeclSDTypeClass sdtClass = dstarray.sdtcClass; 1236 TokenDeclSDTypeClass sdtClass = dstarray.sdtcClass;
1181 if (sdtClass.arrayOfType == null) { 1237 if (sdtClass.arrayOfType == null)
1182 throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); 1238 throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val);
1183 }
1184 1239
1185 /* 1240 /*
1186 * We get a type cast error from mono if they didn't give us a character array. 1241 * We get a type cast error from mono if they didn't give us a character array.
1187 * But if it is ok, copy from the string to the character array. 1242 * But if it is ok, copy from the string to the character array.
1188 */ 1243 */
1189 char[] dstarr = (char[])dstarray.instVars.iarObjects[0]; 1244 char[] dstarr = (char[])dstarray.instVars.iarObjects[0];
1190 for (int i = 0; i < count; i ++) { 1245 for (int i = 0; i < count; i ++)
1191 dstarr[i+dststart] = srcstr[i+srcstart]; 1246 dstarr[i+dststart] = srcstr[i+srcstart];
1192 }
1193 } 1247 }
1194 1248
1195 /** 1249 /**
@@ -1202,8 +1256,10 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1202 { 1256 {
1203 XMR_Array dict = new XMR_Array (this); 1257 XMR_Array dict = new XMR_Array (this);
1204 int idx = ParseJSON (dict, nullList, json, 0); 1258 int idx = ParseJSON (dict, nullList, json, 0);
1205 while (idx < json.Length) { 1259 while (idx < json.Length)
1206 if (json[idx] > ' ') throw new Exception ("left-over json " + json); 1260 {
1261 if (json[idx] > ' ')
1262 throw new Exception ("left-over json " + json);
1207 idx ++; 1263 idx ++;
1208 } 1264 }
1209 return dict; 1265 return dict;
@@ -1214,35 +1270,46 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1214 char c; 1270 char c;
1215 1271
1216 while ((c = json[idx++]) <= ' ') { } 1272 while ((c = json[idx++]) <= ' ') { }
1217 switch (c) { 1273 switch (c)
1274 {
1218 1275
1219 // '{' <keystring> ':' <value> [ ',' <keystring> ':' <value> ... ] '}' 1276 // '{' <keystring> ':' <value> [ ',' <keystring> ':' <value> ... ] '}'
1220 case '{': { 1277 case '{':
1221 do { 1278 {
1279 do
1280 {
1222 string key = ParseJSONString (json, ref idx); 1281 string key = ParseJSONString (json, ref idx);
1223 while ((c = json[idx++]) <= ' ') { } 1282 while ((c = json[idx++]) <= ' ') { }
1224 if (c != ':') throw new Exception ("missing : after key"); 1283 if (c != ':')
1284 throw new Exception ("missing : after key");
1225 idx = ParseJSON (dict, ParseJSONKeyAdd (keys, key), json, idx); 1285 idx = ParseJSON (dict, ParseJSONKeyAdd (keys, key), json, idx);
1226 while ((c = json[idx++]) <= ' ') { } 1286 while ((c = json[idx++]) <= ' ') { }
1227 } while (c == ','); 1287 } while (c == ',');
1228 if (c != '}') throw new Exception ("missing , or } after value"); 1288
1289 if (c != '}')
1290 throw new Exception ("missing , or } after value");
1229 break; 1291 break;
1230 } 1292 }
1231 1293
1232 // '[' <value> [ ',' <value> ... ] ']' 1294 // '[' <value> [ ',' <value> ... ] ']'
1233 case '[': { 1295 case '[':
1296 {
1234 int index = 0; 1297 int index = 0;
1235 do { 1298 do
1299 {
1236 object key = index ++; 1300 object key = index ++;
1237 idx = ParseJSON (dict, ParseJSONKeyAdd (keys, key), json, idx); 1301 idx = ParseJSON (dict, ParseJSONKeyAdd (keys, key), json, idx);
1238 while ((c = json[idx++]) <= ' ') { } 1302 while ((c = json[idx++]) <= ' ') { }
1239 } while (c == ','); 1303 } while (c == ',');
1240 if (c != ']') throw new Exception ("missing , or ] after value"); 1304
1305 if (c != ']')
1306 throw new Exception ("missing , or ] after value");
1241 break; 1307 break;
1242 } 1308 }
1243 1309
1244 // '"'<string>'"' 1310 // '"'<string>'"'
1245 case '"': { 1311 case '"':
1312 {
1246 -- idx; 1313 -- idx;
1247 string val = ParseJSONString (json, ref idx); 1314 string val = ParseJSONString (json, ref idx);
1248 dict.SetByKey (keys, val); 1315 dict.SetByKey (keys, val);
@@ -1250,29 +1317,36 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1250 } 1317 }
1251 1318
1252 // true false null 1319 // true false null
1253 case 't': { 1320 case 't':
1254 if (json.Substring (idx, 3) != "rue") throw new Exception ("bad true in json"); 1321 {
1322 if (json.Substring (idx, 3) != "rue")
1323 throw new Exception ("bad true in json");
1255 idx += 3; 1324 idx += 3;
1256 dict.SetByKey (keys, 1); 1325 dict.SetByKey (keys, 1);
1257 break; 1326 break;
1258 } 1327 }
1259 1328
1260 case 'f': { 1329 case 'f':
1261 if (json.Substring (idx, 4) != "alse") throw new Exception ("bad false in json"); 1330 {
1331 if (json.Substring (idx, 4) != "alse")
1332 throw new Exception ("bad false in json");
1262 idx += 4; 1333 idx += 4;
1263 dict.SetByKey (keys, 0); 1334 dict.SetByKey (keys, 0);
1264 break; 1335 break;
1265 } 1336 }
1266 1337
1267 case 'n': { 1338 case 'n':
1268 if (json.Substring (idx, 3) != "ull") throw new Exception ("bad null in json"); 1339 {
1340 if (json.Substring (idx, 3) != "ull")
1341 throw new Exception ("bad null in json");
1269 idx += 3; 1342 idx += 3;
1270 dict.SetByKey (keys, null); 1343 dict.SetByKey (keys, null);
1271 break; 1344 break;
1272 } 1345 }
1273 1346
1274 // otherwise assume it's a number 1347 // otherwise assume it's a number
1275 default: { 1348 default:
1349 {
1276 -- idx; 1350 -- idx;
1277 object val = ParseJSONNumber (json, ref idx); 1351 object val = ParseJSONNumber (json, ref idx);
1278 dict.SetByKey (keys, val); 1352 dict.SetByKey (keys, val);
@@ -1302,36 +1376,39 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1302 if (c != '"') throw new Exception ("bad start of json string"); 1376 if (c != '"') throw new Exception ("bad start of json string");
1303 1377
1304 StringBuilder sb = new StringBuilder (); 1378 StringBuilder sb = new StringBuilder ();
1305 while ((c = json[idx++]) != '"') { 1379 while ((c = json[idx++]) != '"')
1306 if (c == '\\') { 1380 {
1381 if (c == '\\')
1382 {
1307 c = json[idx++]; 1383 c = json[idx++];
1308 switch (c) { 1384 switch (c)
1309 case 'b': { 1385 {
1386 case 'b':
1310 c = '\b'; 1387 c = '\b';
1311 break; 1388 break;
1312 } 1389
1313 case 'f': { 1390 case 'f':
1314 c = '\f'; 1391 c = '\f';
1315 break; 1392 break;
1316 } 1393
1317 case 'n': { 1394 case 'n':
1318 c = '\n'; 1395 c = '\n';
1319 break; 1396 break;
1320 } 1397
1321 case 'r': { 1398 case 'r':
1322 c = '\r'; 1399 c = '\r';
1323 break; 1400 break;
1324 } 1401
1325 case 't': { 1402 case 't':
1326 c = '\t'; 1403 c = '\t';
1327 break; 1404 break;
1328 } 1405
1329 case 'u': { 1406 case 'u':
1330 c = (char) Int32.Parse (json.Substring (idx, 4), 1407 c = (char) Int32.Parse (json.Substring (idx, 4),
1331 System.Globalization.NumberStyles.HexNumber); 1408 System.Globalization.NumberStyles.HexNumber);
1332 idx += 4; 1409 idx += 4;
1333 break; 1410 break;
1334 } 1411
1335 default: break; 1412 default: break;
1336 } 1413 }
1337 } 1414 }
@@ -1358,49 +1435,65 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
1358 isneg = true; 1435 isneg = true;
1359 c = json[idx++]; 1436 c = json[idx++];
1360 } 1437 }
1361 if ((c < '0') || (c > '9')) { 1438 if ((c < '0') || (c > '9'))
1362 throw new Exception ("bad json number"); 1439 throw new Exception ("bad json number");
1363 } 1440
1364 while ((c >= '0') && (c <= '9')) { 1441 while ((c >= '0') && (c <= '9'))
1442 {
1365 dval *= 10; 1443 dval *= 10;
1366 ival *= 10; 1444 ival *= 10;
1367 dval += c - '0'; 1445 dval += c - '0';
1368 ival += c - '0'; 1446 ival += c - '0';
1369 c = '\0'; 1447 c = '\0';
1370 if (idx < json.Length) c = json[idx++]; 1448 if (idx < json.Length)
1449 c = json[idx++];
1371 } 1450 }
1372 if (c == '.') { 1451 if (c == '.')
1452 {
1373 decpt = 0; 1453 decpt = 0;
1374 c = '\0'; 1454 c = '\0';
1375 if (idx < json.Length) c = json[idx++]; 1455 if (idx < json.Length)
1456 c = json[idx++];
1376 while ((c >= '0') && (c <= '9')) { 1457 while ((c >= '0') && (c <= '9')) {
1377 dval *= 10; 1458 dval *= 10;
1378 dval += c - '0'; 1459 dval += c - '0';
1379 decpt ++; 1460 decpt ++;
1380 c = '\0'; 1461 c = '\0';
1381 if (idx < json.Length) c = json[idx++]; 1462 if (idx < json.Length)
1463 c = json[idx++];
1382 } 1464 }
1383 } 1465 }
1384 if ((c == 'e') || (c == 'E')) { 1466 if ((c == 'e') || (c == 'E'))
1385 if (decpt < 0) decpt = 0; 1467 {
1468 if (decpt < 0)
1469 decpt = 0;
1386 c = json[idx++]; 1470 c = json[idx++];
1387 if (c == '-') expneg = true; 1471 if (c == '-')
1388 if ((c == '-') || (c == '+')) c = json[idx++]; 1472 expneg = true;
1389 while ((c >= '0') && (c <= '9')) { 1473 if ((c == '-') || (c == '+'))
1474 c = json[idx++];
1475 while ((c >= '0') && (c <= '9'))
1476 {
1390 expon *= 10; 1477 expon *= 10;
1391 expon += c - '0'; 1478 expon += c - '0';
1392 c = '\0'; 1479 c = '\0';
1393 if (idx < json.Length) c = json[idx++]; 1480 if (idx < json.Length)
1481 c = json[idx++];
1394 } 1482 }
1395 if (expneg) expon = -expon; 1483 if (expneg)
1484 expon = -expon;
1396 } 1485 }
1397 1486
1398 if (c != 0) -- idx; 1487 if (c != 0)
1399 if (decpt < 0) { 1488 --idx;
1400 if (isneg) ival = -ival; 1489 if (decpt < 0)
1490 {
1491 if (isneg)
1492 ival = -ival;
1401 return ival; 1493 return ival;
1402 } else { 1494 } else {
1403 if (isneg) dval = -dval; 1495 if (isneg)
1496 dval = -dval;
1404 dval *= Math.Pow (10, expon - decpt); 1497 dval *= Math.Pow (10, expon - decpt);
1405 return dval; 1498 return dval;
1406 } 1499 }
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstBackend.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstBackend.cs
index acf1e66..edbd5ce 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstBackend.cs
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstBackend.cs
@@ -27,17 +27,9 @@
27 27
28using System; 28using System;
29using System.Threading; 29using System.Threading;
30using System.Reflection;
31using System.Collections;
32using System.Collections.Generic; 30using System.Collections.Generic;
33using System.Runtime.Remoting.Lifetime;
34using System.Security.Policy;
35using System.IO;
36using System.Xml;
37using System.Text;
38using OpenMetaverse; 31using OpenMetaverse;
39using OpenSim.Framework; 32using OpenSim.Framework;
40using OpenSim.Region.ScriptEngine.Interfaces;
41using OpenSim.Region.ScriptEngine.Shared; 33using OpenSim.Region.ScriptEngine.Shared;
42using OpenSim.Region.ScriptEngine.Shared.Api; 34using OpenSim.Region.ScriptEngine.Shared.Api;
43using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 35using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
@@ -331,7 +323,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
331 ScriptEventCode evc = ScriptEventCode.None; 323 ScriptEventCode evc = ScriptEventCode.None;
332 324
333 callNo = -1; 325 callNo = -1;
334 try { 326 try
327 {
335 if (callMode == CallMode_NORMAL) goto findevent; 328 if (callMode == CallMode_NORMAL) goto findevent;
336 329
337 /* 330 /*
@@ -344,9 +337,11 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
344 returnMask2 = (int)sv[2]; 337 returnMask2 = (int)sv[2];
345 mask1 = (int)sv[3]; 338 mask1 = (int)sv[3];
346 mask2 = (int)sv[4]; 339 mask2 = (int)sv[4];
347 switch (callNo) { 340 switch (callNo)
341 {
348 case 0: goto __call0; 342 case 0: goto __call0;
349 case 1: { 343 case 1:
344 {
350 evc1 = (int)sv[5]; 345 evc1 = (int)sv[5];
351 evc = (ScriptEventCode)(int)sv[6]; 346 evc = (ScriptEventCode)(int)sv[6];
352 DetectParams[] detprms = ObjArrToDetPrms ((object[])sv[7]); 347 DetectParams[] detprms = ObjArrToDetPrms ((object[])sv[7]);
@@ -362,13 +357,15 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
362 */ 357 */
363 findevent: 358 findevent:
364 Monitor.Enter (m_QueueLock); 359 Monitor.Enter (m_QueueLock);
365 for (lln = m_EventQueue.First; lln != null; lln = lln.Next) { 360 for (lln = m_EventQueue.First; lln != null; lln = lln.Next)
361 {
366 evt = lln.Value; 362 evt = lln.Value;
367 evc = (ScriptEventCode)Enum.Parse (typeof (ScriptEventCode), evt.EventName); 363 evc = (ScriptEventCode)Enum.Parse (typeof (ScriptEventCode), evt.EventName);
368 evc1 = (int)evc; 364 evc1 = (int)evc;
369 evc2 = evc1 - 32; 365 evc2 = evc1 - 32;
370 if ((((uint)evc1 < (uint)32) && (((mask1 >> evc1) & 1) != 0)) || 366 if ((((uint)evc1 < (uint)32) && (((mask1 >> evc1) & 1) != 0)) ||
371 (((uint)evc2 < (uint)32) && (((mask2 >> evc2) & 1) != 0))) goto remfromq; 367 (((uint)evc2 < (uint)32) && (((mask2 >> evc2) & 1) != 0)))
368 goto remfromq;
372 } 369 }
373 370
374 /* 371 /*
@@ -389,9 +386,9 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
389 */ 386 */
390 remfromq: 387 remfromq:
391 m_EventQueue.Remove (lln); 388 m_EventQueue.Remove (lln);
392 if ((uint)evc1 < (uint)m_EventCounts.Length) { 389 if ((uint)evc1 < (uint)m_EventCounts.Length)
393 m_EventCounts[evc1] --; 390 m_EventCounts[evc1] --;
394 } 391
395 Monitor.Exit (m_QueueLock); 392 Monitor.Exit (m_QueueLock);
396 m_InstEHEvent ++; 393 m_InstEHEvent ++;
397 394
@@ -399,7 +396,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
399 * See if returnable or background event. 396 * See if returnable or background event.
400 */ 397 */
401 if ((((uint)evc1 < (uint)32) && (((returnMask1 >> evc1) & 1) != 0)) || 398 if ((((uint)evc1 < (uint)32) && (((returnMask1 >> evc1) & 1) != 0)) ||
402 (((uint)evc2 < (uint)32) && (((returnMask2 >> evc2) & 1) != 0))) { 399 (((uint)evc2 < (uint)32) && (((returnMask2 >> evc2) & 1) != 0)))
400 {
403 401
404 /* 402 /*
405 * Returnable event, return its parameters in a list. 403 * Returnable event, return its parameters in a list.
@@ -408,11 +406,15 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
408 int plen = evt.Params.Length; 406 int plen = evt.Params.Length;
409 object[] plist = new object[plen+1]; 407 object[] plist = new object[plen+1];
410 plist[0] = (LSL_Integer)evc1; 408 plist[0] = (LSL_Integer)evc1;
411 for (int i = 0; i < plen;) { 409 for (int i = 0; i < plen;)
410 {
412 object ob = evt.Params[i]; 411 object ob = evt.Params[i];
413 if (ob is int) ob = (LSL_Integer)(int)ob; 412 if (ob is int)
414 else if (ob is double) ob = (LSL_Float)(double)ob; 413 ob = (LSL_Integer)(int)ob;
415 else if (ob is string) ob = (LSL_String)(string)ob; 414 else if (ob is double)
415 ob = (LSL_Float)(double)ob;
416 else if (ob is string)
417 ob = (LSL_String)(string)ob;
416 plist[++i] = ob; 418 plist[++i] = ob;
417 } 419 }
418 m_DetectParams = evt.DetectParams; 420 m_DetectParams = evt.DetectParams;
@@ -426,7 +428,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
426 callNo = 1; 428 callNo = 1;
427 __call1: 429 __call1:
428 ScriptEventHandler seh = m_ObjCode.scriptEventHandlerTable[stateCode,evc1]; 430 ScriptEventHandler seh = m_ObjCode.scriptEventHandlerTable[stateCode,evc1];
429 if (seh == null) goto checktmo; 431 if (seh == null)
432 goto checktmo;
430 433
431 DetectParams[] saveDetParams = this.m_DetectParams; 434 DetectParams[] saveDetParams = this.m_DetectParams;
432 object[] saveEHArgs = this.ehArgs; 435 object[] saveEHArgs = this.ehArgs;
@@ -436,26 +439,33 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
436 this.ehArgs = evt.Params; 439 this.ehArgs = evt.Params;
437 this.eventCode = evc; 440 this.eventCode = evc;
438 441
439 try { 442 try
443 {
440 seh (this); 444 seh (this);
441 } finally { 445 }
442 this.m_DetectParams = saveDetParams; 446 finally
443 this.ehArgs = saveEHArgs; 447 {
444 this.eventCode = saveEventCode; 448 m_DetectParams = saveDetParams;
449 ehArgs = saveEHArgs;
450 eventCode = saveEventCode;
445 } 451 }
446 452
447 /* 453 /*
448 * Keep waiting until we find a returnable event or timeout. 454 * Keep waiting until we find a returnable event or timeout.
449 */ 455 */
450 checktmo: 456 checktmo:
451 if (DateTime.UtcNow < sleepUntil) goto findevent; 457 if (DateTime.UtcNow < sleepUntil)
458 goto findevent;
452 459
453 /* 460 /*
454 * We timed out, return an empty list. 461 * We timed out, return an empty list.
455 */ 462 */
456 return emptyList; 463 return emptyList;
457 } finally { 464 }
458 if (callMode != CallMode_NORMAL) { 465 finally
466 {
467 if (callMode != CallMode_NORMAL)
468 {
459 469
460 /* 470 /*
461 * Stack frame is being saved by CheckRun...(). 471 * Stack frame is being saved by CheckRun...().
@@ -468,7 +478,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
468 sv[2] = returnMask2; // needed at __call0,__call1 478 sv[2] = returnMask2; // needed at __call0,__call1
469 sv[3] = mask1; // needed at __call0,__call1 479 sv[3] = mask1; // needed at __call0,__call1
470 sv[4] = mask2; // needed at __call0,__call1 480 sv[4] = mask2; // needed at __call0,__call1
471 if (callNo == 1) { 481 if (callNo == 1)
482 {
472 sv[5] = evc1; // needed at __call1 483 sv[5] = evc1; // needed at __call1
473 sv[6] = (int)evc; // needed at __call1 484 sv[6] = (int)evc; // needed at __call1
474 sv[7] = DetPrmsToObjArr (evt.DetectParams); // needed at __call1 485 sv[7] = DetPrmsToObjArr (evt.DetectParams); // needed at __call1
@@ -515,7 +526,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
515 object[] obs = new object[len*16+1]; 526 object[] obs = new object[len*16+1];
516 int j = 0; 527 int j = 0;
517 obs[j++] = (LSL_Integer)saveDPVer; 528 obs[j++] = (LSL_Integer)saveDPVer;
518 for (int i = 0; i < len; i ++) { 529 for (int i = 0; i < len; i ++)
530 {
519 DetectParams dp = dps[i]; 531 DetectParams dp = dps[i];
520 obs[j++] = (LSL_String)dp.Key.ToString(); // UUID 532 obs[j++] = (LSL_String)dp.Key.ToString(); // UUID
521 obs[j++] = dp.OffsetPos; // vector 533 obs[j++] = dp.OffsetPos; // vector
@@ -550,14 +562,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
550 private static DetectParams[] ObjArrToDetPrms (object[] objs) 562 private static DetectParams[] ObjArrToDetPrms (object[] objs)
551 { 563 {
552 int j = 0; 564 int j = 0;
553 if ((objs.Length % 16 != 1) || (ListInt (objs[j++]) != saveDPVer)) { 565 if ((objs.Length % 16 != 1) || (ListInt (objs[j++]) != saveDPVer))
554 throw new Exception ("invalid detect param format"); 566 throw new Exception ("invalid detect param format");
555 }
556 567
557 int len = objs.Length / 16; 568 int len = objs.Length / 16;
558 DetectParams[] dps = new DetectParams[len]; 569 DetectParams[] dps = new DetectParams[len];
559 570
560 for (int i = 0; i < len; i ++) { 571 for (int i = 0; i < len; i ++)
572 {
561 DetectParams dp = new DetectParams (); 573 DetectParams dp = new DetectParams ();
562 574
563 dp.Key = new UUID (ListStr (objs[j++])); 575 dp.Key = new UUID (ListStr (objs[j++]));
@@ -612,9 +624,11 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
612 /* 624 /*
613 * Clear out any old events from the queue. 625 * Clear out any old events from the queue.
614 */ 626 */
615 lock (m_QueueLock) { 627 lock (m_QueueLock)
628 {
616 m_EventQueue.Clear(); 629 m_EventQueue.Clear();
617 for (int i = m_EventCounts.Length; -- i >= 0;) m_EventCounts[i] = 0; 630 for (int i = m_EventCounts.Length; -- i >= 0;)
631 m_EventCounts[i] = 0;
618 } 632 }
619 } 633 }
620 634
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs
index 436434a..3573be3 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs
@@ -140,6 +140,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
140 public int m_InstEHEvent = 0; // number of events dequeued (StartEventHandler called) 140 public int m_InstEHEvent = 0; // number of events dequeued (StartEventHandler called)
141 public int m_InstEHSlice = 0; // number of times handler timesliced (ResumeEx called) 141 public int m_InstEHSlice = 0; // number of times handler timesliced (ResumeEx called)
142 public double m_CPUTime = 0; // accumulated CPU time (milliseconds) 142 public double m_CPUTime = 0; // accumulated CPU time (milliseconds)
143 public double m_SliceStart = 0; // when did current exec start
143 144
144 // If code needs to have both m_QueueLock and m_RunLock, 145 // If code needs to have both m_QueueLock and m_RunLock,
145 // be sure to lock m_RunLock first then m_QueueLock, as 146 // be sure to lock m_RunLock first then m_QueueLock, as
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstRun.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstRun.cs
index 61ae549..9654b01 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstRun.cs
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstRun.cs
@@ -27,14 +27,7 @@
27 27
28using System; 28using System;
29using System.Threading; 29using System.Threading;
30using System.Reflection;
31using System.Collections;
32using System.Collections.Generic; 30using System.Collections.Generic;
33using System.Reflection.Emit;
34using System.Runtime.Remoting.Lifetime;
35using System.Security.Policy;
36using System.IO;
37using System.Xml;
38using System.Text; 31using System.Text;
39using OpenMetaverse; 32using OpenMetaverse;
40using OpenSim.Framework; 33using OpenSim.Framework;
@@ -140,22 +133,23 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
140 * of all others so the m_DetachQuantum won't run out 133 * of all others so the m_DetachQuantum won't run out
141 * before attach(NULL_KEY) is executed. 134 * before attach(NULL_KEY) is executed.
142 */ 135 */
143 case ScriptEventCode.attach: { 136 case ScriptEventCode.attach:
137 {
144 if (evt.Params[0].ToString() == UUID.Zero.ToString()) 138 if (evt.Params[0].ToString() == UUID.Zero.ToString())
145 { 139 {
146 LinkedListNode<EventParams> lln2 = null; 140 LinkedListNode<EventParams> lln2 = null;
147 for (lln2 = m_EventQueue.First; lln2 != null; lln2 = lln2.Next) { 141 for (lln2 = m_EventQueue.First; lln2 != null; lln2 = lln2.Next)
142 {
148 EventParams evt2 = lln2.Value; 143 EventParams evt2 = lln2.Value;
149 ScriptEventCode evc2 = (ScriptEventCode)Enum.Parse (typeof (ScriptEventCode), 144 ScriptEventCode evc2 = (ScriptEventCode)Enum.Parse (typeof (ScriptEventCode),
150 evt2.EventName); 145 evt2.EventName);
151 if ((evc2 != ScriptEventCode.state_entry) && 146 if ((evc2 != ScriptEventCode.state_entry) &&
152 (evc2 != ScriptEventCode.attach)) break; 147 (evc2 != ScriptEventCode.attach)) break;
153 } 148 }
154 if (lln2 == null) { 149 if (lln2 == null)
155 m_EventQueue.AddLast(lln); 150 m_EventQueue.AddLast(lln);
156 } else { 151 else
157 m_EventQueue.AddBefore(lln2, lln); 152 m_EventQueue.AddBefore(lln2, lln);
158 }
159 /* If we're detaching, limit the qantum. This will also 153 /* If we're detaching, limit the qantum. This will also
160 * cause the script to self-suspend after running this 154 * cause the script to self-suspend after running this
161 * event 155 * event
@@ -165,16 +159,15 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
165 m_DetachQuantum = 100; 159 m_DetachQuantum = 100;
166 } 160 }
167 else 161 else
168 {
169 m_EventQueue.AddLast(lln); 162 m_EventQueue.AddLast(lln);
170 }
171 break; 163 break;
172 } 164 }
173 165
174 /* 166 /*
175 * All others just go on end in the order queued. 167 * All others just go on end in the order queued.
176 */ 168 */
177 default: { 169 default:
170 {
178 m_EventQueue.AddLast(lln); 171 m_EventQueue.AddLast(lln);
179 break; 172 break;
180 } 173 }
@@ -187,7 +180,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
187 * to do the same thing right now. 180 * to do the same thing right now.
188 * Dont' flag it if it's still suspended! 181 * Dont' flag it if it's still suspended!
189 */ 182 */
190 if ((m_IState == XMRInstState.IDLE) && !m_Suspended) { 183 if ((m_IState == XMRInstState.IDLE) && !m_Suspended)
184 {
191 m_IState = XMRInstState.ONSTARTQ; 185 m_IState = XMRInstState.ONSTARTQ;
192 startIt = true; 186 startIt = true;
193 } 187 }
@@ -196,11 +190,13 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
196 * If instance is sleeping (ie, possibly in xmrEventDequeue), 190 * If instance is sleeping (ie, possibly in xmrEventDequeue),
197 * wake it up if event is in the mask. 191 * wake it up if event is in the mask.
198 */ 192 */
199 if ((m_SleepUntil > DateTime.UtcNow) && !m_Suspended) { 193 if ((m_SleepUntil > DateTime.UtcNow) && !m_Suspended)
194 {
200 int evc1 = (int)evc; 195 int evc1 = (int)evc;
201 int evc2 = evc1 - 32; 196 int evc2 = evc1 - 32;
202 if ((((uint)evc1 < (uint)32) && (((m_SleepEventMask1 >> evc1) & 1) != 0)) || 197 if ((((uint)evc1 < (uint)32) && (((m_SleepEventMask1 >> evc1) & 1) != 0)) ||
203 (((uint)evc2 < (uint)32) && (((m_SleepEventMask2 >> evc2) & 1) != 0))) { 198 (((uint)evc2 < (uint)32) && (((m_SleepEventMask2 >> evc2) & 1) != 0)))
199 {
204 wakeIt = true; 200 wakeIt = true;
205 } 201 }
206 } 202 }
@@ -210,14 +206,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
210 * If transitioned from IDLE->ONSTARTQ, actually go insert it 206 * If transitioned from IDLE->ONSTARTQ, actually go insert it
211 * on m_StartQueue and give the RunScriptThread() a wake-up. 207 * on m_StartQueue and give the RunScriptThread() a wake-up.
212 */ 208 */
213 if (startIt) { 209 if (startIt)
214 m_Engine.QueueToStart(this); 210 m_Engine.QueueToStart(this);
215 }
216 211
217 /* 212 /*
218 * Likewise, if the event mask triggered a wake, wake it up. 213 * Likewise, if the event mask triggered a wake, wake it up.
219 */ 214 */
220 if (wakeIt) { 215 if (wakeIt)
216 {
221 m_SleepUntil = DateTime.MinValue; 217 m_SleepUntil = DateTime.MinValue;
222 m_Engine.WakeFromSleep(this); 218 m_Engine.WakeFromSleep(this);
223 } 219 }
@@ -231,6 +227,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
231 public XMRInstState RunOne() 227 public XMRInstState RunOne()
232 { 228 {
233 DateTime now = DateTime.UtcNow; 229 DateTime now = DateTime.UtcNow;
230 m_SliceStart = Util.GetTimeStampMS();
234 231
235 /* 232 /*
236 * If script has called llSleep(), don't do any more until time is 233 * If script has called llSleep(), don't do any more until time is
@@ -247,7 +244,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
247 * Also, someone may have called Suspend(). 244 * Also, someone may have called Suspend().
248 */ 245 */
249 m_RunOnePhase = "check m_SuspendCount"; 246 m_RunOnePhase = "check m_SuspendCount";
250 if (m_SuspendCount > 0) { 247 if (m_SuspendCount > 0)
248 {
251 m_RunOnePhase = "return is suspended"; 249 m_RunOnePhase = "return is suspended";
252 return XMRInstState.SUSPENDED; 250 return XMRInstState.SUSPENDED;
253 } 251 }
@@ -258,7 +256,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
258 * back right away, delay a bit so we don't get in infinite loop. 256 * back right away, delay a bit so we don't get in infinite loop.
259 */ 257 */
260 m_RunOnePhase = "lock m_RunLock"; 258 m_RunOnePhase = "lock m_RunLock";
261 if (!Monitor.TryEnter (m_RunLock)) { 259 if (!Monitor.TryEnter (m_RunLock))
260 {
262 m_SleepUntil = now.AddMilliseconds(3); 261 m_SleepUntil = now.AddMilliseconds(3);
263 m_RunOnePhase = "return was locked"; 262 m_RunOnePhase = "return was locked";
264 return XMRInstState.ONSLEEPQ; 263 return XMRInstState.ONSLEEPQ;
@@ -282,7 +281,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
282 /* 281 /*
283 * Do some more of the last event if it didn't finish. 282 * Do some more of the last event if it didn't finish.
284 */ 283 */
285 else if (this.eventCode != ScriptEventCode.None) 284 else if (eventCode != ScriptEventCode.None)
286 { 285 {
287 lock (m_QueueLock) 286 lock (m_QueueLock)
288 { 287 {
@@ -336,10 +335,10 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
336 if (m_EventQueue.First != null) 335 if (m_EventQueue.First != null)
337 { 336 {
338 evt = m_EventQueue.First.Value; 337 evt = m_EventQueue.First.Value;
338 evc = (ScriptEventCode)Enum.Parse (typeof (ScriptEventCode),
339 evt.EventName);
339 if (m_DetachQuantum > 0) 340 if (m_DetachQuantum > 0)
340 { 341 {
341 evc = (ScriptEventCode)Enum.Parse (typeof (ScriptEventCode),
342 evt.EventName);
343 if (evc != ScriptEventCode.attach) 342 if (evc != ScriptEventCode.attach)
344 { 343 {
345 /* 344 /*
@@ -356,9 +355,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
356 } 355 }
357 } 356 }
358 m_EventQueue.RemoveFirst(); 357 m_EventQueue.RemoveFirst();
359 evc = (ScriptEventCode)Enum.Parse (typeof (ScriptEventCode), 358 if (evc >= 0)
360 evt.EventName); 359 m_EventCounts[(int)evc] --;
361 if ((int)evc >= 0) m_EventCounts[(int)evc] --;
362 } 360 }
363 361
364 /* 362 /*
@@ -483,28 +481,25 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
483 * We use this.eventCode == ScriptEventCode.None to indicate we are idle. 481 * We use this.eventCode == ScriptEventCode.None to indicate we are idle.
484 * So trying to execute ScriptEventCode.None might make a mess. 482 * So trying to execute ScriptEventCode.None might make a mess.
485 */ 483 */
486 if (eventCode == ScriptEventCode.None) { 484 if (eventCode == ScriptEventCode.None)
487 return new Exception ("Can't process ScriptEventCode.None"); 485 return new Exception ("Can't process ScriptEventCode.None");
488 }
489 486
490 /* 487 /*
491 * Silly to even try if there is no handler defined for this event. 488 * Silly to even try if there is no handler defined for this event.
492 */ 489 */
493 if (((int)eventCode >= 0) && (m_ObjCode.scriptEventHandlerTable[this.stateCode,(int)eventCode] == null)) { 490 if ((eventCode >= 0) && (m_ObjCode.scriptEventHandlerTable[this.stateCode,(int)eventCode] == null))
494 return null; 491 return null;
495 }
496 492
497 /* 493 /*
498 * The microthread shouldn't be processing any event code. 494 * The microthread shouldn't be processing any event code.
499 * These are assert checks so we throw them directly as exceptions. 495 * These are assert checks so we throw them directly as exceptions.
500 */ 496 */
501 if (this.eventCode != ScriptEventCode.None) { 497 if (this.eventCode != ScriptEventCode.None)
502 throw new Exception ("still processing event " + this.eventCode.ToString ()); 498 throw new Exception ("still processing event " + this.eventCode.ToString ());
503 } 499
504 int active = microthread.Active (); 500 int active = microthread.Active ();
505 if (active != 0) { 501 if (active != 0)
506 throw new Exception ("microthread is active " + active.ToString ()); 502 throw new Exception ("microthread is active " + active.ToString ());
507 }
508 503
509 /* 504 /*
510 * Save eventCode so we know what event handler to run in the microthread. 505 * Save eventCode so we know what event handler to run in the microthread.
@@ -956,19 +951,28 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
956 */ 951 */
957 public override void CheckRunWork () 952 public override void CheckRunWork ()
958 { 953 {
954 if(!suspendOnCheckRunHold && ! suspendOnCheckRunTemp)
955 {
956 if(Util.GetTimeStampMS() - m_SliceStart < 60.0)
957 return;
958 suspendOnCheckRunTemp = true;
959 }
960
959 m_CheckRunPhase = "entered"; 961 m_CheckRunPhase = "entered";
960 962
961 /* 963 /*
962 * Stay stuck in this loop as long as something wants us suspended. 964 * Stay stuck in this loop as long as something wants us suspended.
963 */ 965 */
964 while (suspendOnCheckRunHold || suspendOnCheckRunTemp) { 966 while (suspendOnCheckRunHold || suspendOnCheckRunTemp)
967 {
965 m_CheckRunPhase = "top of while"; 968 m_CheckRunPhase = "top of while";
966 969
967 /* 970 /*
968 * See if MigrateOutEventHandler() has been called. 971 * See if MigrateOutEventHandler() has been called.
969 * If so, dump our stack to stackFrames and unwind. 972 * If so, dump our stack to stackFrames and unwind.
970 */ 973 */
971 if (this.captureStackFrames) { 974 if (this.captureStackFrames)
975 {
972 976
973 /* 977 /*
974 * Puque our stack to the output stream. 978 * Puque our stack to the output stream.
@@ -986,7 +990,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
986 * within the functions should do their normal processing instead of trying to 990 * within the functions should do their normal processing instead of trying to
987 * restore their state. 991 * restore their state.
988 */ 992 */
989 if (this.callMode == CallMode_RESTORE) { 993 if (this.callMode == CallMode_RESTORE)
994 {
990 stackFramesRestored = true; 995 stackFramesRestored = true;
991 this.callMode = CallMode_NORMAL; 996 this.callMode = CallMode_NORMAL;
992 } 997 }
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
index 933b478..a1238db 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptThread.cs
@@ -39,7 +39,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
39 * Each sits in a loop checking the Start and Yield queues for 39 * Each sits in a loop checking the Start and Yield queues for
40 * a script to run and calls the script as a microthread. 40 * a script to run and calls the script as a microthread.
41 */ 41 */
42 public class XMRScriptThread { 42 public class XMRScriptThread
43 {
43 private static int m_WakeUpOne = 0; 44 private static int m_WakeUpOne = 0;
44 public static object m_WakeUpLock = new object(); 45 public static object m_WakeUpLock = new object();
45 private static Dictionary<Thread,XMRScriptThread> m_AllThreads = new Dictionary<Thread,XMRScriptThread> (); 46 private static Dictionary<Thread,XMRScriptThread> m_AllThreads = new Dictionary<Thread,XMRScriptThread> ();
@@ -81,10 +82,11 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
81 { 82 {
82 engine = eng; 83 engine = eng;
83 m_Continuations = engine.uThreadCtor.DeclaringType == typeof (ScriptUThread_Con); 84 m_Continuations = engine.uThreadCtor.DeclaringType == typeof (ScriptUThread_Con);
84 thd = XMREngine.StartMyThread (RunScriptThread, "xmrengine script", ThreadPriority.BelowNormal); 85// thd = XMREngine.StartMyThread (RunScriptThread, "xmrengine script", ThreadPriority.BelowNormal);
85 lock (m_AllThreads) { 86 thd = XMREngine.StartMyThread (RunScriptThread, "xmrengine script", ThreadPriority.Normal);
87 lock (m_AllThreads)
86 m_AllThreads.Add (thd, this); 88 m_AllThreads.Add (thd, this);
87 } 89
88 } 90 }
89 91
90 public void SuspendThread() 92 public void SuspendThread()
@@ -104,18 +106,17 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
104 m_Exiting = true; 106 m_Exiting = true;
105 WakeUpScriptThread(); 107 WakeUpScriptThread();
106 thd.Join(); 108 thd.Join();
107 lock (m_AllThreads) { 109 lock (m_AllThreads)
108 m_AllThreads.Remove (thd); 110 m_AllThreads.Remove (thd);
109 } 111
110 thd = null; 112 thd = null;
111 } 113 }
112 114
113 public void TimeSlice() 115 public void TimeSlice()
114 { 116 {
115 XMRInstance instance = m_RunInstance; 117 XMRInstance instance = m_RunInstance;
116 if (instance != null) { 118 if (instance != null)
117 instance.suspendOnCheckRunTemp = true; 119 instance.suspendOnCheckRunTemp = true;
118 }
119 } 120 }
120 121
121 /** 122 /**