Browse Source

Merge pull request #26411 from neikeq/issue-26195

C#: Add Array.Resize(int) method
Ignacio Etcheverry 6 years ago
parent
commit
b69569415f

+ 13 - 0
modules/mono/glue/Managed/Files/Array.cs

@@ -155,6 +155,11 @@ namespace Godot.Collections
             godot_icall_Array_RemoveAt(GetPtr(), index);
             godot_icall_Array_RemoveAt(GetPtr(), index);
         }
         }
 
 
+        public Error Resize(int newSize)
+        {
+            return godot_icall_Array_Resize(GetPtr(), newSize);
+        }
+
         IEnumerator IEnumerable.GetEnumerator()
         IEnumerator IEnumerable.GetEnumerator()
         {
         {
             return GetEnumerator();
             return GetEnumerator();
@@ -202,6 +207,9 @@ namespace Godot.Collections
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         internal extern static void godot_icall_Array_RemoveAt(IntPtr ptr, int index);
         internal extern static void godot_icall_Array_RemoveAt(IntPtr ptr, int index);
 
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        internal extern static Error godot_icall_Array_Resize(IntPtr ptr, int newSize);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         internal extern static void godot_icall_Array_Generic_GetElementTypeInfo(Type elemType, out int elemTypeEncoding, out IntPtr elemTypeClass);
         internal extern static void godot_icall_Array_Generic_GetElementTypeInfo(Type elemType, out int elemTypeEncoding, out IntPtr elemTypeClass);
     }
     }
@@ -339,6 +347,11 @@ namespace Godot.Collections
             objectArray.RemoveAt(index);
             objectArray.RemoveAt(index);
         }
         }
 
 
+        public Error Resize(int newSize)
+        {
+            return objectArray.Resize(newSize);
+        }
+
         IEnumerator IEnumerable.GetEnumerator()
         IEnumerator IEnumerable.GetEnumerator()
         {
         {
             return GetEnumerator();
             return GetEnumerator();

+ 5 - 0
modules/mono/glue/collections_glue.cpp

@@ -130,6 +130,10 @@ void godot_icall_Array_RemoveAt(Array *ptr, int index) {
 	ptr->remove(index);
 	ptr->remove(index);
 }
 }
 
 
+Error godot_icall_Array_Resize(Array *ptr, int new_size) {
+	return ptr->resize(new_size);
+}
+
 void godot_icall_Array_Generic_GetElementTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class) {
 void godot_icall_Array_Generic_GetElementTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class) {
 	MonoType *elem_type = mono_reflection_type_get_type(refltype);
 	MonoType *elem_type = mono_reflection_type_get_type(refltype);
 
 
@@ -274,6 +278,7 @@ void godot_register_collections_icalls() {
 	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Insert", (void *)godot_icall_Array_Insert);
 	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Insert", (void *)godot_icall_Array_Insert);
 	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Remove", (void *)godot_icall_Array_Remove);
 	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Remove", (void *)godot_icall_Array_Remove);
 	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_RemoveAt", (void *)godot_icall_Array_RemoveAt);
 	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_RemoveAt", (void *)godot_icall_Array_RemoveAt);
+	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Resize", (void *)godot_icall_Array_Resize);
 	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Generic_GetElementTypeInfo", (void *)godot_icall_Array_Generic_GetElementTypeInfo);
 	mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Generic_GetElementTypeInfo", (void *)godot_icall_Array_Generic_GetElementTypeInfo);
 
 
 	mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Ctor", (void *)godot_icall_Dictionary_Ctor);
 	mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Ctor", (void *)godot_icall_Dictionary_Ctor);

+ 2 - 0
modules/mono/glue/collections_glue.h

@@ -67,6 +67,8 @@ bool godot_icall_Array_Remove(Array *ptr, MonoObject *item);
 
 
 void godot_icall_Array_RemoveAt(Array *ptr, int index);
 void godot_icall_Array_RemoveAt(Array *ptr, int index);
 
 
+Error godot_icall_Array_Resize(Array *ptr, int new_size);
+
 void godot_icall_Array_Generic_GetElementTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class);
 void godot_icall_Array_Generic_GetElementTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class);
 
 
 // Dictionary
 // Dictionary