diff options
Diffstat (limited to 'modules/gdscript/gdscript_functions.cpp')
-rw-r--r-- | modules/gdscript/gdscript_functions.cpp | 204 |
1 files changed, 107 insertions, 97 deletions
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index 426b5b58cb..aaa308f40f 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -162,7 +162,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ if (!p_args[m_arg]->is_num()) { \ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; \ r_error.argument = m_arg; \ - r_error.expected = Variant::REAL; \ + r_error.expected = Variant::FLOAT; \ r_ret = Variant(); \ return; \ } @@ -272,7 +272,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ int64_t i = *p_args[0]; r_ret = ABS(i); - } else if (p_args[0]->get_type() == Variant::REAL) { + } else if (p_args[0]->get_type() == Variant::FLOAT) { double r = *p_args[0]; r_ret = Math::abs(r); @@ -280,7 +280,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = Variant::REAL; + r_error.expected = Variant::FLOAT; r_ret = Variant(); } } break; @@ -290,7 +290,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ int64_t i = *p_args[0]; r_ret = i < 0 ? -1 : (i > 0 ? +1 : 0); - } else if (p_args[0]->get_type() == Variant::REAL) { + } else if (p_args[0]->get_type() == Variant::FLOAT) { real_t r = *p_args[0]; r_ret = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); @@ -298,7 +298,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = Variant::REAL; + r_error.expected = Variant::FLOAT; r_ret = Variant(); } } break; @@ -360,7 +360,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_COUNT(3); VALIDATE_ARG_NUM(2); const double t = (double)*p_args[2]; - switch (p_args[0]->get_type() == p_args[1]->get_type() ? p_args[0]->get_type() : Variant::REAL) { + switch (p_args[0]->get_type() == p_args[1]->get_type() ? p_args[0]->get_type() : Variant::FLOAT) { case Variant::VECTOR2: { r_ret = ((Vector2)*p_args[0]).linear_interpolate((Vector2)*p_args[1], t); } break; @@ -1359,7 +1359,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case INSTANCE_FROM_ID: { VALIDATE_ARG_COUNT(1); - if (p_args[0]->get_type() != Variant::INT && p_args[0]->get_type() != Variant::REAL) { + if (p_args[0]->get_type() != Variant::INT && p_args[0]->get_type() != Variant::FLOAT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::INT; @@ -1395,14 +1395,24 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ Vector<uint8_t> d = *p_args[0]; r_ret = d.size(); } break; - case Variant::PACKED_INT_ARRAY: { + case Variant::PACKED_INT32_ARRAY: { - Vector<int> d = *p_args[0]; + Vector<int32_t> d = *p_args[0]; r_ret = d.size(); } break; - case Variant::PACKED_REAL_ARRAY: { + case Variant::PACKED_INT64_ARRAY: { - Vector<real_t> d = *p_args[0]; + Vector<int64_t> d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::PACKED_FLOAT32_ARRAY: { + + Vector<float> d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::PACKED_FLOAT64_ARRAY: { + + Vector<double> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_STRING_ARRAY: { @@ -1530,69 +1540,69 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { switch (p_func) { case MATH_SIN: { - MethodInfo mi("sin", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("sin", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_COS: { - MethodInfo mi("cos", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("cos", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_TAN: { - MethodInfo mi("tan", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("tan", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_SINH: { - MethodInfo mi("sinh", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("sinh", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_COSH: { - MethodInfo mi("cosh", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("cosh", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_TANH: { - MethodInfo mi("tanh", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("tanh", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_ASIN: { - MethodInfo mi("asin", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("asin", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_ACOS: { - MethodInfo mi("acos", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("acos", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_ATAN: { - MethodInfo mi("atan", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("atan", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_ATAN2: { - MethodInfo mi("atan2", PropertyInfo(Variant::REAL, "y"), PropertyInfo(Variant::REAL, "x")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("atan2", PropertyInfo(Variant::FLOAT, "y"), PropertyInfo(Variant::FLOAT, "x")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_SQRT: { - MethodInfo mi("sqrt", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("sqrt", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_FMOD: { - MethodInfo mi("fmod", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("fmod", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_FPOSMOD: { - MethodInfo mi("fposmod", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("fposmod", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_POSMOD: { @@ -1601,114 +1611,114 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { return mi; } break; case MATH_FLOOR: { - MethodInfo mi("floor", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("floor", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_CEIL: { - MethodInfo mi("ceil", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("ceil", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_ROUND: { - MethodInfo mi("round", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("round", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_ABS: { - MethodInfo mi("abs", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("abs", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_SIGN: { - MethodInfo mi("sign", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("sign", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_POW: { - MethodInfo mi("pow", PropertyInfo(Variant::REAL, "base"), PropertyInfo(Variant::REAL, "exp")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("pow", PropertyInfo(Variant::FLOAT, "base"), PropertyInfo(Variant::FLOAT, "exp")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_LOG: { - MethodInfo mi("log", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("log", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_EXP: { - MethodInfo mi("exp", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("exp", PropertyInfo(Variant::FLOAT, "s")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_ISNAN: { - MethodInfo mi("is_nan", PropertyInfo(Variant::REAL, "s")); + MethodInfo mi("is_nan", PropertyInfo(Variant::FLOAT, "s")); mi.return_val.type = Variant::BOOL; return mi; } break; case MATH_ISINF: { - MethodInfo mi("is_inf", PropertyInfo(Variant::REAL, "s")); + MethodInfo mi("is_inf", PropertyInfo(Variant::FLOAT, "s")); mi.return_val.type = Variant::BOOL; return mi; } break; case MATH_ISEQUALAPPROX: { - MethodInfo mi("is_equal_approx", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b")); + MethodInfo mi("is_equal_approx", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b")); mi.return_val.type = Variant::BOOL; return mi; } break; case MATH_ISZEROAPPROX: { - MethodInfo mi("is_zero_approx", PropertyInfo(Variant::REAL, "s")); + MethodInfo mi("is_zero_approx", PropertyInfo(Variant::FLOAT, "s")); mi.return_val.type = Variant::BOOL; return mi; } break; case MATH_EASE: { - MethodInfo mi("ease", PropertyInfo(Variant::REAL, "s"), PropertyInfo(Variant::REAL, "curve")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("ease", PropertyInfo(Variant::FLOAT, "s"), PropertyInfo(Variant::FLOAT, "curve")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_STEP_DECIMALS: { - MethodInfo mi("step_decimals", PropertyInfo(Variant::REAL, "step")); + MethodInfo mi("step_decimals", PropertyInfo(Variant::FLOAT, "step")); mi.return_val.type = Variant::INT; return mi; } break; case MATH_STEPIFY: { - MethodInfo mi("stepify", PropertyInfo(Variant::REAL, "s"), PropertyInfo(Variant::REAL, "step")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("stepify", PropertyInfo(Variant::FLOAT, "s"), PropertyInfo(Variant::FLOAT, "step")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_LERP: { - MethodInfo mi("lerp", PropertyInfo(Variant::NIL, "from"), PropertyInfo(Variant::NIL, "to"), PropertyInfo(Variant::REAL, "weight")); + MethodInfo mi("lerp", PropertyInfo(Variant::NIL, "from"), PropertyInfo(Variant::NIL, "to"), PropertyInfo(Variant::FLOAT, "weight")); mi.return_val.type = Variant::NIL; mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; return mi; } break; case MATH_LERP_ANGLE: { - MethodInfo mi("lerp_angle", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "weight")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("lerp_angle", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"), PropertyInfo(Variant::FLOAT, "weight")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_INVERSE_LERP: { - MethodInfo mi("inverse_lerp", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "weight")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("inverse_lerp", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"), PropertyInfo(Variant::FLOAT, "weight")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_RANGE_LERP: { - MethodInfo mi("range_lerp", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "istart"), PropertyInfo(Variant::REAL, "istop"), PropertyInfo(Variant::REAL, "ostart"), PropertyInfo(Variant::REAL, "ostop")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("range_lerp", PropertyInfo(Variant::FLOAT, "value"), PropertyInfo(Variant::FLOAT, "istart"), PropertyInfo(Variant::FLOAT, "istop"), PropertyInfo(Variant::FLOAT, "ostart"), PropertyInfo(Variant::FLOAT, "ostop")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_SMOOTHSTEP: { - MethodInfo mi("smoothstep", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "weight")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("smoothstep", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"), PropertyInfo(Variant::FLOAT, "weight")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_MOVE_TOWARD: { - MethodInfo mi("move_toward", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "delta")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("move_toward", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"), PropertyInfo(Variant::FLOAT, "delta")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_DECTIME: { - MethodInfo mi("dectime", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "amount"), PropertyInfo(Variant::REAL, "step")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("dectime", PropertyInfo(Variant::FLOAT, "value"), PropertyInfo(Variant::FLOAT, "amount"), PropertyInfo(Variant::FLOAT, "step")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_RANDOMIZE: { @@ -1723,12 +1733,12 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case MATH_RANDF: { MethodInfo mi("randf"); - mi.return_val.type = Variant::REAL; + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_RANDOM: { - MethodInfo mi("rand_range", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("rand_range", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_SEED: { @@ -1742,32 +1752,32 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { return mi; } break; case MATH_DEG2RAD: { - MethodInfo mi("deg2rad", PropertyInfo(Variant::REAL, "deg")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("deg2rad", PropertyInfo(Variant::FLOAT, "deg")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_RAD2DEG: { - MethodInfo mi("rad2deg", PropertyInfo(Variant::REAL, "rad")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("rad2deg", PropertyInfo(Variant::FLOAT, "rad")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_LINEAR2DB: { - MethodInfo mi("linear2db", PropertyInfo(Variant::REAL, "nrg")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("linear2db", PropertyInfo(Variant::FLOAT, "nrg")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_DB2LINEAR: { - MethodInfo mi("db2linear", PropertyInfo(Variant::REAL, "db")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("db2linear", PropertyInfo(Variant::FLOAT, "db")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case MATH_POLAR2CARTESIAN: { - MethodInfo mi("polar2cartesian", PropertyInfo(Variant::REAL, "r"), PropertyInfo(Variant::REAL, "th")); + MethodInfo mi("polar2cartesian", PropertyInfo(Variant::FLOAT, "r"), PropertyInfo(Variant::FLOAT, "th")); mi.return_val.type = Variant::VECTOR2; return mi; } break; case MATH_CARTESIAN2POLAR: { - MethodInfo mi("cartesian2polar", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y")); + MethodInfo mi("cartesian2polar", PropertyInfo(Variant::FLOAT, "x"), PropertyInfo(Variant::FLOAT, "y")); mi.return_val.type = Variant::VECTOR2; return mi; } break; @@ -1777,24 +1787,24 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { return mi; } break; case MATH_WRAPF: { - MethodInfo mi("wrapf", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "min"), PropertyInfo(Variant::REAL, "max")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("wrapf", PropertyInfo(Variant::FLOAT, "value"), PropertyInfo(Variant::FLOAT, "min"), PropertyInfo(Variant::FLOAT, "max")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case LOGIC_MAX: { - MethodInfo mi("max", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("max", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case LOGIC_MIN: { - MethodInfo mi("min", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("min", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case LOGIC_CLAMP: { - MethodInfo mi("clamp", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "min"), PropertyInfo(Variant::REAL, "max")); - mi.return_val.type = Variant::REAL; + MethodInfo mi("clamp", PropertyInfo(Variant::FLOAT, "value"), PropertyInfo(Variant::FLOAT, "min"), PropertyInfo(Variant::FLOAT, "max")); + mi.return_val.type = Variant::FLOAT; return mi; } break; case LOGIC_NEAREST_PO2: { @@ -2012,7 +2022,7 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case COLORN: { - MethodInfo mi("ColorN", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::REAL, "alpha")); + MethodInfo mi("ColorN", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::FLOAT, "alpha")); mi.default_arguments.push_back(1.0f); mi.return_val.type = Variant::COLOR; return mi; |