diff options
52 files changed, 378 insertions, 176 deletions
@@ -41,7 +41,7 @@ Official binaries for the Godot editor and the export templates can be found ### Compiling from source -[See the official docs](https://docs.godotengine.org/en/latest/development/compiling/) +[See the official docs](https://docs.godotengine.org/en/latest/contributing/development/compiling) for compilation instructions for every supported platform. ## Community and contributing diff --git a/doc/classes/AnimationPlayer.xml b/doc/classes/AnimationPlayer.xml index 9efd3ac939..ca0cbf0ca1 100644 --- a/doc/classes/AnimationPlayer.xml +++ b/doc/classes/AnimationPlayer.xml @@ -137,6 +137,13 @@ Returns [code]true[/code] if playing an animation. </description> </method> + <method name="pause"> + <return type="void" /> + <description> + Pauses the currently playing animation. The [member current_animation_position] will be kept and calling [method play] or [method play_backwards] without arguments or with the same animation name as [member assigned_animation] will resume the animation. + See also [method stop]. + </description> + </method> <method name="play"> <return type="void" /> <param index="0" name="name" type="StringName" default="""" /> @@ -201,10 +208,9 @@ </method> <method name="stop"> <return type="void" /> - <param index="0" name="reset" type="bool" default="true" /> <description> - Stops or pauses the currently playing animation. If [param reset] is [code]true[/code], the animation position is reset to [code]0[/code] and the playback speed is reset to [code]1.0[/code]. - If [param reset] is [code]false[/code], the [member current_animation_position] will be kept and calling [method play] or [method play_backwards] without arguments or with the same animation name as [member assigned_animation] will resume the animation. + Stops the currently playing animation. The animation position is reset to [code]0[/code] and the playback speed is reset to [code]1.0[/code]. + See also [method pause]. </description> </method> </methods> diff --git a/doc/classes/EditorExportPlatform.xml b/doc/classes/EditorExportPlatform.xml index 1d63af9233..f2b39ab134 100644 --- a/doc/classes/EditorExportPlatform.xml +++ b/doc/classes/EditorExportPlatform.xml @@ -1,8 +1,11 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="EditorExportPlatform" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <brief_description> + Identifies a supported export platform, and internally provides the functionality of exporting to that platform. </brief_description> <description> + Base resource that provides the functionality of exporting a release build of a project to a platform, from the editor. Stores platform-specific metadata such as the name and supported features of the platform, and performs the exporting of projects, PCK files, and ZIP files. Uses an export template for the platform provided at the time of project exporting. + Used in scripting by [EditorExportPlugin] to configure platform-specific customization of scenes and resources. See [method EditorExportPlugin._begin_customize_scenes] and [method EditorExportPlugin._begin_customize_resources] for more details. </description> <tutorials> </tutorials> diff --git a/doc/classes/Timer.xml b/doc/classes/Timer.xml index d171797e80..1b6c05284e 100644 --- a/doc/classes/Timer.xml +++ b/doc/classes/Timer.xml @@ -48,7 +48,7 @@ </member> <member name="time_left" type="float" setter="" getter="get_time_left"> The timer's remaining time in seconds. Returns 0 if the timer is inactive. - [b]Note:[/b] You cannot set this value. To change the timer's remaining time, use [method start]. + [b]Note:[/b] This value is read-only and cannot be set. It is based on [member wait_time], which can be set using [method start]. </member> <member name="wait_time" type="float" setter="set_wait_time" getter="get_wait_time" default="1.0"> The wait time in seconds. diff --git a/doc/classes/VisualShaderNodeParticleRandomness.xml b/doc/classes/VisualShaderNodeParticleRandomness.xml index 574ba63ba9..233e072246 100644 --- a/doc/classes/VisualShaderNodeParticleRandomness.xml +++ b/doc/classes/VisualShaderNodeParticleRandomness.xml @@ -23,7 +23,10 @@ <constant name="OP_TYPE_VECTOR_3D" value="2" enum="OpType"> A 3D vector type. </constant> - <constant name="OP_TYPE_MAX" value="3" enum="OpType"> + <constant name="OP_TYPE_VECTOR_4D" value="3" enum="OpType"> + A 4D vector type. + </constant> + <constant name="OP_TYPE_MAX" value="4" enum="OpType"> Represents the size of the [enum OpType] enum. </constant> </constants> diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 6e701cb6bd..98fcde17c4 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -148,6 +148,11 @@ bool CreateDialog::_should_hide_type(const String &p_type) const { return true; } + StringName native_type = ScriptServer::get_global_class_native_base(p_type); + if (ClassDB::class_exists(native_type) && !ClassDB::can_instantiate(native_type)) { + return true; + } + String script_path = ScriptServer::get_global_class_path(p_type); if (script_path.begins_with("res://addons/")) { if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3))) { diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index ea03b1c744..177266e366 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -253,6 +253,12 @@ void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) { value_input_dirty = true; set_process_internal(true); } break; + case Key::ESCAPE: { + value_input_closed_frame = Engine::get_singleton()->get_frames_drawn(); + if (value_input_popup) { + value_input_popup->hide(); + } + } break; default: break; } @@ -479,10 +485,10 @@ void EditorSpinSlider::_notification(int p_what) { } break; case NOTIFICATION_FOCUS_ENTER: { - if ((Input::get_singleton()->is_action_pressed("ui_focus_next") || Input::get_singleton()->is_action_pressed("ui_focus_prev")) && !value_input_just_closed) { + if ((Input::get_singleton()->is_action_pressed("ui_focus_next") || Input::get_singleton()->is_action_pressed("ui_focus_prev")) && value_input_closed_frame != Engine::get_singleton()->get_frames_drawn()) { _focus_entered(); } - value_input_just_closed = false; + value_input_closed_frame = 0; } break; } } @@ -553,7 +559,7 @@ void EditorSpinSlider::_evaluate_input_text() { //text_submitted signal void EditorSpinSlider::_value_input_submitted(const String &p_text) { - value_input_just_closed = true; + value_input_closed_frame = Engine::get_singleton()->get_frames_drawn(); if (value_input_popup) { value_input_popup->hide(); } @@ -562,7 +568,7 @@ void EditorSpinSlider::_value_input_submitted(const String &p_text) { //modal_closed signal void EditorSpinSlider::_value_input_closed() { _evaluate_input_text(); - value_input_just_closed = true; + value_input_closed_frame = Engine::get_singleton()->get_frames_drawn(); } //focus_exited signal @@ -578,7 +584,7 @@ void EditorSpinSlider::_value_focus_exited() { // -> TAB was pressed // -> modal_close was not called // -> need to close/hide manually - if (!value_input_just_closed) { //value_input_just_closed should do the same + if (value_input_closed_frame != Engine::get_singleton()->get_frames_drawn()) { if (value_input_popup) { value_input_popup->hide(); } @@ -672,6 +678,7 @@ void EditorSpinSlider::_ensure_input_popup() { add_child(value_input_popup); value_input = memnew(LineEdit); + value_input->set_focus_mode(FOCUS_CLICK); value_input_popup->add_child(value_input); value_input->set_anchors_and_offsets_preset(PRESET_FULL_RECT); value_input_popup->connect("hidden", callable_mp(this, &EditorSpinSlider::_value_input_closed)); diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h index 99eb953166..a4d810b18b 100644 --- a/editor/editor_spin_slider.h +++ b/editor/editor_spin_slider.h @@ -65,7 +65,7 @@ class EditorSpinSlider : public Range { Control *value_input_popup = nullptr; LineEdit *value_input = nullptr; - bool value_input_just_closed = false; + uint64_t value_input_closed_frame = 0; bool value_input_dirty = false; bool hide_slider = false; diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index 028071ff62..ef6c835b38 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -444,8 +444,10 @@ HashSet<String> EditorExportPlatform::get_features(const Ref<EditorExportPreset> result.insert("template"); if (p_debug) { + result.insert("debug"); result.insert("template_debug"); } else { + result.insert("release"); result.insert("template_release"); } diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index ec3eb1a494..10f2ce25d9 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -267,7 +267,7 @@ void AnimationPlayerEditor::_stop_pressed() { return; } - player->stop(false); + player->pause(); play->set_pressed(false); stop->set_pressed(true); } @@ -1155,7 +1155,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set, bool player->seek_delta(pos, pos - cpos); } else { - player->stop(true); + player->stop(); player->seek(pos, true); } } diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 7b79c9cf7e..28f478e9cd 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1037,7 +1037,7 @@ String GDScript::get_script_path() const { } Error GDScript::load_source_code(const String &p_path) { - if (p_path.is_empty() || ResourceLoader::get_resource_type(p_path.get_slice("::", 0)) == "PackedScene") { + if (p_path.is_empty() || p_path.begins_with("gdscript://") || ResourceLoader::get_resource_type(p_path.get_slice("::", 0)) == "PackedScene") { return OK; } @@ -1363,6 +1363,8 @@ GDScript::GDScript() : GDScriptLanguage::get_singleton()->script_list.add(&script_list); } + + path = vformat("gdscript://%d.gd", get_instance_id()); } void GDScript::_save_orphaned_subclasses(GDScript::ClearData *p_clear_data) { diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 7bde4e7c4b..8afcb431ec 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -68,9 +68,6 @@ static MethodInfo info_from_utility_func(const StringName &p_function) { pi.name = "arg" + itos(i + 1); #endif pi.type = Variant::get_utility_function_argument_type(p_function, i); - if (pi.type == Variant::NIL) { - pi.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - } info.arguments.push_back(pi); } } @@ -103,8 +100,21 @@ static GDScriptParser::DataType make_native_meta_type(const StringName &p_class_ type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; type.kind = GDScriptParser::DataType::NATIVE; type.builtin_type = Variant::OBJECT; - type.is_constant = true; type.native_type = p_class_name; + type.is_constant = true; + type.is_meta_type = true; + return type; +} + +static GDScriptParser::DataType make_script_meta_type(const Ref<Script> &p_script) { + GDScriptParser::DataType type; + type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; + type.kind = GDScriptParser::DataType::SCRIPT; + type.builtin_type = Variant::OBJECT; + type.native_type = p_script->get_instance_base_type(); + type.script_type = p_script; + type.script_path = p_script->get_path(); + type.is_constant = true; type.is_meta_type = true; return type; } @@ -421,7 +431,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c return err; } base = info_parser->get_parser()->head->get_datatype(); - } else if (class_exists(name) && ClassDB::can_instantiate(name)) { + } else if (class_exists(name)) { base.kind = GDScriptParser::DataType::NATIVE; base.native_type = name; } else { @@ -581,11 +591,8 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type result.builtin_type = GDScriptParser::get_builtin_type(first); if (result.builtin_type == Variant::ARRAY) { - GDScriptParser::DataType container_type = resolve_datatype(p_type->container_type); - + GDScriptParser::DataType container_type = type_from_metatype(resolve_datatype(p_type->container_type)); if (container_type.kind != GDScriptParser::DataType::VARIANT) { - container_type.is_meta_type = false; - container_type.is_constant = false; result.set_container_element_type(container_type); } } @@ -607,12 +614,7 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type } result = ref->get_parser()->head->get_datatype(); } else { - result.kind = GDScriptParser::DataType::SCRIPT; - result.script_type = ResourceLoader::load(path, "Script"); - result.native_type = result.script_type->get_instance_base_type(); - result.script_path = path; - result.is_constant = true; - result.is_meta_type = false; + result = make_script_meta_type(ResourceLoader::load(path, "Script")); } } } else if (ProjectSettings::get_singleton()->has_autoload(first) && ProjectSettings::get_singleton()->get_autoload(first).is_singleton) { @@ -656,7 +658,6 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type case GDScriptParser::ClassNode::Member::CONSTANT: if (member.get_datatype().is_meta_type) { result = member.get_datatype(); - result.is_meta_type = false; found = true; break; } else if (Ref<Script>(member.constant->initializer->reduced_value).is_valid()) { @@ -668,15 +669,8 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type return bad_type; } result = ref->get_parser()->head->get_datatype(); - result.is_meta_type = false; } else { - Ref<Script> script = member.constant->initializer->reduced_value; - result.kind = GDScriptParser::DataType::SCRIPT; - result.builtin_type = Variant::OBJECT; - result.script_type = script; - result.script_path = script->get_path(); - result.native_type = script->get_instance_base_type(); - result.is_meta_type = false; + result = make_script_meta_type(member.constant->initializer->reduced_value); } found = true; break; @@ -832,8 +826,7 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class, for (int j = 0; j < member.signal->parameters.size(); j++) { GDScriptParser::ParameterNode *param = member.signal->parameters[j]; - GDScriptParser::DataType param_type = resolve_datatype(param->datatype_specifier); - param_type.is_meta_type = false; + GDScriptParser::DataType param_type = type_from_metatype(resolve_datatype(param->datatype_specifier)); param->set_datatype(param_type); mi.arguments.push_back(PropertyInfo(param_type.builtin_type, param->identifier->name)); // TODO: add signal parameter default values @@ -1518,14 +1511,12 @@ void GDScriptAnalyzer::resolve_assignable(GDScriptParser::AssignableNode *p_assi GDScriptParser::DataType type; type.kind = GDScriptParser::DataType::VARIANT; - bool is_variable = p_assignable->type == GDScriptParser::Node::VARIABLE; bool is_constant = p_assignable->type == GDScriptParser::Node::CONSTANT; GDScriptParser::DataType specified_type; bool has_specified_type = p_assignable->datatype_specifier != nullptr; if (has_specified_type) { - specified_type = resolve_datatype(p_assignable->datatype_specifier); - specified_type.is_meta_type = false; + specified_type = type_from_metatype(resolve_datatype(p_assignable->datatype_specifier)); type = specified_type; } @@ -1581,13 +1572,11 @@ void GDScriptAnalyzer::resolve_assignable(GDScriptParser::AssignableNode *p_assi } else if (!specified_type.is_variant()) { if (initializer_type.is_variant() || !initializer_type.is_hard_type()) { mark_node_unsafe(p_assignable->initializer); - if (is_variable) { - static_cast<GDScriptParser::VariableNode *>(p_assignable)->use_conversion_assign = true; - } + p_assignable->use_conversion_assign = true; } else if (!is_type_compatible(specified_type, initializer_type, true, p_assignable->initializer)) { - if (is_variable && is_type_compatible(initializer_type, specified_type, true, p_assignable->initializer)) { + if (!is_constant && is_type_compatible(initializer_type, specified_type, true, p_assignable->initializer)) { mark_node_unsafe(p_assignable->initializer); - static_cast<GDScriptParser::VariableNode *>(p_assignable)->use_conversion_assign = true; + p_assignable->use_conversion_assign = true; } else { push_error(vformat(R"(Cannot assign a value of type %s to %s "%s" with specified type %s.)", initializer_type.to_string(), p_kind, p_assignable->identifier->name, specified_type.to_string()), p_assignable->initializer); } @@ -2464,7 +2453,7 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a bool types_match = true; for (int i = 0; i < p_call->arguments.size(); i++) { - GDScriptParser::DataType par_type = type_from_property(info.arguments[i]); + GDScriptParser::DataType par_type = type_from_property(info.arguments[i], true); if (!is_type_compatible(par_type, p_call->arguments[i]->get_datatype(), true)) { types_match = false; @@ -2521,7 +2510,7 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: { PropertyInfo wrong_arg = function_info.arguments[err.argument]; push_error(vformat(R"*(Invalid argument for "%s()" function: argument %d should be "%s" but is "%s".)*", function_name, err.argument + 1, - type_from_property(wrong_arg).to_string(), p_call->arguments[err.argument]->get_datatype().to_string()), + type_from_property(wrong_arg, true).to_string(), p_call->arguments[err.argument]->get_datatype().to_string()), p_call->arguments[err.argument]); } break; case Callable::CallError::CALL_ERROR_INVALID_METHOD: @@ -2568,7 +2557,7 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: { String expected_type_name; if (err.argument < function_info.arguments.size()) { - expected_type_name = type_from_property(function_info.arguments[err.argument]).to_string(); + expected_type_name = type_from_property(function_info.arguments[err.argument], true).to_string(); } else { expected_type_name = Variant::get_type_name((Variant::Type)err.expected); } @@ -2766,14 +2755,13 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a void GDScriptAnalyzer::reduce_cast(GDScriptParser::CastNode *p_cast) { reduce_expression(p_cast->operand); - GDScriptParser::DataType cast_type = resolve_datatype(p_cast->cast_type); + GDScriptParser::DataType cast_type = type_from_metatype(resolve_datatype(p_cast->cast_type)); if (!cast_type.is_set()) { mark_node_unsafe(p_cast); return; } - cast_type = type_from_metatype(cast_type); // The casted value won't be a type name. p_cast->set_datatype(cast_type); if (!cast_type.is_variant()) { @@ -2907,15 +2895,7 @@ GDScriptParser::DataType GDScriptAnalyzer::make_global_class_meta_type(const Str return ref->get_parser()->head->get_datatype(); } else { - type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; - type.kind = GDScriptParser::DataType::SCRIPT; - type.builtin_type = Variant::OBJECT; - type.script_type = ResourceLoader::load(path, "Script"); - type.native_type = type.script_type->get_instance_base_type(); - type.script_path = path; - type.is_constant = true; - type.is_meta_type = true; - return type; + return make_script_meta_type(ResourceLoader::load(path, "Script")); } } @@ -3938,10 +3918,10 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_metatype(const GDScriptPars return result; } -GDScriptParser::DataType GDScriptAnalyzer::type_from_property(const PropertyInfo &p_property) const { +GDScriptParser::DataType GDScriptAnalyzer::type_from_property(const PropertyInfo &p_property, bool p_is_arg) const { GDScriptParser::DataType result; result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; - if (p_property.type == Variant::NIL && (p_property.usage & PROPERTY_USAGE_NIL_IS_VARIANT)) { + if (p_property.type == Variant::NIL && (p_is_arg || (p_property.usage & PROPERTY_USAGE_NIL_IS_VARIANT))) { // Variant result.kind = GDScriptParser::DataType::VARIANT; return result; @@ -4030,6 +4010,25 @@ bool GDScriptAnalyzer::get_function_signature(GDScriptParser::Node *p_source, bo return false; } + StringName base_native = p_base_type.native_type; + if (base_native != StringName()) { + // Empty native class might happen in some Script implementations. + // Just ignore it. + if (!class_exists(base_native)) { + push_error(vformat("Native class %s used in script doesn't exist or isn't exposed.", base_native), p_source); + return false; + } else if (p_is_constructor && !ClassDB::can_instantiate(base_native)) { + if (p_base_type.kind == GDScriptParser::DataType::CLASS) { + push_error(vformat(R"(Class "%s" cannot be constructed as it is based on abstract native class "%s".)", p_base_type.class_type->fqcn.get_file(), base_native), p_source); + } else if (p_base_type.kind == GDScriptParser::DataType::SCRIPT) { + push_error(vformat(R"(Script "%s" cannot be constructed as it is based on abstract native class "%s".)", p_base_type.script_path.get_file(), base_native), p_source); + } else { + push_error(vformat(R"(Native class "%s" cannot be constructed as it is abstract.)", base_native), p_source); + } + return false; + } + } + if (p_is_constructor) { function_name = "_init"; r_static = true; @@ -4090,17 +4089,6 @@ bool GDScriptAnalyzer::get_function_signature(GDScriptParser::Node *p_source, bo } } - StringName base_native = p_base_type.native_type; -#ifdef DEBUG_ENABLED - if (base_native != StringName()) { - // Empty native class might happen in some Script implementations. - // Just ignore it. - if (!class_exists(base_native)) { - ERR_FAIL_V_MSG(false, vformat("Native class %s used in script doesn't exist or isn't exposed.", base_native)); - } - } -#endif - if (p_is_constructor) { // Native types always have a default constructor. r_return_type = p_base_type; @@ -4128,7 +4116,7 @@ bool GDScriptAnalyzer::function_signature_from_info(const MethodInfo &p_info, GD r_static = (p_info.flags & METHOD_FLAG_STATIC) != 0; for (const PropertyInfo &E : p_info.arguments) { - r_par_types.push_back(type_from_property(E)); + r_par_types.push_back(type_from_property(E, true)); } return true; } @@ -4137,7 +4125,7 @@ bool GDScriptAnalyzer::validate_call_arg(const MethodInfo &p_method, const GDScr List<GDScriptParser::DataType> arg_types; for (const PropertyInfo &E : p_method.arguments) { - arg_types.push_back(type_from_property(E)); + arg_types.push_back(type_from_property(E, true)); } return validate_call_arg(arg_types, p_method.default_arguments.size(), (p_method.flags & METHOD_FLAG_VARARG) != 0, p_call); diff --git a/modules/gdscript/gdscript_analyzer.h b/modules/gdscript/gdscript_analyzer.h index ecae0b4629..da7b7ddb75 100644 --- a/modules/gdscript/gdscript_analyzer.h +++ b/modules/gdscript/gdscript_analyzer.h @@ -108,7 +108,7 @@ class GDScriptAnalyzer { // Helpers. GDScriptParser::DataType type_from_variant(const Variant &p_value, const GDScriptParser::Node *p_source); static GDScriptParser::DataType type_from_metatype(const GDScriptParser::DataType &p_meta_type); - GDScriptParser::DataType type_from_property(const PropertyInfo &p_property) const; + GDScriptParser::DataType type_from_property(const PropertyInfo &p_property, bool p_is_arg = false) const; GDScriptParser::DataType make_global_class_meta_type(const StringName &p_class_name, const GDScriptParser::Node *p_source); bool get_function_signature(GDScriptParser::Node *p_source, bool p_is_constructor, GDScriptParser::DataType base_type, const StringName &p_function, GDScriptParser::DataType &r_return_type, List<GDScriptParser::DataType> &r_par_types, int &r_default_arg_count, bool &r_static, bool &r_vararg); bool function_signature_from_info(const MethodInfo &p_info, GDScriptParser::DataType &r_return_type, List<GDScriptParser::DataType> &r_par_types, int &r_default_arg_count, bool &r_static, bool &r_vararg); diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index 57ee41e34e..6c80fb7665 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -872,8 +872,12 @@ void GDScriptByteCodeGenerator::write_assign_false(const Address &p_target) { append(p_target); } -void GDScriptByteCodeGenerator::write_assign_default_parameter(const Address &p_dst, const Address &p_src) { - write_assign(p_dst, p_src); +void GDScriptByteCodeGenerator::write_assign_default_parameter(const Address &p_dst, const Address &p_src, bool p_use_conversion) { + if (p_use_conversion) { + write_assign_with_conversion(p_dst, p_src); + } else { + write_assign(p_dst, p_src); + } function->default_arguments.push_back(opcodes.size()); } diff --git a/modules/gdscript/gdscript_byte_codegen.h b/modules/gdscript/gdscript_byte_codegen.h index ac9c4c8fb5..171c505116 100644 --- a/modules/gdscript/gdscript_byte_codegen.h +++ b/modules/gdscript/gdscript_byte_codegen.h @@ -460,7 +460,7 @@ public: virtual void write_assign_with_conversion(const Address &p_target, const Address &p_source) override; virtual void write_assign_true(const Address &p_target) override; virtual void write_assign_false(const Address &p_target) override; - virtual void write_assign_default_parameter(const Address &p_dst, const Address &p_src) override; + virtual void write_assign_default_parameter(const Address &p_dst, const Address &p_src, bool p_use_conversion) override; virtual void write_store_global(const Address &p_dst, int p_global_index) override; virtual void write_store_named_global(const Address &p_dst, const StringName &p_global) override; virtual void write_cast(const Address &p_target, const Address &p_source, const GDScriptDataType &p_type) override; diff --git a/modules/gdscript/gdscript_codegen.h b/modules/gdscript/gdscript_codegen.h index c7a1bcb9e9..e885938eba 100644 --- a/modules/gdscript/gdscript_codegen.h +++ b/modules/gdscript/gdscript_codegen.h @@ -113,7 +113,7 @@ public: virtual void write_assign_with_conversion(const Address &p_target, const Address &p_source) = 0; virtual void write_assign_true(const Address &p_target) = 0; virtual void write_assign_false(const Address &p_target) = 0; - virtual void write_assign_default_parameter(const Address &dst, const Address &src) = 0; + virtual void write_assign_default_parameter(const Address &dst, const Address &src, bool p_use_conversion) = 0; virtual void write_store_global(const Address &p_dst, int p_global_index) = 0; virtual void write_store_named_global(const Address &p_dst, const StringName &p_global) = 0; virtual void write_cast(const Address &p_target, const Address &p_source, const GDScriptDataType &p_type) = 0; diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index beed6e90d2..77c6690d20 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -2116,7 +2116,7 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_ } } - codegen.generator->write_assign_default_parameter(dst_addr, src_addr); + codegen.generator->write_assign_default_parameter(dst_addr, src_addr, parameter->use_conversion_assign); if (src_addr.mode == GDScriptCodeGenerator::Address::TEMPORARY) { codegen.generator->pop_temporary(); } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index a6b8537074..bbea6fe857 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -1321,14 +1321,8 @@ GDScriptParser::EnumNode *GDScriptParser::parse_enum() { if (elements.has(item.identifier->name)) { push_error(vformat(R"(Name "%s" was already in this enum (at line %d).)", item.identifier->name, elements[item.identifier->name]), item.identifier); } else if (!named) { - // TODO: Abstract this recursive member check. - ClassNode *parent = current_class; - while (parent != nullptr) { - if (parent->members_indices.has(item.identifier->name)) { - push_error(vformat(R"(Name "%s" is already used as a class %s.)", item.identifier->name, parent->get_member(item.identifier->name).get_type_name())); - break; - } - parent = parent->outer; + if (current_class->members_indices.has(item.identifier->name)) { + push_error(vformat(R"(Name "%s" is already used as a class %s.)", item.identifier->name, current_class->get_member(item.identifier->name).get_type_name())); } } diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 4bb02c4ea3..0903f62061 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -360,6 +360,7 @@ public: ExpressionNode *initializer = nullptr; TypeNode *datatype_specifier = nullptr; bool infer_datatype = false; + bool use_conversion_assign = false; int usages = 0; virtual ~AssignableNode() {} @@ -1182,7 +1183,6 @@ public: bool onready = false; PropertyInfo export_info; int assignments = 0; - bool use_conversion_assign = false; #ifdef TOOLS_ENABLED String doc_description; #endif // TOOLS_ENABLED diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 04612c6793..e17a804003 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -164,6 +164,7 @@ bool GDScriptTokenizer::Token::is_identifier() const { switch (type) { case IDENTIFIER: case MATCH: // Used in String.match(). + case CONST_INF: // Used in Vector{2,3,4}.INF return true; default: return false; diff --git a/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.gd b/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.gd new file mode 100644 index 0000000000..38c2faa859 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.gd @@ -0,0 +1,2 @@ +func test(): + CanvasItem.new() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.out b/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.out new file mode 100644 index 0000000000..9eff912b59 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Native class "CanvasItem" cannot be constructed as it is abstract. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.gd b/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.gd new file mode 100644 index 0000000000..118e7e8a45 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.gd @@ -0,0 +1,9 @@ +class A extends CanvasItem: + func _init(): + print('no') + +class B extends A: + pass + +func test(): + B.new() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.out b/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.out new file mode 100644 index 0000000000..8b956f5974 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Class "abstract_script_instantiate.gd::B" cannot be constructed as it is based on abstract native class "CanvasItem". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_outer_enum.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_outer_enum.gd deleted file mode 100644 index f3f3b5ffeb..0000000000 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_outer_enum.gd +++ /dev/null @@ -1,7 +0,0 @@ -enum { V } - -class InnerClass: - enum { V } - -func test(): - pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_outer_enum.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_outer_enum.out deleted file mode 100644 index c9706003e1..0000000000 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_outer_enum.out +++ /dev/null @@ -1,2 +0,0 @@ -GDTEST_PARSER_ERROR -Name "V" is already used as a class enum value. diff --git a/modules/gdscript/tests/scripts/analyzer/features/extend_abstract_class.gd b/modules/gdscript/tests/scripts/analyzer/features/extend_abstract_class.gd new file mode 100644 index 0000000000..95c3268130 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/extend_abstract_class.gd @@ -0,0 +1,12 @@ +class A extends CanvasItem: + func _init(): + pass + +class B extends A: + pass + +class C extends CanvasItem: + pass + +func test(): + print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/extend_abstract_class.out b/modules/gdscript/tests/scripts/analyzer/features/extend_abstract_class.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/extend_abstract_class.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok diff --git a/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.gd b/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.gd new file mode 100644 index 0000000000..da24c06b2e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.gd @@ -0,0 +1,6 @@ +class Check extends Node: + func _set(_property: StringName, _value: Variant) -> bool: + return true + +func test() -> void: + print('OK') diff --git a/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.out b/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.out new file mode 100644 index 0000000000..1ccb591560 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.out @@ -0,0 +1,2 @@ +GDTEST_OK +OK diff --git a/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd new file mode 100644 index 0000000000..4cbb464f59 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd @@ -0,0 +1,17 @@ +class A: + enum { X = 1 } + + class B: + enum { X = 2 } + +class C: + const X = 3 + + class D: + enum { X = 4 } + +func test(): + print(A.X) + print(A.B.X) + print(C.X) + print(C.D.X) diff --git a/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out new file mode 100644 index 0000000000..7536c38490 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out @@ -0,0 +1,5 @@ +GDTEST_OK +1 +2 +3 +4 diff --git a/modules/gdscript/tests/scripts/parser/features/vector_inf.gd b/modules/gdscript/tests/scripts/parser/features/vector_inf.gd new file mode 100644 index 0000000000..039d51d9ed --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/vector_inf.gd @@ -0,0 +1,6 @@ +func test(): + var vec2: = Vector2.INF + var vec3: = Vector3.INF + + print(vec2.x == INF) + print(vec3.z == INF) diff --git a/modules/gdscript/tests/scripts/parser/features/vector_inf.out b/modules/gdscript/tests/scripts/parser/features/vector_inf.out new file mode 100644 index 0000000000..9d111a8322 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/vector_inf.out @@ -0,0 +1,3 @@ +GDTEST_OK +true +true diff --git a/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.gd b/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.gd new file mode 100644 index 0000000000..a72ac9b5ee --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.gd @@ -0,0 +1,8 @@ +var weakling = 'not float' +func weak(x: float = weakling): + print(x) + print('typeof x is', typeof(x)) + +func test(): + print(typeof(weak())) + print('not ok') diff --git a/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.out b/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.out new file mode 100644 index 0000000000..8543cf976e --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.out @@ -0,0 +1,8 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: weak() +>> runtime/errors/bad_conversion_for_default_parameter.gd +>> 2 +>> Trying to assign value of type 'String' to a variable of type 'float'. +0 +not ok diff --git a/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.gd b/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.gd new file mode 100644 index 0000000000..9d0c6317b3 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.gd @@ -0,0 +1,19 @@ +func literal(x: float = 1): + print('x is ', x) + print('typeof x is ', typeof(x)) + +var inferring := 2 +func inferred(x: float = inferring): + print('x is ', x) + print('typeof x is ', typeof(x)) + +var weakling = 3 +func weak(x: float = weakling): + print('x is ', x) + print('typeof x is ', typeof(x)) + +func test(): + literal() + inferred() + weak() + print('ok') diff --git a/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.out b/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.out new file mode 100644 index 0000000000..a9ef4919cf --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.out @@ -0,0 +1,8 @@ +GDTEST_OK +x is 1 +typeof x is 3 +x is 2 +typeof x is 3 +x is 3 +typeof x is 3 +ok diff --git a/modules/gdscript/tests/scripts/runtime/features/gdscript.gd b/modules/gdscript/tests/scripts/runtime/features/gdscript.gd new file mode 100644 index 0000000000..f2368643de --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/gdscript.gd @@ -0,0 +1,20 @@ +func test(): + var gdscr: = GDScript.new() + gdscr.source_code = ''' +extends Resource + +func test() -> void: + prints("Outer") + var inner = InnerClass.new() + +class InnerClass: + func _init() -> void: + prints("Inner") +''' + @warning_ignore(return_value_discarded) + gdscr.reload() + + var inst = gdscr.new() + + @warning_ignore(unsafe_method_access) + inst.test() diff --git a/modules/gdscript/tests/scripts/runtime/features/gdscript.out b/modules/gdscript/tests/scripts/runtime/features/gdscript.out new file mode 100644 index 0000000000..16114f57f7 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/gdscript.out @@ -0,0 +1,3 @@ +GDTEST_OK +Outer +Inner diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 0bb7b57a35..a602cc7926 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -1025,7 +1025,7 @@ void EditorExportPlatformAndroid::_fix_manifest(const Ref<EditorExportPreset> &p string_table.write[attr_value] = "com.oculus.handtracking.version"; } - if (tname == "meta-data" && attrname == "name" && value == "xr_hand_tracking_version_value") { + if (tname == "meta-data" && attrname == "value" && value == "xr_hand_tracking_version_value") { string_table.write[attr_value] = "V2.0"; } } diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index bc74978f0b..b3831573cf 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -718,15 +718,23 @@ Error OS_Windows::create_process(const String &p_path, const List<String> &p_arg } Error OS_Windows::kill(const ProcessID &p_pid) { - ERR_FAIL_COND_V(!process_map->has(p_pid), FAILED); + int ret = 0; + if (process_map->has(p_pid)) { + const PROCESS_INFORMATION pi = (*process_map)[p_pid].pi; + process_map->erase(p_pid); - const PROCESS_INFORMATION pi = (*process_map)[p_pid].pi; - process_map->erase(p_pid); + ret = TerminateProcess(pi.hProcess, 0); - const int ret = TerminateProcess(pi.hProcess, 0); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } else { + HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, false, (DWORD)p_pid); + if (hProcess != NULL) { + ret = TerminateProcess(hProcess, 0); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); + CloseHandle(hProcess); + } + } return ret != 0 ? OK : FAILED; } diff --git a/scene/3d/shape_cast_3d.cpp b/scene/3d/shape_cast_3d.cpp index 358da2b6d0..87361d6b38 100644 --- a/scene/3d/shape_cast_3d.cpp +++ b/scene/3d/shape_cast_3d.cpp @@ -30,8 +30,9 @@ #include "shape_cast_3d.h" -#include "collision_object_3d.h" -#include "mesh_instance_3d.h" +#include "core/core_string_names.h" +#include "scene/3d/collision_object_3d.h" +#include "scene/3d/mesh_instance_3d.h" #include "scene/resources/concave_polygon_shape_3d.h" void ShapeCast3D::_notification(int p_what) { @@ -318,25 +319,35 @@ void ShapeCast3D::resource_changed(Ref<Resource> p_res) { update_gizmos(); } +void ShapeCast3D::_shape_changed() { + update_gizmos(); + bool is_editor = Engine::get_singleton()->is_editor_hint(); + if (is_inside_tree() && (is_editor || get_tree()->is_debugging_collisions_hint())) { + _update_debug_shape(); + } +} + void ShapeCast3D::set_shape(const Ref<Shape3D> &p_shape) { if (p_shape == shape) { return; } if (!shape.is_null()) { + shape->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast3D::_shape_changed)); shape->unregister_owner(this); } shape = p_shape; if (!shape.is_null()) { shape->register_owner(this); + shape->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast3D::_shape_changed)); } if (p_shape.is_valid()) { shape_rid = shape->get_rid(); } - if (is_inside_tree() && get_tree()->is_debugging_collisions_hint()) { + bool is_editor = Engine::get_singleton()->is_editor_hint(); + if (is_inside_tree() && (is_editor || get_tree()->is_debugging_collisions_hint())) { _update_debug_shape(); } - update_gizmos(); update_configuration_warnings(); } diff --git a/scene/3d/shape_cast_3d.h b/scene/3d/shape_cast_3d.h index 483364472f..344f1d3b8a 100644 --- a/scene/3d/shape_cast_3d.h +++ b/scene/3d/shape_cast_3d.h @@ -77,6 +77,7 @@ class ShapeCast3D : public Node3D { protected: void _notification(int p_what); void _update_shapecast_state(); + void _shape_changed(); static void _bind_methods(); public: diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 7f42c8fac3..4714282347 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -1731,18 +1731,12 @@ String AnimationPlayer::get_assigned_animation() const { return playback.assigned; } -void AnimationPlayer::stop(bool p_reset) { - _stop_playing_caches(); - Playback &c = playback; - c.blend.clear(); - if (p_reset) { - c.current.from = nullptr; - c.current.speed_scale = 1; - c.current.pos = 0; - } - _set_process(false); - queued.clear(); - playing = false; +void AnimationPlayer::pause() { + _stop_internal(false); +} + +void AnimationPlayer::stop() { + _stop_internal(true); } void AnimationPlayer::set_speed_scale(float p_speed) { @@ -1957,6 +1951,20 @@ void AnimationPlayer::_set_process(bool p_process, bool p_force) { processing = p_process; } +void AnimationPlayer::_stop_internal(bool p_reset) { + _stop_playing_caches(); + Playback &c = playback; + c.blend.clear(); + if (p_reset) { + c.current.from = nullptr; + c.current.speed_scale = 1; + c.current.pos = 0; + } + _set_process(false); + queued.clear(); + playing = false; +} + void AnimationPlayer::animation_set_next(const StringName &p_animation, const StringName &p_next) { ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation)); animation_set[p_animation].next = p_next; @@ -2119,7 +2127,8 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false)); ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(""), DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("stop", "reset"), &AnimationPlayer::stop, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("pause"), &AnimationPlayer::pause); + ClassDB::bind_method(D_METHOD("stop"), &AnimationPlayer::stop); ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing); ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index f431253876..80ceb70d10 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -294,6 +294,7 @@ private: void _animation_changed(const StringName &p_name); void _set_process(bool p_process, bool p_force = false); + void _stop_internal(bool p_reset); bool playing = false; @@ -346,7 +347,8 @@ public: void queue(const StringName &p_name); Vector<String> get_queue(); void clear_queue(); - void stop(bool p_reset = true); + void pause(); + void stop(); bool is_playing() const; String get_current_animation() const; void set_current_animation(const String &p_anim); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index b88695427e..be8c23844f 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -60,7 +60,7 @@ void Tweener::_bind_methods() { ADD_SIGNAL(MethodInfo("finished")); } -void Tween::start_tweeners() { +void Tween::_start_tweeners() { if (tweeners.is_empty()) { dead = true; ERR_FAIL_MSG("Tween without commands, aborting."); @@ -71,6 +71,15 @@ void Tween::start_tweeners() { } } +void Tween::_stop_internal(bool p_reset) { + running = false; + if (p_reset) { + started = false; + dead = false; + total_time = 0; + } +} + Ref<PropertyTweener> Tween::tween_property(Object *p_target, NodePath p_property, Variant p_to, double p_duration) { ERR_FAIL_NULL_V(p_target, nullptr); ERR_FAIL_COND_V_MSG(!valid, nullptr, "Tween invalid. Either finished or created outside scene tree."); @@ -135,14 +144,11 @@ void Tween::append(Ref<Tweener> p_tweener) { } void Tween::stop() { - started = false; - running = false; - dead = false; - total_time = 0; + _stop_internal(true); } void Tween::pause() { - running = false; + _stop_internal(false); } void Tween::play() { @@ -278,7 +284,7 @@ bool Tween::step(double p_delta) { current_step = 0; loops_done = 0; total_time = 0; - start_tweeners(); + _start_tweeners(); started = true; } @@ -319,7 +325,7 @@ bool Tween::step(double p_delta) { } else { emit_signal(SNAME("loop_finished"), loops_done); current_step = 0; - start_tweeners(); + _start_tweeners(); #ifdef DEBUG_ENABLED if (loops <= 0 && Math::is_equal_approx(rem_delta, initial_delta)) { if (!potential_infinite) { @@ -332,7 +338,7 @@ bool Tween::step(double p_delta) { #endif } } else { - start_tweeners(); + _start_tweeners(); } } } diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 8f65416e71..08911d6623 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -123,7 +123,8 @@ private: typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d); static interpolater interpolaters[TRANS_MAX][EASE_MAX]; - void start_tweeners(); + void _start_tweeners(); + void _stop_internal(bool p_reset); protected: static void _bind_methods(); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index dea61fcf66..5ab64b35fd 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -3336,6 +3336,7 @@ void RichTextLabel::push_table(int p_columns, InlineAlignment p_alignment, int p _stop_thread(); MutexLock data_lock(data_mutex); + ERR_FAIL_COND(current->type == ITEM_TABLE); ERR_FAIL_COND(p_columns < 1); ItemTable *item = memnew(ItemTable); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 0008250f8f..4c99563a91 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -2508,14 +2508,6 @@ void VisualShader::_update_shader() const { global_compute_code += " return __rand_from_seed(seed) * (to - from) + from;\n"; global_compute_code += "}\n\n"; - global_compute_code += "vec2 __randv2_range(inout uint seed, vec2 from, vec2 to) {\n"; - global_compute_code += " return vec2(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y));\n"; - global_compute_code += "}\n\n"; - - global_compute_code += "vec3 __randv3_range(inout uint seed, vec3 from, vec3 to) {\n"; - global_compute_code += " return vec3(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z));\n"; - global_compute_code += "}\n\n"; - global_compute_code += "uint __hash(uint x) {\n"; global_compute_code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; global_compute_code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; diff --git a/scene/resources/visual_shader_particle_nodes.cpp b/scene/resources/visual_shader_particle_nodes.cpp index 4ac663f7f2..9cf42b681c 100644 --- a/scene/resources/visual_shader_particle_nodes.cpp +++ b/scene/resources/visual_shader_particle_nodes.cpp @@ -911,11 +911,12 @@ void VisualShaderNodeParticleRandomness::_bind_methods() { ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeParticleRandomness::set_op_type); ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeParticleRandomness::get_op_type); - ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector3"), "set_op_type", "get_op_type"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector3,Vector4"), "set_op_type", "get_op_type"); BIND_ENUM_CONSTANT(OP_TYPE_SCALAR); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D); + BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D); BIND_ENUM_CONSTANT(OP_TYPE_MAX); } @@ -939,6 +940,8 @@ VisualShaderNodeParticleRandomness::PortType VisualShaderNodeParticleRandomness: return PORT_TYPE_VECTOR_2D; case OP_TYPE_VECTOR_3D: return PORT_TYPE_VECTOR_3D; + case OP_TYPE_VECTOR_4D: + return PORT_TYPE_VECTOR_4D; default: break; } @@ -950,48 +953,69 @@ String VisualShaderNodeParticleRandomness::get_output_port_name(int p_port) cons } int VisualShaderNodeParticleRandomness::get_input_port_count() const { - return 2; + return 3; } VisualShaderNodeParticleRandomness::PortType VisualShaderNodeParticleRandomness::get_input_port_type(int p_port) const { - switch (op_type) { - case OP_TYPE_VECTOR_2D: - return PORT_TYPE_VECTOR_2D; - case OP_TYPE_VECTOR_3D: - return PORT_TYPE_VECTOR_3D; - default: + switch (p_port) { + case 0: + return PORT_TYPE_SCALAR_UINT; + case 1: + case 2: + switch (op_type) { + case OP_TYPE_VECTOR_2D: + return PORT_TYPE_VECTOR_2D; + case OP_TYPE_VECTOR_3D: + return PORT_TYPE_VECTOR_3D; + case OP_TYPE_VECTOR_4D: + return PORT_TYPE_VECTOR_4D; + default: + break; + } break; } return PORT_TYPE_SCALAR; } String VisualShaderNodeParticleRandomness::get_input_port_name(int p_port) const { - if (p_port == 0) { - return "min"; - } else if (p_port == 1) { - return "max"; + switch (p_port) { + case 0: + return "seed"; + case 1: + return "min"; + case 2: + return "max"; } return String(); } -String VisualShaderNodeParticleRandomness::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { +bool VisualShaderNodeParticleRandomness::is_input_port_default(int p_port, Shader::Mode p_mode) const { + return p_port == 0; // seed +} + +String VisualShaderNodeParticleRandomness::generate_global_per_node(Shader::Mode p_mode, int p_id) const { String code; - switch (op_type) { - case OP_TYPE_SCALAR: { - code += vformat(" %s = __randf_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]); - } break; - case OP_TYPE_VECTOR_2D: { - code += vformat(" %s = __randv2_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]); - } break; - case OP_TYPE_VECTOR_3D: { - code += vformat(" %s = __randv3_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]); - } break; - default: - break; - } + + code += "vec2 __randv2_range(inout uint seed, vec2 from, vec2 to) {\n"; + code += " return vec2(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y));\n"; + code += "}\n\n"; + + code += "vec3 __randv3_range(inout uint seed, vec3 from, vec3 to) {\n"; + code += " return vec3(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z));\n"; + code += "}\n\n"; + + code += "vec4 __randv4_range(inout uint seed, vec4 from, vec4 to) {\n"; + code += " return vec4(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z), __randf_range(seed, from.w, to.w));\n"; + code += "}\n\n"; + return code; } +String VisualShaderNodeParticleRandomness::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { + static const char *func[(int)OP_TYPE_MAX] = { "__randf_range", "__randv2_range", "__randv3_range", "__randv4_range" }; + return vformat(" %s = %s(%s, %s, %s);\n", p_output_vars[0], func[op_type], p_input_vars[0].is_empty() ? "__seed" : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1], p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]); +} + void VisualShaderNodeParticleRandomness::set_op_type(OpType p_op_type) { ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX)); if (op_type == p_op_type) { @@ -999,16 +1023,20 @@ void VisualShaderNodeParticleRandomness::set_op_type(OpType p_op_type) { } switch (p_op_type) { case OP_TYPE_SCALAR: { - set_input_port_default_value(0, 0.0, get_input_port_default_value(0)); set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); + set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); } break; case OP_TYPE_VECTOR_2D: { - set_input_port_default_value(0, Vector2(), get_input_port_default_value(0)); set_input_port_default_value(1, Vector2(), get_input_port_default_value(1)); + set_input_port_default_value(2, Vector2(), get_input_port_default_value(2)); } break; case OP_TYPE_VECTOR_3D: { - set_input_port_default_value(0, Vector3(), get_input_port_default_value(0)); set_input_port_default_value(1, Vector3(), get_input_port_default_value(1)); + set_input_port_default_value(2, Vector3(), get_input_port_default_value(2)); + } break; + case OP_TYPE_VECTOR_4D: { + set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1)); + set_input_port_default_value(2, Quaternion(), get_input_port_default_value(2)); } break; default: break; @@ -1026,8 +1054,8 @@ bool VisualShaderNodeParticleRandomness::has_output_port_preview(int p_port) con } VisualShaderNodeParticleRandomness::VisualShaderNodeParticleRandomness() { - set_input_port_default_value(0, -1.0); - set_input_port_default_value(1, 1.0); + set_input_port_default_value(1, -1.0); + set_input_port_default_value(2, 1.0); } // VisualShaderNodeParticleAccelerator diff --git a/scene/resources/visual_shader_particle_nodes.h b/scene/resources/visual_shader_particle_nodes.h index c0ab974693..08fb059534 100644 --- a/scene/resources/visual_shader_particle_nodes.h +++ b/scene/resources/visual_shader_particle_nodes.h @@ -216,6 +216,7 @@ public: OP_TYPE_SCALAR, OP_TYPE_VECTOR_2D, OP_TYPE_VECTOR_3D, + OP_TYPE_VECTOR_4D, OP_TYPE_MAX, }; @@ -232,12 +233,14 @@ public: virtual int get_input_port_count() const override; virtual PortType get_input_port_type(int p_port) const override; virtual String get_input_port_name(int p_port) const override; + virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override; virtual int get_output_port_count() const override; virtual PortType get_output_port_type(int p_port) const override; virtual String get_output_port_name(int p_port) const override; virtual bool has_output_port_preview(int p_port) const override; + virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override; virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; void set_op_type(OpType p_type); |