mirror of
https://github.com/opensim/opensim.git
synced 2026-08-09 02:36:00 +08:00
add from string, from lsl string and from span lsl vector3 and rotation variants
This commit is contained in:
@@ -5562,14 +5562,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
|
||||
object item = src.Data[index];
|
||||
|
||||
//if (item.GetType() == typeof(LSL_Vector))
|
||||
// return (LSL_Vector)item;
|
||||
|
||||
if(item is LSL_Vector vec)
|
||||
return vec;
|
||||
|
||||
if (item is LSL_String lsv)
|
||||
return new LSL_Vector(lsv.m_string);
|
||||
return new LSL_Vector(lsv);
|
||||
if (item is string sv) // xengine sees string
|
||||
return new LSL_Vector(sv);
|
||||
|
||||
@@ -5582,24 +5579,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
index = src.Length + index;
|
||||
|
||||
if (index >= src.Length || index < 0)
|
||||
return new LSL_Rotation(0, 0, 0, 1);
|
||||
return LSL_Rotation.Identity;
|
||||
|
||||
object item = src.Data[index];
|
||||
|
||||
// SL spits always out ZERO_ROTATION for anything other than
|
||||
// strings or vectors. Although keys always return ZERO_ROTATION,
|
||||
// it is currently difficult to make the distinction between
|
||||
// a string, a key as string and a string that by coincidence
|
||||
// is a string, so we're going to leave that up to the
|
||||
// LSL_Rotation constructor.
|
||||
|
||||
if (item.GetType() == typeof(LSL_Rotation))
|
||||
return (LSL_Rotation)item;
|
||||
if (item is LSL_Rotation rot)
|
||||
return rot;
|
||||
if (item is LSL_String lls)
|
||||
return new LSL_Rotation(lls);
|
||||
if (item is string ls) // xengine sees string)
|
||||
return new LSL_Rotation(ls);
|
||||
|
||||
if (item is LSL_String || item is string) // xengine sees string)
|
||||
return new LSL_Rotation(src.Data[index].ToString());
|
||||
|
||||
return new LSL_Rotation(0, 0, 0, 1);
|
||||
return LSL_Rotation.Identity;
|
||||
}
|
||||
|
||||
public LSL_List llList2List(LSL_List src, int start, int end)
|
||||
@@ -5676,10 +5667,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
int parens = 0;
|
||||
int start = 0;
|
||||
int length = 0;
|
||||
|
||||
for (int i = 0; i < src.Length; i++)
|
||||
|
||||
ReadOnlySpan<char> s = src.AsSpan();
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
switch (src[i])
|
||||
switch (s[i])
|
||||
{
|
||||
case '<':
|
||||
parens++;
|
||||
|
||||
@@ -87,7 +87,13 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
z = Z;
|
||||
}
|
||||
|
||||
public Vector3(string str)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Vector3(string str) : this(str.AsSpan()) { }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Vector3(LSLString str) : this(str.m_string.AsSpan()) { }
|
||||
|
||||
public Vector3(ReadOnlySpan<char> str)
|
||||
{
|
||||
if (str.Length < 5)
|
||||
{
|
||||
@@ -95,14 +101,12 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
return;
|
||||
}
|
||||
|
||||
var strspan = str.AsSpan();
|
||||
|
||||
int start = 0;
|
||||
int comma = 0;
|
||||
char c;
|
||||
do
|
||||
{
|
||||
c = Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma);
|
||||
c = Unsafe.Add(ref MemoryMarshal.GetReference(str), comma);
|
||||
if (c == ',' || c == '<')
|
||||
break;
|
||||
}
|
||||
@@ -113,7 +117,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
start = ++comma;
|
||||
while (++comma < str.Length)
|
||||
{
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma) == ',')
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(str), comma) == ',')
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -123,7 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
return;
|
||||
}
|
||||
|
||||
if (!double.TryParse(strspan[start..comma], NumberStyles.Float, Utils.EnUsCulture, out x))
|
||||
if (!double.TryParse(str[start..comma], NumberStyles.Float, Utils.EnUsCulture, out x))
|
||||
{
|
||||
z = y = 0;
|
||||
return;
|
||||
@@ -132,7 +136,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
start = ++comma;
|
||||
while (++comma < str.Length)
|
||||
{
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma) == ',')
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(str), comma) == ',')
|
||||
break;
|
||||
}
|
||||
if (comma > str.Length - 1)
|
||||
@@ -140,7 +144,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
z = y = x = 0;
|
||||
return;
|
||||
}
|
||||
if (!double.TryParse(strspan[start..comma], NumberStyles.Float, Utils.EnUsCulture, out y))
|
||||
if (!double.TryParse(str[start..comma], NumberStyles.Float, Utils.EnUsCulture, out y))
|
||||
{
|
||||
z = x = 0;
|
||||
return;
|
||||
@@ -149,12 +153,12 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
start = ++comma;
|
||||
while (++comma < str.Length)
|
||||
{
|
||||
c = Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma);
|
||||
c = Unsafe.Add(ref MemoryMarshal.GetReference(str), comma);
|
||||
if (c == ' ' || c == '>')
|
||||
break;
|
||||
}
|
||||
|
||||
if (!double.TryParse(strspan[start..comma], NumberStyles.Float, Utils.EnUsCulture, out z))
|
||||
if (!double.TryParse(str[start..comma], NumberStyles.Float, Utils.EnUsCulture, out z))
|
||||
{
|
||||
y = x = 0;
|
||||
return;
|
||||
@@ -478,7 +482,13 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
s = rot.W;
|
||||
}
|
||||
|
||||
public Quaternion(string str)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Quaternion(string str) : this(str.AsSpan()) { }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Quaternion(LSLString str) : this(str.m_string.AsSpan()) { }
|
||||
|
||||
public Quaternion(ReadOnlySpan<char> str)
|
||||
{
|
||||
if (str.Length < 7)
|
||||
{
|
||||
@@ -487,15 +497,13 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
return;
|
||||
}
|
||||
|
||||
var strspan = str.AsSpan();
|
||||
|
||||
int start = 0;
|
||||
int comma = 0;
|
||||
char c;
|
||||
|
||||
do
|
||||
{
|
||||
c = Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma);
|
||||
c = Unsafe.Add(ref MemoryMarshal.GetReference(str), comma);
|
||||
if (c == ',' || c == '<')
|
||||
break;
|
||||
}
|
||||
@@ -506,7 +514,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
start = ++comma;
|
||||
while (++comma < str.Length)
|
||||
{
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma) == ',')
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(str), comma) == ',')
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -517,7 +525,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
return;
|
||||
}
|
||||
|
||||
if (!double.TryParse(strspan[start..comma], NumberStyles.Float, Utils.EnUsCulture, out x))
|
||||
if (!double.TryParse(str[start..comma], NumberStyles.Float, Utils.EnUsCulture, out x))
|
||||
{
|
||||
z = y = 0;
|
||||
s = 1;
|
||||
@@ -527,7 +535,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
start = ++comma;
|
||||
while (++comma < str.Length)
|
||||
{
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma) == ',')
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(str), comma) == ',')
|
||||
break;
|
||||
}
|
||||
if (comma > str.Length - 3)
|
||||
@@ -537,7 +545,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
return;
|
||||
}
|
||||
|
||||
if (!double.TryParse(strspan[start..comma], NumberStyles.Float, Utils.EnUsCulture, out y))
|
||||
if (!double.TryParse(str[start..comma], NumberStyles.Float, Utils.EnUsCulture, out y))
|
||||
{
|
||||
z = x = 0;
|
||||
s = 1;
|
||||
@@ -546,7 +554,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
start = ++comma;
|
||||
while (++comma < str.Length)
|
||||
{
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma) == ',')
|
||||
if (Unsafe.Add(ref MemoryMarshal.GetReference(str), comma) == ',')
|
||||
break;
|
||||
}
|
||||
if (comma > str.Length - 1)
|
||||
@@ -556,7 +564,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
return;
|
||||
}
|
||||
|
||||
if (!double.TryParse(strspan[start..comma], NumberStyles.Float, Utils.EnUsCulture, out z))
|
||||
if (!double.TryParse(str[start..comma], NumberStyles.Float, Utils.EnUsCulture, out z))
|
||||
{
|
||||
y = x = 0;
|
||||
s = 1;
|
||||
@@ -566,12 +574,12 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
start = ++comma;
|
||||
while (++comma < str.Length)
|
||||
{
|
||||
c = Unsafe.Add(ref MemoryMarshal.GetReference(strspan), comma);
|
||||
c = Unsafe.Add(ref MemoryMarshal.GetReference(str), comma);
|
||||
if (c == ' ' || c == '>')
|
||||
break;
|
||||
}
|
||||
|
||||
if (!double.TryParse(strspan[start..comma], NumberStyles.Float, Utils.EnUsCulture, out s))
|
||||
if (!double.TryParse(str[start..comma], NumberStyles.Float, Utils.EnUsCulture, out s))
|
||||
{
|
||||
z = y = x = 0;
|
||||
s = 1;
|
||||
@@ -2095,12 +2103,12 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
|
||||
public static implicit operator Vector3(LSLString s)
|
||||
{
|
||||
return new Vector3(s.m_string);
|
||||
return new Vector3(s);
|
||||
}
|
||||
|
||||
public static implicit operator Quaternion(LSLString s)
|
||||
{
|
||||
return new Quaternion(s.m_string);
|
||||
return new Quaternion(s);
|
||||
}
|
||||
|
||||
public static implicit operator LSLFloat(LSLString s)
|
||||
|
||||
@@ -63,6 +63,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
|
||||
/*
|
||||
* For those listed in noCheckRun, we just generate the call (simple computations).
|
||||
* For all others, we generate the call then a call to CheckRun().
|
||||
* note to self: a change here implies change on magic numbers to invalidate older code and
|
||||
* script state
|
||||
*/
|
||||
noCheckRuns = new HashSet<string>() {
|
||||
"llBase64ToString",
|
||||
|
||||
@@ -6761,8 +6761,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
|
||||
{
|
||||
if(val is LSL_Vector)
|
||||
return rVal;
|
||||
if(val is string)
|
||||
nval = new LSL_Vector((string)val);
|
||||
if(val is string sval)
|
||||
nval = new LSL_Vector(sval);
|
||||
}
|
||||
|
||||
if(nval != null)
|
||||
|
||||
@@ -926,7 +926,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
|
||||
public static LSL_Vector ObjectToVector(object x)
|
||||
{
|
||||
if(x is LSL_String lsx)
|
||||
return new LSL_Vector(lsx.m_string);
|
||||
return new LSL_Vector(lsx);
|
||||
if(x is string sx)
|
||||
return new LSL_Vector(sx);
|
||||
return (LSL_Vector)x;
|
||||
|
||||
Reference in New Issue
Block a user