diff options
Diffstat (limited to 'modules/visual_script/visual_script.cpp')
-rw-r--r-- | modules/visual_script/visual_script.cpp | 402 |
1 files changed, 144 insertions, 258 deletions
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index fe1d82f977..f387c0f288 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -44,7 +44,6 @@ void VisualScriptNode::set_breakpoint(bool p_breakpoint) { } bool VisualScriptNode::is_breakpoint() const { - return breakpoint; } @@ -53,7 +52,6 @@ void VisualScriptNode::ports_changed_notify() { } void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_value) { - ERR_FAIL_INDEX(p_port, default_input_values.size()); default_input_values[p_port] = p_value; @@ -66,13 +64,11 @@ void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_valu } Variant VisualScriptNode::get_default_input_value(int p_port) const { - ERR_FAIL_INDEX_V(p_port, default_input_values.size(), Variant()); return default_input_values[p_port]; } void VisualScriptNode::_set_default_input_values(Array p_values) { - default_input_values = p_values; } @@ -81,7 +77,6 @@ void VisualScriptNode::validate_input_default_values() { //actually validate on save for (int i = 0; i < get_input_value_port_count(); i++) { - Variant::Type expected = get_input_value_port_info(i).type; if (expected == Variant::NIL || expected == default_input_values[i].get_type()) { @@ -101,7 +96,6 @@ void VisualScriptNode::validate_input_default_values() { } Array VisualScriptNode::_get_default_input_values() const { - //validate on save, since on load there is little info about this Array values = default_input_values; values.resize(get_input_value_port_count()); @@ -114,7 +108,6 @@ String VisualScriptNode::get_text() const { } void VisualScriptNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_visual_script"), &VisualScriptNode::get_visual_script); ClassDB::bind_method(D_METHOD("set_default_input_value", "port_idx", "value"), &VisualScriptNode::set_default_input_value); ClassDB::bind_method(D_METHOD("get_default_input_value", "port_idx"), &VisualScriptNode::get_default_input_value); @@ -127,7 +120,6 @@ void VisualScriptNode::_bind_methods() { } VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inputs, int p_output) const { - PropertyInfo pinfo = get_output_value_port_info(p_output); TypeGuess tg; @@ -141,9 +133,9 @@ VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inp } Ref<VisualScript> VisualScriptNode::get_visual_script() const { - - if (scripts_used.size()) + if (scripts_used.size()) { return Ref<VisualScript>(scripts_used.front()->get()); + } return Ref<VisualScript>(); } @@ -157,13 +149,11 @@ VisualScriptNode::VisualScriptNode() { ///////////////////// VisualScriptNodeInstance::VisualScriptNodeInstance() { - sequence_outputs = nullptr; input_ports = nullptr; } VisualScriptNodeInstance::~VisualScriptNodeInstance() { - if (sequence_outputs) { memdelete_arr(sequence_outputs); } @@ -178,7 +168,6 @@ VisualScriptNodeInstance::~VisualScriptNodeInstance() { } void VisualScript::add_function(const StringName &p_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(functions.has(p_name)); @@ -188,16 +177,14 @@ void VisualScript::add_function(const StringName &p_name) { } bool VisualScript::has_function(const StringName &p_name) const { - return functions.has(p_name); } -void VisualScript::remove_function(const StringName &p_name) { +void VisualScript::remove_function(const StringName &p_name) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_name)); for (Map<int, Function::NodeData>::Element *E = functions[p_name].nodes.front(); E; E = E->next()) { - E->get().node->disconnect("ports_changed", callable_mp(this, &VisualScript::_node_ports_changed)); E->get().node->scripts_used.erase(this); } @@ -206,11 +193,11 @@ void VisualScript::remove_function(const StringName &p_name) { } void VisualScript::rename_function(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_name)); - if (p_new_name == p_name) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -223,19 +210,16 @@ void VisualScript::rename_function(const StringName &p_name, const StringName &p } void VisualScript::set_function_scroll(const StringName &p_name, const Vector2 &p_scroll) { - ERR_FAIL_COND(!functions.has(p_name)); functions[p_name].scroll = p_scroll; } Vector2 VisualScript::get_function_scroll(const StringName &p_name) const { - ERR_FAIL_COND_V(!functions.has(p_name), Vector2()); return functions[p_name].scroll; } void VisualScript::get_function_list(List<StringName> *r_functions) const { - for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { r_functions->push_back(E->key()); } @@ -244,18 +228,15 @@ void VisualScript::get_function_list(List<StringName> *r_functions) const { } int VisualScript::get_function_node_id(const StringName &p_name) const { - ERR_FAIL_COND_V(!functions.has(p_name), -1); return functions[p_name].function_id; } void VisualScript::_node_ports_changed(int p_id) { - StringName function; for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - if (E->get().nodes.has(p_id)) { function = E->key(); break; @@ -276,11 +257,9 @@ void VisualScript::_node_ports_changed(int p_id) { for (Set<SequenceConnection>::Element *E = func.sequence_connections.front(); E; E = E->next()) { if (E->get().from_node == p_id && E->get().from_output >= vsn->get_output_sequence_port_count()) { - to_remove.push_back(E->get()); } if (E->get().to_node == p_id && !vsn->has_input_sequence_port()) { - to_remove.push_back(E->get()); } } @@ -292,7 +271,6 @@ void VisualScript::_node_ports_changed(int p_id) { } { - List<DataConnection> to_remove; for (Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { @@ -317,12 +295,10 @@ void VisualScript::_node_ports_changed(int p_id) { } void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<VisualScriptNode> &p_node, const Point2 &p_pos) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - ERR_FAIL_COND(E->get().nodes.has(p_id)); //id can exist only one in script, even for different functions } @@ -348,7 +324,6 @@ void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<Visual } void VisualScript::remove_node(const StringName &p_func, int p_id) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -370,7 +345,6 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) { } { - List<DataConnection> to_remove; for (Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { @@ -396,7 +370,6 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) { } bool VisualScript::has_node(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -404,7 +377,6 @@ bool VisualScript::has_node(const StringName &p_func, int p_id) const { } Ref<VisualScriptNode> VisualScript::get_node(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), Ref<VisualScriptNode>()); const Function &func = functions[p_func]; @@ -414,7 +386,6 @@ Ref<VisualScriptNode> VisualScript::get_node(const StringName &p_func, int p_id) } void VisualScript::set_node_position(const StringName &p_func, int p_id, const Point2 &p_pos) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -424,7 +395,6 @@ void VisualScript::set_node_position(const StringName &p_func, int p_id, const P } Point2 VisualScript::get_node_position(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), Point2()); const Function &func = functions[p_func]; @@ -433,7 +403,6 @@ Point2 VisualScript::get_node_position(const StringName &p_func, int p_id) const } void VisualScript::get_node_list(const StringName &p_func, List<int> *r_nodes) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -443,7 +412,6 @@ void VisualScript::get_node_list(const StringName &p_func, List<int> *r_nodes) c } void VisualScript::sequence_connect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -458,7 +426,6 @@ void VisualScript::sequence_connect(const StringName &p_func, int p_from_node, i } void VisualScript::sequence_disconnect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) { - ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -472,7 +439,6 @@ void VisualScript::sequence_disconnect(const StringName &p_func, int p_from_node } bool VisualScript::has_sequence_connection(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -485,7 +451,6 @@ bool VisualScript::has_sequence_connection(const StringName &p_func, int p_from_ } void VisualScript::get_sequence_connection_list(const StringName &p_func, List<SequenceConnection> *r_connection) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -495,7 +460,6 @@ void VisualScript::get_sequence_connection_list(const StringName &p_func, List<S } void VisualScript::data_connect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -512,7 +476,6 @@ void VisualScript::data_connect(const StringName &p_func, int p_from_node, int p } void VisualScript::data_disconnect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { - ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -528,7 +491,6 @@ void VisualScript::data_disconnect(const StringName &p_func, int p_from_node, in } bool VisualScript::has_data_connection(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -542,20 +504,19 @@ bool VisualScript::has_data_connection(const StringName &p_func, int p_from_node } bool VisualScript::is_input_value_port_connected(const StringName &p_func, int p_node, int p_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; for (const Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { - if (E->get().to_node == p_node && E->get().to_port == p_port) + if (E->get().to_node == p_node && E->get().to_port == p_port) { return true; + } } return false; } bool VisualScript::get_input_value_port_connection_source(const StringName &p_func, int p_node, int p_port, int *r_node, int *r_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -571,7 +532,6 @@ bool VisualScript::get_input_value_port_connection_source(const StringName &p_fu } void VisualScript::get_data_connection_list(const StringName &p_func, List<DataConnection> *r_connection) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -585,7 +545,6 @@ void VisualScript::set_tool_enabled(bool p_enabled) { } void VisualScript::add_variable(const StringName &p_name, const Variant &p_default_value, bool p_export) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(variables.has(p_name)); @@ -605,12 +564,10 @@ void VisualScript::add_variable(const StringName &p_name, const Variant &p_defau } bool VisualScript::has_variable(const StringName &p_name) const { - return variables.has(p_name); } void VisualScript::remove_variable(const StringName &p_name) { - ERR_FAIL_COND(!variables.has(p_name)); variables.erase(p_name); @@ -620,7 +577,6 @@ void VisualScript::remove_variable(const StringName &p_name) { } void VisualScript::set_variable_default_value(const StringName &p_name, const Variant &p_value) { - ERR_FAIL_COND(!variables.has(p_name)); variables[p_name].default_value = p_value; @@ -629,13 +585,13 @@ void VisualScript::set_variable_default_value(const StringName &p_name, const Va _update_placeholders(); #endif } -Variant VisualScript::get_variable_default_value(const StringName &p_name) const { +Variant VisualScript::get_variable_default_value(const StringName &p_name) const { ERR_FAIL_COND_V(!variables.has(p_name), Variant()); return variables[p_name].default_value; } -void VisualScript::set_variable_info(const StringName &p_name, const PropertyInfo &p_info) { +void VisualScript::set_variable_info(const StringName &p_name, const PropertyInfo &p_info) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!variables.has(p_name)); variables[p_name].info = p_info; @@ -645,14 +601,13 @@ void VisualScript::set_variable_info(const StringName &p_name, const PropertyInf _update_placeholders(); #endif } -PropertyInfo VisualScript::get_variable_info(const StringName &p_name) const { +PropertyInfo VisualScript::get_variable_info(const StringName &p_name) const { ERR_FAIL_COND_V(!variables.has(p_name), PropertyInfo()); return variables[p_name].info; } void VisualScript::set_variable_export(const StringName &p_name, bool p_export) { - ERR_FAIL_COND(!variables.has(p_name)); variables[p_name]._export = p_export; @@ -662,30 +617,32 @@ void VisualScript::set_variable_export(const StringName &p_name, bool p_export) } bool VisualScript::get_variable_export(const StringName &p_name) const { - ERR_FAIL_COND_V(!variables.has(p_name), false); return variables[p_name]._export; } void VisualScript::_set_variable_info(const StringName &p_name, const Dictionary &p_info) { - PropertyInfo pinfo; - if (p_info.has("type")) + if (p_info.has("type")) { pinfo.type = Variant::Type(int(p_info["type"])); - if (p_info.has("name")) + } + if (p_info.has("name")) { pinfo.name = p_info["name"]; - if (p_info.has("hint")) + } + if (p_info.has("hint")) { pinfo.hint = PropertyHint(int(p_info["hint"])); - if (p_info.has("hint_string")) + } + if (p_info.has("hint_string")) { pinfo.hint_string = p_info["hint_string"]; - if (p_info.has("usage")) + } + if (p_info.has("usage")) { pinfo.usage = p_info["usage"]; + } set_variable_info(p_name, pinfo); } Dictionary VisualScript::_get_variable_info(const StringName &p_name) const { - PropertyInfo pinfo = get_variable_info(p_name); Dictionary d; d["type"] = pinfo.type; @@ -698,7 +655,6 @@ Dictionary VisualScript::_get_variable_info(const StringName &p_name) const { } void VisualScript::get_variable_list(List<StringName> *r_variables) const { - for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { r_variables->push_back(E->key()); } @@ -707,17 +663,16 @@ void VisualScript::get_variable_list(List<StringName> *r_variables) const { } void VisualScript::set_instance_base_type(const StringName &p_type) { - ERR_FAIL_COND(instances.size()); base_type = p_type; } void VisualScript::rename_variable(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!variables.has(p_name)); - if (p_new_name == p_name) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -736,13 +691,15 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p for (List<int>::Element *E = ids.front(); E; E = E->next()) { Ref<VisualScriptVariableGet> nodeget = get_node(F->get(), E->get()); if (nodeget.is_valid()) { - if (nodeget->get_variable() == p_name) + if (nodeget->get_variable() == p_name) { nodeget->set_variable(p_new_name); + } } else { Ref<VisualScriptVariableSet> nodeset = get_node(F->get(), E->get()); if (nodeset.is_valid()) { - if (nodeset->get_variable() == p_name) + if (nodeset->get_variable() == p_name) { nodeset->set_variable(p_new_name); + } } } } @@ -750,7 +707,6 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p } void VisualScript::add_custom_signal(const StringName &p_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(custom_signals.has(p_name)); @@ -759,48 +715,49 @@ void VisualScript::add_custom_signal(const StringName &p_name) { } bool VisualScript::has_custom_signal(const StringName &p_name) const { - return custom_signals.has(p_name); } -void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant::Type p_type, const String &p_name, int p_index) { +void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant::Type p_type, const String &p_name, int p_index) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); Argument arg; arg.type = p_type; arg.name = p_name; - if (p_index < 0) + if (p_index < 0) { custom_signals[p_func].push_back(arg); - else + } else { custom_signals[p_func].insert(0, arg); + } } -void VisualScript::custom_signal_set_argument_type(const StringName &p_func, int p_argidx, Variant::Type p_type) { +void VisualScript::custom_signal_set_argument_type(const StringName &p_func, int p_argidx, Variant::Type p_type) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); custom_signals[p_func].write[p_argidx].type = p_type; } -Variant::Type VisualScript::custom_signal_get_argument_type(const StringName &p_func, int p_argidx) const { +Variant::Type VisualScript::custom_signal_get_argument_type(const StringName &p_func, int p_argidx) const { ERR_FAIL_COND_V(!custom_signals.has(p_func), Variant::NIL); ERR_FAIL_INDEX_V(p_argidx, custom_signals[p_func].size(), Variant::NIL); return custom_signals[p_func][p_argidx].type; } + void VisualScript::custom_signal_set_argument_name(const StringName &p_func, int p_argidx, const String &p_name) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); custom_signals[p_func].write[p_argidx].name = p_name; } -String VisualScript::custom_signal_get_argument_name(const StringName &p_func, int p_argidx) const { +String VisualScript::custom_signal_get_argument_name(const StringName &p_func, int p_argidx) const { ERR_FAIL_COND_V(!custom_signals.has(p_func), String()); ERR_FAIL_INDEX_V(p_argidx, custom_signals[p_func].size(), String()); return custom_signals[p_func][p_argidx].name; } -void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p_argidx) { +void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p_argidx) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); @@ -808,12 +765,11 @@ void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p } int VisualScript::custom_signal_get_argument_count(const StringName &p_func) const { - ERR_FAIL_COND_V(!custom_signals.has(p_func), 0); return custom_signals[p_func].size(); } -void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_argidx, int p_with_argidx) { +void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_argidx, int p_with_argidx) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); @@ -821,19 +777,19 @@ void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_a SWAP(custom_signals[p_func].write[p_argidx], custom_signals[p_func].write[p_with_argidx]); } -void VisualScript::remove_custom_signal(const StringName &p_name) { +void VisualScript::remove_custom_signal(const StringName &p_name) { ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_name)); custom_signals.erase(p_name); } void VisualScript::rename_custom_signal(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_name)); - if (p_new_name == p_name) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -846,7 +802,6 @@ void VisualScript::rename_custom_signal(const StringName &p_name, const StringNa } void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) const { - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { r_custom_signals->push_back(E->key()); } @@ -855,11 +810,11 @@ void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) co } int VisualScript::get_available_id() const { - int max_id = 0; for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - if (E->get().nodes.empty()) + if (E->get().nodes.empty()) { continue; + } int last_id = E->get().nodes.back()->key(); max_id = MAX(max_id, last_id + 1); @@ -871,12 +826,10 @@ int VisualScript::get_available_id() const { ///////////////////////////////// bool VisualScript::can_instance() const { - return true; //ScriptServer::is_scripting_enabled(); } StringName VisualScript::get_instance_base_type() const { - return base_type; } @@ -886,21 +839,20 @@ Ref<Script> VisualScript::get_base_script() const { #ifdef TOOLS_ENABLED void VisualScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { - placeholders.erase(p_placeholder); } void VisualScript::_update_placeholders() { - - if (placeholders.size() == 0) + if (placeholders.size() == 0) { return; //no bother if no placeholders + } List<PropertyInfo> pinfo; Map<StringName, Variant> values; for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - - if (!E->get()._export) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); @@ -909,7 +861,6 @@ void VisualScript::_update_placeholders() { } for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) { - E->get()->update(pinfo, values); } } @@ -917,11 +868,9 @@ void VisualScript::_update_placeholders() { #endif ScriptInstance *VisualScript::instance_create(Object *p_this) { - #ifdef TOOLS_ENABLED if (!ScriptServer::is_scripting_enabled() && !is_tool_script) { - PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(VisualScriptLanguage::singleton, Ref<Script>((Script *)this), p_this)); placeholders.insert(sins); @@ -929,9 +878,9 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) { Map<StringName, Variant> values; for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - - if (!E->get()._export) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); @@ -958,17 +907,14 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) { } bool VisualScript::instance_has(const Object *p_this) const { - return instances.has((Object *)p_this); } bool VisualScript::has_source_code() const { - return false; } String VisualScript::get_source_code() const { - return String(); } @@ -976,12 +922,10 @@ void VisualScript::set_source_code(const String &p_code) { } Error VisualScript::reload(bool p_keep_state) { - return OK; } bool VisualScript::is_tool() const { - return is_tool_script; } @@ -990,19 +934,15 @@ bool VisualScript::is_valid() const { } ScriptLanguage *VisualScript::get_language() const { - return VisualScriptLanguage::singleton; } bool VisualScript::has_script_signal(const StringName &p_signal) const { - return custom_signals.has(p_signal); } void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const { - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { - MethodInfo mi; mi.name = E->key(); for (int i = 0; i < E->get().size(); i++) { @@ -1017,21 +957,19 @@ void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const { } bool VisualScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { - - if (!variables.has(p_property)) + if (!variables.has(p_property)) { return false; + } r_value = variables[p_property].default_value; return true; } -void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const { +void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const { for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0) { - Ref<VisualScriptFunction> func = E->get().nodes[E->get().function_id].node; if (func.is_valid()) { for (int i = 0; i < func->get_argument_count(); i++) { @@ -1048,22 +986,20 @@ void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const { } bool VisualScript::has_method(const StringName &p_method) const { - return functions.has(p_method); } -MethodInfo VisualScript::get_method_info(const StringName &p_method) const { +MethodInfo VisualScript::get_method_info(const StringName &p_method) const { const Map<StringName, Function>::Element *E = functions.find(p_method); - if (!E) + if (!E) { return MethodInfo(); + } MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0) { - Ref<VisualScriptFunction> func = E->get().nodes[E->get().function_id].node; if (func.is_valid()) { - for (int i = 0; i < func->get_argument_count(); i++) { PropertyInfo arg; arg.name = func->get_argument_name(i); @@ -1081,7 +1017,6 @@ MethodInfo VisualScript::get_method_info(const StringName &p_method) const { } void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const { - List<StringName> vars; get_variable_list(&vars); @@ -1098,8 +1033,9 @@ int VisualScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED if (has_function(p_member)) { for (Map<int, Function::NodeData>::Element *E = functions[p_member].nodes.front(); E; E = E->next()) { - if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) + if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) { return E->key(); + } } } #endif @@ -1108,9 +1044,7 @@ int VisualScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED bool VisualScript::are_subnodes_edited() const { - for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - for (const Map<int, Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { if (F->get().node->is_edited()) { return true; @@ -1177,15 +1111,14 @@ MultiplayerAPI::RPCMode VisualScript::get_rset_mode(const StringName &p_variable } void VisualScript::_set_data(const Dictionary &p_data) { - Dictionary d = p_data; - if (d.has("base_type")) + if (d.has("base_type")) { base_type = d["base_type"]; + } variables.clear(); Array vars = d["variables"]; for (int i = 0; i < vars.size(); i++) { - Dictionary v = vars[i]; StringName name = v["name"]; add_variable(name); @@ -1197,7 +1130,6 @@ void VisualScript::_set_data(const Dictionary &p_data) { custom_signals.clear(); Array sigs = d["signals"]; for (int i = 0; i < sigs.size(); i++) { - Dictionary cs = sigs[i]; add_custom_signal(cs["name"]); @@ -1214,7 +1146,6 @@ void VisualScript::_set_data(const Dictionary &p_data) { Vector2 last_size = Vector2(0.0, 0.0); for (int i = 0; i < funcs.size(); i++) { - Dictionary func = funcs[i]; StringName name = func["name"]; @@ -1264,22 +1195,21 @@ void VisualScript::_set_data(const Dictionary &p_data) { Array sequence_connections = func["sequence_connections"]; for (int j = 0; j < sequence_connections.size(); j += 3) { - sequence_connect(name, sequence_connections[j + 0], sequence_connections[j + 1], sequence_connections[j + 2]); } Array data_connections = func["data_connections"]; for (int j = 0; j < data_connections.size(); j += 4) { - data_connect(name, data_connections[j + 0], data_connections[j + 1], data_connections[j + 2], data_connections[j + 3]); } } - if (d.has("is_tool_script")) + if (d.has("is_tool_script")) { is_tool_script = d["is_tool_script"]; - else + } else { is_tool_script = false; + } // Takes all the rpc methods rpc_functions.clear(); @@ -1307,12 +1237,10 @@ void VisualScript::_set_data(const Dictionary &p_data) { } Dictionary VisualScript::_get_data() const { - Dictionary d; d["base_type"] = base_type; Array vars; for (const Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - Dictionary var = _get_variable_info(E->key()); var["name"] = E->key(); //make sure it's the right one var["default_value"] = E->get().default_value; @@ -1323,7 +1251,6 @@ Dictionary VisualScript::_get_data() const { Array sigs; for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { - Dictionary cs; cs["name"] = E->key(); Array args; @@ -1341,7 +1268,6 @@ Dictionary VisualScript::_get_data() const { Array funcs; for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - Dictionary func; func["name"] = E->key(); func["function_id"] = E->get().function_id; @@ -1350,7 +1276,6 @@ Dictionary VisualScript::_get_data() const { Array nodes; for (const Map<int, Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - nodes.push_back(F->key()); nodes.push_back(F->get().pos); nodes.push_back(F->get().node); @@ -1361,7 +1286,6 @@ Dictionary VisualScript::_get_data() const { Array sequence_connections; for (const Set<SequenceConnection>::Element *F = E->get().sequence_connections.front(); F; F = F->next()) { - sequence_connections.push_back(F->get().from_node); sequence_connections.push_back(F->get().from_output); sequence_connections.push_back(F->get().to_node); @@ -1372,7 +1296,6 @@ Dictionary VisualScript::_get_data() const { Array data_connections; for (const Set<DataConnection>::Element *F = E->get().data_connections.front(); F; F = F->next()) { - data_connections.push_back(F->get().from_node); data_connections.push_back(F->get().from_port); data_connections.push_back(F->get().to_node); @@ -1392,7 +1315,6 @@ Dictionary VisualScript::_get_data() const { } void VisualScript::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_function", "name"), &VisualScript::add_function); ClassDB::bind_method(D_METHOD("has_function", "name"), &VisualScript::has_function); ClassDB::bind_method(D_METHOD("remove_function", "name"), &VisualScript::remove_function); @@ -1455,7 +1377,6 @@ void VisualScript::_bind_methods() { } VisualScript::VisualScript() { - base_type = "Object"; is_tool_script = false; } @@ -1482,7 +1403,6 @@ Set<int> VisualScript::get_output_sequence_ports_connected(const String &edited_ } VisualScript::~VisualScript() { - while (!functions.empty()) { remove_function(functions.front()->key()); } @@ -1491,10 +1411,10 @@ VisualScript::~VisualScript() { //////////////////////////////////////////// bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) { - Map<StringName, Variant>::Element *E = variables.find(p_name); - if (!E) + if (!E) { return false; + } E->get() = p_value; @@ -1502,45 +1422,45 @@ bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) } bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const { - const Map<StringName, Variant>::Element *E = variables.find(p_name); - if (!E) + if (!E) { return false; + } r_ret = E->get(); return true; } -void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { +void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) { - - if (!E->get()._export) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); p.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; p_properties->push_back(p); } } -Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { +Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { const Map<StringName, VisualScript::Variable>::Element *E = script->variables.find(p_name); if (!E) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = false; + } ERR_FAIL_V(Variant::NIL); } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return E->get().info.type; } void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { - for (const Map<StringName, VisualScript::Function>::Element *E = script->functions.front(); E; E = E->next()) { - if (E->key() == script->get_default_func()) { continue; } @@ -1548,10 +1468,8 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0 && E->get().nodes.has(E->get().function_id)) { - Ref<VisualScriptFunction> vsf = E->get().nodes[E->get().function_id].node; if (vsf.is_valid()) { - for (int i = 0; i < vsf->get_argument_count(); i++) { PropertyInfo arg; arg.name = vsf->get_argument_name(i); @@ -1569,10 +1487,11 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { p_list->push_back(mi); } } -bool VisualScriptInstance::has_method(const StringName &p_method) const { - if (p_method == script->get_default_func()) +bool VisualScriptInstance::has_method(const StringName &p_method) const { + if (p_method == script->get_default_func()) { return false; + } return script->functions.has(p_method); } @@ -1581,29 +1500,27 @@ bool VisualScriptInstance::has_method(const StringName &p_method) const { #define VSDEBUG(m_text) void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int p_pass, int *pass_stack, const Variant **input_args, Variant **output_args, Variant *variant_stack, Callable::CallError &r_error, String &error_str, VisualScriptNodeInstance **r_error_node) { - ERR_FAIL_COND(node->pass_idx == -1); - if (pass_stack[node->pass_idx] == p_pass) + if (pass_stack[node->pass_idx] == p_pass) { return; + } pass_stack[node->pass_idx] = p_pass; if (!node->dependencies.empty()) { - int dc = node->dependencies.size(); VisualScriptNodeInstance **deps = node->dependencies.ptrw(); for (int i = 0; i < dc; i++) { - _dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, r_error_node); - if (r_error.error != Callable::CallError::CALL_OK) + if (r_error.error != Callable::CallError::CALL_OK) { return; + } } } for (int i = 0; i < node->input_port_count; i++) { - int index = node->input_ports[i] & VisualScriptNodeInstance::INPUT_MASK; if (node->input_ports[i] & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) { @@ -1628,7 +1545,6 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int } Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p_stack, int p_stack_size, VisualScriptNodeInstance *p_node, int p_flow_stack_pos, int p_pass, bool p_resuming_yield, Callable::CallError &r_error) { - Map<StringName, Function>::Element *F = functions.find(p_method); ERR_FAIL_COND_V(!F, Variant()); Function *f = &F->get(); @@ -1659,7 +1575,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p #endif while (true) { - p_pass++; //increment pass current_node_id = node->get_id(); @@ -1678,16 +1593,13 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p input_args[i] = &variant_stack[i]; } } else { - //run dependencies first if (!node->dependencies.empty()) { - int dc = node->dependencies.size(); VisualScriptNodeInstance **deps = node->dependencies.ptrw(); for (int i = 0; i < dc; i++) { - _dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, &node); if (r_error.error != Callable::CallError::CALL_OK) { error = true; @@ -1698,12 +1610,10 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } if (!error) { - //setup input pointers normally VSDEBUG("INPUT PORTS: " + itos(node->input_port_count)); for (int i = 0; i < node->input_port_count; i++) { - int index = node->input_ports[i] & VisualScriptNodeInstance::INPUT_MASK; if (node->input_ports[i] & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) { @@ -1719,8 +1629,9 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } } - if (error) + if (error) { break; + } //setup output pointers @@ -1766,7 +1677,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } else { Ref<VisualScriptFunctionState> state = *working_mem; if (!state.is_valid()) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; error_str = RTR("Node yielded, but did not return a function state in the first working memory."); error = true; @@ -1805,15 +1715,17 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool do_break = false; if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) { - - if (EngineDebugger::get_script_debugger()->get_depth() <= 0) + if (EngineDebugger::get_script_debugger()->get_depth() <= 0) { EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1); - if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) + } + if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) { do_break = true; + } } - if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source)) + if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source)) { do_break = true; + } if (do_break) { VisualScriptLanguage::singleton->debug_break("Breakpoint", true); @@ -1828,7 +1740,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p if (ret & VisualScriptNodeInstance::STEP_EXIT_FUNCTION_BIT) { if (node->get_working_memory_size() == 0) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; error_str = RTR("Return value must be assigned to first element of node working memory! Fix your node please."); error = true; @@ -1861,13 +1772,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } if (flow_stack) { - //update flow stack pos (may have changed) flow_stack[flow_stack_pos] = current_node_id; //add stack push bit if requested if (ret & VisualScriptNodeInstance::STEP_FLAG_PUSH_STACK_BIT) { - flow_stack[flow_stack_pos] |= VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT; sequence_bits[node->sequence_index] = true; //remember sequence bit VSDEBUG("NEXT SEQ - FLAG BIT"); @@ -1888,7 +1797,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p break; //simply exit without value or error } } else if (next) { - if (sequence_bits[next->sequence_index]) { // what happened here is that we are entering a node that is in the middle of doing a sequence (pushed stack) from the front // because each node has a working memory, we can't really do a sub-sequence @@ -1898,7 +1806,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool found = false; for (int i = flow_stack_pos; i >= 0; i--) { - if ((flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK) == next->get_id()) { flow_stack_pos = i; //roll back and remove bit flow_stack[i] = next->get_id(); @@ -1940,10 +1847,8 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool found = false; for (int i = flow_stack_pos; i >= 0; i--) { - VSDEBUG("FS " + itos(i) + " - " + itos(flow_stack[i])); if (flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT) { - node = instances[flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK]; flow_stack_pos = i; found = true; @@ -1959,13 +1864,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p VSDEBUG("NO NEXT NODE, GO BACK TO: " + itos(flow_stack_pos)); } } else { - node = next; //stackless mode, simply assign next node } } if (error) { - //error // function, file, line, error, explanation String err_file = script->get_path(); @@ -1973,7 +1876,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p int err_line = current_node_id; //not a line but it works as one if (node && (r_error.error != Callable::CallError::CALL_ERROR_INVALID_METHOD || error_str == String())) { - if (error_str != String()) { error_str += " "; } @@ -1996,13 +1898,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p // debugger break did not happen if (!VisualScriptLanguage::singleton->debug_break(error_str, false)) { - _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, error_str.utf8().get_data(), ERR_HANDLER_SCRIPT); } //} } else { - //return_value= } @@ -2021,7 +1921,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; //ok by default Map<StringName, Function>::Element *F = functions.find(p_method); @@ -2109,7 +2008,6 @@ Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p } void VisualScriptInstance::notification(int p_notification) { - //do nothing as this is called using virtual Variant what = p_notification; @@ -2124,22 +2022,24 @@ String VisualScriptInstance::to_string(bool *r_valid) { Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK) { if (ret.get_type() != Variant::STRING) { - if (r_valid) + if (r_valid) { *r_valid = false; + } ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret.operator String(); } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } Ref<Script> VisualScriptInstance::get_script() const { - return script; } @@ -2184,7 +2084,6 @@ MultiplayerAPI::RPCMode VisualScriptInstance::get_rset_mode(const StringName &p_ } void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_owner) { - script = p_script; owner = p_owner; source = p_script->get_path(); @@ -2195,16 +2094,21 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o if (Object::cast_to<Node>(p_owner)) { //turn on these if they exist and base is a node Node *node = Object::cast_to<Node>(p_owner); - if (p_script->functions.has("_process")) + if (p_script->functions.has("_process")) { node->set_process(true); - if (p_script->functions.has("_physics_process")) + } + if (p_script->functions.has("_physics_process")) { node->set_physics_process(true); - if (p_script->functions.has("_input")) + } + if (p_script->functions.has("_input")) { node->set_process_input(true); - if (p_script->functions.has("_unhandled_input")) + } + if (p_script->functions.has("_unhandled_input")) { node->set_process_unhandled_input(true); - if (p_script->functions.has("_unhandled_key_input")) + } + if (p_script->functions.has("_unhandled_key_input")) { node->set_process_unhandled_key_input(true); + } } for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) { @@ -2212,7 +2116,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o } for (const Map<StringName, VisualScript::Function>::Element *E = script->functions.front(); E; E = E->next()) { - if (E->key() == script->get_default_func()) { continue; } @@ -2251,7 +2154,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //first create the nodes for (const Map<int, VisualScript::Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - Ref<VisualScriptNode> node = F->get().node; VisualScriptNodeInstance *instance = node->instance(this); //create instance @@ -2272,7 +2174,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o if (instance->input_port_count) { instance->input_ports = memnew_arr(int, instance->input_port_count); for (int i = 0; i < instance->input_port_count; i++) { - instance->input_ports[i] = -1; //if not assigned, will become default value } } @@ -2297,10 +2198,11 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o StringName var_name; - if (Object::cast_to<VisualScriptLocalVar>(*node)) + if (Object::cast_to<VisualScriptLocalVar>(*node)) { var_name = String(Object::cast_to<VisualScriptLocalVar>(*node)->get_var_name()).strip_edges(); - else + } else { var_name = String(Object::cast_to<VisualScriptLocalVarSet>(*node)->get_var_name()).strip_edges(); + } if (!local_var_indices.has(var_name)) { local_var_indices[var_name] = function.max_stack; @@ -2327,7 +2229,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //second pass, do data connections for (const Set<VisualScript::DataConnection>::Element *F = E->get().data_connections.front(); F; F = F->next()) { - VisualScript::DataConnection dc = F->get(); ERR_CONTINUE(!instances.has(dc.from_node)); VisualScriptNodeInstance *from = instances[dc.from_node]; @@ -2337,7 +2238,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o ERR_CONTINUE(dc.to_port >= to->input_port_count); if (from->output_ports[dc.from_port] == -1) { - int stack_pos = function.max_stack++; from->output_ports[dc.from_port] = stack_pos; } @@ -2357,7 +2257,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //third pass, do sequence connections for (const Set<VisualScript::SequenceConnection>::Element *F = E->get().sequence_connections.front(); F; F = F->next()) { - VisualScript::SequenceConnection sc = F->get(); ERR_CONTINUE(!instances.has(sc.from_node)); VisualScriptNodeInstance *from = instances[sc.from_node]; @@ -2373,7 +2272,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o // 2) connect unassigned output ports to trash for (const Map<int, VisualScript::Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - ERR_CONTINUE(!instances.has(F->key())); Ref<VisualScriptNode> node = F->get().node; @@ -2382,7 +2280,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o // connect to default values for (int i = 0; i < instance->input_port_count; i++) { if (instance->input_ports[i] == -1) { - //unassigned, connect to default val instance->input_ports[i] = default_values.size() | VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT; default_values.push_back(node->get_default_input_value(i)); @@ -2402,7 +2299,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o } ScriptLanguage *VisualScriptInstance::get_language() { - return VisualScriptLanguage::singleton; } @@ -2410,7 +2306,6 @@ VisualScriptInstance::VisualScriptInstance() { } VisualScriptInstance::~VisualScriptInstance() { - { MutexLock lock(VisualScriptLanguage::singleton->lock); @@ -2427,7 +2322,6 @@ VisualScriptInstance::~VisualScriptInstance() { ///////////////////// Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED @@ -2448,7 +2342,6 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int } else if (p_argcount == 1) { //noooneee, reserved for me, me and only me. } else { - for (int i = 0; i < p_argcount - 1; i++) { args.push_back(*p_args[i]); } @@ -2475,7 +2368,6 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int } void VisualScriptFunctionState::connect_to_signal(Object *p_obj, const String &p_signal, Array p_binds) { - Vector<Variant> binds; for (int i = 0; i < p_binds.size(); i++) { binds.push_back(p_binds[i]); @@ -2485,12 +2377,10 @@ void VisualScriptFunctionState::connect_to_signal(Object *p_obj, const String &p } bool VisualScriptFunctionState::is_valid() const { - return function != StringName(); } Variant VisualScriptFunctionState::resume(Array p_args) { - ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED @@ -2512,7 +2402,6 @@ Variant VisualScriptFunctionState::resume(Array p_args) { } void VisualScriptFunctionState::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_signal", "obj", "signals", "args"), &VisualScriptFunctionState::connect_to_signal); ClassDB::bind_method(D_METHOD("resume", "args"), &VisualScriptFunctionState::resume, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("is_valid"), &VisualScriptFunctionState::is_valid); @@ -2523,7 +2412,6 @@ VisualScriptFunctionState::VisualScriptFunctionState() { } VisualScriptFunctionState::~VisualScriptFunctionState() { - if (function != StringName()) { Variant *s = ((Variant *)stack.ptr()); for (int i = 0; i < variant_stack_size; i++) { @@ -2535,37 +2423,39 @@ VisualScriptFunctionState::~VisualScriptFunctionState() { /////////////////////////////////////////////// String VisualScriptLanguage::get_name() const { - return "VisualScript"; } /* LANGUAGE FUNCTIONS */ void VisualScriptLanguage::init() { } -String VisualScriptLanguage::get_type() const { +String VisualScriptLanguage::get_type() const { return "VisualScript"; } -String VisualScriptLanguage::get_extension() const { +String VisualScriptLanguage::get_extension() const { return "vs"; } -Error VisualScriptLanguage::execute_file(const String &p_path) { +Error VisualScriptLanguage::execute_file(const String &p_path) { return OK; } + void VisualScriptLanguage::finish() { } /* EDITOR FUNCTIONS */ void VisualScriptLanguage::get_reserved_words(List<String> *p_words) const { } + void VisualScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { } + void VisualScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { } -Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { +Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { Ref<VisualScript> script; script.instance(); script->set_instance_base_type(p_base_class_name); @@ -2573,7 +2463,6 @@ Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const } bool VisualScriptLanguage::is_using_templates() { - return true; } @@ -2583,32 +2472,32 @@ void VisualScriptLanguage::make_template(const String &p_class_name, const Strin } bool VisualScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { - return false; } -Script *VisualScriptLanguage::create_script() const { +Script *VisualScriptLanguage::create_script() const { return memnew(VisualScript); } -bool VisualScriptLanguage::has_named_classes() const { +bool VisualScriptLanguage::has_named_classes() const { return false; } -bool VisualScriptLanguage::supports_builtin_mode() const { +bool VisualScriptLanguage::supports_builtin_mode() const { return true; } -int VisualScriptLanguage::find_function(const String &p_function, const String &p_code) const { +int VisualScriptLanguage::find_function(const String &p_function, const String &p_code) const { return -1; } -String VisualScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const { +String VisualScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const { return String(); } void VisualScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { } + void VisualScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) { } @@ -2618,7 +2507,6 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c //break because of parse error if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { - _debug_parse_err_node = p_node; _debug_parse_err_file = p_file; _debug_error = p_error; @@ -2630,9 +2518,7 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c } bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { - _debug_parse_err_node = -1; _debug_parse_err_file = ""; _debug_error = p_error; @@ -2644,21 +2530,21 @@ bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_conti } String VisualScriptLanguage::debug_get_error() const { - return _debug_error; } int VisualScriptLanguage::debug_get_stack_level_count() const { - - if (_debug_parse_err_node >= 0) + if (_debug_parse_err_node >= 0) { return 1; + } return _debug_call_stack_pos; } -int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { - if (_debug_parse_err_node >= 0) +int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { + if (_debug_parse_err_node >= 0) { return _debug_parse_err_node; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1); @@ -2666,28 +2552,31 @@ int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { return *(_call_stack[l].current_id); } -String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_node >= 0) +String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { + if (_debug_parse_err_node >= 0) { return ""; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, ""); int l = _debug_call_stack_pos - p_level - 1; return *_call_stack[l].function; } -String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_node >= 0) +String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { + if (_debug_parse_err_node >= 0) { return _debug_parse_err_file; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, ""); int l = _debug_call_stack_pos - p_level - 1; return _call_stack[l].instance->get_script_ptr()->get_path(); } -void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_node >= 0) +void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { + if (_debug_parse_err_node >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); @@ -2724,7 +2613,6 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String } for (int i = 0; i < node->output_port_count; i++) { - String name = node->get_base_node()->get_output_value_port_info(i).name; if (name == String()) { name = "out_" + itos(i); @@ -2759,17 +2647,19 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String } */ } -void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_node >= 0) +void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { + if (_debug_parse_err_node >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); int l = _debug_call_stack_pos - p_level - 1; Ref<VisualScript> vs = _call_stack[l].instance->get_script(); - if (vs.is_null()) + if (vs.is_null()) { return; + } List<StringName> vars; vs->get_variable_list(&vars); @@ -2783,48 +2673,48 @@ void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<Strin } void VisualScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - //no globals are really reachable in gdscript } -String VisualScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { +String VisualScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { return ""; } void VisualScriptLanguage::reload_all_scripts() { } + void VisualScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { } + /* LOADER FUNCTIONS */ void VisualScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("vs"); } + void VisualScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { } + void VisualScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const { } void VisualScriptLanguage::profiling_start() { } + void VisualScriptLanguage::profiling_stop() { } int VisualScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { - return 0; } int VisualScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { - return 0; } VisualScriptLanguage *VisualScriptLanguage::singleton = nullptr; void VisualScriptLanguage::add_register_func(const String &p_name, VisualScriptNodeRegisterFunc p_func) { - ERR_FAIL_COND(register_funcs.has(p_name)); register_funcs[p_name] = p_func; } @@ -2835,21 +2725,18 @@ void VisualScriptLanguage::remove_register_func(const String &p_name) { } Ref<VisualScriptNode> VisualScriptLanguage::create_node_from_name(const String &p_name) { - ERR_FAIL_COND_V(!register_funcs.has(p_name), Ref<VisualScriptNode>()); return register_funcs[p_name](p_name); } void VisualScriptLanguage::get_registered_node_names(List<String> *r_names) { - for (Map<String, VisualScriptNodeRegisterFunc>::Element *E = register_funcs.front(); E; E = E->next()) { r_names->push_back(E->key()); } } VisualScriptLanguage::VisualScriptLanguage() { - notification = "_notification"; _step = "_step"; _subcall = "_subcall"; @@ -2873,7 +2760,6 @@ VisualScriptLanguage::VisualScriptLanguage() { } VisualScriptLanguage::~VisualScriptLanguage() { - if (_call_stack) { memdelete_arr(_call_stack); } |