diff options
Diffstat (limited to 'core/variant')
-rw-r--r-- | core/variant/variant.cpp | 30 | ||||
-rw-r--r-- | core/variant/variant.h | 17 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 8 | ||||
-rw-r--r-- | core/variant/variant_parser.cpp | 2 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 6 |
5 files changed, 24 insertions, 39 deletions
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index b280fc9fe3..f24ffeb1a9 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -3727,36 +3727,6 @@ String Variant::get_callable_error_text(const Callable &p_callable, const Varian return get_call_error_text(p_callable.get_object(), p_callable.get_method(), p_argptrs, p_argcount, ce); } -String vformat(const String &p_text, const Variant &p1, const Variant &p2, const Variant &p3, const Variant &p4, const Variant &p5) { - Array args; - if (p1.get_type() != Variant::NIL) { - args.push_back(p1); - - if (p2.get_type() != Variant::NIL) { - args.push_back(p2); - - if (p3.get_type() != Variant::NIL) { - args.push_back(p3); - - if (p4.get_type() != Variant::NIL) { - args.push_back(p4); - - if (p5.get_type() != Variant::NIL) { - args.push_back(p5); - } - } - } - } - } - - bool error = false; - String fmt = p_text.sprintf(args, &error); - - ERR_FAIL_COND_V_MSG(error, String(), fmt); - - return fmt; -} - void Variant::register_types() { _register_variant_operators(); _register_variant_methods(); diff --git a/core/variant/variant.h b/core/variant/variant.h index 964fcd99a0..b0738e7d44 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -804,7 +804,22 @@ const Variant::ObjData &Variant::_get_obj() const { return *reinterpret_cast<const ObjData *>(&_data._mem[0]); } -String vformat(const String &p_text, const Variant &p1 = Variant(), const Variant &p2 = Variant(), const Variant &p3 = Variant(), const Variant &p4 = Variant(), const Variant &p5 = Variant()); +template <typename... VarArgs> +String vformat(const String &p_text, const VarArgs... p_args) { + Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported. + Array args_array; + args_array.resize(sizeof...(p_args)); + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + args_array[i] = args[i]; + } + + bool error = false; + String fmt = p_text.sprintf(args_array, &error); + + ERR_FAIL_COND_V_MSG(error, String(), fmt); + + return fmt; +} template <typename... VarArgs> Callable Callable::bind(VarArgs... p_args) { diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 8f15a62f79..f09885b325 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1650,7 +1650,7 @@ static void _register_variant_builtin_methods() { bind_method(Rect2, get_center, sarray(), varray()); bind_method(Rect2, get_area, sarray(), varray()); - bind_method(Rect2, has_no_area, sarray(), varray()); + bind_method(Rect2, has_area, sarray(), varray()); bind_method(Rect2, has_point, sarray("point"), varray()); bind_method(Rect2, is_equal_approx, sarray("rect"), varray()); bind_method(Rect2, intersects, sarray("b", "include_borders"), varray(false)); @@ -1667,7 +1667,7 @@ static void _register_variant_builtin_methods() { bind_method(Rect2i, get_center, sarray(), varray()); bind_method(Rect2i, get_area, sarray(), varray()); - bind_method(Rect2i, has_no_area, sarray(), varray()); + bind_method(Rect2i, has_area, sarray(), varray()); bind_method(Rect2i, has_point, sarray("point"), varray()); bind_method(Rect2i, intersects, sarray("b"), varray()); bind_method(Rect2i, encloses, sarray("b"), varray()); @@ -1938,8 +1938,8 @@ static void _register_variant_builtin_methods() { bind_method(AABB, abs, sarray(), varray()); bind_method(AABB, get_center, sarray(), varray()); bind_method(AABB, get_volume, sarray(), varray()); - bind_method(AABB, has_no_volume, sarray(), varray()); - bind_method(AABB, has_no_surface, sarray(), varray()); + bind_method(AABB, has_volume, sarray(), varray()); + bind_method(AABB, has_surface, sarray(), varray()); bind_method(AABB, has_point, sarray("point"), varray()); bind_method(AABB, is_equal_approx, sarray("aabb"), varray()); bind_method(AABB, intersects, sarray("with"), varray()); diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 34653310b1..8151ff2102 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1680,7 +1680,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str } break; case Variant::OBJECT: { - Object *obj = p_variant; + Object *obj = p_variant.get_validated_object(); if (!obj) { p_store_string_func(p_store_string_ud, "null"); diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 1be17405c7..7ff64c88f0 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -393,8 +393,8 @@ struct VariantUtilityFunctions { return Math::inverse_lerp(from, to, weight); } - static inline double range_lerp(double value, double istart, double istop, double ostart, double ostop) { - return Math::range_lerp(value, istart, istop, ostart, ostop); + static inline double remap(double value, double istart, double istop, double ostart, double ostop) { + return Math::remap(value, istart, istop, ostart, ostop); } static inline double smoothstep(double from, double to, double val) { @@ -1434,7 +1434,7 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(bezier_interpolate, sarray("start", "control_1", "control_2", "end", "t"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(lerp_angle, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(inverse_lerp, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH); - FUNCBINDR(range_lerp, sarray("value", "istart", "istop", "ostart", "ostop"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(remap, sarray("value", "istart", "istop", "ostart", "ostop"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(smoothstep, sarray("from", "to", "x"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(move_toward, sarray("from", "to", "delta"), Variant::UTILITY_FUNC_TYPE_MATH); |