diff options
author | Melanie Thielker | 2008-09-03 18:57:06 +0000 |
---|---|---|
committer | Melanie Thielker | 2008-09-03 18:57:06 +0000 |
commit | ef27c8817fb2899b02116296001770005622f375 (patch) | |
tree | 2a75a9cabf187e670b848ccdb88eb43c7e76f8d0 | |
parent | add standard copyright headers for the project (diff) | |
download | opensim-SC-ef27c8817fb2899b02116296001770005622f375.zip opensim-SC-ef27c8817fb2899b02116296001770005622f375.tar.gz opensim-SC-ef27c8817fb2899b02116296001770005622f375.tar.bz2 opensim-SC-ef27c8817fb2899b02116296001770005622f375.tar.xz |
Mantis #2112
Thannk you, ralphos, for a patch to clean up list item type handling
and add a missing explicit cast in Shared/
4 files changed, 103 insertions, 17 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index d4911d7..aa22b2b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -5721,13 +5721,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5721 | if (remain < 7) | 5721 | if (remain < 7) |
5722 | return; | 5722 | return; |
5723 | 5723 | ||
5724 | LSL_Types.LSLInteger flexi = new LSL_Types.LSLInteger(rules.Data[idx++].ToString()); | 5724 | bool flexi = (LSL_Types.LSLInteger)rules.Data[idx++]; |
5725 | int softness = Convert.ToInt32(rules.Data[idx++]); | 5725 | int softness = (LSL_Types.LSLInteger)rules.Data[idx++]; |
5726 | float gravity = (float)Convert.ToDouble(rules.Data[idx++]); | 5726 | float gravity = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; |
5727 | float friction = (float)Convert.ToDouble(rules.Data[idx++]); | 5727 | float friction = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; |
5728 | float wind = (float)Convert.ToDouble(rules.Data[idx++]); | 5728 | float wind = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; |
5729 | float tension = (float)Convert.ToDouble(rules.Data[idx++]); | 5729 | float tension = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; |
5730 | LSL_Types.Vector3 force =new LSL_Types.Vector3(rules.Data[idx++].ToString()); | 5730 | LSL_Types.Vector3 force = (LSL_Types.Vector3)rules.Data[idx++]; |
5731 | 5731 | ||
5732 | SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force); | 5732 | SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force); |
5733 | 5733 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 3e63808..85abdb0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -1569,9 +1569,14 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1569 | 1569 | ||
1570 | #region Operators | 1570 | #region Operators |
1571 | 1571 | ||
1572 | static public explicit operator float(LSLFloat f) | ||
1573 | { | ||
1574 | return (float)f.value; | ||
1575 | } | ||
1576 | |||
1572 | static public explicit operator int(LSLFloat f) | 1577 | static public explicit operator int(LSLFloat f) |
1573 | { | 1578 | { |
1574 | return (int)f.value; | 1579 | return (int)f.value; |
1575 | } | 1580 | } |
1576 | 1581 | ||
1577 | static public explicit operator uint(LSLFloat f) | 1582 | static public explicit operator uint(LSLFloat f) |
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs index c021963..272d06c 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs | |||
@@ -396,6 +396,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
396 | } | 396 | } |
397 | 397 | ||
398 | /// <summary> | 398 | /// <summary> |
399 | /// Tests LSLFloat is correctly cast explicitly to float | ||
400 | /// </summary> | ||
401 | [Test] | ||
402 | public void TestExplicitCastLSLFloatToFloat() | ||
403 | { | ||
404 | float testFloat; | ||
405 | float numberAsFloat; | ||
406 | LSL_Types.LSLFloat testLSLFloat; | ||
407 | foreach (double number in m_doubleList) | ||
408 | { | ||
409 | testLSLFloat = new LSL_Types.LSLFloat(number); | ||
410 | numberAsFloat = (float)number; | ||
411 | testFloat = (float)testLSLFloat; | ||
412 | |||
413 | Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance)); | ||
414 | } | ||
415 | } | ||
416 | |||
417 | |||
418 | /// <summary> | ||
399 | /// Tests the equality (==) operator. | 419 | /// Tests the equality (==) operator. |
400 | /// </summary> | 420 | /// </summary> |
401 | [Test] | 421 | [Test] |
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs index c1c9ef7..9e8d716 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs | |||
@@ -84,18 +84,79 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
84 | [Test] | 84 | [Test] |
85 | public void TestConcatenateDouble() | 85 | public void TestConcatenateDouble() |
86 | { | 86 | { |
87 | LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); | 87 | LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); |
88 | testList += 2.0; | 88 | testList += 2.0; |
89 | 89 | ||
90 | Assert.AreEqual(4, testList.Length); | 90 | Assert.AreEqual(4, testList.Length); |
91 | Assert.AreEqual(2.0, testList.Data[3]); | 91 | Assert.AreEqual(2.0, testList.Data[3]); |
92 | Assert.AreEqual(typeof(double), testList.Data[3].GetType()); | 92 | Assert.AreEqual(typeof(double), testList.Data[3].GetType()); |
93 | 93 | ||
94 | LSL_Types.list secondTestList = testList + 0.04; | 94 | LSL_Types.list secondTestList = testList + 0.04; |
95 | 95 | ||
96 | Assert.AreEqual(5, secondTestList.Length); | 96 | Assert.AreEqual(5, secondTestList.Length); |
97 | Assert.AreEqual(0.04, secondTestList.Data[4]); | 97 | Assert.AreEqual(0.04, secondTestList.Data[4]); |
98 | Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType()); | 98 | Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType()); |
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Tests casting LSLInteger item to LSLInteger. | ||
103 | /// </summary> | ||
104 | [Test] | ||
105 | public void TestCastLSLIntegerItemToLSLInteger() | ||
106 | { | ||
107 | LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(123); | ||
108 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
109 | |||
110 | Assert.AreEqual(testValue, (LSL_Types.LSLInteger)testList.Data[0]); | ||
99 | } | 111 | } |
112 | |||
113 | /// <summary> | ||
114 | /// Tests casting LSLFloat item to LSLFloat. | ||
115 | /// </summary> | ||
116 | [Test] | ||
117 | public void TestCastLSLFloatItemToLSLFloat() | ||
118 | { | ||
119 | LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(123.45678987); | ||
120 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
121 | |||
122 | Assert.AreEqual(testValue, (LSL_Types.LSLFloat)testList.Data[0]); | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
126 | /// Tests casting LSLString item to LSLString. | ||
127 | /// </summary> | ||
128 | [Test] | ||
129 | public void TestCastLSLStringItemToLSLString() | ||
130 | { | ||
131 | LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello there"); | ||
132 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
133 | |||
134 | Assert.AreEqual(testValue, (LSL_Types.LSLString)testList.Data[0]); | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// Tests casting Vector3 item to Vector3. | ||
139 | /// </summary> | ||
140 | [Test] | ||
141 | public void TestCastVector3ItemToVector3() | ||
142 | { | ||
143 | LSL_Types.Vector3 testValue = new LSL_Types.Vector3(12.34, 56.987654, 0.00987); | ||
144 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
145 | |||
146 | Assert.AreEqual(testValue, (LSL_Types.Vector3)testList.Data[0]); | ||
147 | } | ||
148 | /// <summary> | ||
149 | /// Tests casting Quaternion item to Quaternion. | ||
150 | /// </summary> | ||
151 | [Test] | ||
152 | public void TestCastQuaternionItemToQuaternion() | ||
153 | { | ||
154 | LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.34, 56.44323, 765.983421, 0.00987); | ||
155 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
156 | |||
157 | Assert.AreEqual(testValue, (LSL_Types.Quaternion)testList.Data[0]); | ||
158 | } | ||
159 | |||
160 | |||
100 | } | 161 | } |
101 | } | 162 | } |