From fff4a84b4714d5437e050b61746d2fedb23e07aa Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 31 May 2023 01:52:24 +0200 Subject: [PATCH] Also added helper methods to variant for the other new types. --- gdnative/variant.cpp | 98 ++++++++++++++++++++++++++++++++++++++++ include/gdn/projection.h | 2 + include/gdn/transform.h | 1 + include/gdn/variant.h | 21 +++++++++ 4 files changed, 122 insertions(+) diff --git a/gdnative/variant.cpp b/gdnative/variant.cpp index b3fbe1e..6235435 100644 --- a/gdnative/variant.cpp +++ b/gdnative/variant.cpp @@ -137,24 +137,60 @@ void GDAPI pandemonium_variant_new_string(pandemonium_variant *r_dest, const pan memnew_placement_custom(dest, Variant, Variant(*s)); } +void GDAPI pandemonium_variant_new_string_name(pandemonium_variant *r_dest, const pandemonium_string_name *p_s) { + Variant *dest = (Variant *)r_dest; + StringName *s = (StringName *)p_s; + memnew_placement_custom(dest, Variant, Variant(*s)); +} + void GDAPI pandemonium_variant_new_vector2(pandemonium_variant *r_dest, const pandemonium_vector2 *p_v2) { Variant *dest = (Variant *)r_dest; Vector2 *v2 = (Vector2 *)p_v2; memnew_placement_custom(dest, Variant, Variant(*v2)); } +void GDAPI pandemonium_variant_new_vector2i(pandemonium_variant *r_dest, const pandemonium_vector2 *p_v2i) { + Variant *dest = (Variant *)r_dest; + Vector2i *v2i = (Vector2i *)p_v2i; + memnew_placement_custom(dest, Variant, Variant(*v2i)); +} + void GDAPI pandemonium_variant_new_rect2(pandemonium_variant *r_dest, const pandemonium_rect2 *p_rect2) { Variant *dest = (Variant *)r_dest; Rect2 *rect2 = (Rect2 *)p_rect2; memnew_placement_custom(dest, Variant, Variant(*rect2)); } +void GDAPI pandemonium_variant_new_rect2i(pandemonium_variant *r_dest, const pandemonium_rect2i *p_rect2i) { + Variant *dest = (Variant *)r_dest; + Rect2i *rect2i = (Rect2i *)p_rect2i; + memnew_placement_custom(dest, Variant, Variant(*rect2i)); +} + void GDAPI pandemonium_variant_new_vector3(pandemonium_variant *r_dest, const pandemonium_vector3 *p_v3) { Variant *dest = (Variant *)r_dest; Vector3 *v3 = (Vector3 *)p_v3; memnew_placement_custom(dest, Variant, Variant(*v3)); } +void GDAPI pandemonium_variant_new_vector3i(pandemonium_variant *r_dest, const pandemonium_vector3i *p_v3i) { + Variant *dest = (Variant *)r_dest; + Vector3i *v3i = (Vector3i *)p_v3i; + memnew_placement_custom(dest, Variant, Variant(*v3i)); +} + +void GDAPI pandemonium_variant_new_vector4(pandemonium_variant *r_dest, const pandemonium_vector4 *p_v4) { + Variant *dest = (Variant *)r_dest; + Vector4 *v4 = (Vector4 *)p_v4; + memnew_placement_custom(dest, Variant, Variant(*v4)); +} + +void GDAPI pandemonium_variant_new_vector4i(pandemonium_variant *r_dest, const pandemonium_vector4i *p_v4i) { + Variant *dest = (Variant *)r_dest; + Vector4i *v4i = (Vector4i *)p_v4i; + memnew_placement_custom(dest, Variant, Variant(*v4i)); +} + void GDAPI pandemonium_variant_new_transform2d(pandemonium_variant *r_dest, const pandemonium_transform2d *p_t2d) { Variant *dest = (Variant *)r_dest; Transform2D *t2d = (Transform2D *)p_t2d; @@ -191,6 +227,12 @@ void GDAPI pandemonium_variant_new_transform(pandemonium_variant *r_dest, const memnew_placement_custom(dest, Variant, Variant(*trans)); } +void GDAPI pandemonium_variant_new_projection(pandemonium_variant *r_dest, const pandemonium_projection *p_proj) { + Variant *dest = (Variant *)r_dest; + Projection *proj = (Projection *)p_proj; + memnew_placement_custom(dest, Variant, Variant(*proj)); +} + void GDAPI pandemonium_variant_new_color(pandemonium_variant *r_dest, const pandemonium_color *p_color) { Variant *dest = (Variant *)r_dest; Color *color = (Color *)p_color; @@ -335,6 +377,14 @@ pandemonium_string GDAPI pandemonium_variant_as_string(const pandemonium_variant return raw_dest; } +pandemonium_string_name GDAPI pandemonium_variant_as_string_name(const pandemonium_variant *p_self) { + pandemonium_string_name raw_dest; + const Variant *self = (const Variant *)p_self; + StringName *dest = (StringName *)&raw_dest; + memnew_placement(dest, StringName(self->operator StringName())); // operator = is overloaded by String + return raw_dest; +} + pandemonium_vector2 GDAPI pandemonium_variant_as_vector2(const pandemonium_variant *p_self) { pandemonium_vector2 raw_dest; const Variant *self = (const Variant *)p_self; @@ -343,6 +393,14 @@ pandemonium_vector2 GDAPI pandemonium_variant_as_vector2(const pandemonium_varia return raw_dest; } +pandemonium_vector2i GDAPI pandemonium_variant_as_vector2i(const pandemonium_variant *p_self) { + pandemonium_vector2i raw_dest; + const Variant *self = (const Variant *)p_self; + Vector2i *dest = (Vector2i *)&raw_dest; + *dest = *self; + return raw_dest; +} + pandemonium_rect2 GDAPI pandemonium_variant_as_rect2(const pandemonium_variant *p_self) { pandemonium_rect2 raw_dest; const Variant *self = (const Variant *)p_self; @@ -351,6 +409,14 @@ pandemonium_rect2 GDAPI pandemonium_variant_as_rect2(const pandemonium_variant * return raw_dest; } +pandemonium_rect2i GDAPI pandemonium_variant_as_rect2i(const pandemonium_variant *p_self) { + pandemonium_rect2i raw_dest; + const Variant *self = (const Variant *)p_self; + Rect2i *dest = (Rect2i *)&raw_dest; + *dest = *self; + return raw_dest; +} + pandemonium_vector3 GDAPI pandemonium_variant_as_vector3(const pandemonium_variant *p_self) { pandemonium_vector3 raw_dest; const Variant *self = (const Variant *)p_self; @@ -359,6 +425,30 @@ pandemonium_vector3 GDAPI pandemonium_variant_as_vector3(const pandemonium_varia return raw_dest; } +pandemonium_vector3i GDAPI pandemonium_variant_as_vector3i(const pandemonium_variant *p_self) { + pandemonium_vector3i raw_dest; + const Variant *self = (const Variant *)p_self; + Vector3i *dest = (Vector3i *)&raw_dest; + *dest = *self; + return raw_dest; +} + +pandemonium_vector4 GDAPI pandemonium_variant_as_vector4(const pandemonium_variant *p_self) { + pandemonium_vector4 raw_dest; + const Variant *self = (const Variant *)p_self; + Vector4 *dest = (Vector4 *)&raw_dest; + *dest = *self; + return raw_dest; +} + +pandemonium_vector4i GDAPI pandemonium_variant_as_vector4i(const pandemonium_variant *p_self) { + pandemonium_vector4i raw_dest; + const Variant *self = (const Variant *)p_self; + Vector4i *dest = (Vector4i *)&raw_dest; + *dest = *self; + return raw_dest; +} + pandemonium_transform2d GDAPI pandemonium_variant_as_transform2d(const pandemonium_variant *p_self) { pandemonium_transform2d raw_dest; const Variant *self = (const Variant *)p_self; @@ -407,6 +497,14 @@ pandemonium_transform GDAPI pandemonium_variant_as_transform(const pandemonium_v return raw_dest; } +pandemonium_projection GDAPI pandemonium_variant_as_projection(const pandemonium_variant *p_self) { + pandemonium_projection raw_dest; + const Variant *self = (const Variant *)p_self; + Projection *dest = (Projection *)&raw_dest; + *dest = *self; + return raw_dest; +} + pandemonium_color GDAPI pandemonium_variant_as_color(const pandemonium_variant *p_self) { pandemonium_color raw_dest; const Variant *self = (const Variant *)p_self; diff --git a/include/gdn/projection.h b/include/gdn/projection.h index 1071ba0..42d077e 100644 --- a/include/gdn/projection.h +++ b/include/gdn/projection.h @@ -56,6 +56,8 @@ typedef struct { #include #include #include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/include/gdn/transform.h b/include/gdn/transform.h index 644aa5f..8fee291 100644 --- a/include/gdn/transform.h +++ b/include/gdn/transform.h @@ -56,6 +56,7 @@ typedef struct { #include #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/include/gdn/variant.h b/include/gdn/variant.h index df0bf6f..3d342cd 100644 --- a/include/gdn/variant.h +++ b/include/gdn/variant.h @@ -169,15 +169,22 @@ typedef enum pandemonium_variant_operator { #include #include #include +#include #include #include +#include #include #include +#include #include #include #include #include +#include #include +#include +#include +#include #include @@ -267,15 +274,22 @@ uint64_t GDAPI pandemonium_variant_as_uint(const pandemonium_variant *p_self); int64_t GDAPI pandemonium_variant_as_int(const pandemonium_variant *p_self); double GDAPI pandemonium_variant_as_real(const pandemonium_variant *p_self); pandemonium_string GDAPI pandemonium_variant_as_string(const pandemonium_variant *p_self); +pandemonium_string_name GDAPI pandemonium_variant_as_string_name(const pandemonium_variant *p_self); pandemonium_vector2 GDAPI pandemonium_variant_as_vector2(const pandemonium_variant *p_self); +pandemonium_vector2i GDAPI pandemonium_variant_as_vector2i(const pandemonium_variant *p_self); pandemonium_rect2 GDAPI pandemonium_variant_as_rect2(const pandemonium_variant *p_self); +pandemonium_rect2i GDAPI pandemonium_variant_as_rect2i(const pandemonium_variant *p_self); pandemonium_vector3 GDAPI pandemonium_variant_as_vector3(const pandemonium_variant *p_self); +pandemonium_vector3i GDAPI pandemonium_variant_as_vector3i(const pandemonium_variant *p_self); +pandemonium_vector4 GDAPI pandemonium_variant_as_vector4(const pandemonium_variant *p_self); +pandemonium_vector4i GDAPI pandemonium_variant_as_vector4i(const pandemonium_variant *p_self); pandemonium_transform2d GDAPI pandemonium_variant_as_transform2d(const pandemonium_variant *p_self); pandemonium_plane GDAPI pandemonium_variant_as_plane(const pandemonium_variant *p_self); pandemonium_quaternion GDAPI pandemonium_variant_as_quaternion(const pandemonium_variant *p_self); pandemonium_aabb GDAPI pandemonium_variant_as_aabb(const pandemonium_variant *p_self); pandemonium_basis GDAPI pandemonium_variant_as_basis(const pandemonium_variant *p_self); pandemonium_transform GDAPI pandemonium_variant_as_transform(const pandemonium_variant *p_self); +pandemonium_projection GDAPI pandemonium_variant_as_projection(const pandemonium_variant *p_self); pandemonium_color GDAPI pandemonium_variant_as_color(const pandemonium_variant *p_self); pandemonium_node_path GDAPI pandemonium_variant_as_node_path(const pandemonium_variant *p_self); pandemonium_rid GDAPI pandemonium_variant_as_rid(const pandemonium_variant *p_self); @@ -302,15 +316,22 @@ void GDAPI pandemonium_variant_new_uint(pandemonium_variant *r_dest, const uint6 void GDAPI pandemonium_variant_new_int(pandemonium_variant *r_dest, const int64_t p_i); void GDAPI pandemonium_variant_new_real(pandemonium_variant *r_dest, const double p_r); void GDAPI pandemonium_variant_new_string(pandemonium_variant *r_dest, const pandemonium_string *p_s); +void GDAPI pandemonium_variant_new_string_name(pandemonium_variant *r_dest, const pandemonium_string_name *p_s); void GDAPI pandemonium_variant_new_vector2(pandemonium_variant *r_dest, const pandemonium_vector2 *p_v2); +void GDAPI pandemonium_variant_new_vector2i(pandemonium_variant *r_dest, const pandemonium_vector2 *p_v2i); void GDAPI pandemonium_variant_new_rect2(pandemonium_variant *r_dest, const pandemonium_rect2 *p_rect2); +void GDAPI pandemonium_variant_new_rect2i(pandemonium_variant *r_dest, const pandemonium_rect2i *p_rect2i); void GDAPI pandemonium_variant_new_vector3(pandemonium_variant *r_dest, const pandemonium_vector3 *p_v3); +void GDAPI pandemonium_variant_new_vector3i(pandemonium_variant *r_dest, const pandemonium_vector3i *p_v3i); +void GDAPI pandemonium_variant_new_vector4(pandemonium_variant *r_dest, const pandemonium_vector4 *p_v4); +void GDAPI pandemonium_variant_new_vector4i(pandemonium_variant *r_dest, const pandemonium_vector4i *p_v4i); void GDAPI pandemonium_variant_new_transform2d(pandemonium_variant *r_dest, const pandemonium_transform2d *p_t2d); void GDAPI pandemonium_variant_new_plane(pandemonium_variant *r_dest, const pandemonium_plane *p_plane); void GDAPI pandemonium_variant_new_quaternion(pandemonium_variant *r_dest, const pandemonium_quaternion *p_quaternion); void GDAPI pandemonium_variant_new_aabb(pandemonium_variant *r_dest, const pandemonium_aabb *p_aabb); void GDAPI pandemonium_variant_new_basis(pandemonium_variant *r_dest, const pandemonium_basis *p_basis); void GDAPI pandemonium_variant_new_transform(pandemonium_variant *r_dest, const pandemonium_transform *p_trans); +void GDAPI pandemonium_variant_new_projection(pandemonium_variant *r_dest, const pandemonium_projection *p_proj); void GDAPI pandemonium_variant_new_color(pandemonium_variant *r_dest, const pandemonium_color *p_color); void GDAPI pandemonium_variant_new_node_path(pandemonium_variant *r_dest, const pandemonium_node_path *p_np); void GDAPI pandemonium_variant_new_rid(pandemonium_variant *r_dest, const pandemonium_rid *p_rid);