summaryrefslogtreecommitdiff
path: root/modules/visual_script/visual_script_builtin_funcs.cpp
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2018-10-27 16:12:27 -0400
committerAaron Franke <arnfranke@yahoo.com>2019-07-18 16:33:43 -0400
commita60f242982d70e85a5b2c182eb3289b2fa7812e1 (patch)
tree212cd72bf8e9b157de9b35ec8ccda3337f30bbbc /modules/visual_script/visual_script_builtin_funcs.cpp
parent20a3bb9c484431439ffa60a158d7563c466cd530 (diff)
Add integer posmod and rename default arg names
"posmod" is the integer version of "fposmod". We do not need a "mod" because of the % operator. I changed the default arg names from "x" and "y" to "a" and "b" because they are not coordinates. I also changed pow's arg names to "base" and "exp". Also, I reorganized the code in the VS built-in funcs switch statement.
Diffstat (limited to 'modules/visual_script/visual_script_builtin_funcs.cpp')
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.cpp131
1 files changed, 42 insertions, 89 deletions
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp
index 75b79f8929..6c9c6b0fc8 100644
--- a/modules/visual_script/visual_script_builtin_funcs.cpp
+++ b/modules/visual_script/visual_script_builtin_funcs.cpp
@@ -104,6 +104,7 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"bytes2var",
"color_named",
"smoothstep",
+ "posmod",
};
VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String &p_string) {
@@ -192,6 +193,7 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
case MATH_ATAN2:
case MATH_FMOD:
case MATH_FPOSMOD:
+ case MATH_POSMOD:
case MATH_POW:
case MATH_EASE:
case MATH_STEPIFY:
@@ -261,7 +263,16 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case MATH_ASIN:
case MATH_ACOS:
case MATH_ATAN:
- case MATH_SQRT: {
+ case MATH_SQRT:
+ case MATH_FLOOR:
+ case MATH_CEIL:
+ case MATH_ROUND:
+ case MATH_ABS:
+ case MATH_SIGN:
+ case MATH_LOG:
+ case MATH_EXP:
+ case MATH_ISNAN:
+ case MATH_ISINF: {
return PropertyInfo(Variant::REAL, "s");
} break;
case MATH_ATAN2: {
@@ -271,32 +282,25 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::REAL, "x");
} break;
case MATH_FMOD:
- case MATH_FPOSMOD: {
+ case MATH_FPOSMOD:
+ case LOGIC_MAX:
+ case LOGIC_MIN: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "x");
+ return PropertyInfo(Variant::REAL, "a");
else
- return PropertyInfo(Variant::REAL, "y");
+ return PropertyInfo(Variant::REAL, "b");
} break;
- case MATH_FLOOR:
- case MATH_CEIL:
- case MATH_ROUND:
- case MATH_ABS:
- case MATH_SIGN: {
- return PropertyInfo(Variant::REAL, "s");
-
+ case MATH_POSMOD: {
+ if (p_idx == 0)
+ return PropertyInfo(Variant::INT, "a");
+ else
+ return PropertyInfo(Variant::INT, "b");
} break;
-
case MATH_POW: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "x");
+ return PropertyInfo(Variant::REAL, "base");
else
- return PropertyInfo(Variant::REAL, "y");
- } break;
- case MATH_LOG:
- case MATH_EXP:
- case MATH_ISNAN:
- case MATH_ISINF: {
- return PropertyInfo(Variant::REAL, "s");
+ return PropertyInfo(Variant::REAL, "exp");
} break;
case MATH_EASE: {
if (p_idx == 0)
@@ -313,14 +317,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
else
return PropertyInfo(Variant::REAL, "steps");
} break;
- case MATH_LERP: {
- if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "from");
- else if (p_idx == 1)
- return PropertyInfo(Variant::REAL, "to");
- else
- return PropertyInfo(Variant::REAL, "weight");
- } break;
+ case MATH_LERP:
case MATH_INVERSE_LERP: {
if (p_idx == 0)
return PropertyInfo(Variant::REAL, "from");
@@ -365,12 +362,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
else
return PropertyInfo(Variant::REAL, "step");
} break;
- case MATH_RANDOMIZE: {
-
- } break;
- case MATH_RAND: {
-
- } break;
+ case MATH_RANDOMIZE:
+ case MATH_RAND:
case MATH_RANDF: {
} break;
@@ -380,9 +373,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
else
return PropertyInfo(Variant::REAL, "to");
} break;
- case MATH_SEED: {
- return PropertyInfo(Variant::INT, "seed");
- } break;
+ case MATH_SEED:
case MATH_RANDSEED: {
return PropertyInfo(Variant::INT, "seed");
} break;
@@ -418,26 +409,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
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");
- else
- return PropertyInfo(Variant::REAL, "b");
- } break;
- case LOGIC_MIN: {
- if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "a");
- else
- return PropertyInfo(Variant::REAL, "b");
- } break;
+ case MATH_WRAPF:
case LOGIC_CLAMP: {
if (p_idx == 0)
return PropertyInfo(Variant::REAL, "value");
@@ -450,20 +422,15 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::INT, "value");
} break;
case OBJ_WEAKREF: {
-
return PropertyInfo(Variant::OBJECT, "source");
-
} break;
case FUNC_FUNCREF: {
-
if (p_idx == 0)
return PropertyInfo(Variant::OBJECT, "instance");
else
return PropertyInfo(Variant::STRING, "funcname");
-
} break;
case TYPE_CONVERT: {
-
if (p_idx == 0)
return PropertyInfo(Variant::NIL, "what");
else
@@ -471,45 +438,24 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
} break;
case TYPE_OF: {
return PropertyInfo(Variant::NIL, "what");
-
} break;
case TYPE_EXISTS: {
-
return PropertyInfo(Variant::STRING, "type");
-
} break;
case TEXT_CHAR: {
-
return PropertyInfo(Variant::INT, "ascii");
-
- } break;
- case TEXT_STR: {
-
- return PropertyInfo(Variant::NIL, "value");
-
- } break;
- case TEXT_PRINT: {
-
- return PropertyInfo(Variant::NIL, "value");
-
- } break;
- case TEXT_PRINTERR: {
- return PropertyInfo(Variant::NIL, "value");
-
} break;
+ case TEXT_STR:
+ case TEXT_PRINT:
+ case TEXT_PRINTERR:
case TEXT_PRINTRAW: {
-
return PropertyInfo(Variant::NIL, "value");
-
- } break;
- case VAR_TO_STR: {
- return PropertyInfo(Variant::NIL, "var");
-
} break;
case STR_TO_VAR: {
return PropertyInfo(Variant::STRING, "string");
} break;
+ case VAR_TO_STR:
case VAR_TO_BYTES: {
if (p_idx == 0)
return PropertyInfo(Variant::NIL, "var");
@@ -525,12 +471,10 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::BOOL, "allow_objects");
} break;
case COLORN: {
-
if (p_idx == 0)
return PropertyInfo(Variant::STRING, "name");
else
return PropertyInfo(Variant::REAL, "alpha");
-
} break;
case FUNC_MAX: {
}
@@ -561,6 +505,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_CEIL: {
t = Variant::REAL;
} break;
+ case MATH_POSMOD:
case MATH_ROUND: {
t = Variant::INT;
} break;
@@ -806,6 +751,12 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
VALIDATE_ARG_NUM(1);
*r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
+ case VisualScriptBuiltinFunc::MATH_POSMOD: {
+
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]);
+ } break;
case VisualScriptBuiltinFunc::MATH_FLOOR: {
VALIDATE_ARG_NUM(0);
@@ -1365,6 +1316,7 @@ void VisualScriptBuiltinFunc::_bind_methods() {
BIND_ENUM_CONSTANT(MATH_SQRT);
BIND_ENUM_CONSTANT(MATH_FMOD);
BIND_ENUM_CONSTANT(MATH_FPOSMOD);
+ BIND_ENUM_CONSTANT(MATH_POSMOD);
BIND_ENUM_CONSTANT(MATH_FLOOR);
BIND_ENUM_CONSTANT(MATH_CEIL);
BIND_ENUM_CONSTANT(MATH_ROUND);
@@ -1454,6 +1406,7 @@ void register_visual_script_builtin_func_node() {
VisualScriptLanguage::singleton->add_register_func("functions/built_in/sqrt", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SQRT>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/fmod", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FMOD>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/fposmod", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FPOSMOD>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/posmod", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_POSMOD>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/floor", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FLOOR>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/ceil", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_CEIL>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/round", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ROUND>);