mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 14:12:51 +00:00
[Mono] Marshaling for Vector2i, Vector3i, and Rect2i
This commit is contained in:
parent
22ba912d90
commit
9b322d46d3
@ -461,8 +461,11 @@ static String variant_type_to_managed_name(const String &p_var_type_name) {
|
||||
Variant::BOOL,
|
||||
Variant::INT,
|
||||
Variant::VECTOR2,
|
||||
Variant::VECTOR2I,
|
||||
Variant::RECT2,
|
||||
Variant::RECT2I,
|
||||
Variant::VECTOR3,
|
||||
Variant::VECTOR3I,
|
||||
Variant::TRANSFORM2D,
|
||||
Variant::PLANE,
|
||||
Variant::QUAT,
|
||||
|
@ -2810,8 +2810,11 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
|
||||
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
|
||||
break;
|
||||
case Variant::VECTOR2:
|
||||
case Variant::VECTOR2I:
|
||||
case Variant::RECT2:
|
||||
case Variant::RECT2I:
|
||||
case Variant::VECTOR3:
|
||||
case Variant::VECTOR3I:
|
||||
r_iarg.default_argument = "new %s" + r_iarg.default_argument;
|
||||
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
|
||||
break;
|
||||
@ -2891,9 +2894,12 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
|
||||
}
|
||||
|
||||
INSERT_STRUCT_TYPE(Vector2)
|
||||
INSERT_STRUCT_TYPE(Vector2i)
|
||||
INSERT_STRUCT_TYPE(Rect2)
|
||||
INSERT_STRUCT_TYPE(Rect2i)
|
||||
INSERT_STRUCT_TYPE(Transform2D)
|
||||
INSERT_STRUCT_TYPE(Vector3)
|
||||
INSERT_STRUCT_TYPE(Vector3i)
|
||||
INSERT_STRUCT_TYPE(Basis)
|
||||
INSERT_STRUCT_TYPE(Quat)
|
||||
INSERT_STRUCT_TYPE(Transform)
|
||||
@ -3314,7 +3320,10 @@ void BindingsGenerator::_populate_global_constants() {
|
||||
|
||||
// HARDCODED
|
||||
List<StringName> hardcoded_enums;
|
||||
hardcoded_enums.push_back("Vector2.Axis");
|
||||
hardcoded_enums.push_back("Vector2i.Axis");
|
||||
hardcoded_enums.push_back("Vector3.Axis");
|
||||
hardcoded_enums.push_back("Vector3i.Axis");
|
||||
for (List<StringName>::Element *E = hardcoded_enums.front(); E; E = E->next()) {
|
||||
// These enums are not generated and must be written manually (e.g.: Vector3.Axis)
|
||||
// Here, we assume core types do not begin with underscore
|
||||
|
@ -103,9 +103,12 @@ void CachedData::clear_godot_api_cache() {
|
||||
rawclass_Dictionary = NULL;
|
||||
|
||||
class_Vector2 = NULL;
|
||||
class_Vector2i = NULL;
|
||||
class_Rect2 = NULL;
|
||||
class_Rect2i = NULL;
|
||||
class_Transform2D = NULL;
|
||||
class_Vector3 = NULL;
|
||||
class_Vector3i = NULL;
|
||||
class_Basis = NULL;
|
||||
class_Quat = NULL;
|
||||
class_Transform = NULL;
|
||||
@ -229,9 +232,12 @@ void update_corlib_cache() {
|
||||
void update_godot_api_cache() {
|
||||
|
||||
CACHE_CLASS_AND_CHECK(Vector2, GODOT_API_CLASS(Vector2));
|
||||
CACHE_CLASS_AND_CHECK(Vector2i, GODOT_API_CLASS(Vector2i));
|
||||
CACHE_CLASS_AND_CHECK(Rect2, GODOT_API_CLASS(Rect2));
|
||||
CACHE_CLASS_AND_CHECK(Rect2i, GODOT_API_CLASS(Rect2i));
|
||||
CACHE_CLASS_AND_CHECK(Transform2D, GODOT_API_CLASS(Transform2D));
|
||||
CACHE_CLASS_AND_CHECK(Vector3, GODOT_API_CLASS(Vector3));
|
||||
CACHE_CLASS_AND_CHECK(Vector3i, GODOT_API_CLASS(Vector3i));
|
||||
CACHE_CLASS_AND_CHECK(Basis, GODOT_API_CLASS(Basis));
|
||||
CACHE_CLASS_AND_CHECK(Quat, GODOT_API_CLASS(Quat));
|
||||
CACHE_CLASS_AND_CHECK(Transform, GODOT_API_CLASS(Transform));
|
||||
|
@ -73,9 +73,12 @@ struct CachedData {
|
||||
// -----------------------------------------------
|
||||
|
||||
GDMonoClass *class_Vector2;
|
||||
GDMonoClass *class_Vector2i;
|
||||
GDMonoClass *class_Rect2;
|
||||
GDMonoClass *class_Rect2i;
|
||||
GDMonoClass *class_Transform2D;
|
||||
GDMonoClass *class_Vector3;
|
||||
GDMonoClass *class_Vector3i;
|
||||
GDMonoClass *class_Basis;
|
||||
GDMonoClass *class_Quat;
|
||||
GDMonoClass *class_Transform;
|
||||
|
@ -132,11 +132,21 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_
|
||||
break;
|
||||
}
|
||||
|
||||
if (tclass == CACHED_CLASS(Vector2i)) {
|
||||
SET_FROM_STRUCT(Vector2i);
|
||||
break;
|
||||
}
|
||||
|
||||
if (tclass == CACHED_CLASS(Rect2)) {
|
||||
SET_FROM_STRUCT(Rect2);
|
||||
break;
|
||||
}
|
||||
|
||||
if (tclass == CACHED_CLASS(Rect2i)) {
|
||||
SET_FROM_STRUCT(Rect2i);
|
||||
break;
|
||||
}
|
||||
|
||||
if (tclass == CACHED_CLASS(Transform2D)) {
|
||||
SET_FROM_STRUCT(Transform2D);
|
||||
break;
|
||||
@ -147,6 +157,11 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_
|
||||
break;
|
||||
}
|
||||
|
||||
if (tclass == CACHED_CLASS(Vector3i)) {
|
||||
SET_FROM_STRUCT(Vector3i);
|
||||
break;
|
||||
}
|
||||
|
||||
if (tclass == CACHED_CLASS(Basis)) {
|
||||
SET_FROM_STRUCT(Basis);
|
||||
break;
|
||||
@ -418,12 +433,21 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_
|
||||
case Variant::VECTOR2: {
|
||||
SET_FROM_STRUCT(Vector2);
|
||||
} break;
|
||||
case Variant::VECTOR2I: {
|
||||
SET_FROM_STRUCT(Vector2i);
|
||||
} break;
|
||||
case Variant::RECT2: {
|
||||
SET_FROM_STRUCT(Rect2);
|
||||
} break;
|
||||
case Variant::RECT2I: {
|
||||
SET_FROM_STRUCT(Rect2i);
|
||||
} break;
|
||||
case Variant::VECTOR3: {
|
||||
SET_FROM_STRUCT(Vector3);
|
||||
} break;
|
||||
case Variant::VECTOR3I: {
|
||||
SET_FROM_STRUCT(Vector3i);
|
||||
} break;
|
||||
case Variant::TRANSFORM2D: {
|
||||
SET_FROM_STRUCT(Transform2D);
|
||||
} break;
|
||||
|
@ -75,15 +75,24 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type, bool *r_nil_is_
|
||||
if (vtclass == CACHED_CLASS(Vector2))
|
||||
return Variant::VECTOR2;
|
||||
|
||||
if (vtclass == CACHED_CLASS(Vector2i))
|
||||
return Variant::VECTOR2I;
|
||||
|
||||
if (vtclass == CACHED_CLASS(Rect2))
|
||||
return Variant::RECT2;
|
||||
|
||||
if (vtclass == CACHED_CLASS(Rect2i))
|
||||
return Variant::RECT2I;
|
||||
|
||||
if (vtclass == CACHED_CLASS(Transform2D))
|
||||
return Variant::TRANSFORM2D;
|
||||
|
||||
if (vtclass == CACHED_CLASS(Vector3))
|
||||
return Variant::VECTOR3;
|
||||
|
||||
if (vtclass == CACHED_CLASS(Vector3i))
|
||||
return Variant::VECTOR3I;
|
||||
|
||||
if (vtclass == CACHED_CLASS(Basis))
|
||||
return Variant::BASIS;
|
||||
|
||||
@ -413,11 +422,21 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Vector2), &from);
|
||||
}
|
||||
|
||||
if (vtclass == CACHED_CLASS(Vector2i)) {
|
||||
GDMonoMarshal::M_Vector2i from = MARSHALLED_OUT(Vector2i, p_var->operator ::Vector2i());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Vector2i), &from);
|
||||
}
|
||||
|
||||
if (vtclass == CACHED_CLASS(Rect2)) {
|
||||
GDMonoMarshal::M_Rect2 from = MARSHALLED_OUT(Rect2, p_var->operator ::Rect2());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Rect2), &from);
|
||||
}
|
||||
|
||||
if (vtclass == CACHED_CLASS(Rect2i)) {
|
||||
GDMonoMarshal::M_Rect2i from = MARSHALLED_OUT(Rect2i, p_var->operator ::Rect2i());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Rect2i), &from);
|
||||
}
|
||||
|
||||
if (vtclass == CACHED_CLASS(Transform2D)) {
|
||||
GDMonoMarshal::M_Transform2D from = MARSHALLED_OUT(Transform2D, p_var->operator ::Transform2D());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Transform2D), &from);
|
||||
@ -428,6 +447,11 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Vector3), &from);
|
||||
}
|
||||
|
||||
if (vtclass == CACHED_CLASS(Vector3i)) {
|
||||
GDMonoMarshal::M_Vector3i from = MARSHALLED_OUT(Vector3i, p_var->operator ::Vector3i());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Vector3i), &from);
|
||||
}
|
||||
|
||||
if (vtclass == CACHED_CLASS(Basis)) {
|
||||
GDMonoMarshal::M_Basis from = MARSHALLED_OUT(Basis, p_var->operator ::Basis());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Basis), &from);
|
||||
@ -638,14 +662,26 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
|
||||
GDMonoMarshal::M_Vector2 from = MARSHALLED_OUT(Vector2, p_var->operator ::Vector2());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Vector2), &from);
|
||||
}
|
||||
case Variant::VECTOR2I: {
|
||||
GDMonoMarshal::M_Vector2i from = MARSHALLED_OUT(Vector2i, p_var->operator ::Vector2i());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Vector2i), &from);
|
||||
}
|
||||
case Variant::RECT2: {
|
||||
GDMonoMarshal::M_Rect2 from = MARSHALLED_OUT(Rect2, p_var->operator ::Rect2());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Rect2), &from);
|
||||
}
|
||||
case Variant::RECT2I: {
|
||||
GDMonoMarshal::M_Rect2i from = MARSHALLED_OUT(Rect2i, p_var->operator ::Rect2i());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Rect2i), &from);
|
||||
}
|
||||
case Variant::VECTOR3: {
|
||||
GDMonoMarshal::M_Vector3 from = MARSHALLED_OUT(Vector3, p_var->operator ::Vector3());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Vector3), &from);
|
||||
}
|
||||
case Variant::VECTOR3I: {
|
||||
GDMonoMarshal::M_Vector3i from = MARSHALLED_OUT(Vector3i, p_var->operator ::Vector3i());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Vector3i), &from);
|
||||
}
|
||||
case Variant::TRANSFORM2D: {
|
||||
GDMonoMarshal::M_Transform2D from = MARSHALLED_OUT(Transform2D, p_var->operator ::Transform2D());
|
||||
return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(Transform2D), &from);
|
||||
@ -806,15 +842,24 @@ Variant mono_object_to_variant_impl(MonoObject *p_obj, const ManagedType &p_type
|
||||
if (vtclass == CACHED_CLASS(Vector2))
|
||||
return MARSHALLED_IN(Vector2, unbox_addr<GDMonoMarshal::M_Vector2>(p_obj));
|
||||
|
||||
if (vtclass == CACHED_CLASS(Vector2i))
|
||||
return MARSHALLED_IN(Vector2i, unbox_addr<GDMonoMarshal::M_Vector2i>(p_obj));
|
||||
|
||||
if (vtclass == CACHED_CLASS(Rect2))
|
||||
return MARSHALLED_IN(Rect2, unbox_addr<GDMonoMarshal::M_Rect2>(p_obj));
|
||||
|
||||
if (vtclass == CACHED_CLASS(Rect2i))
|
||||
return MARSHALLED_IN(Rect2i, unbox_addr<GDMonoMarshal::M_Rect2i>(p_obj));
|
||||
|
||||
if (vtclass == CACHED_CLASS(Transform2D))
|
||||
return MARSHALLED_IN(Transform2D, unbox_addr<GDMonoMarshal::M_Transform2D>(p_obj));
|
||||
|
||||
if (vtclass == CACHED_CLASS(Vector3))
|
||||
return MARSHALLED_IN(Vector3, unbox_addr<GDMonoMarshal::M_Vector3>(p_obj));
|
||||
|
||||
if (vtclass == CACHED_CLASS(Vector3i))
|
||||
return MARSHALLED_IN(Vector3i, unbox_addr<GDMonoMarshal::M_Vector3i>(p_obj));
|
||||
|
||||
if (vtclass == CACHED_CLASS(Basis))
|
||||
return MARSHALLED_IN(Basis, unbox_addr<GDMonoMarshal::M_Basis>(p_obj));
|
||||
|
||||
|
@ -201,6 +201,8 @@ M_SignalInfo signal_info_to_managed(const Signal &p_signal);
|
||||
namespace InteropLayout {
|
||||
|
||||
enum {
|
||||
MATCHES_int = (sizeof(int32_t) == sizeof(uint32_t)),
|
||||
|
||||
MATCHES_float = (sizeof(float) == sizeof(uint32_t)),
|
||||
|
||||
MATCHES_double = (sizeof(double) == sizeof(uint64_t)),
|
||||
@ -215,10 +217,18 @@ enum {
|
||||
offsetof(Vector2, x) == (sizeof(real_t) * 0) &&
|
||||
offsetof(Vector2, y) == (sizeof(real_t) * 1)),
|
||||
|
||||
MATCHES_Vector2i = (MATCHES_int && (sizeof(Vector2i) == (sizeof(int32_t) * 2)) &&
|
||||
offsetof(Vector2i, x) == (sizeof(int32_t) * 0) &&
|
||||
offsetof(Vector2i, y) == (sizeof(int32_t) * 1)),
|
||||
|
||||
MATCHES_Rect2 = (MATCHES_Vector2 && (sizeof(Rect2) == (sizeof(Vector2) * 2)) &&
|
||||
offsetof(Rect2, position) == (sizeof(Vector2) * 0) &&
|
||||
offsetof(Rect2, size) == (sizeof(Vector2) * 1)),
|
||||
|
||||
MATCHES_Rect2i = (MATCHES_Vector2i && (sizeof(Rect2i) == (sizeof(Vector2i) * 2)) &&
|
||||
offsetof(Rect2i, position) == (sizeof(Vector2i) * 0) &&
|
||||
offsetof(Rect2i, size) == (sizeof(Vector2i) * 1)),
|
||||
|
||||
MATCHES_Transform2D = (MATCHES_Vector2 && (sizeof(Transform2D) == (sizeof(Vector2) * 3))), // No field offset required, it stores an array
|
||||
|
||||
MATCHES_Vector3 = (MATCHES_real_t && (sizeof(Vector3) == (sizeof(real_t) * 3)) &&
|
||||
@ -226,6 +236,11 @@ enum {
|
||||
offsetof(Vector3, y) == (sizeof(real_t) * 1) &&
|
||||
offsetof(Vector3, z) == (sizeof(real_t) * 2)),
|
||||
|
||||
MATCHES_Vector3i = (MATCHES_int && (sizeof(Vector3i) == (sizeof(int32_t) * 3)) &&
|
||||
offsetof(Vector3i, x) == (sizeof(int32_t) * 0) &&
|
||||
offsetof(Vector3i, y) == (sizeof(int32_t) * 1) &&
|
||||
offsetof(Vector3i, z) == (sizeof(int32_t) * 2)),
|
||||
|
||||
MATCHES_Basis = (MATCHES_Vector3 && (sizeof(Basis) == (sizeof(Vector3) * 3))), // No field offset required, it stores an array
|
||||
|
||||
MATCHES_Quat = (MATCHES_real_t && (sizeof(Quat) == (sizeof(real_t) * 4)) &&
|
||||
@ -257,7 +272,8 @@ enum {
|
||||
#ifdef GD_MONO_FORCE_INTEROP_STRUCT_COPY
|
||||
/* clang-format off */
|
||||
static_assert(MATCHES_Vector2 && MATCHES_Rect2 && MATCHES_Transform2D && MATCHES_Vector3 &&
|
||||
MATCHES_Basis && MATCHES_Quat && MATCHES_Transform && MATCHES_AABB && MATCHES_Color && MATCHES_Plane);
|
||||
MATCHES_Basis && MATCHES_Quat && MATCHES_Transform && MATCHES_AABB && MATCHES_Color &&
|
||||
MATCHES_Plane && MATCHES_Vector2i && MATCHES_Rect2i && MATCHES_Vector3i);
|
||||
/* clang-format on */
|
||||
#endif
|
||||
|
||||
@ -278,6 +294,19 @@ struct M_Vector2 {
|
||||
}
|
||||
};
|
||||
|
||||
struct M_Vector2i {
|
||||
int32_t x, y;
|
||||
|
||||
static _FORCE_INLINE_ Vector2i convert_to(const M_Vector2i &p_from) {
|
||||
return Vector2i(p_from.x, p_from.y);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ M_Vector2i convert_from(const Vector2i &p_from) {
|
||||
M_Vector2i ret = { p_from.x, p_from.y };
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
struct M_Rect2 {
|
||||
M_Vector2 position;
|
||||
M_Vector2 size;
|
||||
@ -293,6 +322,21 @@ struct M_Rect2 {
|
||||
}
|
||||
};
|
||||
|
||||
struct M_Rect2i {
|
||||
M_Vector2i position;
|
||||
M_Vector2i size;
|
||||
|
||||
static _FORCE_INLINE_ Rect2i convert_to(const M_Rect2i &p_from) {
|
||||
return Rect2i(M_Vector2i::convert_to(p_from.position),
|
||||
M_Vector2i::convert_to(p_from.size));
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ M_Rect2i convert_from(const Rect2i &p_from) {
|
||||
M_Rect2i ret = { M_Vector2i::convert_from(p_from.position), M_Vector2i::convert_from(p_from.size) };
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
struct M_Transform2D {
|
||||
M_Vector2 elements[3];
|
||||
|
||||
@ -325,6 +369,19 @@ struct M_Vector3 {
|
||||
}
|
||||
};
|
||||
|
||||
struct M_Vector3i {
|
||||
int32_t x, y, z;
|
||||
|
||||
static _FORCE_INLINE_ Vector3i convert_to(const M_Vector3i &p_from) {
|
||||
return Vector3i(p_from.x, p_from.y, p_from.z);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ M_Vector3i convert_from(const Vector3i &p_from) {
|
||||
M_Vector3i ret = { p_from.x, p_from.y, p_from.z };
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
struct M_Basis {
|
||||
M_Vector3 elements[3];
|
||||
|
||||
@ -450,9 +507,12 @@ struct M_Plane {
|
||||
}
|
||||
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Vector2)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Vector2i)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Rect2)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Rect2i)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Transform2D)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Vector3)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Vector3i)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Basis)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Quat)
|
||||
DECL_TYPE_MARSHAL_TEMPLATES(Transform)
|
||||
|
Loading…
Reference in New Issue
Block a user