diff options
Diffstat (limited to 'core/variant.cpp')
-rw-r--r-- | core/variant.cpp | 509 |
1 files changed, 487 insertions, 22 deletions
diff --git a/core/variant.cpp b/core/variant.cpp index b849a83cb4..1acb0e7a73 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -72,10 +72,18 @@ String Variant::get_type_name(Variant::Type p_type) { return "Vector2"; } break; + case VECTOR2I: { + + return "Vector2i"; + } break; case RECT2: { return "Rect2"; } break; + case RECT2I: { + + return "Rect2i"; + } break; case TRANSFORM2D: { return "Transform2D"; @@ -84,6 +92,10 @@ String Variant::get_type_name(Variant::Type p_type) { return "Vector3"; } break; + case VECTOR3I: { + + return "Vector3i"; + } break; case PLANE: { return "Plane"; @@ -128,6 +140,19 @@ String Variant::get_type_name(Variant::Type p_type) { return "Object"; } break; + case CALLABLE: { + + return "Callable"; + } break; + case SIGNAL: { + + return "Signal"; + } break; + case STRING_NAME: { + + return "StringName"; + + } break; case NODE_PATH: { return "NodePath"; @@ -245,6 +270,46 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { invalid_types = invalid; } break; + case VECTOR2: { + + static const Type valid[] = { + VECTOR2I, + NIL, + }; + + valid_types = valid; + + } break; + case VECTOR2I: { + + static const Type valid[] = { + VECTOR2, + NIL, + }; + + valid_types = valid; + + } break; + case RECT2: { + + static const Type valid[] = { + RECT2I, + NIL, + }; + + valid_types = valid; + + } break; + case RECT2I: { + + static const Type valid[] = { + RECT2, + NIL, + }; + + valid_types = valid; + + } break; case TRANSFORM2D: { static const Type valid[] = { @@ -254,6 +319,27 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; + case VECTOR3: { + + static const Type valid[] = { + VECTOR3I, + NIL, + }; + + valid_types = valid; + + } break; + case VECTOR3I: { + + static const Type valid[] = { + VECTOR3, + NIL, + }; + + valid_types = valid; + + } break; + case QUAT: { static const Type valid[] = { @@ -317,6 +403,15 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; + case STRING_NAME: { + + static const Type valid[] = { + STRING, + NIL + }; + + valid_types = valid; + } break; case NODE_PATH: { static const Type valid[] = { @@ -487,11 +582,52 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type static const Type valid[] = { NODE_PATH, + STRING_NAME, NIL }; valid_types = valid; } break; + case VECTOR2: { + + static const Type valid[] = { + VECTOR2I, + NIL, + }; + + valid_types = valid; + + } break; + case VECTOR2I: { + + static const Type valid[] = { + VECTOR2, + NIL, + }; + + valid_types = valid; + + } break; + case RECT2: { + + static const Type valid[] = { + RECT2I, + NIL, + }; + + valid_types = valid; + + } break; + case RECT2I: { + + static const Type valid[] = { + RECT2, + NIL, + }; + + valid_types = valid; + + } break; case TRANSFORM2D: { static const Type valid[] = { @@ -501,6 +637,27 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; + case VECTOR3: { + + static const Type valid[] = { + VECTOR3I, + NIL, + }; + + valid_types = valid; + + } break; + case VECTOR3I: { + + static const Type valid[] = { + VECTOR3, + NIL, + }; + + valid_types = valid; + + } break; + case QUAT: { static const Type valid[] = { @@ -564,6 +721,15 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; + case STRING_NAME: { + + static const Type valid[] = { + STRING, + NIL + }; + + valid_types = valid; + } break; case NODE_PATH: { static const Type valid[] = { @@ -733,11 +899,21 @@ bool Variant::is_zero() const { return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(); } break; + case VECTOR2I: { + + return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(); + + } break; case RECT2: { return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(); } break; + case RECT2I: { + + return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(); + + } break; case TRANSFORM2D: { return *_data._transform2d == Transform2D(); @@ -748,6 +924,11 @@ bool Variant::is_zero() const { return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(); } break; + case VECTOR3I: { + + return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(); + + } break; case PLANE: { return *reinterpret_cast<const Plane *>(_data._mem) == Plane(); @@ -792,6 +973,19 @@ bool Variant::is_zero() const { return _get_obj().obj == NULL; } break; + case CALLABLE: { + + return reinterpret_cast<const Callable *>(_data._mem)->is_null(); + } break; + case SIGNAL: { + + return reinterpret_cast<const Signal *>(_data._mem)->is_null(); + } break; + case STRING_NAME: { + + return *reinterpret_cast<const StringName *>(_data._mem) != StringName(); + + } break; case NODE_PATH: { return reinterpret_cast<const NodePath *>(_data._mem)->is_empty(); @@ -879,16 +1073,31 @@ bool Variant::is_one() const { return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(1, 1); } break; + case VECTOR2I: { + + return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(1, 1); + + } break; case RECT2: { return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(1, 1, 1, 1); } break; + case RECT2I: { + + return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(1, 1, 1, 1); + + } break; case VECTOR3: { return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(1, 1, 1); } break; + case VECTOR3I: { + + return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(1, 1, 1); + + } break; case PLANE: { return *reinterpret_cast<const Plane *>(_data._mem) == Plane(1, 1, 1, 1); @@ -959,10 +1168,18 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem))); } break; + case VECTOR2I: { + + memnew_placement(_data._mem, Vector2i(*reinterpret_cast<const Vector2i *>(p_variant._data._mem))); + } break; case RECT2: { memnew_placement(_data._mem, Rect2(*reinterpret_cast<const Rect2 *>(p_variant._data._mem))); } break; + case RECT2I: { + + memnew_placement(_data._mem, Rect2i(*reinterpret_cast<const Rect2i *>(p_variant._data._mem))); + } break; case TRANSFORM2D: { _data._transform2d = memnew(Transform2D(*p_variant._data._transform2d)); @@ -971,6 +1188,10 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._mem, Vector3(*reinterpret_cast<const Vector3 *>(p_variant._data._mem))); } break; + case VECTOR3I: { + + memnew_placement(_data._mem, Vector3i(*reinterpret_cast<const Vector3i *>(p_variant._data._mem))); + } break; case PLANE: { memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem))); @@ -1022,6 +1243,19 @@ void Variant::reference(const Variant &p_variant) { _get_obj().id = p_variant._get_obj().id; } break; + case CALLABLE: { + + memnew_placement(_data._mem, Callable(*reinterpret_cast<const Callable *>(p_variant._data._mem))); + } break; + case SIGNAL: { + + memnew_placement(_data._mem, Signal(*reinterpret_cast<const Signal *>(p_variant._data._mem))); + } break; + case STRING_NAME: { + + memnew_placement(_data._mem, StringName(*reinterpret_cast<const StringName *>(p_variant._data._mem))); + + } break; case NODE_PATH: { memnew_placement(_data._mem, NodePath(*reinterpret_cast<const NodePath *>(p_variant._data._mem))); @@ -1086,8 +1320,11 @@ void Variant::zero() { case INT: this->_data._int = 0; break; case REAL: this->_data._real = 0; break; case VECTOR2: *reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2(); break; + case VECTOR2I: *reinterpret_cast<Vector2i *>(this->_data._mem) = Vector2i(); break; case RECT2: *reinterpret_cast<Rect2 *>(this->_data._mem) = Rect2(); break; + case RECT2I: *reinterpret_cast<Rect2i *>(this->_data._mem) = Rect2i(); break; case VECTOR3: *reinterpret_cast<Vector3 *>(this->_data._mem) = Vector3(); break; + case VECTOR3I: *reinterpret_cast<Vector3i *>(this->_data._mem) = Vector3i(); break; case PLANE: *reinterpret_cast<Plane *>(this->_data._mem) = Plane(); break; case QUAT: *reinterpret_cast<Quat *>(this->_data._mem) = Quat(); break; case COLOR: *reinterpret_cast<Color *>(this->_data._mem) = Color(); break; @@ -1128,7 +1365,11 @@ void Variant::clear() { memdelete(_data._transform); } break; - // misc types + // misc types + case STRING_NAME: { + + reinterpret_cast<StringName *>(_data._mem)->~StringName(); + } break; case NODE_PATH: { reinterpret_cast<NodePath *>(_data._mem)->~NodePath(); @@ -1149,6 +1390,14 @@ void Variant::clear() { // not much need probably reinterpret_cast<RID *>(_data._mem)->~RID(); } break; + case CALLABLE: { + + reinterpret_cast<Callable *>(_data._mem)->~Callable(); + } break; + case SIGNAL: { + + reinterpret_cast<Signal *>(_data._mem)->~Signal(); + } break; case DICTIONARY: { reinterpret_cast<Dictionary *>(_data._mem)->~Dictionary(); @@ -1421,10 +1670,13 @@ Variant::operator double() const { Variant::operator StringName() const { - if (type == NODE_PATH) { - return reinterpret_cast<const NodePath *>(_data._mem)->get_sname(); + if (type == STRING_NAME) { + return *reinterpret_cast<const StringName *>(_data._mem); + } else if (type == STRING) { + return *reinterpret_cast<const String *>(_data._mem); } - return StringName(operator String()); + + return StringName(); } struct _VariantStrPair { @@ -1453,13 +1705,16 @@ String Variant::stringify(List<const void *> &stack) const { case REAL: return rtos(_data._real); case STRING: return *reinterpret_cast<const String *>(_data._mem); case VECTOR2: return "(" + operator Vector2() + ")"; + case VECTOR2I: return "(" + operator Vector2i() + ")"; case RECT2: return "(" + operator Rect2() + ")"; + case RECT2I: return "(" + operator Rect2i() + ")"; case TRANSFORM2D: { Transform2D mat32 = operator Transform2D(); return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")"; } break; case VECTOR3: return "(" + operator Vector3() + ")"; + case VECTOR3I: return "(" + operator Vector3i() + ")"; case PLANE: return operator Plane(); //case QUAT: @@ -1491,6 +1746,7 @@ String Variant::stringify(List<const void *> &stack) const { return mtx + ")"; } break; case TRANSFORM: return operator Transform(); + case STRING_NAME: return operator StringName(); case NODE_PATH: return operator NodePath(); case COLOR: return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a); case DICTIONARY: { @@ -1627,6 +1883,18 @@ String Variant::stringify(List<const void *> &stack) const { return "[Object:null]"; } break; + case CALLABLE: { + const Callable &c = *reinterpret_cast<const Callable *>(_data._mem); + return c; + } break; + case SIGNAL: { + const Signal &s = *reinterpret_cast<const Signal *>(_data._mem); + return s; + } break; + case _RID: { + const RID &s = *reinterpret_cast<const RID *>(_data._mem); + return "RID(" + itos(s.get_id()) + ")"; + } break; default: { return "[" + get_type_name(type) + "]"; } @@ -1639,28 +1907,78 @@ Variant::operator Vector2() const { if (type == VECTOR2) return *reinterpret_cast<const Vector2 *>(_data._mem); + else if (type == VECTOR2I) + return *reinterpret_cast<const Vector2i *>(_data._mem); else if (type == VECTOR3) return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y); + else if (type == VECTOR3I) + return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y); else return Vector2(); } + +Variant::operator Vector2i() const { + + if (type == VECTOR2I) + return *reinterpret_cast<const Vector2i *>(_data._mem); + else if (type == VECTOR2) + return *reinterpret_cast<const Vector2 *>(_data._mem); + else if (type == VECTOR3) + return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y); + else if (type == VECTOR3I) + return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y); + else + return Vector2i(); +} + Variant::operator Rect2() const { if (type == RECT2) return *reinterpret_cast<const Rect2 *>(_data._mem); + else if (type == RECT2I) + return *reinterpret_cast<const Rect2i *>(_data._mem); else return Rect2(); } +Variant::operator Rect2i() const { + + if (type == RECT2I) + return *reinterpret_cast<const Rect2i *>(_data._mem); + else if (type == RECT2) + return *reinterpret_cast<const Rect2 *>(_data._mem); + else + return Rect2i(); +} + Variant::operator Vector3() const { if (type == VECTOR3) return *reinterpret_cast<const Vector3 *>(_data._mem); + else if (type == VECTOR3I) + return *reinterpret_cast<const Vector3i *>(_data._mem); else if (type == VECTOR2) return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0); + else if (type == VECTOR2I) + return Vector3(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0); else return Vector3(); } + +Variant::operator Vector3i() const { + + if (type == VECTOR3I) + return *reinterpret_cast<const Vector3i *>(_data._mem); + else if (type == VECTOR3) + return *reinterpret_cast<const Vector3 *>(_data._mem); + else if (type == VECTOR2) + return Vector3i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0); + else if (type == VECTOR2I) + return Vector3i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0); + else + return Vector3i(); +} + Variant::operator Plane() const { if (type == PLANE) @@ -1776,9 +2094,9 @@ Variant::operator RID() const { ERR_FAIL_COND_V_MSG(ObjectDB::get_instance(_get_obj().id) == nullptr, RID(), "Invalid pointer (object was freed)."); }; #endif - Variant::CallError ce; + Callable::CallError ce; Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->get_rid, NULL, 0, ce); - if (ce.error == Variant::CallError::CALL_OK && ret.get_type() == Variant::_RID) { + if (ce.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::_RID) { return ret; } return RID(); @@ -1836,6 +2154,22 @@ Variant::operator Dictionary() const { return Dictionary(); } +Variant::operator Callable() const { + + if (type == CALLABLE) + return *reinterpret_cast<const Callable *>(_data._mem); + else + return Callable(); +} + +Variant::operator Signal() const { + + if (type == SIGNAL) + return *reinterpret_cast<const Signal *>(_data._mem); + else + return Signal(); +} + template <class DA, class SA> inline DA _convert_array(const SA &p_array) { @@ -2131,8 +2465,8 @@ Variant::Variant(const ObjectID &p_id) { Variant::Variant(const StringName &p_string) { - type = STRING; - memnew_placement(_data._mem, String(p_string.operator String())); + type = STRING_NAME; + memnew_placement(_data._mem, StringName(p_string)); } Variant::Variant(const String &p_string) { @@ -2156,17 +2490,36 @@ Variant::Variant(const Vector3 &p_vector3) { type = VECTOR3; memnew_placement(_data._mem, Vector3(p_vector3)); } +Variant::Variant(const Vector3i &p_vector3i) { + + type = VECTOR3I; + memnew_placement(_data._mem, Vector3i(p_vector3i)); +} + Variant::Variant(const Vector2 &p_vector2) { type = VECTOR2; memnew_placement(_data._mem, Vector2(p_vector2)); } + +Variant::Variant(const Vector2i &p_vector2i) { + + type = VECTOR2I; + memnew_placement(_data._mem, Vector2i(p_vector2i)); +} + Variant::Variant(const Rect2 &p_rect2) { type = RECT2; memnew_placement(_data._mem, Rect2(p_rect2)); } +Variant::Variant(const Rect2i &p_rect2i) { + + type = RECT2I; + memnew_placement(_data._mem, Rect2i(p_rect2i)); +} + Variant::Variant(const Plane &p_plane) { type = PLANE; @@ -2243,6 +2596,17 @@ Variant::Variant(const Object *p_object) { } } +Variant::Variant(const Callable &p_callable) { + + type = CALLABLE; + memnew_placement(_data._mem, Callable(p_callable)); +} +Variant::Variant(const Signal &p_callable) { + + type = SIGNAL; + memnew_placement(_data._mem, Signal(p_callable)); +} + Variant::Variant(const Dictionary &p_dictionary) { type = DICTIONARY; @@ -2403,10 +2767,18 @@ void Variant::operator=(const Variant &p_variant) { *reinterpret_cast<Vector2 *>(_data._mem) = *reinterpret_cast<const Vector2 *>(p_variant._data._mem); } break; + case VECTOR2I: { + + *reinterpret_cast<Vector2i *>(_data._mem) = *reinterpret_cast<const Vector2i *>(p_variant._data._mem); + } break; case RECT2: { *reinterpret_cast<Rect2 *>(_data._mem) = *reinterpret_cast<const Rect2 *>(p_variant._data._mem); } break; + case RECT2I: { + + *reinterpret_cast<Rect2i *>(_data._mem) = *reinterpret_cast<const Rect2i *>(p_variant._data._mem); + } break; case TRANSFORM2D: { *_data._transform2d = *(p_variant._data._transform2d); @@ -2415,6 +2787,10 @@ void Variant::operator=(const Variant &p_variant) { *reinterpret_cast<Vector3 *>(_data._mem) = *reinterpret_cast<const Vector3 *>(p_variant._data._mem); } break; + case VECTOR3I: { + + *reinterpret_cast<Vector3i *>(_data._mem) = *reinterpret_cast<const Vector3i *>(p_variant._data._mem); + } break; case PLANE: { *reinterpret_cast<Plane *>(_data._mem) = *reinterpret_cast<const Plane *>(p_variant._data._mem); @@ -2469,6 +2845,19 @@ void Variant::operator=(const Variant &p_variant) { _get_obj().id = p_variant._get_obj().id; } break; + case CALLABLE: { + + *reinterpret_cast<Callable *>(_data._mem) = *reinterpret_cast<const Callable *>(p_variant._data._mem); + } break; + case SIGNAL: { + + *reinterpret_cast<Signal *>(_data._mem) = *reinterpret_cast<const Signal *>(p_variant._data._mem); + } break; + + case STRING_NAME: { + + *reinterpret_cast<StringName *>(_data._mem) = *reinterpret_cast<const StringName *>(p_variant._data._mem); + } break; case NODE_PATH: { *reinterpret_cast<NodePath *>(_data._mem) = *reinterpret_cast<const NodePath *>(p_variant._data._mem); @@ -2564,6 +2953,11 @@ uint32_t Variant::hash() const { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->x); return hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->y, hash); } break; + case VECTOR2I: { + + uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->x); + return hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->y, hash); + } break; case RECT2: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.x); @@ -2571,6 +2965,13 @@ uint32_t Variant::hash() const { hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.x, hash); return hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.y, hash); } break; + case RECT2I: { + + uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.x); + hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.y, hash); + hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.x, hash); + return hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.y, hash); + } break; case TRANSFORM2D: { uint32_t hash = 5831; @@ -2589,6 +2990,12 @@ uint32_t Variant::hash() const { hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->y, hash); return hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->z, hash); } break; + case VECTOR3I: { + + uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->x); + hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->y, hash); + return hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->z, hash); + } break; case PLANE: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.x); @@ -2667,6 +3074,10 @@ uint32_t Variant::hash() const { return hash_djb2_one_64(make_uint64_t(_get_obj().obj)); } break; + case STRING_NAME: { + + return reinterpret_cast<const StringName *>(_data._mem)->hash(); + } break; case NODE_PATH: { return reinterpret_cast<const NodePath *>(_data._mem)->hash(); @@ -2676,6 +3087,17 @@ uint32_t Variant::hash() const { return reinterpret_cast<const Dictionary *>(_data._mem)->hash(); } break; + case CALLABLE: { + + return reinterpret_cast<const Callable *>(_data._mem)->hash(); + + } break; + case SIGNAL: { + + const Signal &s = *reinterpret_cast<const Signal *>(_data._mem); + uint32_t hash = s.get_name().hash(); + return hash_djb2_one_64(s.get_object_id(), hash); + } break; case ARRAY: { const Array &arr = *reinterpret_cast<const Array *>(_data._mem); @@ -2852,6 +3274,11 @@ bool Variant::hash_compare(const Variant &p_variant) const { return hash_compare_vector2(*l, *r); } break; + case VECTOR2I: { + const Vector2i *l = reinterpret_cast<const Vector2i *>(_data._mem); + const Vector2i *r = reinterpret_cast<const Vector2i *>(p_variant._data._mem); + return *l == *r; + } break; case RECT2: { const Rect2 *l = reinterpret_cast<const Rect2 *>(_data._mem); @@ -2860,6 +3287,12 @@ bool Variant::hash_compare(const Variant &p_variant) const { return (hash_compare_vector2(l->position, r->position)) && (hash_compare_vector2(l->size, r->size)); } break; + case RECT2I: { + const Rect2i *l = reinterpret_cast<const Rect2i *>(_data._mem); + const Rect2i *r = reinterpret_cast<const Rect2i *>(p_variant._data._mem); + + return *l == *r; + } break; case TRANSFORM2D: { Transform2D *l = _data._transform2d; @@ -2879,6 +3312,12 @@ bool Variant::hash_compare(const Variant &p_variant) const { return hash_compare_vector3(*l, *r); } break; + case VECTOR3I: { + const Vector3i *l = reinterpret_cast<const Vector3i *>(_data._mem); + const Vector3i *r = reinterpret_cast<const Vector3i *>(p_variant._data._mem); + + return *l == *r; + } break; case PLANE: { const Plane *l = reinterpret_cast<const Plane *>(_data._mem); @@ -3054,24 +3493,24 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) { argc++; } - CallError error; + Callable::CallError error; Variant ret = call(p_method, argptr, argc, error); switch (error.error) { - case CallError::CALL_ERROR_INVALID_ARGUMENT: { + case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: { - String err = "Invalid type for argument #" + itos(error.argument) + ", expected '" + Variant::get_type_name(error.expected) + "'."; + String err = "Invalid type for argument #" + itos(error.argument) + ", expected '" + Variant::get_type_name(Variant::Type(error.expected)) + "'."; ERR_PRINT(err.utf8().get_data()); } break; - case CallError::CALL_ERROR_INVALID_METHOD: { + case Callable::CallError::CALL_ERROR_INVALID_METHOD: { String err = "Invalid method '" + p_method + "' for type '" + Variant::get_type_name(type) + "'."; ERR_PRINT(err.utf8().get_data()); } break; - case CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { + case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { String err = "Too many arguments for method '" + p_method + "'"; ERR_PRINT(err.utf8().get_data()); @@ -3096,26 +3535,26 @@ String Variant::get_construct_string() const { return vars; } -String Variant::get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Variant::CallError &ce) { +String Variant::get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { String err_text; - if (ce.error == Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) { + if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { int errorarg = ce.argument; if (p_argptrs) { - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(ce.expected) + "."; + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; } else { - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(ce.expected) + "."; + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; } - } else if (ce.error == Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { + } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; - } else if (ce.error == Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { + } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; - } else if (ce.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) { + } else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) { err_text = "Method not found."; - } else if (ce.error == Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) { + } else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) { err_text = "Instance is null"; - } else if (ce.error == Variant::CallError::CALL_OK) { + } else if (ce.error == Callable::CallError::CALL_OK) { return "Call OK"; } @@ -3128,6 +3567,32 @@ String Variant::get_call_error_text(Object *p_base, const StringName &p_method, return "'" + class_name + "::" + String(p_method) + "': " + err_text; } +String Variant::get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { + + String err_text; + + if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { + int errorarg = ce.argument; + if (p_argptrs) { + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; + } else { + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; + } + } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { + err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; + } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { + err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; + } else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) { + err_text = "Method not found."; + } else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) { + err_text = "Instance is null"; + } else if (ce.error == Callable::CallError::CALL_OK) { + return "Call OK"; + } + + return String(p_callable) + " : " + err_text; +} + String vformat(const String &p_text, const Variant &p1, const Variant &p2, const Variant &p3, const Variant &p4, const Variant &p5) { Array args; |