Added support for the new variant classes in the bindings generator.

This commit is contained in:
Relintai 2023-06-01 13:07:10 +02:00
parent c2f86d2a07
commit 86248c1889
3 changed files with 82 additions and 1 deletions

View File

@ -1468,7 +1468,9 @@ Error BindingsGenerator::_generate_cs_property(const BindingsGenerator::TypeInte
} }
if (getter && setter) { if (getter && setter) {
ERR_FAIL_COND_V(getter->return_type.cname != setter->arguments.back()->get().type.cname, ERR_BUG); if (getter->return_type.cname != setter->arguments.back()->get().type.cname) {
ERR_PRINT("Class has a type mismatch between getter and setter. (This is expected sometimes, usually where the Setter's type is Node, and the getter returns a Node derived class.) Getter: " + getter->name + " Getter type:" + getter->return_type.cname + " Setter type:" + setter->arguments.back()->get().type.cname);
}
} }
const TypeReference &proptype_name = getter ? getter->return_type : setter->arguments.back()->get().type; const TypeReference &proptype_name = getter ? getter->return_type : setter->arguments.back()->get().type;
@ -2628,9 +2630,13 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
break; break;
case Variant::STRING: case Variant::STRING:
case Variant::NODE_PATH: case Variant::NODE_PATH:
case Variant::STRING_NAME:
if (r_iarg.type.cname == name_cache.type_NodePath) { if (r_iarg.type.cname == name_cache.type_NodePath) {
r_iarg.default_argument = "(%s)\"" + r_iarg.default_argument + "\""; r_iarg.default_argument = "(%s)\"" + r_iarg.default_argument + "\"";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF;
} else if (r_iarg.type.cname == name_cache.type_StringName) {
r_iarg.default_argument = "(%s)\"" + r_iarg.default_argument + "\"";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF;
} else { } else {
CRASH_COND(r_iarg.type.cname != name_cache.type_String); CRASH_COND(r_iarg.type.cname != name_cache.type_String);
r_iarg.default_argument = "\"" + r_iarg.default_argument + "\""; r_iarg.default_argument = "\"" + r_iarg.default_argument + "\"";
@ -2651,6 +2657,11 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
r_iarg.default_argument = "new Rect2(new Vector2(" + rect.position.operator String() + "), new Vector2(" + rect.size.operator String() + "))"; r_iarg.default_argument = "new Rect2(new Vector2(" + rect.position.operator String() + "), new Vector2(" + rect.size.operator String() + "))";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break; } break;
case Variant::RECT2I: {
Rect2i rect = p_val.operator Rect2i();
r_iarg.default_argument = "new Rect2I(new Vector2I(" + rect.position.operator String() + "), new Vector2I(" + rect.size.operator String() + "))";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::COLOR: { case Variant::COLOR: {
if (r_iarg.default_argument == "1,1,1,1") { if (r_iarg.default_argument == "1,1,1,1") {
r_iarg.default_argument = "1, 1, 1, 1"; r_iarg.default_argument = "1, 1, 1, 1";
@ -2659,7 +2670,11 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break; } break;
case Variant::VECTOR2: case Variant::VECTOR2:
case Variant::VECTOR2I:
case Variant::VECTOR3: case Variant::VECTOR3:
case Variant::VECTOR3I:
case Variant::VECTOR4:
case Variant::VECTOR4I:
r_iarg.default_argument = "new %s" + r_iarg.default_argument; r_iarg.default_argument = "new %s" + r_iarg.default_argument;
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
break; break;
@ -2691,7 +2706,11 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
case Variant::POOL_REAL_ARRAY: case Variant::POOL_REAL_ARRAY:
case Variant::POOL_STRING_ARRAY: case Variant::POOL_STRING_ARRAY:
case Variant::POOL_VECTOR2_ARRAY: case Variant::POOL_VECTOR2_ARRAY:
case Variant::POOL_VECTOR2I_ARRAY:
case Variant::POOL_VECTOR3_ARRAY: case Variant::POOL_VECTOR3_ARRAY:
case Variant::POOL_VECTOR3I_ARRAY:
case Variant::POOL_VECTOR4_ARRAY:
case Variant::POOL_VECTOR4I_ARRAY:
case Variant::POOL_COLOR_ARRAY: case Variant::POOL_COLOR_ARRAY:
r_iarg.default_argument = "Array.Empty<%s>()"; r_iarg.default_argument = "Array.Empty<%s>()";
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF;
@ -2724,6 +2743,15 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
} }
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break; } break;
case Variant::PROJECTION: {
Projection projection = p_val.operator Projection();
if (projection == Projection()) {
r_iarg.default_argument = "Projection.Identity";
} else {
r_iarg.default_argument = "new Projection(new Vector4" + projection.matrix[0].operator String() + ", new Vector4" + projection.matrix[1].operator String() + ", new Vector4" + projection.matrix[2].operator String() + ", new Vector4" + projection.matrix[3].operator String() + ")";
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::QUATERNION: { case Variant::QUATERNION: {
Quaternion quat = p_val.operator Quaternion(); Quaternion quat = p_val.operator Quaternion();
if (quat == Quaternion()) { if (quat == Quaternion()) {
@ -2766,15 +2794,20 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
} }
INSERT_STRUCT_TYPE(Vector2) INSERT_STRUCT_TYPE(Vector2)
INSERT_STRUCT_TYPE(Vector2i)
INSERT_STRUCT_TYPE(Rect2) INSERT_STRUCT_TYPE(Rect2)
INSERT_STRUCT_TYPE(Transform2D) INSERT_STRUCT_TYPE(Transform2D)
INSERT_STRUCT_TYPE(Vector3) INSERT_STRUCT_TYPE(Vector3)
INSERT_STRUCT_TYPE(Vector3i)
INSERT_STRUCT_TYPE(Vector4)
INSERT_STRUCT_TYPE(Vector4i)
INSERT_STRUCT_TYPE(Basis) INSERT_STRUCT_TYPE(Basis)
INSERT_STRUCT_TYPE(Quaternion) INSERT_STRUCT_TYPE(Quaternion)
INSERT_STRUCT_TYPE(Transform) INSERT_STRUCT_TYPE(Transform)
INSERT_STRUCT_TYPE(AABB) INSERT_STRUCT_TYPE(AABB)
INSERT_STRUCT_TYPE(Color) INSERT_STRUCT_TYPE(Color)
INSERT_STRUCT_TYPE(Plane) INSERT_STRUCT_TYPE(Plane)
INSERT_STRUCT_TYPE(Projection)
#undef INSERT_STRUCT_TYPE #undef INSERT_STRUCT_TYPE
@ -2895,6 +2928,22 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
itype.im_type_out = "IntPtr"; itype.im_type_out = "IntPtr";
builtin_types.insert(itype.cname, itype); builtin_types.insert(itype.cname, itype);
// StringName
itype = TypeInterface();
itype.name = "StringName";
itype.cname = itype.name;
itype.proxy_name = "StringName";
itype.c_out = "\treturn memnew(StringName(%1));\n";
itype.c_type = itype.name;
itype.c_type_in = itype.c_type + "*";
itype.c_type_out = itype.c_type + "*";
itype.cs_type = itype.proxy_name;
itype.cs_in = "StringName." CS_SMETHOD_GETINSTANCE "(%0)";
itype.cs_out = "return new %2(%0(%1));";
itype.im_type_in = "IntPtr";
itype.im_type_out = "IntPtr";
builtin_types.insert(itype.cname, itype);
// RID // RID
itype = TypeInterface(); itype = TypeInterface();
itype.name = "RID"; itype.name = "RID";
@ -2973,7 +3022,11 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
INSERT_ARRAY(PoolColorArray, Color); INSERT_ARRAY(PoolColorArray, Color);
INSERT_ARRAY(PoolVector2Array, Vector2); INSERT_ARRAY(PoolVector2Array, Vector2);
INSERT_ARRAY(PoolVector2iArray, Vector2i);
INSERT_ARRAY(PoolVector3Array, Vector3); INSERT_ARRAY(PoolVector3Array, Vector3);
INSERT_ARRAY(PoolVector3iArray, Vector3i);
INSERT_ARRAY(PoolVector4Array, Vector4);
INSERT_ARRAY(PoolVector4iArray, Vector4i);
#undef INSERT_ARRAY #undef INSERT_ARRAY

View File

@ -524,6 +524,7 @@ class BindingsGenerator {
StringName type_RID; StringName type_RID;
StringName type_String; StringName type_String;
StringName type_NodePath; StringName type_NodePath;
StringName type_StringName;
StringName type_at_GlobalScope; StringName type_at_GlobalScope;
StringName enum_Error; StringName enum_Error;
@ -538,6 +539,8 @@ class BindingsGenerator {
StringName type_float; StringName type_float;
StringName type_double; StringName type_double;
StringName type_Node;
NameCache() { NameCache() {
type_void = StaticCString::create("void"); type_void = StaticCString::create("void");
type_Array = StaticCString::create("Array"); type_Array = StaticCString::create("Array");
@ -549,6 +552,7 @@ class BindingsGenerator {
type_RID = StaticCString::create("RID"); type_RID = StaticCString::create("RID");
type_String = StaticCString::create("String"); type_String = StaticCString::create("String");
type_NodePath = StaticCString::create("NodePath"); type_NodePath = StaticCString::create("NodePath");
type_StringName = StaticCString::create("StringName");
type_at_GlobalScope = StaticCString::create("@GlobalScope"); type_at_GlobalScope = StaticCString::create("@GlobalScope");
enum_Error = StaticCString::create("Error"); enum_Error = StaticCString::create("Error");
@ -562,6 +566,8 @@ class BindingsGenerator {
type_ulong = StaticCString::create("ulong"); type_ulong = StaticCString::create("ulong");
type_float = StaticCString::create("float"); type_float = StaticCString::create("float");
type_double = StaticCString::create("double"); type_double = StaticCString::create("double");
type_Node = StaticCString::create("Node");
} }
private: private:

View File

@ -36,6 +36,28 @@ namespace Godot
public Vector4 Row3; public Vector4 Row3;
private static readonly Projection _identity = new Projection();
public static Projection Identity { get { return _identity; } }
public void set_identity() {
Row0[0] = 1;
Row1[1] = 1;
Row2[2] = 1;
Row3[3] = 1;
}
public Projection() {
set_identity();
}
public Projection(Vector4 Row0, Vector4 Row1, Vector4 Row2, Vector4 Row3) {
this.Row0 = Row0;
this.Row1 = Row1;
this.Row2 = Row2;
this.Row3 = Row3;
}
/// <summary> /// <summary>
/// Returns <see langword="true"/> if the <see cref="Projection"/> is /// Returns <see langword="true"/> if the <see cref="Projection"/> is