mirror of
https://github.com/opensim/opensim.git
synced 2026-05-14 02:39:52 +08:00
add functions osListAs*(list src, integer index) identical to llList2*, but a bit faster with no typecast and index only from origin ( ie >= 0)
This commit is contained in:
@@ -6807,5 +6807,84 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public LSL_Float osListAsFloat(LSL_List src, int index)
|
||||
{
|
||||
object[] data = src.Data;
|
||||
if(data == null)
|
||||
return LSL_Integer.Zero;
|
||||
if (index >= 0 && index < data.Length)
|
||||
{
|
||||
object o = data[index];
|
||||
if(o is LSL_Float d)
|
||||
return d;
|
||||
if(o is double nd)
|
||||
return nd;
|
||||
}
|
||||
return LSL_Float.Zero;
|
||||
}
|
||||
|
||||
public LSL_Integer osListAsInteger(LSL_List src, int index)
|
||||
{
|
||||
object[] data = src.Data;
|
||||
if(data == null)
|
||||
return LSL_Integer.Zero;
|
||||
if (index >= 0 && index < data.Length)
|
||||
{
|
||||
object o = data[index];
|
||||
if(o is LSL_Integer i)
|
||||
return i;
|
||||
if(o is int ni)
|
||||
return ni;
|
||||
}
|
||||
return LSL_Integer.Zero;
|
||||
}
|
||||
|
||||
public LSL_String osListAsString(LSL_List src, int index)
|
||||
{
|
||||
object[] data = src.Data;
|
||||
if(data == null)
|
||||
return LSL_String.Empty;
|
||||
if (index >= 0 && index < data.Length)
|
||||
{
|
||||
object o = data[index];
|
||||
if(o is LSL_String s)
|
||||
return s;
|
||||
if(o is string ns)
|
||||
return ns;
|
||||
}
|
||||
return LSL_String.Empty;
|
||||
}
|
||||
|
||||
public LSL_Vector osListAsVector(LSL_List src, int index)
|
||||
{
|
||||
object[] data = src.Data;
|
||||
if(data == null)
|
||||
return LSL_Vector.Zero;
|
||||
if (index >= 0 && index < data.Length)
|
||||
{
|
||||
object o = data[index];
|
||||
if(o is LSL_Vector v)
|
||||
return v;
|
||||
if(o is Vector3 ov)
|
||||
return ov;
|
||||
}
|
||||
return LSL_Vector.Zero;
|
||||
}
|
||||
|
||||
public LSL_Rotation osListAsRotation(LSL_List src, int index)
|
||||
{
|
||||
object[] data = src.Data;
|
||||
if(data == null)
|
||||
return LSL_Rotation.Identity;
|
||||
if (index >= 0 && index < data.Length)
|
||||
{
|
||||
object o = data[index];
|
||||
if(o is LSL_Rotation r)
|
||||
return r;
|
||||
if(o is Quaternion q)
|
||||
return q;
|
||||
}
|
||||
return LSL_Rotation.Identity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -924,5 +924,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||
/// <returns>a integer with index of match point or -1</returns>
|
||||
//ApiDesc Returns the nth index of the sublist constrained with start and end count.
|
||||
LSL_Integer osListFindListNext(LSL_List src, LSL_List test, LSL_Integer start, LSL_Integer end, LSL_Integer instance);
|
||||
//ApiDesc Returns a string that is at index(>=0) in src or empty string if that is not a string
|
||||
LSL_String osListAsString(LSL_List src, int index);
|
||||
//ApiDesc Returns a integer that is at index(>=0) in src or 0 if that is not a integer
|
||||
LSL_Integer osListAsInteger(LSL_List src, int index);
|
||||
//ApiDesc Returns a float that is at index(>=0) in src or 0 if that is not a float
|
||||
LSL_Float osListAsFloat(LSL_List src, int index);
|
||||
//ApiDesc Returns a vector that is at index(>=0) in src or Zero vector if that is not a vector
|
||||
vector osListAsVector(LSL_List src, int index);
|
||||
//ApiDesc Returns a rotation that is at index(>=0) in src or zero rotation if that is not a vector
|
||||
LSL_Rotation osListAsRotation(LSL_List src, int index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1831,5 +1831,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
{
|
||||
return m_OSSL_Functions.osListFindListNext(src, test, start, end, instance);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public LSL_String osListAsString(LSL_List src, int index)
|
||||
{
|
||||
return m_OSSL_Functions.osListAsString(src, index);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public LSL_Integer osListAsInteger(LSL_List src, int index)
|
||||
{
|
||||
return m_OSSL_Functions.osListAsInteger(src, index);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public LSL_Float osListAsFloat(LSL_List src, int index)
|
||||
{
|
||||
return m_OSSL_Functions.osListAsFloat(src, index);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public vector osListAsVector(LSL_List src, int index)
|
||||
{
|
||||
return m_OSSL_Functions.osListAsVector(src, index);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public rotation osListAsRotation(LSL_List src, int index)
|
||||
{
|
||||
return m_OSSL_Functions.osListAsRotation(src, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user