Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions for access members by index on packed array objects #52309

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions core/extension/gdnative_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions core/extension/gdnative_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down