diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/LSL_Types.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 376 |
1 files changed, 188 insertions, 188 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index edd16a7..923b81e 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | |||
@@ -64,11 +64,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
64 | str = str.Replace('<', ' '); | 64 | str = str.Replace('<', ' '); |
65 | str = str.Replace('>', ' '); | 65 | str = str.Replace('>', ' '); |
66 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); | 66 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); |
67 | if(tmps.Length < 3) | 67 | if (tmps.Length < 3) |
68 | { | 68 | { |
69 | x=y=z=0; | 69 | x=y=z=0; |
70 | return; | 70 | return; |
71 | } | 71 | } |
72 | bool res; | 72 | bool res; |
73 | res = Double.TryParse(tmps[0], out x); | 73 | res = Double.TryParse(tmps[0], out x); |
74 | res = res & Double.TryParse(tmps[1], out y); | 74 | res = res & Double.TryParse(tmps[1], out y); |
@@ -81,26 +81,26 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
81 | 81 | ||
82 | public override string ToString() | 82 | public override string ToString() |
83 | { | 83 | { |
84 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); | 84 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); |
85 | return s; | 85 | return s; |
86 | } | 86 | } |
87 | 87 | ||
88 | public static explicit operator LSLString(Vector3 vec) | 88 | public static explicit operator LSLString(Vector3 vec) |
89 | { | 89 | { |
90 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); | 90 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); |
91 | return new LSLString(s); | 91 | return new LSLString(s); |
92 | } | 92 | } |
93 | 93 | ||
94 | public static explicit operator string(Vector3 vec) | 94 | public static explicit operator string(Vector3 vec) |
95 | { | 95 | { |
96 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); | 96 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); |
97 | return s; | 97 | return s; |
98 | } | 98 | } |
99 | 99 | ||
100 | public static explicit operator Vector3(string s) | 100 | public static explicit operator Vector3(string s) |
101 | { | 101 | { |
102 | return new Vector3(s); | 102 | return new Vector3(s); |
103 | } | 103 | } |
104 | 104 | ||
105 | public static bool operator ==(Vector3 lhs, Vector3 rhs) | 105 | public static bool operator ==(Vector3 lhs, Vector3 rhs) |
106 | { | 106 | { |
@@ -296,11 +296,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
296 | str = str.Replace('<', ' '); | 296 | str = str.Replace('<', ' '); |
297 | str = str.Replace('>', ' '); | 297 | str = str.Replace('>', ' '); |
298 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); | 298 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); |
299 | if(tmps.Length < 4) | 299 | if (tmps.Length < 4) |
300 | { | 300 | { |
301 | x=y=z=s=0; | 301 | x=y=z=s=0; |
302 | return; | 302 | return; |
303 | } | 303 | } |
304 | bool res; | 304 | bool res; |
305 | res = Double.TryParse(tmps[0], out x); | 305 | res = Double.TryParse(tmps[0], out x); |
306 | res = res & Double.TryParse(tmps[1], out y); | 306 | res = res & Double.TryParse(tmps[1], out y); |
@@ -330,26 +330,26 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
330 | 330 | ||
331 | public override string ToString() | 331 | public override string ToString() |
332 | { | 332 | { |
333 | string st=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); | 333 | string st=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); |
334 | return st; | 334 | return st; |
335 | } | 335 | } |
336 | 336 | ||
337 | public static explicit operator string(Quaternion r) | 337 | public static explicit operator string(Quaternion r) |
338 | { | 338 | { |
339 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); | 339 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); |
340 | return s; | 340 | return s; |
341 | } | 341 | } |
342 | 342 | ||
343 | public static explicit operator LSLString(Quaternion r) | 343 | public static explicit operator LSLString(Quaternion r) |
344 | { | 344 | { |
345 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); | 345 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); |
346 | return new LSLString(s); | 346 | return new LSLString(s); |
347 | } | 347 | } |
348 | 348 | ||
349 | public static explicit operator Quaternion(string s) | 349 | public static explicit operator Quaternion(string s) |
350 | { | 350 | { |
351 | return new Quaternion(s); | 351 | return new Quaternion(s); |
352 | } | 352 | } |
353 | 353 | ||
354 | public static bool operator ==(Quaternion lhs, Quaternion rhs) | 354 | public static bool operator ==(Quaternion lhs, Quaternion rhs) |
355 | { | 355 | { |
@@ -406,19 +406,19 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
406 | public int Length | 406 | public int Length |
407 | { | 407 | { |
408 | get { | 408 | get { |
409 | if(m_data == null) | 409 | if (m_data == null) |
410 | m_data=new Object[0]; | 410 | m_data=new Object[0]; |
411 | return m_data.Length; | 411 | return m_data.Length; |
412 | } | 412 | } |
413 | } | 413 | } |
414 | 414 | ||
415 | public object[] Data | 415 | public object[] Data |
416 | { | 416 | { |
417 | get { | 417 | get { |
418 | if(m_data == null) | 418 | if (m_data == null) |
419 | m_data=new Object[0]; | 419 | m_data=new Object[0]; |
420 | return m_data; | 420 | return m_data; |
421 | } | 421 | } |
422 | } | 422 | } |
423 | 423 | ||
424 | public static list operator +(list a, list b) | 424 | public static list operator +(list a, list b) |
@@ -453,67 +453,67 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
453 | return ret; | 453 | return ret; |
454 | } | 454 | } |
455 | 455 | ||
456 | public list DeleteSublist(int start, int end) | 456 | public list DeleteSublist(int start, int end) |
457 | { | 457 | { |
458 | // Not an easy one | 458 | // Not an easy one |
459 | // If start <= end, remove that part | 459 | // If start <= end, remove that part |
460 | // if either is negative, count from the end of the array | 460 | // if either is negative, count from the end of the array |
461 | // if the resulting start > end, remove all BUT that part | 461 | // if the resulting start > end, remove all BUT that part |
462 | 462 | ||
463 | Object[] ret; | 463 | Object[] ret; |
464 | 464 | ||
465 | if(start < 0) | 465 | if (start < 0) |
466 | start=m_data.Length-start; | 466 | start=m_data.Length-start; |
467 | 467 | ||
468 | if(start < 0) | 468 | if (start < 0) |
469 | start=0; | 469 | start=0; |
470 | 470 | ||
471 | if(end < 0) | 471 | if (end < 0) |
472 | end=m_data.Length-end; | 472 | end=m_data.Length-end; |
473 | if(end < 0) | 473 | if (end < 0) |
474 | end=0; | 474 | end=0; |
475 | 475 | ||
476 | if(start > end) | 476 | if (start > end) |
477 | { | 477 | { |
478 | if(end >= m_data.Length) | 478 | if (end >= m_data.Length) |
479 | return new list(new Object[0]); | 479 | return new list(new Object[0]); |
480 | 480 | ||
481 | if(start >= m_data.Length) | 481 | if (start >= m_data.Length) |
482 | start=m_data.Length-1; | 482 | start=m_data.Length-1; |
483 | 483 | ||
484 | return GetSublist(end, start); | 484 | return GetSublist(end, start); |
485 | } | 485 | } |
486 | 486 | ||
487 | // start >= 0 && end >= 0 here | 487 | // start >= 0 && end >= 0 here |
488 | if(start >= m_data.Length) | 488 | if (start >= m_data.Length) |
489 | { | 489 | { |
490 | ret=new Object[m_data.Length]; | 490 | ret=new Object[m_data.Length]; |
491 | Array.Copy(m_data, 0, ret, 0, m_data.Length); | 491 | Array.Copy(m_data, 0, ret, 0, m_data.Length); |
492 | 492 | ||
493 | return new list(ret); | 493 | return new list(ret); |
494 | } | 494 | } |
495 | 495 | ||
496 | if(end >= m_data.Length) | 496 | if (end >= m_data.Length) |
497 | end=m_data.Length-1; | 497 | end=m_data.Length-1; |
498 | 498 | ||
499 | // now, this makes the math easier | 499 | // now, this makes the math easier |
500 | int remove=end+1-start; | 500 | int remove=end+1-start; |
501 | 501 | ||
502 | ret=new Object[m_data.Length-remove]; | 502 | ret=new Object[m_data.Length-remove]; |
503 | if(ret.Length == 0) | 503 | if (ret.Length == 0) |
504 | return new list(ret); | 504 | return new list(ret); |
505 | 505 | ||
506 | int src; | 506 | int src; |
507 | int dest=0; | 507 | int dest=0; |
508 | 508 | ||
509 | for(src = 0 ; src < m_data.Length ; src++) | 509 | for(src = 0 ; src < m_data.Length ; src++) |
510 | { | 510 | { |
511 | if(src < start || src > end) | 511 | if (src < start || src > end) |
512 | ret[dest++]=m_data[src]; | 512 | ret[dest++]=m_data[src]; |
513 | } | 513 | } |
514 | 514 | ||
515 | return new list(ret); | 515 | return new list(ret); |
516 | } | 516 | } |
517 | 517 | ||
518 | public list GetSublist(int start, int end) | 518 | public list GetSublist(int start, int end) |
519 | { | 519 | { |
@@ -581,13 +581,13 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
581 | list result = null; | 581 | list result = null; |
582 | 582 | ||
583 | // If end is negative, then prefix list is empty | 583 | // If end is negative, then prefix list is empty |
584 | if(end < 0) | 584 | if (end < 0) |
585 | { | 585 | { |
586 | result = new list(); | 586 | result = new list(); |
587 | // If start is still negative, then the whole of | 587 | // If start is still negative, then the whole of |
588 | // the existing list is returned. This case is | 588 | // the existing list is returned. This case is |
589 | // only admitted if end is also still negative. | 589 | // only admitted if end is also still negative. |
590 | if(start < 0) | 590 | if (start < 0) |
591 | { | 591 | { |
592 | return this; | 592 | return this; |
593 | } | 593 | } |
@@ -600,7 +600,7 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
600 | 600 | ||
601 | // If start is outside of list, then just return | 601 | // If start is outside of list, then just return |
602 | // the prefix, whatever it is. | 602 | // the prefix, whatever it is. |
603 | if(start >= m_data.Length) | 603 | if (start >= m_data.Length) |
604 | { | 604 | { |
605 | return result; | 605 | return result; |
606 | } | 606 | } |
@@ -610,76 +610,76 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
610 | } | 610 | } |
611 | } | 611 | } |
612 | 612 | ||
613 | public list Sort(int stride, int ascending) | 613 | public list Sort(int stride, int ascending) |
614 | { | 614 | { |
615 | if(Data.Length == 0) | 615 | if (Data.Length == 0) |
616 | return new list(); // Don't even bother | 616 | return new list(); // Don't even bother |
617 | 617 | ||
618 | string[] keys; | 618 | string[] keys; |
619 | 619 | ||
620 | if(stride == 1) // The simple case | 620 | if (stride == 1) // The simple case |
621 | { | 621 | { |
622 | Object[] ret=new Object[Data.Length]; | 622 | Object[] ret=new Object[Data.Length]; |
623 | 623 | ||
624 | Array.Copy(Data, 0, ret, 0, Data.Length); | 624 | Array.Copy(Data, 0, ret, 0, Data.Length); |
625 | 625 | ||
626 | keys=new string[Data.Length]; | 626 | keys=new string[Data.Length]; |
627 | int k; | 627 | int k; |
628 | for(k=0;k<Data.Length;k++) | 628 | for(k=0;k<Data.Length;k++) |
629 | keys[k]=Data[k].ToString(); | 629 | keys[k]=Data[k].ToString(); |
630 | 630 | ||
631 | Array.Sort(keys, ret); | 631 | Array.Sort(keys, ret); |
632 | 632 | ||
633 | if(ascending == 0) | 633 | if (ascending == 0) |
634 | Array.Reverse(ret); | 634 | Array.Reverse(ret); |
635 | return new list(ret); | 635 | return new list(ret); |
636 | } | 636 | } |
637 | 637 | ||
638 | int src=0; | 638 | int src=0; |
639 | 639 | ||
640 | int len=(Data.Length+stride-1)/stride; | 640 | int len=(Data.Length+stride-1)/stride; |
641 | 641 | ||
642 | keys=new string[len]; | 642 | keys=new string[len]; |
643 | Object[][] vals=new Object[len][]; | 643 | Object[][] vals=new Object[len][]; |
644 | 644 | ||
645 | int i; | 645 | int i; |
646 | 646 | ||
647 | while(src < Data.Length) | 647 | while(src < Data.Length) |
648 | { | 648 | { |
649 | Object[] o=new Object[stride]; | 649 | Object[] o=new Object[stride]; |
650 | 650 | ||
651 | for(i=0;i<stride;i++) | 651 | for(i=0;i<stride;i++) |
652 | { | 652 | { |
653 | if(src < Data.Length) | 653 | if (src < Data.Length) |
654 | o[i]=Data[src++]; | 654 | o[i]=Data[src++]; |
655 | else | 655 | else |
656 | { | 656 | { |
657 | o[i]=new Object(); | 657 | o[i]=new Object(); |
658 | src++; | 658 | src++; |
659 | } | 659 | } |
660 | } | 660 | } |
661 | 661 | ||
662 | int idx=src/stride-1; | 662 | int idx=src/stride-1; |
663 | keys[idx]=o[0].ToString(); | 663 | keys[idx]=o[0].ToString(); |
664 | vals[idx]=o; | 664 | vals[idx]=o; |
665 | } | 665 | } |
666 | 666 | ||
667 | Array.Sort(keys, vals); | 667 | Array.Sort(keys, vals); |
668 | if(ascending == 0) | 668 | if (ascending == 0) |
669 | { | 669 | { |
670 | Array.Reverse(vals); | 670 | Array.Reverse(vals); |
671 | } | 671 | } |
672 | 672 | ||
673 | Object[] sorted=new Object[stride*vals.Length]; | 673 | Object[] sorted=new Object[stride*vals.Length]; |
674 | 674 | ||
675 | int j; | 675 | int j; |
676 | 676 | ||
677 | for(i=0;i<vals.Length;i++) | 677 | for(i=0;i<vals.Length;i++) |
678 | for(j=0;j<stride;j++) | 678 | for(j=0;j<stride;j++) |
679 | sorted[i*stride+j]=vals[i][j]; | 679 | sorted[i*stride+j]=vals[i][j]; |
680 | 680 | ||
681 | return new list(sorted); | 681 | return new list(sorted); |
682 | } | 682 | } |
683 | 683 | ||
684 | #region CSV Methods | 684 | #region CSV Methods |
685 | 685 | ||
@@ -693,7 +693,7 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
693 | string ret = ""; | 693 | string ret = ""; |
694 | foreach(object o in this.Data) | 694 | foreach(object o in this.Data) |
695 | { | 695 | { |
696 | if(ret == "") | 696 | if (ret == "") |
697 | { | 697 | { |
698 | ret = o.ToString(); | 698 | ret = o.ToString(); |
699 | } | 699 | } |
@@ -720,20 +720,20 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
720 | return output; | 720 | return output; |
721 | } | 721 | } |
722 | 722 | ||
723 | public static explicit operator String(list l) | 723 | public static explicit operator String(list l) |
724 | { | 724 | { |
725 | return l.ToSoup(); | 725 | return l.ToSoup(); |
726 | } | 726 | } |
727 | 727 | ||
728 | public static explicit operator LSLString(list l) | 728 | public static explicit operator LSLString(list l) |
729 | { | 729 | { |
730 | return new LSLString(l.ToSoup()); | 730 | return new LSLString(l.ToSoup()); |
731 | } | 731 | } |
732 | 732 | ||
733 | public override string ToString() | 733 | public override string ToString() |
734 | { | 734 | { |
735 | return ToSoup(); | 735 | return ToSoup(); |
736 | } | 736 | } |
737 | 737 | ||
738 | #endregion | 738 | #endregion |
739 | 739 | ||
@@ -1068,7 +1068,7 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1068 | 1068 | ||
1069 | public override bool Equals(object o) | 1069 | public override bool Equals(object o) |
1070 | { | 1070 | { |
1071 | return o.ToString() == value; | 1071 | return o.ToString() == value; |
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | public override int GetHashCode() | 1074 | public override int GetHashCode() |
@@ -1089,11 +1089,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1089 | m_string = s; | 1089 | m_string = s; |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | public LSLString(double d) | 1092 | public LSLString(double d) |
1093 | { | 1093 | { |
1094 | string s=String.Format("{0:0.000000}", d); | 1094 | string s=String.Format("{0:0.000000}", d); |
1095 | m_string=s; | 1095 | m_string=s; |
1096 | } | 1096 | } |
1097 | 1097 | ||
1098 | #endregion | 1098 | #endregion |
1099 | 1099 | ||
@@ -1120,10 +1120,10 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1120 | return new LSLString(s); | 1120 | return new LSLString(s); |
1121 | } | 1121 | } |
1122 | 1122 | ||
1123 | public static string ToString(LSLString s) | 1123 | public static string ToString(LSLString s) |
1124 | { | 1124 | { |
1125 | return s.m_string; | 1125 | return s.m_string; |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | public override string ToString() | 1128 | public override string ToString() |
1129 | { | 1129 | { |
@@ -1140,27 +1140,27 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1140 | return s1.m_string != s2; | 1140 | return s1.m_string != s2; |
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | public static explicit operator double(LSLString s) | 1143 | public static explicit operator double(LSLString s) |
1144 | { | 1144 | { |
1145 | return Convert.ToDouble(s.m_string); | 1145 | return Convert.ToDouble(s.m_string); |
1146 | } | 1146 | } |
1147 | 1147 | ||
1148 | public static explicit operator LSLInteger(LSLString s) | 1148 | public static explicit operator LSLInteger(LSLString s) |
1149 | { | 1149 | { |
1150 | return new LSLInteger(Convert.ToInt32(s.m_string)); | 1150 | return new LSLInteger(Convert.ToInt32(s.m_string)); |
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | public static explicit operator LSLString(double d) | 1153 | public static explicit operator LSLString(double d) |
1154 | { | 1154 | { |
1155 | return new LSLString(d); | 1155 | return new LSLString(d); |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | #endregion | 1158 | #endregion |
1159 | 1159 | ||
1160 | #region Overriders | 1160 | #region Overriders |
1161 | public override bool Equals(object o) | 1161 | public override bool Equals(object o) |
1162 | { | 1162 | { |
1163 | return m_string == o.ToString(); | 1163 | return m_string == o.ToString(); |
1164 | } | 1164 | } |
1165 | 1165 | ||
1166 | public override int GetHashCode() | 1166 | public override int GetHashCode() |
@@ -1212,10 +1212,10 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1212 | return (uint)i.value; | 1212 | return (uint)i.value; |
1213 | } | 1213 | } |
1214 | 1214 | ||
1215 | static public explicit operator LSLString(LSLInteger i) | 1215 | static public explicit operator LSLString(LSLInteger i) |
1216 | { | 1216 | { |
1217 | return new LSLString(i.ToString()); | 1217 | return new LSLString(i.ToString()); |
1218 | } | 1218 | } |
1219 | 1219 | ||
1220 | static public implicit operator Boolean(LSLInteger i) | 1220 | static public implicit operator Boolean(LSLInteger i) |
1221 | { | 1221 | { |
@@ -1234,10 +1234,10 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1234 | return new LSLInteger(i); | 1234 | return new LSLInteger(i); |
1235 | } | 1235 | } |
1236 | 1236 | ||
1237 | static public explicit operator LSLInteger(string s) | 1237 | static public explicit operator LSLInteger(string s) |
1238 | { | 1238 | { |
1239 | return new LSLInteger(int.Parse(s)); | 1239 | return new LSLInteger(int.Parse(s)); |
1240 | } | 1240 | } |
1241 | 1241 | ||
1242 | static public implicit operator LSLInteger(double d) | 1242 | static public implicit operator LSLInteger(double d) |
1243 | { | 1243 | { |
@@ -1250,17 +1250,17 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1250 | return ret; | 1250 | return ret; |
1251 | } | 1251 | } |
1252 | 1252 | ||
1253 | public static LSLInteger operator ++(LSLInteger i) | 1253 | public static LSLInteger operator ++(LSLInteger i) |
1254 | { | 1254 | { |
1255 | i.value++; | 1255 | i.value++; |
1256 | return i; | 1256 | return i; |
1257 | } | 1257 | } |
1258 | 1258 | ||
1259 | public static LSLInteger operator --(LSLInteger i) | 1259 | public static LSLInteger operator --(LSLInteger i) |
1260 | { | 1260 | { |
1261 | i.value--; | 1261 | i.value--; |
1262 | return i; | 1262 | return i; |
1263 | } | 1263 | } |
1264 | 1264 | ||
1265 | static public implicit operator System.Double(LSLInteger i) | 1265 | static public implicit operator System.Double(LSLInteger i) |
1266 | { | 1266 | { |