diff options
Diffstat (limited to 'modules/visual_script')
-rw-r--r-- | modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml | 14 | ||||
-rw-r--r-- | modules/visual_script/visual_script.cpp | 13 | ||||
-rw-r--r-- | modules/visual_script/visual_script.h | 91 | ||||
-rw-r--r-- | modules/visual_script/visual_script_builtin_funcs.cpp | 25 | ||||
-rw-r--r-- | modules/visual_script/visual_script_builtin_funcs.h | 1 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 55 | ||||
-rw-r--r-- | modules/visual_script/visual_script_expression.cpp | 23 | ||||
-rw-r--r-- | modules/visual_script/visual_script_expression.h | 47 | ||||
-rw-r--r-- | modules/visual_script/visual_script_flow_control.cpp | 14 | ||||
-rw-r--r-- | modules/visual_script/visual_script_flow_control.h | 2 | ||||
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.cpp | 54 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 61 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.h | 4 | ||||
-rw-r--r-- | modules/visual_script/visual_script_yield_nodes.cpp | 12 |
14 files changed, 214 insertions, 202 deletions
diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml index 4004f1a04c..219ffd01d3 100644 --- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml +++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml @@ -202,24 +202,20 @@ <constant name="BYTES_TO_VAR" value="62" enum="BuiltinFunc"> Deserialize a [Variant] from a [PackedByteArray] serialized using [constant VAR_TO_BYTES]. </constant> - <constant name="COLORN" value="63" enum="BuiltinFunc"> - Return the [Color] with the given name and alpha ranging from 0 to 1. - [b]Note:[/b] Names are defined in [code]color_names.inc[/code]. - </constant> - <constant name="MATH_SMOOTHSTEP" value="64" enum="BuiltinFunc"> + <constant name="MATH_SMOOTHSTEP" value="63" enum="BuiltinFunc"> Return a number smoothly interpolated between the first two inputs, based on the third input. Similar to [constant MATH_LERP], but interpolates faster at the beginning and slower at the end. Using Hermite interpolation formula: [codeblock] var t = clamp((weight - from) / (to - from), 0.0, 1.0) return t * t * (3.0 - 2.0 * t) [/codeblock] </constant> - <constant name="MATH_POSMOD" value="65" enum="BuiltinFunc"> + <constant name="MATH_POSMOD" value="64" enum="BuiltinFunc"> </constant> - <constant name="MATH_LERP_ANGLE" value="66" enum="BuiltinFunc"> + <constant name="MATH_LERP_ANGLE" value="65" enum="BuiltinFunc"> </constant> - <constant name="TEXT_ORD" value="67" enum="BuiltinFunc"> + <constant name="TEXT_ORD" value="66" enum="BuiltinFunc"> </constant> - <constant name="FUNC_MAX" value="68" enum="BuiltinFunc"> + <constant name="FUNC_MAX" value="67" enum="BuiltinFunc"> Represents the size of the [enum BuiltinFunc] enum. </constant> </constants> diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index fe92f59179..e91ae46a57 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -137,7 +137,6 @@ Ref<VisualScript> VisualScriptNode::get_visual_script() const { } VisualScriptNode::VisualScriptNode() { - breakpoint = false; } //////////////// @@ -145,8 +144,6 @@ VisualScriptNode::VisualScriptNode() { ///////////////////// VisualScriptNodeInstance::VisualScriptNodeInstance() { - sequence_outputs = nullptr; - input_ports = nullptr; } VisualScriptNodeInstance::~VisualScriptNodeInstance() { @@ -1372,7 +1369,7 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int // Is a default value (unassigned input port). input_args[i] = &default_values[index]; } else { - // Rregular temporary in stack. + // Regular temporary in stack. input_args[i] = &variant_stack[index]; } } @@ -1394,7 +1391,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p ERR_FAIL_COND_V(!F, Variant()); Function *f = &F->get(); - // This call goes separate, so it can e yielded and suspended. + // This call goes separate, so it can be yielded and suspended. Variant *variant_stack = (Variant *)p_stack; bool *sequence_bits = (bool *)(variant_stack + f->max_stack); const Variant **input_args = (const Variant **)(sequence_bits + f->node_count); @@ -2623,14 +2620,8 @@ void VisualScriptLanguage::get_registered_node_names(List<String> *r_names) { } VisualScriptLanguage::VisualScriptLanguage() { - notification = "_notification"; - _step = "_step"; - _subcall = "_subcall"; singleton = this; - _debug_parse_err_node = -1; - _debug_parse_err_file = ""; - _debug_call_stack_pos = 0; int dmcs = GLOBAL_DEF("debug/settings/visual_script/max_call_stack", 1024); ProjectSettings::get_singleton()->set_custom_property_info("debug/settings/visual_script/max_call_stack", PropertyInfo(Variant::INT, "debug/settings/visual_script/max_call_stack", PROPERTY_HINT_RANGE, "1024,4096,1,or_greater")); //minimum is 1024 diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index bdb3c3a16b..72362e0ef4 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -49,7 +49,7 @@ class VisualScriptNode : public Resource { Ref<VisualScript> script_used; Array default_input_values; - bool breakpoint; + bool breakpoint = false; void _set_default_input_values(Array p_values); Array _get_default_input_values() const; @@ -90,13 +90,9 @@ public: virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) = 0; struct TypeGuess { - Variant::Type type; + Variant::Type type = Variant::NIL; StringName gdclass; Ref<Script> script; - - TypeGuess() { - type = Variant::NIL; - } }; virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; @@ -114,19 +110,19 @@ class VisualScriptNodeInstance { INPUT_DEFAULT_VALUE_BIT = INPUT_SHIFT, // from unassigned input port, using default value (edited by user) }; - int id; - int sequence_index; - VisualScriptNodeInstance **sequence_outputs; - int sequence_output_count; + int id = 0; + int sequence_index = 0; + VisualScriptNodeInstance **sequence_outputs = nullptr; + int sequence_output_count = 0; Vector<VisualScriptNodeInstance *> dependencies; - int *input_ports; - int input_port_count; - int *output_ports; - int output_port_count; - int working_mem_idx; - int pass_idx; + int *input_ports = nullptr; + int input_port_count = 0; + int *output_ports = nullptr; + int output_port_count = 0; + int working_mem_idx = 0; + int pass_idx = 0; - VisualScriptNode *base; + VisualScriptNode *base = nullptr; public: enum StartMode { @@ -178,7 +174,7 @@ public: uint64_t from_output : 16; uint64_t to_node : 24; }; - uint64_t id; + uint64_t id = 0; }; bool operator<(const SequenceConnection &p_connection) const { @@ -194,7 +190,7 @@ public: uint64_t to_node : 24; uint64_t to_port : 8; }; - uint64_t id; + uint64_t id = 0; }; bool operator<(const DataConnection &p_connection) const { @@ -208,7 +204,7 @@ private: StringName base_type; struct Argument { String name; - Variant::Type type; + Variant::Type type = Variant::Type::NIL; }; struct NodeData { @@ -231,7 +227,7 @@ private: struct Variable { PropertyInfo info; Variant default_value; - bool _export; + bool _export = false; // Add getter & setter options here. }; @@ -388,26 +384,27 @@ public: }; class VisualScriptInstance : public ScriptInstance { - Object *owner; + Object *owner = nullptr; Ref<VisualScript> script; Map<StringName, Variant> variables; // Using variable path, not script. Map<int, VisualScriptNodeInstance *> instances; struct Function { - int node; - int max_stack; - int trash_pos; - int flow_stack_size; - int pass_stack_size; - int node_count; - int argument_count; + int node = 0; + int max_stack = 0; + int trash_pos = 0; + int flow_stack_size = 0; + int pass_stack_size = 0; + int node_count = 0; + int argument_count = 0; }; Map<StringName, Function> functions; Vector<Variant> default_values; - int max_input_args, max_output_args; + int max_input_args = 0; + int max_output_args = 0; StringName source; @@ -479,14 +476,14 @@ class VisualScriptFunctionState : public Reference { ObjectID instance_id; ObjectID script_id; - VisualScriptInstance *instance; + VisualScriptInstance *instance = nullptr; StringName function; Vector<uint8_t> stack; - int working_mem_index; - int variant_stack_size; - VisualScriptNodeInstance *node; - int flow_stack_pos; - int pass; + int working_mem_index = 0; + int variant_stack_size = 0; + VisualScriptNodeInstance *node = nullptr; + int flow_stack_pos = 0; + int pass = 0; Variant _signal_callback(const Variant **p_args, int p_argcount, Callable::CallError &r_error); @@ -507,25 +504,25 @@ class VisualScriptLanguage : public ScriptLanguage { Map<String, VisualScriptNodeRegisterFunc> register_funcs; struct CallLevel { - Variant *stack; - Variant **work_mem; - const StringName *function; - VisualScriptInstance *instance; - int *current_id; + Variant *stack = nullptr; + Variant **work_mem = nullptr; + const StringName *function = nullptr; + VisualScriptInstance *instance = nullptr; + int *current_id = nullptr; }; - int _debug_parse_err_node; - String _debug_parse_err_file; + int _debug_parse_err_node = -1; + String _debug_parse_err_file = ""; String _debug_error; - int _debug_call_stack_pos; + int _debug_call_stack_pos = 0; int _debug_max_call_stack; CallLevel *_call_stack; public: - StringName notification; + StringName notification = "_notification"; StringName _get_output_port_unsequenced; - StringName _step; - StringName _subcall; + StringName _step = "_step"; + StringName _subcall = "_subcall"; static VisualScriptLanguage *singleton; diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 2558c1d7ec..7ca14fbca8 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -101,7 +101,6 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX "str2var", "var2bytes", "bytes2var", - "color_named", "smoothstep", "posmod", "lerp_angle", @@ -200,7 +199,6 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { case LOGIC_MAX: case LOGIC_MIN: case TYPE_CONVERT: - case COLORN: return 2; case MATH_LERP: case MATH_LERP_ANGLE: @@ -476,13 +474,6 @@ 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::FLOAT, "alpha"); - } - } break; case FUNC_MAX: { } } @@ -635,9 +626,6 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons t = Variant::BOOL; } } break; - case COLORN: { - t = Variant::COLOR; - } break; case FUNC_MAX: { } } @@ -659,7 +647,7 @@ String VisualScriptBuiltinFunc::get_caption() const { void VisualScriptBuiltinFunc::set_func(BuiltinFunc p_which) { ERR_FAIL_INDEX(p_which, FUNC_MAX); func = p_which; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1176,15 +1164,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = ret; } break; - case VisualScriptBuiltinFunc::COLORN: { - VALIDATE_ARG_NUM(1); - - Color color = Color::named(*p_inputs[0]); - color.a = *p_inputs[1]; - - *r_return = String(color); - - } break; default: { } } @@ -1292,7 +1271,6 @@ void VisualScriptBuiltinFunc::_bind_methods() { BIND_ENUM_CONSTANT(STR_TO_VAR); BIND_ENUM_CONSTANT(VAR_TO_BYTES); BIND_ENUM_CONSTANT(BYTES_TO_VAR); - BIND_ENUM_CONSTANT(COLORN); BIND_ENUM_CONSTANT(MATH_SMOOTHSTEP); BIND_ENUM_CONSTANT(MATH_POSMOD); BIND_ENUM_CONSTANT(MATH_LERP_ANGLE); @@ -1388,5 +1366,4 @@ void register_visual_script_builtin_func_node() { VisualScriptLanguage::singleton->add_register_func("functions/built_in/str2var", create_builtin_func_node<VisualScriptBuiltinFunc::STR_TO_VAR>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2bytes", create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_BYTES>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/bytes2var", create_builtin_func_node<VisualScriptBuiltinFunc::BYTES_TO_VAR>); - VisualScriptLanguage::singleton->add_register_func("functions/built_in/color_named", create_builtin_func_node<VisualScriptBuiltinFunc::COLORN>); } diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index eaa2ef41e2..1fafaf1d98 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -101,7 +101,6 @@ public: STR_TO_VAR, VAR_TO_BYTES, BYTES_TO_VAR, - COLORN, MATH_SMOOTHSTEP, MATH_POSMOD, MATH_LERP_ANGLE, diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 3fbf19a48d..d520837d43 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -61,7 +61,7 @@ protected: } void _sig_changed() { - _change_notify(); + notify_property_list_changed(); emit_signal("changed"); } @@ -172,7 +172,7 @@ protected: public: void edit(const StringName &p_sig) { sig = p_sig; - _change_notify(); + notify_property_list_changed(); } VisualScriptEditorSignalEdit() { undo_redo = nullptr; } @@ -195,11 +195,10 @@ protected: } void _var_changed() { - _change_notify(); + notify_property_list_changed(); emit_signal("changed"); } void _var_value_changed() { - _change_notify("value"); // So the whole tree is not redrawn, makes editing smoother in general. emit_signal("changed"); } @@ -227,6 +226,19 @@ protected: undo_redo->create_action(TTR("Set Variable Type")); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); + + // Setting the default value. + Variant::Type type = (Variant::Type)(int)p_value; + if (type != Variant::NIL) { + Variant default_value; + Callable::CallError ce; + Variant::construct(type, default_value, nullptr, 0, ce); + if (ce.error == Callable::CallError::CALL_OK) { + undo_redo->add_do_method(script.ptr(), "set_variable_default_value", var, default_value); + undo_redo->add_undo_method(script.ptr(), "set_variable_default_value", var, dc["value"]); + } + } + undo_redo->add_do_method(this, "_var_changed"); undo_redo->add_undo_method(this, "_var_changed"); undo_redo->commit_action(); @@ -318,7 +330,7 @@ protected: public: void edit(const StringName &p_var) { var = p_var; - _change_notify(); + notify_property_list_changed(); } VisualScriptEditorVariableEdit() { undo_redo = nullptr; } @@ -968,6 +980,10 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } _update_graph_connections(); + + float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); + graph->set_minimap_opacity(graph_minimap_opacity); + // Use default_func instead of default_func for now I think that should be good stop gap solution to ensure not breaking anything. graph->call_deferred("set_scroll_ofs", script->get_scroll() * EDSCALE); updating_graph = false; @@ -1821,7 +1837,7 @@ void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) { void VisualScriptEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> key = p_event; - if (key.is_valid() && key->is_pressed() && key->get_button_mask() == BUTTON_RIGHT) { + if (key.is_valid() && key->is_pressed() && key->get_button_mask() == MOUSE_BUTTON_RIGHT) { saved_position = graph->get_local_mouse_position(); Point2 gpos = Input::get_singleton()->get_mouse_position(); @@ -3672,16 +3688,23 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_ return; } + Vector2 new_size = p_new_size; + if (graph->is_using_snap()) { + Vector2 snap = Vector2(graph->get_snap(), graph->get_snap()); + Vector2 min_size = (gn->get_minimum_size() + (snap * 0.5)).snapped(snap); + new_size = new_size.snapped(snap).max(min_size); + } + updating_graph = true; graph->set_block_minimum_size_adjust(true); //faster resize undo_redo->create_action(TTR("Resize Comment"), UndoRedo::MERGE_ENDS); - undo_redo->add_do_method(vsc.ptr(), "set_size", p_new_size / EDSCALE); + undo_redo->add_do_method(vsc.ptr(), "set_size", new_size / EDSCALE); undo_redo->add_undo_method(vsc.ptr(), "set_size", vsc->get_size()); undo_redo->commit_action(); - gn->set_custom_minimum_size(p_new_size); + gn->set_custom_minimum_size(new_size); gn->set_size(Size2(1, 1)); graph->set_block_minimum_size_adjust(false); updating_graph = false; @@ -3935,7 +3958,7 @@ void VisualScriptEditor::_menu_option(int p_what) { if (start_node == -1) { // If we still don't have a start node then, // run through the nodes and select the first tree node, - // ie node without any input sequence but output sequence. + // i.e. node without any input sequence but output sequence. for (Set<int>::Element *E = nodes_from.front(); E; E = E->next()) { if (!nodes_to.has(E->get())) { start_node = E->get(); @@ -4251,13 +4274,13 @@ VisualScriptEditor::VisualScriptEditor() { edit_menu->set_shortcut_context(this); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); - edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/delete_selected"), EDIT_DELETE_NODES); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_graph_delete"), EDIT_DELETE_NODES); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/toggle_breakpoint"), EDIT_TOGGLE_BREAKPOINT); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/find_node_type"), EDIT_FIND_NODE_TYPE); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/copy_nodes"), EDIT_COPY_NODES); - edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/cut_nodes"), EDIT_CUT_NODES); - edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/paste_nodes"), EDIT_PASTE_NODES); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY_NODES); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT_NODES); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE_NODES); edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/create_function"), EDIT_CREATE_FUNCTION); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/refresh_nodes"), REFRESH_GRAPH); @@ -4313,6 +4336,8 @@ VisualScriptEditor::VisualScriptEditor() { graph->connect("duplicate_nodes_request", callable_mp(this, &VisualScriptEditor::_on_nodes_duplicate)); graph->connect("gui_input", callable_mp(this, &VisualScriptEditor::_graph_gui_input)); graph->set_drag_forwarding(this); + float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); + graph->set_minimap_opacity(graph_minimap_opacity); graph->hide(); graph->connect("scroll_offset_changed", callable_mp(this, &VisualScriptEditor::_graph_ofs_changed)); @@ -4495,12 +4520,8 @@ void VisualScriptEditor::free_clipboard() { static void register_editor_callback() { ScriptEditor::register_create_script_editor_function(create_editor); - ED_SHORTCUT("visual_script_editor/delete_selected", TTR("Delete Selected"), KEY_DELETE); ED_SHORTCUT("visual_script_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); ED_SHORTCUT("visual_script_editor/find_node_type", TTR("Find Node Type"), KEY_MASK_CMD + KEY_F); - ED_SHORTCUT("visual_script_editor/copy_nodes", TTR("Copy Nodes"), KEY_MASK_CMD + KEY_C); - ED_SHORTCUT("visual_script_editor/cut_nodes", TTR("Cut Nodes"), KEY_MASK_CMD + KEY_X); - ED_SHORTCUT("visual_script_editor/paste_nodes", TTR("Paste Nodes"), KEY_MASK_CMD + KEY_V); ED_SHORTCUT("visual_script_editor/create_function", TTR("Make Function"), KEY_MASK_CMD + KEY_G); ED_SHORTCUT("visual_script_editor/refresh_nodes", TTR("Refresh Graph"), KEY_MASK_CMD + KEY_R); ED_SHORTCUT("visual_script_editor/edit_member", TTR("Edit Member"), KEY_MASK_CMD + KEY_E); diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 9596fda95c..cb4230bea9 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -63,7 +63,7 @@ bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_val } expression_dirty = true; ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); return true; } @@ -1054,7 +1054,7 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } } - /* Reduce the set set of expressions and place them in an operator tree, respecting precedence */ + /* Reduce the set of expressions and place them in an operator tree, respecting precedence */ while (expression.size() > 1) { int next_op = -1; @@ -1506,13 +1506,20 @@ VisualScriptNodeInstance *VisualScriptExpression::instance(VisualScriptInstance return instance; } +void VisualScriptExpression::reset_state() { + if (nodes) { + memdelete(nodes); + nodes = nullptr; + root = nullptr; + } + + error_str = String(); + error_set = false; + str_ofs = 0; + inputs.clear(); +} + VisualScriptExpression::VisualScriptExpression() { - output_type = Variant::NIL; - expression_dirty = true; - error_set = true; - root = nullptr; - nodes = nullptr; - sequenced = false; } VisualScriptExpression::~VisualScriptExpression() { diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index 7fe665769d..c35075ea53 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -39,20 +39,18 @@ class VisualScriptExpression : public VisualScriptNode { friend class VisualScriptNodeInstanceExpression; struct Input { - Variant::Type type; + Variant::Type type = Variant::NIL; String name; - - Input() { type = Variant::NIL; } }; Vector<Input> inputs; - Variant::Type output_type; + Variant::Type output_type = Variant::NIL; String expression; - bool sequenced; - int str_ofs; - bool expression_dirty; + bool sequenced = false; + int str_ofs = 0; + bool expression_dirty = true; bool _compile_expression(); @@ -114,7 +112,7 @@ class VisualScriptExpression : public VisualScriptNode { Error _get_token(Token &r_token); String error_str; - bool error_set; + bool error_set = true; struct ENode { enum Type { @@ -131,11 +129,10 @@ class VisualScriptExpression : public VisualScriptNode { TYPE_CALL }; - ENode *next; + ENode *next = nullptr; - Type type; + Type type = Type::TYPE_SELF; - ENode() { next = nullptr; } virtual ~ENode() { if (next) { memdelete(next); @@ -144,17 +141,17 @@ class VisualScriptExpression : public VisualScriptNode { }; struct Expression { - bool is_op; + bool is_op = false; union { Variant::Operator op; - ENode *node; + ENode *node = nullptr; }; }; ENode *_parse_expression(); struct InputNode : public ENode { - int index; + int index = 0; InputNode() { type = TYPE_INPUT; } @@ -168,9 +165,9 @@ class VisualScriptExpression : public VisualScriptNode { }; struct OperatorNode : public ENode { - Variant::Operator op; + Variant::Operator op = Variant::Operator::OP_ADD; - ENode *nodes[2]; + ENode *nodes[2] = { nullptr, nullptr }; OperatorNode() { type = TYPE_OPERATOR; @@ -184,8 +181,8 @@ class VisualScriptExpression : public VisualScriptNode { }; struct IndexNode : public ENode { - ENode *base; - ENode *index; + ENode *base = nullptr; + ENode *index = nullptr; IndexNode() { type = TYPE_INDEX; @@ -193,7 +190,7 @@ class VisualScriptExpression : public VisualScriptNode { }; struct NamedIndexNode : public ENode { - ENode *base; + ENode *base = nullptr; StringName name; NamedIndexNode() { @@ -202,7 +199,7 @@ class VisualScriptExpression : public VisualScriptNode { }; struct ConstructorNode : public ENode { - Variant::Type data_type; + Variant::Type data_type = Variant::Type::NIL; Vector<ENode *> arguments; ConstructorNode() { @@ -211,7 +208,7 @@ class VisualScriptExpression : public VisualScriptNode { }; struct CallNode : public ENode { - ENode *base; + ENode *base = nullptr; StringName method; Vector<ENode *> arguments; @@ -235,7 +232,7 @@ class VisualScriptExpression : public VisualScriptNode { }; struct BuiltinFuncNode : public ENode { - VisualScriptBuiltinFunc::BuiltinFunc func; + VisualScriptBuiltinFunc::BuiltinFunc func = VisualScriptBuiltinFunc::BuiltinFunc::BYTES_TO_VAR; Vector<ENode *> arguments; BuiltinFuncNode() { type = TYPE_BUILTIN_FUNC; @@ -250,8 +247,8 @@ class VisualScriptExpression : public VisualScriptNode { return node; } - ENode *root; - ENode *nodes; + ENode *root = nullptr; + ENode *nodes = nullptr; protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -259,6 +256,8 @@ protected: void _get_property_list(List<PropertyInfo> *p_list) const; public: + virtual void reset_state() override; + virtual int get_output_sequence_port_count() const override; virtual bool has_input_sequence_port() const override; diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 0049e254c4..e977f9c96b 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -628,7 +628,7 @@ VisualScriptNodeInstance *VisualScriptSwitch::instance(VisualScriptInstance *p_i bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) { if (String(p_name) == "case_count") { case_values.resize(p_value); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); return true; } @@ -638,7 +638,7 @@ bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) ERR_FAIL_INDEX_V(idx, case_values.size(), false); case_values.write[idx].type = Variant::Type(int(p_value)); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); return true; @@ -677,6 +677,10 @@ void VisualScriptSwitch::_get_property_list(List<PropertyInfo> *p_list) const { } } +void VisualScriptSwitch::reset_state() { + case_values.clear(); +} + void VisualScriptSwitch::_bind_methods() { } @@ -733,7 +737,7 @@ void VisualScriptTypeCast::set_base_type(const StringName &p_type) { } base_type = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -747,7 +751,7 @@ void VisualScriptTypeCast::set_base_script(const String &p_path) { } script = p_path; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -796,7 +800,7 @@ public: } if (!ResourceCache::has(script)) { - //if the script is not in use by anyone, we can safely assume whathever we got is not casting to it. + //if the script is not in use by anyone, we can safely assume whatever we got is not casting to it. return 1; } Ref<Script> cast_script = Ref<Resource>(ResourceCache::get(script)); diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index 46a72bb92d..d9c4dedafd 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -202,6 +202,8 @@ protected: static void _bind_methods(); public: + virtual void reset_state() override; + virtual int get_output_sequence_port_count() const override; virtual bool has_input_sequence_port() const override; diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index d016b938de..9310b86627 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -281,7 +281,7 @@ void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { } basic_type = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -295,7 +295,7 @@ void VisualScriptFunctionCall::set_base_type(const StringName &p_type) { } base_type = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -309,7 +309,7 @@ void VisualScriptFunctionCall::set_base_script(const String &p_path) { } base_script = p_path; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -328,7 +328,7 @@ void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { base_type = obj->get_class(); } - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -425,7 +425,7 @@ void VisualScriptFunctionCall::set_function(const StringName &p_type) { _update_method_cache(); } - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -439,7 +439,7 @@ void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) { } base_path = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -453,7 +453,7 @@ void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) { } call_mode = p_mode; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -476,7 +476,7 @@ void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCa } rpc_call_mode = p_mode; ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } VisualScriptFunctionCall::RPCCallMode VisualScriptFunctionCall::get_rpc_call_mode() const { @@ -547,7 +547,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } else { Node *bnode = _get_base_node(); if (bnode) { - property.hint_string = bnode->get_path(); //convert to loong string + property.hint_string = bnode->get_path(); //convert to long string } } } @@ -1067,7 +1067,7 @@ void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { } basic_type = p_type; - _change_notify(); + notify_property_list_changed(); _update_base_type(); ports_changed_notify(); } @@ -1082,7 +1082,7 @@ void VisualScriptPropertySet::set_base_type(const StringName &p_type) { } base_type = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1096,7 +1096,7 @@ void VisualScriptPropertySet::set_base_script(const String &p_path) { } base_script = p_path; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1191,7 +1191,7 @@ void VisualScriptPropertySet::set_property(const StringName &p_type) { property = p_type; index = StringName(); _update_cache(); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1206,7 +1206,7 @@ void VisualScriptPropertySet::set_base_path(const NodePath &p_type) { base_path = p_type; _update_base_type(); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1221,7 +1221,7 @@ void VisualScriptPropertySet::set_call_mode(CallMode p_mode) { call_mode = p_mode; _update_base_type(); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1243,7 +1243,7 @@ void VisualScriptPropertySet::set_index(const StringName &p_type) { } index = p_type; _update_cache(); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1259,7 +1259,7 @@ void VisualScriptPropertySet::set_assign_op(AssignOp p_op) { assign_op = p_op; _update_cache(); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1292,7 +1292,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } else { Node *bnode = _get_base_node(); if (bnode) { - property.hint_string = bnode->get_path(); //convert to loong string + property.hint_string = bnode->get_path(); //convert to long string } } } @@ -1760,7 +1760,7 @@ void VisualScriptPropertyGet::set_base_type(const StringName &p_type) { } base_type = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1774,7 +1774,7 @@ void VisualScriptPropertyGet::set_base_script(const String &p_path) { } base_script = p_path; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1871,7 +1871,7 @@ void VisualScriptPropertyGet::set_property(const StringName &p_type) { property = p_type; _update_cache(); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1885,7 +1885,7 @@ void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) { } base_path = p_type; - _change_notify(); + notify_property_list_changed(); _update_base_type(); ports_changed_notify(); } @@ -1900,7 +1900,7 @@ void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) { } call_mode = p_mode; - _change_notify(); + notify_property_list_changed(); _update_base_type(); ports_changed_notify(); } @@ -1915,7 +1915,7 @@ void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) { } basic_type = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1937,7 +1937,7 @@ void VisualScriptPropertyGet::set_index(const StringName &p_type) { } index = p_type; _update_cache(); - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1970,7 +1970,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { } else { Node *bnode = _get_base_node(); if (bnode) { - property.hint_string = bnode->get_path(); //convert to loong string + property.hint_string = bnode->get_path(); //convert to long string } } } @@ -2261,7 +2261,7 @@ void VisualScriptEmitSignal::set_signal(const StringName &p_type) { name = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index ae2b548f21..fed6637acb 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -57,7 +57,7 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value arguments.write[i].type = Variant::NIL; } ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); return true; } if (String(p_name).begins_with("argument_")) { @@ -303,6 +303,14 @@ VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p return instance; } +void VisualScriptFunction::reset_state() { + arguments.clear(); + stack_size = 256; + stack_less = false; + sequenced = true; + rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; +} + VisualScriptFunction::VisualScriptFunction() { stack_size = 256; stack_less = false; @@ -312,7 +320,7 @@ VisualScriptFunction::VisualScriptFunction() { void VisualScriptFunction::set_stack_less(bool p_enable) { stack_less = p_enable; - _change_notify(); + notify_property_list_changed(); } bool VisualScriptFunction::is_stack_less() const { @@ -421,7 +429,7 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { inputports.write[i].type = Variant::NIL; } ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); return true; } if (String(p_name).begins_with("input_") && is_input_port_editable()) { @@ -457,7 +465,7 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { outputports.write[i].type = Variant::NIL; } ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); return true; } if (String(p_name).begins_with("output_") && is_output_port_editable()) { @@ -578,7 +586,7 @@ void VisualScriptLists::add_input_data_port(Variant::Type p_type, const String & } ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) { @@ -590,7 +598,7 @@ void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type inputports.write[p_idx].type = p_type; ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) { @@ -602,7 +610,7 @@ void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name inputports.write[p_idx].name = p_name; ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } void VisualScriptLists::remove_input_data_port(int p_argidx) { @@ -615,7 +623,7 @@ void VisualScriptLists::remove_input_data_port(int p_argidx) { inputports.remove(p_argidx); ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } // output data port interaction @@ -634,7 +642,7 @@ void VisualScriptLists::add_output_data_port(Variant::Type p_type, const String } ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) { @@ -646,7 +654,7 @@ void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_typ outputports.write[p_idx].type = p_type; ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) { @@ -658,7 +666,7 @@ void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_nam outputports.write[p_idx].name = p_name; ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } void VisualScriptLists::remove_output_data_port(int p_argidx) { @@ -671,7 +679,7 @@ void VisualScriptLists::remove_output_data_port(int p_argidx) { outputports.remove(p_argidx); ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } // sequences @@ -687,6 +695,13 @@ bool VisualScriptLists::is_sequenced() const { return sequenced; } +void VisualScriptLists::reset_state() { + inputports.clear(); + outputports.clear(); + sequenced = false; + flags = 0; +} + VisualScriptLists::VisualScriptLists() { // initialize sequenced = false; @@ -1433,7 +1448,7 @@ void VisualScriptConstant::set_constant_type(Variant::Type p_type) { Callable::CallError ce; Variant::construct(type, value, nullptr, 0, ce); ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } Variant::Type VisualScriptConstant::get_constant_type() const { @@ -1764,7 +1779,7 @@ String VisualScriptGlobalConstant::get_caption() const { void VisualScriptGlobalConstant::set_global_constant(int p_which) { index = p_which; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1850,7 +1865,7 @@ String VisualScriptClassConstant::get_caption() const { void VisualScriptClassConstant::set_class_constant(const StringName &p_which) { name = p_which; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1876,7 +1891,7 @@ void VisualScriptClassConstant::set_base_type(const StringName &p_which) { } else { name = ""; } - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -1983,7 +1998,7 @@ String VisualScriptBasicTypeConstant::get_text() const { void VisualScriptBasicTypeConstant::set_basic_type_constant(const StringName &p_which) { name = p_which; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -2010,7 +2025,7 @@ void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) { } else { name = ""; } - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -2140,7 +2155,7 @@ String VisualScriptMathConstant::get_caption() const { void VisualScriptMathConstant::set_math_constant(MathConstant p_which) { constant = p_which; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -2233,7 +2248,7 @@ String VisualScriptEngineSingleton::get_caption() const { void VisualScriptEngineSingleton::set_singleton(const String &p_string) { singleton = p_string; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -2342,7 +2357,7 @@ String VisualScriptSceneNode::get_caption() const { void VisualScriptSceneNode::set_node_path(const NodePath &p_path) { path = p_path; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -2620,7 +2635,7 @@ String VisualScriptResourcePath::get_caption() const { void VisualScriptResourcePath::set_resource_path(const String &p_path) { path = p_path; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -3748,7 +3763,7 @@ void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) { type = p_type; _update_elements(); ports_changed_notify(); - _change_notify(); //to make input appear/disappear + notify_property_list_changed(); //to make input appear/disappear } Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const { diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index ae5e04d096..7392443e4e 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -99,6 +99,8 @@ public: virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual void reset_state() override; + VisualScriptFunction(); }; @@ -134,6 +136,8 @@ protected: static void _bind_methods(); public: + virtual void reset_state() override; + virtual bool is_output_port_editable() const; virtual bool is_output_port_name_editable() const; virtual bool is_output_port_type_editable() const; diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 6c9af4e600..52fe659983 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -152,7 +152,7 @@ void VisualScriptYield::set_yield_mode(YieldMode p_mode) { } yield_mode = p_mode; ports_changed_notify(); - _change_notify(); + notify_property_list_changed(); } VisualScriptYield::YieldMode VisualScriptYield::get_yield_mode() { @@ -359,7 +359,7 @@ void VisualScriptYieldSignal::set_base_type(const StringName &p_type) { base_type = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -374,7 +374,7 @@ void VisualScriptYieldSignal::set_signal(const StringName &p_type) { signal = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -389,7 +389,7 @@ void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) { base_path = p_type; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -404,7 +404,7 @@ void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) { call_mode = p_mode; - _change_notify(); + notify_property_list_changed(); ports_changed_notify(); } @@ -425,7 +425,7 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { } else { Node *bnode = _get_base_node(); if (bnode) { - property.hint_string = bnode->get_path(); //convert to loong string + property.hint_string = bnode->get_path(); //convert to long string } } } |