diff options
author | SignpostMarv | 2012-08-13 12:20:19 +0100 |
---|---|---|
committer | Melanie | 2012-08-13 19:17:19 +0100 |
commit | 58c630c18e3540fc1c33fda5f12bbcba540f44cb (patch) | |
tree | ff3bd9b611e61ddf25a9264ea9de53c8b732a54a /OpenSim/Region | |
parent | Merge branch 'bulletsim7' (diff) | |
download | opensim-SC_OLD-58c630c18e3540fc1c33fda5f12bbcba540f44cb.zip opensim-SC_OLD-58c630c18e3540fc1c33fda5f12bbcba540f44cb.tar.gz opensim-SC_OLD-58c630c18e3540fc1c33fda5f12bbcba540f44cb.tar.bz2 opensim-SC_OLD-58c630c18e3540fc1c33fda5f12bbcba540f44cb.tar.xz |
attempt at replicating behaviour of llList2thing functions in SL
Committed with changes. Please don't sign comments with your name. Please
don't use your own coding style, use the OpenSim project style. Please
don't modify unrelated whitespace.
Signed-off-by: Melanie <melanie@t-data.com>
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 76 |
1 files changed, 69 insertions, 7 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 3591d14..e87ec1c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -4957,12 +4957,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4957 | { | 4957 | { |
4958 | return 0; | 4958 | return 0; |
4959 | } | 4959 | } |
4960 | |||
4961 | // Vectors & Rotations always return zero in SL, but | ||
4962 | // keys don't always return zero, it seems to be a bit complex. | ||
4963 | else if (src.Data[index] is LSL_Vector || | ||
4964 | src.Data[index] is LSL_Rotation) | ||
4965 | { | ||
4966 | return 0; | ||
4967 | } | ||
4960 | try | 4968 | try |
4961 | { | 4969 | { |
4970 | |||
4962 | if (src.Data[index] is LSL_Integer) | 4971 | if (src.Data[index] is LSL_Integer) |
4963 | return (LSL_Integer) src.Data[index]; | 4972 | return (LSL_Integer)src.Data[index]; |
4964 | else if (src.Data[index] is LSL_Float) | 4973 | else if (src.Data[index] is LSL_Float) |
4965 | return Convert.ToInt32(((LSL_Float) src.Data[index]).value); | 4974 | return Convert.ToInt32(((LSL_Float)src.Data[index]).value); |
4966 | return new LSL_Integer(src.Data[index].ToString()); | 4975 | return new LSL_Integer(src.Data[index].ToString()); |
4967 | } | 4976 | } |
4968 | catch (FormatException) | 4977 | catch (FormatException) |
@@ -4982,14 +4991,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4982 | { | 4991 | { |
4983 | return 0.0; | 4992 | return 0.0; |
4984 | } | 4993 | } |
4994 | |||
4995 | // Vectors & Rotations always return zero in SL | ||
4996 | else if (src.Data[index] is LSL_Vector || | ||
4997 | src.Data[index] is LSL_Rotation) | ||
4998 | { | ||
4999 | return 0; | ||
5000 | } | ||
5001 | // valid keys seem to get parsed as integers then converted to floats | ||
5002 | else | ||
5003 | { | ||
5004 | UUID uuidt; | ||
5005 | if (src.Data[index] is LSL_Key && UUID.TryParse(src.Data[index].ToString(), out uuidt)) | ||
5006 | { | ||
5007 | return Convert.ToDouble(new LSL_Integer(src.Data[index].ToString()).value); | ||
5008 | } | ||
5009 | } | ||
4985 | try | 5010 | try |
4986 | { | 5011 | { |
4987 | if (src.Data[index] is LSL_Integer) | 5012 | if (src.Data[index] is LSL_Integer) |
4988 | return Convert.ToDouble(((LSL_Integer) src.Data[index]).value); | 5013 | return Convert.ToDouble(((LSL_Integer)src.Data[index]).value); |
4989 | else if (src.Data[index] is LSL_Float) | 5014 | else if (src.Data[index] is LSL_Float) |
4990 | return Convert.ToDouble(((LSL_Float) src.Data[index]).value); | 5015 | return Convert.ToDouble(((LSL_Float)src.Data[index]).value); |
4991 | else if (src.Data[index] is LSL_String) | 5016 | else if (src.Data[index] is LSL_String) |
4992 | return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); | 5017 | return Convert.ToDouble(((LSL_String)src.Data[index]).m_string); |
4993 | return Convert.ToDouble(src.Data[index]); | 5018 | return Convert.ToDouble(src.Data[index]); |
4994 | } | 5019 | } |
4995 | catch (FormatException) | 5020 | catch (FormatException) |
@@ -5012,17 +5037,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5012 | return src.Data[index].ToString(); | 5037 | return src.Data[index].ToString(); |
5013 | } | 5038 | } |
5014 | 5039 | ||
5015 | public LSL_String llList2Key(LSL_List src, int index) | 5040 | public LSL_Key llList2Key(LSL_List src, int index) |
5016 | { | 5041 | { |
5017 | m_host.AddScriptLPS(1); | 5042 | m_host.AddScriptLPS(1); |
5018 | if (index < 0) | 5043 | if (index < 0) |
5019 | { | 5044 | { |
5020 | index = src.Length + index; | 5045 | index = src.Length + index; |
5021 | } | 5046 | } |
5047 | |||
5022 | if (index >= src.Length || index < 0) | 5048 | if (index >= src.Length || index < 0) |
5023 | { | 5049 | { |
5024 | return ""; | 5050 | return ""; |
5025 | } | 5051 | } |
5052 | |||
5053 | // SL spits out an empty string for types other than key & string | ||
5054 | // At the time of patching, LSL_Key is currently LSL_String, | ||
5055 | // so the OR check may be a little redundant, but it's being done | ||
5056 | // for completion and should LSL_Key ever be implemented | ||
5057 | // as it's own struct | ||
5058 | else if (!(src.Data[index] is LSL_String || | ||
5059 | src.Data[index] is LSL_Key)) | ||
5060 | { | ||
5061 | return ""; | ||
5062 | } | ||
5063 | |||
5026 | return src.Data[index].ToString(); | 5064 | return src.Data[index].ToString(); |
5027 | } | 5065 | } |
5028 | 5066 | ||
@@ -5041,6 +5079,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5041 | { | 5079 | { |
5042 | return (LSL_Vector)src.Data[index]; | 5080 | return (LSL_Vector)src.Data[index]; |
5043 | } | 5081 | } |
5082 | |||
5083 | // SL spits always out ZERO_VECTOR for anything other than | ||
5084 | // strings or vectors. Although keys always return ZERO_VECTOR, | ||
5085 | // it is currently difficult to make the distinction between | ||
5086 | // a string, a key as string and a string that by coincidence | ||
5087 | // is a string, so we're going to leave that up to the | ||
5088 | // LSL_Vector constructor. | ||
5089 | else if (!(src.Data[index] is LSL_String || | ||
5090 | src.Data[index] is LSL_Vector)) | ||
5091 | { | ||
5092 | return new LSL_Vector(0, 0, 0); | ||
5093 | } | ||
5044 | else | 5094 | else |
5045 | { | 5095 | { |
5046 | return new LSL_Vector(src.Data[index].ToString()); | 5096 | return new LSL_Vector(src.Data[index].ToString()); |
@@ -5058,7 +5108,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5058 | { | 5108 | { |
5059 | return new LSL_Rotation(0, 0, 0, 1); | 5109 | return new LSL_Rotation(0, 0, 0, 1); |
5060 | } | 5110 | } |
5061 | if (src.Data[index].GetType() == typeof(LSL_Rotation)) | 5111 | |
5112 | // SL spits always out ZERO_ROTATION for anything other than | ||
5113 | // strings or vectors. Although keys always return ZERO_ROTATION, | ||
5114 | // it is currently difficult to make the distinction between | ||
5115 | // a string, a key as string and a string that by coincidence | ||
5116 | // is a string, so we're going to leave that up to the | ||
5117 | // LSL_Rotation constructor. | ||
5118 | else if (!(src.Data[index] is LSL_String || | ||
5119 | src.Data[index] is LSL_Rotation)) | ||
5120 | { | ||
5121 | return new LSL_Rotation(0, 0, 0, 1); | ||
5122 | } | ||
5123 | else if (src.Data[index].GetType() == typeof(LSL_Rotation)) | ||
5062 | { | 5124 | { |
5063 | return (LSL_Rotation)src.Data[index]; | 5125 | return (LSL_Rotation)src.Data[index]; |
5064 | } | 5126 | } |