Merge pull request #52309 from BastiaanOlij/add_extension_index_functions

Add functions for access members by index on packed array objects
This commit is contained in:
Bastiaan Olij 2021-09-05 11:52:43 +10:00 committed by GitHub
commit f3ab094133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 162 additions and 0 deletions

View File

@ -661,6 +661,116 @@ static const char32_t *gdnative_string_operator_index_const(const GDNativeString
return &self->ptr()[p_index];
}
/* Packed array functions */
static uint8_t *gdnative_packed_byte_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedByteArray *self = (PackedByteArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptrw()[p_index];
}
static const uint8_t *gdnative_packed_byte_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedByteArray *self = (const PackedByteArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptr()[p_index];
}
static GDNativeTypePtr gdnative_packed_color_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedColorArray *self = (PackedColorArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return (GDNativeTypePtr)&self->ptrw()[p_index];
}
static GDNativeTypePtr gdnative_packed_color_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedColorArray *self = (const PackedColorArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return (GDNativeTypePtr)&self->ptr()[p_index];
}
static float *gdnative_packed_float32_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedFloat32Array *self = (PackedFloat32Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptrw()[p_index];
}
static const float *gdnative_packed_float32_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedFloat32Array *self = (const PackedFloat32Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptr()[p_index];
}
static double *gdnative_packed_float64_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedFloat64Array *self = (PackedFloat64Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptrw()[p_index];
}
static const double *gdnative_packed_float64_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedFloat64Array *self = (const PackedFloat64Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptr()[p_index];
}
static int32_t *gdnative_packed_int32_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedInt32Array *self = (PackedInt32Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptrw()[p_index];
}
static const int32_t *gdnative_packed_int32_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedInt32Array *self = (const PackedInt32Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptr()[p_index];
}
static int64_t *gdnative_packed_int64_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedInt64Array *self = (PackedInt64Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptrw()[p_index];
}
static const int64_t *gdnative_packed_int64_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedInt64Array *self = (const PackedInt64Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return &self->ptr()[p_index];
}
static GDNativeStringPtr gdnative_packed_string_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedStringArray *self = (PackedStringArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return (GDNativeStringPtr)&self->ptrw()[p_index];
}
static GDNativeStringPtr gdnative_packed_string_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedStringArray *self = (const PackedStringArray *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return (GDNativeStringPtr)&self->ptr()[p_index];
}
static GDNativeTypePtr gdnative_packed_vector2_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedVector2Array *self = (PackedVector2Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return (GDNativeTypePtr)&self->ptrw()[p_index];
}
static GDNativeTypePtr gdnative_packed_vector2_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedVector2Array *self = (const PackedVector2Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return (GDNativeTypePtr)&self->ptr()[p_index];
}
static GDNativeTypePtr gdnative_packed_vector3_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) {
PackedVector3Array *self = (PackedVector3Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return (GDNativeTypePtr)&self->ptrw()[p_index];
}
static GDNativeTypePtr gdnative_packed_vector3_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) {
const PackedVector3Array *self = (const PackedVector3Array *)p_self;
ERR_FAIL_INDEX_V(p_index, self->size(), nullptr);
return (GDNativeTypePtr)&self->ptr()[p_index];
}
/* OBJECT API */
static void gdnative_object_method_bind_call(const GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeVariantPtr *p_args, GDNativeInt p_arg_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error) {
@ -843,6 +953,32 @@ void gdnative_setup_interface(GDNativeInterface *p_interface) {
gdni.string_operator_index = gdnative_string_operator_index;
gdni.string_operator_index_const = gdnative_string_operator_index_const;
/* Packed array functions */
gdni.packed_byte_array_operator_index = gdnative_packed_byte_array_operator_index;
gdni.packed_byte_array_operator_index_const = gdnative_packed_byte_array_operator_index_const;
gdni.packed_color_array_operator_index = gdnative_packed_color_array_operator_index;
gdni.packed_color_array_operator_index_const = gdnative_packed_color_array_operator_index_const;
gdni.packed_float32_array_operator_index = gdnative_packed_float32_array_operator_index;
gdni.packed_float32_array_operator_index_const = gdnative_packed_float32_array_operator_index_const;
gdni.packed_float64_array_operator_index = gdnative_packed_float64_array_operator_index;
gdni.packed_float64_array_operator_index_const = gdnative_packed_float64_array_operator_index_const;
gdni.packed_int32_array_operator_index = gdnative_packed_int32_array_operator_index;
gdni.packed_int32_array_operator_index_const = gdnative_packed_int32_array_operator_index_const;
gdni.packed_int64_array_operator_index = gdnative_packed_int64_array_operator_index;
gdni.packed_int64_array_operator_index_const = gdnative_packed_int64_array_operator_index_const;
gdni.packed_string_array_operator_index = gdnative_packed_string_array_operator_index;
gdni.packed_string_array_operator_index_const = gdnative_packed_string_array_operator_index_const;
gdni.packed_vector2_array_operator_index = gdnative_packed_vector2_array_operator_index;
gdni.packed_vector2_array_operator_index_const = gdnative_packed_vector2_array_operator_index_const;
gdni.packed_vector3_array_operator_index = gdnative_packed_vector3_array_operator_index;
gdni.packed_vector3_array_operator_index_const = gdnative_packed_vector3_array_operator_index_const;
/* OBJECT */
gdni.object_method_bind_call = gdnative_object_method_bind_call;

View File

@ -387,6 +387,32 @@ typedef struct {
char32_t *(*string_operator_index)(GDNativeStringPtr p_self, GDNativeInt p_index);
const char32_t *(*string_operator_index_const)(const GDNativeStringPtr p_self, GDNativeInt p_index);
/* Packed array functions */
uint8_t *(*packed_byte_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedByteArray
const uint8_t *(*packed_byte_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedByteArray
GDNativeTypePtr (*packed_color_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedColorArray, returns Color ptr
GDNativeTypePtr (*packed_color_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedColorArray, returns Color ptr
float *(*packed_float32_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedFloat32Array
const float *(*packed_float32_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedFloat32Array
double *(*packed_float64_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedFloat64Array
const double *(*packed_float64_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedFloat64Array
int32_t *(*packed_int32_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedInt32Array
const int32_t *(*packed_int32_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedInt32Array
int64_t *(*packed_int64_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedInt32Array
const int64_t *(*packed_int64_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedInt32Array
GDNativeStringPtr (*packed_string_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedStringArray
GDNativeStringPtr (*packed_string_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedStringArray
GDNativeTypePtr (*packed_vector2_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedVector2Array, returns Vector2 ptr
GDNativeTypePtr (*packed_vector2_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedVector2Array, returns Vector2 ptr
GDNativeTypePtr (*packed_vector3_array_operator_index)(GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedVector3Array, returns Vector3 ptr
GDNativeTypePtr (*packed_vector3_array_operator_index_const)(const GDNativeTypePtr p_self, GDNativeInt p_index); // p_self should be a PackedVector3Array, returns Vector3 ptr
/* OBJECT */
void (*object_method_bind_call)(const GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeVariantPtr *p_args, GDNativeInt p_arg_count, GDNativeVariantPtr r_ret, GDNativeCallError *r_error);