diff options
Diffstat (limited to 'core/variant')
-rw-r--r-- | core/variant/variant.cpp | 3 | ||||
-rw-r--r-- | core/variant/variant.h | 3 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 61 |
3 files changed, 32 insertions, 35 deletions
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 90cb722fd4..80b0bf82d0 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -3562,9 +3562,6 @@ bool Variant::is_ref_counted() const { return type == OBJECT && _get_obj().id.is_ref_counted(); } -void Variant::static_assign(const Variant &p_variant) { -} - bool Variant::is_type_shared(Variant::Type p_type) { switch (p_type) { case OBJECT: diff --git a/core/variant/variant.h b/core/variant/variant.h index 9fd0472550..de0d763246 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -794,7 +794,6 @@ public: String stringify(int recursion_count = 0) const; String to_json_string() const; - void static_assign(const Variant &p_variant); static void get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants); static int get_constants_count_for_type(Variant::Type p_type); static bool has_constant(Variant::Type p_type, const StringName &p_value); @@ -803,6 +802,8 @@ public: static void get_enums_for_type(Variant::Type p_type, List<StringName> *p_enums); static void get_enumerations_for_enum(Variant::Type p_type, const StringName &p_enum_name, List<StringName> *p_enumerations); static int get_enum_value(Variant::Type p_type, const StringName &p_enum_name, const StringName &p_enumeration, bool *r_valid = nullptr); + static bool has_enum(Variant::Type p_type, const StringName &p_enum_name); + static StringName get_enum_for_enumeration(Variant::Type p_type, const StringName &p_enumeration); typedef String (*ObjectDeConstruct)(const Variant &p_object, void *ud); typedef void (*ObjectConstruct)(const String &p_text, void *ud, Variant &r_value); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 95c8550779..89ab7e20d6 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1093,6 +1093,11 @@ struct _VariantCall { static ConstantData *constant_data; static void add_constant(int p_type, const StringName &p_constant_name, int64_t p_constant_value) { +#ifdef DEBUG_ENABLED + ERR_FAIL_COND(constant_data[p_type].value.has(p_constant_name)); + ERR_FAIL_COND(enum_data[p_type].value.has(p_constant_name)); + ERR_FAIL_COND(enum_data[p_type].value_to_enum.has(p_constant_name)); +#endif constant_data[p_type].value[p_constant_name] = p_constant_value; #ifdef DEBUG_ENABLED constant_data[p_type].value_ordered.push_back(p_constant_name); @@ -1108,12 +1113,19 @@ struct _VariantCall { struct EnumData { HashMap<StringName, HashMap<StringName, int>> value; + HashMap<StringName, StringName> value_to_enum; }; static EnumData *enum_data; static void add_enum_constant(int p_type, const StringName &p_enum_type_name, const StringName &p_enumeration_name, int p_enum_value) { +#ifdef DEBUG_ENABLED + ERR_FAIL_COND(constant_data[p_type].value.has(p_enumeration_name)); + ERR_FAIL_COND(enum_data[p_type].value.has(p_enumeration_name)); + ERR_FAIL_COND(enum_data[p_type].value_to_enum.has(p_enumeration_name)); +#endif enum_data[p_type].value[p_enum_type_name][p_enumeration_name] = p_enum_value; + enum_data[p_type].value_to_enum[p_enumeration_name] = p_enum_type_name; } }; @@ -1563,6 +1575,23 @@ int Variant::get_enum_value(Variant::Type p_type, const StringName &p_enum_name, return V->value; } +bool Variant::has_enum(Variant::Type p_type, const StringName &p_enum_name) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); + + _VariantCall::EnumData &enum_data = _VariantCall::enum_data[p_type]; + + return enum_data.value.has(p_enum_name); +} + +StringName Variant::get_enum_for_enumeration(Variant::Type p_type, const StringName &p_enumeration) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, StringName()); + + _VariantCall::EnumData &enum_data = _VariantCall::enum_data[p_type]; + + const StringName *enum_name = enum_data.value_to_enum.getptr(p_enumeration); + return (enum_name == nullptr) ? StringName() : *enum_name; +} + #ifdef DEBUG_METHODS_ENABLED #define bind_method(m_type, m_method, m_arg_names, m_default_args) \ METHOD_CLASS(m_type, m_method, &m_type::m_method); \ @@ -2662,10 +2691,6 @@ static void _register_variant_builtin_constants() { _VariantCall::add_variant_constant(Variant::COLOR, Color::get_named_color_name(i), Color::get_named_color(i)); } - _VariantCall::add_constant(Variant::VECTOR3, "AXIS_X", Vector3::AXIS_X); - _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Y", Vector3::AXIS_Y); - _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Z", Vector3::AXIS_Z); - _VariantCall::add_enum_constant(Variant::VECTOR3, "Axis", "AXIS_X", Vector3::AXIS_X); _VariantCall::add_enum_constant(Variant::VECTOR3, "Axis", "AXIS_Y", Vector3::AXIS_Y); _VariantCall::add_enum_constant(Variant::VECTOR3, "Axis", "AXIS_Z", Vector3::AXIS_Z); @@ -2687,32 +2712,19 @@ static void _register_variant_builtin_constants() { _VariantCall::add_variant_constant(Variant::VECTOR3, "MODEL_FRONT", Vector3(0, 0, 1)); _VariantCall::add_variant_constant(Variant::VECTOR3, "MODEL_REAR", Vector3(0, 0, -1)); - _VariantCall::add_constant(Variant::VECTOR4, "AXIS_X", Vector4::AXIS_X); - _VariantCall::add_constant(Variant::VECTOR4, "AXIS_Y", Vector4::AXIS_Y); - _VariantCall::add_constant(Variant::VECTOR4, "AXIS_Z", Vector4::AXIS_Z); - _VariantCall::add_constant(Variant::VECTOR4, "AXIS_W", Vector4::AXIS_W); - _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_X", Vector4::AXIS_X); _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_Y", Vector4::AXIS_Y); _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_Z", Vector4::AXIS_Z); _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_W", Vector4::AXIS_W); + _VariantCall::add_variant_constant(Variant::VECTOR4, "ZERO", Vector4(0, 0, 0, 0)); _VariantCall::add_variant_constant(Variant::VECTOR4, "ONE", Vector4(1, 1, 1, 1)); _VariantCall::add_variant_constant(Variant::VECTOR4, "INF", Vector4(INFINITY, INFINITY, INFINITY, INFINITY)); - _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_X", Vector3i::AXIS_X); - _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Y", Vector3i::AXIS_Y); - _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Z", Vector3i::AXIS_Z); - _VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_X", Vector3i::AXIS_X); _VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_Y", Vector3i::AXIS_Y); _VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_Z", Vector3i::AXIS_Z); - _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_X", Vector4i::AXIS_X); - _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_Y", Vector4i::AXIS_Y); - _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_Z", Vector4i::AXIS_Z); - _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_W", Vector4i::AXIS_W); - _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_X", Vector4i::AXIS_X); _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_Y", Vector4i::AXIS_Y); _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_Z", Vector4i::AXIS_Z); @@ -2734,15 +2746,9 @@ static void _register_variant_builtin_constants() { _VariantCall::add_variant_constant(Variant::VECTOR3I, "FORWARD", Vector3i(0, 0, -1)); _VariantCall::add_variant_constant(Variant::VECTOR3I, "BACK", Vector3i(0, 0, 1)); - _VariantCall::add_constant(Variant::VECTOR2, "AXIS_X", Vector2::AXIS_X); - _VariantCall::add_constant(Variant::VECTOR2, "AXIS_Y", Vector2::AXIS_Y); - _VariantCall::add_enum_constant(Variant::VECTOR2, "Axis", "AXIS_X", Vector2::AXIS_X); _VariantCall::add_enum_constant(Variant::VECTOR2, "Axis", "AXIS_Y", Vector2::AXIS_Y); - _VariantCall::add_constant(Variant::VECTOR2I, "AXIS_X", Vector2i::AXIS_X); - _VariantCall::add_constant(Variant::VECTOR2I, "AXIS_Y", Vector2i::AXIS_Y); - _VariantCall::add_enum_constant(Variant::VECTOR2I, "Axis", "AXIS_X", Vector2i::AXIS_X); _VariantCall::add_enum_constant(Variant::VECTOR2I, "Axis", "AXIS_Y", Vector2i::AXIS_Y); @@ -2791,13 +2797,6 @@ static void _register_variant_builtin_constants() { _VariantCall::add_variant_constant(Variant::QUATERNION, "IDENTITY", Quaternion(0, 0, 0, 1)); - _VariantCall::add_constant(Variant::PROJECTION, "PLANE_NEAR", Projection::PLANE_NEAR); - _VariantCall::add_constant(Variant::PROJECTION, "PLANE_FAR", Projection::PLANE_FAR); - _VariantCall::add_constant(Variant::PROJECTION, "PLANE_LEFT", Projection::PLANE_LEFT); - _VariantCall::add_constant(Variant::PROJECTION, "PLANE_TOP", Projection::PLANE_TOP); - _VariantCall::add_constant(Variant::PROJECTION, "PLANE_RIGHT", Projection::PLANE_RIGHT); - _VariantCall::add_constant(Variant::PROJECTION, "PLANE_BOTTOM", Projection::PLANE_BOTTOM); - _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_NEAR", Projection::PLANE_NEAR); _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_FAR", Projection::PLANE_FAR); _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_LEFT", Projection::PLANE_LEFT); |