|
|
@@ -7,38 +7,73 @@ using System.Threading.Tasks;
|
|
|
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
- public sealed class SerializableArray
|
|
|
+ public sealed class SerializableArray : ScriptObject
|
|
|
{
|
|
|
+ private object referencedObject;
|
|
|
+ private SerializableField.FieldType elementType;
|
|
|
+ private Type internalElementType;
|
|
|
+ private int[] dimensions;
|
|
|
+
|
|
|
public SerializableArray(object obj)
|
|
|
{
|
|
|
- // TODO - Initialize the array - handle it properly in case obj isn't a valid array
|
|
|
- }
|
|
|
+ Internal_CreateInstance(this, obj);
|
|
|
|
|
|
- public SerializableField.FieldType ElementType;
|
|
|
- private int[] dimensions;
|
|
|
- private int rank;
|
|
|
+ referencedObject = obj;
|
|
|
+ }
|
|
|
|
|
|
public int GetDimension(int rank)
|
|
|
{
|
|
|
return dimensions[rank];
|
|
|
}
|
|
|
|
|
|
+ public SerializableField.FieldType ElementType
|
|
|
+ {
|
|
|
+ get { return elementType; }
|
|
|
+ }
|
|
|
+
|
|
|
public int Rank
|
|
|
{
|
|
|
get { return rank; }
|
|
|
}
|
|
|
|
|
|
- public SerializableValue GetValue(int id)
|
|
|
+ public T GetValue<T>(params int[] indexes)
|
|
|
+ {
|
|
|
+ if (typeof(T) != internalElementType)
|
|
|
+ throw new Exception("Attempted to retrieve a serializable value using an invalid type. Provided type: " + typeof(T) + ". Needed type: " + internalElementType);
|
|
|
+
|
|
|
+ return (T)Internal_GetValue(mCachedPtr, ArrayIndexesToId(indexes));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetValue<T>(T value, params int[] indexes)
|
|
|
+ {
|
|
|
+ if (typeof(T) != internalElementType)
|
|
|
+ throw new Exception("Attempted to set a serializable value using an invalid type. Provided type: " + typeof(T) + ". Needed type: " + internalElementType);
|
|
|
+
|
|
|
+ Internal_SetValue(mCachedPtr, ArrayIndexesToId(indexes), value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private int ArrayIndexesToId(params int[] indexes)
|
|
|
{
|
|
|
- return null; // TODO - Return actual SerializableValue
|
|
|
+ int index = 0;
|
|
|
+ int prevDimensionSize = 1;
|
|
|
+
|
|
|
+ for (int i = dimensions.Length - 1; i >= 0; i--)
|
|
|
+ {
|
|
|
+ index += indexes[i] * prevDimensionSize;
|
|
|
+
|
|
|
+ prevDimensionSize *= dimensions[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ return index;
|
|
|
}
|
|
|
|
|
|
- // TODO - Add getters/setters for all fields
|
|
|
+ [MethodImpl(MethodImplOptions.InternalCall)]
|
|
|
+ private static extern void Internal_CreateInstance(SerializableArray instance, object obj);
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
|
- private static extern void Internal_SetInt32(IntPtr nativeInstance, int arrayIdx, Int32 value);
|
|
|
+ private static extern void Internal_SetValue(IntPtr nativeInstance, int elementId, object value);
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
|
- private static extern Int32 Internal_GetInt32(IntPtr nativeInstance, int arrayIdx);
|
|
|
+ private static extern object Internal_GetValue(IntPtr nativeInstance, int elementId);
|
|
|
}
|
|
|
}
|