diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-10-31 23:30:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-31 23:30:50 +0100 |
commit | ea0e9426175e897618bb4ad332e61c808be730c5 (patch) | |
tree | 5a7df916806dd69da33050da5d35eb6b630eecad /modules/visual_script | |
parent | cb3f594b148e33bebf99955c0bb7dce02c8a50c7 (diff) | |
parent | 216a8aa643503b898e1562634240b93406ae1ce3 (diff) |
Merge pull request #12035 from Chaosus/wrapfunc
Added new Wrap functions for numbers
Diffstat (limited to 'modules/visual_script')
-rw-r--r-- | modules/visual_script/visual_script_builtin_funcs.cpp | 40 | ||||
-rw-r--r-- | modules/visual_script/visual_script_builtin_funcs.h | 2 |
2 files changed, 42 insertions, 0 deletions
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 4b294325dc..7c9d306831 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -78,6 +78,8 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX "rad2deg", "linear2db", "db2linear", + "wrapi", + "wrapf", "max", "min", "clamp", @@ -198,6 +200,8 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { case MATH_LERP: case MATH_INVERSE_LERP: case MATH_DECTIME: + case MATH_WRAP: + case MATH_WRAPF: case LOGIC_CLAMP: return 3; case MATH_RANGE_LERP: @@ -364,6 +368,22 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const case MATH_DB2LINEAR: { return PropertyInfo(Variant::REAL, "db"); } break; + case MATH_WRAP: { + if (p_idx == 0) + return PropertyInfo(Variant::INT, "value"); + else if (p_idx == 1) + return PropertyInfo(Variant::INT, "min"); + else + return PropertyInfo(Variant::INT, "max"); + } break; + case MATH_WRAPF: { + if (p_idx == 0) + return PropertyInfo(Variant::REAL, "value"); + else if (p_idx == 1) + return PropertyInfo(Variant::REAL, "min"); + else + return PropertyInfo(Variant::REAL, "max"); + } break; case LOGIC_MAX: { if (p_idx == 0) return PropertyInfo(Variant::REAL, "a"); @@ -549,9 +569,13 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case MATH_DEG2RAD: case MATH_RAD2DEG: case MATH_LINEAR2DB: + case MATH_WRAPF: case MATH_DB2LINEAR: { t = Variant::REAL; } break; + case MATH_WRAP: { + t = Variant::INT; + } break; case LOGIC_MAX: case LOGIC_MIN: case LOGIC_CLAMP: { @@ -898,6 +922,18 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in VALIDATE_ARG_NUM(0); *r_return = Math::db2linear((double)*p_inputs[0]); } break; + case VisualScriptBuiltinFunc::MATH_WRAP: { + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + VALIDATE_ARG_NUM(2); + *r_return = Math::wrapi((int64_t)*p_inputs[0], (int64_t)*p_inputs[1], (int64_t)*p_inputs[2]); + } break; + case VisualScriptBuiltinFunc::MATH_WRAPF: { + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + VALIDATE_ARG_NUM(2); + *r_return = Math::wrapf((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); + } break; case VisualScriptBuiltinFunc::LOGIC_MAX: { if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { @@ -1258,6 +1294,8 @@ void VisualScriptBuiltinFunc::_bind_methods() { BIND_ENUM_CONSTANT(MATH_RAD2DEG); BIND_ENUM_CONSTANT(MATH_LINEAR2DB); BIND_ENUM_CONSTANT(MATH_DB2LINEAR); + BIND_ENUM_CONSTANT(MATH_WRAP); + BIND_ENUM_CONSTANT(MATH_WRAPF); BIND_ENUM_CONSTANT(LOGIC_MAX); BIND_ENUM_CONSTANT(LOGIC_MIN); BIND_ENUM_CONSTANT(LOGIC_CLAMP); @@ -1343,6 +1381,8 @@ void register_visual_script_builtin_func_node() { VisualScriptLanguage::singleton->add_register_func("functions/built_in/rad2deg", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAD2DEG>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/linear2db", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LINEAR2DB>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/db2linear", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DB2LINEAR>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapi", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAP>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAPF>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/max", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MAX>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/min", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MIN>); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 5758d23e8f..34a2825938 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -77,6 +77,8 @@ public: MATH_RAD2DEG, MATH_LINEAR2DB, MATH_DB2LINEAR, + MATH_WRAP, + MATH_WRAPF, LOGIC_MAX, LOGIC_MIN, LOGIC_CLAMP, |