visual_script_builtin_funcs.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**************************************************************************/
  2. /* visual_script_builtin_funcs.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef VISUAL_SCRIPT_BUILTIN_FUNCS_H
  31. #define VISUAL_SCRIPT_BUILTIN_FUNCS_H
  32. #include "visual_script.h"
  33. class VisualScriptBuiltinFunc : public VisualScriptNode {
  34. GDCLASS(VisualScriptBuiltinFunc, VisualScriptNode);
  35. public:
  36. enum BuiltinFunc {
  37. MATH_SIN,
  38. MATH_COS,
  39. MATH_TAN,
  40. MATH_SINH,
  41. MATH_COSH,
  42. MATH_TANH,
  43. MATH_ASIN,
  44. MATH_ACOS,
  45. MATH_ATAN,
  46. MATH_ATAN2,
  47. MATH_SQRT,
  48. MATH_FMOD,
  49. MATH_FPOSMOD,
  50. MATH_FLOOR,
  51. MATH_CEIL,
  52. MATH_ROUND,
  53. MATH_ABS,
  54. MATH_SIGN,
  55. MATH_POW,
  56. MATH_LOG,
  57. MATH_EXP,
  58. MATH_ISNAN,
  59. MATH_ISINF,
  60. MATH_EASE,
  61. MATH_DECIMALS,
  62. MATH_STEPIFY,
  63. MATH_LERP,
  64. MATH_INVERSE_LERP,
  65. MATH_RANGE_LERP,
  66. MATH_MOVE_TOWARD,
  67. MATH_DECTIME,
  68. MATH_RANDOMIZE,
  69. MATH_RAND,
  70. MATH_RANDF,
  71. MATH_RANDOM,
  72. MATH_SEED,
  73. MATH_RANDSEED,
  74. MATH_DEG2RAD,
  75. MATH_RAD2DEG,
  76. MATH_LINEAR2DB,
  77. MATH_DB2LINEAR,
  78. MATH_POLAR2CARTESIAN,
  79. MATH_CARTESIAN2POLAR,
  80. MATH_WRAP,
  81. MATH_WRAPF,
  82. LOGIC_MAX,
  83. LOGIC_MIN,
  84. LOGIC_CLAMP,
  85. LOGIC_NEAREST_PO2,
  86. OBJ_WEAKREF,
  87. FUNC_FUNCREF,
  88. TYPE_CONVERT,
  89. TYPE_OF,
  90. TYPE_EXISTS,
  91. TEXT_CHAR,
  92. TEXT_STR,
  93. TEXT_PRINT,
  94. TEXT_PRINTERR,
  95. TEXT_PRINTRAW,
  96. VAR_TO_STR,
  97. STR_TO_VAR,
  98. VAR_TO_BYTES,
  99. BYTES_TO_VAR,
  100. COLORN,
  101. MATH_SMOOTHSTEP,
  102. MATH_POSMOD,
  103. MATH_LERP_ANGLE,
  104. TEXT_ORD,
  105. FUNC_MAX
  106. };
  107. static int get_func_argument_count(BuiltinFunc p_func);
  108. static String get_func_name(BuiltinFunc p_func);
  109. static void exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Variant::CallError &r_error, String &r_error_str);
  110. static BuiltinFunc find_function(const String &p_string);
  111. private:
  112. static const char *func_name[FUNC_MAX];
  113. BuiltinFunc func;
  114. protected:
  115. static void _bind_methods();
  116. public:
  117. virtual int get_output_sequence_port_count() const;
  118. virtual bool has_input_sequence_port() const;
  119. virtual String get_output_sequence_port_text(int p_port) const;
  120. virtual int get_input_value_port_count() const;
  121. virtual int get_output_value_port_count() const;
  122. virtual PropertyInfo get_input_value_port_info(int p_idx) const;
  123. virtual PropertyInfo get_output_value_port_info(int p_idx) const;
  124. virtual String get_caption() const;
  125. //virtual String get_text() const;
  126. virtual String get_category() const { return "functions"; }
  127. void set_func(BuiltinFunc p_which);
  128. BuiltinFunc get_func();
  129. virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
  130. VisualScriptBuiltinFunc(VisualScriptBuiltinFunc::BuiltinFunc func);
  131. VisualScriptBuiltinFunc();
  132. };
  133. VARIANT_ENUM_CAST(VisualScriptBuiltinFunc::BuiltinFunc)
  134. void register_visual_script_builtin_func_node();
  135. #endif // VISUAL_SCRIPT_BUILTIN_FUNCS_H