aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
diff options
context:
space:
mode:
authoronefang2019-05-19 21:24:15 +1000
committeronefang2019-05-19 21:24:15 +1000
commit5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch)
treea9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
parentAdd a build script. (diff)
downloadopensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs172
1 files changed, 120 insertions, 52 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 0ca5ff3..a65f71f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Globalization; 30using System.Globalization;
31using System.Text;
31using System.Text.RegularExpressions; 32using System.Text.RegularExpressions;
32using OpenSim.Framework; 33using OpenSim.Framework;
33 34
@@ -38,7 +39,6 @@ using OMV_Quaternion = OpenMetaverse.Quaternion;
38 39
39namespace OpenSim.Region.ScriptEngine.Shared 40namespace OpenSim.Region.ScriptEngine.Shared
40{ 41{
41 [Serializable]
42 public partial class LSL_Types 42 public partial class LSL_Types
43 { 43 {
44 // Types are kept is separate .dll to avoid having to add whatever .dll it is in it to script AppDomain 44 // Types are kept is separate .dll to avoid having to add whatever .dll it is in it to script AppDomain
@@ -100,21 +100,32 @@ namespace OpenSim.Region.ScriptEngine.Shared
100 100
101 #region Overriders 101 #region Overriders
102 102
103 public static implicit operator Boolean(Vector3 vec)
104 {
105 if (vec.x != 0)
106 return true;
107 if (vec.y != 0)
108 return true;
109 if (vec.z != 0)
110 return true;
111 return false;
112 }
113
103 public override string ToString() 114 public override string ToString()
104 { 115 {
105 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); 116 string s = String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}>", x, y, z);
106 return s; 117 return s;
107 } 118 }
108 119
109 public static explicit operator LSLString(Vector3 vec) 120 public static explicit operator LSLString(Vector3 vec)
110 { 121 {
111 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); 122 string s = String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z);
112 return new LSLString(s); 123 return new LSLString(s);
113 } 124 }
114 125
115 public static explicit operator string(Vector3 vec) 126 public static explicit operator string(Vector3 vec)
116 { 127 {
117 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); 128 string s = String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z);
118 return s; 129 return s;
119 } 130 }
120 131
@@ -328,7 +339,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
328 y = (float)Quat.y; 339 y = (float)Quat.y;
329 z = (float)Quat.z; 340 z = (float)Quat.z;
330 s = (float)Quat.s; 341 s = (float)Quat.s;
331 if (x == 0 && y == 0 && z == 0 && s == 0) 342 if (s == 0 && x == 0 && y == 0 && z == 0)
332 s = 1; 343 s = 1;
333 } 344 }
334 345
@@ -338,7 +349,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
338 y = Y; 349 y = Y;
339 z = Z; 350 z = Z;
340 s = S; 351 s = S;
341 if (x == 0 && y == 0 && z == 0 && s == 0) 352 if (s == 0 && x == 0 && y == 0 && z == 0)
342 s = 1; 353 s = 1;
343 } 354 }
344 355
@@ -357,7 +368,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
357 res = res & Double.TryParse(tmps[1], NumberStyles.Float, Culture.NumberFormatInfo, out y); 368 res = res & Double.TryParse(tmps[1], NumberStyles.Float, Culture.NumberFormatInfo, out y);
358 res = res & Double.TryParse(tmps[2], NumberStyles.Float, Culture.NumberFormatInfo, out z); 369 res = res & Double.TryParse(tmps[2], NumberStyles.Float, Culture.NumberFormatInfo, out z);
359 res = res & Double.TryParse(tmps[3], NumberStyles.Float, Culture.NumberFormatInfo, out s); 370 res = res & Double.TryParse(tmps[3], NumberStyles.Float, Culture.NumberFormatInfo, out s);
360 if (x == 0 && y == 0 && z == 0 && s == 0) 371 if (s == 0 && x == 0 && y == 0 && z == 0)
361 s = 1; 372 s = 1;
362 } 373 }
363 374
@@ -397,6 +408,18 @@ namespace OpenSim.Region.ScriptEngine.Shared
397 #endregion 408 #endregion
398 409
399 #region Overriders 410 #region Overriders
411 public static implicit operator Boolean(Quaternion q)
412 {
413 if (q.x != 0)
414 return true;
415 if (q.y != 0)
416 return true;
417 if (q.z != 0)
418 return true;
419 if (q.s != 1.0f)
420 return true;
421 return false;
422 }
400 423
401 public override int GetHashCode() 424 public override int GetHashCode()
402 { 425 {
@@ -414,19 +437,19 @@ namespace OpenSim.Region.ScriptEngine.Shared
414 437
415 public override string ToString() 438 public override string ToString()
416 { 439 {
417 string st=String.Format(Culture.FormatProvider, "<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); 440 string st=String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", x, y, z, s);
418 return st; 441 return st;
419 } 442 }
420 443
421 public static explicit operator string(Quaternion r) 444 public static explicit operator string(Quaternion r)
422 { 445 {
423 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 446 string s=String.Format(Culture.FormatProvider,"<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
424 return s; 447 return s;
425 } 448 }
426 449
427 public static explicit operator LSLString(Quaternion r) 450 public static explicit operator LSLString(Quaternion r)
428 { 451 {
429 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 452 string s=String.Format(Culture.FormatProvider,"<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
430 return new LSLString(s); 453 return new LSLString(s);
431 } 454 }
432 455
@@ -502,7 +525,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
502 } 525 }
503 526
504 [Serializable] 527 [Serializable]
505 public struct list 528 public class list
506 { 529 {
507 private object[] m_data; 530 private object[] m_data;
508 531
@@ -537,7 +560,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
537 else if (o is LSL_Types.LSLFloat) 560 else if (o is LSL_Types.LSLFloat)
538 size += 8; 561 size += 8;
539 else if (o is LSL_Types.LSLString) 562 else if (o is LSL_Types.LSLString)
540 size += ((LSL_Types.LSLString)o).m_string.Length; 563 size += ((LSL_Types.LSLString)o).m_string == null ? 0 : ((LSL_Types.LSLString)o).m_string.Length;
541 else if (o is LSL_Types.key) 564 else if (o is LSL_Types.key)
542 size += ((LSL_Types.key)o).value.Length; 565 size += ((LSL_Types.key)o).value.Length;
543 else if (o is LSL_Types.Vector3) 566 else if (o is LSL_Types.Vector3)
@@ -546,6 +569,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
546 size += 64; 569 size += 64;
547 else if (o is int) 570 else if (o is int)
548 size += 4; 571 size += 4;
572 else if (o is uint)
573 size += 4;
549 else if (o is string) 574 else if (o is string)
550 size += ((string)o).Length; 575 size += ((string)o).Length;
551 else if (o is float) 576 else if (o is float)
@@ -675,16 +700,45 @@ namespace OpenSim.Region.ScriptEngine.Shared
675 } 700 }
676 } 701 }
677 702
703 // use LSL_Types.Quaternion to parse and store a vector4 for lightShare
704 public LSL_Types.Quaternion GetVector4Item(int itemIndex)
705 {
706 if (Data[itemIndex] is LSL_Types.Quaternion)
707 {
708 LSL_Types.Quaternion q = (LSL_Types.Quaternion)Data[itemIndex];
709 return q;
710 }
711 else if(Data[itemIndex] is OpenMetaverse.Quaternion)
712 {
713 LSL_Types.Quaternion q = new LSL_Types.Quaternion(
714 (OpenMetaverse.Quaternion)Data[itemIndex]);
715 q.Normalize();
716 return q;
717 }
718 else
719 {
720 throw new InvalidCastException(string.Format(
721 "{0} expected but {1} given",
722 typeof(LSL_Types.Quaternion).Name,
723 Data[itemIndex] != null ?
724 Data[itemIndex].GetType().Name : "null"));
725 }
726 }
727
678 public LSL_Types.Quaternion GetQuaternionItem(int itemIndex) 728 public LSL_Types.Quaternion GetQuaternionItem(int itemIndex)
679 { 729 {
680 if (Data[itemIndex] is LSL_Types.Quaternion) 730 if (Data[itemIndex] is LSL_Types.Quaternion)
681 { 731 {
682 return (LSL_Types.Quaternion)Data[itemIndex]; 732 LSL_Types.Quaternion q = (LSL_Types.Quaternion)Data[itemIndex];
733 q.Normalize();
734 return q;
683 } 735 }
684 else if(Data[itemIndex] is OpenMetaverse.Quaternion) 736 else if(Data[itemIndex] is OpenMetaverse.Quaternion)
685 { 737 {
686 return new LSL_Types.Quaternion( 738 LSL_Types.Quaternion q = new LSL_Types.Quaternion(
687 (OpenMetaverse.Quaternion)Data[itemIndex]); 739 (OpenMetaverse.Quaternion)Data[itemIndex]);
740 q.Normalize();
741 return q;
688 } 742 }
689 else 743 else
690 { 744 {
@@ -719,6 +773,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
719 Data = tmp; 773 Data = tmp;
720 } 774 }
721 775
776 public static implicit operator Boolean(list l)
777 {
778 return l.Length != 0;
779 }
780
722 public static list operator +(list a, LSLString s) 781 public static list operator +(list a, LSLString s)
723 { 782 {
724 a.ExtendAndAdd(s); 783 a.ExtendAndAdd(s);
@@ -755,7 +814,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
755 int lb = -1; 814 int lb = -1;
756 try { la = a.Length; } 815 try { la = a.Length; }
757 catch (NullReferenceException) { } 816 catch (NullReferenceException) { }
758 try {lb = b.Length;} 817 try { lb = b.Length; }
759 catch (NullReferenceException) { } 818 catch (NullReferenceException) { }
760 819
761 return la != lb; 820 return la != lb;
@@ -1023,6 +1082,9 @@ namespace OpenSim.Region.ScriptEngine.Shared
1023 stride = 1; 1082 stride = 1;
1024 } 1083 }
1025 1084
1085 if ((Data.Length % stride) != 0)
1086 return new list(ret);
1087
1026 // we can optimize here in the case where stride == 1 and the list 1088 // we can optimize here in the case where stride == 1 and the list
1027 // consists of homogeneous types 1089 // consists of homogeneous types
1028 1090
@@ -1090,34 +1152,35 @@ namespace OpenSim.Region.ScriptEngine.Shared
1090 1152
1091 public string ToCSV() 1153 public string ToCSV()
1092 { 1154 {
1093 string ret = ""; 1155 if(m_data == null || m_data.Length == 0)
1094 foreach (object o in this.Data) 1156 return String.Empty;
1157
1158 Object o = m_data[0];
1159 int len = m_data.Length;
1160 if(len == 1)
1161 return o.ToString();
1162
1163 StringBuilder sb = new StringBuilder(1024);
1164 sb.Append(o.ToString());
1165 for(int i = 1 ; i < len; i++)
1095 { 1166 {
1096 if (ret == "") 1167 sb.Append(",");
1097 { 1168 sb.Append(o.ToString());
1098 ret = o.ToString();
1099 }
1100 else
1101 {
1102 ret = ret + ", " + o.ToString();
1103 }
1104 } 1169 }
1105 return ret; 1170 return sb.ToString();
1106 } 1171 }
1107 1172
1108 private string ToSoup() 1173 private string ToSoup()
1109 { 1174 {
1110 string output; 1175 if(m_data == null || m_data.Length == 0)
1111 output = String.Empty;
1112 if (Data.Length == 0)
1113 {
1114 return String.Empty; 1176 return String.Empty;
1115 } 1177
1116 foreach (object o in Data) 1178 StringBuilder sb = new StringBuilder(1024);
1179 foreach (object o in m_data)
1117 { 1180 {
1118 output = output + o.ToString(); 1181 sb.Append(o.ToString());
1119 } 1182 }
1120 return output; 1183 return sb.ToString();
1121 } 1184 }
1122 1185
1123 public static explicit operator String(list l) 1186 public static explicit operator String(list l)
@@ -1307,26 +1370,33 @@ namespace OpenSim.Region.ScriptEngine.Shared
1307 1370
1308 public string ToPrettyString() 1371 public string ToPrettyString()
1309 { 1372 {
1310 string output; 1373 if(m_data == null || m_data.Length == 0)
1311 if (Data.Length == 0)
1312 {
1313 return "[]"; 1374 return "[]";
1314 } 1375
1315 output = "["; 1376 StringBuilder sb = new StringBuilder(1024);
1316 foreach (object o in Data) 1377 int len = m_data.Length;
1378 int last = len - 1;
1379 object o;
1380
1381 sb.Append("[");
1382 for(int i = 0; i < len; i++ )
1317 { 1383 {
1384 o = m_data[i];
1318 if (o is String) 1385 if (o is String)
1319 { 1386 {
1320 output = output + "\"" + o + "\", "; 1387 sb.Append("\"");
1388 sb.Append((String)o);
1389 sb.Append("\"");
1321 } 1390 }
1322 else 1391 else
1323 { 1392 {
1324 output = output + o.ToString() + ", "; 1393 sb.Append(o.ToString());
1325 } 1394 }
1395 if(i < last)
1396 sb.Append(",");
1326 } 1397 }
1327 output = output.Substring(0, output.Length - 2); 1398 sb.Append("]");
1328 output = output + "]"; 1399 return sb.ToString();
1329 return output;
1330 } 1400 }
1331 1401
1332 public class AlphaCompare : IComparer 1402 public class AlphaCompare : IComparer
@@ -1433,7 +1503,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1433 return false; 1503 return false;
1434 } 1504 }
1435 } 1505 }
1436 1506
1437 public static bool operator true(key k) 1507 public static bool operator true(key k)
1438 { 1508 {
1439 return (Boolean)k; 1509 return (Boolean)k;
@@ -1513,7 +1583,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1513 string s = String.Format(Culture.FormatProvider, "{0:0.000000}", f.value); 1583 string s = String.Format(Culture.FormatProvider, "{0:0.000000}", f.value);
1514 m_string = s; 1584 m_string = s;
1515 } 1585 }
1516 1586
1517 public LSLString(int i) 1587 public LSLString(int i)
1518 { 1588 {
1519 string s = String.Format("{0}", i); 1589 string s = String.Format("{0}", i);
@@ -1521,7 +1591,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1521 } 1591 }
1522 1592
1523 public LSLString(LSLInteger i) : this(i.value) {} 1593 public LSLString(LSLInteger i) : this(i.value) {}
1524 1594
1525 #endregion 1595 #endregion
1526 1596
1527 #region Operators 1597 #region Operators
@@ -1537,8 +1607,6 @@ namespace OpenSim.Region.ScriptEngine.Shared
1537 } 1607 }
1538 } 1608 }
1539 1609
1540
1541
1542 static public implicit operator String(LSLString s) 1610 static public implicit operator String(LSLString s)
1543 { 1611 {
1544 return s.m_string; 1612 return s.m_string;
@@ -1588,7 +1656,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1588 { 1656 {
1589 return new LSLString(d); 1657 return new LSLString(d);
1590 } 1658 }
1591 1659
1592 static public explicit operator LSLString(int i) 1660 static public explicit operator LSLString(int i)
1593 { 1661 {
1594 return new LSLString(i); 1662 return new LSLString(i);
@@ -1876,7 +1944,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1876 return false; 1944 return false;
1877 } 1945 }
1878 } 1946 }
1879 1947
1880 return value == ((LSLInteger)o).value; 1948 return value == ((LSLInteger)o).value;
1881 } 1949 }
1882 1950